From 2fe9ad595f017d49a00f5579f724f81aa55d7c8a Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Fri, 31 May 2013 19:05:29 +0200 Subject: [PATCH] Canvas: bug fixing and add some helpers. --- simgear/canvas/Canvas.cxx | 28 ++++++++++++++++++++++ simgear/canvas/Canvas.hxx | 6 +++++ simgear/canvas/ODGauge.cxx | 2 +- simgear/canvas/ODGauge.hxx | 2 +- simgear/canvas/ShivaVG/include/vg/openvg.h | 1 + simgear/canvas/ShivaVG/src/shContext.c | 5 ++++ simgear/canvas/elements/CanvasPath.cxx | 3 +++ simgear/canvas/elements/CanvasText.cxx | 3 +++ simgear/props/PropertyBasedElement.hxx | 8 +++++++ 9 files changed, 56 insertions(+), 2 deletions(-) diff --git a/simgear/canvas/Canvas.cxx b/simgear/canvas/Canvas.cxx index 7651635b..74ccb60b 100644 --- a/simgear/canvas/Canvas.cxx +++ b/simgear/canvas/Canvas.cxx @@ -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 Canvas::getViewport() const + { + return SGRect(0, 0, getViewWidth(), getViewHeight()); + } + //---------------------------------------------------------------------------- bool Canvas::handleMouseEvent(const MouseEventPtr& event) { diff --git a/simgear/canvas/Canvas.hxx b/simgear/canvas/Canvas.hxx index c746e287..8e735528 100644 --- a/simgear/canvas/Canvas.hxx +++ b/simgear/canvas/Canvas.hxx @@ -23,6 +23,7 @@ #include "ODGauge.hxx" #include +#include #include #include #include @@ -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 getViewport() const; bool handleMouseEvent(const MouseEventPtr& event); diff --git a/simgear/canvas/ODGauge.cxx b/simgear/canvas/ODGauge.cxx index 17858db7..a95581a1 100644 --- a/simgear/canvas/ODGauge.cxx +++ b/simgear/canvas/ODGauge.cxx @@ -160,7 +160,7 @@ namespace canvas } //---------------------------------------------------------------------------- - bool ODGauge::serviceable(void) + bool ODGauge::serviceable() const { return _flags & AVAILABLE; } diff --git a/simgear/canvas/ODGauge.hxx b/simgear/canvas/ODGauge.hxx index 6c62823e..825b603b 100644 --- a/simgear/canvas/ODGauge.hxx +++ b/simgear/canvas/ODGauge.hxx @@ -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. diff --git a/simgear/canvas/ShivaVG/include/vg/openvg.h b/simgear/canvas/ShivaVG/include/vg/openvg.h index 186f2f5b..0e86f9de 100644 --- a/simgear/canvas/ShivaVG/include/vg/openvg.h +++ b/simgear/canvas/ShivaVG/include/vg/openvg.h @@ -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); diff --git a/simgear/canvas/ShivaVG/src/shContext.c b/simgear/canvas/ShivaVG/src/shContext.c index 6f2fe597..647516b6 100644 --- a/simgear/canvas/ShivaVG/src/shContext.c +++ b/simgear/canvas/ShivaVG/src/shContext.c @@ -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); diff --git a/simgear/canvas/elements/CanvasPath.cxx b/simgear/canvas/elements/CanvasPath.cxx index 045aabf5..a62ab080 100644 --- a/simgear/canvas/elements/CanvasPath.cxx +++ b/simgear/canvas/elements/CanvasPath.cxx @@ -429,6 +429,9 @@ namespace canvas */ void update() { + if( !vgHasContextSH() ) + return; + if( _attributes_dirty & PATH ) { const VGbitfield caps = VG_PATH_CAPABILITY_APPEND_TO diff --git a/simgear/canvas/elements/CanvasText.cxx b/simgear/canvas/elements/CanvasText.cxx index a00cc1fa..469b19aa 100644 --- a/simgear/canvas/elements/CanvasText.cxx +++ b/simgear/canvas/elements/CanvasText.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include 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); diff --git a/simgear/props/PropertyBasedElement.hxx b/simgear/props/PropertyBasedElement.hxx index 05dbcd1b..f402b959 100644 --- a/simgear/props/PropertyBasedElement.hxx +++ b/simgear/props/PropertyBasedElement.hxx @@ -21,6 +21,7 @@ #include +#include #include #include @@ -47,6 +48,13 @@ namespace simgear SGConstPropertyNode_ptr getProps() const; SGPropertyNode_ptr getProps(); + template + void set( const std::string& name, + typename boost::call_traits::param_type val ) + { + setValue(_node->getNode(name, true), val); + } + virtual void setSelf(const PropertyBasedElementPtr& self); protected: -- 2.39.5