diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-03 21:09:13 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-03 21:09:13 +0100 |
commit | 1c9ebd15bb0ada387038b7278226a557d0de92ad (patch) | |
tree | 3a13e033a6407080781e5b47b896ee39a333e90a | |
parent | c2d177ad974a7dd7fda89f70e2c30077deb68a96 (diff) |
Add window set_view and get_view
m--------- | depends/mgl | 0 | ||||
-rw-r--r-- | include/mglpp/window/Window.hpp | 15 | ||||
-rw-r--r-- | src/window/Window.cpp | 14 |
3 files changed, 29 insertions, 0 deletions
diff --git a/depends/mgl b/depends/mgl -Subproject def772cc0efd7c22c6154c6d9f73df1a08fa267 +Subproject 61279a1947328df0b8004edebcbe405ab7b1c09 diff --git a/include/mglpp/window/Window.hpp b/include/mglpp/window/Window.hpp index 88a025c..2ef6526 100644 --- a/include/mglpp/window/Window.hpp +++ b/include/mglpp/window/Window.hpp @@ -18,6 +18,11 @@ namespace mgl { class Shader; class Vertex; + struct View { + vec2i position; + vec2i size; + }; + class Window { public: class Delegate { @@ -49,6 +54,16 @@ namespace mgl { void set_cursor_visible(bool visible); vec2i get_size() const; vec2i get_cursor_position() const; + + /* + This should be called every frame to retain the view. + Make sure to set the view back to the previous view after rendering items + by saving the previous view with |get_view| and then call + |set_view| with that saved view. + */ + void set_view(const View &new_view); + View get_view(); + WindowHandle get_system_handle() const; private: mgl_window window; diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 580737d..7f1fe38 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -112,6 +112,20 @@ namespace mgl { return { window.cursor_position.x, window.cursor_position.y }; } + void Window::set_view(const View &new_view) { + if(!window.window) + return; + mgl_window_set_view(&window, (mgl_view*)&new_view); + } + + View Window::get_view() { + View view; + if(!window.window) + return view; + mgl_window_get_view(&window, (mgl_view*)&view); + return view; + } + WindowHandle Window::get_system_handle() const { return window.window; } |