From 3ec8616aa76390280c7b51696b731a85e070de0f Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 9 Apr 2012 18:09:28 +0200 Subject: utils/rectangle: removed external constructors and added helper constructors that generate a rectangle from GLint[4] or FTBBox are now helper functions to remove the external dependencies from the helper class --- src/menu/clipping_helper.cpp | 8 +++++++- src/menu/clipping_helper.hpp | 6 ++++++ src/menu/text.cpp | 9 ++++++++- src/menu/text.hpp | 7 +++++++ src/utils/rectangle.hpp | 14 -------------- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/menu/clipping_helper.cpp b/src/menu/clipping_helper.cpp index e12823cc..3f6bc4cd 100644 --- a/src/menu/clipping_helper.cpp +++ b/src/menu/clipping_helper.cpp @@ -31,6 +31,12 @@ namespace usdx log4cpp::Category& ClippingHelper::log = log4cpp::Category::getInstance("usdx.menu.clipping_helper"); + Rectangle ClippingHelper::makeRect(GLint box[4]) + { + return Rectangle(Point(box[0], box[1]), + Point(box[0] + box[2], box[1] + box[3])); + } + ClippingHelper::ClippingHelper(const Rectangle &rect) { was_enabled = glIsEnabled(GL_SCISSOR_TEST); @@ -40,7 +46,7 @@ namespace usdx if (was_enabled) { glGetIntegerv(GL_SCISSOR_BOX, scissor_box); - new_scissor_box = rect.intersect(Rectangle(scissor_box)); + new_scissor_box = new_scissor_box.intersect(makeRect(scissor_box)); } log << log4cpp::Priority::DEBUG << "Clipping (" diff --git a/src/menu/clipping_helper.hpp b/src/menu/clipping_helper.hpp index 119cc3c2..0435f01f 100644 --- a/src/menu/clipping_helper.hpp +++ b/src/menu/clipping_helper.hpp @@ -42,6 +42,12 @@ namespace usdx GLboolean was_enabled; GLint scissor_box[4]; + /** + * Helper to create a Rectangle object out of an GLint array. This + * array is returned by glGetIntegerv with GL_SCISSOR_BOX. The helper is + * used for converting the OpenGL array to the common internal format. + */ + static Rectangle makeRect(GLint box[4]); public: ClippingHelper(const Rectangle&); virtual ~ClippingHelper(); diff --git a/src/menu/text.cpp b/src/menu/text.cpp index 39df2e06..884809c9 100644 --- a/src/menu/text.cpp +++ b/src/menu/text.cpp @@ -62,9 +62,16 @@ namespace usdx } } + Rectangle Text::makeRect(const FTBBox& bbox) + { + return Rectangle(Point(bbox.Upper().X(), bbox.Upper().Y()), + Point(bbox.Lower().X(), bbox.Lower().Y())); + } + + void Text::realign(void) { - Rectangle bbox(font->BBox(text.c_str())); + Rectangle bbox = makeRect(font->BBox(text.c_str())); bbox.get_point1().set_y(font->Ascender()); bbox.get_point2().set_y(font->Descender()); valign->align(offset, bbox, get_size()); diff --git a/src/menu/text.hpp b/src/menu/text.hpp index b172b2c3..cb8e8dc4 100644 --- a/src/menu/text.hpp +++ b/src/menu/text.hpp @@ -83,6 +83,13 @@ namespace usdx */ void realign(void); + /** + * Helper to create a Rectangle object out of an FTBBox. This is + * used for converting the BBox from ftgl to the common internal format. + */ + static Rectangle makeRect(const FTBBox& bbox); + + protected: virtual void draw(void); diff --git a/src/utils/rectangle.hpp b/src/utils/rectangle.hpp index f3f4477d..b1e67ba8 100644 --- a/src/utils/rectangle.hpp +++ b/src/utils/rectangle.hpp @@ -27,8 +27,6 @@ #ifndef RECTANGLE_HPP #define RECTANGLE_HPP -#include - #include "point.hpp" #include "dimension.hpp" #include "math.hpp" @@ -66,18 +64,6 @@ namespace usdx { } - Rectangle(const T rectangle[]) : - point1(rectangle[0], rectangle[1]), - point2(rectangle[0] + rectangle[2], rectangle[1] + rectangle[3]) - { - } - - Rectangle(const FTBBox& bbox) : - point1((T)bbox.Upper().X(), (T)bbox.Upper().Y()), - point2((T)bbox.Lower().X(), (T)bbox.Lower().Y()) - { - } - Rectangle(const Rectangle& rectangle) : point1(rectangle.point1), point2(rectangle.point2) { -- cgit v1.2.3