Mercurial > hg > dmlib
changeset 593:17bf1704d42e
More work on video setup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 12 Apr 2013 05:56:56 +0300 |
parents | 6711f50f0759 |
children | 935b91d0f508 695a623eed63 |
files | dmengine.h dmsimple.c |
diffstat | 2 files changed, 48 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/dmengine.h Fri Apr 12 05:32:37 2013 +0300 +++ b/dmengine.h Fri Apr 12 05:56:56 2013 +0300 @@ -19,6 +19,16 @@ extern "C" { #endif +// Video setup screen / window size +#define DM_VSETUP_WIDTH 640 +#define DM_VSETUP_HEIGHT 480 + +// 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 DT_MAGIC_ID "SDMETLNE" #define DT_MAX_EFFECT_PARAMS 16 @@ -212,8 +222,9 @@ SDL_Event event; SDL_AudioSpec optAfmt; - int optScrWidth, optScrHeight, - optScrDepth, optVFlags, optScrAspect; + int optVidWidth, optVidHeight, + optVidDepth, optVFlags, + optVidAspect, optVidSetup; int optResFlags; char *optDataPath, *optPackFilename; @@ -313,6 +324,9 @@ int engineGetTick(DMEngineData *eng); float engineGetTimeDT(DMEngineData *eng); +int engineGetVideoAspect(int width, int height); + + // Implemented in actual demo code int demoPreInit(DMEngineData *eng);
--- 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)