-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.pde
143 lines (122 loc) · 3.18 KB
/
UI.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
/* UI-related functions */
int CONNECT_LIST = 0;
int DISCONNECT_LIST = 1;
int listState = CONNECT_LIST;
void mousePressed(){
//keyboard button -- toggle virtual keyboard
if (mouseY <= 50*displayDensity && mouseX > 0 && mouseX < width/3)
KetaiKeyboard.toggle(this);
else if (mouseY <= 50*displayDensity && mouseX > width/3 && mouseX < 2*(width/3)) //config button
{
isConfiguring=true;
} else if (mouseY <= 50*displayDensity && mouseX > 2*(width/3) && mouseX < width) // draw button
{
if (isConfiguring)
{
//if we're entering draw mode then clear canvas
background(78, 93, 75);
isConfiguring=false;
}
}
}
void mouseDragged()
{
if (isConfiguring)
return;
//send data to everyone
// we could send to a specific device through
// the writeToDevice(String _devName, byte[] data)
// method.
OscMessage m = new OscMessage("/remoteMouse/");
m.add(mouseX);
m.add(mouseY);
//text("2."+ otherSize.get(0) +", "+ otherSize.get(1) , mouseX, mouseY);
//println("m= "+ m);
bt.broadcast(m.getBytes());
ellipse(mouseX, mouseY, 20, 20);
OscMessage mm = new OscMessage("/size/");
mm.add(width);
mm.add(height);
bt.broadcast(mm.getBytes());
}
public void keyPressed() {
if (key =='c')
{
listState = CONNECT_LIST;
//If we have not discovered any devices, try prior paired devices
if (bt.getDiscoveredDeviceNames().size() > 0) {
ArrayList<String> list = bt.getDiscoveredDeviceNames();
list.add("CANCEL");
klist = new KetaiList(this, list);
} else if (bt.getPairedDeviceNames().size() > 0) {
ArrayList<String> list = bt.getPairedDeviceNames();
list.add("CANCEL");
klist = new KetaiList(this, list);
}
} else if (key =='x')
{
listState = DISCONNECT_LIST;
//If we have not discovered any devices, try prior paired devices
if (bt.getConnectedDeviceNames().size() > 0) {
ArrayList<String> list = bt.getConnectedDeviceNames();
list.add("CANCEL");
klist = new KetaiList(this, list);
} else {
println("No devices to disconnect.");
}
} else if (key == 'd')
{
bt.discoverDevices();
}
else if (key == 'b')
{
bt.makeDiscoverable();
} else if (key == 's')
{
bt.start();
}
}
void drawUI()
{
//Draw top shelf UI buttons
pushStyle();
fill(0);
stroke(255);
rect(0, 0, width/3, 50*displayDensity);
if (isConfiguring)
{
noStroke();
fill(78, 93, 75);
} else
fill(0);
rect(width/3, 0, width/3, 50*displayDensity);
if (!isConfiguring)
{
noStroke();
fill(78, 93, 75);
} else
{
fill(0);
stroke(255);
}
rect((width/3)*2, 0, width/3, 50*displayDensity);
fill(255);
text("Keyboard", 5, 30*displayDensity);
text("Bluetooth", width/3+5, 30*displayDensity);
text("Interact", width/3*2+5, 30*displayDensity);
popStyle();
}
void onKetaiListSelection(KetaiList klist)
{
String selection = klist.getSelection();
if (listState == CONNECT_LIST)
{
if (!selection.equals("CANCEL"))
bt.connectToDeviceByName(selection);
}else if (listState == DISCONNECT_LIST)
{
bt.disconnectDevice(selection);
}
//dispose of list for now
klist = null;
}