diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-08-07 21:27:36 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-08-07 21:27:36 +0200 |
commit | 1a49f86e9841035fe670f6b42a3c988f737267d2 (patch) | |
tree | 9059935a17d2599ae9f366975472314a9c89e052 /src/gui/CustomRendererWidget.cpp | |
parent | b709805cfac4d1fe1bfe28e497a3e48e224372a8 (diff) |
Add settings icon, close window when pressing the close button
Diffstat (limited to 'src/gui/CustomRendererWidget.cpp')
-rw-r--r-- | src/gui/CustomRendererWidget.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/gui/CustomRendererWidget.cpp b/src/gui/CustomRendererWidget.cpp new file mode 100644 index 0000000..98b7caf --- /dev/null +++ b/src/gui/CustomRendererWidget.cpp @@ -0,0 +1,41 @@ +#include "../../include/gui/CustomRendererWidget.hpp" + +#include <mglpp/window/Window.hpp> + +namespace gsr { + CustomRendererWidget::CustomRendererWidget(mgl::vec2f size) : size(size) {} + + bool CustomRendererWidget::on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) { + if(!visible || !event_handler) + return true; + return event_handler(event, window, position + offset, size); + } + + void CustomRendererWidget::draw(mgl::Window &window, mgl::vec2f offset) { + if(!visible) + return; + + const mgl::vec2f draw_pos = position + offset; + + mgl_scissor prev_scissor; + mgl_window_get_scissor(window.internal_window(), &prev_scissor); + + mgl_scissor new_scissor = { + mgl_vec2i{(int)draw_pos.x, (int)draw_pos.y}, + mgl_vec2i{(int)size.x, (int)size.y} + }; + mgl_window_set_scissor(window.internal_window(), &new_scissor); + + if(draw_handler) + draw_handler(window, draw_pos, size); + + mgl_window_set_scissor(window.internal_window(), &prev_scissor); + } + + mgl::vec2f CustomRendererWidget::get_size() { + if(!visible) + return {0.0f, 0.0f}; + + return size; + } +}
\ No newline at end of file |