]> 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 012f932502e5784124f5d2e6eaa67f651b0de50a..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
@@ -34,8 +34,9 @@ namespace canvas
 
       TextOSG(canvas::Text* text);
 
-      void setCharacterSize(float height);
+      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,31 +55,25 @@ namespace canvas
   Text::TextOSG::TextOSG(canvas::Text* text):
     _text_element(text)
   {
-
+    setBackdropImplementation(NO_DEPTH_BUFFER);
   }
 
   //----------------------------------------------------------------------------
-  void Text::TextOSG::setCharacterSize(float height)
+  void Text::TextOSG::setFontResolution(int res)
   {
-    TextBase::setCharacterSize(height);
-
-    unsigned int res = 32;
-    CanvasPtr canvas = _text_element->_canvas.lock();
-    if( canvas )
-    {
-      float factor = canvas->getSizeY() / canvas->getViewHeight();
-      res = height * factor;
-    }
-
-    // TODO different vertical/horizontal resolution?
-    // TODO configurable?
-    setFontResolution(res, res);
+    TextBase::setFontResolution(res, res);
   }
 
   //----------------------------------------------------------------------------
   void Text::TextOSG::setCharacterAspect(float aspect)
   {
-    TextBase::setCharacterSize(getCharacterHeight(), aspect);
+    setCharacterSize(getCharacterHeight(), aspect);
+  }
+
+  //----------------------------------------------------------------------------
+  void Text::TextOSG::setLineHeight(float factor)
+  {
+    setLineSpacing(factor - 1);
   }
 
   //----------------------------------------------------------------------------
@@ -187,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();
@@ -266,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,
@@ -274,38 +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("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();
   }
 
@@ -324,7 +327,7 @@ namespace canvas
   //----------------------------------------------------------------------------
   void Text::setFont(const char* name)
   {
-    _text->setFont( _canvas.lock()->getSystemAdapter()->getFont(name) );
+    _text->setFont( Canvas::getSystemAdapter()->getFont(name) );
   }
 
   //----------------------------------------------------------------------------