PageRenderTime 23ms CodeModel.GetById 2ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/core/definitions.d

http://github.com/wilkie/djehuty
D | 324 lines | 207 code | 60 blank | 57 comment | 8 complexity | 31dc8c5999fe09c770316ea744ec56fc MD5 | raw file
  1/*
  2 * definitions.d
  3 *
  4 * This file contains the core definitions, structures, and datatypes
  5 * taking into account some platform-specific properties.
  6 *
  7 * Author: Dave Wilkinson
  8 *
  9 */
 10
 11module core.definitions;
 12
 13import Platform = platform.definitions;
 14
 15// String
 16version(D_Version2) {
 17	template _D2_Support_string() {
 18		version(D_Version2) {
 19			const char[] _D2_Support_string = `alias invariant(char)[] string;`;
 20		}
 21		else {
 22			const char[] _D2_Support_string = `alias char[] string;`;
 23		}
 24	}
 25	template _D2_Support_wstring() {
 26		version(D_Version2) {
 27			const char[] _D2_Support_wstring = `alias invariant(wchar)[] wstring;`;
 28		}
 29		else {
 30			const char[] _D2_Support_wstring = `alias wchar[] wstring;`;
 31		}
 32	}
 33	template _D2_Support_dstring() {
 34		version(D_Version2) {
 35			const char[] _D2_Support_dstring = `alias invariant(dchar)[] dstring;`;
 36		}
 37		else {
 38			const char[] _D2_Support_dstring = `alias dchar[] dstring;`;
 39		}
 40	}
 41
 42	mixin(_D2_Support_string!());
 43	mixin(_D2_Support_wstring!());
 44	mixin(_D2_Support_dstring!());
 45}
 46else {
 47	version(Tango) {
 48		alias char[] string;
 49		alias wchar[] wstring;
 50		alias dchar[] dstring;
 51	}
 52}
 53
 54// Section: Types
 55
 56// Description: This struct stores an x and y and is used to specify a point.
 57struct Coord {
 58
 59	// Description: The x coordinate.
 60	int x;
 61
 62	// Description: The y coordinate.
 63	int y;
 64
 65}
 66
 67// Description: This struct stores an x any y, or a width and height, useful for some measurements.
 68struct Size {
 69
 70	// Description: The width of the measurement.
 71	uint x;
 72
 73	// Description: The height of the measurement.
 74	uint y;
 75}
 76
 77
 78// Description: This struct stores a description of a rectangle.
 79struct Rect {
 80
 81	// Description: The x point of the top-left of the rectangle.
 82	uint left;
 83
 84	// Description: The y point of the top-left of the rectangle.
 85	uint top;
 86
 87	// Description: The y point of the bottom-right of the rectangle.
 88	uint bottom;
 89
 90	// Description: The x point of the bottom-right of the rectangle.
 91	uint right;
 92	
 93	// Description: This function will test whether another rectangle intersects (overlaps) this one.
 94	// test: A rectangle to test.
 95	// Returns: Will return true when the rectangle given by test overlaps.
 96	bool intersects(Rect test) {
 97		return !(left > test.right || right < test.left || top > test.bottom || bottom < test.top);
 98	}
 99}
100
101// Section: Enums
102
103// Window Styles
104
105// Description: This enum gives all possible window styles.  Use the SetStyle() function within the BaseWindow class to set the style of the window to this value.
106enum WindowStyle : int {
107	// Description: Represents a non-sizable window.
108	Fixed,
109
110	// Description: Represents a common sizable window.
111	Sizable,
112
113	// Description: Represents a borderless window.
114	Popup,
115}
116
117// Window Positions
118enum WindowPosition : int {
119	// Description: Will be placed according to the window manager.
120	Default,
121
122	// Description: Will be placed in the center of the default monitor.
123	Center,
124
125	// Description: Will be placed with the Window's x and y properties.
126	User,
127}
128
129// Window States
130
131// Description: This enum gives all possible window states.  Use the SetState() function within the BaseWindow class to set the state of the window to this value.
132enum WindowState : int {
133	// Description: This would be the normal view of the window.  Sometimes refered to as the restored view.
134	Normal,
135	// Description: This state will cause the window to be minimized.  Sometimes refered to as shrinking, or even rarely iconizing.
136	Minimized,
137	// Description: This state will cause the window to be maximized, and this would mean the window would get as big as it can within the constraints of the desktop environment.
138	Maximized,
139	// Description: This state will cause the window to take up the entire screen, essentially the width and height would be that of the current screen resolution on the current display.
140	Fullscreen
141}
142
143// System Colors
144
145// Description: This enum gives all possible system colors to query.
146enum SystemColor : ubyte {
147	// Description: This would be the normal window background style.  Give this to the constructor, and it will produce a normal looking window.
148	Window = 0,
149}
150
151
152// Section: Types
153
154
155// Mouse structure
156//   from the Window class
157
158// Description: This struct gives the state of the mouse input for a window.
159struct Mouse {
160	// Description: The x coordinate in coordination to the client area of the window of the mouse cursor.
161	int x;
162	// Description: The y coordinate in coordination to the client area of the window of the mouse cursor.
163	int y;
164
165	// Description: The number of clicks the user has done in a row.  1 is a single click.  2 is a double click, and so on.  You should use the mod operator to use this property properly.
166	int clicks;
167
168	// Description: Whether or not the primary button is down.
169	bool leftDown;
170	// Description: Whether or not the secondary button is down.
171	bool rightDown;
172	// Description: Whether or not the tertiary button is down.
173	bool middleDown;
174}
175
176struct Key {
177	uint code;
178
179	bool ctrl;
180	bool alt;
181	bool shift;
182
183	const uint Backspace = Platform.KeyBackspace;
184	const uint Tab = Platform.KeyTab;
185
186	const uint Return = Platform.KeyReturn;
187	const uint Pause = Platform.KeyPause;
188	const uint Escape = Platform.KeyEscape;
189	const uint Space = Platform.KeySpace;
190
191	const uint PageUp = Platform.KeyPageUp;
192	const uint PageDown = Platform.KeyPageDown;
193
194	const uint End = Platform.KeyEnd;
195	const uint Home = Platform.KeyHome;
196
197	const uint Left = Platform.KeyArrowLeft;
198	const uint Right = Platform.KeyArrowRight;
199	const uint Up = Platform.KeyArrowUp;
200	const uint Down = Platform.KeyArrowDown;
201
202	const uint Insert = Platform.KeyInsert;
203	const uint Delete = Platform.KeyDelete;
204
205	const uint NumLock = Platform.KeyNumLock;
206	const uint ScrollLock = Platform.KeyScrollLock;
207
208	const uint LeftShift = Platform.KeyLeftShift;
209	const uint RightShift = Platform.KeyRightShift;
210
211	const uint LeftControl = Platform.KeyLeftControl;
212	const uint RightControl = Platform.KeyRightControl;
213
214	const uint LeftAlt = Platform.KeyLeftAlt;
215	const uint RightAlt = Platform.KeyRightAlt;
216
217	const uint Zero = Platform.Key0;
218	const uint One = Platform.Key1;
219	const uint Two = Platform.Key2;
220	const uint Three = Platform.Key3;
221	const uint Four = Platform.Key4;
222	const uint Five = Platform.Key5;
223	const uint Six = Platform.Key6;
224	const uint Seven = Platform.Key7;
225	const uint Eight = Platform.Key8;
226	const uint Nine = Platform.Key9;
227
228	const uint SingleQuote = Platform.KeySingleQuote;
229	const uint Quote = Platform.KeyQuote;
230	const uint Comma = Platform.KeyComma;
231	const uint Period = Platform.KeyPeriod;
232	const uint Foreslash = Platform.KeyForeslash;
233	const uint Backslash = Platform.KeyBackslash;
234	const uint LeftBracket = Platform.KeyLeftBracket;
235	const uint RightBracket = Platform.KeyRightBracket;
236	const uint Semicolon = Platform.KeySemicolon;
237	const uint Minus = Platform.KeyMinus;
238	const uint Equals = Platform.KeyEquals;
239
240	const uint A = Platform.KeyA;
241	const uint B = Platform.KeyB;
242	const uint C = Platform.KeyC;
243	const uint D = Platform.KeyD;
244	const uint E = Platform.KeyE;
245	const uint F = Platform.KeyF;
246	const uint G = Platform.KeyG;
247	const uint H = Platform.KeyH;
248	const uint I = Platform.KeyI;
249	const uint J = Platform.KeyJ;
250	const uint K = Platform.KeyK;
251	const uint L = Platform.KeyL;
252	const uint M = Platform.KeyM;
253	const uint N = Platform.KeyN;
254	const uint O = Platform.KeyO;
255	const uint P = Platform.KeyP;
256	const uint Q = Platform.KeyQ;
257	const uint R = Platform.KeyR;
258	const uint S = Platform.KeyS;
259	const uint T = Platform.KeyT;
260	const uint U = Platform.KeyU;
261	const uint V = Platform.KeyV;
262	const uint W = Platform.KeyW;
263	const uint X = Platform.KeyX;
264	const uint Y = Platform.KeyY;
265	const uint Z = Platform.KeyZ;
266
267	const uint F1 = Platform.KeyF1;
268	const uint F2 = Platform.KeyF2;
269	const uint F3 = Platform.KeyF3;
270	const uint F4 = Platform.KeyF4;
271	const uint F5 = Platform.KeyF5;
272	const uint F6 = Platform.KeyF6;
273	const uint F7 = Platform.KeyF7;
274	const uint F8 = Platform.KeyF8;
275	const uint F9 = Platform.KeyF9;
276	const uint F10 = Platform.KeyF10;
277	const uint F11 = Platform.KeyF11;
278	const uint F12 = Platform.KeyF12;
279	const uint F13 = Platform.KeyF13;
280	const uint F14 = Platform.KeyF14;
281	const uint F15 = Platform.KeyF15;
282	const uint F16 = Platform.KeyF16;
283}
284
285// Redefine Platform Hints
286alias Platform.FontSans FontSans;
287alias Platform.Char Char;
288
289// Default parameters
290const int Default = -1;
291
292// C Types
293version(X86) {
294	alias uint Culong;
295	alias int Clong;
296}
297else {
298	alias ulong Culong;
299	alias long Clong;
300}
301
302union CuiEventInfo {
303	Key key;
304	Mouse mouse;
305	Size size;
306}
307
308struct CuiEvent {
309	enum Type {
310		KeyDown,
311		KeyUp,
312		MouseDown,
313		MouseUp,
314		MouseMove,
315		MouseWheelX,
316		MouseWheelY,
317		Size,
318		Close,
319	}
320
321	Type type;
322	CuiEventInfo info;
323	uint aux;
324}