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