diff mde/font/FontTexture.d @ 137:9f035cd139c6

BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed. Content restrutured a lot: New IContent module, Content module includes more functionality. New ContentLoader module to manage content loading/saving/translation. Translation module moved to content dir and cut down to reflect current usage. File format unchanged except renames: FontOptions -> Font, VideoOptions -> Screen. Font render mode and LCD filter options are now enums. GUI loading needs to create content (and set type for enums), but doesn't save/load value. Some setup of mainSchedule moved to mde.mainLoop. Content callbacks are called on content change now. ContentLists are set up implicitly from content symbols. Not as fast but much easier! Bug-fix in the new MTTagReader. Renamed MT *Reader maker functions to avoid confusion in paths.d. New mde.setup.logger module to allow logger setup before any other module's static this().
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 07 Feb 2009 12:46:03 +0000
parents ee209602770d
children e45226d3deae
line wrap: on
line diff
--- a/mde/font/FontTexture.d	Sun Feb 01 12:36:21 2009 +0000
+++ b/mde/font/FontTexture.d	Sat Feb 07 12:46:03 2009 +0000
@@ -25,7 +25,7 @@
 module mde.font.FontTexture;
 
 import mde.types.Colour;
-import mde.lookup.Options;
+import mde.content.AStringContent;
 import mde.font.exception;
 
 import derelict.freetype.ft;
@@ -240,8 +240,7 @@
         auto gi = FT_Get_Char_Index (face, chr);
         auto g = face.glyph;
         
-        // Use renderMode from options, masking bits which are allowable:
-        if (FT_Load_Glyph (face, gi, FT_LOAD_RENDER | (fontOpts.renderMode() & 0xF0000)))
+        if (FT_Load_Glyph (face, gi, FT_LOAD_RENDER | fontOpts.modeFlag))
             throw new fontGlyphException ("Unable to render glyph");
         
         auto b = g.bitmap;
@@ -292,7 +291,7 @@
                 buffer[i*b.width + j + 2] = b.buffer[i*b.pitch + j + 2];
             }
             
-            format = (fontOpts.renderMode() & RENDER_LCD_BGR) ? GL_BGR : GL_RGB;
+            format = (fontOpts.mode() >= 4) ? GL_BGR : GL_RGB;
         } else if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD_V) {
             // NOTE: Notes above apply. But in this case converting the buffers seems essential.
             buffer = new ubyte[b.width*b.rows];
@@ -304,7 +303,7 @@
                 buffer[i/3*b.width*3 + 3*j + i%3] = b.buffer[i*b.pitch + j];
             }
             
-            format = (fontOpts.renderMode() & RENDER_LCD_BGR) ? GL_BGR : GL_RGB;
+            format = (fontOpts.mode() >= 4) ? GL_BGR : GL_RGB;
         } else
             throw new fontGlyphException ("Unsupported freetype bitmap format");
         
@@ -445,26 +444,33 @@
     int nextYPos = 0;	// y position for next created line (0 for first line)
 }
 
-// this bit of renderMode, if set, means read glyph as BGR not RGB when using LCD rendering
-enum { RENDER_LCD_BGR = 1 << 30 }
-FontOptions fontOpts;
-class FontOptions : Options {
-    /* renderMode have one of the following values, possibly with bit 31 set (see RENDER_LCD_BGR):
-     * FT_LOAD_TARGET_NORMAL    (0x00000)
-     * FT_LOAD_TARGET_LIGHT     (0x10000)
-     * FT_LOAD_TARGET_LCD       (0x30000)
-     * FT_LOAD_TARGET_LCD_V     (0x40000)
-     * The mode FT_LOAD_TARGET_MONO (0x20000) is unsupported.
-     *
-     * lcdFilter should come from enum FT_LcdFilter:
-     * FT_LCD_FILTER_NONE (0), FT_LCD_FILTER_DEFAULT (1), FT_LCD_FILTER_LIGHT (2) */
-    mixin (impl!("int renderMode, lcdFilter, defaultSize; char[] defaultFont;"));
-    
-    void validate() {
-    }
+struct fontOpts {
+static:
+    EnumContent mode;
+    int modeFlag;
+    /* lcdFilter should come from enum FT_LcdFilter:
+    * FT_LCD_FILTER_NONE (0), FT_LCD_FILTER_DEFAULT (1), FT_LCD_FILTER_LIGHT (2) */
+    EnumContent lcdFilter;
+    IntContent defaultSize;
+    StringContent defaultFont;
     
     static this() {
-        fontOpts = new FontOptions ("FontOptions");
+        mode = new EnumContent ("Font.mode", ["normal"[],"light","lcd","lcd_v","lcd_bgr","lcd_bgr_v"]);
+        lcdFilter = new EnumContent ("Font.lcdFilter", ["none"[],"default","light"]);
+        defaultSize = new IntContent ("Font.defaultSize");
+        defaultFont = new StringContent ("Font.defaultFont");
+        mode.addCallback (delegate void(Content) {
+           /* modeFlag should have one of the following values:
+            * FT_LOAD_TARGET_NORMAL    (0x00000)
+            * FT_LOAD_TARGET_LIGHT     (0x10000)
+            * FT_LOAD_TARGET_LCD       (0x30000)
+            * FT_LOAD_TARGET_LCD_V     (0x40000)
+            * The mode FT_LOAD_TARGET_MONO (0x20000) is unsupported. */
+            modeFlag = fontOpts.mode();
+            if (modeFlag == 2 || modeFlag == 4) modeFlag = 0x30000;
+            else if (modeFlag == 3 || modeFlag == 5) modeFlag = 0x40000;
+            else modeFlag <<= 16;
+        });
     }
 }