This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrackpad.pde
159 lines (141 loc) · 3.44 KB
/
Trackpad.pde
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
/*
* From SimpleOpenNI NITE Slider2d example
* Processing Wrapper for the OpenNI/Kinect library
* http://code.google.com/p/simple-openni
* prog: Max Rheiner / Interaction Design / zhdk / http://iad.zhdk.ch/
* date: 03/28/2011 (m/d/y)
*/
class Trackpad
{
int xRes;
int yRes;
int width;
int height;
boolean active;
PVector center;
PVector offset;
int space;
int focusX;
int focusY;
int selX;
int selY;
int dir;
int currentAlpha;
int activeItems;
long _now, _sendAt = 0;
boolean[][] selected;
IRDevice device;
Date d = new Date();
public Trackpad(PVector center, int xRes, int yRes, int width, int height, int space, IRDevice device)
{
this.currentAlpha = 255;
this.activeItems = 0;
this.xRes = xRes;
this.yRes = yRes;
this.width = width;
this.height = height;
active = false;
this.center = center.get();
offset = new PVector();
offset.set(-(float)(xRes * width + (xRes - 1) * space) * .5f, - (float)(yRes * height + (yRes - 1) * space) * .5f,
0.0f);
offset.add(this.center);
this.space = space;
this.selected = new boolean[yRes][xRes];
this.device = device;
}
void setAlpha(int alpha)
{
this.currentAlpha = alpha;
if (this.currentAlpha < 0)
this.currentAlpha = 0;
if (this.currentAlpha > 255)
this.currentAlpha = 255;
}
int getAlpha()
{
return this.currentAlpha;
}
void enable()
{
active = true;
focusX = -1;
focusY = -1;
selX = -1;
selY = -1;
}
void update(int indexX, int indexY)
{
focusX = indexX;
focusY = (yRes - 1) - indexY;
}
void push(int indexX, int indexY, int dir)
{
d = new Date();
_now = d.getTime();
if (_now - _sendAt > 1000) //bloqueia por um segundo o push
{
selX = indexX;
selY = (yRes - 1) - indexY;
this.dir = dir;
activeItems++;
selected[selY][selX] = true;
this.draw();
if (device != null)
{
device.transmit(Integer.toString((selY * 5) + selX));
d = new Date();
_sendAt = d.getTime();
}
if (activeItems >= 2)
{
selected = new boolean[yRes][xRes];
activeItems = 0;
}
}
}
void disable()
{
active = false;
selected = new boolean[yRes][xRes];
activeItems = 0;
}
void draw()
{
pushStyle();
pushMatrix();
translate(offset.x, offset.y);
int k = 0;
for (int y = 0; y < yRes; y++) {
for (int x = 0; x < xRes; x++) {
if (active && (selX == x) && (selY == y) || (selected[y][x])) { // selected object
fill(204, 102, 0, currentAlpha - 20);
strokeWeight(1);
stroke(204, 102, 0, 220);
}
else if (active && (focusX == x) && (focusY == y)) { // focus object
fill(134, 1, 199, currentAlpha + 20);
strokeWeight(1);
stroke(134, 1, 199, 220);
}
else if (active) { // normal
fill(0, 0, 0, 60);
strokeWeight(1);
stroke(0, 0, 0, 190);
}
else {
noFill();
strokeWeight(1);
stroke(0, 0, 0, 60);
}
rect(x * (width + space), y * (width + space), width, height);
fill(255, 255, 255, currentAlpha);
textSize(56);
text(String.valueOf(k), (x * (width + space)) + width / 2 - 25, (y * (width + space)) + height / 2 - 25, width, height);
k++;
}
}
popMatrix();
popStyle();
}
}