]> git.mxchange.org Git - flightgear.git/blob - src/Canvas/gui_mgr.hxx
Canvas GUI: refactor and simplify based on canvas::Group
[flightgear.git] / src / Canvas / gui_mgr.hxx
1 // Canvas gui/dialog manager
2 //
3 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19 #ifndef CANVAS_GUI_MGR_HXX_
20 #define CANVAS_GUI_MGR_HXX_
21
22 #include "canvas_fwd.hpp"
23
24 #include <simgear/canvas/canvas_fwd.hxx>
25 #include <simgear/canvas/elements/CanvasGroup.hxx>
26 #include <simgear/props/PropertyBasedMgr.hxx>
27 #include <simgear/props/propertyObject.hxx>
28
29 #include <osg/ref_ptr>
30 #include <osg/Geode>
31 #include <osg/MatrixTransform>
32
33 namespace osgGA
34 {
35   class GUIEventAdapter;
36 }
37
38 class GUIEventHandler;
39 class GUIMgr:
40   public simgear::canvas::Group,
41   public SGSubsystem
42 {
43   public:
44     GUIMgr();
45
46     canvas::WindowPtr createWindow(const std::string& name = "");
47
48     virtual void init();
49     virtual void shutdown();
50
51     virtual void update(double dt);
52
53     bool handleEvent(const osgGA::GUIEventAdapter& ea);
54
55   protected:
56
57     typedef simgear::canvas::ElementFactory ElementFactory;
58
59     osg::ref_ptr<GUIEventHandler>       _event_handler;
60     SGPropertyChangeCallback<GUIMgr>    _cb_mouse_mode;
61     bool                                _handle_events;
62
63     simgear::PropertyObject<int>        _width,
64                                         _height;
65
66     canvas::WindowWeakPtr _last_push,
67                           _last_mouse_over,
68                           _resize_window;
69     uint8_t _resize;
70     int     _last_cursor;
71
72     float _last_x,
73           _last_y;
74     double _last_scroll_time;
75
76     virtual ElementFactory getChildFactory(const std::string& type) const;
77
78     simgear::canvas::Placements
79     addPlacement(SGPropertyNode*, simgear::canvas::CanvasPtr canvas);
80
81     bool handleMouse(const osgGA::GUIEventAdapter& ea);
82     void handleResize(int x, int y, int width, int height);
83     void handleMouseMode(SGPropertyNode* node);
84 };
85
86 #endif /* CANVAS_GUI_MGR_HXX_ */