~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
7
* This program is free software; you can redistribute it and/or
 
8
* modify it under the terms of the GNU General Public License
 
9
* as published by the Free Software Foundation; either version 3
 
10
* of the License, or (at your option) any later version.
 
11
*
 
12
* This program is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
* GNU General Public License for more details.
 
16
* You should have received a copy of the GNU General Public License
 
17
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
******************************************************************************/
 
28
 
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
#include <math.h>
 
32
 
 
33
#include "applet-struct.h"
 
34
#include "applet-wave.h"
 
35
 
 
36
 
 
37
void cd_animations_init_wave (CDAnimationData *pData)
 
38
{
 
39
        pData->pCoords[0] = .5;
 
40
        pData->pCoords[1] = .5;
 
41
        
 
42
        pData->pVertices[0] = 0.;
 
43
        pData->pVertices[1] = 0.;
 
44
        pData->pVertices[2] = 0.;
 
45
        pData->fWavePosition = - myConfig.fWaveWidth / 2;
 
46
        
 
47
        pData->iNumActiveNodes = 6;
 
48
        pData->pVertices[3*1+0] = -.5;
 
49
        pData->pVertices[3*1+1] = -.5;
 
50
        pData->pVertices[3*2+0] = .5;
 
51
        pData->pVertices[3*2+1] = -.5;
 
52
        pData->pVertices[3*3+0] = .5;
 
53
        pData->pVertices[3*3+1] = .5;
 
54
        pData->pVertices[3*4+0] = -.5;
 
55
        pData->pVertices[3*4+1] = .5;
 
56
        pData->pVertices[3*5+0] = -.5;
 
57
        pData->pVertices[3*5+1] = -.5;
 
58
        pData->pCoords[2*1+0] = 0.;
 
59
        pData->pCoords[2*1+1] = 1.;
 
60
        pData->pCoords[2*2+0] = 1.;
 
61
        pData->pCoords[2*2+1] = 1.;
 
62
        pData->pCoords[2*3+0] = 1.;
 
63
        pData->pCoords[2*3+1] = 0.;
 
64
        pData->pCoords[2*4+0] = 0.;
 
65
        pData->pCoords[2*4+1] = 0.;
 
66
        pData->pCoords[2*5+0] = 0.;
 
67
        pData->pCoords[2*5+1] = 1.;
 
68
        pData->bIsWaving = TRUE;
 
69
}
 
70
 
 
71
 
 
72
gboolean cd_animations_update_wave (CDAnimationData *pData, double dt)
 
73
{
 
74
        GLfloat *pVertices = &pData->pVertices[3];
 
75
        GLfloat *pCoords = &pData->pCoords[2];
 
76
        double x, y, a, a_, x_;
 
77
        double p = pData->fWavePosition, w = myConfig.fWaveWidth;
 
78
        int n = (CD_WAVE_NB_POINTS - 1) / 2;  // nbre de points pour une demi-vague.
 
79
        int i, j=0, k;
 
80
        for (i = 0; i < CD_WAVE_NB_POINTS; i ++)
 
81
        {
 
82
                if (i == 0)
 
83
                {
 
84
                        if (p - w/2 < 0)
 
85
                        {
 
86
                                a_ = 1. * (i+1-n) / (n-1);
 
87
                                x_ = p + a_ * w/2;
 
88
                                if (x_ > 0)  // le point suivant est dedans.
 
89
                                {
 
90
                                        y = myConfig.fWaveAmplitude * cos (G_PI/2 * a + x / (w/2) * G_PI/2);
 
91
                                        x = 0.;
 
92
                                }
 
93
                                else
 
94
                                        continue ;
 
95
                        }
 
96
                        else
 
97
                        {
 
98
                                x = 0.;
 
99
                                y = 0.;
 
100
                        }
 
101
                }
 
102
                else if (i == CD_WAVE_NB_POINTS-1)
 
103
                {
 
104
                        if (p + w/2 > 1)
 
105
                        {
 
106
                                a_ = 1. * (i-1-n) / (n-1);
 
107
                                x_ = p + a_ * w/2;
 
108
                                if (x_ < 1)  // le point precedent est dedans.
 
109
                                {
 
110
                                        y = myConfig.fWaveAmplitude * cos (G_PI/2 * a - (x-1) / (w/2) * G_PI/2);
 
111
                                        x = 1.;
 
112
                                }
 
113
                                else
 
114
                                        continue;
 
115
                        }
 
116
                        else
 
117
                        {
 
118
                                x = 1.;
 
119
                                y = 0.;
 
120
                        }
 
121
                }
 
122
                else
 
123
                {
 
124
                        a = 1. * (i-n) / (n-1);
 
125
                        x = p + a * w/2;
 
126
                        if (x < 0)
 
127
                        {
 
128
                                a_ = 1. * (i+1-n) / (n-1);
 
129
                                x_ = p + a_ * w/2;
 
130
                                if (x_ > 0)  // le point suivant est dedans.
 
131
                                {
 
132
                                        y = myConfig.fWaveAmplitude * cos (G_PI/2 * a - x / (w/2) * G_PI/2);
 
133
                                        x = 0.;
 
134
                                }
 
135
                                else
 
136
                                        continue ;
 
137
                        }
 
138
                        else if (x > 1)
 
139
                        {
 
140
                                a_ = 1. * (i-1-n) / (n-1);
 
141
                                x_ = p + a_ * w/2;
 
142
                                if (x_ < 1)  // le point precedent est dedans.
 
143
                                {
 
144
                                        y = myConfig.fWaveAmplitude * cos (G_PI/2 * a - (x-1) / (w/2) * G_PI/2);
 
145
                                        x = 1.;
 
146
                                }
 
147
                                else
 
148
                                        continue;
 
149
                        }
 
150
                        else
 
151
                                y = myConfig.fWaveAmplitude * cos (G_PI/2 * a);
 
152
                }
 
153
                
 
154
                pCoords[2*j] = 0.;
 
155
                pCoords[2*j+1] = x;
 
156
                
 
157
                pVertices[3*j] = -.5 - y;
 
158
                pVertices[3*j+1] = .5 - x;
 
159
                pVertices[3*j+2] = 0.;
 
160
                
 
161
                j ++;
 
162
        }
 
163
        
 
164
        for (i = 0; i < j; i ++)
 
165
        {
 
166
                k = 2 * j - 1 - i;
 
167
                pCoords[2*k] = 1.;
 
168
                pCoords[2*k+1] = pCoords[2*i+1];
 
169
                
 
170
                pVertices[3*k] = - pVertices[3*i];
 
171
                pVertices[3*k+1] = pVertices[3*i+1];
 
172
                pVertices[3*k+2] = 0.;
 
173
        }
 
174
        
 
175
        // on boucle.
 
176
        j = 2 * j;
 
177
        pCoords[2*j] = pCoords[0];
 
178
        pCoords[2*j+1] = pCoords[1];
 
179
        
 
180
        pVertices[3*j] = pVertices[0];
 
181
        pVertices[3*j+1] = pVertices[1];
 
182
        pVertices[3*j+2] = 0.;
 
183
        
 
184
        pData->fWavePosition += dt / myConfig.iWaveDuration;
 
185
        pData->iNumActiveNodes = j + 2;
 
186
        return (pData->fWavePosition - w/2 < 1);
 
187
}
 
188
 
 
189
void cd_animations_draw_wave_icon (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData)
 
190
{
 
191
        glPushMatrix ();
 
192
        cairo_dock_set_icon_scale (pIcon, pDock, 1.);
 
193
        
 
194
        glColor4f (1., 1., 1., pIcon->fAlpha);
 
195
        glEnable(GL_BLEND);
 
196
        if (pIcon->fAlpha == 1)
 
197
                glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
198
        else
 
199
                _cairo_dock_set_blend_alpha ();
 
200
        
 
201
        glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
202
        
 
203
        glEnable(GL_TEXTURE_2D); // Je veux de la texture
 
204
        glBindTexture(GL_TEXTURE_2D, pIcon->iIconTexture);
 
205
        glPolygonMode(GL_FRONT, GL_FILL);
 
206
        
 
207
        glEnableClientState (GL_TEXTURE_COORD_ARRAY);
 
208
        glEnableClientState (GL_VERTEX_ARRAY);
 
209
        
 
210
        glTexCoordPointer (2, GL_FLOAT, 0, pData->pCoords);
 
211
        glVertexPointer (3, GL_FLOAT, 0, pData->pVertices);
 
212
 
 
213
        glDrawArrays (GL_TRIANGLE_FAN, 0, pData->iNumActiveNodes);
 
214
        
 
215
        glPopMatrix ();
 
216
        
 
217
        if (pDock->bUseReflect)
 
218
        {
 
219
                glPushMatrix ();
 
220
                double x0, y0, x1, y1;
 
221
                double fReflectRatio = myIcons.fReflectSize * pDock->fRatio / pIcon->fHeight / pIcon->fScale;
 
222
                double fOffsetY = pIcon->fHeight * pIcon->fScale/2 + (myIcons.fReflectSize/2 + pIcon->fDeltaYReflection) * pDock->fRatio;
 
223
                if (pDock->bHorizontalDock)
 
224
                {
 
225
                        if (pDock->bDirectionUp)
 
226
                        {
 
227
                                fOffsetY = pIcon->fHeight * pIcon->fScale + pIcon->fDeltaYReflection;
 
228
                                glTranslatef (0., - fOffsetY, 0.);
 
229
                                glScalef (pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, - pIcon->fHeight * pIcon->fScale, 1.);  // taille du reflet et on se retourne.
 
230
                                x0 = 0.;
 
231
                                y0 = 1. - fReflectRatio;
 
232
                                x1 = 1.;
 
233
                                y1 = 1.;
 
234
                        }
 
235
                        else
 
236
                        {
 
237
                                glTranslatef (0., fOffsetY, 0.);
 
238
                                glScalef (pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, myIcons.fReflectSize * pDock->fRatio, 1.);
 
239
                                x0 = 0.;
 
240
                                y0 = fReflectRatio;
 
241
                                x1 = 1.;
 
242
                                y1 = 0.;
 
243
                        }
 
244
                }
 
245
                else
 
246
                {
 
247
                        if (pDock->bDirectionUp)
 
248
                        {
 
249
                                glTranslatef (fOffsetY, 0., 0.);
 
250
                                glScalef (- myIcons.fReflectSize * pDock->fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.);
 
251
                                x0 = 1. - fReflectRatio;
 
252
                                y0 = 0.;
 
253
                                x1 = 1.;
 
254
                                y1 = 1.;
 
255
                        }
 
256
                        else
 
257
                        {
 
258
                                glTranslatef (- fOffsetY, 0., 0.);
 
259
                                glScalef (myIcons.fReflectSize * pDock->fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.);
 
260
                                x0 = fReflectRatio;
 
261
                                y0 = 0.;
 
262
                                x1 = 0.;
 
263
                                y1 = 1.;
 
264
                        }
 
265
                }
 
266
                //glEnableClientState(GL_COLOR_ARRAY);
 
267
                
 
268
                //glColorPointer(4, GL_FLOAT, 0, pData->pColors);
 
269
                //glDrawArrays (GL_TRIANGLE_FAN, 0, pData->iNumActiveNodes);
 
270
                
 
271
                //glDisableClientState(GL_COLOR_ARRAY);
 
272
                
 
273
                
 
274
                glActiveTexture(GL_TEXTURE0_ARB); // Go pour le multitexturing 1ere passe
 
275
                glEnable(GL_TEXTURE_2D); // On active le texturing sur cette passe
 
276
                glBindTexture(GL_TEXTURE_2D, pIcon->iIconTexture);
 
277
                
 
278
                glColor4f(1., 1., 1., myIcons.fAlbedo * pIcon->fAlpha);  // transparence du reflet.
 
279
                glEnable(GL_BLEND);
 
280
                glBlendFunc (1, 0);
 
281
                glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
282
                
 
283
                glActiveTexture(GL_TEXTURE1_ARB); // Go pour le texturing 2eme passe
 
284
                glEnable(GL_TEXTURE_2D);
 
285
                glBindTexture(GL_TEXTURE_2D, g_pGradationTexture[pDock->bHorizontalDock]);
 
286
                glColor4f(1., 1., 1., 1.);  // transparence du reflet.
 
287
                glEnable(GL_BLEND);
 
288
                glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
289
                glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // Le mode de combinaison des textures
 
290
                glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE);  // multiplier les alpha.
 
291
                /*glEnable(GL_TEXTURE_GEN_S);                                // generation texture en S
 
292
                glEnable(GL_TEXTURE_GEN_T);        // et en T
 
293
                glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); // la je veux un mapping tout ce qu'il y a de plus classique
 
294
                glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);*/
 
295
                glEnableClientState (GL_TEXTURE_COORD_ARRAY);
 
296
                glEnableClientState (GL_VERTEX_ARRAY);
 
297
                
 
298
        glTexCoordPointer (2, GL_FLOAT, 0, pData->pCoords);
 
299
        glVertexPointer (3, GL_FLOAT, 0, pData->pVertices);
 
300
                
 
301
                glDrawArrays (GL_TRIANGLE_FAN, 0, pData->iNumActiveNodes);
 
302
                
 
303
                glActiveTexture(GL_TEXTURE1_ARB);
 
304
                glDisable(GL_TEXTURE_2D);
 
305
                glDisableClientState (GL_TEXTURE_COORD_ARRAY);
 
306
                glDisableClientState (GL_VERTEX_ARRAY);
 
307
                glDisable(GL_TEXTURE_GEN_S);
 
308
                glDisable(GL_TEXTURE_GEN_T);
 
309
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
310
                glActiveTexture(GL_TEXTURE0_ARB);
 
311
                glDisable(GL_TEXTURE_2D);
 
312
                glDisable(GL_TEXTURE_GEN_S);
 
313
                glDisable(GL_TEXTURE_GEN_T);
 
314
                
 
315
                glPopMatrix ();
 
316
        }
 
317
        
 
318
        glDisableClientState (GL_TEXTURE_COORD_ARRAY);
 
319
        glDisableClientState (GL_VERTEX_ARRAY);
 
320
        glDisable (GL_TEXTURE_2D);
 
321
        glDisable (GL_BLEND);
 
322
}