]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/CanvasWindow.hxx
Canvas: basic layouting system.
[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/layout/Layout.hxx>
24 #include <simgear/canvas/events/MouseEvent.hxx>
25 #include <simgear/props/PropertyBasedElement.hxx>
26 #include <simgear/props/propertyObject.hxx>
27 #include <simgear/misc/CSSBorder.hxx>
28
29 #include <osg/Geode>
30 #include <osg/Geometry>
31
32 namespace simgear
33 {
34 namespace canvas
35 {
36
37   class Window:
38     public Image,
39     public LayoutItem
40   {
41     public:
42       static const std::string TYPE_NAME;
43
44       enum Resize
45       {
46         NONE    = 0,
47         LEFT    = 1,
48         RIGHT   = LEFT << 1,
49         TOP     = RIGHT << 1,
50         BOTTOM  = TOP << 1,
51         INIT    = BOTTOM << 1
52       };
53
54       /**
55        * @param node    Property node containing settings for this window:
56        *                  capture-events    Disable/Enable event capturing
57        *                  content-size[0-1] Size of content area (excluding
58        *                                    decoration border)
59        *                  decoration-border Size of decoration border
60        *                  resize            Enable resize cursor and properties
61        *                  shadow-inset      Inset of shadow image
62        *                  shadow-radius     Radius/outset of shadow image
63        */
64       Window( const CanvasWeakPtr& canvas,
65               const SGPropertyNode_ptr& node,
66               const Style& parent_style = Style(),
67               Element* parent = 0 );
68       virtual ~Window();
69
70       virtual void update(double delta_time_sec);
71       virtual void valueChanged(SGPropertyNode* node);
72
73       osg::Group* getGroup();
74       const SGVec2<float> getPosition() const;
75       const SGRect<float>  getScreenRegion() const;
76
77       void setCanvasContent(CanvasPtr canvas);
78       simgear::canvas::CanvasWeakPtr getCanvasContent() const;
79
80       void setLayout(const LayoutRef& layout);
81
82       CanvasPtr getCanvasDecoration() const;
83
84       bool isResizable() const;
85       bool isCapturingEvents() const;
86
87       /**
88        * Moves window on top of all other windows with the same z-index.
89        *
90        * @note If no z-index is set it defaults to 0.
91        */
92       void raise();
93
94       void handleResize( uint8_t mode,
95                          const osg::Vec2f& offset = osg::Vec2f() );
96
97     protected:
98
99       enum Attributes
100       {
101         DECORATION = 1
102       };
103
104       uint32_t  _attributes_dirty;
105
106       CanvasPtr        _canvas_decoration;
107       CanvasWeakPtr    _canvas_content;
108       LayoutRef        _layout;
109
110       ImagePtr _image_content,
111                _image_shadow;
112
113       bool _resizable,
114            _capture_events;
115
116       PropertyObject<int> _resize_top,
117                           _resize_right,
118                           _resize_bottom,
119                           _resize_left,
120                           _resize_status;
121
122       CSSBorder _decoration_border;
123
124       void parseDecorationBorder(const std::string& str);
125       void updateDecoration();
126   };
127
128 } // namespace canvas
129 } // namespace simgear
130
131 #endif /* CANVAS_WINDOW_HXX_ */