root/mde/mde.d

Revision 118:9ac208b53582, 3.9 kB (checked in by Diggory Hardy <diggory.hardy@gmail.com>, 2 weeks ago)

Unittest for mde.gui.widget.layout.

Line 
1 /* LICENSE BLOCK
2 Part of mde: a Modular D game-oriented Engine
3 Copyright © 2007-2008 Diggory Hardy
4
5 This program is free software: you can redistribute it and/or modify it under the terms
6 of the GNU General Public License as published by the Free Software Foundation, either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
15
16 /** Modular D Engine
17  *
18  * This module contains a minimal main() function. Practically, it is useful for running unittests
19  * and some other testing. It also serves as a basic example program.
20  */
21 module mde.mde;
22
23 import mde.imde;                        // this module's interface for external modules
24 import mde.setup.Init;                  // initialization
25 import mde.setup.Screen;                // Screen.draw()
26 import mde.events;                      // pollEvents()
27 import mde.lookup.Options;              // pollInterval option
28 import mde.scheduler.Scheduler;         // mainSchedule
29
30 import tango.core.Thread : Thread;  // Thread.sleep()
31 import tango.time.Clock;                // Clock.now()
32 import tango.util.log.Log : Log, Logger;
33 debug (mdeUnitTest) {                   // These modules contain unittests which wouldn't be run otherwise.
34     import mde.file.ssi;
35     import mde.file.mergetag.mdeUT;
36     import mde.lookup.Translation;
37     import mde.gui.widget.layout;
38 }
39
40 //BEGIN A simple drawable to print a message in the window.
41 /* This block of code is to draw the message you see on the screen. Most users of mde would be
42 better off using the gui drawable in gui.WidgetManager than this. */
43 import mde.font.font;
44 class SimpleDrawable : Screen.IDrawable {
45     this () {
46         msg = "Welcome to mde.\nThis executable is only for testing, and\nas such doesn't do anything interesting.";
47         debug msg ~= "\nRunning in debug mode.";
48         font = FontStyle.getDefault;    // get the default or fallback font
49     }
50     void sizeEvent (int,int) {};        // Don't care what the size is
51     void draw () {
52         font.textBlock (16,32, msg, textCache, Colour.WHITE);
53     }
54     char[] msg;
55     FontStyle font;
56     TextBlock textCache;
57 }
58 //END A simple drawable to print a message in the window.
59
60
61 int main(char[][] args)
62 {
63     Logger logger = Log.getLogger ("mde.mde");
64    
65     // If compiled with unittests, notify that they completed and exit:
66     debug (mdeUnitTest) {
67         logger.info ("Compiled unittests have completed; terminating.");
68         return 0;
69     }
70    
71     scope Init init = new Init(args);   // initialize mde
72    
73     // Note: must create the drawable after init, since it uses font (initialized in init).
74     Screen.addDrawable (new SimpleDrawable);    // a drawable to print a message.
75    
76     //BEGIN Main loop setup
77     /* Note: the main loop is currently controlled by the scheduler. This is not really ideal,
78      * since it provides no direct control of the order in which components are executed and does
79      * not allow running components simultaeneously with threads.
80      * Note: probably drawing should start at the beginning of the loop and glFlush()/swapBuffers
81      * be called at the end to optimise. */
82     mainSchedule.add (SCHEDULE.DRAW, &Screen.draw).request = true;      // Draw, per event and first frame only.
83     mainSchedule.add (mainSchedule.getNewID, &mde.events.pollEvents).frame = true;
84     //END Main loop setup
85    
86     double pollInterval = miscOpts.pollInterval();
87     while (run) {
88         mainSchedule.execute (Clock.now());
89        
90         Thread.sleep (pollInterval);    // sleep this many seconds
91     }
92    
93     return 0;       // cleanup handled by init's DTOR
94 }
Note: See TracBrowser for help on using the browser.