~ubuntu-branches/ubuntu/trusty/gnurobbo/trusty-proposed

« back to all changes in this revision

Viewing changes to screen.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Kitt
  • Date: 2009-10-25 13:08:58 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20091025130858-hhngbr72w60jsen2
Tags: 0.62-1
* New maintainer (Closes: #544913).
* New upstream version.
* Refreshed patches:
  + do-not-dump-vmusage.diff: removed, merged upstream;
  + Makefile.diff: updated.
* Bump Standards-Version to 3.8.3; no change required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
 
631
 
 
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 */
631
641
 
632
642
/*      On exit: returns 1 on error */   
633
643
 
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;
639
649
        #endif
640
650
        char description[256];
641
651
 
 
652
        /* Initialise all 3 modes to use software surfaces by default */
 
653
        for (count = 0; count < 3; count++) hwsurface[count] = SDL_SWSURFACE;
 
654
 
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;
649
662
        }
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;
653
 
        #endif
 
666
        #endif */
 
667
 
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)
658
672
        #elif defined(PLATFORM_ZAURUS)
659
673
                video.fullscreen = SDL_FULLSCREEN;
660
674
        #endif
 
675
 
661
676
        /* Validate the viewport dimensions */
662
677
        if (viewport.max_w == UNDEFINED || viewport.max_h == UNDEFINED) {
663
678
                viewport.max_w = DEFAULT_VIEWPORT_WIDTH;
665
680
        }
666
681
        if (viewport.maximise == UNDEFINED) viewport.maximise = FALSE;
667
682
        
 
683
        /* Query available fullscreen hwsurface modes */
668
684
        #ifdef DEBUG_VIDEO      
669
685
                printf("*** Start %s ***\n", __func__);
670
686
                printf ("Fullscreen hwsurfaces :-\n");
671
687
        #endif
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");
681
696
                #endif
682
 
                hwsurface = TRUE;
 
697
                for (count = 0; count < 3; count++) hwsurface[count] = SDL_HWSURFACE;
683
698
        } else {
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);
687
702
                        #endif
688
703
                        if (modes[count]->w == video.xres && modes[count]->h == video.yres) {
689
 
                                hwsurface = TRUE;
 
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;
690
709
                        }
691
710
                }
692
711
        }
 
712
 
 
713
        /* Query available fullscreen swsurface modes */
693
714
        #ifdef DEBUG_VIDEO      
694
715
                printf ("Fullscreen swsurfaces :-\n");
695
716
        #endif
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);
728
748
        #endif
729
749
 
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)
733
 
                hwsurface = FALSE;
 
753
                for (count = 0; count < 3; count++) hwsurface[count] = SDL_SWSURFACE;
734
754
        #endif
735
755
        
736
 
        /* We have enough info to set the correct mode now */
737
 
        if (hwsurface) {
738
 
                flags = SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_ANYFORMAT | video.fullscreen;
739
 
                strcpy(description, "double buffered hardware");
740
 
        } else {
741
 
                flags = SDL_SWSURFACE | SDL_ANYFORMAT | video.fullscreen;
742
 
                strcpy(description, "software");
743
 
        }
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++) {
 
758
 
 
759
                /* Set the hi-res or lo-res modes if the user requested mode failed */
 
760
                if (count == 1) {
 
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;
 
764
                }
 
765
 
 
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");
 
770
                } else {
 
771
                        flags = SDL_SWSURFACE | SDL_ANYFORMAT | video.fullscreen;
 
772
                        strcpy(description, "software");
 
773
                }
 
774
 
 
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);
754
782
                }
 
783
 
 
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) {
757
787
                        break;
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;
1879
1910
                        } else {
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;
1881
1912
                        }
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);
1904
1935
 
 
1936
                        /* Save rcfile */
 
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;
 
1939
                        } else {
 
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;
 
1941
                        }
 
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);
 
1947
 
 
1948
                        /* < */
 
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;
 
1951
                        } else {
 
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;
 
1953
                        }
 
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);
 
1959
 
 
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);
 
1966
                        }
 
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);
 
1972
 
 
1973
                        /* > */
 
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;
 
1976
                        } else {
 
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;
 
1978
                        }
 
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);
 
1983
 
1905
1984
                } else if (optionsscreenpage == 1) {
1906
1985
 
1907
1986
                        /* Draw the control reconfiguration help text */
2254
2333
    
2255
2334
    On entry: redrawlevel = REDRAW_INITIALISE to initialise a message box
2256
2335
                          name = unique identifier
2257
 
                          timeout = units of TICK_INTERVAL
 
2336
                          timeout = units of game cycles
2258
2337
                          message = message
2259
2338
                          dynamic = TRUE to fit to the size of the text
2260
2339
                          dynamic = FALSE for an exact size with