]> git.mxchange.org Git - simgear.git/commitdiff
Canvas: bug fixing and add some helpers.
authorThomas Geymayer <tomgey@gmail.com>
Fri, 31 May 2013 17:05:29 +0000 (19:05 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Fri, 31 May 2013 17:07:55 +0000 (19:07 +0200)
simgear/canvas/Canvas.cxx
simgear/canvas/Canvas.hxx
simgear/canvas/ODGauge.cxx
simgear/canvas/ODGauge.hxx
simgear/canvas/ShivaVG/include/vg/openvg.h
simgear/canvas/ShivaVG/src/shContext.c
simgear/canvas/elements/CanvasPath.cxx
simgear/canvas/elements/CanvasText.cxx
simgear/props/PropertyBasedElement.hxx

index 7651635b9ba79f1c6fa73aad33650e8cc9384bf7..74ccb60bd92136d1a690238156ee226041373aec 100644 (file)
@@ -106,6 +106,22 @@ namespace canvas
     return _canvas_mgr;
   }
 
+  //----------------------------------------------------------------------------
+  bool Canvas::isInit() const
+  {
+    return _texture.serviceable();
+  }
+
+  //----------------------------------------------------------------------------
+  void Canvas::destroy()
+  {
+    // TODO check if really not in use anymore
+    getProps()->getParent()
+              ->removeChild( getProps()->getName(),
+                             getProps()->getIndex(),
+                             false );
+  }
+
   //----------------------------------------------------------------------------
   void Canvas::addParentCanvas(const CanvasWeakPtr& canvas)
   {
@@ -161,6 +177,12 @@ namespace canvas
     );
   }
 
+  //----------------------------------------------------------------------------
+  GroupPtr Canvas::getRootGroup()
+  {
+    return _root_group;
+  }
+
   //----------------------------------------------------------------------------
   void Canvas::enableRendering(bool force)
   {
@@ -379,6 +401,12 @@ namespace canvas
     return _texture.getViewSize().y();
   }
 
+  //----------------------------------------------------------------------------
+  SGRect<int> Canvas::getViewport() const
+  {
+    return SGRect<int>(0, 0, getViewWidth(), getViewHeight());
+  }
+
   //----------------------------------------------------------------------------
   bool Canvas::handleMouseEvent(const MouseEventPtr& event)
   {
index c746e2876e3510baf5935f5ce8491d7ace364efa..8e73552865a71388241db96f7404118fe285592b 100644 (file)
@@ -23,6 +23,7 @@
 #include "ODGauge.hxx"
 
 #include <simgear/canvas/elements/CanvasGroup.hxx>
+#include <simgear/math/SGRect.hxx>
 #include <simgear/props/PropertyBasedElement.hxx>
 #include <simgear/props/propertyObject.hxx>
 #include <osg/NodeCallback>
@@ -78,6 +79,9 @@ namespace canvas
       void setCanvasMgr(CanvasMgr* canvas_mgr);
       CanvasMgr* getCanvasMgr() const;
 
+      bool isInit() const;
+      void destroy();
+
       /**
        * Add a canvas which should be marked as dirty upon any change to this
        * canvas.
@@ -99,6 +103,7 @@ namespace canvas
       void removeChildCanvas(const CanvasWeakPtr& canvas);
 
       GroupPtr createGroup(const std::string& name = "");
+      GroupPtr getRootGroup();
 
       /**
        * Enable rendering for the next frame
@@ -123,6 +128,7 @@ namespace canvas
 
       int getViewWidth() const;
       int getViewHeight() const;
+      SGRect<int> getViewport() const;
 
       bool handleMouseEvent(const MouseEventPtr& event);
 
index 17858db7514afb035a09786b4acd8a2e8730d12b..a95581a1daaaea833b12e053c4d2e7c6384c127c 100644 (file)
@@ -160,7 +160,7 @@ namespace canvas
   }
 
   //----------------------------------------------------------------------------
-  bool ODGauge::serviceable(void)
+  bool ODGauge::serviceable() const
   {
     return _flags & AVAILABLE;
   }
index 6c62823ef825f5c94d6e66b572f9c26a22dbded2..825b603bca7e4b959400af9b1a33fa755a6bcbba 100644 (file)
@@ -120,7 +120,7 @@ namespace canvas
        * Say if we can render to a texture.
        * @return true if rtt is available
        */
-      bool serviceable(void);
+      bool serviceable() const;
 
       /**
        * Get the OSG camera for drawing this gauge.
index 186f2f5b5db54fce211b6c5bda646e76f62002d6..0e86f9de6c41f7711ca74915dabfee08bfafa915 100644 (file)
@@ -627,6 +627,7 @@ VG_API_CALL const VGubyte * vgGetString(VGStringID name);
 #define OVG_SH_blend_dst_atop         1
 
 VG_API_CALL VGboolean vgCreateContextSH(VGint width, VGint height);
+VG_API_CALL VGboolean vgHasContextSH();
 VG_API_CALL void vgResizeSurfaceSH(VGint width, VGint height);
 VG_API_CALL void vgDestroyContextSH(void);
 
index 6f2fe5974081b3435728d0773d620d3dde3fb27f..647516b6ac7029a1847e7dc8bcac30f79621ea0f 100644 (file)
@@ -61,6 +61,11 @@ VG_API_CALL VGboolean vgCreateContextSH(VGint width, VGint height)
   return VG_TRUE;
 }
 
+VG_API_CALL VGboolean vgHasContextSH()
+{
+  return g_context != NULL;
+}
+
 VG_API_CALL void vgResizeSurfaceSH(VGint width, VGint height)
 {
   VG_GETCONTEXT(VG_NO_RETVAL);
index 045aabf5e0ff6799cc11553b65f6c2be736067be..a62ab0803e2921ac1096f339e8d3a0a93833e235 100644 (file)
@@ -429,6 +429,9 @@ namespace canvas
        */
       void update()
       {
+        if( !vgHasContextSH() )
+          return;
+
         if( _attributes_dirty & PATH )
         {
           const VGbitfield caps = VG_PATH_CAPABILITY_APPEND_TO
index a00cc1fa703f6b362a687034b6255dd273025c2d..469b19aa6fc596947ebe62566d642a927a2ce902 100644 (file)
@@ -20,6 +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 <osgText/Text>
 
 namespace simgear
@@ -167,10 +168,12 @@ namespace canvas
     if( !bb.valid() )
       return bb;
 
+#if SG_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();
     bb._max.y() += _offset.y();
+#endif
 
     _text_element->setBoundingBox(bb);
 
index 05dbcd1bae15d006d744bbf0929a29585e3d2028..f402b959c7e40a47ba9a34454762d6fca4ecca13 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <simgear/props/props.hxx>
 
+#include <boost/call_traits.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/weak_ptr.hpp>
 
@@ -47,6 +48,13 @@ namespace simgear
       SGConstPropertyNode_ptr getProps() const;
       SGPropertyNode_ptr getProps();
 
+      template<class T>
+      void set( const std::string& name,
+                typename boost::call_traits<T>::param_type val )
+      {
+        setValue(_node->getNode(name, true), val);
+      }
+
       virtual void setSelf(const PropertyBasedElementPtr& self);
 
     protected: