canvas::Text: fix global StateSet and line start cursor pos with empty line.
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -65,6 +65,8 @@ namespace canvas
|
||||
class TextOSG;
|
||||
osg::ref_ptr<TextOSG> _text;
|
||||
|
||||
virtual osg::StateSet* getOrCreateStateSet();
|
||||
|
||||
};
|
||||
|
||||
} // namespace canvas
|
||||
|
||||
Reference in New Issue
Block a user