2 CLASS(Slider) EXTENDS(Label)
3 METHOD(Slider, resizeNotify, void(entity, vector, vector, vector, vector))
4 METHOD(Slider, configureSliderVisuals, void(entity, string, string, float, float, string))
5 METHOD(Slider, configureSliderValues, void(entity, float, float, float, float, float, float))
6 METHOD(Slider, draw, void(entity))
7 METHOD(Slider, keyDown, float(entity, float, float, float))
8 METHOD(Slider, mousePress, float(entity, vector))
9 METHOD(Slider, mouseDrag, float(entity, vector))
10 METHOD(Slider, mouseRelease, float(entity, vector))
11 ATTRIB(Slider, src, string, "")
12 ATTRIB(Slider, focusable, float, 1)
13 ATTRIB(Slider, value, float, 0)
14 ATTRIB(Slider, valueMin, float, 0)
15 ATTRIB(Slider, valueMax, float, 0)
16 ATTRIB(Slider, valueStep, float, 0)
17 ATTRIB(Slider, valueKeyStep, float, 0)
18 ATTRIB(Slider, valuePageStep, float, 0)
19 ATTRIB(Slider, valueSpace, float, 0)
20 ATTRIB(Slider, controlWidth, float, 0)
21 ATTRIB(Slider, pressed, float, 0)
22 ATTRIB(Slider, pressOffset, float, 0)
23 ATTRIB(Slider, prefix, string, "")
24 ATTRIB(Slider, suffix, string, "")
25 ATTRIB(Slider, previousValue, float, 0)
30 void resizeNotifySlider(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
32 resizeNotifyLabel(me, relOrigin, relSize, absOrigin, absSize);
33 me.controlWidth = absSize_y / absSize_x;
35 void configureSliderVisualsSlider(entity me, string thePrefix, string theSuffix, float sz, float theValueSpace, string gfx)
37 configureLabelLabel(me, "", sz, 1);
38 me.prefix = thePrefix;
39 me.suffix = theSuffix;
40 me.valueSpace = theValueSpace;
43 void configureSliderValuesSlider(entity me, float theValueMin, float theValue, float theValueMax, float theValueStep, float theValueKeyStep, float theValuePageStep)
46 me.valueStep = theValueStep;
47 me.valueMin = theValueMin;
48 me.valueMax = theValueMax;
49 me.valueKeyStep = theValueKeyStep;
50 me.valuePageStep = theValuePageStep;
52 float keyDownSlider(entity me, float key, float ascii, float shift)
54 if(key == K_LEFTARROW)
56 me.value = bound(me.valueMin, me.value - me.valueKeyStep, me.valueMax);
59 if(key == K_RIGHTARROW)
61 me.value = bound(me.valueMin, me.value + me.valueKeyStep, me.valueMax);
66 me.value = bound(me.valueMin, me.value - me.valuePageStep, me.valueMax);
71 me.value = bound(me.valueMin, me.value + me.valuePageStep, me.valueMax);
77 float mouseDragSlider(entity me, vector pos)
83 if(pos_x < 0) hit = 0;
84 if(pos_y < 0) hit = 0;
85 if(pos_x >= 1 - me.valueSpace) hit = 0;
86 if(pos_y >= 1) hit = 0;
89 me.value = bound(0, (pos_x - me.pressOffset - 0.5 * me.controlWidth) / (1 - me.valueSpace - me.controlWidth), 1) * (me.valueMax - me.valueMin) + me.valueMin;
91 me.value = floor(0.5 + me.value / me.valueStep) * me.valueStep;
94 me.value = me.previousValue;
98 float mousePressSlider(entity me, vector pos)
101 if(pos_x < 0) return 0;
102 if(pos_y < 0) return 0;
103 if(pos_x >= 1 - me.valueSpace) return 0;
104 if(pos_y < 0) return 0;
105 controlCenter = (me.value - me.valueMin) / (me.valueMax - me.valueMin) * (1 - me.valueSpace - me.controlWidth) + 0.5 * me.controlWidth;
106 if(fabs(pos_x - controlCenter) <= 0.5 * me.controlWidth)
109 me.pressOffset = pos_x - controlCenter;
110 me.previousValue = me.value;
111 me.mouseDrag(me, pos);
115 if(pos_x < controlCenter)
116 me.keyDown(me, K_PGUP, 0, 0);
118 me.keyDown(me, K_PGDN, 0, 0);
122 float mouseReleaseSlider(entity me, vector pos)
127 void drawSlider(entity me)
130 controlLeft = (me.value - me.valueMin) / (me.valueMax - me.valueMin) * (1 - me.valueSpace - me.controlWidth);
131 draw_ButtonPicture('0 0 0', strcat(me.src, "_s"), eX * (1 - me.valueSpace) + eY, '1 1 1', 1);
133 draw_Picture(eX * controlLeft, strcat(me.src, "_c"), eX * me.controlWidth + eY, '1 1 1', 1);
135 draw_Picture(eX * controlLeft, strcat(me.src, "_f"), eX * me.controlWidth + eY, '1 1 1', 1);
137 draw_Picture(eX * controlLeft, strcat(me.src, "_n"), eX * me.controlWidth + eY, '1 1 1', 1);
138 me.setText(me, strcat(me.prefix, ftos(me.value), me.suffix));
140 me.text = ""; // TEMPSTRING!