canvas::Text: fix global StateSet and line start cursor pos with empty line.

This commit is contained in:
Thomas Geymayer
2014-08-31 19:24:58 +02:00
parent f33ad357e9
commit 85090180d0
3 changed files with 20 additions and 3 deletions

View File

@@ -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();

View File

@@ -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

View File

@@ -65,6 +65,8 @@ namespace canvas
class TextOSG;
osg::ref_ptr<TextOSG> _text;
virtual osg::StateSet* getOrCreateStateSet();
};
} // namespace canvas