diff mde/options.d @ 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
line wrap: on
line diff
--- 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));
     }
 }