-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugKey.pde
More file actions
115 lines (103 loc) · 2.56 KB
/
PlugKey.pde
File metadata and controls
115 lines (103 loc) · 2.56 KB
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
public class PlugKey{
float diameter, x, y;
char letter;
//Colors for the keys.
int kR, kG, kB, row;
//Colors for the outline.
int oR, oG, oB;
boolean highLight, selected;
public PlugKey(float x, float y, char c, int row){
this.diameter = 55;
this.x = x;
this.y = y;
this.letter = c;
this.kR = 150;
this.kG = 150;
this.kB = 150;
this.oR = 0;
this.oG = 0;
this.oB = 0;
this.highLight = false;
this.selected = false;
this.row = row;
}
/**
* Display the current key.
*/
public void show(){
highLight();
selectColors();
pushMatrix();
//Translate the center point to be at the x,y coord for this object.
translate(x, y);
//Thickness of the outline
strokeWeight(3);
//Color of the outline
stroke(oR,oG,oB);
//Don't fill the circle
fill(kR, kG, kB);
//Draw the circle from its center point
rectMode(CENTER);
//Draw a circle at x,y with width and height of size
rect(0, 0, diameter, diameter);
//Text size
textSize(30);
//Draw text from the center
textAlign(CENTER, CENTER);
//Color of the text.
fill(0,0,0);
//Display the text.
text(letter, 0, -5);
popMatrix();
}
private void selectColors(){
if(highLight){
this.kR = 143;
this.kG = 255;
this.kB = 137;
}
else{
this.kR = 150;
this.kG = 150;
this.kB = 150;
}
}
public void highLight(){
if (dist(x, y, mouseX, mouseY) < diameter/2){
this.highLight = true;
}
else{
this.highLight = false;
}
}
public boolean clicked(){
if(highLight && !selected){
selected = true;
this.oR = 200;
this.oG = 0;
this.oB = 0;
return true;
}
return false;
}
public float getX(){
return x;
}
public void deselect(){
selected = false;
this.oR = 0;
this.oG = 0;
this.oB = 0;
}
public float getY(){
return y;
}
public void setSelectedColors(int r, int g, int b){
this.oR = r;
this.oG = g;
this.oB = b;
}
public int getRow(){
return row;
}
}