]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'master' into terencehill/slider_anim_improvements
authorterencehill <piuntn@gmail.com>
Wed, 26 Aug 2015 12:24:11 +0000 (14:24 +0200)
committerterencehill <piuntn@gmail.com>
Wed, 26 Aug 2015 12:24:11 +0000 (14:24 +0200)
Conflicts:
qcsrc/menu/anim/animation.qc

qcsrc/menu/anim/animation.qc
qcsrc/menu/item/slider.qc

index d52ae4f719e07b5017216e0251a01a6749b5d9dd..5563b969d98bfb4751e29e661b2c97a6c5248c45 100644 (file)
@@ -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;
index 4654425431199bb1913b0c4ee54fefeac866f7db..cdc8e2b9549d00e0c7e8a57351083016029e08de 100644 (file)
@@ -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,13 @@ 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.pressed == 2)
+                       t = 0.3; // slightly more responsive while dragging the handle
+               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);
        }
@@ -177,14 +183,10 @@ float Slider_keyUp(entity me, float key, float ascii, float shift)
 float Slider_mouseDrag(entity me, vector pos)
 {
        float hit;
-       float v, animed;
+       float v;
        if(me.disabled)
                return 0;
 
-       anim.removeObjAnim(anim, me);
-       animed = me.animated;
-       me.animated = false;
-
        if(me.pressed)
        {
                hit = 1;
@@ -194,6 +196,9 @@ float Slider_mouseDrag(entity me, vector pos)
                if(pos.y >= 1 + me.tolerance.y) hit = 0;
                if(hit)
                {
+                       // handle dragging
+                       me.pressed = 2;
+
                        v = median(0, (pos.x - me.pressOffset - 0.5 * me.controlWidth) / (1 - me.textSpace - me.controlWidth), 1) * (me.valueMax - me.valueMin) + me.valueMin;
                        if(me.valueStep)
                                v = floor(0.5 + v / me.valueStep) * me.valueStep;
@@ -203,8 +208,6 @@ float Slider_mouseDrag(entity me, vector pos)
                        me.setValue(me, me.previousValue);
        }
 
-       me.animated = animed;
-
        return 1;
 }
 float Slider_mousePress(entity me, vector pos)
@@ -295,6 +298,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);