DragController.h 1.5 KB

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