-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPointerProxy.cpp
130 lines (111 loc) · 3.45 KB
/
PointerProxy.cpp
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
#include "PointerProxy.h"
#include "s3eSurface.h"
PointerProxy* gpPointerProxy=0;
PointerProxy* PointerProxy::singleton()
{
if (!gpPointerProxy)
{
gpPointerProxy = new PointerProxy();
gpPointerProxy->Touches = new TouchInfo[MAX_TOUCHES];
}
return gpPointerProxy;
}
void PointerProxy::DestroySingleton()
{
if (gpPointerProxy)
{
if (gpPointerProxy->Touches)
delete gpPointerProxy->Touches;
delete gpPointerProxy;
gpPointerProxy = 0;
}
}
//Find an active touch with the specified id, or allocate a free one from the list
TouchInfo* PointerProxy::GetTouch(int32 id)
{
TouchInfo* pInActive = NULL;
for (uint32 i = 0; i < MAX_TOUCHES; i++)
{
if (id == Touches[i].id)
return &Touches[i];
if (!Touches[i].active)
pInActive = &Touches[i];
}
//Return first inactive touch
if (pInActive)
{
pInActive->id = id;
return pInActive;
}
return NULL;
}
void PointerProxy::MultiTouchButtonCB(s3ePointerTouchEvent* ev)
{
TouchInfo* touch = singleton()->GetTouch(ev->m_TouchID);
if (touch)
{
touch->active = ev->m_Pressed != 0;
touch->x = ev->m_x;
touch->y = ev->m_y;
singleton()->ClickEvents.push_back( TouchInfo(touch));
}
}
void PointerProxy::MultiTouchMotionCB(s3ePointerTouchMotionEvent* ev)
{
TouchInfo* touch = singleton()->GetTouch(ev->m_TouchID);
if (touch)
{
touch->x = ev->m_x;
touch->y = ev->m_y;
singleton()->MoveEvents.push_back( TouchInfo(touch) );
}
}
void PointerProxy::SingleTouchButtonCB(s3ePointerEvent* ev)
{
TouchInfo *touch = &singleton()->Touches[0];
touch->active = (ev->m_Pressed != 0);
touch->x = ev->m_x;
touch->y = ev->m_y;
singleton()->ClickEvents.push_back( TouchInfo(touch) );
//sprintf(g_TouchEventMsg, "`x666666Touch %s", event->m_Pressed ? "PRESSED" : "RELEASED");
}
void PointerProxy::SingleTouchMotionCB(s3ePointerMotionEvent* ev)
{
TouchInfo *touch = &singleton()->Touches[0];
touch->x = ev->m_x;
touch->y = ev->m_y;
uint32 siz = singleton()->MoveEvents.size();
singleton()->MoveEvents.push_back( TouchInfo(touch) );
}
void PointerProxy::RegisterCallbacks()
{
// An OS which supports multi-touch will return TOUCH_EVENTs if they are registered for.
// An OS which does not will only raise standard pointer events.
singleton()->bMultiTouch = s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE) ? true : false;
if (singleton()->bMultiTouch)
{
//Register for multi touch events on platforms where the functionality is available.
s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)MultiTouchButtonCB, NULL);
s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)MultiTouchMotionCB, NULL);
}
else
{
//Register for standard pointer events
s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)SingleTouchButtonCB, NULL);
s3ePointerRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)SingleTouchMotionCB, NULL);
}
}
void PointerProxy::Unregister()
{
//Clear up
if (singleton()->bMultiTouch)
{
s3ePointerUnRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)MultiTouchButtonCB);
s3ePointerUnRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)MultiTouchMotionCB);
}
else
{
s3ePointerUnRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)SingleTouchButtonCB);
s3ePointerUnRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)SingleTouchMotionCB);
}
}