[692] | 1 | /************************************************************************
|
---|
| 2 | filename: CEGUIDragContainer.h
|
---|
| 3 | created: 14/2/2005
|
---|
| 4 | author: Paul D Turner
|
---|
| 5 | *************************************************************************/
|
---|
| 6 | /*************************************************************************
|
---|
| 7 | Crazy Eddie's GUI System (http://www.cegui.org.uk)
|
---|
| 8 | Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
|
---|
| 9 |
|
---|
| 10 | This library is free software; you can redistribute it and/or
|
---|
| 11 | modify it under the terms of the GNU Lesser General Public
|
---|
| 12 | License as published by the Free Software Foundation; either
|
---|
| 13 | version 2.1 of the License, or (at your option) any later version.
|
---|
| 14 |
|
---|
| 15 | This library is distributed in the hope that it will be useful,
|
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 18 | Lesser General Public License for more details.
|
---|
| 19 |
|
---|
| 20 | You should have received a copy of the GNU Lesser General Public
|
---|
| 21 | License along with this library; if not, write to the Free Software
|
---|
| 22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 23 | *************************************************************************/
|
---|
| 24 | #ifndef _CEGUIDragContainer_h_
|
---|
| 25 | #define _CEGUIDragContainer_h_
|
---|
| 26 |
|
---|
| 27 | #include "CEGUIWindow.h"
|
---|
| 28 | #include "CEGUIWindowFactory.h"
|
---|
| 29 | #include "elements/CEGUIDragContainerProperties.h"
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | #if defined(_MSC_VER)
|
---|
| 33 | # pragma warning(push)
|
---|
| 34 | # pragma warning(disable : 4251)
|
---|
| 35 | #endif
|
---|
| 36 |
|
---|
| 37 | // Start of CEGUI namespace section
|
---|
| 38 | namespace CEGUI
|
---|
| 39 | {
|
---|
| 40 | /*!
|
---|
| 41 | \brief
|
---|
| 42 | Generic drag & drop enabled window class
|
---|
| 43 | */
|
---|
| 44 | class CEGUIEXPORT DragContainer : public Window
|
---|
| 45 | {
|
---|
| 46 | public:
|
---|
| 47 | /*************************************************************************
|
---|
| 48 | Constants
|
---|
| 49 | *************************************************************************/
|
---|
| 50 | static const String WidgetTypeName; //!< Type name for DragContainer.
|
---|
| 51 | static const String EventNamespace; //!< Namespace for global events
|
---|
| 52 | static const String EventDragStarted; //!< Name of the event fired when the user begins dragging the thumb.
|
---|
| 53 | static const String EventDragEnded; //!< Name of the event fired when the user releases the thumb.
|
---|
| 54 | static const String EventDragPositionChanged; //!< Event fired when the drag position has changed.
|
---|
| 55 | static const String EventDragEnabledChanged; //!< Event fired when dragging is enabled or disabled.
|
---|
| 56 | static const String EventDragAlphaChanged; //!< Event fired when the alpha value used when dragging is changed.
|
---|
| 57 | static const String EventDragMouseCursorChanged;//!< Event fired when the mouse cursor used when dragging is changed.
|
---|
| 58 | static const String EventDragThresholdChanged; //!< Event fired when the drag pixel threshold is changed.
|
---|
| 59 | static const String EventDragDropTargetChanged; //!< Event fired when the drop target changes.
|
---|
| 60 |
|
---|
| 61 | /*************************************************************************
|
---|
| 62 | Object Construction and Destruction
|
---|
| 63 | *************************************************************************/
|
---|
| 64 | /*!
|
---|
| 65 | \brief
|
---|
| 66 | Constructor for DragContainer objects
|
---|
| 67 | */
|
---|
| 68 | DragContainer(const String& type, const String& name);
|
---|
| 69 |
|
---|
| 70 | /*!
|
---|
| 71 | \brief
|
---|
| 72 | Destructor for DragContainer objects
|
---|
| 73 | */
|
---|
| 74 | virtual ~DragContainer(void);
|
---|
| 75 |
|
---|
| 76 | /*************************************************************************
|
---|
| 77 | Public Interface to DragContainer
|
---|
| 78 | *************************************************************************/
|
---|
| 79 | /*!
|
---|
| 80 | \brief
|
---|
| 81 | Return whether dragging is currently enabled for this DragContainer.
|
---|
| 82 |
|
---|
| 83 | \return
|
---|
| 84 | - true if dragging is enabled and the DragContainer may be dragged.
|
---|
| 85 | - false if dragging is disabled and the DragContainer may not be dragged.
|
---|
| 86 | */
|
---|
| 87 | bool isDraggingEnabled(void) const;
|
---|
| 88 |
|
---|
| 89 | /*!
|
---|
| 90 | \brief
|
---|
| 91 | Set whether dragging is currently enabled for this DragContainer.
|
---|
| 92 |
|
---|
| 93 | \param setting
|
---|
| 94 | - true to enable dragging so that the DragContainer may be dragged.
|
---|
| 95 | - false to disabled dragging so that the DragContainer may not be dragged.
|
---|
| 96 |
|
---|
| 97 | \return
|
---|
| 98 | Nothing.
|
---|
| 99 | */
|
---|
| 100 | void setDraggingEnabled(bool setting);
|
---|
| 101 |
|
---|
| 102 | /*!
|
---|
| 103 | \brief
|
---|
| 104 | Return whether the DragContainer is currently being dragged.
|
---|
| 105 |
|
---|
| 106 | \return
|
---|
| 107 | - true if the DragContainer is being dragged.
|
---|
| 108 | - false if te DragContainer is not being dragged.
|
---|
| 109 | */
|
---|
| 110 | bool isBeingDragged(void) const;
|
---|
| 111 |
|
---|
| 112 | /*!
|
---|
| 113 | \brief
|
---|
| 114 | Return the current drag threshold in pixels.
|
---|
| 115 |
|
---|
| 116 | The drag threshold is the number of pixels that the mouse must be
|
---|
| 117 | moved with the left button held down in order to commence a drag
|
---|
| 118 | operation.
|
---|
| 119 |
|
---|
| 120 | \return
|
---|
| 121 | float value indicating the current drag threshold value.
|
---|
| 122 | */
|
---|
| 123 | float getPixelDragThreshold(void) const;
|
---|
| 124 |
|
---|
| 125 | /*!
|
---|
| 126 | \brief
|
---|
| 127 | Set the current drag threshold in pixels.
|
---|
| 128 |
|
---|
| 129 | The drag threshold is the number of pixels that the mouse must be
|
---|
| 130 | moved with the left button held down in order to commence a drag
|
---|
| 131 | operation.
|
---|
| 132 |
|
---|
| 133 | \param pixels
|
---|
| 134 | float value indicating the new drag threshold value.
|
---|
| 135 |
|
---|
| 136 | \return
|
---|
| 137 | Nothing.
|
---|
| 138 | */
|
---|
| 139 | void setPixelDragThreshold(float pixels);
|
---|
| 140 |
|
---|
| 141 | /*!
|
---|
| 142 | \brief
|
---|
| 143 | Return the alpha value that will be set on the DragContainer while a drag operation is
|
---|
| 144 | in progress.
|
---|
| 145 |
|
---|
| 146 | \return
|
---|
| 147 | Current alpha value to use whilst dragging.
|
---|
| 148 | */
|
---|
| 149 | float getDragAlpha(void) const;
|
---|
| 150 |
|
---|
| 151 | /*!
|
---|
| 152 | \brief
|
---|
| 153 | Set the alpha value to be set on the DragContainer when a drag operation is
|
---|
| 154 | in progress.
|
---|
| 155 |
|
---|
| 156 | This method can be used while a drag is in progress to update the alpha. Note that
|
---|
| 157 | the normal setAlpha method does not affect alpha while a drag is in progress, but
|
---|
| 158 | once the drag operation has ended, any value set via setAlpha will be restored.
|
---|
| 159 |
|
---|
| 160 | \param alpha
|
---|
| 161 | Alpha value to use whilst dragging.
|
---|
| 162 |
|
---|
| 163 | \return
|
---|
| 164 | Nothing.
|
---|
| 165 | */
|
---|
| 166 | void setDragAlpha(float alpha);
|
---|
| 167 |
|
---|
| 168 | /*!
|
---|
| 169 | \brief
|
---|
| 170 | Return the Image currently set to be used for the mouse cursor when a
|
---|
| 171 | drag operation is in progress.
|
---|
| 172 |
|
---|
| 173 | \return
|
---|
| 174 | Image object currently set to be used as the mouse cursor when dragging.
|
---|
| 175 | */
|
---|
| 176 | const Image* getDragCursorImage(void) const;
|
---|
| 177 |
|
---|
| 178 | /*!
|
---|
| 179 | \brief
|
---|
| 180 | Set the Image to be used for the mouse cursor when a drag operation is
|
---|
| 181 | in progress.
|
---|
| 182 |
|
---|
| 183 | This method may be used during a drag operation to update the current mouse
|
---|
| 184 | cursor image.
|
---|
| 185 |
|
---|
| 186 | \param image
|
---|
| 187 | Image object to be used as the mouse cursor while dragging.
|
---|
| 188 |
|
---|
| 189 | \return
|
---|
| 190 | Nothing.
|
---|
| 191 | */
|
---|
| 192 | void setDragCursorImage(const Image* image);
|
---|
| 193 |
|
---|
| 194 | /*!
|
---|
| 195 | \brief
|
---|
| 196 | Set the Image to be used for the mouse cursor when a drag operation is
|
---|
| 197 | in progress.
|
---|
| 198 |
|
---|
| 199 | This method may be used during a drag operation to update the current mouse
|
---|
| 200 | cursor image.
|
---|
| 201 |
|
---|
| 202 | \param image
|
---|
| 203 | One of the MouseCursorImage enumerated values.
|
---|
| 204 |
|
---|
| 205 | \return
|
---|
| 206 | Nothing.
|
---|
| 207 | */
|
---|
| 208 | void setDragCursorImage(MouseCursorImage image);
|
---|
| 209 |
|
---|
| 210 | /*!
|
---|
| 211 | \brief
|
---|
| 212 | Set the Image to be used for the mouse cursor when a drag operation is
|
---|
| 213 | in progress.
|
---|
| 214 |
|
---|
| 215 | This method may be used during a drag operation to update the current mouse
|
---|
| 216 | cursor image.
|
---|
| 217 |
|
---|
| 218 | \param imageset
|
---|
| 219 | String holding the name of the Imageset that contains the Image to be used.
|
---|
| 220 |
|
---|
| 221 | \param image
|
---|
| 222 | Image defined for the Imageset \a imageset to be used as the mouse cursor
|
---|
| 223 | when dragging.
|
---|
| 224 |
|
---|
| 225 | \return
|
---|
| 226 | Nothing.
|
---|
| 227 |
|
---|
| 228 | \exception UnknownObjectException thrown if either \a imageset or \a image are unknown.
|
---|
| 229 | */
|
---|
| 230 | void setDragCursorImage(const String& imageset, const String& image);
|
---|
| 231 |
|
---|
| 232 | /*!
|
---|
| 233 | \brief
|
---|
| 234 | Return the Window object that is the current drop target for the DragContainer.
|
---|
| 235 |
|
---|
| 236 | The drop target for a DragContainer is basically the Window that the DragContainer
|
---|
| 237 | is within while being dragged. The drop target may be 0 to indicate no target.
|
---|
| 238 |
|
---|
| 239 | \return
|
---|
| 240 | Pointer to a Window object that contains the DragContainer whilst being dragged, or
|
---|
| 241 | 0 to indicate no current target.
|
---|
| 242 | */
|
---|
| 243 | Window* getCurrentDropTarget(void) const;
|
---|
| 244 |
|
---|
| 245 | protected:
|
---|
| 246 | /*************************************************************************
|
---|
| 247 | Protected Implementation Methods
|
---|
| 248 | *************************************************************************/
|
---|
| 249 | /*!
|
---|
| 250 | \brief
|
---|
| 251 | Adds events specific to the DragContainer base class.
|
---|
| 252 |
|
---|
| 253 | \return
|
---|
| 254 | Nothing.
|
---|
| 255 | */
|
---|
| 256 | void addDragContainerEvents(void);
|
---|
| 257 |
|
---|
| 258 | /*!
|
---|
| 259 | \brief
|
---|
| 260 | Return whether the required minimum movement threshold before initiating dragging
|
---|
| 261 | has been exceeded.
|
---|
| 262 |
|
---|
| 263 | \param local_mouse
|
---|
| 264 | Mouse position as a pixel offset from the top-left corner of this window.
|
---|
| 265 |
|
---|
| 266 | \return
|
---|
| 267 | - true if the threshold has been exceeded and dragging should be initiated.
|
---|
| 268 | - false if the threshold has not been exceeded.
|
---|
| 269 | */
|
---|
| 270 | bool isDraggingThresholdExceeded(const Point& local_mouse);
|
---|
| 271 |
|
---|
| 272 | /*!
|
---|
| 273 | \brief
|
---|
| 274 | Initialise the required states to put the window into dragging mode.
|
---|
| 275 |
|
---|
| 276 | \return
|
---|
| 277 | Nothing.
|
---|
| 278 | */
|
---|
| 279 | void initialiseDragging(void);
|
---|
| 280 |
|
---|
| 281 | /*!
|
---|
| 282 | \brief
|
---|
| 283 | Update state for window dragging.
|
---|
| 284 |
|
---|
| 285 | \param local_mouse
|
---|
| 286 | Mouse position as a pixel offset from the top-left corner of this window.
|
---|
| 287 |
|
---|
| 288 | \return
|
---|
| 289 | Nothing.
|
---|
| 290 | */
|
---|
| 291 | void doDragging(const Point& local_mouse);
|
---|
| 292 |
|
---|
| 293 | /*!
|
---|
| 294 | \brief
|
---|
| 295 | Method to update mouse cursor image
|
---|
| 296 | */
|
---|
| 297 | void updateActiveMouseCursor(void) const;
|
---|
| 298 |
|
---|
| 299 |
|
---|
| 300 | /*!
|
---|
| 301 | \brief
|
---|
| 302 | Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
|
---|
| 303 |
|
---|
| 304 | \param class_name
|
---|
| 305 | The class name that is to be checked.
|
---|
| 306 |
|
---|
| 307 | \return
|
---|
| 308 | true if this window was inherited from \a class_name. false if not.
|
---|
| 309 | */
|
---|
| 310 | virtual bool testClassName_impl(const String& class_name) const
|
---|
| 311 | {
|
---|
| 312 | if (class_name==(const utf8*)"DragContainer") return true;
|
---|
| 313 | return Window::testClassName_impl(class_name);
|
---|
| 314 | }
|
---|
| 315 |
|
---|
| 316 |
|
---|
| 317 | /*************************************************************************
|
---|
| 318 | Implementation of abstract methods in Window
|
---|
| 319 | *************************************************************************/
|
---|
| 320 | void drawSelf(float z);
|
---|
| 321 |
|
---|
| 322 | /*************************************************************************
|
---|
| 323 | Overrides of methods in Window
|
---|
| 324 | *************************************************************************/
|
---|
| 325 |
|
---|
| 326 | /*************************************************************************
|
---|
| 327 | Overrides for Event handler methods
|
---|
| 328 | *************************************************************************/
|
---|
| 329 | virtual void onMouseButtonDown(MouseEventArgs& e);
|
---|
| 330 | virtual void onMouseButtonUp(MouseEventArgs& e);
|
---|
| 331 | virtual void onMouseMove(MouseEventArgs& e);
|
---|
| 332 | virtual void onCaptureLost(WindowEventArgs& e);
|
---|
| 333 | virtual void onAlphaChanged(WindowEventArgs& e);
|
---|
| 334 | virtual void onClippingChanged(WindowEventArgs& e);/*Window::drawSelf(z);*/
|
---|
| 335 |
|
---|
| 336 | /*************************************************************************
|
---|
| 337 | New Event handler methods
|
---|
| 338 | *************************************************************************/
|
---|
| 339 | /*!
|
---|
| 340 | \brief
|
---|
| 341 | Method called when dragging commences
|
---|
| 342 |
|
---|
| 343 | \param e
|
---|
| 344 | WindowEventArgs object containing any relevant data.
|
---|
| 345 |
|
---|
| 346 | \return
|
---|
| 347 | Nothing.
|
---|
| 348 | */
|
---|
| 349 | virtual void onDragStarted(WindowEventArgs& e);
|
---|
| 350 |
|
---|
| 351 | /*!
|
---|
| 352 | \brief
|
---|
| 353 | Method called when dragging ends.
|
---|
| 354 |
|
---|
| 355 | \param e
|
---|
| 356 | WindowEventArgs object containing any relevant data.
|
---|
| 357 |
|
---|
| 358 | \return
|
---|
| 359 | Nothing.
|
---|
| 360 | */
|
---|
| 361 | virtual void onDragEnded(WindowEventArgs& e);
|
---|
| 362 |
|
---|
| 363 | /*!
|
---|
| 364 | \brief
|
---|
| 365 | Method called when the dragged object position is changed.
|
---|
| 366 |
|
---|
| 367 | \param e
|
---|
| 368 | WindowEventArgs object containing any relevant data.
|
---|
| 369 |
|
---|
| 370 | \return
|
---|
| 371 | Nothing.
|
---|
| 372 | */
|
---|
| 373 | virtual void onDragPositionChanged(WindowEventArgs& e);
|
---|
| 374 |
|
---|
| 375 | /*!
|
---|
| 376 | \brief
|
---|
| 377 | Method called when the dragging state is enabled or disabled
|
---|
| 378 | \param e
|
---|
| 379 | WindowEventArgs object.
|
---|
| 380 | \return
|
---|
| 381 | Nothing.
|
---|
| 382 | */
|
---|
| 383 | virtual void onDragEnabledChanged(WindowEventArgs& e);
|
---|
| 384 |
|
---|
| 385 | /*!
|
---|
| 386 | \brief
|
---|
| 387 | Method called when the alpha value to use when dragging is changed.
|
---|
| 388 | \param e
|
---|
| 389 | WindowEventArgs object.
|
---|
| 390 | \return
|
---|
| 391 | Nothing.
|
---|
| 392 | */
|
---|
| 393 | virtual void onDragAlphaChanged(WindowEventArgs& e);
|
---|
| 394 |
|
---|
| 395 | /*!
|
---|
| 396 | \brief
|
---|
| 397 | Method called when the mouse cursor to use when dragging is changed.
|
---|
| 398 | \param e
|
---|
| 399 | WindowEventArgs object.
|
---|
| 400 | \return
|
---|
| 401 | Nothing.
|
---|
| 402 | */
|
---|
| 403 | virtual void onDragMouseCursorChanged(WindowEventArgs& e);
|
---|
| 404 |
|
---|
| 405 | /*!
|
---|
| 406 | \brief
|
---|
| 407 | Method called when the movement threshold required to trigger dragging is changed.
|
---|
| 408 | \param e
|
---|
| 409 | WindowEventArgs object.
|
---|
| 410 | \return
|
---|
| 411 | Nothing.
|
---|
| 412 | */
|
---|
| 413 | virtual void onDragThresholdChanged(WindowEventArgs& e);
|
---|
| 414 |
|
---|
| 415 | /*!
|
---|
| 416 | \brief
|
---|
| 417 | Method called when the current drop target of this DragContainer changes.
|
---|
| 418 | \note
|
---|
| 419 | This event fires just prior to the target field being changed. The default implementation
|
---|
| 420 | changes the drop target, you can examine the old and new targets before calling the default
|
---|
| 421 | implementation to make the actual change (and fire appropriate events for the Window objects
|
---|
| 422 | involved).
|
---|
| 423 | \param e
|
---|
| 424 | DragDropEventArgs object initialised as follows:
|
---|
| 425 | - dragDropItem is initialised to the DragContainer triggering the event (typically 'this').
|
---|
| 426 | - window is initialised to point to the Window which will be the new drop target.
|
---|
| 427 | \return
|
---|
| 428 | Nothing.
|
---|
| 429 | */
|
---|
| 430 | virtual void onDragDropTargetChanged(DragDropEventArgs& e);
|
---|
| 431 |
|
---|
| 432 | /*************************************************************************
|
---|
| 433 | Data
|
---|
| 434 | *************************************************************************/
|
---|
| 435 | bool d_draggingEnabled; //!< True when dragging is enabled.
|
---|
| 436 | bool d_leftMouseDown; //!< True when left mouse button is down.
|
---|
| 437 | bool d_dragging; //!< true when being dragged.
|
---|
| 438 | Point d_dragPoint; //!< point we are being dragged at.
|
---|
| 439 | Point d_startPosition; //!< position prior to dragging.
|
---|
| 440 | float d_dragThreshold; //!< Pixels mouse must move before dragging commences.
|
---|
| 441 | float d_dragAlpha; //!< Alpha value to set when dragging.
|
---|
| 442 | float d_storedAlpha; //!< Alpha value to re-set when dragging ends.
|
---|
| 443 | bool d_storedClipState; //!< Parent clip state to re-set.
|
---|
| 444 | Window* d_dropTarget; //!< Target window for possible drop operation.
|
---|
| 445 | const Image* d_dragCursorImage; //!< Image to use for mouse cursor when dragging.
|
---|
| 446 |
|
---|
| 447 | private:
|
---|
| 448 | /*************************************************************************
|
---|
| 449 | Static properties for the Spinner widget
|
---|
| 450 | *************************************************************************/
|
---|
| 451 | static DragContainerProperties::DragAlpha d_dragAlphaProperty;
|
---|
| 452 | static DragContainerProperties::DragCursorImage d_dragCursorImageProperty;
|
---|
| 453 | static DragContainerProperties::DraggingEnabled d_dragEnabledProperty;
|
---|
| 454 | static DragContainerProperties::DragThreshold d_dragThresholdProperty;
|
---|
| 455 |
|
---|
| 456 | /*************************************************************************
|
---|
| 457 | Implementation methods
|
---|
| 458 | *************************************************************************/
|
---|
| 459 | /*!
|
---|
| 460 | \brief
|
---|
| 461 | Adds properties specific to the DragContainer base class.
|
---|
| 462 |
|
---|
| 463 | \return
|
---|
| 464 | Nothing.
|
---|
| 465 | */
|
---|
| 466 | void addDragContainerProperties(void);
|
---|
| 467 | };
|
---|
| 468 |
|
---|
| 469 | /*!
|
---|
| 470 | \brief
|
---|
| 471 | Factory class for producing DragContainer windows
|
---|
| 472 | */
|
---|
| 473 | class DragContainerFactory : public WindowFactory
|
---|
| 474 | {
|
---|
| 475 | public:
|
---|
| 476 | DragContainerFactory(void) : WindowFactory(DragContainer::WidgetTypeName) { }
|
---|
| 477 | ~DragContainerFactory(void){}
|
---|
| 478 |
|
---|
| 479 | Window* createWindow(const String& name)
|
---|
| 480 | {
|
---|
| 481 | DragContainer* wnd = new DragContainer(d_type, name);
|
---|
| 482 | return wnd;
|
---|
| 483 | }
|
---|
| 484 |
|
---|
| 485 | void destroyWindow(Window* window)
|
---|
| 486 | {
|
---|
| 487 | if (window->getType() == d_type)
|
---|
| 488 | delete window;
|
---|
| 489 | }
|
---|
| 490 |
|
---|
| 491 | };
|
---|
| 492 |
|
---|
| 493 |
|
---|
| 494 | } // End of CEGUI namespace section
|
---|
| 495 |
|
---|
| 496 |
|
---|
| 497 | #if defined(_MSC_VER)
|
---|
| 498 | # pragma warning(pop)
|
---|
| 499 | #endif
|
---|
| 500 |
|
---|
| 501 | #endif // end of guard _CEGUIDragContainer_h_
|
---|