Added beginnings of new osgUI library, a replacement for osgWidget that works fully in 3D/stereo and is scriptable.

This commit is contained in:
Robert Osfield
2014-05-12 11:27:54 +00:00
parent 490b351330
commit ead92353fe
27 changed files with 1438 additions and 9 deletions

View File

@@ -0,0 +1,67 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 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.
*/
#ifndef OSGUI_ALIGNMENTSETTINGS
#define OSGUI_ALIGNMENTSETTINGS
#include <osg/Object>
#include <osg/BoundingBox>
#include <osg/Vec4>
#include <osgUI/Export>
namespace osgUI
{
class OSGUI_EXPORT AlignmentSettings : public osg::Object
{
public:
AlignmentSettings();
AlignmentSettings(const AlignmentSettings& textSettings, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgUI, AlignmentSettings);
enum Alignment
{
LEFT_TOP,
LEFT_CENTER,
LEFT_BOTTOM,
CENTER_TOP,
CENTER_CENTER,
CENTER_BOTTOM,
RIGHT_TOP,
RIGHT_CENTER,
RIGHT_BOTTOM,
LEFT_BASE_LINE,
CENTER_BASE_LINE,
RIGHT_BASE_LINE,
LEFT_BOTTOM_BASE_LINE,
CENTER_BOTTOM_BASE_LINE,
RIGHT_BOTTOM_BASE_LINE
};
void setAlignment(Alignment alignment) { _alignment = alignment; }
Alignment getAlignment() const { return _alignment; }
protected:
virtual ~AlignmentSettings() {}
Alignment _alignment;
};
}
#endif

57
include/osgUI/Export Normal file
View File

@@ -0,0 +1,57 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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.
*/
// The following symbol has a underscore suffix for compatibility.
#ifndef OSGUI_EXPORT_
#define OSGUI_EXPORT_ 1
#include<osg/Config>
#if defined(_MSC_VER) && defined(OSG_DISABLE_MSVC_WARNINGS)
#pragma warning( disable : 4244 )
#pragma warning( disable : 4251 )
#pragma warning( disable : 4267 )
#pragma warning( disable : 4275 )
#pragma warning( disable : 4290 )
#pragma warning( disable : 4786 )
#pragma warning( disable : 4305 )
#pragma warning( disable : 4996 )
#endif
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
# if defined( OSG_LIBRARY_STATIC )
# define OSGUI_EXPORT
# elif defined( OSGVIEWER_LIBRARY )
# define OSGUI_EXPORT __declspec(dllexport)
# else
# define OSGUI_EXPORT __declspec(dllimport)
#endif
#else
#define OSGUI_EXPORT
#endif
#endif
/**
\namespace osgViewer
The osgViewer library provides high level viewer functionality designed to make it easier to write a range of different types of viewers,
from viewers embedded in existing windows via SimpleViewer, through to highly scalable and flexible Viewer and Composite classes. A
set of event handlers add functionality to these viewers so that you can rapidly compose the viewer functionality tailored to your needs.
Finally the viewer classes can be adapted to work with a range of different window toolkit API's via GraphicsWindow implementations,
with native Win32, X11 and Carbon implementations on Windows, Unices and OSX respectively, and other window toolkits such as WxWidgets, Qt etc.
*/

View File

@@ -0,0 +1,66 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 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.
*/
#ifndef OSGUI_FRAMESETTINGS
#define OSGUI_FRAMESETTINGS
#include <osg/Object>
#include <osg/BoundingBox>
#include <osg/Vec4>
#include <osgUI/Export>
namespace osgUI
{
class OSGUI_EXPORT FrameSettings : public osg::Object
{
public:
FrameSettings();
FrameSettings(const FrameSettings& frameSettings, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgUI, FrameSettings);
enum Shape
{
NO_FRAME,
BOX,
PANEL
};
void setShape(Shape shape) { _shape = shape; }
Shape getShape() const { return _shape; }
enum Shadow
{
PLAIN,
SUNKEN,
RAISED
};
void setShadow(Shadow shadow) { _shadow = shadow; }
Shadow getShadow() const { return _shadow; }
void setLineWidth(float width) { _lineWidth = width; }
float getLineWidth() const { return _lineWidth; }
protected:
virtual ~FrameSettings() {}
Shape _shape;
Shadow _shadow;
float _lineWidth;
};
}
#endif

49
include/osgUI/Label Normal file
View File

@@ -0,0 +1,49 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 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.
*/
#ifndef OSGUI_LABEL
#define OSGUI_LABEL
#include <osgUI/Widget>
#include <osgText/Text>
namespace osgUI
{
class OSGUI_EXPORT Label : public osgUI::Widget
{
public:
Label();
Label(const Label& label, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Node(osgUI, Label);
void setText(const std::string& text) { _text = text; dirty(); }
std::string& getText() { return _text; }
const std::string& getText() const { return _text; }
virtual void createGraphicsImplementation();
protected:
virtual ~Label() {}
std::string _text;
// implementation detail
osg::ref_ptr<osgText::Text> _textDrawable;
osg::ref_ptr<osg::Geode> _textGeode;
};
}
#endif

50
include/osgUI/LineEdit Normal file
View File

@@ -0,0 +1,50 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 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.
*/
#ifndef OSGUI_LINEEDIT
#define OSGUI_LINEEDIT
#include <osgUI/Widget>
#include <osgText/Text>
namespace osgUI
{
class OSGUI_EXPORT LineEdit : public osgUI::Widget
{
public:
LineEdit();
LineEdit(const LineEdit& label, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Node(osgUI, LineEdit);
virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
void setText(const std::string& text) { _text = text; dirty(); }
std::string& getText() { return _text; }
const std::string& getText() const { return _text; }
virtual void createGraphicsImplementation();
protected:
virtual ~LineEdit() {}
std::string _text;
// implementation detail
osg::ref_ptr<osgText::Text> _textDrawable;
osg::ref_ptr<osg::Geode> _textGeode;
};
}
#endif

61
include/osgUI/Style Normal file
View File

@@ -0,0 +1,61 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 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.
*/
#ifndef OSGUI_STYLE
#define OSGUI_STYLE
#include <osg/Object>
#include <osg/BoundingBox>
#include <osg/Vec4>
#include <osgUI/AlignmentSettings>
#include <osgUI/FrameSettings>
#include <osgUI/TextSettings>
namespace osgUI
{
class OSGUI_EXPORT Style : public osg::Object
{
public:
Style();
Style(const Style& style, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgUI, Style);
static osg::ref_ptr<Style>& instance();
void setBackgroundColor(const osg::Vec4& color) { _backgroundColor = color; }
const osg::Vec4& getBackgroundColor() const { return _backgroundColor; }
void setTextColor(const osg::Vec4& color) { _textColor = color; }
const osg::Vec4& getTextColor() const { return _textColor; }
void setDisabledTextColor(const osg::Vec4& color) { _disabledTextColor = color; }
const osg::Vec4& getDisabledTextColor() const { return _disabledTextColor; }
virtual osg::Node* createPanel(const osg::BoundingBox& extents, const osg::Vec4& colour);
virtual osg::Node* createFrame(const osg::BoundingBox& extents, const FrameSettings* frameSettings);
virtual osg::Node* createText(const osg::BoundingBox& extents, const AlignmentSettings* as, const TextSettings* textSettings, const std::string& text);
virtual osg::Node* createIcon(const osg::BoundingBox& extents, const std::string& filename);
protected:
virtual ~Style() {}
osg::Vec4 _backgroundColor;
osg::Vec4 _textColor;
osg::Vec4 _disabledTextColor;
};
}
#endif

View File

@@ -0,0 +1,49 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 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.
*/
#ifndef OSGUI_TEXTSETTINGS
#define OSGUI_TEXTSETTINGS
#include <osg/Object>
#include <osg/BoundingBox>
#include <osg/Vec4>
#include <osgUI/Export>
namespace osgUI
{
class OSGUI_EXPORT TextSettings : public osg::Object
{
public:
TextSettings();
TextSettings(const TextSettings& textSettings, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgUI, TextSettings);
void setFont(const std::string& font) { _font = font; }
const std::string& getFont() const { return _font; }
void setCharacterSize(float characterSize) { _characterSize = characterSize; }
float getCharacterSize() const { return _characterSize; }
protected:
virtual ~TextSettings() {}
std::string _font;
float _characterSize;
};
}
#endif

116
include/osgUI/Widget Normal file
View File

@@ -0,0 +1,116 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 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.
*/
#ifndef OSGUI_WIDGET
#define OSGUI_WIDGET
#include <osg/Group>
#include <osg/BoundingBox>
#include <osgGA/Event>
#include <osgGA/EventVisitor>
#include <osgUI/Style>
namespace osgUI
{
class OSGUI_EXPORT Widget : public osg::Group
{
public:
Widget();
Widget(const Widget& widget, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Node(osgUI, Widget);
virtual void traverse(osg::NodeVisitor& nv);
virtual void traverseImplementation(osg::NodeVisitor& nv);
virtual bool handle(osgGA::EventVisitor* ev, osgGA::Event* event);
virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
virtual bool computePositionInLocalCoordinates(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, osg::Vec3& localPosition) const;
virtual void dirty();
virtual void createGraphics();
virtual void createGraphicsImplementation();
virtual void setExtents(const osg::BoundingBoxf& bb);
const osg::BoundingBoxf& getExtents() const { return _extents; }
void setStyle(Style* style) { _style = style; }
Style* getStyle() { return _style.get(); }
const Style* getStyle() const { return _style.get(); }
void setAlignmentSettings(AlignmentSettings* alignmentSettings) { _alignmentSettings = alignmentSettings; }
AlignmentSettings* getAlignmentSettings() { return _alignmentSettings.get(); }
const AlignmentSettings* getAlignmentSettings() const { return _alignmentSettings.get(); }
void setFrameSettings(FrameSettings* textSettings) { _frameSettings = textSettings; }
FrameSettings* getFrameSettings() { return _frameSettings.get(); }
const FrameSettings* getFrameSettings() const { return _frameSettings.get(); }
void setTextSettings(TextSettings* textSettings) { _textSettings = textSettings; }
TextSettings* getTextSettings() { return _textSettings.get(); }
const TextSettings* getTextSettings() const { return _textSettings.get(); }
enum FocusBehaviour
{
CLICK_TO_FOCUS,
FOCUS_FOLLOWS_POINTER,
EVENT_DRIVEN_FOCUS_DISABLED
};
void setFocusBehaviour(FocusBehaviour behaviour) { _focusBehaviour = behaviour; }
FocusBehaviour getFocusBehaviour() const { return _focusBehaviour; }
/** update the focus according to events.*/
virtual void updateFocus(osg::NodeVisitor& nv);
/** set whether the widget has focus or not.*/
virtual void setHasEventFocus(bool focus);
/** get whether the widget has focus or not.*/
virtual bool getHasEventFocus() const;
virtual osg::BoundingSphere computeBound() const;
/** update any focus related graphics+state to the focused state.*/
virtual void enter();
virtual void enterImplementation();
/** update any focus related graphics+state to the unfocused state.*/
virtual void leave();
virtual void leaveImplementation();
protected:
virtual ~Widget() {}
FocusBehaviour _focusBehaviour;
bool _hasEventFocus;
bool _graphicsInitialized;
osg::BoundingBoxf _extents;
osg::ref_ptr<Style> _style;
osg::ref_ptr<AlignmentSettings> _alignmentSettings;
osg::ref_ptr<FrameSettings> _frameSettings;
osg::ref_ptr<TextSettings> _textSettings;
};
}
#endif