entry.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef ENTRY_H_HEADER_GUARD
  6. #define ENTRY_H_HEADER_GUARD
  7. #include "dbg.h"
  8. #include <string.h> // memset
  9. #include <bx/bx.h>
  10. namespace bx { struct FileReaderI; struct FileWriterI; }
  11. extern "C" int _main_(int _argc, char** _argv);
  12. #define ENTRY_WINDOW_FLAG_NONE UINT32_C(0x00000000)
  13. #define ENTRY_WINDOW_FLAG_ASPECT_RATIO UINT32_C(0x00000001)
  14. #define ENTRY_WINDOW_FLAG_FRAME UINT32_C(0x00000002)
  15. namespace entry
  16. {
  17. struct WindowHandle { uint16_t idx; };
  18. inline bool isValid(WindowHandle _handle) { return UINT16_MAX != _handle.idx; }
  19. struct GamepadHandle { uint16_t idx; };
  20. inline bool isValid(GamepadHandle _handle) { return UINT16_MAX != _handle.idx; }
  21. struct MouseButton
  22. {
  23. enum Enum
  24. {
  25. None,
  26. Left,
  27. Middle,
  28. Right,
  29. Count
  30. };
  31. };
  32. struct GamepadAxis
  33. {
  34. enum Enum
  35. {
  36. LeftX,
  37. LeftY,
  38. LeftZ,
  39. RightX,
  40. RightY,
  41. RightZ,
  42. Count
  43. };
  44. };
  45. struct Modifier
  46. {
  47. enum Enum
  48. {
  49. None = 0,
  50. LeftAlt = 0x01,
  51. RightAlt = 0x02,
  52. LeftCtrl = 0x04,
  53. RightCtrl = 0x08,
  54. LeftShift = 0x10,
  55. RightShift = 0x20,
  56. LeftMeta = 0x40,
  57. RightMeta = 0x80,
  58. };
  59. };
  60. struct Key
  61. {
  62. enum Enum
  63. {
  64. None = 0,
  65. Esc,
  66. Return,
  67. Tab,
  68. Space,
  69. Backspace,
  70. Up,
  71. Down,
  72. Left,
  73. Right,
  74. PageUp,
  75. PageDown,
  76. Home,
  77. End,
  78. Print,
  79. Plus,
  80. Minus,
  81. F1,
  82. F2,
  83. F3,
  84. F4,
  85. F5,
  86. F6,
  87. F7,
  88. F8,
  89. F9,
  90. F10,
  91. F11,
  92. F12,
  93. NumPad0,
  94. NumPad1,
  95. NumPad2,
  96. NumPad3,
  97. NumPad4,
  98. NumPad5,
  99. NumPad6,
  100. NumPad7,
  101. NumPad8,
  102. NumPad9,
  103. Key0,
  104. Key1,
  105. Key2,
  106. Key3,
  107. Key4,
  108. Key5,
  109. Key6,
  110. Key7,
  111. Key8,
  112. Key9,
  113. KeyA,
  114. KeyB,
  115. KeyC,
  116. KeyD,
  117. KeyE,
  118. KeyF,
  119. KeyG,
  120. KeyH,
  121. KeyI,
  122. KeyJ,
  123. KeyK,
  124. KeyL,
  125. KeyM,
  126. KeyN,
  127. KeyO,
  128. KeyP,
  129. KeyQ,
  130. KeyR,
  131. KeyS,
  132. KeyT,
  133. KeyU,
  134. KeyV,
  135. KeyW,
  136. KeyX,
  137. KeyY,
  138. KeyZ,
  139. GamepadA,
  140. GamepadB,
  141. GamepadX,
  142. GamepadY,
  143. GamepadThumbL,
  144. GamepadThumbR,
  145. GamepadShoulderL,
  146. GamepadShoulderR,
  147. GamepadUp,
  148. GamepadDown,
  149. GamepadLeft,
  150. GamepadRight,
  151. GamepadBack,
  152. GamepadStart,
  153. GamepadGuide,
  154. Count
  155. };
  156. };
  157. struct MouseState
  158. {
  159. MouseState()
  160. : m_mx(0)
  161. , m_my(0)
  162. , m_mz(0)
  163. {
  164. for (uint32_t ii = 0; ii < entry::MouseButton::Count; ++ii)
  165. {
  166. m_buttons[ii] = entry::MouseButton::None;
  167. }
  168. }
  169. int32_t m_mx;
  170. int32_t m_my;
  171. int32_t m_mz;
  172. uint8_t m_buttons[entry::MouseButton::Count];
  173. };
  174. struct GamepadState
  175. {
  176. GamepadState()
  177. {
  178. memset(m_axis, 0, sizeof(m_axis) );
  179. }
  180. int32_t m_axis[entry::GamepadAxis::Count];
  181. };
  182. bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse = NULL);
  183. bx::FileReaderI* getFileReader();
  184. bx::FileWriterI* getFileWriter();
  185. WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags = ENTRY_WINDOW_FLAG_NONE, const char* _title = "");
  186. void destroyWindow(WindowHandle _handle);
  187. void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y);
  188. void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height);
  189. void setWindowTitle(WindowHandle _handle, const char* _title);
  190. void toggleWindowFrame(WindowHandle _handle);
  191. void setMouseLock(WindowHandle _handle, bool _lock);
  192. struct WindowState
  193. {
  194. WindowState()
  195. : m_nwh(NULL)
  196. {
  197. m_handle.idx = UINT16_MAX;
  198. }
  199. WindowHandle m_handle;
  200. uint32_t m_width;
  201. uint32_t m_height;
  202. MouseState m_mouse;
  203. void* m_nwh;
  204. };
  205. bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset);
  206. } // namespace entry
  207. #endif // ENTRY_H_HEADER_GUARD