Canvas: bug fixing and add some helpers.

This commit is contained in:
Thomas Geymayer
2013-05-31 19:07:55 +02:00
parent 0f798289f0
commit 2fe9ad595f
9 changed files with 56 additions and 2 deletions
+28
View File
@@ -106,6 +106,22 @@ namespace canvas
return _canvas_mgr; 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) void Canvas::addParentCanvas(const CanvasWeakPtr& canvas)
{ {
@@ -161,6 +177,12 @@ namespace canvas
); );
} }
//----------------------------------------------------------------------------
GroupPtr Canvas::getRootGroup()
{
return _root_group;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void Canvas::enableRendering(bool force) void Canvas::enableRendering(bool force)
{ {
@@ -379,6 +401,12 @@ namespace canvas
return _texture.getViewSize().y(); return _texture.getViewSize().y();
} }
//----------------------------------------------------------------------------
SGRect<int> Canvas::getViewport() const
{
return SGRect<int>(0, 0, getViewWidth(), getViewHeight());
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool Canvas::handleMouseEvent(const MouseEventPtr& event) bool Canvas::handleMouseEvent(const MouseEventPtr& event)
{ {
+6
View File
@@ -23,6 +23,7 @@
#include "ODGauge.hxx" #include "ODGauge.hxx"
#include <simgear/canvas/elements/CanvasGroup.hxx> #include <simgear/canvas/elements/CanvasGroup.hxx>
#include <simgear/math/SGRect.hxx>
#include <simgear/props/PropertyBasedElement.hxx> #include <simgear/props/PropertyBasedElement.hxx>
#include <simgear/props/propertyObject.hxx> #include <simgear/props/propertyObject.hxx>
#include <osg/NodeCallback> #include <osg/NodeCallback>
@@ -78,6 +79,9 @@ namespace canvas
void setCanvasMgr(CanvasMgr* canvas_mgr); void setCanvasMgr(CanvasMgr* canvas_mgr);
CanvasMgr* getCanvasMgr() const; CanvasMgr* getCanvasMgr() const;
bool isInit() const;
void destroy();
/** /**
* Add a canvas which should be marked as dirty upon any change to this * Add a canvas which should be marked as dirty upon any change to this
* canvas. * canvas.
@@ -99,6 +103,7 @@ namespace canvas
void removeChildCanvas(const CanvasWeakPtr& canvas); void removeChildCanvas(const CanvasWeakPtr& canvas);
GroupPtr createGroup(const std::string& name = ""); GroupPtr createGroup(const std::string& name = "");
GroupPtr getRootGroup();
/** /**
* Enable rendering for the next frame * Enable rendering for the next frame
@@ -123,6 +128,7 @@ namespace canvas
int getViewWidth() const; int getViewWidth() const;
int getViewHeight() const; int getViewHeight() const;
SGRect<int> getViewport() const;
bool handleMouseEvent(const MouseEventPtr& event); bool handleMouseEvent(const MouseEventPtr& event);
+1 -1
View File
@@ -160,7 +160,7 @@ namespace canvas
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool ODGauge::serviceable(void) bool ODGauge::serviceable() const
{ {
return _flags & AVAILABLE; return _flags & AVAILABLE;
} }
+1 -1
View File
@@ -120,7 +120,7 @@ namespace canvas
* Say if we can render to a texture. * Say if we can render to a texture.
* @return true if rtt is available * @return true if rtt is available
*/ */
bool serviceable(void); bool serviceable() const;
/** /**
* Get the OSG camera for drawing this gauge. * Get the OSG camera for drawing this gauge.
@@ -627,6 +627,7 @@ VG_API_CALL const VGubyte * vgGetString(VGStringID name);
#define OVG_SH_blend_dst_atop 1 #define OVG_SH_blend_dst_atop 1
VG_API_CALL VGboolean vgCreateContextSH(VGint width, VGint height); 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 vgResizeSurfaceSH(VGint width, VGint height);
VG_API_CALL void vgDestroyContextSH(void); VG_API_CALL void vgDestroyContextSH(void);
+5
View File
@@ -61,6 +61,11 @@ VG_API_CALL VGboolean vgCreateContextSH(VGint width, VGint height)
return VG_TRUE; return VG_TRUE;
} }
VG_API_CALL VGboolean vgHasContextSH()
{
return g_context != NULL;
}
VG_API_CALL void vgResizeSurfaceSH(VGint width, VGint height) VG_API_CALL void vgResizeSurfaceSH(VGint width, VGint height)
{ {
VG_GETCONTEXT(VG_NO_RETVAL); VG_GETCONTEXT(VG_NO_RETVAL);
+3
View File
@@ -429,6 +429,9 @@ namespace canvas
*/ */
void update() void update()
{ {
if( !vgHasContextSH() )
return;
if( _attributes_dirty & PATH ) if( _attributes_dirty & PATH )
{ {
const VGbitfield caps = VG_PATH_CAPABILITY_APPEND_TO const VGbitfield caps = VG_PATH_CAPABILITY_APPEND_TO
+3
View File
@@ -20,6 +20,7 @@
#include <simgear/canvas/Canvas.hxx> #include <simgear/canvas/Canvas.hxx>
#include <simgear/canvas/CanvasSystemAdapter.hxx> #include <simgear/canvas/CanvasSystemAdapter.hxx>
#include <simgear/scene/util/parse_color.hxx> #include <simgear/scene/util/parse_color.hxx>
#include <simgear/structure/OSGVersion.hxx>
#include <osgText/Text> #include <osgText/Text>
namespace simgear namespace simgear
@@ -167,10 +168,12 @@ namespace canvas
if( !bb.valid() ) if( !bb.valid() )
return bb; return bb;
#if SG_OSG_VERSION_LESS_THAN(3,1,0)
// TODO bounding box still doesn't seem always right (eg. with center // TODO bounding box still doesn't seem always right (eg. with center
// horizontal alignment not completely accurate) // horizontal alignment not completely accurate)
bb._min.y() += _offset.y(); bb._min.y() += _offset.y();
bb._max.y() += _offset.y(); bb._max.y() += _offset.y();
#endif
_text_element->setBoundingBox(bb); _text_element->setBoundingBox(bb);
+8
View File
@@ -21,6 +21,7 @@
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <boost/call_traits.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp> #include <boost/weak_ptr.hpp>
@@ -47,6 +48,13 @@ namespace simgear
SGConstPropertyNode_ptr getProps() const; SGConstPropertyNode_ptr getProps() const;
SGPropertyNode_ptr getProps(); 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); virtual void setSelf(const PropertyBasedElementPtr& self);
protected: protected: