From fdfe3210cef3f53d30cfe036c24491a12ff771bd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 3 Sep 2013 10:17:06 +0000 Subject: [PATCH] Added beginings of Text implementation --- include/osgPresentation/Element | 27 ++++++++++++++++ include/osgPresentation/Group | 8 +++++ include/osgPresentation/Text | 6 ++++ src/osgPresentation/CMakeLists.txt | 3 ++ src/osgPresentation/Element.cpp | 52 ++++++++++++++++++++++++++++++ src/osgPresentation/Group.cpp | 18 +++++++++++ src/osgPresentation/Text.cpp | 33 +++++++++++++++++++ 7 files changed, 147 insertions(+) create mode 100644 src/osgPresentation/Element.cpp create mode 100644 src/osgPresentation/Group.cpp create mode 100644 src/osgPresentation/Text.cpp diff --git a/include/osgPresentation/Element b/include/osgPresentation/Element index 39cead2a4..3dc57bee8 100644 --- a/include/osgPresentation/Element +++ b/include/osgPresentation/Element @@ -15,6 +15,8 @@ #define OSGPRESENTATION_ELEMENT 1 #include +#include +#include namespace osgPresentation { @@ -31,6 +33,31 @@ class OSGPRESENTATION_EXPORT Element : public osgPresentation::Group META_Node(osgPresentation, Element); + virtual void traverse(osg::NodeVisitor& nv); + + /** Load the subgraph implementation of the element.*/ + virtual bool load() { return false; } + + /** Remove the the subgraph implementation, freeing up space.*/ + virtual bool unload() { removeChildren(0, getNumChildren()); return true; } + + /** Return true if the subgraph implementation has been loaded.*/ + virtual bool loaded() const { return getNumChildren()!=0; } + + + /** Do updates as part of the update traversal.*/ + virtual void updateTraversal(osgUtil::UpdateVisitor& uv); + + /** Do updates as part of the event traversal.*/ + virtual void eventTraversal(osgGA::EventVisitor& ev); + + /** Enter the element for the first time, starting any animations, movies, audio etc..*/ + virtual void enter() {} + + /** Leave the element, stopping any animations, movies, audio etc..*/ + virtual void leave() {} + + protected : virtual ~Element() {} diff --git a/include/osgPresentation/Group b/include/osgPresentation/Group index e1c1085a6..1e72eb903 100644 --- a/include/osgPresentation/Group +++ b/include/osgPresentation/Group @@ -19,6 +19,10 @@ namespace osgPresentation { + +typedef std::pair< osg::ref_ptr, std::string> ObjectDescription; +typedef std::list< ObjectDescription > PropertyList; + /** osgPresentation::Group */ class OSGPRESENTATION_EXPORT Group : public osg::MatrixTransform @@ -49,6 +53,10 @@ class OSGPRESENTATION_EXPORT Group : public osg::MatrixTransform return setUserValue(name, value); } + /** Get all types of Properties supported by Presentation Object type, return true if the Properties are supported, false otherwise.*/ + virtual bool getSupportedProperties(PropertyList&) { return false; } + + protected : virtual ~Group() {} diff --git a/include/osgPresentation/Text b/include/osgPresentation/Text index 239928bc4..2e08a76ee 100644 --- a/include/osgPresentation/Text +++ b/include/osgPresentation/Text @@ -31,6 +31,12 @@ class OSGPRESENTATION_EXPORT Text : public osgPresentation::Element META_Node(osgPresentation, Text); + /** load the text subgraph.*/ + virtual bool load(); + + /** Get all types of Properties supported by Presentation Object type, return true if the Properties are supported, false otherwise.*/ + virtual bool getSupportedProperties(PropertyList&); + protected : virtual ~Text() {} diff --git a/src/osgPresentation/CMakeLists.txt b/src/osgPresentation/CMakeLists.txt index 77a3f9a12..b6e8453c2 100644 --- a/src/osgPresentation/CMakeLists.txt +++ b/src/osgPresentation/CMakeLists.txt @@ -38,6 +38,9 @@ SET(TARGET_H # FIXME: For OS X, need flag for Framework or dylib SET(TARGET_SRC Cursor.cpp + Group.cpp + Element.cpp + Text.cpp deprecated/AnimationMaterial.cpp deprecated/CompileSlideCallback.cpp diff --git a/src/osgPresentation/Element.cpp b/src/osgPresentation/Element.cpp new file mode 100644 index 000000000..c5328adb3 --- /dev/null +++ b/src/osgPresentation/Element.cpp @@ -0,0 +1,52 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include + +using namespace osgPresentation; + + +void Element::traverse(osg::NodeVisitor& nv) +{ + if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR) + { + osgUtil::UpdateVisitor* uv = dynamic_cast(&nv); + if (uv) + { + updateTraversal(*uv); + return; + } + } + else if (nv.getVisitorType()==osg::NodeVisitor::EVENT_VISITOR) + { + osgGA::EventVisitor* ev = dynamic_cast(&nv); + if (ev) + { + eventTraversal(*ev); + return; + } + } + osgPresentation::Group::traverse(nv); +} + +void Element::updateTraversal(osgUtil::UpdateVisitor& uv) +{ + OSG_NOTICE<<"Element::updateTraversal()"< + +using namespace osgPresentation; + +/** Nothing to implement yet...*/ \ No newline at end of file diff --git a/src/osgPresentation/Text.cpp b/src/osgPresentation/Text.cpp new file mode 100644 index 000000000..3a38f865f --- /dev/null +++ b/src/osgPresentation/Text.cpp @@ -0,0 +1,33 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include +#include +#include + +using namespace osgPresentation; + + +bool Text::load() +{ + return false; +} + +bool Text::getSupportedProperties(PropertyList& pl) +{ + pl.push_back(ObjectDescription(new osg::StringValueObject("string",""), std::string("Text to render."))); + pl.push_back(ObjectDescription(new osg::StringValueObject("font",""), std::string("Font name."))); + pl.push_back(ObjectDescription(new osg::DoubleValueObject("width",1.0), std::string("Maximum width of the text."))); + pl.push_back(ObjectDescription(new osg::DoubleValueObject("character_size",0.06), std::string("Character size."))); + return true; +}