OpenSceneGraph 3.6.5
Widget
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGUI_WIDGET
15#define OSGUI_WIDGET
16
17#include <osg/Group>
18#include <osg/BoundingBox>
19#include <osg/ScriptEngine>
20#include <osgGA/Event>
21#include <osgGA/EventVisitor>
22
23#include <osgUI/Style>
24
25namespace osgUI
26{
27
29{
30public:
32 Widget(const Widget& widget, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
34
35 virtual void traverse(osg::NodeVisitor& nv);
37
38 virtual bool handle(osgGA::EventVisitor* ev, osgGA::Event* event);
40
41 typedef std::vector<osgUtil::LineSegmentIntersector::Intersection> Intersections;
42 virtual bool computeIntersections(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, Intersections& intersections, osg::Node::NodeMask traversalMask = 0xffffffff) const;
44 virtual bool computeExtentsPositionInLocalCoordinates(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, osg::Vec3d& localPosition, bool withinExtents=true) const;
45
46 virtual void dirty();
47
48 typedef std::map<int, osg::ref_ptr<osg::Node> > GraphicsSubgraphMap;
49
51 void setGraphicsSubgraph(int orderNum, osg::Node* node) { _graphicsSubgraphMap[orderNum] = node; _graphicsInitialized = true; }
53 osg::Node* getGraphicsSubgraph(int orderNum) { GraphicsSubgraphMap::iterator itr = _graphicsSubgraphMap.find(orderNum); return (itr!=_graphicsSubgraphMap.end()) ? itr->second.get() : 0; }
55 const osg::Node* getGraphicsSubgraph(int orderNum) const { GraphicsSubgraphMap::const_iterator itr = _graphicsSubgraphMap.find(orderNum); return (itr!=_graphicsSubgraphMap.end()) ? itr->second.get() : 0; }
56
60
65 void setWidgetStateSet(osg::StateSet* stateset) { _widgetStateSet = stateset; }
67 const osg::StateSet* getWidgetStateSet() const { return _widgetStateSet.get(); }
69
70
72 virtual void createGraphics();
73
76
77
78 virtual void setExtents(const osg::BoundingBoxf& bb);
79 const osg::BoundingBoxf& getExtents() const { return _extents; }
80
81 void setStyle(Style* style) { _style = style; }
82 Style* getStyle() { return _style.get(); }
83 const Style* getStyle() const { return _style.get(); }
84
85 void setAlignmentSettings(AlignmentSettings* alignmentSettings) { _alignmentSettings = alignmentSettings; }
88
89 void setFrameSettings(FrameSettings* textSettings) { _frameSettings = textSettings; }
91 const FrameSettings* getFrameSettings() const { return _frameSettings.get(); }
92
93 void setTextSettings(TextSettings* textSettings) { _textSettings = textSettings; }
95 const TextSettings* getTextSettings() const { return _textSettings.get(); }
96
98 virtual void setAutoFillBackground(bool enabled) { _autoFillBackground = enabled; }
100 virtual bool getAutoFillBackground() const { return _autoFillBackground; }
101
103 virtual void setVisible(bool visible) { _visible = visible; }
105 virtual bool getVisible() const { return _visible; }
106
108 virtual void setEnabled(bool enabled) { _enabled = enabled; }
110 virtual bool getEnabled() const { return _enabled; }
111
118
119 void setFocusBehaviour(FocusBehaviour behaviour) { _focusBehaviour = behaviour; }
121
123 virtual void updateFocus(osg::NodeVisitor& nv);
124
126 virtual void setHasEventFocus(bool focus);
127
129 virtual bool getHasEventFocus() const;
130
131
133 bool runCallbacks(const std::string& name, osg::Parameters& inputParameters, osg::Parameters& outputParameters) { return osg::runNamedCallbackObjects(this, name, inputParameters, outputParameters); }
134
136 bool runCallbacks(const std::string& name) { osg::Parameters inputParameters, outputParameters; return osg::runNamedCallbackObjects(this, name, inputParameters, outputParameters); }
137
138
141
143 virtual void enter();
144 virtual void enterImplementation();
145
147 virtual void leave();
148 virtual void leaveImplementation();
149
151 virtual void resizeGLObjectBuffers(unsigned int maxSize);
153 virtual void releaseGLObjects(osg::State* = 0) const;
154
155protected:
156 virtual ~Widget() {}
157
161
164
166
168
173
176};
177
178}
179
180#endif
bool runNamedCallbackObjects(osg::Object *object, const std::string &name, osg::Parameters &inputParameters, osg::Parameters &outputParameters)
Call run(..) on named CallbackObjects attached to specified Object.
Definition Callback:187
BoundingBoxImpl< Vec3f > BoundingBoxf
Definition BoundingBox:251
BoundingSphered BoundingSphere
Definition BoundingSphere:308
std::vector< osg::ref_ptr< osg::Object > > Parameters
Definition Callback:130
Definition AlignmentSettings:23
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
General group node which maintains a list of children.
Definition Group:29
Base class for all internal nodes in the scene graph.
Definition Node:72
unsigned int NodeMask
This is a set of bits (flags) that represent the Node.
Definition Node:363
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Stores a set of modes and attributes which represent a set of OpenGL state.
Definition StateSet:46
General purpose double triple for use as vertices, vectors and normals.
Definition Vec3d:30
Base Event class.
Definition Event:27
Basic EventVisitor implementation for animating a scene.
Definition EventVisitor:42
Event class for storing Keyboard, mouse and window events.
Definition GUIEventAdapter:82
Definition AlignmentSettings:26
Definition FrameSettings:25
Definition Style:32
Definition TextSettings:26
virtual void dirty()
const osg::StateSet * getWidgetStateSet() const
Definition Widget:67
std::vector< osgUtil::LineSegmentIntersector::Intersection > Intersections
Definition Widget:41
virtual void traverse(osg::NodeVisitor &nv)
Traverse downwards : calls children's accept method with NodeVisitor.
osg::ref_ptr< AlignmentSettings > _alignmentSettings
Definition Widget:169
virtual void releaseGLObjects(osg::State *=0) const
resize all GLObjectBuffers.
virtual void leaveImplementation()
void setWidgetStateSet(osg::StateSet *stateset)
Set the WidgetStateSet is used internally by Widgets to manage state that decorates the subgraph.
Definition Widget:65
bool _hasEventFocus
Definition Widget:159
virtual osg::BoundingSphere computeBound() const
Compute the bounding sphere of the widget.
virtual void traverseImplementation(osg::NodeVisitor &nv)
void setFrameSettings(FrameSettings *textSettings)
Definition Widget:89
virtual void enter()
update any focus related graphics+state to the focused state.
virtual void setVisible(bool visible)
set the visibility of the widget.
Definition Widget:103
const osg::BoundingBoxf & getExtents() const
Definition Widget:79
osg::ref_ptr< Style > _style
Definition Widget:167
const AlignmentSettings * getAlignmentSettings() const
Definition Widget:87
virtual void setAutoFillBackground(bool enabled)
set whether the widget should fill the extents of its background.
Definition Widget:98
FrameSettings * getFrameSettings()
Definition Widget:90
std::map< int, osg::ref_ptr< osg::Node > > GraphicsSubgraphMap
Definition Widget:48
virtual void setExtents(const osg::BoundingBoxf &bb)
osg::ref_ptr< TextSettings > _textSettings
Definition Widget:171
bool _visible
Definition Widget:174
virtual bool getVisible() const
get the visibility of the widget.
Definition Widget:105
void setStyle(Style *style)
Definition Widget:81
const osg::Node * getGraphicsSubgraph(int orderNum) const
Get the const subgraph to be used to render the widget.
Definition Widget:55
void setAlignmentSettings(AlignmentSettings *alignmentSettings)
Definition Widget:85
osg::StateSet * getOrCreateWidgetStateSet()
Definition Widget:68
virtual bool handleImplementation(osgGA::EventVisitor *ev, osgGA::Event *event)
const FrameSettings * getFrameSettings() const
Definition Widget:91
bool runCallbacks(const std::string &name, osg::Parameters &inputParameters, osg::Parameters &outputParameters)
invoke all callbacks with specified names providing input and output parameters.
Definition Widget:133
osg::BoundingBoxf _extents
Definition Widget:165
virtual void setEnabled(bool enabled)
set whether the widget is enabled for user interaction.
Definition Widget:108
Widget(const Widget &widget, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
FocusBehaviour getFocusBehaviour() const
Definition Widget:120
virtual bool getEnabled() const
get whether the widget is enabled for user interaction.
Definition Widget:110
virtual bool computePositionInLocalCoordinates(osgGA::EventVisitor *ev, osgGA::GUIEventAdapter *event, osg::Vec3d &localPosition) const
Style * getStyle()
Definition Widget:82
void setFocusBehaviour(FocusBehaviour behaviour)
Definition Widget:119
bool _autoFillBackground
Definition Widget:172
GraphicsSubgraphMap & getGraphicsSubgraphMap()
Definition Widget:58
virtual void leave()
update any focus related graphics+state to the unfocused state.
FocusBehaviour
Definition Widget:113
@ FOCUS_FOLLOWS_POINTER
Definition Widget:115
@ CLICK_TO_FOCUS
Definition Widget:114
@ EVENT_DRIVEN_FOCUS_DISABLED
Definition Widget:116
virtual void setHasEventFocus(bool focus)
set whether the widget has focus or not.
const Style * getStyle() const
Definition Widget:83
void setGraphicsSubgraphMap(const GraphicsSubgraphMap &gsm)
Definition Widget:57
bool _graphicsInitialized
Definition Widget:160
virtual bool getAutoFillBackground() const
get whether the widget should fill the extents of its background.
Definition Widget:100
virtual bool handle(osgGA::EventVisitor *ev, osgGA::Event *event)
virtual void updateFocus(osg::NodeVisitor &nv)
update the focus according to events.
osg::Node * getGraphicsSubgraph(int orderNum)
Get the subgraph to be used to render the widget.
Definition Widget:53
bool _enabled
Definition Widget:175
osg::ref_ptr< osg::StateSet > _widgetStateSet
Definition Widget:163
FocusBehaviour _focusBehaviour
Definition Widget:158
const GraphicsSubgraphMap & getGraphicsSubgraphMap() const
Definition Widget:59
TextSettings * getTextSettings()
Definition Widget:94
virtual void enterImplementation()
bool runCallbacks(const std::string &name)
invoke all callbacks with specified names without any specified input or output parameters.
Definition Widget:136
virtual bool getHasEventFocus() const
get whether the widget has focus or not.
GraphicsSubgraphMap _graphicsSubgraphMap
Definition Widget:162
virtual void createGraphicsImplementation()
createGraphicsImplementation method that creates the subgraph that will render the widget and assigns...
virtual void createGraphics()
createGraphics entry method, calls either callback object named "createGraphics" or the createGraphic...
virtual bool computeIntersections(osgGA::EventVisitor *ev, osgGA::GUIEventAdapter *event, Intersections &intersections, osg::Node::NodeMask traversalMask=0xffffffff) const
virtual ~Widget()
Definition Widget:156
void setTextSettings(TextSettings *textSettings)
Definition Widget:93
AlignmentSettings * getAlignmentSettings()
Definition Widget:86
META_Node(osgUI, Widget)
virtual bool computeExtentsPositionInLocalCoordinates(osgGA::EventVisitor *ev, osgGA::GUIEventAdapter *event, osg::Vec3d &localPosition, bool withinExtents=true) const
osg::ref_ptr< FrameSettings > _frameSettings
Definition Widget:170
virtual void resizeGLObjectBuffers(unsigned int maxSize)
resize all GLObjectBuffers.
osg::StateSet * getWidgetStateSet()
Definition Widget:66
const TextSettings * getTextSettings() const
Definition Widget:95
void setGraphicsSubgraph(int orderNum, osg::Node *node)
Set the subgraph to be used to render the widget.
Definition Widget:51
#define OSGUI_EXPORT
Definition Export:40

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.