/
ManipulationEventsink.cpp
257 lines (216 loc) · 5.81 KB
/
ManipulationEventsink.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved
#include "ManipulationEventsink.h"
#include "CoreObject.h"
#include <math.h>
#include <stdio.h>
static void SaveToFile(LPSTR str)
{
HANDLE hdl = CreateFile("C:\\debug.txt", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hdl == INVALID_HANDLE_VALUE)
{
return;
}
SetFilePointer(hdl, 0, NULL, FILE_END);
DWORD dwWritenSize = 0;
BOOL bRet = WriteFile(hdl, str, strlen(str),&dwWritenSize, NULL);
FlushFileBuffers(hdl);
CloseHandle(hdl);
}
CManipulationEventSink::CManipulationEventSink(HWND hWnd, CCoreObject *coRef, int iTimerId, BOOL inertia):
m_coRef(coRef),
m_hWnd(hWnd),
m_iTimerId(iTimerId),
m_bInertia(inertia),
m_pConnPoint(NULL),
m_cRefCount(1)
{
}
HRESULT STDMETHODCALLTYPE CManipulationEventSink::ManipulationStarted(
FLOAT x,
FLOAT y)
{
UNREFERENCED_PARAMETER(x);
UNREFERENCED_PARAMETER(y);
return S_OK;
}
HRESULT STDMETHODCALLTYPE CManipulationEventSink::ManipulationDelta(
FLOAT x,
FLOAT y,
FLOAT translationDeltaX,
FLOAT translationDeltaY,
FLOAT scaleDelta,
FLOAT expansionDelta,
FLOAT rotationDelta,
FLOAT cumulativeTranslationX,
FLOAT cumulativeTranslationY,
FLOAT cumulativeScale,
FLOAT cumulativeExpansion,
FLOAT cumulativeRotation)
{
UNREFERENCED_PARAMETER(cumulativeRotation);
UNREFERENCED_PARAMETER(cumulativeExpansion);
UNREFERENCED_PARAMETER(cumulativeScale);
UNREFERENCED_PARAMETER(cumulativeTranslationX);
UNREFERENCED_PARAMETER(cumulativeTranslationY);
UNREFERENCED_PARAMETER(expansionDelta);
dx=translationDeltaX;
dy=translationDeltaY;
Angle=rotationDelta*180.0/3.1415926535;
Scale=scaleDelta;
return S_OK;
}
HRESULT STDMETHODCALLTYPE CManipulationEventSink::ManipulationCompleted(
FLOAT x,
FLOAT y,
FLOAT cumulativeTranslationX,
FLOAT cumulativeTranslationY,
FLOAT cumulativeScale,
FLOAT cumulativeExpansion,
FLOAT cumulativeRotation)
{
UNREFERENCED_PARAMETER(cumulativeRotation);
UNREFERENCED_PARAMETER(cumulativeExpansion);
UNREFERENCED_PARAMETER(cumulativeScale);
UNREFERENCED_PARAMETER(cumulativeTranslationX);
UNREFERENCED_PARAMETER(cumulativeTranslationY);
UNREFERENCED_PARAMETER(x);
UNREFERENCED_PARAMETER(y);
return S_OK;
}
HRESULT CManipulationEventSink::SetupInertia(IInertiaProcessor* ip, IManipulationProcessor* mp)
{
HRESULT hr = S_OK;
// Set desired properties for inertia events
// Deceleration for tranlations in pixel / msec^2
HRESULT hrPutDD = ip->put_DesiredDeceleration(0.003f);
// Deceleration for rotations in radians / msec^2
HRESULT hrPutDAD = ip->put_DesiredAngularDeceleration(0.000015f);
// Set initial origins
// HRESULT hrPutIOX = ip->put_InitialOriginX(m_coRef->doDrawing->GetCenterX());
// HRESULT hrPutIOY = ip->put_InitialOriginY(m_coRef->doDrawing->GetCenterY());
FLOAT fVX;
FLOAT fVY;
FLOAT fVR;
HRESULT hrPutVX = mp->GetVelocityX(&fVX);
HRESULT hrGetVY = mp->GetVelocityY(&fVY);
HRESULT hrGetAV = mp->GetAngularVelocity(&fVR);
// Set initial velocities for inertia processor
HRESULT hrPutIVX = ip->put_InitialVelocityX(fVX);
HRESULT hrPutIVY = ip->put_InitialVelocityY(fVY);
HRESULT hrPutIAV = ip->put_InitialAngularVelocity(fVR);
// if(FAILED(hrPutDD) || FAILED(hrPutDAD) || FAILED(hrPutIOX) || FAILED(hrPutIOY)
// || FAILED(hrPutVX) || FAILED(hrGetVY) || FAILED(hrGetAV) || FAILED(hrPutIVX)
// || FAILED(hrPutIVY) || FAILED(hrPutIAV))
// {
// hr = E_FAIL;
// }
return hr;
}
ULONG CManipulationEventSink::AddRef()
{
return ++m_cRefCount;
}
ULONG CManipulationEventSink::Release()
{
m_cRefCount--;
if(m_cRefCount == 0)
{
delete this;
return 0;
}
return m_cRefCount;
}
HRESULT CManipulationEventSink::QueryInterface(REFIID riid, LPVOID *ppvObj)
{
HRESULT hr = S_OK;
if(ppvObj == NULL)
{
hr = E_POINTER;
}
if(!FAILED(hr))
{
*ppvObj = NULL;
if (IID__IManipulationEvents == riid)
{
*ppvObj = static_cast<_IManipulationEvents*>(this);
}
else if (IID_IUnknown == riid)
{
*ppvObj = static_cast<IUnknown*>(this);
}
if(*ppvObj)
{
AddRef();
}
else
{
hr = E_NOINTERFACE;
}
}
return hr;
}
// Set up the connection to a manipulation or inertia processor
BOOL CManipulationEventSink::SetupConnPt(IUnknown *manipulationProc)
{
BOOL success = FALSE;
IConnectionPointContainer* pConPointContainer = NULL;
// Only connect if there isn't already an active connection
if (m_pConnPoint == NULL)
{
// Check if supports connectable objects
success = SUCCEEDED(manipulationProc->QueryInterface(IID_IConnectionPointContainer,
(LPVOID*)&(pConPointContainer)));
// Get connection point interface
if(success)
{
success = SUCCEEDED(pConPointContainer->FindConnectionPoint(
_uuidof(_IManipulationEvents),
&(m_pConnPoint)));
}
// Clean up connection point container
if (pConPointContainer != NULL)
{
pConPointContainer->Release();
pConPointContainer = NULL;
}
// Hook event object to the connection point
IUnknown* pUnk = NULL;
if(success)
{
// Get pointer to manipulation event sink's IUnknown pointer
success = SUCCEEDED(QueryInterface(IID_IUnknown, (LPVOID*)&pUnk));
}
// Establish connection point to callback interface
if(success)
{
success = SUCCEEDED(m_pConnPoint->Advise(pUnk, &(m_uID)));
}
// Clean up IUnknown pointer
if(pUnk != NULL)
{
pUnk->Release();
}
if (!success && m_pConnPoint != NULL)
{
m_pConnPoint->Release();
m_pConnPoint = NULL;
}
}
return success;
}
VOID CManipulationEventSink::RemoveConnPt()
{
// Clean up the connection point associated to this event sink
if(m_pConnPoint)
{
m_pConnPoint->Unadvise(m_uID);
m_pConnPoint->Release();
m_pConnPoint = NULL;
}
}