-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtons.pde
More file actions
38 lines (38 loc) · 999 Bytes
/
Buttons.pde
File metadata and controls
38 lines (38 loc) · 999 Bytes
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
public class Button{ //Basic button again from processing tutorial
PVector position; //where
float sizeX, sizeY; //how big
String text; //saying what
public boolean mouseOver = false; //is mouse over
//Basic constructor
public Button(PVector where, float w, float h, String line){
position = where.copy();
sizeX = w;
sizeY = h;
text = line;
}
//2d collision logic!
public boolean isMouseOver(int mX, int mY){
if(mX >= position.x && mX <= position.x+sizeX && mY >= position.y && mY <= position.y+sizeY){
mouseOver = true;
}else{
mouseOver = false;
}
return mouseOver;
}
//renders to screen
public void show(){
fill(0);
//If mouse is over change colour.
if(mouseOver){
stroke(0, 255, 0);
}else{
stroke(0, 0, 255);
}
//draw to screen.
rect(position.x, position.y, sizeX, sizeY);
stroke(0, 0, 255);
fill(0, 0, 255);
textSize(24);
text(text, position.x, position.y+sizeY/2);
}
}