From: terencehill Date: Thu, 13 Aug 2015 13:51:12 +0000 (+0200) Subject: Make sliders animation work much better on quick repeated changes (e.g. with mouse... X-Git-Tag: xonotic-v0.8.2~1890^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e07c15a4b598bc0b36965f21fe88bd7ef4e2deeb;p=xonotic%2Fxonotic-data.pk3dir.git Make sliders animation work much better on quick repeated changes (e.g. with mouse wheel). Default animation is now easingQuadOut and lasts 0.5 s (instead of easingQuadInOut, 1 s), more similar to the list scrolling animation --- diff --git a/qcsrc/menu/anim/animation.qc b/qcsrc/menu/anim/animation.qc index 3039d85b8..2a954db36 100644 --- a/qcsrc/menu/anim/animation.qc +++ b/qcsrc/menu/anim/animation.qc @@ -4,6 +4,7 @@ void setterDummy(entity, float); CLASS(Animation, Object) METHOD(Animation, configureAnimation, void(entity, entity, void(entity, float), float, float, float, float)) + METHOD(Animation, update, void(entity, float, float, float)) METHOD(Animation, setTimeStartEnd, void(entity, float, float)) METHOD(Animation, setTimeStartDuration, void(entity, float, float)) METHOD(Animation, setValueStartEnd, void(entity, float, float)) @@ -36,6 +37,12 @@ void Animation_configureAnimation(entity me, entity obj, void(entity, float) obj me.setValueStartEnd(me, animStartValue, animEndValue); } +void Animation_update(entity me, float animDuration, float animStartValue, float animEndValue) +{ + me.setTimeStartDuration(me, time, animDuration); + me.setValueStartEnd(me, animStartValue, animEndValue); +} + void Animation_setTimeStartEnd(entity me, float s, float e) { me.startTime = s; diff --git a/qcsrc/menu/item/slider.qc b/qcsrc/menu/item/slider.qc index 1d9cb8e72..345ad0423 100644 --- a/qcsrc/menu/item/slider.qc +++ b/qcsrc/menu/item/slider.qc @@ -24,6 +24,7 @@ CLASS(Slider, Label) ATTRIB(Slider, value, float, 0) ATTRIB(Slider, animated, float, 1) ATTRIB(Slider, sliderValue, float, 0) + ATTRIB(Slider, sliderAnim, entity, world) ATTRIB(Slider, valueMin, float, 0) ATTRIB(Slider, valueMax, float, 0) ATTRIB(Slider, valueStep, float, 0) @@ -51,8 +52,11 @@ ENDCLASS(Slider) void Slider_setValue(entity me, float val) { if (me.animated) { - anim.removeObjAnim(anim, me); - makeHostedEasing(me, Slider_setSliderValue, easingQuadInOut, 1, me.sliderValue, val); + float t = 0.5; + if(!me.sliderAnim) + me.sliderAnim = makeHostedEasing(me, Slider_setSliderValue, easingQuadOut, t, me.sliderValue, val); + else + me.sliderAnim.update(me.sliderAnim, t, me.sliderValue, val); } else { me.setSliderValue(me, val); } @@ -295,6 +299,14 @@ void Slider_draw(entity me) else draw_Picture(eX * controlLeft, strcat(me.src, "_n"), eX * me.controlWidth + eY, me.color, 1); } + + if(me.sliderAnim) + if(me.sliderAnim.isFinished(me.sliderAnim)) + { + anim.removeObjAnim(anim, me); + me.sliderAnim = world; + } + me.setText(me, me.valueToText(me, me.value)); draw_alpha = save; SUPER(Slider).draw(me);