2
0

Window.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. #pragma once
  2. #include "App.h"
  3. #include "Input.h"
  4. #include "Signal.h"
  5. namespace gameplay
  6. {
  7. class Cursor;
  8. struct WindowHandle;
  9. /**
  10. * Defines a platform window.
  11. *
  12. * @see App::get_window() to access main application window.
  13. * @see App::create_window() to create additional windows.
  14. */
  15. class GP_API Window
  16. {
  17. friend class App;
  18. public:
  19. /**
  20. * Constructor.
  21. *
  22. * @see Windowing::create_window() instead.
  23. */
  24. Window();
  25. /**
  26. * Destructor.
  27. *
  28. * @see Windowing::destroy_window() instead.
  29. */
  30. ~Window();
  31. /**
  32. * Sets the title for a window.
  33. *
  34. * @param The title to be applied to the window.
  35. */
  36. void set_title(const char* title);
  37. /**
  38. * Sets the size of a window.
  39. *
  40. * @param size The new size to set for the window.
  41. */
  42. void set_size(const Int2& size);
  43. /**
  44. * Gets the size of the window.
  45. *
  46. * @return The size of the window.
  47. */
  48. Int2 get_size() const;
  49. /**
  50. * Signals that the window size has changed.
  51. *
  52. * emits:
  53. * <Window*> The window being resized
  54. * <Int2> The new size of the window
  55. */
  56. Signal<Window*, Int2> on_resize;
  57. /**
  58. * Sets the position of a window.
  59. *
  60. * @param pos The position to set the window to.
  61. */
  62. void set_pos(const Int2& pos);
  63. /**
  64. * Gets the position of a window.
  65. *
  66. * @returm The position of a window.
  67. */
  68. Int2 get_pos() const;
  69. /**
  70. * Signals that the window position has been moved.
  71. *
  72. * emits:
  73. * <Window*> The window being resized
  74. * <Int2> The new position of the window.
  75. */
  76. Signal<Window*, Int2> on_move;
  77. /**
  78. * Sets the window into fullscreen mode.
  79. *
  80. * @param fullscreen true to set to fullscreen, false for windowed.
  81. */
  82. void set_fullscreen(bool fullscreen);
  83. /**
  84. * Checks if the window is in fullscreen mode.
  85. *
  86. * @return true if the winow is in fullscreen, false if window is windowed.
  87. */
  88. bool is_fullscreen() const;
  89. /**
  90. * Gets the frame size for each edge of the frame of the window.
  91. *
  92. * The frame size includes the title bar, if the window has one.
  93. * The size of the frame may vary depending on the window-related hints used to create it.
  94. *
  95. * @param left The size of the left edge of the frame.
  96. * @param top The size of the top of the frame including title bar.
  97. * @param right The size of the right edge of the frame.
  98. * @param bottom The size of the bottom of the frame.
  99. */
  100. void get_frame_size(int* left, int* top, int* right, int* bottom) const;
  101. /**
  102. * Sets the opacity of the window, including any decorations.
  103. *
  104. * The opacity (or alpha) value is a positive finite number
  105. * between zero and one, where zero is fully transparent and
  106. * one is fully opaque.
  107. *
  108. * @param opacity The opacity to set for the window between 0.0 - 1.0
  109. */
  110. void set_opacity(float opacity);
  111. /**
  112. * Gets the opacity of the window, including any decorations.
  113. *
  114. * The opacity (or alpha) value is a positive finite number
  115. * between zero and one, where zero is fully transparent and
  116. * one is fully opaque.
  117. *
  118. * @return The opacity to set for the window between 0.0 - 1.0
  119. */
  120. float get_opacity() const;
  121. /**
  122. * Sets the icon of the window.
  123. *
  124. * If passed an array of candidate images, those of or closest
  125. * to the sizes desired by the system are selected.
  126. * If no images are specified, the window reverts to its default icon.
  127. *
  128. * @param images The images.
  129. * @param imageCount The number of images passed.
  130. */
  131. void set_icon(const Pixmap* images, size_t imageCount);
  132. /**
  133. * Checks the value of the close flag of the window.
  134. *
  135. * @return The value of the close flag of the window.
  136. */
  137. bool should_close();
  138. /**
  139. * Closes the window.
  140. */
  141. void close();
  142. /**
  143. * Signals that the window has been flagged to close.
  144. *
  145. * emits:
  146. * <Window*> The window being closed
  147. */
  148. Signal<Window*> on_close;
  149. /**
  150. * Shows the window.
  151. */
  152. void show();
  153. /**
  154. * Hides the window.
  155. */
  156. void hide();
  157. /**
  158. * Checks if the window is visible (shown).
  159. *
  160. * @return true if the window is visible, false if the window is hidden.
  161. */
  162. bool is_visible() const;
  163. /**
  164. * Brings the window to front and sets input focus.
  165. *
  166. * The window should already be visible and not minimized.
  167. *
  168. * Note: Do not use this function to steal focus from other applications
  169. * unless you are certain that is what the user wants.
  170. * Focus stealing can be extremely disruptive.
  171. */
  172. void focus();
  173. /**
  174. * Checks if the window is in focus.
  175. *
  176. * @return true if the window is in focus, false if not in focus.
  177. */
  178. bool is_focused() const;
  179. /**
  180. * Signals when the window gains or loses input focus.
  181. *
  182. * emits:
  183. * <Window*> The window losing or gaining focus.
  184. * <bool> true if gaining focused, false if loosing focus.
  185. */
  186. Signal<Window*, bool> on_focus;
  187. /**
  188. * Minimizes (iconifies) the window.
  189. *
  190. * If the window is already minimized, this function does nothing.
  191. *
  192. * @see restore() to restore the window back.
  193. */
  194. void minimize();
  195. /**
  196. * Checks if the window is currently minimized(inonified).
  197. *
  198. * @returns true if the window is minimized(icoinified), false if not minimized.
  199. */
  200. bool is_minimized() const;
  201. /**
  202. * Signals when the window is minimized(iconified) or restored.
  203. *
  204. * emits:
  205. * <Window*> The window being minimized or restored.
  206. * <bool> true if the window is being minimized(iconified) or false if being restored.
  207. */
  208. Signal<Window*, bool> on_minimize;
  209. /**
  210. * Maximizes the window if it was previously not maximized.
  211. *
  212. * If the window is already maximized, this function does nothing.
  213. *
  214. * @see restore() to restore the window back.
  215. */
  216. void maximize();
  217. /**
  218. * Checks if the window is currently maximized.
  219. *
  220. * @returns true if the window is maximized, false if not maximized.
  221. */
  222. bool is_maximized() const;
  223. /**
  224. * Signals when the window is maximized or restored.
  225. *
  226. * emits:
  227. * <Window*> The window being maximized or restored.
  228. * <bool> true if the window is being maximized or false if being restored.
  229. */
  230. Signal<Window*, bool> on_maximize;
  231. /**
  232. * Restores the window if it was previously minimized(iconified) or maximized.
  233. *
  234. * If the window is already restored, this function does nothing.
  235. * If the window is a full screen window, the resolution
  236. * chosen for the window is restored on the selected monitor.
  237. */
  238. void restore();
  239. /**
  240. * Gets the content scale for the window.
  241. *
  242. * The content scale is the ratio between the current DPI
  243. * and the platform's default DPI. This is especially important
  244. * for text and any UI elements. If the pixel dimensions of
  245. * your UI scaled by this look appropriate on your machine then
  246. * it should appear at a reasonable size on other machines regardless
  247. * of their DPI and scaling settings. This relies on the system DPI and
  248. * scaling settings being somewhat correct.
  249. *
  250. * On systems where each monitors can have its own content scale,
  251. * the window content scale will depend on which monitor the
  252. * system considers the window to be on.
  253. *
  254. * @return The content scale for the window.
  255. */
  256. Float2 get_content_scale() const;
  257. /**
  258. * Signals when the content scale of the specified window changes.
  259. *
  260. * emits:
  261. * <Window*> The window being content scaled.
  262. * <Float2> The update x and y content scale.
  263. */
  264. Signal<Window*, Float2> on_content_scale;
  265. /**
  266. * Sets the window cursor to he
  267. */
  268. void set_cursor(Cursor* cursor);
  269. /**
  270. * Sets the position of the coordinates of the cursor.
  271. *
  272. * The position is in screen coordinates, of the cursor relative
  273. * to the upper-left corner of the client area of the specified window.
  274. * The window must have input focus. If the window does not have input
  275. * focus when this function is called, it fails silently.
  276. *
  277. * Do not use this function to implement things like camera controls.
  278. * @see set_cursor_mode with `CursorMode::DISABLED`
  279. * to hide the cursor, transparently re-centers it and provides
  280. * unconstrained cursor motion.
  281. *
  282. * @param pos The coorinates which to set the cursor position to.
  283. */
  284. void set_cursor_pos(const Double2& pos);
  285. /**
  286. * Gets the position of the coordinates of the cursor.
  287. *
  288. * The position is in screen coordinates, of the cursor relative
  289. * to the upper-left corner of the client area of the specified window.
  290. * The window must have input focus. If the window does not have input
  291. * focus when this function is called, it fails silently.
  292. *
  293. * @return The cursor position coordinates
  294. */
  295. Double2 get_cursor_pos() const;
  296. /**
  297. * Sets the mode for the cursor.
  298. *
  299. * CursorMode::NORMAL makes the cursor visible and behaving normally.
  300. * CursorMode::HIDDEN makes the cursor invisible when it is over the content area
  301. * of the window but does not restrict the cursor from leaving.
  302. * CursorMode::DISABLED makes the cursor invisible when it is over the
  303. * content area of the window but does not restrict the cursor from leaving.
  304. *
  305. * @param mode The cursor mode to set to.
  306. */
  307. void set_cursor_mode(CursorMode mode);
  308. /**
  309. * Gets the mode for the cursor.
  310. *
  311. * CursorMode::NORMAL makes the cursor visible and behaving normally.
  312. * CursorMode::HIDDEN makes the cursor invisible when it is over the content area
  313. * of the window but does not restrict the cursor from leaving.
  314. * CursorMode::DISABLED makes the cursor invisible when it is over the
  315. * content area of the window but does not restrict the cursor from leaving.
  316. *
  317. * @return The current cursor mode.
  318. */
  319. CursorMode get_cursor_mode() const;
  320. /**
  321. * Signal when the cursor is moved.
  322. *
  323. * emits:
  324. * <Window*> The window being content scaled.
  325. * <Double2> The updated x and y screen coordinates.
  326. */
  327. Signal<Window*, Double2> on_cursor_move;
  328. /**
  329. * Signal when the cursor enters or leaves the client area of the window.
  330. *
  331. * emits:
  332. * <Window*> The window being content scaled.
  333. * <bool> true if the cursor enter the client area, false if it leaves it.
  334. */
  335. Signal<Window*, bool> on_cursor_enter;
  336. /**
  337. * Sets the input mode to be enabled.
  338. *
  339. * @param mode The input mode to be enabled.
  340. * @param enabled true if the input mode is enabled, false if disabled.
  341. */
  342. void set_input_mode_enabled(InputMode mode, bool enabled);
  343. /**
  344. * Checks if an input mode is enabled.
  345. *
  346. * @param mode The input mode to be enabled.
  347. * @return true if the input mode is enabled, false if disabled.
  348. */
  349. bool is_input_mode_enabled(InputMode mode) const;
  350. /**
  351. * Signaled when the user scrolls, whether with a mouse wheel or touchpad gesture.
  352. *
  353. * A normal mouse wheel, being vertical, provides offsets along the Y-axis.
  354. *
  355. * emits:
  356. * <Window*> The window the mouse button is actioned in.
  357. * <Float2> The x,y scroll offset.
  358. */
  359. Signal<Window*, Float2> on_scroll;
  360. /**
  361. * Get the current mouse button action (state).
  362. *
  363. * @param button The button to get the action (state).
  364. * @return The current mouse button action (state)
  365. */
  366. ButtonAction get_mouse_button_action(MouseButton button);
  367. /**
  368. * Signaled when the mouse button action is fired (down) or released(up).
  369. *
  370. * emits:
  371. * <Window*> The window the mouse button is actioned in.
  372. * <int> The mouse button index. You can also use MouseButton::LEFT,RIGHT or MIDDLE.
  373. * <ButtonAction> The action of the mouse button (PRESS or RELEASE)
  374. * <Float2> The mouse window coordinates
  375. * <KeyModFlags> The flags that are active when the button is pressed/released.
  376. */
  377. Signal<Window*, int, ButtonAction, Float2, KeyModFlags> on_mouse_button;
  378. /**
  379. * Get the current key action (state) of a key.
  380. *
  381. * @param key The key to check.
  382. * @return The current key action (state) of a key.
  383. */
  384. KeyAction get_key_action(Key key);
  385. /**
  386. * Signaled when the key action is fired (PRESS, RELEASE or REPEAT).
  387. *
  388. * emits:
  389. * <Window*> The window the key is actioned from.
  390. * <Key> The keyboard key actioned
  391. * <KeyAction> The action of the key (PRESS, RELEASE or REPEAT)
  392. * <KeyModFlags> The flags that are active when the button is actioned.
  393. */
  394. Signal<Window*, Key, KeyAction, KeyModFlags> on_key;
  395. /**
  396. * Signaled when a unicode character is input.
  397. *
  398. * The character callback is intended for Unicode text input.
  399. * As it deals with characters, it is keyboard layout dependent,
  400. * whereas the key callback is not. Characters do not map 1:1 to physical keys,
  401. * as a key may produce zero, one or more characters. If you want to know whether
  402. * a specific physical key was pressed or released, see the key callback instead.
  403. *
  404. * The character callback behaves as system text input normally does and will not
  405. * be called if modifier keys are held down that would prevent normal text input
  406. * on that platform, for example a Super (Command) key on macOS or Alt key on Windows.
  407. *
  408. * emits:
  409. * <Window*> The window the character is input into.
  410. * <uint32_t> The unicode point that is entered.
  411. */
  412. Signal<Window*, uint32_t> on_char;
  413. /**
  414. * Signaled when one or more dragged paths are dropped on the window.
  415. *
  416. * emits:
  417. * <Window*> The window the mouse button is actioned in.
  418. * <const char**> The paths dropped.
  419. * <size_t> The number of paths dropped.
  420. */
  421. Signal<Window*, const char**, size_t> on_drop;
  422. /**
  423. * Sets user pointer data associated with this window.
  424. *
  425. * @param userPtr The user pointer data to associate.
  426. */
  427. void set_user_ptr(void* userPtr);
  428. /**
  429. * Gets the user pointer data associate with this window.
  430. *
  431. * @return The user pointer data to associate.
  432. */
  433. void* get_user_ptr() const;
  434. std::unique_ptr<WindowHandle> handle;
  435. };
  436. }