Skip to content

Commit 496b9a6

Browse files
committed
add window_params::orientation, api breaking changes
1 parent 9fc4efd commit 496b9a6

3 files changed

Lines changed: 59 additions & 20 deletions

File tree

src/ruisapp/glue/sdl/glue.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,20 @@ class window_wrapper : public utki::destructable
502502
}
503503

504504
#if CFG_OS_NAME == CFG_OS_NAME_EMSCRIPTEN
505+
// Lock orientation if requested
506+
if (wp.orientation != ruisapp::orientation::dynamic) {
507+
int emsc_orient = [&]() {
508+
switch (wp.orientation) {
509+
default:
510+
case ruisapp::orientation::landscape:
511+
return EMSCRIPTEN_ORIENTATION_LANDSCAPE_PRIMARY;
512+
case ruisapp::orientation::portrait:
513+
return EMSCRIPTEN_ORIENTATION_PORTRAIT_PRIMARY;
514+
}
515+
}();
516+
emscripten_lock_orientation(emsc_orient);
517+
}
518+
505519
// Change to soft fullscreen mode before creating the window to set correct OpenGL viewport initially.
506520
{
507521
EmscriptenFullscreenStrategy strategy{};

src/ruisapp/window.hpp

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,59 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2626

2727
namespace ruisapp {
2828

29+
/**
30+
* @brief Widnow orientation policy.
31+
*/
32+
enum class orientation {
33+
/**
34+
* @brief Switch orientation when screen orientation changes.
35+
*/
36+
dynamic,
37+
38+
/**
39+
* @brief Stay always in landscape orientation.
40+
*/
41+
landscape,
42+
43+
/**
44+
* @brief Stay always in portrait orientation.
45+
*/
46+
portrait
47+
};
48+
49+
/**
50+
* @brief Graphics buffer kind.
51+
* Color buffer is always present, so no enum entry for color buffer is needed.
52+
*/
53+
enum class buffer {
54+
depth,
55+
stencil,
56+
57+
enum_size
58+
};
59+
2960
/**
3061
* @brief Desired window parameters.
3162
*/
3263
struct window_params {
3364
/**
3465
* @brief Desired dimensions of the window
3566
*/
36-
r4::vector2<unsigned> dims;
67+
r4::vector2<unsigned> dims = {300, 150};
3768

3869
/**
3970
* @brief Window title.
4071
*/
4172
std::string title = "ruisapp";
4273

4374
/**
44-
* @brief Graphics buffer kind.
45-
* Color buffer is always present, so no enum entry for color buffer is needed.
75+
* @brief Orientation policy.
4676
*/
47-
enum class buffer {
48-
depth,
49-
stencil,
77+
ruisapp::orientation orientation = ruisapp::orientation::dynamic;
5078

51-
enum_size
52-
};
79+
// TODO: remove
80+
// DEPRECATED: use ruisapp::buffer.
81+
using buffer = ruisapp::buffer;
5382

5483
/**
5584
* @brief Flags describing desired buffers for rendering context.
@@ -64,10 +93,6 @@ struct window_params {
6493
.minor = 0
6594
};
6695
// clang-format on
67-
68-
window_params(r4::vector2<unsigned> dims) :
69-
dims(dims)
70-
{}
7196
};
7297

7398
class window

tests/app/src/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ using namespace ruis::make;
5454
class application : public ruisapp::application{
5555
public:
5656
application() :
57-
ruisapp::application("ruis-tests", [](){
58-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
59-
ruisapp::window_params wp(r4::vector2<unsigned>(1024, 800));
60-
wp.buffers.set(ruisapp::window_params::buffer::depth);
61-
62-
return wp;
63-
}())
57+
ruisapp::application(
58+
"ruis-tests",
59+
{
60+
.dims = {1024, 800},
61+
.orientation = ruisapp::orientation::landscape,
62+
.buffers = {ruisapp::buffer::depth}
63+
}
64+
)
6465
{
6566
this->gui.init_standard_widgets(*this->get_res_file("../../res/ruis_res/"));
6667

6768
this->gui.context.get().loader().mount_res_pack(*this->get_res_file("res/"));
68-
// this->ResMan().MountResPack(ruis::ZipFile::New(papki::FSFile::New("res.zip")));
6969

7070
auto c = make_root_widget(this->gui.context);
7171
this->gui.set_root(c);

0 commit comments

Comments
 (0)