💿🐜 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.

252 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 "math/vector.hpp"
  22. #include "event/publisher.hpp"
  23. #include "app/window-events.hpp"
  24. #include "gl/rasterizer.hpp"
  25. #include <string>
  26. namespace app {
  27. class window_manager;
  28. /**
  29. *
  30. */
  31. class window
  32. {
  33. public:
  34. /**
  35. * Constructs a window.
  36. */
  37. window() = default;
  38. /**
  39. * Destructs a window.
  40. */
  41. virtual ~window() = default;
  42. /**
  43. * Changes the title of the window.
  44. *
  45. * @param title Window title.
  46. */
  47. virtual void set_title(const std::string& title) = 0;
  48. /**
  49. * Changes the position of the window.
  50. *
  51. * @param position Position of the window, in display units.
  52. */
  53. virtual void set_position(const math::vector<int, 2>& position) = 0;
  54. /**
  55. * Changes the size of the window.
  56. *
  57. * @param size Size of the window, in display units.
  58. */
  59. virtual void set_size(const math::vector<int, 2>& size) = 0;
  60. /**
  61. * Sets the minimum size of the window.
  62. *
  63. * @param size Minimum size of the window, in display units.
  64. */
  65. virtual void set_minimum_size(const math::vector<int, 2>& size) = 0;
  66. /**
  67. * Sets the maximum size of the window.
  68. *
  69. * @param size Maximum size of the window, in display units.
  70. */
  71. virtual void set_maximum_size(const math::vector<int, 2>& size) = 0;
  72. /**
  73. * Maximizes or unmaximizes the window.
  74. *
  75. * @param maximized `true` if the window should be maximized, `false` otherwise.
  76. */
  77. virtual void set_maximized(bool maximized) = 0;
  78. /**
  79. * Enables or disables fullscreen mode.
  80. *
  81. * @param fullscreen `true` if the window should be in fullscreen mode, `false` otherwise.
  82. */
  83. virtual void set_fullscreen(bool fullscreen) = 0;
  84. /**
  85. * Enables or disables v-sync.
  86. *
  87. * @param v_sync `true` if the v-sync should be enabled, `false` otherwise.
  88. */
  89. virtual void set_v_sync(bool v_sync) = 0;
  90. /**
  91. * Makes the window's graphics context current.
  92. */
  93. virtual void make_current() = 0;
  94. /**
  95. * Swaps the front and back buffers of the window's graphics context.
  96. */
  97. virtual void swap_buffers() = 0;
  98. /// Returns the title of the window.
  99. [[nodiscard]] inline const std::string& get_title() const noexcept
  100. {
  101. return title;
  102. }
  103. /// Returns the windowed (non-maximized, non-fullscreen) position of the window, in display units.
  104. [[nodiscard]] inline const math::vector<int, 2>& get_windowed_position() const noexcept
  105. {
  106. return windowed_position;
  107. }
  108. /// Returns the current position of the window, in display units.
  109. [[nodiscard]] inline const math::vector<int, 2>& get_position() const noexcept
  110. {
  111. return position;
  112. }
  113. /// Returns the windowed (non-maximized, non-fullscreen) size of the window, in display units.
  114. [[nodiscard]] inline const math::vector<int, 2>& get_windowed_size() const noexcept
  115. {
  116. return windowed_size;
  117. }
  118. /// Returns the current size of the window, in display units.
  119. [[nodiscard]] inline const math::vector<int, 2>& get_size() const noexcept
  120. {
  121. return size;
  122. }
  123. /// Returns the minimum size of the window, in display units.
  124. [[nodiscard]] inline const math::vector<int, 2>& get_minimum_size() const noexcept
  125. {
  126. return minimum_size;
  127. }
  128. /// Returns the maximum size of the window, in display units.
  129. [[nodiscard]] inline const math::vector<int, 2>& get_maximum_size() const noexcept
  130. {
  131. return minimum_size;
  132. }
  133. /// Returns the current size of the window's drawable viewport, in pixels.
  134. [[nodiscard]] inline const math::vector<int, 2>& get_viewport_size() const noexcept
  135. {
  136. return viewport_size;
  137. }
  138. /// Returns `true` if the window is maximized, `false` otherwise.
  139. [[nodiscard]] inline bool is_maximized() const noexcept
  140. {
  141. return maximized;
  142. }
  143. /// Returns `true` if the window is in fullscreen mode, `false` otherwise.
  144. [[nodiscard]] inline bool is_fullscreen() const noexcept
  145. {
  146. return fullscreen;
  147. }
  148. /// Returns `true` if the v-sync is enabled, `false` otherwise.
  149. [[nodiscard]] inline bool get_v_sync() const noexcept
  150. {
  151. return v_sync;
  152. }
  153. /// Returns the rasterizer associated with this window.
  154. [[nodiscard]] virtual gl::rasterizer* get_rasterizer() noexcept = 0;
  155. /// Returns the channel through which window closed events are published.
  156. [[nodiscard]] inline event::channel<window_closed_event>& get_closed_channel() noexcept
  157. {
  158. return closed_publisher.channel();
  159. }
  160. /// Returns the channel through which window focus changed events are published.
  161. [[nodiscard]] inline event::channel<window_focus_changed_event>& get_focus_changed_channel() noexcept
  162. {
  163. return focus_changed_publisher.channel();
  164. }
  165. /// Returns the channel through which window maximized events are published.
  166. [[nodiscard]] inline event::channel<window_maximized_event>& get_maximized_channel() noexcept
  167. {
  168. return maximized_publisher.channel();
  169. }
  170. /// Returns the channel through which window minimized events are published.
  171. [[nodiscard]] inline event::channel<window_minimized_event>& get_minimized_channel() noexcept
  172. {
  173. return minimized_publisher.channel();
  174. }
  175. /// Returns the channel through which window moved events are published.
  176. [[nodiscard]] inline event::channel<window_moved_event>& get_moved_channel() noexcept
  177. {
  178. return moved_publisher.channel();
  179. }
  180. /// Returns the channel through which window resized events are published.
  181. [[nodiscard]] inline event::channel<window_resized_event>& get_resized_channel() noexcept
  182. {
  183. return resized_publisher.channel();
  184. }
  185. /// Returns the channel through which window restored events are published.
  186. [[nodiscard]] inline event::channel<window_restored_event>& get_restored_channel() noexcept
  187. {
  188. return restored_publisher.channel();
  189. }
  190. protected:
  191. friend class window_manager;
  192. std::string title;
  193. math::vector<int, 2> windowed_position;
  194. math::vector<int, 2> position;
  195. math::vector<int, 2> windowed_size;
  196. math::vector<int, 2> size;
  197. math::vector<int, 2> minimum_size;
  198. math::vector<int, 2> maximum_size;
  199. math::vector<int, 2> viewport_size;
  200. bool maximized;
  201. bool fullscreen;
  202. bool v_sync;
  203. event::publisher<window_closed_event> closed_publisher;
  204. event::publisher<window_focus_changed_event> focus_changed_publisher;
  205. event::publisher<window_maximized_event> maximized_publisher;
  206. event::publisher<window_minimized_event> minimized_publisher;
  207. event::publisher<window_moved_event> moved_publisher;
  208. event::publisher<window_resized_event> resized_publisher;
  209. event::publisher<window_restored_event> restored_publisher;
  210. };
  211. } // namespace app
  212. #endif // ANTKEEPER_APP_WINDOW_HPP