627
627
/***************************************************************************
628
628
* Set Video Mode *
629
629
***************************************************************************/
630
/* Now allows the setting of any resolution with a choice of field_sizes */
630
/* Now allows the setting of any resolution with a choice of field_sizes.
632
This function works thus :-
633
* There is a user requested mode, a hi-res mode (640x480) and a lo-res mode (320x240)
634
* SDL is queried to see if any of these modes can use hardware surfaces
635
* The GP2X using the GPH SDK is forced to 320x240 software surface fullscreen
636
* The Zaurus is forced fullscreen
637
* An attempt is made to set the user requested mode
638
* If that fails then an attempt is made to set the hi-res mode (640x480)
639
* If that fails then an attempt is made to set the lo-res mode (320x240)
640
* If that fails then the program quits */
632
642
/* On exit: returns 1 on error */
634
644
int set_video_mode(void) {
635
645
SDL_Rect **modes;
636
int hwsurface = FALSE, count, flags;
646
int hwsurface[3], count, flags;
637
647
#ifdef DEBUG_VIDEO
638
648
const SDL_VideoInfo *videoinfo;
640
650
char description[256];
652
/* Initialise all 3 modes to use software surfaces by default */
653
for (count = 0; count < 3; count++) hwsurface[count] = SDL_SWSURFACE;
642
655
/* Validate the screen resolution and field_size that the user may have requested */
643
656
if (video.xres == UNDEFINED || video.yres == UNDEFINED) {
644
657
video.xres = 640; video.yres = 480;
647
660
if (video.field_size == UNDEFINED) video.field_size = 32;
648
661
if (video.xres < 480 || video.yres < 480) video.field_size = 16;
650
/* Force GP2X screen resolution as there is no option */
663
/* Force GP2X screen resolution as there is no option. Redundant
651
664
#if defined(PLATFORM_GP2X)
652
665
video.xres = 320; video.yres = 240; video.field_size = 16;
654
668
/* Validate fullscreen that the user may have requested */
655
669
if (video.fullscreen == UNDEFINED) video.fullscreen = 0;
656
670
#if defined(PLATFORM_GP2X)
666
681
if (viewport.maximise == UNDEFINED) viewport.maximise = FALSE;
683
/* Query available fullscreen hwsurface modes */
668
684
#ifdef DEBUG_VIDEO
669
685
printf("*** Start %s ***\n", __func__);
670
686
printf ("Fullscreen hwsurfaces :-\n");
672
/* Query available fullscreen hwsurface modes */
673
688
modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
674
689
if (modes == NULL) {
675
690
#ifdef DEBUG_VIDEO
679
694
#ifdef DEBUG_VIDEO
680
695
printf("Any dimension is okay\n");
697
for (count = 0; count < 3; count++) hwsurface[count] = SDL_HWSURFACE;
684
699
for (count = 0; modes[count]; ++count) {
685
700
#ifdef DEBUG_VIDEO
686
701
printf("%dx%d\n", modes[count]->w, modes[count]->h);
688
703
if (modes[count]->w == video.xres && modes[count]->h == video.yres) {
704
hwsurface[0] = SDL_HWSURFACE;
705
} else if (modes[count]->w == 640 && modes[count]->h == 480) {
706
hwsurface[1] = SDL_HWSURFACE;
707
} else if (modes[count]->w == 320 && modes[count]->h == 240) {
708
hwsurface[2] = SDL_HWSURFACE;
713
/* Query available fullscreen swsurface modes */
693
714
#ifdef DEBUG_VIDEO
694
715
printf ("Fullscreen swsurfaces :-\n");
696
/* Query available fullscreen swsurface modes */
697
717
modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_SWSURFACE);
698
718
if (modes == NULL) {
699
719
#ifdef DEBUG_VIDEO
727
747
printf ("BytesPerPixel: %u\n", videoinfo->vfmt->BytesPerPixel);
730
/* Well after all that clever video mode detection code the GP2X
731
GPH SDL states it has hwsurface support and then seg faults ;) */
750
/* Well after all that clever video mode detection code the GPH
751
GP2X SDL states it has hwsurface support and then seg faults ;) */
732
752
#if defined(PLATFORM_GP2X)
753
for (count = 0; count < 3; count++) hwsurface[count] = SDL_SWSURFACE;
736
/* We have enough info to set the correct mode now */
738
flags = SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_ANYFORMAT | video.fullscreen;
739
strcpy(description, "double buffered hardware");
741
flags = SDL_SWSURFACE | SDL_ANYFORMAT | video.fullscreen;
742
strcpy(description, "software");
744
/* Attempt to set the requested video mode or fall back to some defaults */
756
/* First attempt to set the user requested mode, then hi-res, then lo-res, then quit */
745
757
for (count = 0; count < 3; count++) {
759
/* Set the hi-res or lo-res modes if the user requested mode failed */
761
video.xres = 640; video.yres = 480; video.field_size = 32;
762
} else if (count == 2) {
763
video.xres = 320; video.yres = 240; video.field_size = 16;
766
/* Set the SDL flags and prepare the description string */
767
if (hwsurface[count] == SDL_HWSURFACE) {
768
flags = SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_ANYFORMAT | video.fullscreen;
769
strcpy(description, "double buffered hardware");
771
flags = SDL_SWSURFACE | SDL_ANYFORMAT | video.fullscreen;
772
strcpy(description, "software");
775
/* Tell the user what we're about to do */
746
776
if (count == 0) {
747
777
fprintf(stdout, "Setting video mode %ix%i 16bpp %s surface.\n", video.xres, video.yres, description);
748
778
} else if (count == 1) {
749
video.xres = 640; video.yres = 480; video.field_size = 32;
750
779
fprintf(stdout, "Trying default hi-res video mode %ix%i 16bpp %s surface.\n", video.xres, video.yres, description);
751
780
} else if (count == 2) {
752
video.xres = 320; video.yres = 240; video.field_size = 16;
753
fprintf(stdout, "Trying default low-res video mode %ix%i 16bpp %s surface.\n", video.xres, video.yres, description);
781
fprintf(stdout, "Trying default lo-res video mode %ix%i 16bpp %s surface.\n", video.xres, video.yres, description);
784
/* We have enough info to set the correct mode now */
755
785
screen = SDL_SetVideoMode(video.xres, video.yres, 16, flags);
756
786
if (screen != NULL) {
1540
1570
temp_joystick_dead_zone = joystick_dead_zone;
1541
1571
temp_selected_skin = selected_skin;
1542
1572
temp_selected_locale = selected_locale;
1573
temp_rcfile_save_type = rcfile.save_type;
1543
1574
for (count = 0; count < USER_CONTROLS; count++) {
1544
1575
temp_user_controls[count].device = user_controls[count].device;
1545
1576
temp_user_controls[count].id = user_controls[count].id;
1880
1911
fgcolor.r = skins[selected_skin].menu_selected_limit_text_colour >> 16 & 0xff; fgcolor.g = skins[selected_skin].menu_selected_limit_text_colour >> 8 & 0xff; fgcolor.b = skins[selected_skin].menu_selected_limit_text_colour & 0xff;
1882
image = TTF_RenderUTF8_Shaded(font, " > ", fgcolor, bgcolor);
1913
image = TTF_RenderUTF8_Shaded(font, " > ", fgcolor, bgcolor);
1883
1914
destrect.w = image->w; destrect.h = image->h;
1884
1915
SDL_BlitSurface(image, NULL, screen, &destrect);
1885
1916
SDL_FreeSurface(image);
1902
1933
SDL_BlitSurface(image, NULL, screen, &destrect);
1903
1934
SDL_FreeSurface(image);
1937
if (optionsscreenmenuposition[optionsscreenpage] == 6) {
1938
fgcolor.r = skins[selected_skin].menu_selected_text_colour >> 16 & 0xff; fgcolor.g = skins[selected_skin].menu_selected_text_colour >> 8 & 0xff; fgcolor.b = skins[selected_skin].menu_selected_text_colour & 0xff;
1940
fgcolor.r = skins[selected_skin].menu_text_colour >> 16 & 0xff; fgcolor.g = skins[selected_skin].menu_text_colour >> 8 & 0xff; fgcolor.b = skins[selected_skin].menu_text_colour & 0xff;
1942
image = TTF_RenderUTF8_Shaded(font, txt_Save_rcfile, fgcolor, bgcolor);
1943
destrect = set_rect(xoffset + 2 * video.field_size / 16, yoffset + 57 * video.field_size / 16 + 8 * yincrement, image->w, image->h);
1944
SDL_BlitSurface(image, NULL, screen, &destrect);
1945
destrect.x += image->w;
1946
SDL_FreeSurface(image);
1949
if (temp_rcfile_save_type > 0) {
1950
fgcolor.r = skins[selected_skin].menu_selected_text_colour >> 16 & 0xff; fgcolor.g = skins[selected_skin].menu_selected_text_colour >> 8 & 0xff; fgcolor.b = skins[selected_skin].menu_selected_text_colour & 0xff;
1952
fgcolor.r = skins[selected_skin].menu_selected_limit_text_colour >> 16 & 0xff; fgcolor.g = skins[selected_skin].menu_selected_limit_text_colour >> 8 & 0xff; fgcolor.b = skins[selected_skin].menu_selected_limit_text_colour & 0xff;
1954
image = TTF_RenderUTF8_Shaded(font, " < ", fgcolor, bgcolor);
1955
destrect.w = image->w; destrect.h = image->h;
1956
SDL_BlitSurface(image, NULL, screen, &destrect);
1957
destrect.x += image->w;
1958
SDL_FreeSurface(image);
1960
/* on exit / on change */
1961
fgcolor.r = skins[selected_skin].general_text_colour >> 16 & 0xff; fgcolor.g = skins[selected_skin].general_text_colour >> 8 & 0xff; fgcolor.b = skins[selected_skin].general_text_colour & 0xff;
1962
if (temp_rcfile_save_type == RCFILE_SAVE_ON_EXIT) {
1963
sprintf(tempstring, "%s", txt_on_exit);
1964
} else if (temp_rcfile_save_type == RCFILE_SAVE_ON_CHANGE) {
1965
sprintf(tempstring, "%s", txt_on_change);
1967
image = TTF_RenderUTF8_Shaded(font, tempstring, fgcolor, bgcolor);
1968
destrect.w = image->w; destrect.h = image->h;
1969
SDL_BlitSurface(image, NULL, screen, &destrect);
1970
destrect.x += image->w;
1971
SDL_FreeSurface(image);
1974
if (temp_rcfile_save_type < 1) {
1975
fgcolor.r = skins[selected_skin].menu_selected_text_colour >> 16 & 0xff; fgcolor.g = skins[selected_skin].menu_selected_text_colour >> 8 & 0xff; fgcolor.b = skins[selected_skin].menu_selected_text_colour & 0xff;
1977
fgcolor.r = skins[selected_skin].menu_selected_limit_text_colour >> 16 & 0xff; fgcolor.g = skins[selected_skin].menu_selected_limit_text_colour >> 8 & 0xff; fgcolor.b = skins[selected_skin].menu_selected_limit_text_colour & 0xff;
1979
image = TTF_RenderUTF8_Shaded(font, " > ", fgcolor, bgcolor);
1980
destrect.w = image->w; destrect.h = image->h;
1981
SDL_BlitSurface(image, NULL, screen, &destrect);
1982
SDL_FreeSurface(image);
1905
1984
} else if (optionsscreenpage == 1) {
1907
1986
/* Draw the control reconfiguration help text */