From 85090180d0df534a876829ffa3bbd90e28d4606c Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sun, 31 Aug 2014 19:24:58 +0200 Subject: [PATCH] canvas::Text: fix global StateSet and line start cursor pos with empty line. --- simgear/canvas/elements/CanvasElement.hxx | 2 +- simgear/canvas/elements/CanvasText.cxx | 19 +++++++++++++++++-- simgear/canvas/elements/CanvasText.hxx | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx index 8f178b58..37e12dea 100644 --- a/simgear/canvas/elements/CanvasElement.hxx +++ b/simgear/canvas/elements/CanvasElement.hxx @@ -564,7 +564,7 @@ namespace canvas /** * Get stateset of drawable if available or use transform otherwise */ - osg::StateSet* getOrCreateStateSet(); + virtual osg::StateSet* getOrCreateStateSet(); void setupStyle(); diff --git a/simgear/canvas/elements/CanvasText.cxx b/simgear/canvas/elements/CanvasText.cxx index 3e34a8f6..4b7600fc 100644 --- a/simgear/canvas/elements/CanvasText.cxx +++ b/simgear/canvas/elements/CanvasText.cxx @@ -148,8 +148,12 @@ namespace canvas //---------------------------------------------------------------------------- osg::Vec2 TextLine::cursorPos(size_t i) const { - if( !_quads || i > size() ) - return osg::Vec2(-1, -1); + if( !_quads ) + return osg::Vec2(0, 0); + + if( i > size() ) + // Position after last character if out of range (TODO better exception?) + i = size(); osg::Vec2 pos(0, _text->_offset.y() + _line * _text->lineHeight()); @@ -829,5 +833,16 @@ namespace canvas return _text->lineAt(line).cursorPos(character); } + //---------------------------------------------------------------------------- + osg::StateSet* Text::getOrCreateStateSet() + { + if( !_transform.valid() ) + return 0; + + // Only check for StateSet on Transform, as the text stateset is shared + // between all text instances using the same font (texture). + return _transform->getOrCreateStateSet(); + } + } // namespace canvas } // namespace simgear diff --git a/simgear/canvas/elements/CanvasText.hxx b/simgear/canvas/elements/CanvasText.hxx index 738a9737..27754dd6 100644 --- a/simgear/canvas/elements/CanvasText.hxx +++ b/simgear/canvas/elements/CanvasText.hxx @@ -65,6 +65,8 @@ namespace canvas class TextOSG; osg::ref_ptr _text; + virtual osg::StateSet* getOrCreateStateSet(); + }; } // namespace canvas -- 2.39.5