-
Notifications
You must be signed in to change notification settings - Fork 7
/
Selector.pde
53 lines (44 loc) · 1.06 KB
/
Selector.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
/*
* Selector Class
* Used for keeping the state of selection, rendering, and updating the selection areas
*/
public class Selector extends Constants {
private PVector fStart, fEnd;
private boolean fSelecting;
public Selector() {
fStart = new PVector();
fEnd = new PVector();
fSelecting = false;
}
public boolean isSelecting() {
return fSelecting;
}
public PVector getStart() {
return fStart;
}
public PVector getEnd() {
return fEnd;
}
public void beginSelection(float x, float y) {
fStart.set(x, y, 0);
fEnd.set(x, y, 0);
fSelecting = true;
}
public void updateSelection(float x, float y) {
fEnd.set(x, y, 0);
}
public void endSelection(float x, float y) {
fSelecting = false;
}
public void draw() {
if (isSelecting()) {
pushStyle();
stroke(SELECTION_BORDER_COLOR);
strokeWeight(SELECTION_BORDER_WIDTH);
fill(SELECTION_COLOR);
PVector size = PVector.sub(fEnd, fStart);
rect(fStart.x, fStart.y, size.x, size.y);
popStyle();
}
}
}