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