Added beginnings of new osgUI library, a replacement for osgWidget that works fully in 3D/stereo and is scriptable.
This commit is contained in:
@@ -3,7 +3,7 @@ SET(TARGET_SRC
|
||||
osgtransferfunction.cpp
|
||||
)
|
||||
|
||||
SET(TARGET_ADDED_LIBRARIES osgVolume osgManipulator)
|
||||
SET(TARGET_ADDED_LIBRARIES osgVolume osgUI osgManipulator)
|
||||
|
||||
#### end var setup ###
|
||||
SETUP_EXAMPLE(osgtransferfunction)
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
#include <osg/Group>
|
||||
#include <osg/TransferFunction>
|
||||
|
||||
#include <osgGA/Widget>
|
||||
#include <osgUI/Widget>
|
||||
|
||||
#define OSGUI_EXPORT
|
||||
|
||||
namespace osgUI
|
||||
{
|
||||
|
||||
class OSGUI_EXPORT TransferFunctionWidget : public osgGA::Widget
|
||||
class OSGUI_EXPORT TransferFunctionWidget : public osgUI::Widget
|
||||
{
|
||||
public:
|
||||
TransferFunctionWidget(osg::TransferFunction1D* tf=0);
|
||||
|
||||
67
include/osgUI/AlignmentSettings
Normal file
67
include/osgUI/AlignmentSettings
Normal 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
57
include/osgUI/Export
Normal 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.
|
||||
*/
|
||||
|
||||
|
||||
66
include/osgUI/FrameSettings
Normal file
66
include/osgUI/FrameSettings
Normal 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
49
include/osgUI/Label
Normal 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
50
include/osgUI/LineEdit
Normal 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
61
include/osgUI/Style
Normal 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
|
||||
49
include/osgUI/TextSettings
Normal file
49
include/osgUI/TextSettings
Normal 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
116
include/osgUI/Widget
Normal 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
|
||||
@@ -7,15 +7,15 @@ IF(MSVC80 OR MSVC90)
|
||||
ENDIF()
|
||||
|
||||
#the old construct SUBDIRS( was substituded by ADD_SUBDIRECTORY that is to be preferred according on CMake docs.
|
||||
FOREACH( mylibfolder
|
||||
FOREACH( mylibfolder
|
||||
OpenThreads
|
||||
osg
|
||||
osgDB
|
||||
osgUtil
|
||||
osgGA
|
||||
osgText
|
||||
osgDB
|
||||
osgUtil
|
||||
osgGA
|
||||
osgText
|
||||
osgViewer
|
||||
osgAnimation
|
||||
osgAnimation
|
||||
osgFX
|
||||
osgManipulator
|
||||
osgParticle
|
||||
@@ -24,6 +24,7 @@ FOREACH( mylibfolder
|
||||
osgSim
|
||||
osgTerrain
|
||||
osgWidget
|
||||
osgUI
|
||||
osgVolume
|
||||
osgWrappers/serializers
|
||||
osgWrappers/deprecated-dotosg
|
||||
|
||||
29
src/osgUI/AlignmentSettings.cpp
Normal file
29
src/osgUI/AlignmentSettings.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/* -*-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.
|
||||
*/
|
||||
|
||||
#include <osgUI/Style>
|
||||
#include <osg/Geode>
|
||||
#include <osgText/Text>
|
||||
|
||||
using namespace osgUI;
|
||||
|
||||
AlignmentSettings::AlignmentSettings():
|
||||
_alignment(AlignmentSettings::LEFT_BOTTOM)
|
||||
{
|
||||
}
|
||||
|
||||
AlignmentSettings::AlignmentSettings(const AlignmentSettings& alingmentSettings, const osg::CopyOp& copyop):
|
||||
osg::Object(alingmentSettings, copyop),
|
||||
_alignment(alingmentSettings._alignment)
|
||||
{
|
||||
}
|
||||
41
src/osgUI/CMakeLists.txt
Normal file
41
src/osgUI/CMakeLists.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
IF (DYNAMIC_OPENSCENEGRAPH)
|
||||
ADD_DEFINITIONS(-DOSGGA_LIBRARY)
|
||||
ELSE (DYNAMIC_OPENSCENEGRAPH)
|
||||
ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC)
|
||||
ENDIF(DYNAMIC_OPENSCENEGRAPH)
|
||||
|
||||
SET(LIB_NAME osgUI)
|
||||
SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME})
|
||||
SET(TARGET_H
|
||||
${HEADER_PATH}/Export
|
||||
${HEADER_PATH}/Widget
|
||||
${HEADER_PATH}/Label
|
||||
${HEADER_PATH}/LineEdit
|
||||
${HEADER_PATH}/Style
|
||||
${HEADER_PATH}/AlignmentSettings
|
||||
${HEADER_PATH}/FrameSettings
|
||||
${HEADER_PATH}/TextSettings
|
||||
)
|
||||
|
||||
SET(TARGET_SRC
|
||||
Widget.cpp
|
||||
Label.cpp
|
||||
LineEdit.cpp
|
||||
Style.cpp
|
||||
AlignmentSettings.cpp
|
||||
FrameSettings.cpp
|
||||
TextSettings.cpp
|
||||
${OPENSCENEGRAPH_VERSIONINFO_RC}
|
||||
)
|
||||
|
||||
SET(TARGET_LIBRARIES
|
||||
osgDB
|
||||
osgUtil
|
||||
osgText
|
||||
osg
|
||||
OpenThreads
|
||||
)
|
||||
|
||||
SETUP_LIBRARY(${LIB_NAME})
|
||||
|
||||
31
src/osgUI/FrameSettings.cpp
Normal file
31
src/osgUI/FrameSettings.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/* -*-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.
|
||||
*/
|
||||
|
||||
#include <osgUI/FrameSettings>
|
||||
|
||||
using namespace osgUI;
|
||||
|
||||
FrameSettings::FrameSettings():
|
||||
_shape(FrameSettings::NO_FRAME),
|
||||
_shadow(FrameSettings::PLAIN),
|
||||
_lineWidth(0.01)
|
||||
{
|
||||
}
|
||||
|
||||
FrameSettings::FrameSettings(const FrameSettings& frameSettings, const osg::CopyOp& copyop):
|
||||
osg::Object(frameSettings, copyop),
|
||||
_shape(frameSettings._shape),
|
||||
_shadow(frameSettings._shadow),
|
||||
_lineWidth(frameSettings._lineWidth)
|
||||
{
|
||||
}
|
||||
40
src/osgUI/Label.cpp
Normal file
40
src/osgUI/Label.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*-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.
|
||||
*/
|
||||
|
||||
|
||||
#include <osgUI/Label>
|
||||
#include <osgText/String>
|
||||
#include <osgText/Font>
|
||||
#include <osgText/Text>
|
||||
|
||||
using namespace osgUI;
|
||||
|
||||
Label::Label()
|
||||
{
|
||||
}
|
||||
|
||||
Label::Label(const osgUI::Label& label, const osg::CopyOp& copyop):
|
||||
Widget(label, copyop),
|
||||
_text(label._text)
|
||||
{
|
||||
}
|
||||
|
||||
void Label::createGraphicsImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"Label::createGraphicsImplementation()"<<std::endl;
|
||||
|
||||
Widget::createGraphicsImplementation();
|
||||
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
addChild(style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text));
|
||||
}
|
||||
69
src/osgUI/LineEdit.cpp
Normal file
69
src/osgUI/LineEdit.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/* -*-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.
|
||||
*/
|
||||
|
||||
|
||||
#include <osgUI/LineEdit>
|
||||
#include <osgText/String>
|
||||
#include <osgText/Font>
|
||||
#include <osgText/Text>
|
||||
|
||||
using namespace osgUI;
|
||||
|
||||
LineEdit::LineEdit()
|
||||
{
|
||||
}
|
||||
|
||||
LineEdit::LineEdit(const osgUI::LineEdit& label, const osg::CopyOp& copyop):
|
||||
Widget(label, copyop),
|
||||
_text(label._text)
|
||||
{
|
||||
}
|
||||
|
||||
bool LineEdit::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event)
|
||||
{
|
||||
osgGA::GUIEventAdapter* ea = event->asGUIEventAdapter();
|
||||
if (!ea) return false;
|
||||
|
||||
switch(ea->getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||
if (ea->getKey()==osgGA::GUIEventAdapter::KEY_BackSpace ||
|
||||
ea->getKey()==osgGA::GUIEventAdapter::KEY_Delete)
|
||||
{
|
||||
if (!_text.empty()) _text.erase(_text.size()-1, 1);
|
||||
}
|
||||
else if (ea->getKey()>=32 && ea->getKey()<=0xff00)
|
||||
{
|
||||
_text.push_back(ea->getKey());
|
||||
}
|
||||
dirty();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LineEdit::createGraphicsImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"LineEdit::createGraphicsImplementation()"<<std::endl;
|
||||
|
||||
Widget::createGraphicsImplementation();
|
||||
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
|
||||
removeChildren(0, getNumChildren());
|
||||
|
||||
addChild(style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text));
|
||||
}
|
||||
75
src/osgUI/Style.cpp
Normal file
75
src/osgUI/Style.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/* -*-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.
|
||||
*/
|
||||
|
||||
#include <osgUI/Style>
|
||||
#include <osg/Geode>
|
||||
#include <osgText/Text>
|
||||
|
||||
using namespace osgUI;
|
||||
|
||||
osg::ref_ptr<Style>& Style::instance()
|
||||
{
|
||||
static osg::ref_ptr<Style> s_style = new Style;
|
||||
return s_style;
|
||||
}
|
||||
|
||||
OSG_INIT_SINGLETON_PROXY(StyleSingletonProxy, Style::instance())
|
||||
|
||||
Style::Style()
|
||||
{
|
||||
}
|
||||
|
||||
Style::Style(const Style& style, const osg::CopyOp& copyop):
|
||||
osg::Object(style, copyop)
|
||||
{
|
||||
}
|
||||
|
||||
osg::Node* Style::createPanel(const osg::BoundingBox& extents, const osg::Vec4& colour)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::Node* Style::createFrame(const osg::BoundingBox& extents, const FrameSettings* frameSettings)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::Node* Style::createText(const osg::BoundingBox& extents, const AlignmentSettings* as, const TextSettings* ts, const std::string& text)
|
||||
{
|
||||
osg::ref_ptr<osg::Geode> textGeode = new osg::Geode;
|
||||
osg::ref_ptr<osgText::Text> textDrawable = new osgText::Text;
|
||||
|
||||
textGeode->addDrawable(textDrawable.get());
|
||||
|
||||
textDrawable->setText(text);
|
||||
|
||||
if (ts)
|
||||
{
|
||||
textDrawable->setFont(ts->getFont());
|
||||
textDrawable->setCharacterSize(ts->getCharacterSize());
|
||||
}
|
||||
|
||||
if (as)
|
||||
{
|
||||
osgText::TextBase::AlignmentType alignmentType = static_cast<osgText::TextBase::AlignmentType>(as->getAlignment());
|
||||
textDrawable->setAlignment(alignmentType);
|
||||
}
|
||||
|
||||
return textGeode.release();
|
||||
}
|
||||
|
||||
osg::Node* Style::createIcon(const osg::BoundingBox& extents, const std::string& filename)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
31
src/osgUI/TextSettings.cpp
Normal file
31
src/osgUI/TextSettings.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/* -*-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.
|
||||
*/
|
||||
|
||||
#include <osgUI/TextSettings>
|
||||
#include <osg/Geode>
|
||||
#include <osgText/Text>
|
||||
|
||||
using namespace osgUI;
|
||||
|
||||
TextSettings::TextSettings():
|
||||
_characterSize(1.0)
|
||||
{
|
||||
}
|
||||
|
||||
TextSettings::TextSettings(const TextSettings& textSettings, const osg::CopyOp& copyop):
|
||||
osg::Object(textSettings, copyop),
|
||||
_font(textSettings._font),
|
||||
_characterSize(textSettings._characterSize)
|
||||
{
|
||||
}
|
||||
|
||||
331
src/osgUI/Widget.cpp
Normal file
331
src/osgUI/Widget.cpp
Normal file
@@ -0,0 +1,331 @@
|
||||
/* -*-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.
|
||||
*/
|
||||
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/ScriptEngine>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/ValueObject>
|
||||
#include <osg/io_utils>
|
||||
|
||||
#include <osgUI/Widget>
|
||||
#include <osgGA/EventVisitor>
|
||||
#include <osgGA/GUIActionAdapter>
|
||||
|
||||
using namespace osgUI;
|
||||
|
||||
Widget::Widget():
|
||||
_focusBehaviour(FOCUS_FOLLOWS_POINTER),
|
||||
_hasEventFocus(false),
|
||||
_graphicsInitialized(false)
|
||||
{
|
||||
setNumChildrenRequiringEventTraversal(1);
|
||||
}
|
||||
|
||||
Widget::Widget(const Widget& widget, const osg::CopyOp& copyop):
|
||||
osg::Group(),
|
||||
_focusBehaviour(widget._focusBehaviour),
|
||||
_hasEventFocus(false),
|
||||
_graphicsInitialized(false),
|
||||
_alignmentSettings(osg::clone(widget._alignmentSettings.get(), copyop)),
|
||||
_frameSettings(osg::clone(widget._frameSettings.get(), copyop)),
|
||||
_textSettings(osg::clone(widget._textSettings.get(), copyop))
|
||||
{
|
||||
setNumChildrenRequiringEventTraversal(1);
|
||||
}
|
||||
|
||||
void Widget::setExtents(const osg::BoundingBoxf& bb)
|
||||
{
|
||||
_extents = bb;
|
||||
}
|
||||
|
||||
void Widget::updateFocus(osg::NodeVisitor& nv)
|
||||
{
|
||||
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv);
|
||||
osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0;
|
||||
if (ev && aa)
|
||||
{
|
||||
osgGA::EventQueue::Events& events = ev->getEvents();
|
||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||
itr != events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* ea = (*itr)->asGUIEventAdapter();
|
||||
if (ea)
|
||||
{
|
||||
bool previousFocus = _hasEventFocus;
|
||||
if (_focusBehaviour==CLICK_TO_FOCUS)
|
||||
{
|
||||
if (ea->getEventType()==osgGA::GUIEventAdapter::PUSH)
|
||||
{
|
||||
int numButtonsPressed = 0;
|
||||
if (ea->getButtonMask()&osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON) ++numButtonsPressed;
|
||||
if (ea->getButtonMask()&osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON) ++numButtonsPressed;
|
||||
if (ea->getButtonMask()&osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) ++numButtonsPressed;
|
||||
|
||||
if (numButtonsPressed==1)
|
||||
{
|
||||
osgUtil::LineSegmentIntersector::Intersections intersections;
|
||||
bool withinWidget = aa->computeIntersections(*ea, nv.getNodePath(), intersections);
|
||||
if (withinWidget) _hasEventFocus = true;
|
||||
else _hasEventFocus = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_focusBehaviour==FOCUS_FOLLOWS_POINTER)
|
||||
{
|
||||
bool checkWithinWidget = false;
|
||||
if (!_hasEventFocus)
|
||||
{
|
||||
checkWithinWidget = (ea->getEventType()!=osgGA::GUIEventAdapter::FRAME) && ea->getButtonMask()==0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if mouse move or mouse release check to see if mouse still within widget to retain focus
|
||||
if (ea->getEventType()==osgGA::GUIEventAdapter::MOVE)
|
||||
{
|
||||
checkWithinWidget = true;
|
||||
}
|
||||
else if (ea->getEventType()==osgGA::GUIEventAdapter::RELEASE)
|
||||
{
|
||||
// if no buttons pressed then check
|
||||
if (ea->getButtonMask()==0) checkWithinWidget = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkWithinWidget)
|
||||
{
|
||||
osgUtil::LineSegmentIntersector::Intersections intersections;
|
||||
bool withinWidget = aa->computeIntersections(*ea, nv.getNodePath(), intersections);
|
||||
|
||||
_hasEventFocus = withinWidget;
|
||||
}
|
||||
}
|
||||
|
||||
if (previousFocus != _hasEventFocus)
|
||||
{
|
||||
if (_hasEventFocus)
|
||||
{
|
||||
enter();
|
||||
#if 0
|
||||
if (view->getCameraManipulator())
|
||||
{
|
||||
view->getCameraManipulator()->finishAnimation();
|
||||
view->requestContinuousUpdate( false );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
leave();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::setHasEventFocus(bool focus)
|
||||
{
|
||||
if (_hasEventFocus == focus) return;
|
||||
|
||||
_hasEventFocus = focus;
|
||||
|
||||
if (_hasEventFocus) enter();
|
||||
else leave();
|
||||
}
|
||||
|
||||
bool Widget::getHasEventFocus() const
|
||||
{
|
||||
return _hasEventFocus;
|
||||
}
|
||||
|
||||
void Widget::enter()
|
||||
{
|
||||
osg::CallbackObject* co = osg::getCallbackObject(this, "enter");
|
||||
if (co)
|
||||
{
|
||||
co->run(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
enterImplementation();
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::enterImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"enter()"<<std::endl;
|
||||
}
|
||||
|
||||
void Widget::leave()
|
||||
{
|
||||
osg::CallbackObject* co = osg::getCallbackObject(this, "leave");
|
||||
if (co)
|
||||
{
|
||||
co->run(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
leaveImplementation();
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::leaveImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"leave()"<<std::endl;
|
||||
}
|
||||
|
||||
void Widget::traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
osg::CallbackObject* co = osg::getCallbackObject(this, "traverse");
|
||||
if (co)
|
||||
{
|
||||
// currently lua scripting takes a ref count so messes up handling of NodeVisitor's created on stack,
|
||||
// so don't attempt to call the sctipt.
|
||||
if (nv.referenceCount()==0)
|
||||
{
|
||||
traverseImplementation(nv);
|
||||
return;
|
||||
}
|
||||
|
||||
osg::Parameters inputParameters, outputParameters;
|
||||
inputParameters.push_back(&nv);
|
||||
co->run(this, inputParameters, outputParameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
traverseImplementation(nv);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::traverseImplementation(osg::NodeVisitor& nv)
|
||||
{
|
||||
if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics();
|
||||
|
||||
|
||||
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv);
|
||||
if (ev)
|
||||
{
|
||||
updateFocus(nv);
|
||||
|
||||
if (getHasEventFocus())
|
||||
{
|
||||
// signify that event has been taken by widget with focus
|
||||
ev->setEventHandled(true);
|
||||
|
||||
osgGA::EventQueue::Events& events = ev->getEvents();
|
||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||
itr != events.end();
|
||||
++itr)
|
||||
{
|
||||
if (handle(ev, itr->get()))
|
||||
{
|
||||
(*itr)->setHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::Group::traverse(nv);
|
||||
}
|
||||
}
|
||||
|
||||
bool Widget::handle(osgGA::EventVisitor* ev, osgGA::Event* event)
|
||||
{
|
||||
osg::CallbackObject* co = osg::getCallbackObject(this, "handle");
|
||||
if (co)
|
||||
{
|
||||
// currently lua scripting takes a ref count so messes up handling of NodeVisitor's created on stack,
|
||||
// so don't attempt to call the sctipt.
|
||||
if (ev->referenceCount()==0)
|
||||
{
|
||||
return handleImplementation(ev, event);
|
||||
}
|
||||
|
||||
osg::Parameters inputParameters, outputParameters;
|
||||
inputParameters.push_back(ev);
|
||||
inputParameters.push_back(event);
|
||||
if (co->run(this, inputParameters, outputParameters))
|
||||
{
|
||||
if (outputParameters.size()>=1)
|
||||
{
|
||||
osg::BoolValueObject* bvo = dynamic_cast<osg::BoolValueObject*>(outputParameters[0].get());
|
||||
if (bvo)
|
||||
{
|
||||
return bvo->getValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return handleImplementation(ev, event);
|
||||
}
|
||||
}
|
||||
|
||||
bool Widget::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Widget::computePositionInLocalCoordinates(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, osg::Vec3& localPosition) const
|
||||
{
|
||||
osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0;
|
||||
osgUtil::LineSegmentIntersector::Intersections intersections;
|
||||
if (aa && aa->computeIntersections(*event, ev->getNodePath(), intersections))
|
||||
{
|
||||
localPosition = intersections.begin()->getLocalIntersectPoint();
|
||||
|
||||
return (_extents.contains(localPosition, 1e-6));
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::dirty()
|
||||
{
|
||||
_graphicsInitialized = false;
|
||||
}
|
||||
|
||||
void Widget::createGraphics()
|
||||
{
|
||||
osg::CallbackObject* co = osg::getCallbackObject(this, "createGraphics");
|
||||
if (co)
|
||||
{
|
||||
co->run(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
createGraphicsImplementation();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Widget::createGraphicsImplementation()
|
||||
{
|
||||
_graphicsInitialized = true;
|
||||
}
|
||||
|
||||
osg::BoundingSphere Widget::computeBound() const
|
||||
{
|
||||
if (_extents.valid()) return osg::BoundingSphere(_extents);
|
||||
else return osg::Group::computeBound();
|
||||
}
|
||||
@@ -50,3 +50,4 @@ ADD_SUBDIRECTORY(osgText)
|
||||
ADD_SUBDIRECTORY(osgVolume)
|
||||
ADD_SUBDIRECTORY(osgPresentation)
|
||||
ADD_SUBDIRECTORY(osgViewer)
|
||||
ADD_SUBDIRECTORY(osgUI)
|
||||
|
||||
31
src/osgWrappers/serializers/osgUI/AlignmentSettings.cpp
Normal file
31
src/osgWrappers/serializers/osgUI/AlignmentSettings.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <osgUI/AlignmentSettings>
|
||||
#include <osg/ValueObject>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( AlignmentSettings,
|
||||
new osgUI::AlignmentSettings,
|
||||
osgUI::AlignmentSettings,
|
||||
"osg::Object osgUI::AlignmentSettings" )
|
||||
{
|
||||
BEGIN_ENUM_SERIALIZER2( Alignment, osgUI::AlignmentSettings::Alignment, LEFT_BOTTOM );
|
||||
ADD_ENUM_VALUE( LEFT_TOP );
|
||||
ADD_ENUM_VALUE( LEFT_CENTER );
|
||||
ADD_ENUM_VALUE( LEFT_BOTTOM );
|
||||
ADD_ENUM_VALUE( CENTER_TOP );
|
||||
ADD_ENUM_VALUE( CENTER_CENTER );
|
||||
ADD_ENUM_VALUE( CENTER_BOTTOM );
|
||||
ADD_ENUM_VALUE( RIGHT_TOP );
|
||||
ADD_ENUM_VALUE( RIGHT_CENTER );
|
||||
ADD_ENUM_VALUE( RIGHT_BOTTOM );
|
||||
ADD_ENUM_VALUE( LEFT_BASE_LINE );
|
||||
ADD_ENUM_VALUE( CENTER_BASE_LINE );
|
||||
ADD_ENUM_VALUE( RIGHT_BASE_LINE );
|
||||
ADD_ENUM_VALUE( LEFT_BOTTOM_BASE_LINE );
|
||||
ADD_ENUM_VALUE( CENTER_BOTTOM_BASE_LINE );
|
||||
ADD_ENUM_VALUE( RIGHT_BOTTOM_BASE_LINE );
|
||||
END_ENUM_SERIALIZER(); // _alignment
|
||||
}
|
||||
7
src/osgWrappers/serializers/osgUI/CMakeLists.txt
Normal file
7
src/osgWrappers/serializers/osgUI/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
FILE(GLOB TARGET_SRC *.cpp)
|
||||
FILE(GLOB TARGET_H *.h)
|
||||
|
||||
SET(TARGET_ADDED_LIBRARIES osgUI )
|
||||
|
||||
#### end var setup ###
|
||||
SETUP_PLUGIN(osgui)
|
||||
27
src/osgWrappers/serializers/osgUI/FrameSettings.cpp
Normal file
27
src/osgWrappers/serializers/osgUI/FrameSettings.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <osgUI/FrameSettings>
|
||||
#include <osg/ValueObject>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( FrameSettings,
|
||||
new osgUI::FrameSettings,
|
||||
osgUI::FrameSettings,
|
||||
"osg::Object osgUI::FrameSettings" )
|
||||
{
|
||||
BEGIN_ENUM_SERIALIZER2( Shape, osgUI::FrameSettings::Shape, NO_FRAME );
|
||||
ADD_ENUM_VALUE( NO_FRAME );
|
||||
ADD_ENUM_VALUE( BOX );
|
||||
ADD_ENUM_VALUE( PANEL );
|
||||
END_ENUM_SERIALIZER();
|
||||
|
||||
BEGIN_ENUM_SERIALIZER2( Shadow, osgUI::FrameSettings::Shadow, PLAIN );
|
||||
ADD_ENUM_VALUE( PLAIN );
|
||||
ADD_ENUM_VALUE( SUNKEN );
|
||||
ADD_ENUM_VALUE( RAISED );
|
||||
END_ENUM_SERIALIZER();
|
||||
|
||||
ADD_FLOAT_SERIALIZER( LineWidth, 0.01);
|
||||
}
|
||||
15
src/osgWrappers/serializers/osgUI/Label.cpp
Normal file
15
src/osgWrappers/serializers/osgUI/Label.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <osgUI/Label>
|
||||
#include <osg/ValueObject>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( Label,
|
||||
new osgUI::Label,
|
||||
osgUI::Label,
|
||||
"osg::Object osg::Node osg::Group osgUI::Widget osgUI::Label" )
|
||||
{
|
||||
ADD_STRING_SERIALIZER( Text, std::string());
|
||||
|
||||
}
|
||||
14
src/osgWrappers/serializers/osgUI/LineEdit.cpp
Normal file
14
src/osgWrappers/serializers/osgUI/LineEdit.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <osgUI/LineEdit>
|
||||
#include <osg/ValueObject>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( LineEdit,
|
||||
new osgUI::LineEdit,
|
||||
osgUI::LineEdit,
|
||||
"osg::Object osg::Node osg::Group osgUI::Widget osgUI::LineEdit" )
|
||||
{
|
||||
ADD_STRING_SERIALIZER( Text, std::string());
|
||||
}
|
||||
16
src/osgWrappers/serializers/osgUI/TextSettings.cpp
Normal file
16
src/osgWrappers/serializers/osgUI/TextSettings.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <osgUI/TextSettings>
|
||||
#include <osg/ValueObject>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( TextSettings,
|
||||
new osgUI::TextSettings,
|
||||
osgUI::TextSettings,
|
||||
"osg::Object osgUI::TextSettings" )
|
||||
{
|
||||
ADD_STRING_SERIALIZER( Font, std::string());
|
||||
ADD_FLOAT_SERIALIZER( CharacterSize, 0.0f);
|
||||
}
|
||||
155
src/osgWrappers/serializers/osgUI/Widget.cpp
Normal file
155
src/osgWrappers/serializers/osgUI/Widget.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
#include <osgUI/Widget>
|
||||
#include <osg/ValueObject>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
|
||||
struct CreateGraphics : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const
|
||||
{
|
||||
osgUI::Widget* widget = reinterpret_cast<osgUI::Widget*>(objectPtr);
|
||||
widget->createGraphics();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct CreateGraphicsImplementation : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const
|
||||
{
|
||||
osgUI::Widget* widget = reinterpret_cast<osgUI::Widget*>(objectPtr);
|
||||
widget->createGraphicsImplementation();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct Enter : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const
|
||||
{
|
||||
osgUI::Widget* widget = reinterpret_cast<osgUI::Widget*>(objectPtr);
|
||||
widget->enter();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct EnterImplementation : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const
|
||||
{
|
||||
osgUI::Widget* widget = reinterpret_cast<osgUI::Widget*>(objectPtr);
|
||||
widget->enterImplementation();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct Leave : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const
|
||||
{
|
||||
osgUI::Widget* widget = reinterpret_cast<osgUI::Widget*>(objectPtr);
|
||||
widget->leave();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct LeaveImplementation : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const
|
||||
{
|
||||
osgUI::Widget* widget = reinterpret_cast<osgUI::Widget*>(objectPtr);
|
||||
widget->leaveImplementation();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct Traverse : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters&) const
|
||||
{
|
||||
osgUI::Widget* widget = reinterpret_cast<osgUI::Widget*>(objectPtr);
|
||||
osg::NodeVisitor* nv = (inputParameters.size()>=1) ? dynamic_cast<osg::NodeVisitor*>(inputParameters[0].get()) : 0;
|
||||
if (!nv) return false;
|
||||
widget->traverse(*nv);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct TraverseImplementation : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters&) const
|
||||
{
|
||||
osgUI::Widget* widget = reinterpret_cast<osgUI::Widget*>(objectPtr);
|
||||
osg::NodeVisitor* nv = (inputParameters.size()>=1) ? dynamic_cast<osg::NodeVisitor*>(inputParameters[0].get()) : 0;
|
||||
if (!nv) return false;
|
||||
widget->traverseImplementation(*nv);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct Handle : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters&) const
|
||||
{
|
||||
osgUI::Widget* widget = reinterpret_cast<osgUI::Widget*>(objectPtr);
|
||||
osgGA::EventVisitor* ev = (inputParameters.size()>=1) ? dynamic_cast<osgGA::EventVisitor*>(inputParameters[0].get()) : 0;
|
||||
osgGA::Event* event = (inputParameters.size()>=2) ? dynamic_cast<osgGA::Event*>(inputParameters[1].get()) : 0;
|
||||
if (!widget || !ev || !event) return false;
|
||||
widget->handle(ev, event);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct HandleImplementation : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters&) const
|
||||
{
|
||||
osgUI::Widget* widget = reinterpret_cast<osgUI::Widget*>(objectPtr);
|
||||
osgGA::EventVisitor* ev = (inputParameters.size()>=1) ? dynamic_cast<osgGA::EventVisitor*>(inputParameters[0].get()) : 0;
|
||||
osgGA::Event* event = (inputParameters.size()>=2) ? dynamic_cast<osgGA::Event*>(inputParameters[1].get()) : 0;
|
||||
if (!widget || !ev || !event) return false;
|
||||
widget->handleImplementation(ev, event);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( Widget,
|
||||
new osgUI::Widget,
|
||||
osgUI::Widget,
|
||||
"osg::Object osg::Node osg::Group osgUI::Widget" )
|
||||
{
|
||||
BEGIN_ENUM_SERIALIZER( FocusBehaviour, FOCUS_FOLLOWS_POINTER );
|
||||
ADD_ENUM_VALUE( CLICK_TO_FOCUS );
|
||||
ADD_ENUM_VALUE( FOCUS_FOLLOWS_POINTER );
|
||||
ADD_ENUM_VALUE( EVENT_DRIVEN_FOCUS_DISABLED );
|
||||
END_ENUM_SERIALIZER();
|
||||
|
||||
ADD_BOOL_SERIALIZER(HasEventFocus, false);
|
||||
|
||||
ADD_BOUNDINGBOXF_SERIALIZER(Extents, osg::BoundingBoxf());
|
||||
|
||||
ADD_OBJECT_SERIALIZER( FrameSettings, osgUI::FrameSettings, NULL );
|
||||
ADD_OBJECT_SERIALIZER( AlignmentSettings, osgUI::AlignmentSettings, NULL );
|
||||
ADD_OBJECT_SERIALIZER( TextSettings, osgUI::TextSettings, NULL );
|
||||
|
||||
|
||||
ADD_METHOD_OBJECT( "createGraphics", CreateGraphics );
|
||||
ADD_METHOD_OBJECT( "createGraphicsImplementation", CreateGraphicsImplementation );
|
||||
|
||||
ADD_METHOD_OBJECT( "enter", Enter );
|
||||
ADD_METHOD_OBJECT( "enterImplementation", EnterImplementation );
|
||||
|
||||
ADD_METHOD_OBJECT( "leave", Leave );
|
||||
ADD_METHOD_OBJECT( "leaveImplementation", LeaveImplementation );
|
||||
|
||||
ADD_METHOD_OBJECT( "traverse", Traverse );
|
||||
ADD_METHOD_OBJECT( "traverseImplementation", TraverseImplementation );
|
||||
|
||||
ADD_METHOD_OBJECT( "handle", Handle );
|
||||
ADD_METHOD_OBJECT( "handleImplementation", HandleImplementation );
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user