-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSliderData.cpp
More file actions
48 lines (39 loc) · 1009 Bytes
/
Copy pathSliderData.cpp
File metadata and controls
48 lines (39 loc) · 1009 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
39
40
41
42
43
44
45
46
47
48
#include "master.h"
#include "SliderData.h"
using namespace pyrodactyl;
void SliderData::Load(rapidxml::xml_node<char> * node, pyroRect* parent)
{
ImageData::Load(node, parent);
LoadNum(min, "min", node);
LoadNum(max, "max", node);
//By default, 10 presses will get you from slider min->max and max->min
if (!LoadNum(inc_val, "inc_val", node))
inc_val = (max - min) / 10.0f;
CreateBackup();
}
void SliderData::Clamp()
{
if (value < min)
value = min;
else if (value > max)
value = max;
}
void SliderData::Value(const float val)
{
value = val;
Clamp();
}
void SliderData::Value(const int &knob_x, const int &knob_w)
{
float pos = (float)(knob_x - x) / (float)(w - knob_w);
value = min + ((max - min) * pos);
Clamp();
}
int SliderData::KnobPos(const int &knob_w)
{
return static_cast<int>((static_cast<float>(w - knob_w) * value) / (max - min));
}
int SliderData::Offset(const int &knob_w)
{
return static_cast<int>((static_cast<float>(w - knob_w) * (value - min)) / (max - min));
}