window.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2012-2025 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: MIT
  4. */
  5. #pragma once
  6. #include "core/memory/types.h"
  7. #include "core/types.h"
  8. namespace crown
  9. {
  10. /// Mouse cursor.
  11. ///
  12. /// @ingroup Device
  13. struct MouseCursor
  14. {
  15. enum Enum
  16. {
  17. ARROW,
  18. HAND,
  19. TEXT_INPUT,
  20. CORNER_TOP_LEFT,
  21. CORNER_TOP_RIGHT,
  22. CORNER_BOTTOM_LEFT,
  23. CORNER_BOTTOM_RIGHT,
  24. SIZE_HORIZONTAL,
  25. SIZE_VERTICAL,
  26. WAIT,
  27. COUNT
  28. };
  29. };
  30. /// Cursor Mode
  31. ///
  32. /// @ingroup Device
  33. struct CursorMode
  34. {
  35. enum Enum
  36. {
  37. NORMAL,
  38. DISABLED,
  39. COUNT
  40. };
  41. };
  42. /// Window interface.
  43. ///
  44. /// @ingroup Device
  45. struct Window
  46. {
  47. ///
  48. virtual ~Window()
  49. {
  50. }
  51. /// Opens the window.
  52. virtual void open(u16 x, u16 y, u16 width, u16 height, u32 parent) = 0;
  53. /// Closes the window.
  54. virtual void close() = 0;
  55. /// Shows the window.
  56. virtual void show() = 0;
  57. /// Hides the window.
  58. virtual void hide() = 0;
  59. /// Resizes the window to @a width and @a height.
  60. virtual void resize(u16 width, u16 height) = 0;
  61. /// Moves the window to @a x and @a y.
  62. virtual void move(u16 x, u16 y) = 0;
  63. /// Minimizes the window.
  64. virtual void minimize() = 0;
  65. /// Maximizes the window.
  66. virtual void maximize() = 0;
  67. /// Restores the window.
  68. virtual void restore() = 0;
  69. /// Returns the title of the window.
  70. virtual const char *title() = 0;
  71. /// Sets the title of the window.
  72. virtual void set_title(const char *title) = 0;
  73. /// Sets whether to @a show the cursor.
  74. virtual void show_cursor(bool show) = 0;
  75. /// Sets whether the window is @a fullscreen.
  76. virtual void set_fullscreen(bool fullscreen) = 0;
  77. /// Sets the mouse @a cursor on this window. Setting the mode to
  78. /// CursorMode::DISABLED hides the cursor and automatically re-centers it
  79. /// every time is moved.
  80. virtual void set_cursor(MouseCursor::Enum cursor) = 0;
  81. /// Sets the mouse cursor @a mode on this window
  82. virtual void set_cursor_mode(CursorMode::Enum mode) = 0;
  83. /// Returns the native window handle or NULL if the platform does not support it.
  84. virtual void *native_handle() = 0;
  85. /// Returns the native display handle or NULL if the platform does not support it.
  86. virtual void *native_display() = 0;
  87. };
  88. /// Functions to manipulate Window
  89. ///
  90. /// @ingroup Device
  91. namespace window
  92. {
  93. /// Creates a new window.
  94. Window *create(Allocator &a);
  95. /// Destroys the window @a w.
  96. void destroy(Allocator &a, Window &w);
  97. } // namespace window
  98. } // namespace crown