-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvirons.Cli.PixelSense.cpp
223 lines (178 loc) · 6.14 KB
/
Environs.Cli.PixelSense.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
/**
* Environs CLI Tabletop surface part
* ------------------------------------------------------------------
* Copyright (c) Chi-Tai Dang
*
* @author Chi-Tai Dang
* @version 1.0
* @remarks
*
* This file is part of the Environs framework developed at the
* Lab for Human Centered Multimedia of the University of Augsburg.
* http://hcm-lab.de/environs
*
* Environ is free software; you can redistribute it and/or modify
* it under the terms of the Eclipse Public License v1.0.
* A copy of the license may be obtained at:
* http://www.eclipse.org/org/documents/epl-v10.html
* --------------------------------------------------------------------
*/
#include "stdafx.h"
#if (defined(CLI_CPP) && defined(CLI_PS))
#include "Environs.Types.h.cli.h"
#include "Environs.Observer.CLI.h"
#include "Environs.Cli.h"
#include "Message.Instance.h"
#include "File.Instance.h"
#include "Portal.Instance.h"
#include "Device.Instance.h"
#include "Device.List.h"
#include "Interop/Stat.h"
#include "Environs.h"
#include "Environs.Cli.TouchDevice.h"
#include <stdio.h>
#include <stdarg.h>
#if !defined(WINDOWS_PHONE) && !defined(_WIN32)
# include <stdlib.h>
#endif
using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
using namespace Microsoft::Surface::Presentation::Input;
namespace environs
{
bool Environs::InitSurfacePlatformLayer ()
{
EnvironsTouchDevice::Init ( appWindow );
latencyIndicator = gcnew LatencyIndicator ();
deviceHandler = gcnew DeviceHandler ( this );
applicationEnvironments = gcnew System::Collections::Generic::Dictionary<int, ApplicationEnvironment ^ > ();
// Detect whether we are running on a real PixelSense device or not
int platform = environs::API::GetPlatformN ();
int pixelSense = ( int ) Platforms::SAMSUR40;
if ( ( platform & pixelSense ) == pixelSense ) {
environs::API::SetUseDeviceMarkerAutomaticN ( false );
environs::API::SetDeviceMarkerReducedPrecisionN ( false );
isSurface = true;
}
else {
// Not a PixelSense device, so make use of the more efficient native handling of device marker
environs::API::SetUseDeviceMarkerAutomaticN ( true );
environs::API::SetDeviceMarkerReducedPrecisionN ( true );
// In order to disable native marker handling
// Set both options to false and isSurface to true
}
//InitRawImageCapture ( new WindowInteropHelper ( appWindow ).Handle );
return true;
}
void Environs::InitLatencyIndicator ( System::Windows::Controls::TextBlock ^ tb )
{
latencyIndicator->Init ( tb );
latencyIndicator->Start ();
}
ref class EnvironsInjectTouch
{
InputPack ^ pack;
int nativeID;
public:
EnvironsInjectTouch ( int n, InputPack ^ p ) : nativeID ( n ), pack ( p ) {}
void Run () {
switch ( pack->state )
{
case INPUT_STATE_ADD: // touch down from client id on x/y
EnvironsTouchDevice::ContactDown ( nativeID, pack );
break;
case INPUT_STATE_CHANGE: // touch moved from client id to x/y
EnvironsTouchDevice::ContactChanged ( nativeID, pack );
break;
case INPUT_STATE_DROP: // touch up from client id on x/y
EnvironsTouchDevice::ContactUp ( nativeID, pack );
break;
}
}
};
/// <summary>
/// A static method of the surface specific handling of injection of contact down events.
/// </summary>
/// <param name="id"></param>
/// <param name="x"></param>
/// <param name="y"></param>
void Environs::InjectTouch ( int nativeID, InputPack ^ pack )
{
EnvironsInjectTouch ^ act = gcnew EnvironsInjectTouch ( nativeID, pack );
Action ^ action = gcnew Action ( act, &EnvironsInjectTouch::Run );
environs::Environs::dispatch ( action );
}
void Environs::appTouchDown ( Object ^ sender, TouchEventArgs ^ e )
{
TouchDevice ^ c = e->TouchDevice;
//if (c->GetType() == typeof(EnvironsTouchDevice))
// return;
//Debug.WriteLine("appTouchDown");
if ( EnvironsTouchExtensions::GetIsTagRecognized ( c ) )
{
if ( isSurface && updateDeviceTagPosition )
{
System::Windows::Point ^ pt = EnvironsTouchExtensions::GetPosition ( c, appWindow );
float orientation = (float)EnvironsTouchExtensions::GetOrientation ( c, appWindow );
int deviceID = (int)EnvironsTouchExtensions::GetTagData ( c )->Value;
//FilterTagUp.down(deviceID);
deviceHandler->detected ( deviceID, (int)pt->X, (int)pt->Y, orientation );
}
e->Handled = true;
return;
}
else if ( EnvironsTouchExtensions::GetIsFingerRecognized ( c ) )
{
return;
}
}
void Environs::appTouchMove ( Object ^ sender, TouchEventArgs ^ e )
{
TouchDevice ^ c = e->TouchDevice;
// Debug.WriteLine("appTouchMove");
if ( EnvironsTouchExtensions::GetIsTagRecognized ( c ) )
{
if ( isSurface && updateDeviceTagPosition )
{
System::Windows::Point ^ pt = EnvironsTouchExtensions::GetPosition ( c, appWindow );
float orientation = (float)EnvironsTouchExtensions::GetOrientation ( c, appWindow );
int deviceID = (int)EnvironsTouchExtensions::GetTagData ( c )->Value;
//FilterTagUp.down(deviceID);
deviceHandler->moved ( deviceID, (int)pt->X, (int)pt->Y, orientation );
}
e->Handled = true;
return;
}
else if ( EnvironsTouchExtensions::GetIsFingerRecognized ( c ) )
{
return;
}
}
void Environs::appTouchUp ( Object ^ sender, TouchEventArgs ^ e )
{
TouchDevice ^ c = e->TouchDevice;
//Debug.WriteLine("appTouchUp");
if ( EnvironsTouchExtensions::GetIsTagRecognized ( c ) )
{
if ( isSurface && updateDeviceTagPosition )
{
System::Windows::Point ^ pt = EnvironsTouchExtensions::GetPosition ( c, appWindow );
float orientation = (float)EnvironsTouchExtensions::GetOrientation ( c, appWindow );
int deviceID = (int)EnvironsTouchExtensions::GetTagData ( c )->Value;
//FilterTagUp.up(deviceID, pt, orientation);
deviceHandler->vanished ( deviceID, (int)pt->X, (int)pt->Y, orientation );
}
e->Handled = true;
return;
}
else if ( EnvironsTouchExtensions::GetIsFingerRecognized ( c ) )
{
return;
}
}
namespace lib
{
}
}
#endif