aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-04-11 21:14:59 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-13 22:40:52 +0100
commit40caf6163ff2e1274d71146c207fbde0c099b089 (patch)
tree200d52aa09aa03cd199216d8ad172a57dcde62e0 /src
parentbb8e600a93557207410cf11977d19bb5bc133fcc (diff)
downloadusdx-40caf6163ff2e1274d71146c207fbde0c099b089.tar.gz
usdx-40caf6163ff2e1274d71146c207fbde0c099b089.tar.xz
usdx-40caf6163ff2e1274d71146c207fbde0c099b089.zip
menu/clipping_helper: made clipping working
Diffstat (limited to 'src')
-rw-r--r--src/menu/clipping_helper.cpp19
-rw-r--r--src/menu/clipping_helper.hpp3
-rw-r--r--src/menu/drawable_control.cpp6
-rw-r--r--src/utils/rectangle.hpp7
4 files changed, 20 insertions, 15 deletions
diff --git a/src/menu/clipping_helper.cpp b/src/menu/clipping_helper.cpp
index 3f6bc4cd..8b54d41b 100644
--- a/src/menu/clipping_helper.cpp
+++ b/src/menu/clipping_helper.cpp
@@ -37,26 +37,27 @@ namespace usdx
Point<int>(box[0] + box[2], box[1] + box[3]));
}
- ClippingHelper::ClippingHelper(const Rectangle<int> &rect)
+ ClippingHelper::ClippingHelper(const Container *parent,
+ const Rectangle<int> &rect)
{
was_enabled = glIsEnabled(GL_SCISSOR_TEST);
- // calculate intersection of old clipping and requested clipping
Rectangle<int> new_scissor_box(rect);
+ // calculate window coordinates of rectangle
+ if (parent) {
+ int offset = parent->get_size().get_height() - rect.get_bottom();
+ new_scissor_box.set_top(parent->get_window_coords().get_y() + offset);
+ }
+
+ // calculate intersection of old clipping and requested clipping
if (was_enabled) {
glGetIntegerv(GL_SCISSOR_BOX, scissor_box);
new_scissor_box = new_scissor_box.intersect(makeRect(scissor_box));
}
- log << log4cpp::Priority::DEBUG << "Clipping ("
- << new_scissor_box.get_width() << ", "
- << new_scissor_box.get_height() << ") at window offset: ("
- << new_scissor_box.get_top() << ", "
- << new_scissor_box.get_left() << ")";
-
// setup clipping box
- glScissor(new_scissor_box.get_top(), new_scissor_box.get_left(),
+ glScissor(new_scissor_box.get_left(), new_scissor_box.get_top(),
new_scissor_box.get_width(), new_scissor_box.get_height());
// enable clipping
diff --git a/src/menu/clipping_helper.hpp b/src/menu/clipping_helper.hpp
index 0435f01f..9132492c 100644
--- a/src/menu/clipping_helper.hpp
+++ b/src/menu/clipping_helper.hpp
@@ -31,6 +31,7 @@
#include <log4cpp/Category.hh>
#include "utils/rectangle.hpp"
+#include "container.hpp"
namespace usdx
{
@@ -49,7 +50,7 @@ namespace usdx
*/
static Rectangle<int> makeRect(GLint box[4]);
public:
- ClippingHelper(const Rectangle<int>&);
+ ClippingHelper(const Container*, const Rectangle<int>&);
virtual ~ClippingHelper();
};
};
diff --git a/src/menu/drawable_control.cpp b/src/menu/drawable_control.cpp
index 4d1f8355..9d00d3f1 100644
--- a/src/menu/drawable_control.cpp
+++ b/src/menu/drawable_control.cpp
@@ -79,11 +79,7 @@ namespace usdx
clipping_lock.unlock();
boost::mutex::scoped_lock lock(size_mutex);
- Point<int> offset(0, 0);
- if (parent)
- offset = parent->get_window_coords();
-
- ClippingHelper clipping(Rectangle<int>(offset + position, size));
+ ClippingHelper clipping(parent, Rectangle<int>(position, size));
Drawable::repaint();
}
else {
diff --git a/src/utils/rectangle.hpp b/src/utils/rectangle.hpp
index b1e67ba8..95f1a7b4 100644
--- a/src/utils/rectangle.hpp
+++ b/src/utils/rectangle.hpp
@@ -95,6 +95,13 @@ namespace usdx
return Math::min(point1.get_y(), point2.get_y());
}
+ void set_top(T value)
+ {
+ T height = get_height();
+ point1.set_y(value);
+ point2.set_y(value + height);
+ }
+
const T get_bottom(void) const
{
return Math::max(point1.get_y(), point2.get_y());