| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #pragma once
- #include <Image.h>
- #include <Drawing.h>
- #include "DragElement.h"
- #include "Globals.h"
- template<typename Source, typename Element> class DragController
- : public Framework::ReferenceCounter
- {
- private:
- Source* container;
- Element currentElement;
- DragElement* drag;
- std::function<void()> onDragEnd;
- public:
- DragController()
- : ReferenceCounter()
- {
- container = 0;
- currentElement = 0;
- drag = new DragElement();
- }
- ~DragController()
- {
- if (this->container) stopDrag();
- drag->release();
- }
- void beginDrag(Source* container,
- Element element,
- Framework::Image* zDragDisplay,
- std::function<void()> onDragEnd)
- {
- if (this->container) stopDrag();
- ((Framework::ImageView*)drag)
- ->setImageZ(dynamic_cast<Framework::Image*>(zDragDisplay->getThis()));
- window->zScreen()->addMember(
- dynamic_cast<Drawable*>(drag->getThis()));
- this->container = container;
- this->currentElement = element;
- this->onDragEnd = onDragEnd;
- }
- Source* getCurrentDragContainer() const
- {
- return container;
- }
- Element getCurrentDaragElement() const
- {
- return currentElement;
- }
- void stopDrag()
- {
- if (container)
- {
- window->zScreen()->removeMember(drag);
- onDragEnd();
- container = 0;
- currentElement = 0;
- }
- }
- };
|