neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
window_bits.hpp
Go to the documentation of this file.
1// window_bits.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program 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 This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
25
26namespace neogfx
27{
28 enum class window_style : uint32_t
29 {
30 Invalid = 0x00000000,
31 NoDecoration = 0x00000001, // No decoration at all (useful for splash screens, for example); this style cannot be combined with others
32 TitleBar = 0x00000002, // The window has a titlebar
33 NativeTitleBar = 0x00000004, // The window has a native titlebar
34 SystemMenu = 0x00000008,
35 MinimizeBox = 0x00000010,
36 MaximizeBox = 0x00000020,
37 Resize = 0x00000040, // The window can be resized and has a maximize button
38 SizeGrip = 0x00000080,
39 Close = 0x00000100, // The window has a close button
40 Nested = 0x00000200, // The window is not a native desktop window but a part of an existing one
41 Fullscreen = 0x00000400, // The window is shown in fullscreen mode; this style cannot be combined with others, and requires a valid video mode
42 Main = 0x00000800, // The window is a main window so may go fullscreen or change video mode
43 Dialog = 0x00001000,
44 Popup = 0x00002000, // The window is a popup
45 Menu = 0x00004000,
46 Tool = 0x00008000, // The window shouldn't appear on the operating system taskbar
47 DropShadow = 0x00010000,
48 Modal = 0x00020000,
49 ApplicationModal = 0x00040000,
50 NoActivate = 0x00080000,
51 RequiresOwnerFocus = 0x00100000,
52 DismissOnOwnerClick = 0x00200000,
53 DismissOnParentClick = 0x00400000,
54 HideOnOwnerClick = 0x00800000,
55 HideOnParentClick = 0x01000000,
56 InitiallyHidden = 0x02000000,
57 InitiallyCentered = 0x04000000, // Center on desktop or parent
58 InitiallyRenderable = 0x08000000,
59 SizeToContents = 0x10000000,
60 Weak = 0x80000000,
64 };
65
66 inline constexpr window_style operator~(window_style aStyle)
67 {
68 return static_cast<window_style>(~static_cast<uint32_t>(aStyle));
69 }
70
71 inline constexpr window_style operator|(window_style aLhs, window_style aRhs)
72 {
73 return static_cast<window_style>(static_cast<uint32_t>(aLhs) | static_cast<uint32_t>(aRhs));
74 }
75
76 inline constexpr window_style operator&(window_style aLhs, window_style aRhs)
77 {
78 return static_cast<window_style>(static_cast<uint32_t>(aLhs) & static_cast<uint32_t>(aRhs));
79 }
80
81 inline constexpr window_style& operator|=(window_style& aLhs, window_style aRhs)
82 {
83 return aLhs = static_cast<window_style>(static_cast<uint32_t>(aLhs) | static_cast<uint32_t>(aRhs));
84 }
85
86 inline constexpr window_style& operator&=(window_style& aLhs, window_style aRhs)
87 {
88 return aLhs = static_cast<window_style>(static_cast<uint32_t>(aLhs) & static_cast<uint32_t>(aRhs));
89 }
90
91 enum class window_state : uint32_t
92 {
93 Normal = 0x00000000,
94 Iconized = 0x00000001,
95 Maximized = 0x00000002
96 };
97}
98
118declare_enum_string(neogfx::window_style, RequiresOwnerFocus)
119declare_enum_string(neogfx::window_style, DismissOnOwnerClick)
120declare_enum_string(neogfx::window_style, DismissOnParentClick)
130
136
137namespace neogfx
138{
139 class window_placement
140 {
141 public:
142 struct geometry_not_specified : std::logic_error { geometry_not_specified() : std::logic_error{ "neogfx::window_placement::geometry_not_specified" } {} };
143 struct invalid_state : std::logic_error { invalid_state() : std::logic_error{ "neogfx::window_placement::invalid_state" } {} };
144 public:
145 window_placement() :
146 iPositionSpecified{},
147 iNormalGeometry{},
148 iIconizedGeometry{},
149 iMaximizedGeometry{},
150 iVideoMode{},
151 iState{window_state::Normal}
152 {
153 }
154 window_placement(
155 const rect& aNormalGeometry,
156 const optional_rect& aIconizedGeometry = rect{},
157 const optional_rect& aMaximizedGeometry = {},
158 const optional_video_mode& aVideoMode = {},
159 window_state aState = window_state::Normal) :
160 iPositionSpecified{ true },
161 iNormalGeometry{ aNormalGeometry },
162 iIconizedGeometry{ aIconizedGeometry },
163 iMaximizedGeometry{ aMaximizedGeometry },
164 iVideoMode{ aVideoMode },
165 iState{ aState }
166 {
167 check_state();
168 }
169 window_placement(
170 const point& aNormalPosition,
171 const optional_rect& aIconizedGeometry = rect{},
172 const optional_rect& aMaximizedGeometry = {},
173 const optional_video_mode& aVideoMode = {},
174 window_state aState = window_state::Normal) :
175 iPositionSpecified{ true },
176 iNormalGeometry{ aNormalPosition },
177 iIconizedGeometry{ aIconizedGeometry },
178 iMaximizedGeometry{ aMaximizedGeometry },
179 iVideoMode{ aVideoMode },
180 iState{ aState }
181 {
182 check_state();
183 }
184 window_placement(
185 const point& aNormalTopLeft,
186 const point& aNormalBottomRight,
187 const optional_rect& aIconizedGeometry = rect{},
188 const optional_rect& aMaximizedGeometry = {},
189 const optional_video_mode& aVideoMode = {},
190 window_state aState = window_state::Normal) :
191 iPositionSpecified{ true },
192 iNormalGeometry{ rect{ aNormalTopLeft, aNormalBottomRight } },
193 iIconizedGeometry{ aIconizedGeometry },
194 iMaximizedGeometry{ aMaximizedGeometry },
195 iVideoMode{ aVideoMode },
196 iState{ aState }
197 {
198 check_state();
199 }
200 window_placement(
201 const point& aNormalPosition,
202 const size& aNormalSize,
203 const optional_rect& aIconizedGeometry = rect{},
204 const optional_rect& aMaximizedGeometry = {},
205 const optional_video_mode& aVideoMode = {},
206 window_state aState = window_state::Normal) :
207 iPositionSpecified{ true },
208 iNormalGeometry{ rect{ aNormalPosition, aNormalSize } },
209 iIconizedGeometry{ aIconizedGeometry },
210 iMaximizedGeometry{ aMaximizedGeometry },
211 iVideoMode{ aVideoMode },
212 iState{ aState }
213 {
214 check_state();
215 }
216 window_placement(
217 const size& aNormalGeometry,
218 const optional_rect& aIconizedGeometry = rect{},
219 const optional_rect& aMaximizedGeometry = {},
220 const optional_video_mode& aVideoMode = {},
221 window_state aState = window_state::Normal) :
222 iPositionSpecified{ false },
223 iNormalGeometry{ aNormalGeometry },
224 iIconizedGeometry{ aIconizedGeometry },
225 iMaximizedGeometry{ aMaximizedGeometry },
226 iVideoMode{ aVideoMode },
227 iState{ aState }
228 {
229 check_state();
230 }
231 window_placement(
232 const video_mode& aVideoMode) :
233 iPositionSpecified{ true },
234 iNormalGeometry{ rect{ aVideoMode.resolution() } },
235 iIconizedGeometry{ rect{} },
236 iMaximizedGeometry{ rect{ aVideoMode.resolution() } },
237 iVideoMode{ aVideoMode },
238 iState{ window_state::Normal }
239 {
240 check_state();
241 }
242 public:
243 bool position_specified() const
244 {
245 return iPositionSpecified;
246 }
247 const optional_rect& normal_geometry() const
248 {
249 check_state();
250 return iNormalGeometry;
251 }
252 const optional_rect& iconized_geometry() const
253 {
254 check_state();
255 return iIconizedGeometry;
256 }
257 const optional_rect& maximized_geometry() const
258 {
259 check_state();
260 return iMaximizedGeometry;
261 }
262 const optional_video_mode& video_mode() const
263 {
264 check_state();
265 return iVideoMode;
266 }
267 window_state state() const
268 {
269 check_state();
270 return iState;
271 }
272 window_placement& set_normal_geometry(const optional_rect& aNormalGeometry)
273 {
274 iPositionSpecified = !!aNormalGeometry;
275 iNormalGeometry = aNormalGeometry;
276 return *this;
277 }
278 window_placement& set_iconized_geometry(const optional_rect& aIconizedGeometry)
279 {
280 iIconizedGeometry = aIconizedGeometry;
281 return *this;
282 }
283 window_placement& set_maximized_geometry(const optional_rect& aMaximizedGeometry)
284 {
285 iMaximizedGeometry = aMaximizedGeometry;
286 return *this;
287 }
288 window_placement& set_video_mode(const optional_video_mode& aVideoMode)
289 {
290 iVideoMode = aVideoMode;
291 return *this;
292 }
293 window_placement& set_state(window_state aState)
294 {
295 iState = aState;
296 return *this;
297 }
298 public:
299 static window_placement default_placement();
300 private:
301 void check_state() const
302 {
303 switch (iState)
304 {
305 case window_state::Normal:
306 if (!iNormalGeometry)
307 throw geometry_not_specified();
308 break;
309 case window_state::Iconized:
310 if (!iIconizedGeometry)
311 throw geometry_not_specified();
312 break;
313 case window_state::Maximized:
314 if (!iMaximizedGeometry)
315 throw geometry_not_specified();
316 break;
317 default:
318 throw invalid_state();
319 }
320 }
321 private:
322 bool iPositionSpecified;
323 optional_rect iNormalGeometry;
324 optional_rect iIconizedGeometry;
325 optional_rect iMaximizedGeometry;
326 optional_video_mode iVideoMode;
327 window_state iState;
328 };
329
330 typedef std::optional<window_placement> optional_window_placement;
331}
#define end_declare_enum(enumName)
Definition i_enum.hpp:62
#define declare_enum_string(enumName, enumEnumerator)
Definition i_enum.hpp:59
#define begin_declare_enum(enumName)
Definition i_enum.hpp:52
optional< rect > optional_rect
constexpr font_style & operator&=(font_style &aLhs, font_style aRhs)
Definition font.hpp:81
constexpr style_aspect operator&(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:60
audio_channel operator~(audio_channel lhs)
gui_rect rect
std::optional< video_mode > optional_video_mode
constexpr font_style & operator|=(font_style &aLhs, font_style aRhs)
Definition font.hpp:76
constexpr style_aspect operator|(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:55
Definition plf_hive.h:79