fennec
Loading...
Searching...
No Matches
window.h
Go to the documentation of this file.
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
30
31#ifndef FENNEC_PLATFORM_INTERFACE_WINDOW_H
32#define FENNEC_PLATFORM_INTERFACE_WINDOW_H
33
34#include <fennec/platform/interface/fwd.h>
35
37
38#include <fennec/string/string.h>
39
42#include <fennec/memory/pointers.h>
43
44namespace fennec
45{
46
47class window {
48// Structures & Typedefs ===============================================================================================
49public:
50 static constexpr size_t nullid = -1;
51
52 enum mode_ : uint8_t {
53 mode_windowed = 0,
54 mode_minimized,
55 mode_maximized,
56 mode_fullscreen,
57 mode_exclusive_fullscreen,
58 };
59
60 enum vsync_ : uint8_t {
61 vsync_disabled = 0,
62 vsync_enabled,
63 vsync_adaptive
64 };
65
66 enum flag_ : uint8_t {
67 flag_always_on_top = 0, // Window always appears on top level
68 flag_borderless, // Window has no border decorations
69 flag_modal, // Window always appears above parent and blocks input going to parent
70 flag_pass_mouse, // Mouse interaction passes to next underlying window in the application
71 flag_popup, // Window does not show in taskbar and closes when loses focus
72 flag_resizable, // Window can be resized through functions defined by Desktop Environment
73 flag_transparent, // Window has an alpha value
74 flag_no_focus, // Window can be focused
75
76 flag_count
77 };
78
79 enum state_ : uint8_t {
80 state_running = 0, // Window is running
81 state_child, // Window is a child
82 state_suspended, // Window is suspended
83 state_visible, // Window is visible
84
85 state_count
86 };
87
88 using flags_t = bitfield<flag_count>;
89 using state_t = bitfield<state_count>;
90
91 struct accessibility {
92 string name, description;
93 };
94
95 struct config {
96 string title;
97 flags_t flags;
98 uint8_t mode;
99
100 size_t parent;
101 irect rect;
102
103 double_t fractional_scaling;
104
105 accessibility accessibility;
106 };
107
108 struct state {
109 uint8_t mode;
110 irect rect;
111 state_t flags;
112 int_t buffer_scale;
113 double_t fractional_scaling;
114 };
115
116 window(display_server* server, const config& conf, window* parent);
117
118 virtual ~window();
119
120 const config& get_config() const { return cfg; }
121
122 window* get_parent() const { return parent; }
123 window* get_root() const { return root; }
124
125 const ivec2& get_size() const { return state.rect.size; }
126 const ivec2& get_position() const { return state.rect.position; }
127
128 int get_width() const { return state.rect.size.x; }
129 int get_height() const { return state.rect.size.y; }
130 int get_pos_x() const { return state.rect.position.x; }
131 int get_pos_y() const { return state.rect.position.y; }
132
133 bool is_visible() const { return state.flags.test(state_visible); }
134 bool is_child() const { return state.flags.test(state_child); }
135 bool is_running() const { return state.flags.test(state_running); }
136 bool is_suspended() const { return state.flags.test(state_suspended); }
137
138 bool get_flag(uint8_t flag) const { return cfg.flags.test(flag); }
139
140 bool is_always_on_top() const { return get_flag(flag_always_on_top); }
141 bool is_borderless() const { return get_flag(flag_borderless); }
142 bool is_modal() const { return get_flag(flag_modal); }
143 bool is_passing_mouse() const { return get_flag(flag_pass_mouse); }
144 bool is_popup() const { return get_flag(flag_popup); }
145 bool is_resizable() const { return get_flag(flag_resizable); }
146 bool is_transparent() const { return get_flag(flag_transparent); }
147 bool is_no_focus() const { return get_flag(flag_no_focus); }
148
149
150 virtual bool set_flag(uint8_t flag, bool val) = 0;
151
152 bool set_always_on_top(bool val) { return set_flag(flag_always_on_top, val); }
153 bool set_borderless(bool val) { return set_flag(flag_borderless, val); }
154 bool set_modal(bool val) { return set_flag(flag_modal, val); }
155 bool set_passing_mouse(bool val) { return set_flag(flag_pass_mouse, val); }
156 bool set_popup(bool val) { return set_flag(flag_popup, val); }
157 bool set_resizable(bool val) { return set_flag(flag_resizable, val); }
158 bool set_transparent(bool val) { return set_flag(flag_transparent, val); }
159 bool set_no_focus(bool val) { return set_flag(flag_no_focus, val); }
160
161 virtual void initialize() = 0;
162 virtual void shutdown() = 0;
163
164 virtual void begin_frame();
165 virtual void end_frame();
166
167 virtual void* get_native_handle() = 0;
168
169protected:
170 display_server* const server;
171 window* const parent;
172 config cfg;
173 state state;
174 window* root;
175 unique_ptr<gfxsurface> gfx_surface;
176};
177
178template<typename DisplayT>
179class window_base : public window {
180public:
181 window_base(display_server* display, const config& conf, window* parent)
182 : window(display, conf, parent) {
183 }
184
185 using display_t = DisplayT;
186};
187
188}
189
190#endif // FENNEC_PLATFORM_INTERFACE_WINDOW_H
A header containing the definition for a container with an optionally present variable.
double double_t
A double-precision floating-point type, typically with a size of 64-bits.
Definition types.h:235
::uint8_t uint8_t
Unsigned 8-bit integer.
Definition types.h:272
signed int int_t
A signed integer type, size varies by implementation, but typically 32-bit.
Definition types.h:225
tvec2< int32_t > ivec2
A two-component signed integer vector.
Definition vector.h:153