]> git.mxchange.org Git - simgear.git/commitdiff
canvas::Text: fix global StateSet and line start cursor pos with empty line.
authorThomas Geymayer <tomgey@gmail.com>
Sun, 31 Aug 2014 17:24:58 +0000 (19:24 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 31 Aug 2014 17:24:58 +0000 (19:24 +0200)
simgear/canvas/elements/CanvasElement.hxx
simgear/canvas/elements/CanvasText.cxx
simgear/canvas/elements/CanvasText.hxx

index 8f178b580291444514a524fb96a426ed5915be29..37e12deac95e271c7b611fc4675c906d140de618 100644 (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();
 
index 3e34a8f695b1eb5171d02f7ad76c0c4af4c85242..4b7600fc1dc4136ed08b706db5c756971ead4005 100644 (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
index 738a9737ae41daa50896d98ef85d21c987410f4b..27754dd6047668674850ae43e0fa02db00411755 100644 (file)
@@ -65,6 +65,8 @@ namespace canvas
       class TextOSG;
       osg::ref_ptr<TextOSG> _text;
 
+      virtual osg::StateSet* getOrCreateStateSet();
+
   };
 
 } // namespace canvas