From 40caf6163ff2e1274d71146c207fbde0c099b089 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 11 Apr 2012 21:14:59 +0200 Subject: menu/clipping_helper: made clipping working --- src/menu/clipping_helper.cpp | 19 ++++++++++--------- src/menu/clipping_helper.hpp | 3 ++- src/menu/drawable_control.cpp | 6 +----- src/utils/rectangle.hpp | 7 +++++++ 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(box[0] + box[2], box[1] + box[3])); } - ClippingHelper::ClippingHelper(const Rectangle &rect) + ClippingHelper::ClippingHelper(const Container *parent, + const Rectangle &rect) { was_enabled = glIsEnabled(GL_SCISSOR_TEST); - // calculate intersection of old clipping and requested clipping Rectangle 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 #include "utils/rectangle.hpp" +#include "container.hpp" namespace usdx { @@ -49,7 +50,7 @@ namespace usdx */ static Rectangle makeRect(GLint box[4]); public: - ClippingHelper(const Rectangle&); + ClippingHelper(const Container*, const Rectangle&); 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 offset(0, 0); - if (parent) - offset = parent->get_window_coords(); - - ClippingHelper clipping(Rectangle(offset + position, size)); + ClippingHelper clipping(parent, Rectangle(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()); -- cgit v1.2.3