DragController.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include <Zeichnung.h>
  3. #include "DragElement.h"
  4. template<typename Source, typename Element>
  5. class DragController : public Framework::ReferenceCounter
  6. {
  7. private:
  8. Source* container;
  9. Element currentElement;
  10. DragElement* drag;
  11. std::function<void()> onDragEnd;
  12. public:
  13. DragController()
  14. : ReferenceCounter()
  15. {
  16. container = 0;
  17. currentElement = 0;
  18. drag = new DragElement();
  19. }
  20. ~DragController()
  21. {
  22. if (this->container)
  23. stopDrag();
  24. drag->release();
  25. }
  26. void beginDrag(Source* container, Element element, Framework::Bild* zDragDisplay, std::function<void()> onDragEnd)
  27. {
  28. if (this->container)
  29. stopDrag();
  30. ((BildZ*)drag)->setBildZ(dynamic_cast<Bild*>(zDragDisplay->getThis()));
  31. window->zBildschirm()->addMember(dynamic_cast<Zeichnung*>(drag->getThis()));
  32. this->container = container;
  33. this->currentElement = element;
  34. this->onDragEnd = onDragEnd;
  35. }
  36. Source* getCurrentDragContainer() const
  37. {
  38. return container;
  39. }
  40. Element getCurrentDaragElement() const
  41. {
  42. return currentElement;
  43. }
  44. void stopDrag()
  45. {
  46. if (container)
  47. {
  48. window->zBildschirm()->removeMember(drag);
  49. onDragEnd();
  50. container = 0;
  51. currentElement = 0;
  52. }
  53. }
  54. };