-
Notifications
You must be signed in to change notification settings - Fork 0
/
SliderBox.pde
130 lines (122 loc) · 3.02 KB
/
SliderBox.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
class SliderBox
{
// The sliderbox allows the user to use a scroll at the bottom of the screen
int x, y, x1, y1, slideX, slideValue;
int width = SLIDERBOX_WIDTH;
int height = SLIDERBOX_HEIGHT;
int widthIn = SLIDERBOX_WIDTH - (MARGIN_BT_BOXES_IN_SLIDER_BOX*2);
int heightIn = SLIDERBOX_HEIGHT - (MARGIN_BT_BOXES_IN_SLIDER_BOX*2);
color insideBoxColor = RAIL_COLOR;
boolean pressed = false;
boolean slide=false;
SliderBox(ColorGroup colors)
{
this.x = SLIDERRAIL_WIDTH + MARGIN_X - SLIDERBOX_WIDTH;
this.y = SCREEN_Y - (MARGIN_Y + SLIDERBOX_HEIGHT);
this.x1 = x + MARGIN_BT_BOXES_IN_SLIDER_BOX;
this.y1 = y + MARGIN_BT_BOXES_IN_SLIDER_BOX;
this.slideX=SLIDE_X_NULL;
this.slideValue=0;
}
void draw()
{
if (slide) slide();
this.x1 = x + MARGIN_BT_BOXES_IN_SLIDER_BOX;
if(pressed == true){
noStroke();
fill(colors.getSelectedScheme().getHighlightedNode());
rect(x, y, width, height, 10);
}
else if(pressed == false){
noStroke();
fill(colors.getSelectedScheme().getDefaultNode());
rect(x, y, width, height, 10);
}
fill(insideBoxColor);
rect(x1, y1, widthIn, heightIn, 10);
}
int getX()
{
return this.x;
}
void setX(int x)
{
this.x = x;
}
void slideSetX(int slideX, int slideValue)
{
if (this.slideX==SLIDE_X_NULL)
{
this.slideX = slideX;
this.slideValue=slideValue;
slide=true;
}
}
void slide()
{
if ((this.slideX!=SLIDE_X_NULL)&&(this.slide))
{
if (slideValue==-1)
{
if (this.x>slideX)
{
this.x+=slideValue*2;
}
else
{
slideValue=0;
slide=false;
slideX=SLIDE_X_NULL;
}
}
else if (slideValue==1)
{
if (this.x<slideX)
{
this.x+=slideValue*2;
}
else
{
slideValue=0;
slide=false;
slideX=SLIDE_X_NULL;
}
}
}
}
void move()
{
// Check to see if slider has been selected
// boolean pressed is set to true if this is
// the case
if(pressed == false &&
mousePressed &&
mouseX >= x &&
mouseX <= (x + SLIDERBOX_WIDTH) &&
mouseY >= y &&
mouseY <= (y + SLIDERBOX_HEIGHT) &&
mouseX <= SCREEN_X - MARGIN_X - SLIDERBOX_WIDTH + (SLIDERBOX_WIDTH/2) &&
mouseX >= MARGIN_X + (SLIDERBOX_WIDTH/2))
{
pressed = true;
}
// If the user holds down the mouse button
// they can manipulate the slider without
// being over it
else if( pressed == true &&
mousePressed &&
mouseX <= SCREEN_X - MARGIN_X - SLIDERBOX_WIDTH + (SLIDERBOX_WIDTH/2) &&
mouseX >= MARGIN_X + (SLIDERBOX_WIDTH/2)&&
mouseY > MAP_HEIGHT + MAP_MAP_SLIDER_BOUNDARY_MARGIN)
{
this.x = mouseX - (SLIDERBOX_WIDTH/2);
}
// Once the mouse button is released, pressed reverts
// to false and the user ceases to be able to move the
// slider.
else
{
pressed = false;
}
}
}