openscenegraph
Frame
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 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// Code by: Jeremy Moles (cubicool) 2007-2008
15
16#ifndef OSGWIDGET_FRAME
17#define OSGWIDGET_FRAME
18
19#include <osgWidget/Table>
20
21namespace osgWidget {
22
23/*
24Lets take a moment and explain how Frame texturing works. When you create a Frame, you use
25a specially designed texture that is "chopped" up horizontally by the Frame code into 8 equal
26regions. Each region is then textured to a corresponding portion of the Frame, in the
27following order:
28
29 +---+---+---+---+---+---+---+---+
30 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
31 +---+---+---+---+---+---+---+---+
32
33 1. Upper-Left corner.
34 2. Top border (rotated 90 degrees CCW).
35 3. Upper-Right corner.
36 4. Left border.
37 5. Right border.
38 6. Bottom-Left corner.
39 7. Bottom border (rotated 90 degrees CCW).
40 8. Bottom-Right corner.
41
42Now, these should be pretty self-explanatory if you visualize a frame as a 3x3 "table"
43(which is exactly what it is), but note how regions 2 and 7 are rotated counter-clockwise.
44We do this for a VERY important reason: we want to enable texture repeat on the border
45regions, so that when the frame is resized the borders cleanly paint the texture over
46the entire are (and don't stretch it). However, it is impossible in OpenGL to repeat a
47sub-region of a texture without including either the vertical or horizontal bounds, so the
48artist is required to rotate the region during their rendering so that our code can properly
49rotate it back internally and have it repeat in the desired way.
50
51This method of texturing a Frame object is inspired by World of Warcraft "edge files", and it
52is both efficient and easy-to-use--once you understand the basics. If you're still confused,
53take a look at this URL, or any of the example themes:
54
55 http://www.wowwiki.com/EdgeFiles
56*/
57
59{
60 public:
61
69
77
79 {
80 FRAME_RESIZE = 1,
81 FRAME_MOVE = 2,
82 FRAME_TEXTURE = 4,
83 FRAME_ALL = FRAME_RESIZE | FRAME_MOVE | FRAME_TEXTURE
84 };
85
86 static std::string cornerTypeToString (CornerType);
87 static std::string borderTypeToString (BorderType);
88
90 {
91 public:
93
94 Corner (CornerType = CORNER_LOWER_LEFT, point_type = 0.0f, point_type = 0.0f);
95 Corner (const Corner&, const osg::CopyOp&);
96
97 virtual void parented (Window*);
98 virtual bool mouseDrag (double, double, const WindowManager*);
99
101 {
102 return _corner;
103 }
104
106 {
107 _corner = corner;
108 }
109
111 {
112 _corner = corner;
113 _name = cornerTypeToString(corner);
114 }
115
116 protected:
117
119 };
120
122 {
123 public:
125
126 Border (BorderType = BORDER_LEFT, point_type = 0.0f, point_type = 0.0f);
127 Border (const Border&, const osg::CopyOp&);
128
129 virtual void parented (Window*);
130 virtual void positioned ();
131 virtual bool mouseDrag (double, double, const WindowManager*);
132
134 {
135 return _border;
136 }
137
139 {
140 _border = border;
141 }
142
144 {
145 _border = border;
146 _name = borderTypeToString(border);
147 }
148
149 protected:
150
152 };
153
155
156 Frame (const std::string& = "", unsigned int = 0);
157 Frame (const Frame&, const osg::CopyOp&);
158
160 const std::string&,
165 unsigned int = 0,
166 Frame* = 0
167 );
168
170 const std::string&,
174 unsigned int = 0,
175 Frame* = 0
176 );
177
179 const std::string&,
183 unsigned int = 0,
184 Frame* = 0
185 );
186
188 {
189 createSimpleFrame(_name, cw, ch, w, h, 0, this);
190 }
191
193 osg::Image* image,
194 point_type w,
195 point_type h
196 )
197 {
198 createSimpleFrameWithSingleTexture(_name, image, w, h, 0, this);
199 }
200
202
203 EmbeddedWindow* getEmbeddedWindow() { return dynamic_cast<EmbeddedWindow*>(getByRowCol(1, 1)); }
204
205 const EmbeddedWindow* getEmbeddedWindow() const { return dynamic_cast<const EmbeddedWindow*>(getByRowCol(1, 1)); }
206
207 Corner* getCorner(CornerType c) { return dynamic_cast<Corner*>(_getCorner(c)); }
208
209 const Corner* getCorner(CornerType c) const { return dynamic_cast<const Corner*>(_getCorner(c)); }
210
211 Border* getBorder(BorderType b) { return dynamic_cast<Border*>(_getBorder(b)); }
212
213 const Border* getBorder(BorderType b) const { return dynamic_cast<const Border*>(_getBorder(b)); }
214
215 // This method resizes the internal EmbeddedWindow object and then properly resizes
216 // the reset of the Frame based on the sizes of the Corners, Borders, etc.
218
219 unsigned int getFlags() const
220 {
221 return _flags;
222 }
223
224 void setFlags(unsigned int flags)
225 {
226 _flags = flags;
227 }
228
229 bool canResize() const
230 {
231 return (_flags & FRAME_RESIZE) != 0;
232 }
233
234 bool canMove() const
235 {
236 return (_flags & FRAME_MOVE) != 0;
237 }
238
239 bool canTexture() const
240 {
241 return (_flags & FRAME_TEXTURE) != 0;
242 }
243
244 protected:
245
248
249 unsigned int _flags;
250};
251
252}
253
254#endif
Definition Frame:122
META_Object(osgWidget, Border)
BorderType getBorderType() const
Definition Frame:133
BorderType _border
Definition Frame:151
virtual bool mouseDrag(double, double, const WindowManager *)
void setBorderTypeAndName(BorderType border)
Definition Frame:143
virtual void positioned()
void setBorderType(BorderType border)
Definition Frame:138
Border(const Border &, const osg::CopyOp &)
virtual void parented(Window *)
Border(BorderType=BORDER_LEFT, point_type=0.0f, point_type=0.0f)
Definition Frame:90
Corner(CornerType=CORNER_LOWER_LEFT, point_type=0.0f, point_type=0.0f)
CornerType _corner
Definition Frame:118
CornerType getCornerType() const
Definition Frame:100
virtual bool mouseDrag(double, double, const WindowManager *)
Corner(const Corner &, const osg::CopyOp &)
void setCornerTypeAndName(CornerType corner)
Definition Frame:110
META_Object(osgWidget, Corner)
virtual void parented(Window *)
void setCornerType(CornerType corner)
Definition Frame:105
Definition Frame:59
static Frame * createSimpleFrameFromTheme(const std::string &, osg::ref_ptr< osg::Image >, point_type, point_type, unsigned int=0, Frame *=0)
void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h)
Definition Frame:187
META_Object(osgWidget, Frame)
static Frame * createSimpleFrameWithSingleTexture(const std::string &, osg::ref_ptr< osg::Image >, point_type, point_type, unsigned int=0, Frame *=0)
Widget * _getBorder(BorderType) const
const Border * getBorder(BorderType b) const
Definition Frame:213
bool resizeFrame(point_type, point_type)
static Frame * createSimpleFrame(const std::string &, point_type, point_type, point_type, point_type, unsigned int=0, Frame *=0)
Widget * _getCorner(CornerType) const
unsigned int _flags
Definition Frame:249
const Corner * getCorner(CornerType c) const
Definition Frame:209
const EmbeddedWindow * getEmbeddedWindow() const
Definition Frame:205
unsigned int getFlags() const
Definition Frame:219
bool canTexture() const
Definition Frame:239
CornerType
Definition Frame:63
@ CORNER_UPPER_LEFT
Definition Frame:66
@ CORNER_LOWER_LEFT
Definition Frame:64
@ CORNER_LOWER_RIGHT
Definition Frame:65
void setFlags(unsigned int flags)
Definition Frame:224
Corner * getCorner(CornerType c)
Definition Frame:207
BorderType
Definition Frame:71
@ BORDER_TOP
Definition Frame:74
@ BORDER_RIGHT
Definition Frame:73
@ BORDER_LEFT
Definition Frame:72
bool setWindow(Window *)
static std::string borderTypeToString(BorderType)
EmbeddedWindow * getEmbeddedWindow()
Definition Frame:203
FrameOptions
Definition Frame:79
static std::string cornerTypeToString(CornerType)
bool canMove() const
Definition Frame:234
Frame(const Frame &, const osg::CopyOp &)
void createSimpleFrameWithSingleTexture(osg::Image *image, point_type w, point_type h)
Definition Frame:192
bool canResize() const
Definition Frame:229
Frame(const std::string &="", unsigned int=0)
Border * getBorder(BorderType b)
Definition Frame:211
Definition Table:24
Definition osgWidget/Widget:35
Corner
Definition osgWidget/Widget:37
Definition WindowManager:39
Definition Window:44
Definition CopyOp:41
Definition Image:179
Definition ref_ptr:32
Definition Box:21
Point::value_type point_type
Definition osgWidget/Types:33
#define OSGWIDGET_EXPORT
Definition osgWidget/Export:42