aboutsummaryrefslogtreecommitdiffstats
path: root/src/menu
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-03-22 22:39:19 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-13 22:40:45 +0100
commitce83bbe3db755828faea0490ede53f8889ba0254 (patch)
treea59f99c0e31fbbc0d8b5500710e55af2f40b17e7 /src/menu
parent3d6a2c963c24212a0650f6dce5c1a47899f0e387 (diff)
downloadusdx-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')
-rw-r--r--src/menu/container.cpp2
-rw-r--r--src/menu/drawable_control.cpp60
-rw-r--r--src/menu/drawable_control.hpp17
-rw-r--r--src/menu/software_mouse_pointer.cpp1
4 files changed, 77 insertions, 3 deletions
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<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)
{
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<int> position;
+ Dimension<int> 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<int>& get_position(void) const;
int get_left(void) const;
int get_top(void) const;
+
+ void set_size(const Dimension<int>& size);
+ void set_size(int width, int height);
+
+ const Dimension<int>& 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");