Commit 048ece35 authored by Daniel Trstenjak's avatar Daniel Trstenjak
Browse files

Camera: convenience methods to find nested callback by type

parent 3547b985
......@@ -121,8 +121,33 @@ class OSG_EXPORT Callback : public virtual Object {
}
}
protected:
/** Convenience method to find a nested callback by type. */
template <typename T>
static T* findNestedCallback(osg::Callback* callback)
{
if (!callback)
return nullptr;
if (T* cb = dynamic_cast<T*>(callback))
return cb;
return findNestedCallback<T>(callback->getNestedCallback());
}
/** Convenience method to find a nested callback by type. */
template <typename T>
static const T* findNestedCallback(const osg::Callback* callback)
{
if (!callback)
return nullptr;
if (const T* cb = dynamic_cast<const T*>(callback))
return cb;
return findNestedCallback<T>(callback->getNestedCallback());
}
protected:
virtual ~Callback() {}
ref_ptr<Callback> _nestedCallback;
};
......
......@@ -642,6 +642,14 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
/** Get the const initial draw callback.*/
const DrawCallback* getInitialDrawCallback() const { return _initialDrawCallback.get(); }
/** Convenience method to find a nested initial draw callback by type. */
template <typename T>
T* findInitialDrawCallback() { return osg::Callback::findNestedCallback<T>(_initialDrawCallback.get()); }
/** Convenience method to find a nested initial draw callback by type. */
template <typename T>
const T* findInitialDrawCallback() const { return osg::Callback::findNestedCallback<T>(_initialDrawCallback.get()); }
/** Convenience method that sets DrawCallback Initial callback of the node if it doesn't exist, or nest it into the existing one. */
inline void addInitialDrawCallback(DrawCallback* nc)
{
......@@ -680,6 +688,14 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
/** Get the const pre draw callback.*/
const DrawCallback* getPreDrawCallback() const { return _preDrawCallback.get(); }
/** Convenience method to find a nested pre draw callback by type. */
template <typename T>
T* findPreDrawCallback() { return osg::Callback::findNestedCallback<T>(_preDrawCallback.get()); }
/** Convenience method to find a nested pre draw callback by type. */
template <typename T>
const T* findPreDrawCallback() const { return osg::Callback::findNestedCallback<T>(_preDrawCallback.get()); }
/** Convenience method that sets DrawCallback Initial callback of the node if it doesn't exist, or nest it into the existing one. */
inline void addPreDrawCallback(DrawCallback* nc)
{
......@@ -718,6 +734,14 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
/** Get the const post draw callback.*/
const DrawCallback* getPostDrawCallback() const { return _postDrawCallback.get(); }
/** Convenience method to find a nested post draw callback by type. */
template <typename T>
T* findPostDrawCallback() { return osg::Callback::findNestedCallback<T>(_postDrawCallback.get()); }
/** Convenience method to find a nested post draw callback by type. */
template <typename T>
const T* findPostDrawCallback() const { return osg::Callback::findNestedCallback<T>(_postDrawCallback.get()); }
/** Convenience method that sets DrawCallback Initial callback of the node if it doesn't exist, or nest it into the existing one. */
inline void addPostDrawCallback(DrawCallback* nc)
{
......@@ -756,6 +780,14 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
/** Get the const final draw callback.*/
const DrawCallback* getFinalDrawCallback() const { return _finalDrawCallback.get(); }
/** Convenience method to find a nested final draw callback by type. */
template <typename T>
T* findFinalDrawCallback() { return osg::Callback::findNestedCallback<T>(_finalDrawCallback.get()); }
/** Convenience method to find a nested final draw callback by type. */
template <typename T>
const T* findFinalDrawCallback() const { return osg::Callback::findNestedCallback<T>(_finalDrawCallback.get()); }
/** Convenience method that sets DrawCallback Initial callback of the node if it doesn't exist, or nest it into the existing one. */
inline void addFinalDrawCallback(DrawCallback* nc)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment