From 04d23659b33bf5372ed37ce6252cc34b3ce52a4d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 22 Feb 2017 12:07:43 +0000 Subject: [PATCH] Added the option for changing the type of the GlyphQuads::Coords --- examples/osgfont/osgfont.cpp | 8 +-- include/osgText/Text | 27 ++++++++++- src/osgText/Text.cpp | 94 +++++++++++++++++++----------------- src/osgWidget/Input.cpp | 9 +++- 4 files changed, 85 insertions(+), 53 deletions(-) diff --git a/examples/osgfont/osgfont.cpp b/examples/osgfont/osgfont.cpp index 77617a87a..37c71e136 100644 --- a/examples/osgfont/osgfont.cpp +++ b/examples/osgfont/osgfont.cpp @@ -19,10 +19,10 @@ void textInfo(osgText::Text* text) for(unsigned int i = 0; i < s.size(); i++) { - osg::Vec2 ul = (*gq.getCoords())[0 + (i * 4)]; // upperLeft - osg::Vec2 ll = (*gq.getCoords())[1 + (i * 4)]; // lowerLeft - osg::Vec2 lr = (*gq.getCoords())[2 + (i * 4)]; // lowerRight - osg::Vec2 ur = (*gq.getCoords())[3 + (i * 4)]; // upperRight + osg::Vec2 ul; gq.getCoord(0 + (i * 4), ul); // upperLeft + osg::Vec2 ll; gq.getCoord(1 + (i * 4), ll); // lowerLeft + osg::Vec2 lr; gq.getCoord(2 + (i * 4), lr); // lowerRight + osg::Vec2 ur; gq.getCoord(3 + (i * 4), ur); // upperRight osg::notify(osg::NOTICE) << "'" << static_cast(s[i]) << "':" diff --git a/include/osgText/Text b/include/osgText/Text index 7caa75446..aaebbd2b8 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -304,9 +304,14 @@ public: typedef osg::ref_ptr TexCoords; typedef osg::ref_ptr ColorCoords; - Glyphs _glyphs; - Coords2 _coords; +#ifdef NEW_APPROACH + typedef Coords3 Coords; +#else + typedef Coords2 Coords; +#endif + Glyphs _glyphs; + Coords _coords; #ifdef NEW_APPROACH Coords3 _transformedCoords; @@ -338,8 +343,26 @@ public: Glyphs& getGlyphs() { return _glyphs; } const Glyphs& getGlyphs() const { return _glyphs; } +#ifdef NEW_APPROACH + + void addCoord(const osg::Vec2& c) { _coords->push_back(osg::Vec3(c.x(), c.y(), 0.0f)); } + + void getCoord(unsigned int i, osg::Vec2& c) const { c.set((*_coords)[i].x(), (*_coords)[i].y()); } + void getCoord(unsigned int i, osg::Vec3& c) const { c = (*_coords)[i]; } + + Coords3& getCoords() { return _coords; } + const Coords3& getCoords() const { return _coords; } +#else + void addCoord(const osg::Vec2& c) { _coords->push_back(c); } + + void getCoord(unsigned int i, osg::Vec2& c) const { c = (*_coords)[i]; } + void getCoord(unsigned int i, osg::Vec3& c) const { c.set((*_coords)[i].x(), (*_coords)[i].y(), 0.0f); } + Coords2& getCoords() { return _coords; } const Coords2& getCoords() const { return _coords; } +#endif + + void addTexCoord(const osg::Vec2& tc) { _texcoords->push_back(tc); } #ifndef NEW_APPROACH Coords3& getTransformedCoords(unsigned int contexID) { return _transformedCoords[contexID]; } diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 23de98439..893bd9f95 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -445,16 +445,16 @@ void Text::computeGlyphRepresentation() osg::Vec2 lowLeft = local+osg::Vec2(0.0f-fHorizQuadMargin,0.0f-fVertQuadMargin); osg::Vec2 lowRight = local+osg::Vec2(width+fHorizQuadMargin,0.0f-fVertQuadMargin); osg::Vec2 upRight = local+osg::Vec2(width+fHorizQuadMargin,height+fVertQuadMargin); - glyphquad._coords->push_back(upLeft); - glyphquad._coords->push_back(lowLeft); - glyphquad._coords->push_back(lowRight); - glyphquad._coords->push_back(upRight); + glyphquad.addCoord(upLeft); + glyphquad.addCoord(lowLeft); + glyphquad.addCoord(lowRight); + glyphquad.addCoord(upRight); // set up the tex coords of the quad - glyphquad._texcoords->push_back(osg::Vec2(mintc.x(), maxtc.y())); - glyphquad._texcoords->push_back(osg::Vec2(mintc.x(), mintc.y())); - glyphquad._texcoords->push_back(osg::Vec2(maxtc.x(), mintc.y())); - glyphquad._texcoords->push_back(osg::Vec2(maxtc.x(), maxtc.y())); + glyphquad.addTexCoord(osg::Vec2(mintc.x(), maxtc.y())); + glyphquad.addTexCoord(osg::Vec2(mintc.x(), mintc.y())); + glyphquad.addTexCoord(osg::Vec2(maxtc.x(), mintc.y())); + glyphquad.addTexCoord(osg::Vec2(maxtc.x(), maxtc.y())); // move the cursor onto the next character. // also expand bounding box @@ -573,11 +573,11 @@ bool Text::computeAverageGlyphWidthAndHeight(float& avg_width, float& avg_height ++const_titr) { const GlyphQuads& glyphquad = const_titr->second; - const GlyphQuads::Coords2& coords2 = glyphquad._coords; - for (i = 0; i < coords2->size(); i += 4) + const GlyphQuads::Coords& coords = glyphquad._coords; + for (i = 0; i < coords->size(); i += 4) { - width = (*coords2)[i + 2].x() - (*coords2)[i].x(); - height = (*coords2)[i].y() - (*coords2)[i + 1].y(); + width = (*coords)[i + 2].x() - (*coords)[i].x(); + height = (*coords)[i].y() - (*coords)[i + 1].y(); running_width += width; running_height += height; @@ -842,7 +842,7 @@ void Text::computePositions(unsigned int contextID) const { GlyphQuads& glyphquad = titr->second; //OSG_NOTICE<<"Text::computePositions("<