BsDragAndDropManager.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "CmModule.h"
  4. #include "CmInput.h"
  5. #include <boost/signals.hpp>
  6. #include <atomic>
  7. namespace BansheeEngine
  8. {
  9. class BS_EXPORT DragAndDropManager : public Module<DragAndDropManager>
  10. {
  11. public:
  12. DragAndDropManager();
  13. /**
  14. * @brief Starts a drag operation of the specified type. This means GUI elements will start receiving
  15. * drag and drop related events and they may choose to handle them.
  16. *
  17. * @param typeId Type of the drag and drop operation that other objects may query and decide if they want
  18. * to handle it.
  19. * @param data Some operation specific data that is just passed through to however needs it.
  20. * @param dropCallback The drop callback that gets triggered whenever mouse button is released and drag operation ends.
  21. * You should perform any cleanup here.
  22. * @param needsValidDropTarget (optional) Determines whether the drop operation may happen anywhere or does the GUI element need to specifically
  23. * accept the drag of this type. If false all GUI elements we mouse over will receive drag/drop events, otherwise only
  24. * those that specifically subscribe to the specified drag operation of this typeId will.
  25. *
  26. * Additionally this will determine the cursor displayed (whether or not it can have a "denied" state).
  27. */
  28. void startDrag(UINT32 typeId, void* data, std::function<void(bool)> dropCallback, bool needsValidDropTarget = false);
  29. bool isDragInProgress() const { return mIsDragInProgress; }
  30. UINT32 getDragTypeId() const { return mDragTypeId; }
  31. void* getDragData() const { return mData; }
  32. bool needsValidDropTarget() const { return mNeedsValidDropTarget; }
  33. void addDropCallback(std::function<void(bool)> dropCallback);
  34. /**
  35. * @brief Called once per frame. Internal method.
  36. */
  37. void update();
  38. boost::signal<bool(const PositionalInputEvent&)> onDragEnded;
  39. private:
  40. UINT32 mDragTypeId;
  41. void* mData;
  42. Vector<std::function<void(bool)>>::type mDropCallbacks;
  43. bool mIsDragInProgress;
  44. bool mNeedsValidDropTarget;
  45. std::atomic<bool> mCaptureChanged;
  46. std::atomic<int> mCaptureActive;
  47. void endDrag(bool processed);
  48. void mouseCaptureChanged();
  49. void cursorReleased(const PositionalInputEvent& event);
  50. };
  51. }