entry.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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; struct ReallocatorI; }
  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. Insert,
  75. Delete,
  76. Home,
  77. End,
  78. PageUp,
  79. PageDown,
  80. Print,
  81. Plus,
  82. Minus,
  83. LeftBracket,
  84. RightBracket,
  85. Semicolon,
  86. Quote,
  87. Comma,
  88. Period,
  89. Slash,
  90. Backslash,
  91. Tilde,
  92. F1,
  93. F2,
  94. F3,
  95. F4,
  96. F5,
  97. F6,
  98. F7,
  99. F8,
  100. F9,
  101. F10,
  102. F11,
  103. F12,
  104. NumPad0,
  105. NumPad1,
  106. NumPad2,
  107. NumPad3,
  108. NumPad4,
  109. NumPad5,
  110. NumPad6,
  111. NumPad7,
  112. NumPad8,
  113. NumPad9,
  114. Key0,
  115. Key1,
  116. Key2,
  117. Key3,
  118. Key4,
  119. Key5,
  120. Key6,
  121. Key7,
  122. Key8,
  123. Key9,
  124. KeyA,
  125. KeyB,
  126. KeyC,
  127. KeyD,
  128. KeyE,
  129. KeyF,
  130. KeyG,
  131. KeyH,
  132. KeyI,
  133. KeyJ,
  134. KeyK,
  135. KeyL,
  136. KeyM,
  137. KeyN,
  138. KeyO,
  139. KeyP,
  140. KeyQ,
  141. KeyR,
  142. KeyS,
  143. KeyT,
  144. KeyU,
  145. KeyV,
  146. KeyW,
  147. KeyX,
  148. KeyY,
  149. KeyZ,
  150. GamepadA,
  151. GamepadB,
  152. GamepadX,
  153. GamepadY,
  154. GamepadThumbL,
  155. GamepadThumbR,
  156. GamepadShoulderL,
  157. GamepadShoulderR,
  158. GamepadUp,
  159. GamepadDown,
  160. GamepadLeft,
  161. GamepadRight,
  162. GamepadBack,
  163. GamepadStart,
  164. GamepadGuide,
  165. Count
  166. };
  167. };
  168. const char* getName(Key::Enum _key);
  169. struct MouseState
  170. {
  171. MouseState()
  172. : m_mx(0)
  173. , m_my(0)
  174. , m_mz(0)
  175. {
  176. for (uint32_t ii = 0; ii < entry::MouseButton::Count; ++ii)
  177. {
  178. m_buttons[ii] = entry::MouseButton::None;
  179. }
  180. }
  181. int32_t m_mx;
  182. int32_t m_my;
  183. int32_t m_mz;
  184. uint8_t m_buttons[entry::MouseButton::Count];
  185. };
  186. struct GamepadState
  187. {
  188. GamepadState()
  189. {
  190. memset(m_axis, 0, sizeof(m_axis) );
  191. }
  192. int32_t m_axis[entry::GamepadAxis::Count];
  193. };
  194. bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse = NULL);
  195. bx::FileReaderI* getFileReader();
  196. bx::FileWriterI* getFileWriter();
  197. bx::ReallocatorI* getAllocator();
  198. WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags = ENTRY_WINDOW_FLAG_NONE, const char* _title = "");
  199. void destroyWindow(WindowHandle _handle);
  200. void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y);
  201. void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height);
  202. void setWindowTitle(WindowHandle _handle, const char* _title);
  203. void toggleWindowFrame(WindowHandle _handle);
  204. void toggleFullscreen(WindowHandle _handle);
  205. void setMouseLock(WindowHandle _handle, bool _lock);
  206. struct WindowState
  207. {
  208. WindowState()
  209. : m_nwh(NULL)
  210. {
  211. m_handle.idx = UINT16_MAX;
  212. }
  213. WindowHandle m_handle;
  214. uint32_t m_width;
  215. uint32_t m_height;
  216. MouseState m_mouse;
  217. void* m_nwh;
  218. };
  219. bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset);
  220. } // namespace entry
  221. #endif // ENTRY_H_HEADER_GUARD