From ce83bbe3db755828faea0490ede53f8889ba0254 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Thu, 22 Mar 2012 22:39:19 +0100 Subject: menu/drawable_control: added size to controls and clip drawing if requested if requested (set_clipping_required) DrawableControl will use ClippingHelper to setup glScissor befor drawing the content. container will request clipping by default --- src/menu/container.cpp | 2 ++ src/menu/drawable_control.cpp | 60 +++++++++++++++++++++++++++++++++++-- src/menu/drawable_control.hpp | 17 +++++++++++ src/menu/software_mouse_pointer.cpp | 1 + 4 files changed, 77 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/menu/container.cpp b/src/menu/container.cpp index 05cb9fd4..4ac26548 100644 --- a/src/menu/container.cpp +++ b/src/menu/container.cpp @@ -35,11 +35,13 @@ namespace usdx Container::Container(Container* owner) : DrawableControl(owner), frame(NULL) { + set_clipping_required(true); } Container::Container(Container* owner, const ContainerHelper& add) : DrawableControl(owner, add), frame(NULL) { + set_clipping_required(true); } Container::~Container() diff --git a/src/menu/drawable_control.cpp b/src/menu/drawable_control.cpp index 6ee5100c..72486d42 100644 --- a/src/menu/drawable_control.cpp +++ b/src/menu/drawable_control.cpp @@ -28,6 +28,7 @@ #include "drawable_control.hpp" #include "container.hpp" +#include "clipping_helper.hpp" namespace usdx { @@ -35,14 +36,16 @@ namespace usdx log4cpp::Category::getInstance("usdx.menu.drawable_control"); DrawableControl::DrawableControl(Container* parent) - : Control(parent), position(0, 0), parent(parent) + : Control(parent), position(0, 0), size(0, 0), + clipping_required(false), parent(parent) { ContainerHelper(this).add(parent); } DrawableControl::DrawableControl(Container* parent, const ContainerHelper& helper) - : Control(parent), position(0, 0), parent(parent) + : Control(parent), position(0, 0), size(0, 0), + clipping_required(false), parent(parent) { helper.add(parent); } @@ -55,6 +58,17 @@ namespace usdx } } + bool DrawableControl::get_clipping_required(void) const + { + return clipping_required; + } + + void DrawableControl::set_clipping_required(const bool value) + { + boost::mutex::scoped_lock lock(clipping_required_mutex); + clipping_required = value; + } + void DrawableControl::repaint(void) { glLoadIdentity(); @@ -65,7 +79,19 @@ namespace usdx glTranslatef(position.get_x(), position.get_y(), 0.0f); } - Drawable::repaint(); + boost::mutex::scoped_lock clipping_lock(clipping_required_mutex); + if (clipping_required) { + clipping_lock.unlock(); + + boost::mutex::scoped_lock lock(size_mutex); + ClippingHelper clipping(Rectangle(position, size)); + + Drawable::repaint(); + } + else { + clipping_lock.unlock(); + Drawable::repaint(); + } } void DrawableControl::set_position(const Point& position) @@ -97,6 +123,34 @@ namespace usdx } + void DrawableControl::set_size(const Dimension &size) + { + boost::mutex::scoped_lock lock(size_mutex); + this->size = size; + } + + void DrawableControl::set_size(int width, int height) + { + boost::mutex::scoped_lock lock(size_mutex); + this->size = Dimension(width, height); + } + + + const Dimension& DrawableControl::get_size(void) const + { + return size; + } + + int DrawableControl::get_width(void) const + { + return size.get_width(); + } + + int DrawableControl::get_height(void) const + { + return size.get_height(); + } + DrawableControl::ContainerHelper::ContainerHelper(DrawableControl* self) : self(self) { diff --git a/src/menu/drawable_control.hpp b/src/menu/drawable_control.hpp index e954f291..64bd5a24 100644 --- a/src/menu/drawable_control.hpp +++ b/src/menu/drawable_control.hpp @@ -34,6 +34,7 @@ #include "drawable.hpp" #include "control.hpp" #include "utils/point.hpp" +#include "utils/dimension.hpp" namespace usdx { @@ -45,8 +46,14 @@ namespace usdx static log4cpp::Category& log; Point position; + Dimension size; + + bool clipping_required; boost::mutex position_mutex; + boost::mutex size_mutex; + boost::mutex clipping_required_mutex; + protected: Container* parent; @@ -61,6 +68,9 @@ namespace usdx }; DrawableControl(Container*, const ContainerHelper&); + bool get_clipping_required(void) const; + void set_clipping_required(const bool); + public: DrawableControl(Container*); virtual ~DrawableControl(); @@ -73,6 +83,13 @@ namespace usdx const Point& get_position(void) const; int get_left(void) const; int get_top(void) const; + + void set_size(const Dimension& size); + void set_size(int width, int height); + + const Dimension& get_size(void) const; + int get_width(void) const; + int get_height(void) const; }; }; diff --git a/src/menu/software_mouse_pointer.cpp b/src/menu/software_mouse_pointer.cpp index dfe67475..814f64b6 100644 --- a/src/menu/software_mouse_pointer.cpp +++ b/src/menu/software_mouse_pointer.cpp @@ -69,6 +69,7 @@ namespace usdx this->texture[7] = 0.0f; set_position(0, 0); + set_size(40, 40); texture_normal = new Texture("game/themes/Deluxe/interface/cursor.png"); texture_pressed = new Texture("game/themes/Deluxe/interface/cursor_pressed.png"); -- cgit v1.2.3