comparison 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
comparison
equal deleted inserted replaced
30:467c74d4804d 31:baa87e68d7dc
21 * wrapped in another function before being run in a thread (i.e. run indirectly). Functions fail 21 * wrapped in another function before being run in a thread (i.e. run indirectly). Functions fail
22 * either by throwing an exception or by returning a boolean. Functions may take parameters, e.g. 22 * either by throwing an exception or by returning a boolean. Functions may take parameters, e.g.
23 * "out cleanupFunc[]". */ 23 * "out cleanupFunc[]". */
24 module mde.scheduler.InitFunctions; 24 module mde.scheduler.InitFunctions;
25 25
26 /+ unused
26 import tango.util.log.Log : Log, Logger; 27 import tango.util.log.Log : Log, Logger;
27 static this() { 28 static this() {
28 logger = Log.getLogger ("mde.scheduler.InitFunctions"); 29 logger = Log.getLogger ("mde.scheduler.InitFunctions");
29 } 30 }+/
30 31
31 void setInitFailure () { /// Call to indicate failure in an init function 32 void setInitFailure () { /// Call to indicate failure in an init function
32 initFailure = true; 33 initFailure = true;
33 } 34 }
34 35
35 /** Represents all functions to be called for a particular init stage. */ 36 /** Represents all functions to be called for a particular init stage. */
36 struct InitStage 37 struct InitStage
37 { 38 {
38 struct InitFunction { 39 struct InitFunction {
39 void function() func; // the actual function 40 void delegate() func; // the actual function
40 char[] name; // it's name; 41 char[] name; // it's name;
41 } 42 }
42 43
43 /** Add a function to be called during this init stage. 44 /** Add a function to be called during this init stage.
44 * 45 *
45 * Called in order added when not threaded (reverse order for cleanup). 46 * Called in order added when not threaded (reverse order for cleanup).
46 * 47 *
47 * Exceptions should never be thrown, since each function may run as a thread, and catching 48 * Exceptions should never be thrown, since each function may run as a thread, and catching
48 * thread exceptions is not guaranteed to work. Log a message, call setFailure() and return 49 * thread exceptions is not guaranteed to work. Log a message, call setFailure() and return
49 * instead. */ 50 * instead. */
50 void addFunc (void function() f, char[] name) { 51 void addFunc (void delegate() f, char[] name) {
51 InitFunction s; 52 InitFunction s;
52 s.func = f; 53 s.func = f;
54 s.name = name;
55 funcs ~= s;
56 }
57 void addFunc (void function() f, char[] name) { /// ditto
58 InitFunction s;
59 s.func.funcptr = f;
53 s.name = name; 60 s.name = name;
54 funcs ~= s; 61 funcs ~= s;
55 } 62 }
56 63
57 InitFunction[] funcs = []; 64 InitFunction[] funcs = [];
62 69
63 package: 70 package:
64 bool initFailure = false; // set on failure (throwing through threads isn't a good idea) 71 bool initFailure = false; // set on failure (throwing through threads isn't a good idea)
65 72
66 private: 73 private:
67 Logger logger; 74 //Logger logger;
68 /+ I keep changing my mind about wrapping all init functions:
69 const LOG_MSG = "Init function ";
70 const TRACE_START = " - running";
71 const TRACE_END = " - completed";
72 const FAIL_MSG = " - failed: ";
73 // Template to call function, catching exceptions:
74 void initInput(alias Func, char[] name) () {
75 try {
76 debug logger.trace (LOG_MSG ~ name ~ TRACE_START);
77 Func();
78 debug logger.trace (LOG_MSG ~ name ~ TRACE_END);
79 } catch (Exception e) {
80 logger.fatal (LOG_MSG ~ name ~ FAIL_MSG ~ e.msg);
81 initFailure = true;
82 }
83 }
84 +/