comparison mde/setup/Screen.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 5ee69b3ed9c9
children
comparison
equal deleted inserted replaced
136:4084f07f2c7a 137:9f035cd139c6
17 * 17 *
18 * Has an interface by which other code can hook in for drawing and resize notifications. */ 18 * Has an interface by which other code can hook in for drawing and resize notifications. */
19 module mde.setup.Screen; 19 module mde.setup.Screen;
20 20
21 import mde.setup.exception; 21 import mde.setup.exception;
22 import mde.lookup.Options; 22 import mde.content.AStringContent;
23 import imde = mde.imde; 23 import imde = mde.imde;
24 debug (drawGlyphCache) import mde.font.font; 24 debug (drawGlyphCache) import mde.font.font;
25 25
26 import tango.util.log.Log : Log, Logger; 26 import tango.util.log.Log : Log, Logger;
27 import tango.stdc.stringz; 27 import tango.stdc.stringz;
45 45
46 /** Called you guess when :-) */ 46 /** Called you guess when :-) */
47 void draw (); 47 void draw ();
48 } 48 }
49 49
50 /** All video options. */
51 class VideoOptions : Options {
52 mixin (impl!("bool fullscreen,hardware,resizable,noFrame; int screenW,screenH,windowW,windowH;"));
53 }
54
55 static: 50 static:
56 /** Init function to initialize SDL. */ 51 /** Init function to initialize SDL. */
57 StageState init () { // init func 52 StageState init () { // init func
58 // Initialise SDL 53 // Initialise SDL
59 debug (SDLCalls) logger.trace ("Calling SDL_Init (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK)"); 54 debug (SDLCalls) logger.trace ("Calling SDL_Init (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK)");
75 /** Init function to set up a window with OpenGL support. */ 70 /** Init function to set up a window with OpenGL support. */
76 StageState initWindow () { 71 StageState initWindow () {
77 //BEGIN Create window and initialize OpenGL 72 //BEGIN Create window and initialize OpenGL
78 // Window creation flags and size 73 // Window creation flags and size
79 flags = SDL_OPENGL; 74 flags = SDL_OPENGL;
80 if (videoOpts.hardware()) flags |= SDL_HWSURFACE | SDL_DOUBLEBUF; 75 if (hardware()) flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
81 else flags |= SDL_SWSURFACE; 76 else flags |= SDL_SWSURFACE;
82 int w, h; 77 int w, h;
83 if (videoOpts.fullscreen()) { 78 if (fullscreen()) {
84 flags |= SDL_FULLSCREEN; 79 flags |= SDL_FULLSCREEN;
85 w = videoOpts.screenW(); 80 w = screenW();
86 h = videoOpts.screenH(); 81 h = screenH();
87 } 82 }
88 else { 83 else {
89 if (videoOpts.resizable()) flags |= SDL_RESIZABLE; 84 if (resizable()) flags |= SDL_RESIZABLE;
90 if (videoOpts.noFrame()) flags |= SDL_NOFRAME; 85 if (noFrame()) flags |= SDL_NOFRAME;
91 w = videoOpts.windowW(); 86 w = windowW();
92 h = videoOpts.windowH(); 87 h = windowH();
93 } 88 }
94 89
95 // OpenGL attributes 90 // OpenGL attributes
96 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); 91 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
97 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); 92 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
154 149
155 150
156 /** Called when a resize event occurs (when the window manager resizes the window). */ 151 /** Called when a resize event occurs (when the window manager resizes the window). */
157 void resizeEvent (int w, int h) { 152 void resizeEvent (int w, int h) {
158 // Save new size to config 153 // Save new size to config
159 if (videoOpts.fullscreen()) { // probably resizeEvent only called when not fullscreen 154 if (fullscreen()) { // probably resizeEvent only called when not fullscreen
160 videoOpts.screenW = w; 155 screenW = w;
161 videoOpts.screenH = h; 156 screenH = h;
162 } else { 157 } else {
163 videoOpts.windowW = w; 158 windowW = w;
164 videoOpts.windowH = h; 159 windowH = h;
165 } 160 }
166 161
167 if (setWindow (w,h)) 162 if (setWindow (w,h))
168 imde.run = false; 163 imde.run = false;
169 } 164 }
262 } 257 }
263 258
264 static this() { 259 static this() {
265 logger = Log.getLogger ("mde.setup.Screen"); 260 logger = Log.getLogger ("mde.setup.Screen");
266 261
267 videoOpts = new VideoOptions ("VideoOptions"); 262 fullscreen = new BoolContent ("Screen.fullscreen");
263 hardware = new BoolContent ("Screen.hardware");
264 resizable = new BoolContent ("Screen.resizable");
265 noFrame = new BoolContent ("Screen.noFrame");
266 screenW = new IntContent ("Screen.screenW");
267 screenH = new IntContent ("Screen.screenH");
268 windowW = new IntContent ("Screen.windowW");
269 windowH = new IntContent ("Screen.windowH");
268 } 270 }
269 271
270 // DATA: 272 // DATA:
271 private: 273 private:
272 uint flags = 0; 274 uint flags = 0;
273 IDrawable[] drawables; 275 IDrawable[] drawables;
274 Logger logger; 276 Logger logger;
275 VideoOptions videoOpts; 277
278 // Option values:
279 BoolContent fullscreen, hardware, resizable, noFrame;
280 IntContent screenW,screenH, windowW,windowH;
276 } 281 }