diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2012-03-22 22:39:19 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-13 22:40:45 +0100 |
commit | ce83bbe3db755828faea0490ede53f8889ba0254 (patch) | |
tree | a59f99c0e31fbbc0d8b5500710e55af2f40b17e7 /src/menu/drawable_control.cpp | |
parent | 3d6a2c963c24212a0650f6dce5c1a47899f0e387 (diff) | |
download | usdx-ce83bbe3db755828faea0490ede53f8889ba0254.tar.gz usdx-ce83bbe3db755828faea0490ede53f8889ba0254.tar.xz usdx-ce83bbe3db755828faea0490ede53f8889ba0254.zip |
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
Diffstat (limited to 'src/menu/drawable_control.cpp')
-rw-r--r-- | src/menu/drawable_control.cpp | 60 |
1 files changed, 57 insertions, 3 deletions
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<int>(position, size)); + + Drawable::repaint(); + } + else { + clipping_lock.unlock(); + Drawable::repaint(); + } } void DrawableControl::set_position(const Point<int>& position) @@ -97,6 +123,34 @@ namespace usdx } + void DrawableControl::set_size(const Dimension<int> &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<int>(width, height); + } + + + const Dimension<int>& 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) { |