annotate mde/scheduler/InitFunctions.d @ 31:baa87e68d7dc

GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup. Removed some circular dependencies which slipped in. As a result, the OpenGL code got separated into different files. Enabled widgets to recieve events. New IParentWidget interface allowing widgets to interact with their parents. New Widget base class. New WidgetDecoration class. New ButtonWidget class responding to events (in a basic way). committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 29 Apr 2008 18:10:58 +0100
parents 467c74d4804d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
1 /* LICENSE BLOCK
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
2 Part of mde: a Modular D game-oriented Engine
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
4
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
7 version 2 of the License, or (at your option) any later version.
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
8
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
11 See the GNU General Public License for more details.
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
12
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
13 You should have received a copy of the GNU General Public License
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
15
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** This module is responsible for calling all init functions.
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 *
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
18 * It is also responsible for setting up all scheduled functions for now.
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
19
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
20 * Idea: change import direction so this module adds all init functions. All init functions are
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
21 * wrapped in another function before being run in a thread (i.e. run indirectly). Functions fail
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
22 * either by throwing an exception or by returning a boolean. Functions may take parameters, e.g.
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
23 * "out cleanupFunc[]". */
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 module mde.scheduler.InitFunctions;
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25
31
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 30
diff changeset
26 /+ unused
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27 import tango.util.log.Log : Log, Logger;
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28 static this() {
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29 logger = Log.getLogger ("mde.scheduler.InitFunctions");
31
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 30
diff changeset
30 }+/
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 27
diff changeset
32 void setInitFailure () { /// Call to indicate failure in an init function
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 initFailure = true;
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34 }
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 /** Represents all functions to be called for a particular init stage. */
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 struct InitStage
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 {
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 27
diff changeset
39 struct InitFunction {
31
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 30
diff changeset
40 void delegate() func; // the actual function
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 27
diff changeset
41 char[] name; // it's name;
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 27
diff changeset
42 }
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 /** Add a function to be called during this init stage.
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 *
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 * Called in order added when not threaded (reverse order for cleanup).
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47 *
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 * Exceptions should never be thrown, since each function may run as a thread, and catching
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 * thread exceptions is not guaranteed to work. Log a message, call setFailure() and return
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 * instead. */
31
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 30
diff changeset
51 void addFunc (void delegate() f, char[] name) {
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 27
diff changeset
52 InitFunction s;
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 27
diff changeset
53 s.func = f;
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 27
diff changeset
54 s.name = name;
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 27
diff changeset
55 funcs ~= s;
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 }
31
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 30
diff changeset
57 void addFunc (void function() f, char[] name) { /// ditto
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 30
diff changeset
58 InitFunction s;
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 30
diff changeset
59 s.func.funcptr = f;
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 30
diff changeset
60 s.name = name;
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 30
diff changeset
61 funcs ~= s;
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 30
diff changeset
62 }
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 InitFunction[] funcs = [];
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65 }
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 InitStage init; // all functions called during init (all should be thread-safe)
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68 InitStage cleanup; // all functions called during cleanup (all should be thread-safe)
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 27
diff changeset
70 package:
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71 bool initFailure = false; // set on failure (throwing through threads isn't a good idea)
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
73 private:
31
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 30
diff changeset
74 //Logger logger;