From 09eacc82176c37fdc12c903061ffa3ff960ac4cf Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 9 Apr 2012 18:33:45 +0200 Subject: menu/container: calculate window coordinates the container have to keep the current window coordinates of its left, bottom corner, therefor they have to be recalculated on every size/position change (need virtual functions in DrawableControl) --- src/menu/container.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/menu/container.hpp | 37 ++++++++++++++++++++++++++++++++++++- src/menu/drawable_control.hpp | 4 ++-- 3 files changed, 74 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/menu/container.cpp b/src/menu/container.cpp index ce73c1c2..3cf8d770 100644 --- a/src/menu/container.cpp +++ b/src/menu/container.cpp @@ -91,4 +91,40 @@ namespace usdx { return window_coords; } + + void Container::recalculate_window_coords(void) + { + if (parent) { + assert(parent != NULL); + window_coords.set_x(parent->get_width() - + (get_left() + get_width())); + + window_coords.set_y(parent->get_height() - + (get_top() + get_height())); + } + } + + void Container::set_position(const Point& position) + { + DrawableControl::set_position(position); + recalculate_window_coords(); + } + + void Container::set_position(int left, int top) + { + DrawableControl::set_position(left, top); + recalculate_window_coords(); + } + + void Container::set_size(const Dimension& size) + { + DrawableControl::set_size(size); + recalculate_window_coords(); + } + + void Container::set_size(int width, int height) + { + DrawableControl::set_size(width, height); + recalculate_window_coords(); + } }; diff --git a/src/menu/container.hpp b/src/menu/container.hpp index 147a0d92..0fa4803e 100644 --- a/src/menu/container.hpp +++ b/src/menu/container.hpp @@ -45,11 +45,18 @@ namespace usdx Frame* frame; std::list controls; + /** + * Left bottom corner of the container in window coordinats. This is + * used for calculating the window coordinates of the containing + * controls for clipping, that only works with window coordinates. + */ + Point window_coords; + void recalculate_window_coords(void); + protected: Container(Container*, const ContainerHelper&); virtual void draw(void); - Point window_coords; public: Container(Container*); @@ -62,6 +69,34 @@ namespace usdx virtual void removeFrame(void); const Point& get_window_coords(void) const; + + /** + * Overwritten here to be able to recalculate the window coordinates. + * + * @see window_coords + */ + virtual void set_position(const Point& position); + + /** + * Overwritten here to be able to recalculate the window coordinates. + * + * @see window_coords + */ + virtual void set_position(int left, int top); + + /** + * Overwritten here to be able to recalculate the window coordinates. + * + * @see window_coords + */ + virtual void set_size(const Dimension& size); + + /** + * Overwritten here to be able to recalculate the window coordinates. + * + * @see window_coords + */ + virtual void set_size(int width, int height); }; }; diff --git a/src/menu/drawable_control.hpp b/src/menu/drawable_control.hpp index 7f353a5a..261f0514 100644 --- a/src/menu/drawable_control.hpp +++ b/src/menu/drawable_control.hpp @@ -77,8 +77,8 @@ namespace usdx void repaint(void); - void set_position(const Point& position); - void set_position(int left, int top); + virtual void set_position(const Point& position); + virtual void set_position(int left, int top); const Point& get_position(void) const; int get_left(void) const; -- cgit v1.2.3