OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Widget.h
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 
25 namespace osgUI
26 {
27 
29 {
30 public:
31  Widget();
32  Widget(const Widget& widget, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
34 
35  virtual void traverse(osg::NodeVisitor& nv);
36  virtual void traverseImplementation(osg::NodeVisitor& nv);
37 
38  virtual bool handle(osgGA::EventVisitor* ev, osgGA::Event* event);
39  virtual bool handleImplementation(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;
43  virtual bool computePositionInLocalCoordinates(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, osg::Vec3d& localPosition) 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 
57  void setGraphicsSubgraphMap(const GraphicsSubgraphMap& gsm) { _graphicsSubgraphMap = gsm; _graphicsInitialized = true; }
58  GraphicsSubgraphMap& getGraphicsSubgraphMap() { return _graphicsSubgraphMap; }
59  const GraphicsSubgraphMap& getGraphicsSubgraphMap() const { return _graphicsSubgraphMap; }
60 
65  void setWidgetStateSet(osg::StateSet* stateset) { _widgetStateSet = stateset; }
66  osg::StateSet* getWidgetStateSet() { return _widgetStateSet.get(); }
67  const osg::StateSet* getWidgetStateSet() const { return _widgetStateSet.get(); }
68  osg::StateSet* getOrCreateWidgetStateSet() { if (!_widgetStateSet) _widgetStateSet = new osg::StateSet; return _widgetStateSet.get(); }
69 
70 
72  virtual void createGraphics();
73 
75  virtual void createGraphicsImplementation();
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; }
86  AlignmentSettings* getAlignmentSettings() { return _alignmentSettings.get(); }
87  const AlignmentSettings* getAlignmentSettings() const { return _alignmentSettings.get(); }
88 
89  void setFrameSettings(FrameSettings* textSettings) { _frameSettings = textSettings; }
90  FrameSettings* getFrameSettings() { return _frameSettings.get(); }
91  const FrameSettings* getFrameSettings() const { return _frameSettings.get(); }
92 
93  void setTextSettings(TextSettings* textSettings) { _textSettings = textSettings; }
94  TextSettings* getTextSettings() { return _textSettings.get(); }
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 
113  {
116  EVENT_DRIVEN_FOCUS_DISABLED
117  };
118 
119  void setFocusBehaviour(FocusBehaviour behaviour) { _focusBehaviour = behaviour; }
120  FocusBehaviour getFocusBehaviour() const { return _focusBehaviour; }
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 
140  virtual osg::BoundingSphere computeBound() const;
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 
155 protected:
156  virtual ~Widget() {}
157 
161 
162  GraphicsSubgraphMap _graphicsSubgraphMap;
164 
166 
168 
173 
174  bool _visible;
175  bool _enabled;
176 };
177 
178 }
179 
180 #endif
bool runCallbacks(const std::string &name)
Definition: Widget.h:136
const GraphicsSubgraphMap & getGraphicsSubgraphMap() const
Definition: Widget.h:59
FrameSettings * getFrameSettings()
Definition: Widget.h:90
virtual void setAutoFillBackground(bool enabled)
Definition: Widget.h:98
const Style * getStyle() const
Definition: Widget.h:83
const osg::Node * getGraphicsSubgraph(int orderNum) const
Definition: Widget.h:55
void setStyle(Style *style)
Definition: Widget.h:81
osg::ref_ptr< osg::StateSet > _widgetStateSet
Definition: Widget.h:163
bool _hasEventFocus
Definition: Widget.h:159
virtual ~Widget()
Definition: Widget.h:156
Style * getStyle()
Definition: Widget.h:82
osg::StateSet * getOrCreateWidgetStateSet()
Definition: Widget.h:68
#define META_Node(library, name)
Definition: Node.h:59
FocusBehaviour _focusBehaviour
Definition: Widget.h:158
const osg::StateSet * getWidgetStateSet() const
Definition: Widget.h:67
const AlignmentSettings * getAlignmentSettings() const
Definition: Widget.h:87
void setGraphicsSubgraph(int orderNum, osg::Node *node)
Definition: Widget.h:51
std::vector< osg::ref_ptr< osg::Object > > Parameters
Definition: Callback.h:92
bool _graphicsInitialized
Definition: Widget.h:160
GraphicsSubgraphMap _graphicsSubgraphMap
Definition: Widget.h:162
osg::Node * getGraphicsSubgraph(int orderNum)
Definition: Widget.h:53
std::vector< osgUtil::LineSegmentIntersector::Intersection > Intersections
Definition: Widget.h:41
virtual bool getAutoFillBackground() const
Definition: Widget.h:100
virtual void setEnabled(bool enabled)
Definition: Widget.h:108
osg::ref_ptr< TextSettings > _textSettings
Definition: Widget.h:171
FocusBehaviour getFocusBehaviour() const
Definition: Widget.h:120
void setFrameSettings(FrameSettings *textSettings)
Definition: Widget.h:89
void setWidgetStateSet(osg::StateSet *stateset)
Definition: Widget.h:65
bool runNamedCallbackObjects(osg::Object *object, const std::string &name, osg::Parameters &inputParameters, osg::Parameters &outputParameters)
Definition: Callback.h:139
osg::BoundingBoxf _extents
Definition: Widget.h:165
osg::ref_ptr< AlignmentSettings > _alignmentSettings
Definition: Widget.h:169
osg::ref_ptr< FrameSettings > _frameSettings
Definition: Widget.h:170
void setGraphicsSubgraphMap(const GraphicsSubgraphMap &gsm)
Definition: Widget.h:57
const FrameSettings * getFrameSettings() const
Definition: Widget.h:91
AlignmentSettings * getAlignmentSettings()
Definition: Widget.h:86
TextSettings * getTextSettings()
Definition: Widget.h:94
Definition: Node.h:71
GraphicsSubgraphMap & getGraphicsSubgraphMap()
Definition: Widget.h:58
void setTextSettings(TextSettings *textSettings)
Definition: Widget.h:93
bool _autoFillBackground
Definition: Widget.h:172
void setAlignmentSettings(AlignmentSettings *alignmentSettings)
Definition: Widget.h:85
virtual void setVisible(bool visible)
Definition: Widget.h:103
bool _enabled
Definition: Widget.h:175
osg::StateSet * getWidgetStateSet()
Definition: Widget.h:66
bool _visible
Definition: Widget.h:174
void setFocusBehaviour(FocusBehaviour behaviour)
Definition: Widget.h:119
std::map< int, osg::ref_ptr< osg::Node > > GraphicsSubgraphMap
Definition: Widget.h:48
bool runCallbacks(const std::string &name, osg::Parameters &inputParameters, osg::Parameters &outputParameters)
Definition: Widget.h:133
const osg::BoundingBoxf & getExtents() const
Definition: Widget.h:79
unsigned int NodeMask
Definition: Node.h:352
const TextSettings * getTextSettings() const
Definition: Widget.h:95
osg::ref_ptr< Style > _style
Definition: Widget.h:167
virtual bool getVisible() const
Definition: Widget.h:105
virtual bool getEnabled() const
Definition: Widget.h:110
#define OSGUI_EXPORT
Definition: Widget.h:22