entry.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright 2011-2014 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 <bx/bx.h>
  9. namespace bx { struct FileReaderI; struct FileWriterI; }
  10. extern "C" int _main_(int _argc, char** _argv);
  11. #define ENTRY_WINDOW_FLAG_NONE UINT32_C(0x00000000)
  12. #define ENTRY_WINDOW_FLAG_ASPECT_RATIO UINT32_C(0x00000001)
  13. #define ENTRY_WINDOW_FLAG_FRAME UINT32_C(0x00000002)
  14. namespace entry
  15. {
  16. struct WindowHandle { uint16_t idx; static const uint16_t invalidHandle; };
  17. inline bool isValid(WindowHandle _handle) { return WindowHandle::invalidHandle != _handle.idx; }
  18. struct MouseButton
  19. {
  20. enum Enum
  21. {
  22. None,
  23. Left,
  24. Middle,
  25. Right,
  26. Count
  27. };
  28. };
  29. struct Modifier
  30. {
  31. enum Enum
  32. {
  33. None = 0,
  34. LeftAlt = 0x01,
  35. RightAlt = 0x02,
  36. LeftCtrl = 0x04,
  37. RightCtrl = 0x08,
  38. LeftShift = 0x10,
  39. RightShift = 0x20,
  40. LeftMeta = 0x40,
  41. RightMeta = 0x80,
  42. };
  43. };
  44. struct Key
  45. {
  46. enum Enum
  47. {
  48. None = 0,
  49. Esc,
  50. Return,
  51. Tab,
  52. Space,
  53. Backspace,
  54. Up,
  55. Down,
  56. Left,
  57. Right,
  58. PageUp,
  59. PageDown,
  60. Home,
  61. End,
  62. Print,
  63. Plus,
  64. Minus,
  65. F1,
  66. F2,
  67. F3,
  68. F4,
  69. F5,
  70. F6,
  71. F7,
  72. F8,
  73. F9,
  74. F10,
  75. F11,
  76. F12,
  77. NumPad0,
  78. NumPad1,
  79. NumPad2,
  80. NumPad3,
  81. NumPad4,
  82. NumPad5,
  83. NumPad6,
  84. NumPad7,
  85. NumPad8,
  86. NumPad9,
  87. Key0,
  88. Key1,
  89. Key2,
  90. Key3,
  91. Key4,
  92. Key5,
  93. Key6,
  94. Key7,
  95. Key8,
  96. Key9,
  97. KeyA,
  98. KeyB,
  99. KeyC,
  100. KeyD,
  101. KeyE,
  102. KeyF,
  103. KeyG,
  104. KeyH,
  105. KeyI,
  106. KeyJ,
  107. KeyK,
  108. KeyL,
  109. KeyM,
  110. KeyN,
  111. KeyO,
  112. KeyP,
  113. KeyQ,
  114. KeyR,
  115. KeyS,
  116. KeyT,
  117. KeyU,
  118. KeyV,
  119. KeyW,
  120. KeyX,
  121. KeyY,
  122. KeyZ,
  123. Count,
  124. };
  125. };
  126. struct MouseState
  127. {
  128. MouseState()
  129. : m_mx(0)
  130. , m_my(0)
  131. , m_mz(0)
  132. {
  133. for (uint32_t ii = 0; ii < entry::MouseButton::Count; ++ii)
  134. {
  135. m_buttons[ii] = entry::MouseButton::None;
  136. }
  137. }
  138. int32_t m_mx;
  139. int32_t m_my;
  140. int32_t m_mz;
  141. uint8_t m_buttons[entry::MouseButton::Count];
  142. };
  143. bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse = NULL);
  144. bx::FileReaderI* getFileReader();
  145. bx::FileWriterI* getFileWriter();
  146. WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags = ENTRY_WINDOW_FLAG_NONE, const char* _title = "");
  147. void destroyWindow(WindowHandle _handle);
  148. void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y);
  149. void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height);
  150. void setWindowTitle(WindowHandle _handle, const char* _title);
  151. void toggleWindowFrame(WindowHandle _handle);
  152. void setMouseLock(WindowHandle _handle, bool _lock);
  153. struct WindowState
  154. {
  155. WindowState()
  156. : m_nwh(NULL)
  157. {
  158. m_handle.idx = UINT16_MAX;
  159. }
  160. WindowHandle m_handle;
  161. uint32_t m_width;
  162. uint32_t m_height;
  163. MouseState m_mouse;
  164. void* m_nwh;
  165. };
  166. bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset);
  167. } // namespace entry
  168. #endif // ENTRY_H_HEADER_GUARD