1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/********************************************************************
*
*	Created:	22/4/2014   14:16
*
*	File:		fsCDragDropComponent.h
*
*	Author:		Mick Waites
*	
*	Purpose:	Short lived sprite based entities which can be
*				dragged around a scene and dropped.
*
*********************************************************************/

#ifndef fsCDragDropComponenthdr
#define fsCDragDropComponenthdr

#include <fsCore/src/fsCUniqueId.h>

#include "fsIGestureHandlingComponent.h"

class fsCLine;
struct fsPoint;
class fsCBrush;

// #define COLLISION_DEBUG_RENDERING
// #define COLLISION_DEBUG_MESSAGES


class fsCDragDropComponent : public fsIGestureHandlingComponent
{
	friend class fsCComponentFactory;

public:

	static const fsCUniqueId mTypeId;

	static const fsCUniqueId mDragEndMsg;

#ifdef COLLISION_DEBUG_MESSAGES
	static const fsCUniqueId mDragingMsg;
#endif
	static fsCEntity* dragDropEntityCreate(const fsStr& pEntName, std::shared_ptr<fsCBrush> pBrush, fsCEntity* pEnt,
					       const fsPoint& pOffset);

	void dragStart(const fsPoint& pPos, fsS32 pPointerIndexForDrag);

protected:

	fsBool acceptingInputGet() const override;

	void onDragMove(const fsPoint& pCurrPos) override;
	void onDragEnd(const fsPoint& pEndPos) override;

	void renderDo() override;<--- Function in derived class
	void matrixApplyDo() override;<--- Function in derived class

	static fsIComponent* create(fsCEntity* pParent);

	fsCDragDropComponent(fsCEntity* pParent);
	virtual ~fsCDragDropComponent();<--- Destructor in derived class

private:

	void spritePositionSet(const fsPoint& pCurrPos) const;

	const fsS32 mTouchFingerVerticalOffset;
	fsPoint mOffset;
#ifdef COLLISION_DEBUG_RENDERING
	fsCLine* mLine;
#endif
};

#endif