changeset 22:249eb6620685

Changes to Options, particularly regarding window sizes. Window sizes for fullscreen and windowed modes are now independant. Window resizes by the WM are now persistant. Options class contents are now generated by templates. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 25 Mar 2008 12:24:04 +0000
parents a60cbb7359dd
children 47478557428d
files codeDoc/jobs.txt data/L10n/OptionsMisc.mtt data/L10n/OptionsVideo.mtt mde/SDL.d mde/events.d mde/options.d
diffstat 6 files changed, 104 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/codeDoc/jobs.txt	Mon Mar 24 17:53:28 2008 +0000
+++ b/codeDoc/jobs.txt	Tue Mar 25 12:24:04 2008 +0000
@@ -6,7 +6,6 @@
 
 
 To do:
-*   SDL window settings from options. Design to be resetable.
 Also see todo.txt.
 *   Windows building/compatibility (currently partial)
 *   gdc building/compatibility (wait for tango 0.99.5 release?)
@@ -41,4 +40,6 @@
 
 
 Done (for git log message):
-Window settings now come from options.
\ No newline at end of file
+Window sizes for fullscreen and windowed modes are now independant.
+Window resizes by the WM are now persistant.
+Options class contents are now generated by templates.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/L10n/OptionsMisc.mtt	Tue Mar 25 12:24:04 2008 +0000
@@ -0,0 +1,5 @@
+{MT01}
+{en-GB}
+<entry|useThreads=["Use threads","Global option for threading in mde."]>
+<entry|logLevel=["Logging level","Controls which messages are logged, from 0=trace to 6=none (default: 1=info)."]>
+<entry|=["Localisation","Specifies the language to use."]>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/L10n/OptionsVideo.mtt	Tue Mar 25 12:24:04 2008 +0000
@@ -0,0 +1,10 @@
+{MT01}
+{en-GB}
+<entry|fullscreen=["Fullscreen","If true use the whole screen, if false use a window."]>
+<entry|hardware=["Hardware","Create the video surface in hardware or software memory."]>
+<entry|resizable=["Resizable","In windowed mode, allow the window to be resized by the window manager."]>
+<entry|noFrame=["No frame","In windowed mode, don't draw a window border."]>
+<entry|screenW=["Screen width","Horizontal resolution (fullscreen mode)."]>
+<entry|screenH=["Screen height","Vertical resolution (fullscreen mode)."]>
+<entry|windowW=["Window width","Horizontal size (windowed mode)."]>
+<entry|windowH=["Window height","Vertical size (windowed mode)."]>
--- a/mde/SDL.d	Mon Mar 24 17:53:28 2008 +0000
+++ b/mde/SDL.d	Tue Mar 25 12:24:04 2008 +0000
@@ -36,6 +36,8 @@
     init4.addFunc (&setupWindow);
 }
 
+private uint flags = 0;
+
 void initSdlAndGl() {   // init2 func
     logger.trace ("init2: initSdlAndGl() started");
     
@@ -78,8 +80,7 @@
     // Window creation flags
     /* NOTE: I'm getting an API mismatch error from the nvidia driver when using OpenGL,
     * thus I've temporarily disabled it. */
-    version (MDE_OPENGL) uint flags = SDL_OPENGL;
-    else uint flags = 0;
+    version (MDE_OPENGL) flags = SDL_OPENGL;
     if (Options.video.fullscreen) flags |= SDL_FULLSCREEN;
     else {
         if (Options.video.resizable) flags |= SDL_RESIZABLE;
@@ -98,7 +99,13 @@
     }
     
     // Open a window
-    if (SDL_SetVideoMode (Options.video.width, Options.video.height, 32, flags) is null) {
+    SDL_Surface* surface;
+    if (Options.video.fullscreen) {
+        surface = SDL_SetVideoMode (Options.video.screenW, Options.video.screenH, 32, flags);
+    } else {
+        surface = SDL_SetVideoMode (Options.video.windowW, Options.video.windowH, 32, flags);
+    }
+    if (surface is null) {
         logger.fatal ("Unable to set video mode:");
         char* msg = SDL_GetError ();
         logger.fatal (msg ? fromStringz(msg) : "no reason available");
@@ -114,6 +121,20 @@
     logger.trace ("init4: setupWindow() finished");
 }
 
+void resizeWindow (int w, int h) {
+    if (Options.video.fullscreen) {
+        Options.video.screenW = w;
+        Options.video.screenH = h;
+    } else {
+        Options.video.windowW = w;
+        Options.video.windowH = h;
+    }
+    
+    /+ Does SDL_SetVideoMode need to be called?
+    setupWindow ();
+    +/
+}
+
 void cleanupSDL () {    // cleanup2 func
     logger.trace ("cleanup2: cleanupSDL() started");
     SDL_Quit();
--- a/mde/events.d	Mon Mar 24 17:53:28 2008 +0000
+++ b/mde/events.d	Tue Mar 25 12:24:04 2008 +0000
@@ -20,6 +20,7 @@
 import mde.scheduler.runTime;
 
 import global = mde.global;
+static import mde.SDL;
 
 import mde.input.input;
 import mde.input.exception;
@@ -58,6 +59,9 @@
                 logger.info ("Quit requested");
                 global.run = false;
                 break;
+            case SDL_VIDEORESIZE:
+                mde.SDL.resizeWindow (event.resize.w, event.resize.h);
+                break;
             default:
                 try {
                     global.input (event);
--- a/mde/options.d	Mon Mar 24 17:53:28 2008 +0000
+++ b/mde/options.d	Tue Mar 25 12:24:04 2008 +0000
@@ -133,32 +133,77 @@
         logger = Log.getLogger ("mde.options");
     }
     //END Static
+    
+    //BEGIN Templates
+    template store(A...) {
+        alias A a;
+    }
+    template decRecurse(char[] A, B...) {
+        static if (B.length) const char[] decRecurse = A ~ ", " ~ decRecurse!(B);
+        else                 const char[] decRecurse = A;
+    }
+    template decBool(A...) {
+        const char[] decBool = "bool " ~ decRecurse!(A) ~ ";\n";
+    }
+    template decCharA(A...) {
+        const char[] decCharA = "char[] " ~ decRecurse!(A) ~ ";\n";
+    }
+    template decInt(A...) {
+        const char[] decInt = "int " ~ decRecurse!(A) ~ ";\n";
+    }
+    template aaRecurse(char[] A, B...) {
+        static if (B.length) const char[] aaRecurse = "\""~A~"\"[]:&"~A ~ ", " ~ aaRecurse!(B);
+        else                 const char[] aaRecurse = "\""~A~"\"[]:&"~A;
+    }
+    template aaBool(A...) {
+        const char[] aaBool = "optsBool = [" ~ aaRecurse!(A) ~ "];\n";
+    }
+    template aaInt(A...) {
+        const char[] aaInt = "optsInt = [" ~ aaRecurse!(A) ~ "];\n";
+    }
+    template aaCharA(A...) {
+        const char[] aaCharA = "optsCharA = [" ~ aaRecurse!(A) ~ "];\n";
+    }
+    //END Templates
 }
 
+/* NOTE: These Options classes use templates to ease inserting contents.
+*
+* Each entry has an I18nTranslation entry; see data/L10n/ClassName.mtt for descriptions.
+*
+* To create a new class, copy and paste, and update Options.
+*/
+
 /** A home for all miscellaneous options, at least for now. */
 class OptionsMisc : Options {
-    bool useThreads;    // set 0 to disable threading
-    char[] L10n;        // locale, e.g. en-GB
+    alias store!("useThreads") BOOL;
+    alias store!("logLevel") INT;
+    alias store!("L10n") CHARA;
     
-    int logLevel;       // tango logger level
+    mixin (decBool!(BOOL.a));
+    mixin (decInt!(INT.a));
+    mixin (decCharA!(CHARA.a));
     
     this () {
-        optsBool    = ["useThreads":&useThreads];
-        optsCharA   = ["L10n":&L10n];
-        optsInt     = ["logLevel":&logLevel];
+        mixin (aaBool!(BOOL.a));
+        mixin (aaInt!(INT.a));
+        mixin (aaCharA!(CHARA.a));
     }
 }
 
 /** All video options. */
 class OptionsVideo : Options {
-    int width, height;  // screen/window dimensions
-    bool fullscreen;
-    bool resizable;     // when not fullscreen, window can be resized
-    bool noFrame;       // when not fullscreen, don't draw the window decorations
-    bool hardware;      // use a hardware surface. Relevant with OpenGL?
+    alias store!("fullscreen","hardware","resizable","noFrame") BOOL;
+    alias store!("screenW","screenH","windowW","windowH") INT;
+    //alias store!() CHARA;
+    
+    mixin (decBool!(BOOL.a));
+    mixin (decInt!(INT.a));
+    //mixin (decCharA!(CHARA.a));
     
     this () {
-        optsBool    = ["fullscreen"[]:&fullscreen, "hardware":&hardware, "noFrame":&noFrame, "resizable":&resizable];
-        optsInt     = ["height"[]:&height, "width":&width];
+        mixin (aaBool!(BOOL.a));
+        mixin (aaInt!(INT.a));
+        //mixin (aaCharA!(CHARA.a));
     }
 }