openscenegraph
osgUI/Callbacks
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_CALLBACKS
15#define OSGUI_CALLBACKS
16
17#include <osg/Callback>
18#include <osgGA/EventVisitor>
19
20#include <osgUI/Export>
21#include <osgUI/Widget>
22
23namespace osgUI
24{
25
26
27class OSGUI_EXPORT CloseCallback : public osg::CallbackObject
28{
29public:
30 CloseCallback(const std::string& callbackName=std::string("close"), osgUI::Widget* closeWidget=0);
31 CloseCallback(const CloseCallback& hc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
32 META_Object(osgUI, CloseCallback);
33
34 void setCloseWidget(osgUI::Widget* widget) { _closeWidget = widget; }
35 osgUI::Widget* getCloseWidget() { return _closeWidget.get(); }
36 const osgUI::Widget* getCloseWidget() const { return _closeWidget.get(); }
37
38 virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
39
40protected:
41 virtual ~CloseCallback() {}
42 osg::observer_ptr<osgUI::Widget> _closeWidget;
43};
44
45class OSGUI_EXPORT HandleCallback : public osg::CallbackObject
46{
47public:
48 HandleCallback();
49 HandleCallback(const HandleCallback& hc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
50 META_Object(osgUI, HandleCallback);
51
52 virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
53 virtual bool handle(osgGA::EventVisitor* ev, osgGA::Event* event) const;
54
55protected:
56 virtual ~HandleCallback() {}
57};
58
59class OSGUI_EXPORT DragCallback : public HandleCallback
60{
61public:
62 DragCallback();
63 DragCallback(const DragCallback& dc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
64 META_Object(osgUI, DragCallback);
65
66 void setDragging(bool v) { _dragging = v; }
67 bool getDragging() const { return _dragging; }
68
69 void setPreviousPosition(const osg::Vec3d& position) { _previousPosition = position; }
70 const osg::Vec3d& getPreviousPosition() const { return _previousPosition; }
71
72 virtual bool handle(osgGA::EventVisitor* ev, osgGA::Event* event) const;
73
74protected:
75 virtual ~DragCallback() {}
76
77 bool _dragging;
78 osg::Vec3d _previousPosition;
79
80};
81
82}
83
84#endif