From 10a5669330ba978c37d984a312ba1de7a2542503 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 1 Aug 2024 22:19:59 +0200 Subject: Draw and event position relative to parent (for pages) --- src/gui/StaticPage.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/gui/StaticPage.cpp (limited to 'src/gui/StaticPage.cpp') diff --git a/src/gui/StaticPage.cpp b/src/gui/StaticPage.cpp new file mode 100644 index 0000000..78fa497 --- /dev/null +++ b/src/gui/StaticPage.cpp @@ -0,0 +1,33 @@ +#include "../../include/gui/StaticPage.hpp" + +namespace gsr { + bool StaticPage::on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) { + const mgl::vec2f draw_pos = position + offset; + offset = draw_pos; + + // Process widgets by visibility (backwards) + for(auto it = widgets.rbegin(), end = widgets.rend(); it != end; ++it) { + if(!(*it)->on_event(event, window, offset)) + return false; + } + + return true; + } + + void StaticPage::draw(mgl::Window &window, mgl::vec2f offset) { + const mgl::vec2f draw_pos = position + offset; + offset = draw_pos; + + for(auto &widget : widgets) { + if(widget->move_to_top) { + widget->move_to_top = false; + std::swap(widget, widgets.back()); + } + widget->draw(window, offset); + } + + for(auto &widget : widgets) { + widget->draw(window, offset); + } + } +} \ No newline at end of file -- cgit v1.2.3