3 #include "../anim/easing.qh" 4 #include "../anim/animhost.qh" 10 if (allowAnim && me.animated)
14 else me.sliderAnim.update(me.sliderAnim, t, me.sliderValue, val);
18 me.setSliderValue(me, val);
36 return sprintf(
"%d (%s)", me.value, me.valueToText(me, me.value));
40 SUPER(
Slider).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
41 me.controlWidth = absSize.x == 0 ? 0 : (absSize.y / absSize.x);
51 me.textSpace = theTextSpace;
52 me.keepspaceLeft = (theTextSpace == 0) ? 0 : (1 - theTextSpace);
58 me.sliderValue = theValue;
59 me.valueStep = theValueStep;
60 me.valueMin = theValueMin;
61 me.valueMax = theValueMax;
62 me.valueKeyStep = theValueKeyStep;
63 me.valuePageStep = theValuePageStep;
65 if (
fabs(
floor(me.valueStep * 100 + 0.5) - (me.valueStep * 100)) < 0.01)
67 if (
fabs(
floor(me.valueStep * 10 + 0.5) - (me.valueStep * 10)) < 0.01)
69 if (
fabs(
floor(me.valueStep * 1 + 0.5) - (me.valueStep * 1)) < 0.01)
76 if (me.disabled)
return 0;
80 if (inRange) me.setValue(me,
median(me.valueMin, me.value - me.valueKeyStep, me.valueMax));
81 else me.setValue(me, me.valueMax);
86 if (inRange) me.setValue(me,
median(me.valueMin, me.value + me.valueKeyStep, me.valueMax));
87 else me.setValue(me, me.valueMin);
92 if (inRange) me.setValue(me,
median(me.valueMin, me.value - me.valuePageStep, me.valueMax));
93 else me.setValue(me, me.valueMax);
98 if (inRange) me.setValue(me,
median(me.valueMin, me.value + me.valuePageStep, me.valueMax));
99 else me.setValue(me, me.valueMin);
104 me.setValue(me, me.valueMin);
109 me.setValue(me, me.valueMax);
115 me.applyButton.disabled =
false;
123 if (me.disabled)
return 0;
146 if (me.disabled)
return 0;
151 if (pos.x < 0 - me.tolerance.x) hit = 0;
152 if (pos.y < 0 - me.tolerance.y) hit = 0;
153 if (pos.x >= 1 - me.textSpace + me.tolerance.x) hit = 0;
154 if (pos.y >= 1 + me.tolerance.y) hit = 0;
160 float f =
bound(0, (pos.x - me.pressOffset - 0.5 * me.controlWidth) / (1 - me.textSpace - me.controlWidth), 1);
161 v = f * (me.valueMax - me.valueMin) + me.valueMin;
164 if (f > 0 && f < 1 && me.valueStep)
165 v =
floor(0.5 + v / me.valueStep) * me.valueStep;
166 me.setValue_noAnim(me, v);
168 if(me.previousValue != me.value)
169 me.applyButton.disabled =
false;
173 me.setValue(me, me.previousValue);
183 if (pos.x < 0)
return false;
184 if (pos.y < 0)
return false;
185 if (pos.x >= 1 -
this.textSpace)
return false;
186 if (pos.y >= 1)
return false;
187 controlCenter = (this.value - this.valueMin) / (this.valueMax - this.valueMin) * (1 - this.textSpace - this.controlWidth) + 0.5 * this.controlWidth;
188 if (
fabs(pos.x - controlCenter) <= 0.5 * this.controlWidth)
191 this.pressOffset = pos.x - controlCenter;
192 this.previousValue = this.value;
197 float clickValue, pageValue, inRange;
198 clickValue =
median(0, (pos.x -
this.pressOffset - 0.5 *
this.controlWidth) / (1 -
this.textSpace -
this.controlWidth), 1) * (this.valueMax - this.valueMin) + this.valueMin;
200 if (pos.x < controlCenter)
202 pageValue = this.value - this.valuePageStep;
203 if (this.valueStep) clickValue =
floor(clickValue / this.valueStep) * this.valueStep;
204 pageValue =
max(pageValue, clickValue);
208 pageValue = this.value + this.valuePageStep;
209 if (this.valueStep) clickValue =
ceil(clickValue / this.valueStep) * this.valueStep;
210 pageValue =
min(pageValue, clickValue);
212 if (inRange) this.setValue(
this,
median(this.valueMin, pageValue, this.valueMax));
213 else this.setValue(
this, this.valueMax);
216 if (pageValue == clickValue)
218 controlCenter = (this.value - this.valueMin) / (this.valueMax - this.valueMin) * (1 - this.textSpace - this.controlWidth) + 0.5 * this.controlWidth;
220 this.pressOffset = pos.x - controlCenter;
221 this.previousValue = this.value;
230 if (me.disabled)
return 0;
236 me.focusable = !me.disabled;
242 me.focusable = !me.disabled;
244 if (me.disabled)
draw_alpha *= me.disabledAlpha;
246 if (me.valueMax > me.valueMin)
249 controlLeft = (me.sliderValue - me.valueMin) / (me.valueMax - me.valueMin) * (1 - me.textSpace - me.controlWidth);
257 if (me.sliderAnim.isFinished(me.sliderAnim))
260 me.sliderAnim =
NULL;
263 if (me.valueMax > me.valueMin)
264 me.setText(me, me.valueToText(me, me.value));
ERASEABLE float median(float a, float b, float c)
ERASEABLE float almost_in_bounds(float a, float b, float c)
ERASEABLE string ftos_decimals(float number, int decimals)
converts a number to a string with the indicated number of decimals
void Slider_setValue_noAnim(entity me, float val)
string Slider_valueToText(entity me, float val)
float Slider_keyUp(entity me, float key, float ascii, float shift)
void Slider_showNotify(entity me)
void Slider_draw(entity me)
#define METHOD(cname, name, prototype)
void Slider_setValue_allowAnim(entity me, float val, bool allowAnim)
void Slider_setValue(entity me, float val)
void Slider_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
float easingQuadOut(float tickTime, float animDuration, float animStart, float animDelta)
float Slider_keyDown(entity me, float key, float ascii, float shift)
entity makeHostedEasing(entity obj, void(entity, float) objSetter, float(float, float, float, float) func, float animDuration, float animStartValue, float animEnd)
string Slider_toString(entity me)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
void Slider_configureSliderValues(entity me, float theValueMin, float theValue, float theValueMax, float theValueStep, float theValueKeyStep, float theValuePageStep)
float Slider_mouseRelease(entity me, vector pos)
float Slider_mouseDrag(entity me, vector pos)
void Slider_configureSliderVisuals(entity me, float sz, float theAlign, float theTextSpace, string gfx)
void Slider_setSliderValue(entity me, float val)