DragController.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include <Zeichnung.h>
  3. #include "DragElement.h"
  4. template<typename Source, typename Element> class DragController
  5. : 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) stopDrag();
  23. drag->release();
  24. }
  25. void beginDrag(Source* container,
  26. Element element,
  27. Framework::Bild* zDragDisplay,
  28. std::function<void()> onDragEnd)
  29. {
  30. if (this->container) stopDrag();
  31. ((BildZ*)drag)->setBildZ(dynamic_cast<Bild*>(zDragDisplay->getThis()));
  32. window->zBildschirm()->addMember(
  33. dynamic_cast<Zeichnung*>(drag->getThis()));
  34. this->container = container;
  35. this->currentElement = element;
  36. this->onDragEnd = onDragEnd;
  37. }
  38. Source* getCurrentDragContainer() const
  39. {
  40. return container;
  41. }
  42. Element getCurrentDaragElement() const
  43. {
  44. return currentElement;
  45. }
  46. void stopDrag()
  47. {
  48. if (container)
  49. {
  50. window->zBildschirm()->removeMember(drag);
  51. onDragEnd();
  52. container = 0;
  53. currentElement = 0;
  54. }
  55. }
  56. };