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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 | #include "fsCDragDropComponent.h"
#include <fsCore/src/debug/fsAssert.h>
#include <fsRenderer/src/components/fsCSpriteComponent.h>
#include "../../src/fsCEntity.h"
#include "../../src/fsCEntityFactory.h"
#include "../../src/fsCGuiMessageDispatcher.h"
#include "fsRenderer/src/fsCBrush.h"
#include "fsRenderer/src/fsCLine.h"
const fsCUniqueId fsCDragDropComponent::mTypeId("fsCDragDropComponent");
const fsCUniqueId fsCDragDropComponent::mDragEndMsg("DragDropCompDragEnd");
#ifdef COLLISION_DEBUG_MESSAGES
const fsCUniqueId fsCDragDropComponent::mDragingMsg("DragDropCompDragging");
#endif
void fsCDragDropComponent::dragStart(const fsPoint& pPos, fsS32 pPointerIndexForDrag)
{
fsAssert(( eSTATE_NOT_IN_GESTURE == mGestureState && 0 == mNumPointsDown ),
"dragStart() should be called immediately after creating the DragDropComponent.\n");
mGestureState = eSTATE_IN_DRAG_GESTURE;
mGesturePoints[pPointerIndexForDrag].mInGesture = true;
mGesturePoints[pPointerIndexForDrag].mPrevPos = pPos;
mNumPointsDown = 1;
spritePositionSet(fsPoint(pPos.x, pPos.y + mTouchFingerVerticalOffset));
fsIInputManager::instanceGet()->priorityListenerRegister(this);
}
void fsCDragDropComponent::onDragMove(const fsPoint& pCurrPos)
{
spritePositionSet(fsPoint(pCurrPos.x, pCurrPos.y + mTouchFingerVerticalOffset));
#ifdef COLLISION_DEBUG_MESSAGES
fsCGuiMessageDispatcher::instanceGet()->messageDispatch(mDragingMsg, fsIMessageDispatcher::mNullParam);
#endif
}
void fsCDragDropComponent::onDragEnd(const fsPoint& pEndPos)
{
fsCGuiMessageDispatcher::instanceGet()->messageDispatch(mDragEndMsg, fsIMessageDispatcher::mNullParam);
spritePositionSet(pEndPos);
}
void fsCDragDropComponent::spritePositionSet(const fsPoint& pCurrPos) const
{
fsVec2d localPos;
parentGet()->parentGet()->screenCoordConvertToLocal(pCurrPos, localPos);
parentGet()->posSet(localPos + mOffset);
}
fsBool fsCDragDropComponent::acceptingInputGet() const
{
return true;
}
void fsCDragDropComponent::matrixApplyDo()
{
#ifdef COLLISION_DEBUG_RENDERING
mLine->matrixApply(parentGet()->renderMatrixGet());
#endif
}
void fsCDragDropComponent::renderDo() {
#ifdef COLLISION_DEBUG_RENDERING
mLine->render();
#endif
}
fsCEntity* fsCDragDropComponent::dragDropEntityCreate(const fsStr& pEntName, std::shared_ptr<fsCBrush> pBrush,
fsCEntity* const pEnt, const fsPoint& pOffset)
{
fsCEntity* dragDropEnt = pEnt->entityFactoryGet()->emptyEntityCreate(pEntName);
fsISpriteComponent* sprComp = dragDropEnt->spriteComponentAdd();
sprComp->brushSet(pBrush);
fsCDragDropComponent* dragDropComp = dragDropEnt->componentAdd<fsCDragDropComponent>();
dragDropEnt->posSet(pEnt->posGet());
dragDropComp->mOffset = pOffset;
#ifdef COLLISION_DEBUG_RENDERING
dragDropComp->mLine = new fsCLine(std::vector<fsVec2d>());
auto brushSize = pEnt->spriteComponentGet()->brushGet()->dimensionsGet();
// dragDropComp->mLine->vertSet(std::vector<fsVec2d>{
// fsVec2d(-brushSize.x / 2.0, -brushSize.y / 2.0),
// fsVec2d(brushSize.x / 2.0, -brushSize.y / 2.0f),
//
// fsVec2d(brushSize.x / 2.0, -brushSize.y / 2.0),
// fsVec2d(brushSize.x / 2.0, brushSize.y / 2.0),
//
// fsVec2d(brushSize.x / 2.0, brushSize.y / 2.0),
// fsVec2d(-brushSize.x / 2.0, brushSize.y / 2.0),
//
// fsVec2d(-brushSize.x / 2.0, brushSize.y / 2.0),
// fsVec2d(-brushSize.x / 2.0, -brushSize.y / 2.0),
// });
// dragDropComp->mLine->colourSet(fsSColour(0.0f, 1.0f, 0.0f, 1.0f ));
#endif
return dragDropEnt;
}
fsIComponent* fsCDragDropComponent::create(fsCEntity* pParent)
{
return new fsCDragDropComponent(pParent);
}
fsCDragDropComponent::fsCDragDropComponent(fsCEntity* const pParent) :
#ifdef COLLISION_DEBUG_RENDERING
mLine(nullptr),
#endif
fsIGestureHandlingComponent(pParent, false, true, false),
mTouchFingerVerticalOffset(fsIInputManager::ePOINTER_TYPE_MOUSE == fsIInputManager::instanceGet()->pointerTypeGet()
? 0
:
#if defined fsINVERTED_Y_AXIS
90
#else
-90
#endif
)
{
}
fsCDragDropComponent::~fsCDragDropComponent()
{
#ifdef COLLISION_DEBUG_RENDERING
delete mLine;<--- Class 'fsCDragDropComponent' does not have a copy constructor which is recommended since it has dynamic memory/resource management.<--- Class 'fsCDragDropComponent' does not have a operator= which is recommended since it has dynamic memory/resource management.
#endif
}
|