]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/anim/animhost.c
more anim math functions, some restructuring.. need to make the animated sliders...
[divverent/nexuiz.git] / data / qcsrc / menu / anim / animhost.c
1 #ifdef INTERFACE
2 CLASS(AnimHost) EXTENDS(Object)
3         METHOD(AnimHost, addAnim, void(entity, entity))
4         METHOD(AnimHost, removeAnim, void(entity, entity))
5         METHOD(AnimHost, stopAllAnim, void(entity))
6         METHOD(AnimHost, finishAllAnim, void(entity))
7         METHOD(AnimHost, tickAll, void(entity))
8         ATTRIB(AnimHost, firstChild, entity, NULL)
9         ATTRIB(AnimHost, lastChild, entity, NULL)
10 ENDCLASS(AnimHost)
11 .entity nextSibling;
12 .entity prevSibling;
13 #endif
14
15 #ifdef IMPLEMENTATION
16 void addAnimAnimHost(entity me, entity other)
17 {
18         if(other.parent)
19                 error("Can't add already added anim!");
20
21         if(other.isFinished(other))
22                 error("Can't add finished anim!");
23
24         other.parent = me;
25
26         entity f, l;
27         f = me.firstChild;
28         l = me.lastChild;
29
30         if(l)
31                 l.nextSibling = other;
32         else
33                 me.firstChild = other;
34
35         other.prevSibling = l;
36         other.nextSibling = NULL;
37         me.lastChild = other;
38 }
39
40 void removeAnimAnimHost(entity me, entity other)
41 {
42         if(other.parent != me)
43                 error("Can't remove from wrong AnimHost!");
44
45         other.parent = NULL;
46
47         entity n, p, f, l;
48         f = me.firstChild;
49         l = me.lastChild;
50         n = other.nextSibling;
51         p = other.prevSibling;
52
53         if(p)
54                 p.nextSibling = n;
55         else
56                 me.firstChild = n;
57
58         if(n)
59                 n.prevSibling = p;
60         else
61                 me.lastChild = p;
62 }
63
64 void stopAllAnimAnimHost(entity me)
65 {
66         entity e;
67         for(e = me.firstChild; e; e = e.nextSibling)
68         {
69                 e.stopAnim(e);
70         }
71 }
72
73 void finishAllAnimAnimHost(entity me)
74 {
75         entity e, tmp;
76         for(e = me.firstChild; e; e = e.nextSibling)
77         {
78                 tmp = e;
79                 e = tmp.prevSibling;
80                 me.removeAnim(me, tmp);
81                 e.finishAnim(tmp);
82         }
83 }
84
85 void tickAllAnimHost(entity me)
86 {
87         entity e, tmp;
88         for(e = me.firstChild; e; e = e.nextSibling)
89         {
90                 e.tick(e, time);
91         }
92         for(e = me.firstChild; e; e = e.nextSibling)
93         {
94                 if (e.isFinished(e))
95                 {
96                         tmp = e;
97                         e = tmp.prevSibling;
98                         me.removeAnim(me, tmp);
99                         remove(tmp);
100                 }
101         }
102 }
103 #endif