-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlider.cpp
More file actions
72 lines (69 loc) · 1.7 KB
/
Slider.cpp
File metadata and controls
72 lines (69 loc) · 1.7 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
#include "menuElements.h"
#include "Font.h"
#include <stdlib.h>
#include <string.h>
void Slider::Update(const V2D &mouse,bool mouseBtn,bool lastBtn)
{
ul=bbox;
br=bbox;
text=bbox;
float s;
unsigned char i;
if(vertical) i=1; else i=0;
s=bbox.sup[1-i]-bbox.inf[1-i];
text.inf[i]=ul.sup[i]=ul.inf[i]+s;
text.sup[i]=br.inf[i]=br.sup[i]-s;
if(mouseBtn)
{
if((!lastBtn)&&(bbox.IsInside(mouse)))
{
if(ul.IsInside(mouse)) state=CLICK_UL;
if(br.IsInside(mouse)) state=CLICK_BR;
if((state==CLICK_UL) || (state==CLICK_BR))
{
time=29;
currLimit=30;
counterVel=60;
}
}
if((state==CLICK_UL) || (state==CLICK_BR))
{
time++;
if(time==currLimit)
{
if(state==CLICK_UL) if(ul.IsInside(mouse)) if(pos>minValue) pos-=stepValue;
if(state==CLICK_BR) if(br.IsInside(mouse)) if(pos<maxValue) pos+=stepValue;
time=0;
counterVel-=currLimit;
if(counterVel<=0)
{
currLimit/=2;
if(currLimit==0) currLimit=1;
counterVel+=60;
}
}
}
} else state=NORMAL;
}
void Slider::Draw(Font *f,Arrow2D *a)
{
char buff[20];
itoa(pos,buff,10);
if(withMax)
{
char b2[10];
itoa(maxValue,b2,20);
strcat(buff,"/");
strcat(buff,b2);
}
f->ShowStringOnBox(buff,text.inf.x,text.inf.y,text.sup.x,text.sup.y,cBlack,Font::CENTER);
if(vertical)
{
a->DrawUp(ul.inf.x+0,ul.inf.y+0,ul.sup.x-0,ul.sup.y-0,false,(state==CLICK_UL));
a->DrawDown(br.inf.x+0,br.inf.y+0,br.sup.x-0,br.sup.y-0,false,(state==CLICK_BR));
} else
{
a->DrawLeft(ul.inf.x+0,ul.inf.y+0,ul.sup.x-0,ul.sup.y-0,false,(state==CLICK_UL));
a->DrawRight(br.inf.x+0,br.inf.y+0,br.sup.x-0,br.sup.y-0,false,(state==CLICK_BR));
}
}