changeset 620:5fda51e99fe5

More work.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 13 Apr 2013 01:27:25 +0300
parents 6c23042c546f
children 3a9d92533312
files dmengine.h dmsimple.c
diffstat 2 files changed, 67 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/dmengine.h	Fri Apr 12 15:32:37 2013 +0300
+++ b/dmengine.h	Sat Apr 13 01:27:25 2013 +0300
@@ -20,8 +20,8 @@
 #endif
 
 // Video setup screen / window size
-#define DM_VSETUP_WIDTH  640
-#define DM_VSETUP_HEIGHT 480
+#define DM_VSETUP_WIDTH       640
+#define DM_VSETUP_HEIGHT      480
 
 #define DM_VSETUP_MENU_XC     120
 #define DM_VSETUP_MENU_YC     200
@@ -30,9 +30,9 @@
 
 
 // Video setup type
-#define DM_VSETUP_NONE   0x00  // No video setup, just set window/screen to what demo specifies
-#define DM_VSETUP_ASPECT 0x01  // Only modes that match the optVidAspect aspect ratio are ok
-#define DM_VSETUP_ANY    0x02  // Any available mode is okay, the code can adapt
+#define DM_VSETUP_NONE        0x00  // No video setup, just set window/screen to what demo specifies
+#define DM_VSETUP_ASPECT      0x01  // Only modes that match the optVidAspect aspect ratio are ok
+#define DM_VSETUP_ANY         0x02  // Any available mode is okay, the code can adapt
 
 
 
--- a/dmsimple.c	Fri Apr 12 15:32:37 2013 +0300
+++ b/dmsimple.c	Sat Apr 13 01:27:25 2013 +0300
@@ -165,7 +165,7 @@
 
 typedef struct
 {
-    int w, h;
+    int w, h, aspect;
 } DMModeEntry;
 
 
@@ -187,6 +187,10 @@
 {
     DMModeEntry *mode;
     int i;
+    int aspect = engineGetVideoAspect(w, h);
+    
+    if (aspect <= 0)
+        return DMERR_INVALID_ARGS;
     
     // Check if the mode is already in our list
     for (i = 0; i < nengineModeList; i++)
@@ -196,6 +200,18 @@
             return DMERR_OK;
     }
 
+    // Check if the mode fits our criteria
+    switch (engine.optVidSetup)
+    {
+        case DM_VSETUP_ASPECT:
+            if (aspect != engine.optVidAspect)
+                return DMERR_OK;
+            break;
+        
+        case DM_VSETUP_ANY:
+            break;
+    }
+
     // Reallocate array if needed
     if (nengineModeList + 1 >= aengineModeList)
     {
@@ -209,6 +225,7 @@
     mode = &engineModeList[nengineModeList];
     mode->w = w;
     mode->h = h;
+    mode->aspect = engineGetVideoAspect(w, h);
     
     nengineModeList++;
     
@@ -221,15 +238,13 @@
     DMBitmapFont *menuFont = NULL;
     DMResource *file = NULL;
     SDL_Surface *menuBgImage = NULL, *menuBarImage = NULL;
-    int result, menuState = -1, menuChoice = 0;
+    int result, menuState = -1;
     BOOL fullScreen = TRUE;
-    char menuStr[64];
 
     // Compute a list of valid modes
     if (!engineGenInitializeVideo(DM_VSETUP_WIDTH, DM_VSETUP_HEIGHT, engine.optVidDepth, engine.optVFlags))
         goto out;
 
-
     SDL_Rect **modes = SDL_ListModes(engine.screen->format, engine.screen->flags | SDL_FULLSCREEN);
     if (modes == (SDL_Rect**) 0)
     {
@@ -244,6 +259,12 @@
             engineAddModeToList(modes[i]->w, modes[i]->h);
     }
 
+    if (nengineModeList == 0)
+    {
+        dmError("Umm, no modes found.\n");
+        goto out;
+    }
+
     qsort(engineModeList, nengineModeList, sizeof(engineModeList[0]), engineModeSort);
 
     // Open video temporarily
@@ -311,12 +332,19 @@
 
     SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
     
-    int menuEntryHeight = menuFont->height + 2,
+
+
+    // Enter the main loop of the menu
+    char menuStr[64];
+    int menuOffset = 0,
+        menuIndex = 0,
+        menuEntryHeight = menuFont->height + 2,
         menuHeight = DM_VSETUP_MENU_HEIGHT / menuEntryHeight;
 
-    // Enter the main loop of the menu
+    menuState = 0;
+
     engine.startTime = SDL_GetTicks();
-    menuState = 0;
+
     while (!menuState)
     {
         while (SDL_PollEvent(&engine.event))
@@ -334,13 +362,19 @@
                         break;
 
                     case SDLK_UP:
-                        if (menuChoice > 0)
-                            menuChoice--;
+                        if (menuIndex > 0)
+                            menuIndex--;
+                        else
+                        if (menuOffset > 0)
+                            menuOffset--;
                         break;
 
                     case SDLK_DOWN:
-                        if (menuChoice < nengineModeList - 1)
-                            menuChoice++;
+                        if (menuIndex < menuHeight - 1 && menuOffset + menuIndex < nengineModeList - 1)
+                            menuIndex++;
+                        else
+                        if (menuOffset + menuIndex < nengineModeList - 1)
+                            menuOffset++;
                         break;
                     
                     case SDLK_SPACE:
@@ -371,25 +405,32 @@
         
         // XXX/TODO: Some hardcoded bits here ...
         float t = engineGetTimeDT(&engine);
-        int entry;
-        dmScaledBlitSurface32to32TransparentGA(menuBarImage,
-            DM_VSETUP_MENU_XC,
-            DM_VSETUP_MENU_YC + (menuChoice * menuEntryHeight),
-            DM_VSETUP_MENU_WIDTH, menuEntryHeight + 2,
-            engine.screen,
-            200 + sin(t * 10.0) * 50);
+        int index, entry;
 
-        for (entry = 0; entry < nengineModeList && entry < menuHeight; entry++)
+        for (index = 0, entry = menuOffset; entry < nengineModeList && index < menuHeight; index++, entry++)
         {
             DMModeEntry *mode = &engineModeList[entry];
 
+            if (entry == menuOffset + menuIndex)
+            {
+                dmScaledBlitSurface32to32TransparentGA(menuBarImage,
+                    DM_VSETUP_MENU_XC,
+                    DM_VSETUP_MENU_YC + (index * menuEntryHeight),
+                    DM_VSETUP_MENU_WIDTH, menuEntryHeight + 2,
+                    engine.screen,
+                    200 + sin(t * 10.0) * 50);
+            }
+
             snprintf(menuStr, sizeof(menuStr),
-                "%4d X %4d", mode->w, mode->h);
+                "%4d X %4d  [%d:%d]",
+                mode->w, mode->h,
+                mode->aspect / 1000,
+                mode->aspect % 1000);
 
             dmDrawBMTextConst(
                 engine.screen, menuFont, DMD_TRANSPARENT,
                 DM_VSETUP_MENU_XC + 2,
-                DM_VSETUP_MENU_YC + 2 + entry * menuEntryHeight,
+                DM_VSETUP_MENU_YC + 2 + (index * menuEntryHeight),
                 menuStr);
         }