Antkeeper  0.0.1
window.hpp
Go to the documentation of this file.
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 
20 #ifndef ANTKEEPER_APP_WINDOW_HPP
21 #define ANTKEEPER_APP_WINDOW_HPP
22 
23 #include <engine/math/vector.hpp>
26 #include <string>
27 
28 namespace gl {
29 
30  class pipeline;
31 
32 }
33 
34 namespace app {
35 
36 class window_manager;
37 
41 class window
42 {
43 public:
49  virtual void set_title(const std::string& title) = 0;
50 
56  virtual void set_position(const math::ivec2& position) = 0;
57 
63  virtual void set_size(const math::ivec2& size) = 0;
64 
70  virtual void set_minimum_size(const math::ivec2& size) = 0;
71 
77  virtual void set_maximum_size(const math::ivec2& size) = 0;
78 
84  virtual void set_maximized(bool maximized) = 0;
85 
91  virtual void set_fullscreen(bool fullscreen) = 0;
92 
98  virtual void set_v_sync(bool v_sync) = 0;
99 
103  virtual void make_current() = 0;
104 
108  virtual void swap_buffers() = 0;
109 
111  [[nodiscard]] inline const std::string& get_title() const noexcept
112  {
113  return m_title;
114  }
115 
117  [[nodiscard]] inline const math::ivec2& get_windowed_position() const noexcept
118  {
119  return m_windowed_position;
120  }
121 
123  [[nodiscard]] inline const math::ivec2& get_position() const noexcept
124  {
125  return m_position;
126  }
127 
129  [[nodiscard]] inline const math::ivec2& get_windowed_size() const noexcept
130  {
131  return m_windowed_size;
132  }
133 
135  [[nodiscard]] inline const math::ivec2& get_size() const noexcept
136  {
137  return m_size;
138  }
139 
141  [[nodiscard]] inline const math::ivec2& get_minimum_size() const noexcept
142  {
143  return m_minimum_size;
144  }
145 
147  [[nodiscard]] inline const math::ivec2& get_maximum_size() const noexcept
148  {
149  return m_minimum_size;
150  }
151 
153  [[nodiscard]] inline const math::ivec2& get_viewport_size() const noexcept
154  {
155  return m_viewport_size;
156  }
157 
159  [[nodiscard]] inline bool is_maximized() const noexcept
160  {
161  return m_maximized;
162  }
163 
165  [[nodiscard]] inline bool is_fullscreen() const noexcept
166  {
167  return m_fullscreen;
168  }
169 
171  [[nodiscard]] inline bool get_v_sync() const noexcept
172  {
173  return m_v_sync;
174  }
175 
178  [[nodiscard]] virtual const gl::pipeline& get_graphics_pipeline() const noexcept = 0;
179  [[nodiscard]] virtual gl::pipeline& get_graphics_pipeline() noexcept = 0;
181 
183  [[nodiscard]] inline event::channel<window_closed_event>& get_closed_channel() noexcept
184  {
185  return m_closed_publisher.channel();
186  }
187 
190  {
191  return m_focus_changed_publisher.channel();
192  }
193 
196  {
197  return m_maximized_publisher.channel();
198  }
199 
202  {
203  return m_minimized_publisher.channel();
204  }
205 
207  [[nodiscard]] inline event::channel<window_moved_event>& get_moved_channel() noexcept
208  {
209  return m_moved_publisher.channel();
210  }
211 
214  {
215  return m_resized_publisher.channel();
216  }
217 
220  {
221  return m_restored_publisher.channel();
222  }
223 
224 protected:
225  friend class window_manager;
226 
227  std::string m_title;
235  bool m_maximized{false};
236  bool m_fullscreen{false};
237  bool m_v_sync{false};
238 
246 };
247 
248 } // namespace app
249 
250 #endif // ANTKEEPER_APP_WINDOW_HPP
event::publisher< window_restored_event > m_restored_publisher
Definition: window.hpp:245
virtual void set_position(const math::ivec2 &position)=0
Changes the position of the window.
virtual void set_size(const math::ivec2 &size)=0
Changes the size of the window.
event::publisher< window_maximized_event > m_maximized_publisher
Definition: window.hpp:241
const math::ivec2 & get_size() const noexcept
Returns the current size of the window, in display units.
Definition: window.hpp:135
event::channel< window_closed_event > & get_closed_channel() noexcept
Returns the channel through which window closed events are published.
Definition: window.hpp:183
virtual void set_maximized(bool maximized)=0
Maximizes or unmaximizes the window.
event::channel< window_moved_event > & get_moved_channel() noexcept
Returns the channel through which window moved events are published.
Definition: window.hpp:207
event::channel< window_restored_event > & get_restored_channel() noexcept
Returns the channel through which window restored events are published.
Definition: window.hpp:219
math::ivec2 m_minimum_size
Definition: window.hpp:232
bool m_v_sync
Definition: window.hpp:237
bool is_maximized() const noexcept
Returns true if the window is maximized, false otherwise.
Definition: window.hpp:159
virtual void make_current()=0
Makes the window's graphics context current.
event::publisher< window_closed_event > m_closed_publisher
Definition: window.hpp:239
math::ivec2 m_viewport_size
Definition: window.hpp:234
math::ivec2 m_windowed_position
Definition: window.hpp:228
math::ivec2 m_windowed_size
Definition: window.hpp:230
event::channel< window_minimized_event > & get_minimized_channel() noexcept
Returns the channel through which window minimized events are published.
Definition: window.hpp:201
std::string m_title
Definition: window.hpp:227
bool is_fullscreen() const noexcept
Returns true if the window is in fullscreen mode, false otherwise.
Definition: window.hpp:165
event::publisher< window_focus_changed_event > m_focus_changed_publisher
Definition: window.hpp:240
event::channel< window_focus_changed_event > & get_focus_changed_channel() noexcept
Returns the channel through which window focus changed events are published.
Definition: window.hpp:189
math::ivec2 m_size
Definition: window.hpp:231
const math::ivec2 & get_maximum_size() const noexcept
Returns the maximum size of the window, in display units.
Definition: window.hpp:147
event::channel< window_resized_event > & get_resized_channel() noexcept
Returns the channel through which window resized events are published.
Definition: window.hpp:213
bool get_v_sync() const noexcept
Returns true if the v-sync is enabled, false otherwise.
Definition: window.hpp:171
virtual void set_title(const std::string &title)=0
Changes the title of the window.
event::channel< window_maximized_event > & get_maximized_channel() noexcept
Returns the channel through which window maximized events are published.
Definition: window.hpp:195
virtual const gl::pipeline & get_graphics_pipeline() const noexcept=0
Returns the graphics pipeline associated with this window.
const math::ivec2 & get_viewport_size() const noexcept
Returns the current size of the window's drawable viewport, in pixels.
Definition: window.hpp:153
bool m_maximized
Definition: window.hpp:235
const math::ivec2 & get_windowed_position() const noexcept
Returns the windowed (non-maximized, non-fullscreen) position of the window, in display units.
Definition: window.hpp:117
const math::ivec2 & get_windowed_size() const noexcept
Returns the windowed (non-maximized, non-fullscreen) size of the window, in display units.
Definition: window.hpp:129
bool m_fullscreen
Definition: window.hpp:236
virtual void set_maximum_size(const math::ivec2 &size)=0
Sets the maximum size of the window.
const math::ivec2 & get_position() const noexcept
Returns the current position of the window, in display units.
Definition: window.hpp:123
virtual void set_minimum_size(const math::ivec2 &size)=0
Sets the minimum size of the window.
math::ivec2 m_position
Definition: window.hpp:229
virtual void set_fullscreen(bool fullscreen)=0
Enables or disables fullscreen mode.
const std::string & get_title() const noexcept
Returns the title of the window.
Definition: window.hpp:111
event::publisher< window_moved_event > m_moved_publisher
Definition: window.hpp:243
event::publisher< window_minimized_event > m_minimized_publisher
Definition: window.hpp:242
virtual void set_v_sync(bool v_sync)=0
Enables or disables v-sync.
event::publisher< window_resized_event > m_resized_publisher
Definition: window.hpp:244
const math::ivec2 & get_minimum_size() const noexcept
Returns the minimum size of the window, in display units.
Definition: window.hpp:141
math::ivec2 m_maximum_size
Definition: window.hpp:233
virtual void swap_buffers()=0
Swaps the front and back buffers of the window's graphics context.
Channel through which messages are published.
Definition: channel.hpp:44
Publishes messages to subscribers.
Definition: publisher.hpp:36
Graphics pipeline interface.
Definition: pipeline.hpp:48
Publish-subscribe messaging.
Definition: channel.hpp:32
Graphics library interface.
Definition: window.hpp:28
Event generated when a window has been requested to close.
n-dimensional vector.
Definition: vector.hpp:44