OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Frame.h
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 
21 namespace osgWidget {
22 
23 /*
24 Lets take a moment and explain how Frame texturing works. When you create a Frame, you use
25 a specially designed texture that is "chopped" up horizontally by the Frame code into 8 equal
26 regions. Each region is then textured to a corresponding portion of the Frame, in the
27 following 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 
42 Now, 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.
44 We do this for a VERY important reason: we want to enable texture repeat on the border
45 regions, so that when the frame is resized the borders cleanly paint the texture over
46 the entire are (and don't stretch it). However, it is impossible in OpenGL to repeat a
47 sub-region of a texture without including either the vertical or horizontal bounds, so the
48 artist is required to rotate the region during their rendering so that our code can properly
49 rotate it back internally and have it repeat in the desired way.
50 
51 This method of texturing a Frame object is inspired by World of Warcraft "edge files", and it
52 is both efficient and easy-to-use--once you understand the basics. If you're still confused,
53 take a look at this URL, or any of the example themes:
54 
55  http://www.wowwiki.com/EdgeFiles
56 */
57 
59 {
60  public:
61 
63  {
67  CORNER_UPPER_RIGHT
68  };
69 
71  {
75  BORDER_BOTTOM
76  };
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 
159  static Frame* createSimpleFrame(
160  const std::string&,
161  point_type,
162  point_type,
163  point_type,
164  point_type,
165  unsigned int = 0,
166  Frame* = 0
167  );
168 
169  static Frame* createSimpleFrameWithSingleTexture(
170  const std::string&,
171  osg::Image*,
172  point_type,
173  point_type,
174  unsigned int = 0,
175  Frame* = 0
176  );
177 
178  static Frame* createSimpleFrameFromTheme(
179  const std::string&,
180  osg::Image*,
181  point_type,
182  point_type,
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 
201  bool setWindow(Window*);
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.
217  bool resizeFrame(point_type, point_type);
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 
246  Widget* _getCorner (CornerType) const;
247  Widget* _getBorder (BorderType) const;
248 
249  unsigned int _flags;
250 };
251 
252 }
253 
254 #endif
void setFlags(unsigned int flags)
Definition: Frame.h:224
const Border * getBorder(BorderType b) const
Definition: Frame.h:213
void setBorderTypeAndName(BorderType border)
Definition: Frame.h:143
bool canResize() const
Definition: Frame.h:229
const EmbeddedWindow * getEmbeddedWindow() const
Definition: Frame.h:205
Border * getBorder(BorderType b)
Definition: Frame.h:211
Definition: Box.h:21
#define OSGWIDGET_EXPORT
Definition: Export.h:42
unsigned int _flags
Definition: Frame.h:249
void setCornerTypeAndName(CornerType corner)
Definition: Frame.h:110
bool canTexture() const
Definition: Frame.h:239
Point::value_type point_type
Definition: Types.h:33
unsigned int getFlags() const
Definition: Frame.h:219
#define META_Object(library, name)
Definition: Object.h:42
EmbeddedWindow * getEmbeddedWindow()
Definition: Frame.h:203
BorderType _border
Definition: Frame.h:151
CornerType getCornerType() const
Definition: Frame.h:100
void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h)
Definition: Frame.h:187
void createSimpleFrameWithSingleTexture(osg::Image *image, point_type w, point_type h)
Definition: Frame.h:192
const Corner * getCorner(CornerType c) const
Definition: Frame.h:209
BorderType getBorderType() const
Definition: Frame.h:133
void setCornerType(CornerType corner)
Definition: Frame.h:105
CornerType _corner
Definition: Frame.h:118
void setBorderType(BorderType border)
Definition: Frame.h:138
Corner * getCorner(CornerType c)
Definition: Frame.h:207
GLint GLenum GLsizei GLsizei GLsizei GLint border
Definition: GLU.h:71
bool canMove() const
Definition: Frame.h:234