Canvas: bug fixing and add some helpers.

This commit is contained in:
Thomas Geymayer
2013-05-31 19:05:29 +02:00
parent 0f798289f0
commit 2fe9ad595f
9 changed files with 56 additions and 2 deletions

View 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)
{

View 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);

View File

@@ -160,7 +160,7 @@ namespace canvas
}
//----------------------------------------------------------------------------
bool ODGauge::serviceable(void)
bool ODGauge::serviceable() const
{
return _flags & AVAILABLE;
}

View 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.

View 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);

View 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);

View File

@@ -429,6 +429,9 @@ namespace canvas
*/
void update()
{
if( !vgHasContextSH() )
return;
if( _attributes_dirty & PATH )
{
const VGbitfield caps = VG_PATH_CAPABILITY_APPEND_TO

View 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);

View 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: