~cairo-dock-team/ubuntu/quantal/cairo-dock-plug-ins/3.0.2

« back to all changes in this revision

Viewing changes to Animated-icons/src/applet-wave.c

Tags: upstream-2.2.0~0beta4
ImportĀ upstreamĀ versionĀ 2.2.0~0beta4

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "applet-struct.h"
25
25
#include "applet-wave.h"
26
26
 
 
27
static inline void _init_wave (GLfloat *pVertices, GLfloat *pCoords)
 
28
{
 
29
        // point bas gauche.
 
30
        pVertices[0] = -.5;
 
31
        pVertices[1] = -.5;
 
32
        pCoords[0] = 0.;
 
33
        pCoords[1] = 1.;
 
34
        
 
35
        // point bas droit.
 
36
        pVertices[2] = .5;
 
37
        pVertices[3] = -.5;
 
38
        pCoords[2] = 1.;
 
39
        pCoords[3] = 1.;
 
40
        
 
41
        // point haut gauche.
 
42
        pVertices[4] = -.5;
 
43
        pVertices[5] = .5;
 
44
        pCoords[4] = 0.;
 
45
        pCoords[5] = 0.;
 
46
        
 
47
        // point haut droit.
 
48
        pVertices[6] = .5;
 
49
        pVertices[7] = .5;
 
50
        pCoords[6] = 1;
 
51
        pCoords[7] = 0.;
 
52
}
27
53
 
28
54
void cd_animations_init_wave (CDAnimationData *pData)
29
55
{
30
 
        pData->pCoords[0] = .5;
31
 
        pData->pCoords[1] = .5;
32
 
        
33
 
        pData->pVertices[0] = 0.;
34
 
        pData->pVertices[1] = 0.;
35
 
        pData->pVertices[2] = 0.;
36
 
        pData->fWavePosition = - myConfig.fWaveWidth / 2;
37
 
        
38
 
        pData->iNumActiveNodes = 6;
39
 
        pData->pVertices[3*1+0] = -.5;
40
 
        pData->pVertices[3*1+1] = -.5;
41
 
        pData->pVertices[3*2+0] = .5;
42
 
        pData->pVertices[3*2+1] = -.5;
43
 
        pData->pVertices[3*3+0] = .5;
44
 
        pData->pVertices[3*3+1] = .5;
45
 
        pData->pVertices[3*4+0] = -.5;
46
 
        pData->pVertices[3*4+1] = .5;
47
 
        pData->pVertices[3*5+0] = -.5;
48
 
        pData->pVertices[3*5+1] = -.5;
49
 
        pData->pCoords[2*1+0] = 0.;
50
 
        pData->pCoords[2*1+1] = 1.;
51
 
        pData->pCoords[2*2+0] = 1.;
52
 
        pData->pCoords[2*2+1] = 1.;
53
 
        pData->pCoords[2*3+0] = 1.;
54
 
        pData->pCoords[2*3+1] = 0.;
55
 
        pData->pCoords[2*4+0] = 0.;
56
 
        pData->pCoords[2*4+1] = 0.;
57
 
        pData->pCoords[2*5+0] = 0.;
58
 
        pData->pCoords[2*5+1] = 1.;
 
56
        _init_wave (pData->pVertices, pData->pCoords);
 
57
        
 
58
        pData->iNumActiveNodes = 4;
 
59
        pData->fWavePosition = - myConfig.fWaveWidth / 2 + .01;  // on rajoute epsilon pour commencer avec 2 points.
59
60
        pData->bIsWaving = TRUE;
60
61
}
61
62
 
62
63
 
63
64
gboolean cd_animations_update_wave (CairoDock *pDock, CDAnimationData *pData, double dt)
64
65
{
65
 
        GLfloat *pVertices = &pData->pVertices[3];
66
 
        GLfloat *pCoords = &pData->pCoords[2];
67
 
        double x, y, a, a_, x_;
 
66
        GLfloat *pVertices = pData->pVertices;
 
67
        GLfloat *pCoords = pData->pCoords;
 
68
        
68
69
        double p = pData->fWavePosition, w = myConfig.fWaveWidth;
69
 
        int n = (CD_WAVE_NB_POINTS - 1) / 2;  // nbre de points pour une demi-vague.
70
 
        int i, j=0, k;
71
 
        for (i = 0; i < CD_WAVE_NB_POINTS; i ++)
72
 
        {
73
 
                if (i == 0)
74
 
                {
75
 
                        if (p - w/2 < 0)
76
 
                        {
77
 
                                a_ = 1. * (i+1-n) / (n-1);
78
 
                                x_ = p + a_ * w/2;
79
 
                                if (x_ > 0)  // le point suivant est dedans.
80
 
                                {
81
 
                                        y = myConfig.fWaveAmplitude * cos (G_PI/2 * a + x / (w/2) * G_PI/2);
82
 
                                        x = 0.;
83
 
                                }
84
 
                                else
85
 
                                        continue ;
86
 
                        }
87
 
                        else
88
 
                        {
89
 
                                x = 0.;
90
 
                                y = 0.;
91
 
                        }
92
 
                }
93
 
                else if (i == CD_WAVE_NB_POINTS-1)
94
 
                {
95
 
                        if (p + w/2 > 1)
96
 
                        {
97
 
                                a_ = 1. * (i-1-n) / (n-1);
98
 
                                x_ = p + a_ * w/2;
99
 
                                if (x_ < 1)  // le point precedent est dedans.
100
 
                                {
101
 
                                        y = myConfig.fWaveAmplitude * cos (G_PI/2 * a - (x-1) / (w/2) * G_PI/2);
102
 
                                        x = 1.;
103
 
                                }
104
 
                                else
105
 
                                        continue;
106
 
                        }
107
 
                        else
108
 
                        {
109
 
                                x = 1.;
110
 
                                y = 0.;
111
 
                        }
112
 
                }
113
 
                else
114
 
                {
115
 
                        a = 1. * (i-n) / (n-1);
116
 
                        x = p + a * w/2;
117
 
                        if (x < 0)
118
 
                        {
119
 
                                a_ = 1. * (i+1-n) / (n-1);
120
 
                                x_ = p + a_ * w/2;
121
 
                                if (x_ > 0)  // le point suivant est dedans.
122
 
                                {
123
 
                                        y = myConfig.fWaveAmplitude * cos (G_PI/2 * a - x / (w/2) * G_PI/2);
124
 
                                        x = 0.;
125
 
                                }
126
 
                                else
127
 
                                        continue ;
128
 
                        }
129
 
                        else if (x > 1)
130
 
                        {
131
 
                                a_ = 1. * (i-1-n) / (n-1);
132
 
                                x_ = p + a_ * w/2;
133
 
                                if (x_ < 1)  // le point precedent est dedans.
134
 
                                {
135
 
                                        y = myConfig.fWaveAmplitude * cos (G_PI/2 * a - (x-1) / (w/2) * G_PI/2);
136
 
                                        x = 1.;
137
 
                                }
138
 
                                else
139
 
                                        continue;
140
 
                        }
141
 
                        else
 
70
        if (p + w/2 < 0 || p - w/2 > 1)  // la vague est entierement en-dehors du cote.
 
71
        {
 
72
                _init_wave (pVertices, pCoords);  // on s'assure d'avoir au moins un carre.
 
73
                pData->iNumActiveNodes = 4;
 
74
        }
 
75
        else
 
76
        {
 
77
                int j = 0;  // nombre de points calcules.
 
78
                if (p - w/2 > 0)  // la vague n'englobe pas le point du bas.
 
79
                {
 
80
                        pVertices[0] = -.5;
 
81
                        pVertices[1] = -.5;
 
82
                        pCoords[0] = 0.;
 
83
                        pCoords[1] = 1.;
 
84
                        j ++;
 
85
                }
 
86
                
 
87
                double x, x_, y;  // position du point et du point precedent.
 
88
                double a, a_;  // position sur la vague dans [-1, 1].
 
89
                int n = CD_WAVE_NB_POINTS / 2;  // nbre de points pour une demi-vague (N est impair).
 
90
                int i;
 
91
                for (i = 0; i < CD_WAVE_NB_POINTS; i ++)  // on discretise la vague.
 
92
                {
 
93
                        a = 1. * (i-n) / (n);  // position courante sur la vague, dans [-1, 1].
 
94
                        x = p + a * w/2;  // abscisse correspondante.
 
95
                        
 
96
                        a = 1. * (i-n) / n;  // position courante sur la vague, dans [-1, 1].
 
97
                        x = p + a * w/2;  // abscisse correspondante.
 
98
                        if (x < 0)  // le point sort par le bas.
 
99
                        {
 
100
                                a_ = 1. * (i+1-n) / n;
 
101
                                x_ = p + a_ * w/2;
 
102
                                if (x_ > 0)  // le point suivant est dedans.
 
103
                                {
 
104
                                        y = myConfig.fWaveAmplitude * cos (G_PI/2 * a - x / (w/2) * G_PI/2);  // on depasse de x, donc on dephase d'autant.
 
105
                                        x = 0.;  // coin de la texture.
 
106
                                }
 
107
                                else  // tout le segment est dehors, on zappe.
 
108
                                        continue ;
 
109
                        }
 
110
                        else if (x > 1)  // le point sort par le haut.
 
111
                        {
 
112
                                a_ = 1. * (i-1-n) / n;
 
113
                                x_ = p + a_ * w/2;
 
114
                                if (x_ < 1)  // le point precedent est dedans.
 
115
                                {
 
116
                                        y = myConfig.fWaveAmplitude * cos (G_PI/2 * a - (x-1) / (w/2) * G_PI/2);  // on depasse de x-1, donc on dephase d'autant.
 
117
                                        x = 1.;  // coin de la texture.
 
118
                                }
 
119
                                else  // tout le segment est dehors, on zappe.
 
120
                                        continue;
 
121
                        }
 
122
                        else  // le point est dans l'icone.
142
123
                                y = myConfig.fWaveAmplitude * cos (G_PI/2 * a);
143
 
                }
144
 
                
145
 
                pCoords[2*j] = 0.;
146
 
                pCoords[2*j+1] = x;
147
 
                
148
 
                pVertices[3*j] = -.5 - y;
149
 
                pVertices[3*j+1] = .5 - x;
150
 
                pVertices[3*j+2] = 0.;
151
 
                
152
 
                j ++;
153
 
        }
154
 
        
155
 
        for (i = 0; i < j; i ++)
156
 
        {
157
 
                k = 2 * j - 1 - i;
158
 
                pCoords[2*k] = 1.;
159
 
                pCoords[2*k+1] = pCoords[2*i+1];
160
 
                
161
 
                pVertices[3*k] = - pVertices[3*i];
162
 
                pVertices[3*k+1] = pVertices[3*i+1];
163
 
                pVertices[3*k+2] = 0.;
164
 
        }
165
 
        
166
 
        // on boucle.
167
 
        j = 2 * j;
168
 
        pCoords[2*j] = pCoords[0];
169
 
        pCoords[2*j+1] = pCoords[1];
170
 
        
171
 
        pVertices[3*j] = pVertices[0];
172
 
        pVertices[3*j+1] = pVertices[1];
173
 
        pVertices[3*j+2] = 0.;
 
124
                        
 
125
                        pVertices[4*j] = -.5 - y;
 
126
                        pVertices[4*j+1] = x - .5;
 
127
                        pCoords[4*j] = 0.;
 
128
                        pCoords[4*j+1] = 1. - x;
 
129
                        j ++;
 
130
                }
 
131
                
 
132
                if (p + w/2 < 1)  // la vague n'englobe pas le point du haut.
 
133
                {
 
134
                        pVertices[4*j] = -.5;
 
135
                        pVertices[4*j+1] = .5;
 
136
                        pCoords[4*j] = 0.;
 
137
                        pCoords[4*j+1] = 0.;
 
138
                        j ++;
 
139
                }
 
140
                
 
141
                for (i = 0; i < j; i ++)  // on complete l'autre cote symetriquement.
 
142
                {
 
143
                        pVertices[4*i+2] = - pVertices[4*i];
 
144
                        pVertices[4*i+3] = pVertices[4*i+1];
 
145
                        pCoords[4*i+2] = 1.;
 
146
                        pCoords[4*i+3] = pCoords[4*i+1];
 
147
                }
 
148
                pData->iNumActiveNodes = 2*j;
 
149
        }
174
150
        
175
151
        pData->fWavePosition += dt / myConfig.iWaveDuration;
176
 
        pData->iNumActiveNodes = j + 2;
177
152
        
178
153
        cairo_dock_redraw_container (CAIRO_CONTAINER (pDock));
179
154
        return (pData->fWavePosition - w/2 < 1);
182
157
void cd_animations_draw_wave_icon (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData)
183
158
{
184
159
        glPushMatrix ();
185
 
        cairo_dock_set_icon_scale (pIcon, pDock, 1.);
 
160
        cairo_dock_set_icon_scale (pIcon, CAIRO_CONTAINER (pDock), 1.);
186
161
        
187
162
        glColor4f (1., 1., 1., pIcon->fAlpha);
188
163
        glEnable(GL_BLEND);
201
176
        glEnableClientState (GL_VERTEX_ARRAY);
202
177
        
203
178
        glTexCoordPointer (2, GL_FLOAT, 0, pData->pCoords);
204
 
        glVertexPointer (3, GL_FLOAT, 0, pData->pVertices);
 
179
        glVertexPointer (2, GL_FLOAT, 0, pData->pVertices);
205
180
 
206
 
        glDrawArrays (GL_TRIANGLE_FAN, 0, pData->iNumActiveNodes);
 
181
        glDrawArrays (GL_QUAD_STRIP, 0, pData->iNumActiveNodes);
207
182
        
208
183
        glPopMatrix ();
209
184
        
256
231
                                y1 = 1.;
257
232
                        }
258
233
                }
259
 
                //glEnableClientState(GL_COLOR_ARRAY);
260
 
                
261
 
                //glColorPointer(4, GL_FLOAT, 0, pData->pColors);
262
 
                //glDrawArrays (GL_TRIANGLE_FAN, 0, pData->iNumActiveNodes);
263
 
                
264
 
                //glDisableClientState(GL_COLOR_ARRAY);
265
 
                
266
234
                
267
235
                glActiveTexture(GL_TEXTURE0_ARB); // Go pour le multitexturing 1ere passe
268
236
                glEnable(GL_TEXTURE_2D); // On active le texturing sur cette passe
288
256
                glEnableClientState (GL_TEXTURE_COORD_ARRAY);
289
257
                glEnableClientState (GL_VERTEX_ARRAY);
290
258
                
291
 
        glTexCoordPointer (2, GL_FLOAT, 0, pData->pCoords);
292
 
        glVertexPointer (3, GL_FLOAT, 0, pData->pVertices);
 
259
                glTexCoordPointer (2, GL_FLOAT, 0, pData->pCoords);
 
260
                glVertexPointer (2, GL_FLOAT, 0, pData->pVertices);
293
261
                
294
 
                glDrawArrays (GL_TRIANGLE_FAN, 0, pData->iNumActiveNodes);
 
262
                glDrawArrays (GL_QUAD_STRIP, 0, pData->iNumActiveNodes);
295
263
                
296
264
                glActiveTexture(GL_TEXTURE1_ARB);
297
265
                glDisable(GL_TEXTURE_2D);