aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/menu/clipping_helper.cpp6
-rw-r--r--src/utils/rectangle.hpp27
-rw-r--r--test/utils/rectangle.cpp4
3 files changed, 24 insertions, 13 deletions
diff --git a/src/menu/clipping_helper.cpp b/src/menu/clipping_helper.cpp
index b03a4e8c..e12823cc 100644
--- a/src/menu/clipping_helper.cpp
+++ b/src/menu/clipping_helper.cpp
@@ -46,11 +46,11 @@ namespace usdx
log << log4cpp::Priority::DEBUG << "Clipping ("
<< new_scissor_box.get_width() << ", "
<< new_scissor_box.get_height() << ") at window offset: ("
- << new_scissor_box.get_x() << ", "
- << new_scissor_box.get_y() << ")";
+ << new_scissor_box.get_top() << ", "
+ << new_scissor_box.get_left() << ")";
// setup clipping box
- glScissor(new_scissor_box.get_x(), new_scissor_box.get_y(),
+ glScissor(new_scissor_box.get_top(), new_scissor_box.get_left(),
new_scissor_box.get_width(), new_scissor_box.get_height());
// enable clipping
diff --git a/src/utils/rectangle.hpp b/src/utils/rectangle.hpp
index 39743e5d..f3f4477d 100644
--- a/src/utils/rectangle.hpp
+++ b/src/utils/rectangle.hpp
@@ -31,6 +31,7 @@
#include "point.hpp"
#include "dimension.hpp"
+#include "math.hpp"
namespace usdx
{
@@ -93,24 +94,34 @@ namespace usdx
return point2;
}
- const T get_x(void) const
+ const T get_width(void) const
{
- return point1.get_x();
+ return Math::abs(point2.get_x() - point1.get_x());
}
- const T get_y(void) const
+ const T get_height(void) const
{
- return point1.get_y();
+ return Math::abs(point2.get_y() - point1.get_y());
}
- const T get_width(void) const
+ const T get_top(void) const
{
- return point2.get_x() - point1.get_x();
+ return Math::min(point1.get_y(), point2.get_y());
}
- const T get_height(void) const
+ const T get_bottom(void) const
+ {
+ return Math::max(point1.get_y(), point2.get_y());
+ }
+
+ const T get_left(void) const
+ {
+ return Math::min(point1.get_x(), point2.get_x());
+ }
+
+ const T get_right(void) const
{
- return point2.get_y() - point1.get_y();
+ return Math::max(point1.get_x(), point2.get_x());
}
const Rectangle<T> intersect(const Rectangle<T>& inner) const
diff --git a/test/utils/rectangle.cpp b/test/utils/rectangle.cpp
index 0cfbece2..343d442f 100644
--- a/test/utils/rectangle.cpp
+++ b/test/utils/rectangle.cpp
@@ -54,8 +54,8 @@ namespace usdx
int coords[] = { 100, 150, 200, 250 };
Rectangle<int> rect(coords);
- CPPUNIT_ASSERT(rect.get_x() == 100);
- CPPUNIT_ASSERT(rect.get_y() == 150);
+ CPPUNIT_ASSERT(rect.get_left() == 100);
+ CPPUNIT_ASSERT(rect.get_top() == 150);
CPPUNIT_ASSERT(rect.get_width() == 200);
CPPUNIT_ASSERT(rect.get_height() == 250);
}