1 /*********************************************************************** 2 created: 13/4/2004 3 author: Paul D Turner 4 5 purpose: Interface to base class for FrameWindow 6 *************************************************************************/ 7 /*************************************************************************** 8 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 9 * 10 * Permission is hereby granted, free of charge, to any person obtaining 11 * a copy of this software and associated documentation files (the 12 * "Software"), to deal in the Software without restriction, including 13 * without limitation the rights to use, copy, modify, merge, publish, 14 * distribute, sublicense, and/or sell copies of the Software, and to 15 * permit persons to whom the Software is furnished to do so, subject to 16 * the following conditions: 17 * 18 * The above copyright notice and this permission notice shall be 19 * included in all copies or substantial portions of the Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 * OTHER DEALINGS IN THE SOFTWARE. 28 ***************************************************************************/ 29 #ifndef _CEGUIFrameWindow_h_ 30 #define _CEGUIFrameWindow_h_ 31 32 #include "../Base.h" 33 #include "../Window.h" 34 35 #if defined(_MSC_VER) 36 # pragma warning(push) 37 # pragma warning(disable : 4251) 38 #endif 39 40 41 // Start of CEGUI namespace section 42 namespace CEGUI 43 { 44 /*! 45 \brief 46 Abstract base class for a movable, sizable, window with a title-bar and a frame. 47 */ 48 class CEGUIEXPORT FrameWindow : public Window 49 { 50 public: 51 static const String EventNamespace; //!< Namespace for global events 52 static const String WidgetTypeName; //!< Window factory name 53 54 /************************************************************************* 55 Constants 56 *************************************************************************/ 57 // additional event names for this window 58 /** Event fired when the rollup (shade) state of the window is changed. 59 * Handlers are passed a const WindowEventArgs reference with 60 * WindowEventArgs::window set to the FrameWindow whose rolled up state 61 * has been changed. 62 */ 63 static const String EventRollupToggled; 64 /** Event fired when the close button for the window is clicked. 65 * Handlers are passed a const WindowEventArgs reference with 66 * WindowEventArgs::window set to the FrameWindow whose close button was 67 * clicked. 68 */ 69 static const String EventCloseClicked; 70 /** Event fired when drag-sizing of the window starts. 71 * Handlers are passed a const WindowEventArgs reference with 72 * WindowEventArgs::window set to the FrameWindow that has started to be 73 * drag sized. 74 */ 75 static const String EventDragSizingStarted; 76 /** Event fired when drag-sizing of the window ends. 77 * Handlers are passed a const WindowEventArgs reference with 78 * WindowEventArgs::window set to the FrameWindow for which drag sizing has 79 * ended. 80 */ 81 static const String EventDragSizingEnded; 82 83 // other bits 84 static const float DefaultSizingBorderSize; //!< Default size for the sizing border (in pixels) 85 86 /************************************************************************* 87 Child Widget name constants 88 *************************************************************************/ 89 static const String TitlebarName; //!< Widget name for the titlebar component. 90 static const String CloseButtonName; //!< Widget name for the close button component. 91 92 93 /*! 94 \brief 95 Enumeration that defines the set of possible locations for the mouse on a frame windows sizing border. 96 */ 97 enum SizingLocation { 98 SizingNone, //!< Position is not a sizing location. 99 SizingTopLeft, //!< Position will size from the top-left. 100 SizingTopRight, //!< Position will size from the top-right. 101 SizingBottomLeft, //!< Position will size from the bottom left. 102 SizingBottomRight, //!< Position will size from the bottom right. 103 SizingTop, //!< Position will size from the top. 104 SizingLeft, //!< Position will size from the left. 105 SizingBottom, //!< Position will size from the bottom. 106 SizingRight //!< Position will size from the right. 107 }; 108 109 /*! 110 \brief 111 Initialises the Window based object ready for use. 112 113 \note 114 This must be called for every window created. Normally this is handled automatically by the WindowFactory for each Window type. 115 116 \return 117 Nothing 118 */ 119 virtual void initialiseComponents(void); 120 121 122 /*! 123 \brief 124 Return whether this window is sizable. Note that this requires that the window have an enabled frame and that sizing itself is enabled 125 126 \return 127 true if the window can be sized, false if the window can not be sized 128 */ isSizingEnabled(void)129 bool isSizingEnabled(void) const {return d_sizingEnabled && isFrameEnabled();} 130 131 132 /*! 133 \brief 134 Return whether the frame for this window is enabled. 135 136 \return 137 true if the frame for this window is enabled, false if the frame for this window is disabled. 138 */ isFrameEnabled(void)139 bool isFrameEnabled(void) const {return d_frameEnabled;} 140 141 142 /*! 143 \brief 144 Return whether the title bar for this window is enabled. 145 146 \return 147 true if the window has a title bar and it is enabled, false if the window has no title bar or if the title bar is disabled. 148 */ 149 bool isTitleBarEnabled(void) const; 150 151 152 /*! 153 \brief 154 Return whether this close button for this window is enabled. 155 156 \return 157 true if the window has a close button and it is enabled, false if the window either has no close button or if the close button is disabled. 158 */ 159 bool isCloseButtonEnabled(void) const; 160 161 162 /*! 163 \brief 164 Return whether roll up (a.k.a shading) is enabled for this window. 165 166 \return 167 true if roll up is enabled, false if roll up is disabled. 168 */ isRollupEnabled(void)169 bool isRollupEnabled(void) const {return d_rollupEnabled;} 170 171 /*! 172 \brief 173 Sets whether the window is currently rolled up (a.k.a shaded). 174 175 \see 176 Window::isRolledup 177 */ 178 void setRolledup(bool val); 179 180 /*! 181 \brief 182 Return whether the window is currently rolled up (a.k.a shaded). 183 184 \return 185 true if the window is rolled up, false if the window is not rolled up. 186 */ isRolledup(void)187 bool isRolledup(void) const {return d_rolledup;} 188 189 190 /*! 191 \brief 192 Return the thickness of the sizing border. 193 194 \return 195 float value describing the thickness of the sizing border in screen pixels. 196 */ getSizingBorderThickness(void)197 float getSizingBorderThickness(void) const {return d_borderSize;} 198 199 200 /*! 201 \brief 202 Enables or disables sizing for this window. 203 204 \param setting 205 set to true to enable sizing (also requires frame to be enabled), or false to disable sizing. 206 207 \return 208 nothing 209 */ 210 void setSizingEnabled(bool setting); 211 212 213 /*! 214 \brief 215 Enables or disables the frame for this window. 216 217 \param setting 218 set to true to enable the frame for this window, or false to disable the frame for this window. 219 220 \return 221 Nothing. 222 */ 223 void setFrameEnabled(bool setting); 224 225 226 /*! 227 \brief 228 Enables or disables the title bar for the frame window. 229 230 \param setting 231 set to true to enable the title bar (if one is attached), or false to disable the title bar. 232 233 \return 234 Nothing. 235 */ 236 void setTitleBarEnabled(bool setting); 237 238 239 /*! 240 \brief 241 Enables or disables the close button for the frame window. 242 243 \param setting 244 Set to true to enable the close button (if one is attached), or false to disable the close button. 245 246 \return 247 Nothing. 248 */ 249 void setCloseButtonEnabled(bool setting); 250 251 252 /*! 253 \brief 254 Enables or disables roll-up (shading) for this window. 255 256 \param setting 257 Set to true to enable roll-up for the frame window, or false to disable roll-up. 258 259 \return 260 Nothing. 261 */ 262 void setRollupEnabled(bool setting); 263 264 265 /*! 266 \brief 267 Toggles the state of the window between rolled-up (shaded) and normal sizes. This requires roll-up to be enabled. 268 269 \return 270 Nothing 271 */ 272 void toggleRollup(void); 273 274 /*! 275 \brief 276 Set the size of the sizing border for this window. 277 278 \param pixels 279 float value specifying the thickness for the sizing border in screen pixels. 280 281 \return 282 Nothing. 283 */ setSizingBorderThickness(float pixels)284 void setSizingBorderThickness(float pixels) {d_borderSize = pixels;} 285 286 287 /*! 288 \brief 289 Move the window by the pixel offsets specified in \a offset. 290 291 This is intended for internal system use - it is the method by which the title bar moves the frame window. 292 293 \param offset 294 Vector2 object containing the offsets to apply (offsets are in screen pixels). 295 296 \return 297 Nothing. 298 */ 299 void offsetPixelPosition(const Vector2f& offset); 300 301 302 /*! 303 \brief 304 Return whether this FrameWindow can be moved by dragging the title bar. 305 306 \return 307 true if the Window will move when the user drags the title bar, false if the window will not move. 308 */ isDragMovingEnabled(void)309 bool isDragMovingEnabled(void) const {return d_dragMovable;} 310 311 312 /*! 313 \brief 314 Set whether this FrameWindow can be moved by dragging the title bar. 315 316 \param setting 317 true if the Window should move when the user drags the title bar, false if the window should not move. 318 319 \return 320 Nothing. 321 */ 322 void setDragMovingEnabled(bool setting); 323 324 325 /*! 326 \brief 327 Return a pointer to the currently set Image to be used for the north-south 328 sizing mouse cursor. 329 330 \return 331 Pointer to an Image object, or 0 for none. 332 */ 333 const Image* getNSSizingCursorImage() const; 334 335 /*! 336 \brief 337 Return a pointer to the currently set Image to be used for the east-west 338 sizing mouse cursor. 339 340 \return 341 Pointer to an Image object, or 0 for none. 342 */ 343 const Image* getEWSizingCursorImage() const; 344 345 /*! 346 \brief 347 Return a pointer to the currently set Image to be used for the northwest-southeast 348 sizing mouse cursor. 349 350 \return 351 Pointer to an Image object, or 0 for none. 352 */ 353 const Image* getNWSESizingCursorImage() const; 354 355 /*! 356 \brief 357 Return a pointer to the currently set Image to be used for the northeast-southwest 358 sizing mouse cursor. 359 360 \return 361 Pointer to an Image object, or 0 for none. 362 */ 363 const Image* getNESWSizingCursorImage() const; 364 365 /*! 366 \brief 367 Set the Image to be used for the north-south sizing mouse cursor. 368 369 \param image 370 Pointer to an Image object, or 0 for none. 371 372 \return 373 Nothing. 374 */ 375 void setNSSizingCursorImage(const Image* image); 376 377 /*! 378 \brief 379 Set the Image to be used for the east-west sizing mouse cursor. 380 381 \param image 382 Pointer to an Image object, or 0 for none. 383 384 \return 385 Nothing. 386 */ 387 void setEWSizingCursorImage(const Image* image); 388 389 /*! 390 \brief 391 Set the Image to be used for the northwest-southeast sizing mouse cursor. 392 393 \param image 394 Pointer to an Image object, or 0 for none. 395 396 \return 397 Nothing. 398 */ 399 void setNWSESizingCursorImage(const Image* image); 400 401 /*! 402 \brief 403 Set the Image to be used for the northeast-southwest sizing mouse cursor. 404 405 \param image 406 Pointer to an Image object, or 0 for none. 407 408 \return 409 Nothing. 410 */ 411 void setNESWSizingCursorImage(const Image* image); 412 413 /*! 414 \brief 415 Set the image to be used for the north-south sizing mouse cursor. 416 417 \param name 418 String holding the name of the Image to be used. 419 420 \return 421 Nothing. 422 423 \exception UnknownObjectException thrown if either \a imageset or \a image refer to non-existant entities. 424 */ 425 void setNSSizingCursorImage(const String& name); 426 427 /*! 428 \brief 429 Set the image to be used for the east-west sizing mouse cursor. 430 431 \param name 432 String holding the name of the Image to be used. 433 434 \return 435 Nothing. 436 437 \exception UnknownObjectException thrown if either \a imageset or \a image refer to non-existant entities. 438 */ 439 void setEWSizingCursorImage(const String& name); 440 441 /*! 442 \brief 443 Set the image to be used for the northwest-southeast sizing mouse cursor. 444 445 \param name 446 String holding the name of the Image to be used. 447 448 \return 449 Nothing. 450 451 \exception UnknownObjectException thrown if either \a imageset or \a image refer to non-existant entities. 452 */ 453 void setNWSESizingCursorImage(const String& name); 454 455 /*! 456 \brief 457 Set the image to be used for the northeast-southwest sizing mouse cursor. 458 459 \param name 460 String holding the name of the Image to be used. 461 462 \return 463 Nothing. 464 465 \exception UnknownObjectException thrown if either \a imageset or \a image refer to non-existant entities. 466 */ 467 void setNESWSizingCursorImage(const String& name); 468 469 // overridden from Window class isHit(const Vector2f & position,const bool)470 bool isHit(const Vector2f& position, const bool /*allow_disabled*/) const 471 { return Window::isHit(position) && !d_rolledup; } 472 473 /*! 474 \brief 475 Return a pointer to the Titlebar component widget for this FrameWindow. 476 477 \return 478 Pointer to a Titlebar object. 479 480 \exception UnknownObjectException 481 Thrown if the Titlebar component does not exist. 482 */ 483 Titlebar* getTitlebar() const; 484 485 /*! 486 \brief 487 Return a pointer to the close button component widget for this 488 FrameWindow. 489 490 \return 491 Pointer to a PushButton object. 492 493 \exception UnknownObjectException 494 Thrown if the close button component does not exist. 495 */ 496 PushButton* getCloseButton() const; 497 498 /************************************************************************* 499 Construction / Destruction 500 *************************************************************************/ 501 /*! 502 \brief 503 Constructor for FrameWindow objects. 504 */ 505 FrameWindow(const String& type, const String& name); 506 507 /*! 508 \brief 509 Destructor for FramwWindow objects. 510 */ 511 virtual ~FrameWindow(void); 512 513 514 protected: 515 /************************************************************************* 516 Implementation Functions 517 *************************************************************************/ 518 /*! 519 \brief 520 move the window's left edge by 'delta'. The rest of the window does not move, thus this changes the size of the Window. 521 522 \param delta 523 float value that specifies the amount to move the window edge, and in which direction. Positive values make window smaller. 524 */ 525 bool moveLeftEdge(float delta, URect& out_area); 526 527 528 /*! 529 \brief 530 move the window's right edge by 'delta'. The rest of the window does not move, thus this changes the size of the Window. 531 532 \param delta 533 float value that specifies the amount to move the window edge, and in which direction. Positive values make window larger. 534 */ 535 bool moveRightEdge(float delta, URect& out_area); 536 537 538 /*! 539 \brief 540 move the window's top edge by 'delta'. The rest of the window does not move, thus this changes the size of the Window. 541 542 \param delta 543 float value that specifies the amount to move the window edge, and in which direction. Positive values make window smaller. 544 */ 545 bool moveTopEdge(float delta, URect& out_area); 546 547 548 /*! 549 \brief 550 move the window's bottom edge by 'delta'. The rest of the window does not move, thus this changes the size of the Window. 551 552 \param delta 553 float value that specifies the amount to move the window edge, and in which direction. Positive values make window larger. 554 */ 555 bool moveBottomEdge(float delta, URect& out_area); 556 557 558 /*! 559 \brief 560 check local pixel co-ordinate point 'pt' and return one of the 561 SizingLocation enumerated values depending where the point falls on 562 the sizing border. 563 564 \param pt 565 Point object describing, in pixels, the window relative offset to check. 566 567 \return 568 One of the SizingLocation enumerated values that describe which part of 569 the sizing border that \a pt corresponded to, if any. 570 */ 571 SizingLocation getSizingBorderAtPoint(const Vector2f& pt) const; 572 573 574 /*! 575 \brief 576 return true if given SizingLocation is on left edge. 577 578 \param loc 579 SizingLocation value to be checked. 580 581 \return 582 true if \a loc is on the left edge. false if \a loc is not on the left edge. 583 */ isLeftSizingLocation(SizingLocation loc)584 bool isLeftSizingLocation(SizingLocation loc) const {return ((loc == SizingLeft) || (loc == SizingTopLeft) || (loc == SizingBottomLeft));} 585 586 587 /*! 588 \brief 589 return true if given SizingLocation is on right edge. 590 591 \param loc 592 SizingLocation value to be checked. 593 594 \return 595 true if \a loc is on the right edge. false if \a loc is not on the right edge. 596 */ isRightSizingLocation(SizingLocation loc)597 bool isRightSizingLocation(SizingLocation loc) const {return ((loc == SizingRight) || (loc == SizingTopRight) || (loc == SizingBottomRight));} 598 599 600 /*! 601 \brief 602 return true if given SizingLocation is on top edge. 603 604 \param loc 605 SizingLocation value to be checked. 606 607 \return 608 true if \a loc is on the top edge. false if \a loc is not on the top edge. 609 */ isTopSizingLocation(SizingLocation loc)610 bool isTopSizingLocation(SizingLocation loc) const {return ((loc == SizingTop) || (loc == SizingTopLeft) || (loc == SizingTopRight));} 611 612 613 /*! 614 \brief 615 return true if given SizingLocation is on bottom edge. 616 617 \param loc 618 SizingLocation value to be checked. 619 620 \return 621 true if \a loc is on the bottom edge. false if \a loc is not on the bottom edge. 622 */ isBottomSizingLocation(SizingLocation loc)623 bool isBottomSizingLocation(SizingLocation loc) const {return ((loc == SizingBottom) || (loc == SizingBottomLeft) || (loc == SizingBottomRight));} 624 625 626 /*! 627 \brief 628 Method to respond to close button click events and fire our close event 629 */ 630 bool closeClickHandler(const EventArgs& e); 631 632 633 /*! 634 \brief 635 Set the appropriate mouse cursor for the given window-relative pixel point. 636 */ 637 void setCursorForPoint(const Vector2f& pt) const; 638 639 640 /*! 641 \brief 642 Return a Rect that describes, in window relative pixel co-ordinates, the outer edge of the sizing area for this window. 643 */ getSizingRect(void)644 virtual Rectf getSizingRect(void) const {return Rectf(0, 0, d_pixelSize.d_width, d_pixelSize.d_height);} 645 646 /************************************************************************* 647 New events for Frame Windows 648 *************************************************************************/ 649 /*! 650 \brief 651 Event generated internally whenever the roll-up / shade state of the window 652 changes. 653 */ 654 virtual void onRollupToggled(WindowEventArgs& e); 655 656 657 /*! 658 \brief 659 Event generated internally whenever the close button is clicked. 660 */ 661 virtual void onCloseClicked(WindowEventArgs& e); 662 663 //! Handler called when drag-sizing of the FrameWindow starts. 664 virtual void onDragSizingStarted(WindowEventArgs& e); 665 666 //! Handler called when drag-sizing of the FrameWindow ends. 667 virtual void onDragSizingEnded(WindowEventArgs& e); 668 669 /************************************************************************* 670 Overridden event handlers 671 *************************************************************************/ 672 virtual void onMouseMove(MouseEventArgs& e); 673 virtual void onMouseButtonDown(MouseEventArgs& e); 674 virtual void onMouseButtonUp(MouseEventArgs& e); 675 virtual void onCaptureLost(WindowEventArgs& e); 676 virtual void onTextChanged(WindowEventArgs& e); 677 virtual void onActivated(ActivationEventArgs& e); 678 virtual void onDeactivated(ActivationEventArgs& e); 679 680 681 /************************************************************************* 682 Implementation Data 683 *************************************************************************/ 684 // frame data 685 bool d_frameEnabled; //!< true if window frame should be drawn. 686 687 // window roll-up data 688 bool d_rollupEnabled; //!< true if roll-up of window is allowed. 689 bool d_rolledup; //!< true if window is rolled up. 690 691 // drag-sizing data 692 bool d_sizingEnabled; //!< true if sizing is enabled for this window. 693 bool d_beingSized; //!< true if window is being sized. 694 float d_borderSize; //!< thickness of the sizing border around this window 695 Vector2f d_dragPoint; //!< point window is being dragged at. 696 697 // images for cursor when on sizing border 698 const Image* d_nsSizingCursor; //!< North/South sizing cursor image. 699 const Image* d_ewSizingCursor; //!< East/West sizing cursor image. 700 const Image* d_nwseSizingCursor; //!< North-West/South-East cursor image. 701 const Image* d_neswSizingCursor; //!< North-East/South-West cursor image. 702 703 bool d_dragMovable; //!< true if the window will move when dragged by the title bar. 704 705 706 private: 707 /************************************************************************* 708 Private methods 709 *************************************************************************/ 710 void addFrameWindowProperties(void); 711 }; 712 713 } // End of CEGUI namespace section 714 715 #if defined(_MSC_VER) 716 # pragma warning(pop) 717 #endif 718 719 #endif // end of guard _CEGUIFrameWindow_h_ 720 721