]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/CanvasWindow.hxx
57068a84e914b66fba986e648e1e187804780dc3
[simgear.git] / simgear / canvas / CanvasWindow.hxx
1 // Window for placing a Canvas onto it (for dialogs, menus, etc.)
2 //
3 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Library General Public License for more details.
14 //
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
18
19 #ifndef CANVAS_WINDOW_HXX_
20 #define CANVAS_WINDOW_HXX_
21
22 #include <simgear/canvas/elements/CanvasImage.hxx>
23 #include <simgear/canvas/events/MouseEvent.hxx>
24 #include <simgear/props/PropertyBasedElement.hxx>
25 #include <simgear/props/propertyObject.hxx>
26 #include <simgear/misc/CSSBorder.hxx>
27
28 #include <osg/Geode>
29 #include <osg/Geometry>
30
31 namespace simgear
32 {
33 namespace canvas
34 {
35
36   class Window:
37     public Image
38   {
39     public:
40       static const std::string TYPE_NAME;
41
42       enum Resize
43       {
44         NONE    = 0,
45         LEFT    = 1,
46         RIGHT   = LEFT << 1,
47         TOP     = RIGHT << 1,
48         BOTTOM  = TOP << 1,
49         INIT    = BOTTOM << 1
50       };
51
52       /**
53        * @param node    Property node containing settings for this window:
54        *                  capture-events    Disable/Enable event capturing
55        *                  content-size[0-1] Size of content area (excluding
56        *                                    decoration border)
57        *                  decoration-border Size of decoration border
58        *                  resize            Enable resize cursor and properties
59        *                  shadow-inset      Inset of shadow image
60        *                  shadow-radius     Radius/outset of shadow image
61        */
62       Window( const CanvasWeakPtr& canvas,
63               const SGPropertyNode_ptr& node,
64               const Style& parent_style = Style(),
65               Element* parent = 0 );
66       virtual ~Window();
67
68       virtual void update(double delta_time_sec);
69       virtual void valueChanged(SGPropertyNode* node);
70
71       osg::Group* getGroup();
72       const SGVec2<float> getPosition() const;
73       const SGRect<float>  getScreenRegion() const;
74
75       void setCanvasContent(CanvasPtr canvas);
76       simgear::canvas::CanvasWeakPtr getCanvasContent() const;
77
78       CanvasPtr getCanvasDecoration() const;
79
80       bool isResizable() const;
81       bool isCapturingEvents() const;
82
83       /**
84        * Moves window on top of all other windows with the same z-index.
85        *
86        * @note If no z-index is set it defaults to 0.
87        */
88       void raise();
89
90       void handleResize( uint8_t mode,
91                          const osg::Vec2f& offset = osg::Vec2f() );
92
93     protected:
94
95       enum Attributes
96       {
97         DECORATION = 1
98       };
99
100       uint32_t  _attributes_dirty;
101
102       CanvasPtr        _canvas_decoration;
103       CanvasWeakPtr    _canvas_content;
104
105       ImagePtr _image_content,
106                _image_shadow;
107
108       bool _resizable,
109            _capture_events;
110
111       PropertyObject<int> _resize_top,
112                           _resize_right,
113                           _resize_bottom,
114                           _resize_left,
115                           _resize_status;
116
117       CSSBorder _decoration_border;
118
119       void parseDecorationBorder(const std::string& str);
120       void updateDecoration();
121   };
122
123 } // namespace canvas
124 } // namespace simgear
125
126 #endif /* CANVAS_WINDOW_HXX_ */