💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
7.1 KiB

  1. /*
  2. * Copyright (C) 2023 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_APP_WINDOW_HPP
  20. #define ANTKEEPER_APP_WINDOW_HPP
  21. #include <engine/math/vector.hpp>
  22. #include <engine/event/publisher.hpp>
  23. #include <engine/app/window-events.hpp>
  24. #include <string>
  25. namespace gl {
  26. class pipeline;
  27. }
  28. namespace app {
  29. class window_manager;
  30. /**
  31. *
  32. */
  33. class window
  34. {
  35. public:
  36. /**
  37. * Changes the title of the window.
  38. *
  39. * @param title Window title.
  40. */
  41. virtual void set_title(const std::string& title) = 0;
  42. /**
  43. * Changes the position of the window.
  44. *
  45. * @param position Position of the window, in display units.
  46. */
  47. virtual void set_position(const math::ivec2& position) = 0;
  48. /**
  49. * Changes the size of the window.
  50. *
  51. * @param size Size of the window, in display units.
  52. */
  53. virtual void set_size(const math::ivec2& size) = 0;
  54. /**
  55. * Sets the minimum size of the window.
  56. *
  57. * @param size Minimum size of the window, in display units.
  58. */
  59. virtual void set_minimum_size(const math::ivec2& size) = 0;
  60. /**
  61. * Sets the maximum size of the window.
  62. *
  63. * @param size Maximum size of the window, in display units.
  64. */
  65. virtual void set_maximum_size(const math::ivec2& size) = 0;
  66. /**
  67. * Maximizes or unmaximizes the window.
  68. *
  69. * @param maximized `true` if the window should be maximized, `false` otherwise.
  70. */
  71. virtual void set_maximized(bool maximized) = 0;
  72. /**
  73. * Enables or disables fullscreen mode.
  74. *
  75. * @param fullscreen `true` if the window should be in fullscreen mode, `false` otherwise.
  76. */
  77. virtual void set_fullscreen(bool fullscreen) = 0;
  78. /**
  79. * Enables or disables v-sync.
  80. *
  81. * @param v_sync `true` if the v-sync should be enabled, `false` otherwise.
  82. */
  83. virtual void set_v_sync(bool v_sync) = 0;
  84. /**
  85. * Makes the window's graphics context current.
  86. */
  87. virtual void make_current() = 0;
  88. /**
  89. * Swaps the front and back buffers of the window's graphics context.
  90. */
  91. virtual void swap_buffers() = 0;
  92. /// Returns the title of the window.
  93. [[nodiscard]] inline const std::string& get_title() const noexcept
  94. {
  95. return m_title;
  96. }
  97. /// Returns the windowed (non-maximized, non-fullscreen) position of the window, in display units.
  98. [[nodiscard]] inline const math::ivec2& get_windowed_position() const noexcept
  99. {
  100. return m_windowed_position;
  101. }
  102. /// Returns the current position of the window, in display units.
  103. [[nodiscard]] inline const math::ivec2& get_position() const noexcept
  104. {
  105. return m_position;
  106. }
  107. /// Returns the windowed (non-maximized, non-fullscreen) size of the window, in display units.
  108. [[nodiscard]] inline const math::ivec2& get_windowed_size() const noexcept
  109. {
  110. return m_windowed_size;
  111. }
  112. /// Returns the current size of the window, in display units.
  113. [[nodiscard]] inline const math::ivec2& get_size() const noexcept
  114. {
  115. return m_size;
  116. }
  117. /// Returns the minimum size of the window, in display units.
  118. [[nodiscard]] inline const math::ivec2& get_minimum_size() const noexcept
  119. {
  120. return m_minimum_size;
  121. }
  122. /// Returns the maximum size of the window, in display units.
  123. [[nodiscard]] inline const math::ivec2& get_maximum_size() const noexcept
  124. {
  125. return m_minimum_size;
  126. }
  127. /// Returns the current size of the window's drawable viewport, in pixels.
  128. [[nodiscard]] inline const math::ivec2& get_viewport_size() const noexcept
  129. {
  130. return m_viewport_size;
  131. }
  132. /// Returns `true` if the window is maximized, `false` otherwise.
  133. [[nodiscard]] inline bool is_maximized() const noexcept
  134. {
  135. return m_maximized;
  136. }
  137. /// Returns `true` if the window is in fullscreen mode, `false` otherwise.
  138. [[nodiscard]] inline bool is_fullscreen() const noexcept
  139. {
  140. return m_fullscreen;
  141. }
  142. /// Returns `true` if the v-sync is enabled, `false` otherwise.
  143. [[nodiscard]] inline bool get_v_sync() const noexcept
  144. {
  145. return m_v_sync;
  146. }
  147. /// Returns the graphics pipeline associated with this window.
  148. /// @{
  149. [[nodiscard]] virtual const gl::pipeline& get_graphics_pipeline() const noexcept = 0;
  150. [[nodiscard]] virtual gl::pipeline& get_graphics_pipeline() noexcept = 0;
  151. /// @}
  152. /// Returns the channel through which window closed events are published.
  153. [[nodiscard]] inline event::channel<window_closed_event>& get_closed_channel() noexcept
  154. {
  155. return m_closed_publisher.channel();
  156. }
  157. /// Returns the channel through which window focus changed events are published.
  158. [[nodiscard]] inline event::channel<window_focus_changed_event>& get_focus_changed_channel() noexcept
  159. {
  160. return m_focus_changed_publisher.channel();
  161. }
  162. /// Returns the channel through which window maximized events are published.
  163. [[nodiscard]] inline event::channel<window_maximized_event>& get_maximized_channel() noexcept
  164. {
  165. return m_maximized_publisher.channel();
  166. }
  167. /// Returns the channel through which window minimized events are published.
  168. [[nodiscard]] inline event::channel<window_minimized_event>& get_minimized_channel() noexcept
  169. {
  170. return m_minimized_publisher.channel();
  171. }
  172. /// Returns the channel through which window moved events are published.
  173. [[nodiscard]] inline event::channel<window_moved_event>& get_moved_channel() noexcept
  174. {
  175. return m_moved_publisher.channel();
  176. }
  177. /// Returns the channel through which window resized events are published.
  178. [[nodiscard]] inline event::channel<window_resized_event>& get_resized_channel() noexcept
  179. {
  180. return m_resized_publisher.channel();
  181. }
  182. /// Returns the channel through which window restored events are published.
  183. [[nodiscard]] inline event::channel<window_restored_event>& get_restored_channel() noexcept
  184. {
  185. return m_restored_publisher.channel();
  186. }
  187. protected:
  188. friend class window_manager;
  189. std::string m_title;
  190. math::ivec2 m_windowed_position{0, 0};
  191. math::ivec2 m_position{0, 0};
  192. math::ivec2 m_windowed_size{0, 0};
  193. math::ivec2 m_size{0, 0};
  194. math::ivec2 m_minimum_size{0, 0};
  195. math::ivec2 m_maximum_size{0, 0};
  196. math::ivec2 m_viewport_size{0, 0};
  197. bool m_maximized{false};
  198. bool m_fullscreen{false};
  199. bool m_v_sync{false};
  200. event::publisher<window_closed_event> m_closed_publisher;
  201. event::publisher<window_focus_changed_event> m_focus_changed_publisher;
  202. event::publisher<window_maximized_event> m_maximized_publisher;
  203. event::publisher<window_minimized_event> m_minimized_publisher;
  204. event::publisher<window_moved_event> m_moved_publisher;
  205. event::publisher<window_resized_event> m_resized_publisher;
  206. event::publisher<window_restored_event> m_restored_publisher;
  207. };
  208. } // namespace app
  209. #endif // ANTKEEPER_APP_WINDOW_HPP