root/trunk/processing/sketches/modest_maps_interactive/Button.pde

Revision 500, 1.5 kB (checked in by tom, 9 months ago)

fixing the image-less processing sketch for posting

Line 
1
2 class Button {
3  
4   float x, y, w, h;
5  
6   Button(float x, float y, float w, float h) {
7     this.x = x;
8     this.y = y;
9     this.w = w;
10     this.h = h;
11   }
12  
13   boolean mouseOver() {
14     return (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h);
15   }
16  
17   void draw() {
18     stroke(80);
19     fill(mouseOver() ? 255 : 220);
20     rect(x,y,w,h);
21   }
22  
23 }
24
25 class ZoomButton extends Button {
26  
27   boolean in = false;
28  
29   ZoomButton(float x, float y, float w, float h, boolean in) {
30     super(x, y, w, h);
31     this.in = in;
32   }
33  
34   void draw() {
35     super.draw();
36     stroke(0);
37     line(x+3,y+h/2,x+w-3,y+h/2);
38     if (in) {
39       line(x+w/2,y+3,x+w/2,y+h-3);
40     }
41   }
42  
43 }
44
45 class PanButton extends Button {
46  
47   int dir = UP;
48  
49   PanButton(float x, float y, float w, float h, int dir) {
50     super(x, y, w, h);
51     this.dir = dir;
52   }
53  
54   void draw() {
55     super.draw();
56     stroke(0);
57     switch(dir) {
58       case UP:
59         line(x+w/2,y+3,x+w/2,y+h-3);
60         line(x-3+w/2,y+6,x+w/2,y+3);
61         line(x+3+w/2,y+6,x+w/2,y+3);
62         break;
63       case DOWN:
64         line(x+w/2,y+3,x+w/2,y+h-3);
65         line(x-3+w/2,y+h-6,x+w/2,y+h-3);
66         line(x+3+w/2,y+h-6,x+w/2,y+h-3);
67         break;
68       case LEFT:
69         line(x+3,y+h/2,x+w-3,y+h/2);
70         line(x+3,y+h/2,x+6,y-3+h/2);
71         line(x+3,y+h/2,x+6,y+3+h/2);
72         break;
73       case RIGHT:
74         line(x+3,y+h/2,x+w-3,y+h/2);
75         line(x+w-3,y+h/2,x+w-6,y-3+h/2);
76         line(x+w-3,y+h/2,x+w-6,y+3+h/2);
77         break;
78     }
79   }
80  
81 }
Note: See TracBrowser for help on using the browser.