Skip to content

Commit 515cd6a

Browse files
committed
add dmpty window class
1 parent c2eba81 commit 515cd6a

3 files changed

Lines changed: 131 additions & 62 deletions

File tree

src/ruisapp/application.hpp

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -35,53 +35,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3535
#include <utki/util.hpp>
3636

3737
#include "config.hpp"
38+
#include "window.hpp"
3839

3940
namespace ruisapp {
4041

41-
/**
42-
* @brief Desired window parameters.
43-
*/
44-
struct window_params {
45-
/**
46-
* @brief Desired dimensions of the window
47-
*/
48-
r4::vector2<unsigned> dims;
49-
50-
/**
51-
* @brief Window title.
52-
*/
53-
std::string title = "ruisapp";
54-
55-
/**
56-
* @brief Graphics buffer kind.
57-
* Color buffer is always present, so no enum entry for color buffer is needed.
58-
*/
59-
enum class buffer {
60-
depth,
61-
stencil,
62-
63-
enum_size
64-
};
65-
66-
/**
67-
* @brief Flags describing desired buffers for rendering context.
68-
* Color buffer is always there implicitly.
69-
*/
70-
utki::flags<buffer> buffers = false;
71-
72-
// version 0.0 means default version
73-
// clang-format off
74-
utki::version_duplet graphics_api_version = {
75-
.major = 0,
76-
.minor = 0
77-
};
78-
// clang-format on
79-
80-
window_params(r4::vector2<unsigned> dims) :
81-
dims(dims)
82-
{}
83-
};
84-
8542
/**
8643
* @brief Base singleton class of application.
8744
* An application should subclass this class and return an instance from the
@@ -142,7 +99,7 @@ class application : public utki::intrusive_singleton<application>
14299
const directories directory;
143100

144101
private:
145-
// TODO: make it window rectangle and track vieport separately,
102+
// TODO: make it window rectangle and track viewport separately,
146103
// use top-left coordinate system
147104

148105
// this is a viewport rectangle in coordinates that are as follows: x grows
@@ -162,44 +119,80 @@ class application : public utki::intrusive_singleton<application>
162119

163120
void update_window_rect(const ruis::rect& rect);
164121

165-
friend void update_window_rect(application& app, const ruis::rect& rect);
122+
friend void update_window_rect(
123+
application& app, //
124+
const ruis::rect& rect
125+
);
166126

167127
// pos is in usual window coordinates, y goes down.
168-
void handle_mouse_move(const r4::vector2<float>& pos, unsigned id)
128+
void handle_mouse_move(
129+
const r4::vector2<float>& pos, //
130+
unsigned id
131+
)
169132
{
170-
this->gui.send_mouse_move(pos, id);
133+
this->gui.send_mouse_move(
134+
pos, //
135+
id
136+
);
171137
}
172138

173-
friend void handle_mouse_move(application& app, const r4::vector2<float>& pos, unsigned id);
139+
friend void handle_mouse_move(
140+
application& app, //
141+
const r4::vector2<float>& pos,
142+
unsigned id
143+
);
174144

175145
// pos is in usual window coordinates, y goes down.
176-
void handle_mouse_button(bool is_down, const r4::vector2<float>& pos, ruis::mouse_button button, unsigned id)
146+
void handle_mouse_button(
147+
bool is_down, //
148+
const r4::vector2<float>& pos,
149+
ruis::mouse_button button,
150+
unsigned id
151+
)
177152
{
178-
this->gui.send_mouse_button(is_down, pos, button, id);
153+
this->gui.send_mouse_button(
154+
is_down, //
155+
pos,
156+
button,
157+
id
158+
);
179159
}
180160

181161
friend void handle_mouse_button(
182-
application& app,
162+
application& app, //
183163
bool is_down,
184164
const r4::vector2<float>& pos,
185165
ruis::mouse_button button,
186166
unsigned id
187167
);
188168

189-
void handle_mouse_hover(bool is_hovered, unsigned id)
169+
void handle_mouse_hover(
170+
bool is_hovered, //
171+
unsigned id
172+
)
190173
{
191-
this->gui.send_mouse_hover(is_hovered, id);
174+
this->gui.send_mouse_hover(
175+
is_hovered, //
176+
id
177+
);
192178
}
193179

194-
friend void handle_mouse_hover(application& app, bool is_hovered, unsigned pointer_id);
180+
friend void handle_mouse_hover(
181+
application& app, //
182+
bool is_hovered,
183+
unsigned pointer_id
184+
);
195185

196186
protected:
197187
/**
198188
* @brief Application constructor.
199189
* @param name - name of the application.
200190
* @param requested_window_params - requested window parameters.
201191
*/
202-
application(std::string name, const window_params& requested_window_params);
192+
application(
193+
std::string name, //
194+
const window_params& requested_window_params
195+
);
203196

204197
public:
205198
application(const application&) = delete;
@@ -228,20 +221,33 @@ class application : public utki::intrusive_singleton<application>
228221
// The idea with unicode_resolver parameter is that we don't want to calculate
229222
// the unicode unless it is really needed, thus postpone it as much as
230223
// possible.
231-
void handle_character_input(const ruis::gui::input_string_provider& string_provider, ruis::key key_code)
224+
void handle_character_input(
225+
const ruis::gui::input_string_provider& string_provider, //
226+
ruis::key key_code
227+
)
232228
{
233-
this->gui.send_character_input(string_provider, key_code);
229+
this->gui.send_character_input(
230+
string_provider, //
231+
key_code
232+
);
234233
}
235234

236235
friend void handle_character_input(
237-
application& app,
236+
application& app, //
238237
const ruis::gui::input_string_provider& string_provider,
239238
ruis::key key_code
240239
);
241240

242-
void handle_key_event(bool is_down, ruis::key key_code);
241+
void handle_key_event(
242+
bool is_down, //
243+
ruis::key key_code
244+
);
243245

244-
friend void handle_key_event(application& app, bool is_down, ruis::key key_code);
246+
friend void handle_key_event(
247+
application& app, //
248+
bool is_down,
249+
ruis::key key_code
250+
);
245251

246252
public:
247253
/**
@@ -290,7 +296,10 @@ class application : public utki::intrusive_singleton<application>
290296
* @param screen_size_mm - size of the display in millimeters.
291297
* @return Size of one display density pixel in pixels.
292298
*/
293-
static ruis::real get_pixels_per_pp(r4::vector2<unsigned> screen_size_pixels, r4::vector2<unsigned> screen_size_mm);
299+
static ruis::real get_pixels_per_pp(
300+
r4::vector2<unsigned> screen_size_pixels, //
301+
r4::vector2<unsigned> screen_size_mm
302+
);
294303
};
295304

296305
inline application& inst()

src/ruisapp/window.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "window.hpp"
2+
3+
using namespace ruisapp;

src/ruisapp/window.hpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#pragma once
2+
3+
#include <r4/vector.hpp>
4+
#include <utki/flags.hpp>
5+
6+
namespace ruisapp {
7+
8+
/**
9+
* @brief Desired window parameters.
10+
*/
11+
struct window_params {
12+
/**
13+
* @brief Desired dimensions of the window
14+
*/
15+
r4::vector2<unsigned> dims;
16+
17+
/**
18+
* @brief Window title.
19+
*/
20+
std::string title = "ruisapp";
21+
22+
/**
23+
* @brief Graphics buffer kind.
24+
* Color buffer is always present, so no enum entry for color buffer is needed.
25+
*/
26+
enum class buffer {
27+
depth,
28+
stencil,
29+
30+
enum_size
31+
};
32+
33+
/**
34+
* @brief Flags describing desired buffers for rendering context.
35+
* Color buffer is always there implicitly.
36+
*/
37+
utki::flags<buffer> buffers = false;
38+
39+
// version 0.0 means default version
40+
// clang-format off
41+
utki::version_duplet graphics_api_version = {
42+
.major = 0,
43+
.minor = 0
44+
};
45+
// clang-format on
46+
47+
window_params(r4::vector2<unsigned> dims) :
48+
dims(dims)
49+
{}
50+
};
51+
52+
class window
53+
{
54+
public:
55+
};
56+
57+
} // namespace ruisapp

0 commit comments

Comments
 (0)