]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/CanvasWindow.hxx
Fixes for error handling in NetChannel
[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       virtual void setVisible(bool visible);
88       virtual bool isVisible() const;
89
90       /**
91        * Moves window on top of all other windows with the same z-index.
92        *
93        * @note If no z-index is set it defaults to 0.
94        */
95       void raise();
96
97       void handleResize( uint8_t mode,
98                          const osg::Vec2f& offset = osg::Vec2f() );
99
100     protected:
101
102       enum Attributes
103       {
104         DECORATION = 1
105       };
106
107       uint32_t  _attributes_dirty;
108
109       CanvasPtr        _canvas_decoration;
110       CanvasWeakPtr    _canvas_content;
111       LayoutRef        _layout;
112
113       ImagePtr _image_content,
114                _image_shadow;
115
116       bool _resizable,
117            _capture_events;
118
119       PropertyObject<int> _resize_top,
120                           _resize_right,
121                           _resize_bottom,
122                           _resize_left,
123                           _resize_status;
124
125       CSSBorder _decoration_border;
126
127       void parseDecorationBorder(const std::string& str);
128       void updateDecoration();
129   };
130
131 } // namespace canvas
132 } // namespace simgear
133
134 #endif /* CANVAS_WINDOW_HXX_ */