diff dmsimple.c @ 593:17bf1704d42e

More work on video setup.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 12 Apr 2013 05:56:56 +0300
parents f165883c2ea6
children 695a623eed63
line wrap: on
line diff
--- a/dmsimple.c	Fri Apr 12 05:32:37 2013 +0300
+++ b/dmsimple.c	Fri Apr 12 05:56:56 2013 +0300
@@ -1,6 +1,8 @@
 #include <SDL.h>
 #include "dmengine.h"
 #include "dmargs.h"
+#include "dmtext.h"
+#include "dmimage.h"
 #include "setupfont.h"
 #include "setupimage.h"
 
@@ -150,17 +152,16 @@
         return FALSE;
     }
 
-    SDL_ShowCursor(SDL_DISABLE);
     SDL_WM_SetCaption(dmProgDesc, dmProgName);
 
     return TRUE;
 }
 
 
-static BOOL engineInitializeVideo(int width, int height, int depth, Uint32 flags)
+static BOOL engineInitializeVideo()
 {
-    return engineInitializeVideo(engine.optScrWidth, engine.optScrHeight,
-        engine.optScrDepth, engine.optVFlags);
+    return engineGenInitializeVideo(engine.optVidWidth, engine.optVidHeight,
+        engine.optVidDepth, engine.optVFlags);
 }
 
 
@@ -169,14 +170,14 @@
     DMBitmapFont *font = NULL;
     DMResource *file = NULL;
     SDL_Surface *menuBgImage = NULL;
-    int menuState = -1, nmenuList;
+    int result, menuState = -1, nmenuList, menuChoice = 0;
     DMScaledBlitFunc menuBgBlit;
 
     // Compute a list of valid modes
 
 
     // Open video temporarily
-    if (!engineGenInitializeVideo(DM_VIDEO_SETUP_WIDTH, DM_VIDEO_SETUP_HEIGHT, 32, SDL_SWSURFACE | SDL_DOUBLEBUF))
+    if (!engineGenInitializeVideo(DM_VSETUP_WIDTH, DM_VSETUP_HEIGHT, 32, SDL_SWSURFACE | SDL_DOUBLEBUF))
         goto out;
 
     // Fetch and decompress setup image, try regular resources first
@@ -184,7 +185,7 @@
     if (file == NULL)
         file = dmf_create_memio(NULL, "SetupImage", engineSetupImage, sizeof(engineSetupImage));
 
-    menuBgImage = dmLoadImageBitmapFont(file);
+    menuBgImage = dmLoadImage(file);
     dmf_close(file);
     if (menuBgImage == NULL)
     {
@@ -193,13 +194,13 @@
         goto out;
     }
     
-    if (menuBgImage->w != DM_VIDEO_SETUP_WIDTH ||
-        menuBgImage->h != DM_VIDEO_SETUP_HEIGHT)
+    if (menuBgImage->w != DM_VSETUP_WIDTH ||
+        menuBgImage->h != DM_VSETUP_HEIGHT)
     {
         dmError("Setup screen background image does not match "
             "required dimensions (%dx%d vs %dx%d)\n",
             menuBgImage->w, menuBgImage->h,
-            DM_VIDEO_SETUP_WIDTH, DM_VIDEO_SETUP_HEIGHT);
+            DM_VSETUP_WIDTH, DM_VSETUP_HEIGHT);
         goto out;
     }
 
@@ -218,9 +219,10 @@
         goto out;
     }
     
-    menuBgBlit = dmGetScaledBlitFunc(menuBgImage, engine.screen->format, DMD_NONE);
+    menuBgBlit = dmGetScaledBlitFunc(menuBgImage->format, engine.screen->format, DMD_NONE);
 
     // Enter the main loop of the menu
+    menuState = 0;
     while (!menuState)
     {
         while (SDL_PollEvent(&engine.event))
@@ -284,6 +286,15 @@
 }
 
 
+int engineGetVideoAspect(int width, int height)
+{
+    if (width > 0 && height > 0)
+        return (width * 1000) / height;
+    else
+        return 1;
+}
+
+
 int main(int argc, char *argv[])
 {
     int err;
@@ -335,8 +346,14 @@
 
 
     // Present video mode selector
+    if (engine.optVidAspect <= 0)
+        engine.optVidAspect = engineGetVideoAspect(engine.optVidWidth, engine.optVidHeight);
+
     if (engine.optVidSetup)
-        engineVideoSetup();
+    {
+        if ((err = engineVideoSetup()) <= 0)
+            goto error_exit;
+    }
 
     // Initialize audio parts
     if (engine.optAfmt.freq == 0 && engine.optAfmt.channels == 0)
@@ -405,6 +422,9 @@
         goto error_exit;
     }
 
+    // Hide cursor
+    SDL_ShowCursor(SDL_DISABLE);
+
     // Load resources
     dmPrint(1, "Loading resources, please wait...\n");
     if ((err = engineLoadResources()) != DMERR_OK)