| 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_WIDGET |
|---|
| 17 | #define OSGWIDGET_WIDGET |
|---|
| 18 | |
|---|
| 19 | #include <osg/Texture2D> |
|---|
| 20 | #include <osgWidget/EventInterface> |
|---|
| 21 | #include <osgWidget/StyleInterface> |
|---|
| 22 | #include <osgWidget/UIObjectParent> |
|---|
| 23 | #include <osgWidget/Types> |
|---|
| 24 | |
|---|
| 25 | namespace osgWidget { |
|---|
| 26 | |
|---|
| 27 | class Window; |
|---|
| 28 | class WindowManager; |
|---|
| 29 | |
|---|
| 30 | // A Widget is a rectangular region that recieves events about the state of various input |
|---|
| 31 | // devices such as the pointer and keyboard. It is aware of it's width, height, and origin but |
|---|
| 32 | // nothing else. It is the job of higher-level container objects to organize layouts and |
|---|
| 33 | // the like, and to contextualize the meaning of the widgets "origin" (whether it is absolute |
|---|
| 34 | // or relative). |
|---|
| 35 | class OSGWIDGET_EXPORT Widget: public osg::Geometry, public EventInterface, public StyleInterface { |
|---|
| 36 | public: |
|---|
| 37 | enum Corner { |
|---|
| 38 | LOWER_LEFT = 0, |
|---|
| 39 | LOWER_RIGHT = 1, |
|---|
| 40 | UPPER_RIGHT = 2, |
|---|
| 41 | UPPER_LEFT = 3, |
|---|
| 42 | LL = LOWER_LEFT, |
|---|
| 43 | LR = LOWER_RIGHT, |
|---|
| 44 | UR = UPPER_RIGHT, |
|---|
| 45 | UL = UPPER_LEFT, |
|---|
| 46 | ALL_CORNERS = 4 |
|---|
| 47 | }; |
|---|
| 48 | |
|---|
| 49 | enum Layer { |
|---|
| 50 | LAYER_TOP = 100, |
|---|
| 51 | LAYER_HIGH = 75, |
|---|
| 52 | LAYER_MIDDLE = 50, |
|---|
| 53 | LAYER_LOW = 25, |
|---|
| 54 | LAYER_BG = 0 |
|---|
| 55 | }; |
|---|
| 56 | |
|---|
| 57 | enum VerticalAlignment { |
|---|
| 58 | VA_CENTER, |
|---|
| 59 | VA_TOP, |
|---|
| 60 | VA_BOTTOM |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | enum HorizontalAlignment { |
|---|
| 64 | HA_CENTER, |
|---|
| 65 | HA_LEFT, |
|---|
| 66 | HA_RIGHT |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | enum CoordinateMode { |
|---|
| 70 | CM_ABSOLUTE, |
|---|
| 71 | CM_RELATIVE |
|---|
| 72 | }; |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | Widget (const std::string& = "", point_type = 0.0f, point_type = 0.0f); |
|---|
| 76 | Widget (const Widget&, const osg::CopyOp&); |
|---|
| 77 | |
|---|
| 78 | META_Object (osgWidget, Widget); |
|---|
| 79 | |
|---|
| 80 | virtual ~Widget() { |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | // This method is called when the widget is added to a Window; this is useful |
|---|
| 84 | // when the widget needs to do something advanced (like a Label). The parent |
|---|
| 85 | // is passed as the first argument, although _parent should already be set. |
|---|
| 86 | virtual void parented(Window*) { |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | virtual void unparented(Window*) { |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | // This method is called when the widget's parent Window is added to a |
|---|
| 93 | // WindowManager object. The base managed method (WHICH YOU MUST REMEMBER |
|---|
| 94 | // TO CALL IN YOUR DERIVED METHODS!) sets the TexMat properly depending |
|---|
| 95 | // on what coordinate system you're using. |
|---|
| 96 | virtual void managed(WindowManager*) { |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | virtual void unmanaged(WindowManager*) { |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | // This method is called when the widget is resized or reallocated in any |
|---|
| 103 | // way. This is useful when the widget manages some internal Drawables that need |
|---|
| 104 | // to be modified in some way. |
|---|
| 105 | virtual void positioned() { |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | void setDimensions( |
|---|
| 109 | point_type = -1.0f, |
|---|
| 110 | point_type = -1.0f, |
|---|
| 111 | point_type = -1.0f, |
|---|
| 112 | point_type = -1.0f, |
|---|
| 113 | point_type = -1.0f |
|---|
| 114 | ); |
|---|
| 115 | |
|---|
| 116 | void setPadding (point_type); |
|---|
| 117 | void setColor (color_type, color_type, color_type, color_type, Corner = ALL_CORNERS); |
|---|
| 118 | void addColor (color_type, color_type, color_type, color_type, Corner = ALL_CORNERS); |
|---|
| 119 | void setTexCoord (texcoord_type, texcoord_type, Corner = ALL_CORNERS); |
|---|
| 120 | void setLayer (Layer l, unsigned int offset = 0); |
|---|
| 121 | |
|---|
| 122 | // These are additional texture coordinate setting methods. |
|---|
| 123 | // This method will use a given origin as the LOWER_LEFT point and texture the |
|---|
| 124 | // remaining area based on some width and height values. |
|---|
| 125 | void setTexCoordRegion(point_type, point_type, point_type, point_type); |
|---|
| 126 | |
|---|
| 127 | // These are convenience methods for setting up wrapping modes. |
|---|
| 128 | void setTexCoordWrapHorizontal (); |
|---|
| 129 | void setTexCoordWrapVertical (); |
|---|
| 130 | |
|---|
| 131 | bool setImage (osg::Image*, bool = false, bool = false); |
|---|
| 132 | bool setImage (const std::string&, bool = false, bool = false); |
|---|
| 133 | bool setTexture (osg::Texture*, bool = false, bool = false); |
|---|
| 134 | |
|---|
| 135 | void addX (point_type); |
|---|
| 136 | void addY (point_type); |
|---|
| 137 | void addWidth (point_type); |
|---|
| 138 | void addHeight (point_type); |
|---|
| 139 | void addOrigin (point_type, point_type); |
|---|
| 140 | void addSize (point_type, point_type); |
|---|
| 141 | |
|---|
| 142 | point_type getWidth () const; |
|---|
| 143 | point_type getHeight () const; |
|---|
| 144 | point_type getX () const; |
|---|
| 145 | point_type getY () const; |
|---|
| 146 | point_type getZ () const; |
|---|
| 147 | point_type getPadHorizontal () const; |
|---|
| 148 | point_type getPadVertical () const; |
|---|
| 149 | |
|---|
| 150 | const Point& getPoint (Corner = ALL_CORNERS) const; |
|---|
| 151 | const Color& getColor (Corner = ALL_CORNERS) const; |
|---|
| 152 | const TexCoord& getTexCoord (Corner = ALL_CORNERS) const; |
|---|
| 153 | |
|---|
| 154 | Color getImageColorAtXY (point_type x, point_type y) const; |
|---|
| 155 | XYCoord localXY (double, double) const; |
|---|
| 156 | |
|---|
| 157 | bool isPaddingUniform() const; |
|---|
| 158 | |
|---|
| 159 | bool isManaged() const { |
|---|
| 160 | return _isManaged; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | bool isStyled() const { |
|---|
| 164 | return _isStyled; |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | void setDimensions(const Quad& q, point_type z = -1.0f) { |
|---|
| 168 | setDimensions(q[0], q[1], q[2], q[3], z); |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | void setX(point_type x) { |
|---|
| 172 | setDimensions(x); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | void setY(point_type y) { |
|---|
| 176 | setDimensions(-1.0f, y); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | // This method should be use with extreme caution. |
|---|
| 180 | void setZ(point_type z) { |
|---|
| 181 | setDimensions(-1.0f, -1.0f, -1.0f, -1.0f, z); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | void setWidth(point_type w) { |
|---|
| 185 | setDimensions(-1.0f, -1.0f, w); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | void setHeight(point_type h) { |
|---|
| 189 | setDimensions(-1.0f, -1.0f, -1.0f, h); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | void setOrigin(point_type x, point_type y) { |
|---|
| 193 | setDimensions(x, y); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | void setOrigin(const XYCoord& xy) { |
|---|
| 197 | setOrigin(xy.x(), xy.y()); |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | void setSize(point_type w, point_type h) { |
|---|
| 201 | setDimensions(-1.0f, -1.0f, w, h); |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | void setSize(const XYCoord& xy) { |
|---|
| 205 | setSize(xy.x(), xy.y()); |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | void setColor(const Color& col, Corner p = ALL_CORNERS) { |
|---|
| 209 | setColor(col.r(), col.g(), col.b(), col.a(), p); |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | void setTexCoord(const XYCoord& xy, Corner p = ALL_CORNERS) { |
|---|
| 213 | setTexCoord(xy.x(), xy.y(), p); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | void setTexCoordRegion(const XYCoord& xy, point_type w, point_type h) { |
|---|
| 217 | setTexCoordRegion(xy.x(), xy.y(), w, h); |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | void setTexCoordRegion(point_type x, point_type y, const XYCoord& wh) { |
|---|
| 221 | setTexCoordRegion(x, y, wh.x(), wh.y()); |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | void setTexCoordRegion(const XYCoord& xy, const XYCoord& wh) { |
|---|
| 225 | setTexCoordRegion(xy.x(), xy.y(), wh.x(), wh.y()); |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | void addColor(const Color& col, Corner p = ALL_CORNERS) { |
|---|
| 229 | addColor(col.r(), col.g(), col.b(), col.a(), p); |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | void addOrigin(const XYCoord& xy) { |
|---|
| 233 | addOrigin(xy.x(), xy.y()); |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | void addSize(const XYCoord& xy) { |
|---|
| 237 | addSize(xy.x(), xy.y()); |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | void setMinimumSize(point_type width, point_type height) { |
|---|
| 241 | _minWidth = width; |
|---|
| 242 | _minHeight = height; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | void setMinimumSize(const XYCoord& xy) { |
|---|
| 246 | setMinimumSize(xy.x(), xy.y()); |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | void setPadLeft(point_type p) { |
|---|
| 250 | _padLeft = p; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | void setPadRight(point_type p) { |
|---|
| 254 | _padRight = p; |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | void setPadTop(point_type p) { |
|---|
| 258 | _padTop = p; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | void setPadBottom(point_type p) { |
|---|
| 262 | _padBottom = p; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | void setAlignHorizontal(HorizontalAlignment h) { |
|---|
| 266 | _halign = h; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | void setAlignVertical(VerticalAlignment v) { |
|---|
| 270 | _valign = v; |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | void setCoordinateMode(CoordinateMode cm) { |
|---|
| 274 | _coordMode = cm; |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | void setCanFill(bool f) { |
|---|
| 278 | _canFill = f; |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | void setCanClone(bool c) { |
|---|
| 282 | _canClone = c; |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | WindowManager* getWindowManager() { |
|---|
| 286 | return _getWindowManager(); |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | const WindowManager* getWindowManager() const { |
|---|
| 290 | return _getWindowManager(); |
|---|
| 291 | } |
|---|
| 292 | |
|---|
| 293 | Window* getParent() { |
|---|
| 294 | return _parent; |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | const Window* getParent() const { |
|---|
| 298 | return _parent; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | unsigned int getIndex() const { |
|---|
| 302 | return _index; |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | XYCoord getOrigin() const { |
|---|
| 306 | return XYCoord(getX(), getY()); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | Color getImageColorAtXY(const XYCoord& xy) const { |
|---|
| 310 | return getImageColorAtXY(xy.x(), xy.y()); |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | Color getImageColorAtPointerXY(double x, double y) const { |
|---|
| 314 | return getImageColorAtXY(localXY(x, y)); |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | Point getPosition() const { |
|---|
| 318 | return Point(getX(), getY(), getZ()); |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | XYCoord getSize() const { |
|---|
| 322 | return XYCoord(getWidth(), getHeight()); |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | Quad getDimensions() const { |
|---|
| 326 | return Quad(getX(), getY(), getWidth(), getHeight()); |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | point_type getPadLeft() const { |
|---|
| 330 | return _padLeft; |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | point_type getPadRight() const { |
|---|
| 334 | return _padRight; |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | point_type getPadTop() const { |
|---|
| 338 | return _padTop; |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | point_type getPadBottom() const { |
|---|
| 342 | return _padBottom; |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | HorizontalAlignment getAlignHorizontal() const { |
|---|
| 346 | return _halign; |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | VerticalAlignment getAlignVertical() const { |
|---|
| 350 | return _valign; |
|---|
| 351 | } |
|---|
| 352 | |
|---|
| 353 | CoordinateMode getCoordinateMode() const { |
|---|
| 354 | return _coordMode; |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | bool canFill() const { |
|---|
| 358 | return _canFill; |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | bool canClone() const { |
|---|
| 362 | return _canClone; |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | // This casts the bool _fill variable to be used in iteratively in functions such |
|---|
| 366 | // as Window::_accumulate and whatnot. |
|---|
| 367 | point_type getFillAsNumeric() const { |
|---|
| 368 | return static_cast<point_type>(_canFill); |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | point_type getWidthTotal() const { |
|---|
| 372 | return getWidth() + getPadHorizontal(); |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | point_type getHeightTotal() const { |
|---|
| 376 | return getHeight() + getPadVertical(); |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | point_type getMinWidth() const { |
|---|
| 380 | return _minWidth; |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | point_type getMinHeight() const { |
|---|
| 384 | return _minHeight; |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | point_type getMinWidthTotal() const { |
|---|
| 388 | return _minWidth + getPadHorizontal(); |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | point_type getMinHeightTotal() const { |
|---|
| 392 | return _minHeight + getPadVertical(); |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | unsigned int getLayer() const { |
|---|
| 396 | return _layer; |
|---|
| 397 | } |
|---|
| 398 | |
|---|
| 399 | protected: |
|---|
| 400 | |
|---|
| 401 | point_type _calculateZ(unsigned int) const; |
|---|
| 402 | |
|---|
| 403 | PointArray* _verts() { |
|---|
| 404 | return dynamic_cast<PointArray*>(getVertexArray()); |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | const PointArray* _verts() const { |
|---|
| 408 | return dynamic_cast<const PointArray*>(getVertexArray()); |
|---|
| 409 | } |
|---|
| 410 | |
|---|
| 411 | ColorArray* _cols() { |
|---|
| 412 | return dynamic_cast<ColorArray*>(getColorArray()); |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | const ColorArray* _cols() const { |
|---|
| 416 | return dynamic_cast<const ColorArray*>(getColorArray()); |
|---|
| 417 | } |
|---|
| 418 | |
|---|
| 419 | TexCoordArray* _texs() { |
|---|
| 420 | return dynamic_cast<TexCoordArray*>(getTexCoordArray(0)); |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | const TexCoordArray* _texs() const { |
|---|
| 424 | return dynamic_cast<const TexCoordArray*>(getTexCoordArray(0)); |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | osg::Texture* _texture() { |
|---|
| 428 | osg::StateSet* ss = getStateSet(); |
|---|
| 429 | |
|---|
| 430 | if(!ss) return 0; |
|---|
| 431 | |
|---|
| 432 | return dynamic_cast<osg::Texture2D*>( |
|---|
| 433 | ss->getTextureAttribute(0, osg::StateAttribute::TEXTURE) |
|---|
| 434 | ); |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | const osg::Texture* _texture() const { |
|---|
| 438 | const osg::StateSet* ss = getStateSet(); |
|---|
| 439 | |
|---|
| 440 | if(!ss) return 0; |
|---|
| 441 | |
|---|
| 442 | return dynamic_cast<const osg::Texture2D*>( |
|---|
| 443 | ss->getTextureAttribute(0, osg::StateAttribute::TEXTURE) |
|---|
| 444 | ); |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | osg::Image* _image() { |
|---|
| 448 | return _getImage(); |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | const osg::Image* _image() const { |
|---|
| 452 | return _getImage(); |
|---|
| 453 | } |
|---|
| 454 | |
|---|
| 455 | friend class Window; |
|---|
| 456 | |
|---|
| 457 | // TODO: Because of the current class design, I don't think it's possible to |
|---|
| 458 | // have a ref_ptr here. :( |
|---|
| 459 | Window* _parent; |
|---|
| 460 | |
|---|
| 461 | unsigned int _index; |
|---|
| 462 | unsigned int _layer; |
|---|
| 463 | |
|---|
| 464 | // Padding is the value of pixels of space between whatever the widget is "contianed" |
|---|
| 465 | // in and the point at which it starts getting placed. |
|---|
| 466 | point_type _padLeft; |
|---|
| 467 | point_type _padRight; |
|---|
| 468 | point_type _padTop; |
|---|
| 469 | point_type _padBottom; |
|---|
| 470 | |
|---|
| 471 | // The alignments are used in conjuction when the widget is NOT set to fill. |
|---|
| 472 | VerticalAlignment _valign; |
|---|
| 473 | HorizontalAlignment _halign; |
|---|
| 474 | |
|---|
| 475 | // This flag determines how sizing values are interpretted by setDimensions(). |
|---|
| 476 | CoordinateMode _coordMode; |
|---|
| 477 | |
|---|
| 478 | // These are the relative values, which are not stored directly in our verts |
|---|
| 479 | // array but kept around for calculation later. |
|---|
| 480 | Quad _relCoords; |
|---|
| 481 | |
|---|
| 482 | // This fill flag determines whether or not the widget will resize itself to fill |
|---|
| 483 | // all available space. |
|---|
| 484 | bool _canFill; |
|---|
| 485 | |
|---|
| 486 | // Set this to false in an implementation to prevent copying. |
|---|
| 487 | bool _canClone; |
|---|
| 488 | |
|---|
| 489 | // This variable is only used by the Window object to determine if it's necessary |
|---|
| 490 | // to call managed(). |
|---|
| 491 | bool _isManaged; |
|---|
| 492 | |
|---|
| 493 | // This variable is like _isManaged; it is used to store whether the Widget has |
|---|
| 494 | // been styled yet. |
|---|
| 495 | bool _isStyled; |
|---|
| 496 | |
|---|
| 497 | // Set these variables to be the minimum size of a Widget so that it cannot be |
|---|
| 498 | // resized any smaller than this. |
|---|
| 499 | point_type _minWidth; |
|---|
| 500 | point_type _minHeight; |
|---|
| 501 | |
|---|
| 502 | static osg::ref_ptr<PointArray> _norms; |
|---|
| 503 | |
|---|
| 504 | WindowManager* _getWindowManager () const; |
|---|
| 505 | osg::Image* _getImage () const; |
|---|
| 506 | |
|---|
| 507 | }; |
|---|
| 508 | |
|---|
| 509 | typedef std::list<osg::observer_ptr<Widget> > WidgetList; |
|---|
| 510 | |
|---|
| 511 | // A Widget subclass that prints stuff using osg::notify(). :) |
|---|
| 512 | struct NotifyWidget: public Widget { |
|---|
| 513 | META_Object(osgWidget, NotifyWidget); |
|---|
| 514 | |
|---|
| 515 | NotifyWidget(const std::string& n = "", point_type w = 0.0f, point_type h = 0.0f): |
|---|
| 516 | Widget(n, w, h) { |
|---|
| 517 | setEventMask(EVENT_ALL); |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | NotifyWidget(const NotifyWidget& widget, const osg::CopyOp& co): |
|---|
| 521 | Widget(widget, co) { |
|---|
| 522 | } |
|---|
| 523 | |
|---|
| 524 | bool focus(const WindowManager*) { |
|---|
| 525 | osg::notify(osg::NOTICE) << _name << " > focus called" << std::endl; |
|---|
| 526 | |
|---|
| 527 | return false; |
|---|
| 528 | } |
|---|
| 529 | |
|---|
| 530 | bool unfocus(const WindowManager*) { |
|---|
| 531 | osg::notify(osg::NOTICE) << _name << " > unfocus called" << std::endl; |
|---|
| 532 | |
|---|
| 533 | return false; |
|---|
| 534 | } |
|---|
| 535 | |
|---|
| 536 | bool mouseEnter(double, double, const WindowManager*) { |
|---|
| 537 | osg::notify(osg::NOTICE) << _name << " > mouseEnter called" << std::endl; |
|---|
| 538 | |
|---|
| 539 | return false; |
|---|
| 540 | } |
|---|
| 541 | |
|---|
| 542 | bool mouseOver(double, double, const WindowManager*) { |
|---|
| 543 | osg::notify(osg::NOTICE) << _name << " > mouseOver called" << std::endl; |
|---|
| 544 | |
|---|
| 545 | return false; |
|---|
| 546 | } |
|---|
| 547 | |
|---|
| 548 | bool mouseLeave(double, double, const WindowManager*) { |
|---|
| 549 | osg::notify(osg::NOTICE) << _name << " > mouseLeave called" << std::endl; |
|---|
| 550 | |
|---|
| 551 | return false; |
|---|
| 552 | } |
|---|
| 553 | |
|---|
| 554 | bool mouseDrag(double, double, const WindowManager*) { |
|---|
| 555 | osg::notify(osg::NOTICE) << _name << " > mouseDrag called" << std::endl; |
|---|
| 556 | |
|---|
| 557 | return false; |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | bool mousePush(double, double, const WindowManager*) { |
|---|
| 561 | osg::notify(osg::NOTICE) << _name << " > mousePush called" << std::endl; |
|---|
| 562 | |
|---|
| 563 | return false; |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | bool mouseRelease(double, double, const WindowManager*) { |
|---|
| 567 | osg::notify(osg::NOTICE) << _name << " > mouseRelease called" << std::endl; |
|---|
| 568 | |
|---|
| 569 | return false; |
|---|
| 570 | } |
|---|
| 571 | |
|---|
| 572 | bool mouseScroll(double, double, const WindowManager*) { |
|---|
| 573 | osg::notify(osg::NOTICE) << _name << " > mouseScroll called" << std::endl; |
|---|
| 574 | |
|---|
| 575 | return false; |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | bool keyPress(int, int, const WindowManager*) { |
|---|
| 579 | osg::notify(osg::NOTICE) << _name << " > keyPress called" << std::endl; |
|---|
| 580 | |
|---|
| 581 | return false; |
|---|
| 582 | } |
|---|
| 583 | |
|---|
| 584 | bool keyRelease(int, int, const WindowManager*) { |
|---|
| 585 | osg::notify(osg::NOTICE) << _name << " > keyRelease called" << std::endl; |
|---|
| 586 | |
|---|
| 587 | return false; |
|---|
| 588 | } |
|---|
| 589 | }; |
|---|
| 590 | |
|---|
| 591 | // A Widget that eats all events and returns true. |
|---|
| 592 | struct NullWidget: public Widget { |
|---|
| 593 | META_Object(osgWidget, NullWidget); |
|---|
| 594 | |
|---|
| 595 | NullWidget(const std::string& n = "", point_type w = 0.0f, point_type h = 0.0f): |
|---|
| 596 | Widget(n, w, h) { |
|---|
| 597 | setEventMask(EVENT_ALL); |
|---|
| 598 | } |
|---|
| 599 | |
|---|
| 600 | NullWidget(const NullWidget& widget, const osg::CopyOp& co): |
|---|
| 601 | Widget(widget, co) { |
|---|
| 602 | } |
|---|
| 603 | |
|---|
| 604 | bool focus(const WindowManager*) { |
|---|
| 605 | return true; |
|---|
| 606 | } |
|---|
| 607 | |
|---|
| 608 | bool unfocus(const WindowManager*) { |
|---|
| 609 | return true; |
|---|
| 610 | } |
|---|
| 611 | |
|---|
| 612 | bool mouseEnter(double, double, const WindowManager*) { |
|---|
| 613 | return true; |
|---|
| 614 | } |
|---|
| 615 | |
|---|
| 616 | bool mouseOver(double, double, const WindowManager*) { |
|---|
| 617 | return true; |
|---|
| 618 | } |
|---|
| 619 | |
|---|
| 620 | bool mouseLeave(double, double, const WindowManager*) { |
|---|
| 621 | return true; |
|---|
| 622 | } |
|---|
| 623 | |
|---|
| 624 | bool mouseDrag(double, double, const WindowManager*) { |
|---|
| 625 | return true; |
|---|
| 626 | } |
|---|
| 627 | |
|---|
| 628 | bool mousePush(double, double, const WindowManager*) { |
|---|
| 629 | return true; |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | bool mouseRelease(double, double, const WindowManager*) { |
|---|
| 633 | return true; |
|---|
| 634 | } |
|---|
| 635 | |
|---|
| 636 | bool mouseScroll(double, double, const WindowManager*) { |
|---|
| 637 | return true; |
|---|
| 638 | } |
|---|
| 639 | |
|---|
| 640 | bool keyPress(int, int, const WindowManager*) { |
|---|
| 641 | return true; |
|---|
| 642 | } |
|---|
| 643 | |
|---|
| 644 | bool keyRelease(int, int, const WindowManager*) { |
|---|
| 645 | return true; |
|---|
| 646 | } |
|---|
| 647 | }; |
|---|
| 648 | |
|---|
| 649 | } |
|---|
| 650 | |
|---|
| 651 | #endif |
|---|