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/drawable_control.cpp | 60 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) (limited to 'src/menu/drawable_control.cpp') 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) { -- cgit v1.2.3