]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
more work on the menu animation framework, keyframes are now more easy to use
authorStephan Stahl <esteel@eos.franken.de>
Sun, 11 Apr 2010 19:25:50 +0000 (19:25 +0000)
committerStephan Stahl <esteel@eos.franken.de>
Sun, 11 Apr 2010 19:25:50 +0000 (19:25 +0000)
qcsrc/menu/anim/keyframe.c

index 39e1fd8b423f9c0ba15a53a47b0199724af885d8..d32f19618454dd655c9cc87b51bab9303e3c0cb3 100644 (file)
@@ -1,5 +1,6 @@
 #ifdef INTERFACE
 CLASS(Keyframe) EXTENDS(Animation)
+       METHOD(Keyframe, addEasing, entity(entity, float, float, float(float, float, float, float)))
        METHOD(Keyframe, addAnim, void(entity, entity))
        METHOD(Keyframe, calcValue, float(entity, float, float, float, float))
        ATTRIB(Keyframe, currentChild, entity, NULL)
@@ -8,6 +9,9 @@ CLASS(Keyframe) EXTENDS(Animation)
 ENDCLASS(Animation)
 entity makeHostedKeyframe(entity, void(entity, float), float, float, float);
 entity makeKeyframe(entity, void(entity, float), float, float, float);
+float getNewChildStart(entity);
+float getNewChildDuration(entity, float);
+float getNewChildValue(entity);
 #endif
 
 #ifdef IMPLEMENTATION
@@ -27,6 +31,40 @@ entity makeKeyframe(entity obj, void(entity, float) setter, float duration, floa
        return me;
 }
 
+entity addEasingKeyframe(entity me, float durationTime, float end, float(float, float, float, float) func)
+{
+       entity other;
+       other = makeEasing(me.object, me.setter, func, getNewChildStart(me), getNewChildDuration(me, durationTime), getNewChildValue(me), end);
+       me.addAnim(me, other);
+       return other;
+}
+
+float getNewChildStart(entity me)
+{
+       if (me.lastChild)
+               return (me.lastChild.startTime + me.lastChild.duration);
+       else
+               return 0;
+}
+
+float getNewChildDuration(entity me, float durationTime)
+{
+       float dura, maxDura;
+       maxDura = me.duration;
+       if (me.lastChild) maxDura = maxDura - (me.lastChild.startTime + me.lastChild.duration);
+       dura = durationTime;
+       if (0 >= dura || dura > maxDura) dura = maxDura;
+       return dura;
+}
+
+float getNewChildValue(entity me)
+{
+       if (me.lastChild)
+               return (me.lastChild.startValue + me.lastChild.delta);
+       else
+               return me.startValue;
+}
+
 void addAnimKeyframe(entity me, entity other)
 {
        if(other.parent)