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 +++++++ 4 files changed, 28 insertions(+), 2 deletions(-) (limited to 'src/menu') 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); -- cgit v1.2.3