openscenegraph
osgGA/Widget
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 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 OSGGA_WIDGET
15#define OSGGA_WIDGET
16
17#include <osg/Group>
18#include <osg/BoundingBox>
19#include <osgGA/Event>
20#include <osgGA/EventVisitor>
21
22namespace osgGA
23{
24
25class OSGGA_EXPORT Widget : public osg::Group
26{
27public:
28 Widget();
29 Widget(const Widget& tfw, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
30 META_Node(osgGA, Widget);
31
32 virtual void traverse(osg::NodeVisitor& nv);
33 virtual void traverseImplementation(osg::NodeVisitor& nv);
34
35 virtual bool handle(osgGA::EventVisitor* ev, osgGA::Event* event);
36 virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
37
38 virtual bool computePositionInLocalCoordinates(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, osg::Vec3& localPosition) const;
39
40 virtual void createGraphics();
41 virtual void createGraphicsImplementation();
42
43 virtual void setExtents(const osg::BoundingBoxf& bb);
44 const osg::BoundingBoxf& getExtents() const { return _extents; }
45
46 enum FocusBehaviour
47 {
48 CLICK_TO_FOCUS,
49 FOCUS_FOLLOWS_POINTER,
50 EVENT_DRIVEN_FOCUS_DISABLED
51 };
52
53 void setFocusBehaviour(FocusBehaviour behaviour) { _focusBehaviour = behaviour; }
54 FocusBehaviour getFocusBehaviour() const { return _focusBehaviour; }
55
56 /** update the focus according to events.*/
57 virtual void updateFocus(osg::NodeVisitor& nv);
58
59 /** set whether the widget has focus or not.*/
60 virtual void setHasEventFocus(bool focus);
61
62 /** get whether the widget has focus or not.*/
63 virtual bool getHasEventFocus() const;
64
65 virtual osg::BoundingSphere computeBound() const;
66
67 /** update any focus related graphics+state to the focused state.*/
68 virtual void enter();
69 virtual void enterImplementation();
70
71 /** update any focus related graphics+state to the unfocused state.*/
72 virtual void leave();
73 virtual void leaveImplementation();
74
75
76protected:
77 virtual ~Widget() {}
78
79 FocusBehaviour _focusBehaviour;
80 bool _hasEventFocus;
81 bool _graphicsInitialized;
82
83 osg::BoundingBoxf _extents;
84};
85
86}
87
88#endif