BsDropTarget.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "Utility/BsEvent.h"
  6. #include "Math/BsRect2I.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Platform-Internal
  10. * @{
  11. */
  12. /** Type of drop event type. This is used when dragging items over drop targets. */
  13. enum class DropTargetType
  14. {
  15. FileList,
  16. None
  17. };
  18. /**
  19. * Drop targets allow you to register a certain portion of a window as a drop target that accepts certain drop types
  20. * from the OS (platform) specific drag and drop system. Accepted drop types are provided by the OS and include things
  21. * like file and item dragging.
  22. *
  23. * You will receive events with the specified drop area as long as it is active.
  24. */
  25. class BS_CORE_EXPORT DropTarget
  26. {
  27. public:
  28. ~DropTarget();
  29. /** Sets the drop target area, in local window coordinates. */
  30. void setArea(const Rect2I& area);
  31. /** Returns the drop target area, in local window coordinates. */
  32. const Rect2I& getArea() const { return mArea;}
  33. /** Gets the type of drop that this drop target is looking for. Only valid after a drop has been triggered. */
  34. DropTargetType getDropType() const { return mDropType; }
  35. /**
  36. * Returns a list of files received by the drop target. Only valid after a drop of FileList type has been triggered.
  37. */
  38. const Vector<Path>& getFileList() const { return mFileList; }
  39. /**
  40. * Creates a new drop target. Any drop events that happen on the specified window's drop area will be reported
  41. * through the target's events.
  42. *
  43. * @param[in] window Window to which the drop target will be attached to.
  44. * @param[in] area Area, relative to the window, in which the drop events are allowed.
  45. * @return Newly created drop target.
  46. */
  47. static SPtr<DropTarget> create(const RenderWindow* window, const Rect2I& area);
  48. /**
  49. * Triggered when a pointer is being dragged over the drop area. Provides window coordinates of the pointer position.
  50. */
  51. Event<void(INT32, INT32)> onDragOver;
  52. /**
  53. * Triggered when the user completes a drop while pointer is over the drop area. Provides window coordinates of the
  54. * pointer position.
  55. */
  56. Event<void(INT32, INT32)> onDrop;
  57. /**
  58. * Triggered when a pointer enters the drop area. Provides window coordinates of the pointer position.
  59. */
  60. Event<void(INT32, INT32)> onEnter;
  61. /** Triggered when a pointer leaves the drop area. */
  62. Event<void()> onLeave;
  63. /** @name Internal
  64. * @{
  65. */
  66. /** Clears all internal values. */
  67. void _clear();
  68. /** Sets the file list and marks the drop event as FileList. */
  69. void _setFileList(const Vector<Path>& fileList);
  70. /** Marks the drop area as inactive or active. */
  71. void _setActive(bool active) { mActive = active; }
  72. /** Checks is the specified position within the current drop area. Position should be in window local coordinates. */
  73. bool _isInside(const Vector2I& pos) const;
  74. /** Returns true if the drop target is active. */
  75. bool _isActive() const { return mActive; }
  76. /** Returns a render window this drop target is attached to. */
  77. const RenderWindow* _getOwnerWindow() const { return mOwnerWindow; }
  78. /** @} */
  79. private:
  80. friend class Platform;
  81. DropTarget(const RenderWindow* ownerWindow, const Rect2I& area);
  82. Rect2I mArea;
  83. bool mActive;
  84. const RenderWindow* mOwnerWindow;
  85. DropTargetType mDropType;
  86. Vector<Path> mFileList;
  87. };
  88. /** @} */
  89. }