]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/elements/CanvasText.cxx
Canvas: Respect clipping while event handling.
[simgear.git] / simgear / canvas / elements / CanvasText.cxx
index 031adba700a809c2f8d012dee3c3583d3450222f..f73a6ce8ccc2d7d14f352fad1294e061e00dbcd5 100644 (file)
@@ -20,7 +20,7 @@
 #include <simgear/canvas/Canvas.hxx>
 #include <simgear/canvas/CanvasSystemAdapter.hxx>
 #include <simgear/scene/util/parse_color.hxx>
-#include <simgear/structure/OSGVersion.hxx>
+#include <osg/Version>
 #include <osgText/Text>
 
 namespace simgear
@@ -36,6 +36,7 @@ namespace canvas
 
       void setFontResolution(int res);
       void setCharacterAspect(float aspect);
+      void setLineHeight(float factor);
       void setFill(const std::string& fill);
       void setBackgroundColor(const std::string& fill);
 
@@ -54,7 +55,7 @@ namespace canvas
   Text::TextOSG::TextOSG(canvas::Text* text):
     _text_element(text)
   {
-
+    setBackdropImplementation(NO_DEPTH_BUFFER);
   }
 
   //----------------------------------------------------------------------------
@@ -69,6 +70,12 @@ namespace canvas
     setCharacterSize(getCharacterHeight(), aspect);
   }
 
+  //----------------------------------------------------------------------------
+  void Text::TextOSG::setLineHeight(float factor)
+  {
+    setLineSpacing(factor - 1);
+  }
+
   //----------------------------------------------------------------------------
   void Text::TextOSG::setFill(const std::string& fill)
   {
@@ -175,7 +182,7 @@ namespace canvas
     if( !bb.valid() )
       return bb;
 
-#if SG_OSG_VERSION_LESS_THAN(3,1,0)
+#if OSG_VERSION_LESS_THAN(3,1,0)
     // TODO bounding box still doesn't seem always right (eg. with center
     //      horizontal alignment not completely accurate)
     bb._min.y() += _offset.y();
@@ -254,6 +261,39 @@ namespace canvas
   //----------------------------------------------------------------------------
   const std::string Text::TYPE_NAME = "text";
 
+  //----------------------------------------------------------------------------
+  void Text::staticInit()
+  {
+    if( isInit<Text>() )
+      return;
+
+    osg::ref_ptr<TextOSG> Text::*text = &Text::_text;
+
+    addStyle("fill", "color", &TextOSG::setFill, text);
+    addStyle("background", "color", &TextOSG::setBackgroundColor, text);
+    addStyle("character-size",
+             "numeric",
+             static_cast<
+               void (TextOSG::*)(float)
+             > (&TextOSG::setCharacterSize),
+             text);
+    addStyle("character-aspect-ratio",
+             "numeric",
+             &TextOSG::setCharacterAspect, text);
+    addStyle("line-height", "numeric", &TextOSG::setLineHeight, text);
+    addStyle("font-resolution", "numeric", &TextOSG::setFontResolution, text);
+    addStyle("padding", "numeric", &TextOSG::setBoundingBoxMargin, text);
+    //  TEXT              = 1 default
+    //  BOUNDINGBOX       = 2
+    //  FILLEDBOUNDINGBOX = 4
+    //  ALIGNMENT         = 8
+    addStyle<int>("draw-mode", "", &TextOSG::setDrawMode, text);
+    addStyle("max-width", "numeric", &TextOSG::setMaximumWidth, text);
+    addStyle("font", "", &Text::setFont);
+    addStyle("alignment", "", &Text::setAlignment);
+    addStyle("text", "", &Text::setText, false);
+  }
+
   //----------------------------------------------------------------------------
   Text::Text( const CanvasWeakPtr& canvas,
               const SGPropertyNode_ptr& node,
@@ -262,39 +302,13 @@ namespace canvas
     Element(canvas, node, parent_style, parent),
     _text( new Text::TextOSG(this) )
   {
+    staticInit();
+
     setDrawable(_text);
     _text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS);
     _text->setAxisAlignment(osgText::Text::USER_DEFINED_ROTATION);
     _text->setRotation(osg::Quat(osg::PI, osg::X_AXIS));
 
-    if( !isInit<Text>() )
-    {
-      osg::ref_ptr<TextOSG> Text::*text = &Text::_text;
-
-      addStyle("fill", "color", &TextOSG::setFill, text);
-      addStyle("background", "color", &TextOSG::setBackgroundColor, text);
-      addStyle("character-size",
-               "numeric",
-               static_cast<
-                 void (TextOSG::*)(float)
-               > (&TextOSG::setCharacterSize),
-               text);
-      addStyle("character-aspect-ratio",
-               "numeric",
-               &TextOSG::setCharacterAspect, text);
-      addStyle("font-resolution", "numeric", &TextOSG::setFontResolution, text);
-      addStyle("padding", "numeric", &TextOSG::setBoundingBoxMargin, text);
-      //  TEXT              = 1 default
-      //  BOUNDINGBOX       = 2
-      //  FILLEDBOUNDINGBOX = 4
-      //  ALIGNMENT         = 8
-      addStyle<int>("draw-mode", "", &TextOSG::setDrawMode, text);
-      addStyle("max-width", "numeric", &TextOSG::setMaximumWidth, text);
-      addStyle("font", "", &Text::setFont);
-      addStyle("alignment", "", &Text::setAlignment);
-      addStyle("text", "", &Text::setText);
-    }
-
     setupStyle();
   }
 
@@ -313,7 +327,7 @@ namespace canvas
   //----------------------------------------------------------------------------
   void Text::setFont(const char* name)
   {
-    _text->setFont( _canvas.lock()->getSystemAdapter()->getFont(name) );
+    _text->setFont( Canvas::getSystemAdapter()->getFont(name) );
   }
 
   //----------------------------------------------------------------------------