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