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

« back to all changes in this revision

Viewing changes to illusion/src/applet-evaporate.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-evaporate.h"
 
35
 
 
36
 
 
37
gboolean cd_illusion_init_evaporate (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
 
38
{
 
39
        if (myData.iEvaporateTexture == 0)
 
40
                myData.iEvaporateTexture = cd_illusion_load_evaporate_texture ();
 
41
        double fMaxScale = (pDock->bAtBottom ? 1. : cairo_dock_get_max_scale (CAIRO_CONTAINER (pDock)));
 
42
        CairoParticleSystem *pEvaporateParticleSystem = cairo_dock_create_particle_system (myConfig.iNbEvaporateParticles, myData.iEvaporateTexture, pIcon->fWidth * pIcon->fScale, pIcon->fHeight * fMaxScale);
 
43
        g_return_val_if_fail (pEvaporateParticleSystem != NULL, FALSE);
 
44
        double dt = pData->fDeltaT;
 
45
        pEvaporateParticleSystem->dt = dt;
 
46
        pEvaporateParticleSystem->bAddLuminance = TRUE;
 
47
        pData->pEvaporateSystem = pEvaporateParticleSystem;
 
48
        
 
49
        double a = myConfig.fEvaporateParticleSpeed;
 
50
        static double epsilon = 0.1;
 
51
        double r = myConfig.iEvaporateParticleSize;
 
52
        double fBlend;
 
53
        double vmax = 1. / myConfig.iEvaporateDuration;
 
54
        CairoParticle *p;
 
55
        int i;
 
56
        for (i = 0; i < myConfig.iNbEvaporateParticles; i ++)
 
57
        {
 
58
                p = &(pEvaporateParticleSystem->pParticles[i]);
 
59
                
 
60
                p->x = 2 * g_random_double () - 1;
 
61
                p->x = p->x * p->x * (p->x > 0 ? 1 : -1);
 
62
                p->y = (myConfig.bEvaporateFromBottom ? 0. : 1.);
 
63
                p->z = 2 * g_random_double () - 1;
 
64
                p->fWidth = r*(p->z + 2)/3 * g_random_double ();
 
65
                p->fHeight = p->fWidth;
 
66
                
 
67
                p->vx = 0.;
 
68
                p->vy = a * vmax * ((p->z + 1)/2 + epsilon) * dt;
 
69
                p->iInitialLife = myConfig.iEvaporateDuration / dt;
 
70
                if (a > 1)
 
71
                        p->iInitialLife = MIN (p->iInitialLife, 1. / p->vy);
 
72
                else
 
73
                        p->iInitialLife = 8;
 
74
                p->iInitialLife *= g_random_double ();
 
75
                p->iLife = p->iInitialLife;
 
76
                
 
77
                if (myConfig.bMysticalEvaporate)
 
78
                {
 
79
                        p->color[0] = g_random_double ();
 
80
                        p->color[1] = g_random_double ();
 
81
                        p->color[2] = g_random_double ();
 
82
                }
 
83
                else
 
84
                {
 
85
                        fBlend = g_random_double ();
 
86
                        p->color[0] = fBlend * myConfig.pEvaporateColor1[0] + (1 - fBlend) * myConfig.pEvaporateColor2[0];
 
87
                        p->color[1] = fBlend * myConfig.pEvaporateColor1[1] + (1 - fBlend) * myConfig.pEvaporateColor2[1];
 
88
                        p->color[2] = fBlend * myConfig.pEvaporateColor1[2] + (1 - fBlend) * myConfig.pEvaporateColor2[2];
 
89
                }
 
90
                p->color[3] = 1.;
 
91
                
 
92
                p->fOscillation = G_PI * (2 * g_random_double () - 1);
 
93
                p->fOmega = 2*G_PI / myConfig.iEvaporateDuration * dt;  // tr/s
 
94
                
 
95
                p->fSizeFactor = 1.;
 
96
                p->fResizeSpeed = -.5 / myConfig.iEvaporateDuration * dt;  // zoom 0.5 a la fin.
 
97
        }
 
98
        
 
99
        return TRUE;
 
100
}
 
101
 
 
102
 
 
103
 
 
104
static void _cd_illusion_rewind_evaporate_particle (CairoParticle *p, CDIllusionData *pData, double dt)
 
105
{
 
106
        static double epsilon = 0.1;
 
107
        double a = myConfig.fEvaporateParticleSpeed;
 
108
        double r = myConfig.iEvaporateParticleSize;
 
109
        double vmax = 1. / myConfig.iEvaporateDuration;
 
110
        p->x = 2 * g_random_double () - 1;
 
111
        p->x = p->x * p->x * (p->x > 0 ? 1 : -1);
 
112
        p->y = (myConfig.bEvaporateFromBottom ? pData->fEvaporatePercent : 1 - pData->fEvaporatePercent);
 
113
        p->fWidth = r*(p->z + 2)/3 * g_random_double ();
 
114
        p->fHeight = p->fWidth;
 
115
        p->vy = a * vmax * ((p->z + 1)/2 * g_random_double () + epsilon) * dt;
 
116
        
 
117
        p->iInitialLife = myConfig.iEvaporateDuration / dt;
 
118
        if (a > 1)
 
119
                p->iInitialLife = MIN (p->iInitialLife, 1. / p->vy);
 
120
        else
 
121
                p->iInitialLife = 8;
 
122
        p->iInitialLife *= g_random_double ();
 
123
        p->iLife = p->iInitialLife;
 
124
        
 
125
        p->fSizeFactor = 1.;
 
126
}
 
127
static void cd_illusion_update_evaporate_system (CairoParticleSystem *pParticleSystem, CDIllusionData *pData)
 
128
{
 
129
        CairoParticle *p;
 
130
        int i;
 
131
        for (i = 0; i < pParticleSystem->iNbParticles; i ++)
 
132
        {
 
133
                p = &(pParticleSystem->pParticles[i]);
 
134
                
 
135
                p->fOscillation += p->fOmega;
 
136
                p->x += p->vx + (p->z + 2)/3. * .02 * sin (p->fOscillation);  // 3%
 
137
                p->y += p->vy;
 
138
                p->color[3] = 1.*p->iLife / p->iInitialLife;
 
139
                p->fSizeFactor += p->fResizeSpeed;
 
140
                if (p->iLife > 0)
 
141
                {
 
142
                        p->iLife --;
 
143
                        if (p->iLife == 0)
 
144
                        {
 
145
                                _cd_illusion_rewind_evaporate_particle (p, pData, pParticleSystem->dt);
 
146
                        }
 
147
                }
 
148
                else
 
149
                        _cd_illusion_rewind_evaporate_particle (p, pData, pParticleSystem->dt);
 
150
        }
 
151
}
 
152
 
 
153
void cd_illusion_update_evaporate (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
 
154
{
 
155
        pData->fEvaporatePercent = pData->fTime / myConfig.iEvaporateDuration;
 
156
        
 
157
        cd_illusion_update_evaporate_system (pData->pEvaporateSystem, pData);
 
158
        pData->pEvaporateSystem->fHeight = pIcon->fHeight * pIcon->fScale;
 
159
        pData->pEvaporateSystem->fWidth = pIcon->fWidth * pIcon->fScale;
 
160
        
 
161
        cairo_dock_redraw_icon (pIcon, pDock);
 
162
}
 
163
 
 
164
void cd_illusion_draw_evaporate_icon (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
 
165
{
 
166
        glPushMatrix ();
 
167
        cairo_dock_set_icon_scale (pIcon, pDock, 1.);
 
168
        
 
169
        _cairo_dock_enable_texture ();
 
170
        _cairo_dock_set_alpha (pIcon->fAlpha);
 
171
        _cairo_dock_set_blend_over ();
 
172
        
 
173
        glBindTexture(GL_TEXTURE_2D, pIcon->iIconTexture);
 
174
        
 
175
        glNormal3f(0,0,1);
 
176
        glBegin(GL_QUADS);
 
177
        if (myConfig.bEvaporateFromBottom)
 
178
        {
 
179
                glTexCoord2f(0., 0.); glVertex3f(-.5,  .5, 0.);  // Bottom Left Of The Texture and Quad
 
180
                glTexCoord2f(1., 0.); glVertex3f( .5,  .5, 0.);  // Bottom Right Of The Texture and Quad
 
181
                glTexCoord2f(1., 1 - pData->fEvaporatePercent); glVertex3f( .5, -.5 + pData->fEvaporatePercent, 0.);  // Top Right Of The Texture and Quad
 
182
                glTexCoord2f(0., 1 - pData->fEvaporatePercent); glVertex3f(-.5, -.5 + pData->fEvaporatePercent, 0.);  // Top Left Of The Texture and Quad
 
183
        }
 
184
        else
 
185
        {
 
186
                glTexCoord2f(0., pData->fEvaporatePercent); glVertex3f(-.5,  .5 - pData->fEvaporatePercent, 0.);  // Bottom Left Of The Texture and Quad
 
187
                glTexCoord2f(1., pData->fEvaporatePercent); glVertex3f( .5,  .5 - pData->fEvaporatePercent, 0.);  // Bottom Right Of The Texture and Quad
 
188
                glTexCoord2f(1., 1.); glVertex3f( .5, -.5, 0.);  // Top Right Of The Texture and Quad
 
189
                glTexCoord2f(0., 1.); glVertex3f(-.5, -.5, 0.);  // Top Left Of The Texture and Quad
 
190
        }
 
191
        glEnd();
 
192
        
 
193
        glPopMatrix ();
 
194
        
 
195
        /*if (pDock->bUseReflect)
 
196
        {
 
197
                glPushMatrix ();
 
198
                double x0, y0, x1, y1;
 
199
                double fReflectRatio = myIcons.fReflectSize * pDock->fRatio / pIcon->fHeight / pIcon->fScale;
 
200
                double fOffsetY = pIcon->fHeight * pIcon->fScale/2 + (myIcons.fReflectSize/2 + pIcon->fDeltaYReflection) * pDock->fRatio;
 
201
                if (pDock->bHorizontalDock)
 
202
                {
 
203
                        if (pDock->bDirectionUp)
 
204
                        {
 
205
                                fOffsetY = pIcon->fHeight * pIcon->fScale + pIcon->fDeltaYReflection;
 
206
                                glTranslatef (0., - fOffsetY, 0.);
 
207
                                glScalef (pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, - pIcon->fHeight * pIcon->fScale, 1.);  // taille du reflet et on se retourne.
 
208
                                x0 = 0.;
 
209
                                y0 = 1. - fReflectRatio;
 
210
                                x1 = 1.;
 
211
                                y1 = 1.;
 
212
                        }
 
213
                        else
 
214
                        {
 
215
                                glTranslatef (0., fOffsetY, 0.);
 
216
                                glScalef (pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, myIcons.fReflectSize * pDock->fRatio, 1.);
 
217
                                x0 = 0.;
 
218
                                y0 = fReflectRatio;
 
219
                                x1 = 1.;
 
220
                                y1 = 0.;
 
221
                        }
 
222
                }
 
223
                else
 
224
                {
 
225
                        if (pDock->bDirectionUp)
 
226
                        {
 
227
                                glTranslatef (fOffsetY, 0., 0.);
 
228
                                glScalef (- myIcons.fReflectSize * pDock->fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.);
 
229
                                x0 = 1. - fReflectRatio;
 
230
                                y0 = 0.;
 
231
                                x1 = 1.;
 
232
                                y1 = 1.;
 
233
                        }
 
234
                        else
 
235
                        {
 
236
                                glTranslatef (- fOffsetY, 0., 0.);
 
237
                                glScalef (myIcons.fReflectSize * pDock->fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.);
 
238
                                x0 = fReflectRatio;
 
239
                                y0 = 0.;
 
240
                                x1 = 0.;
 
241
                                y1 = 1.;
 
242
                        }
 
243
                }
 
244
                //glEnableClientState(GL_COLOR_ARRAY);
 
245
                
 
246
                //glColorPointer(4, GL_FLOAT, 0, pData->pColors);
 
247
                //glDrawArrays (GL_TRIANGLE_FAN, 0, pData->iNumActiveNodes);
 
248
                
 
249
                //glDisableClientState(GL_COLOR_ARRAY);
 
250
                
 
251
                
 
252
                glActiveTexture(GL_TEXTURE0_ARB); // Go pour le multitexturing 1ere passe
 
253
                glEnable(GL_TEXTURE_2D); // On active le texturing sur cette passe
 
254
                glBindTexture(GL_TEXTURE_2D, pIcon->iIconTexture);
 
255
                
 
256
                glColor4f(1., 1., 1., myIcons.fAlbedo * pIcon->fAlpha);  // transparence du reflet.
 
257
                glEnable(GL_BLEND);
 
258
                glBlendFunc (1, 0);
 
259
                glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
260
                
 
261
                glActiveTexture(GL_TEXTURE1_ARB); // Go pour le texturing 2eme passe
 
262
                glEnable(GL_TEXTURE_2D);
 
263
                glBindTexture(GL_TEXTURE_2D, g_pGradationTexture[pDock->bHorizontalDock]);
 
264
                glColor4f(1., 1., 1., 1.);  // transparence du reflet.
 
265
                glEnable(GL_BLEND);
 
266
                glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
267
                glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // Le mode de combinaison des textures
 
268
                glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE);  // multiplier les alpha.
 
269
                glEnableClientState (GL_TEXTURE_COORD_ARRAY);
 
270
                glEnableClientState (GL_VERTEX_ARRAY);
 
271
                
 
272
        glTexCoordPointer (2, GL_FLOAT, 0, pData->pCoords);
 
273
        glVertexPointer (3, GL_FLOAT, 0, pData->pVertices);
 
274
                
 
275
                glDrawArrays (GL_TRIANGLE_FAN, 0, pData->iNumActiveNodes);
 
276
                
 
277
                glActiveTexture(GL_TEXTURE1_ARB);
 
278
                glDisable(GL_TEXTURE_2D);
 
279
                glDisableClientState (GL_TEXTURE_COORD_ARRAY);
 
280
                glDisableClientState (GL_VERTEX_ARRAY);
 
281
                glDisable(GL_TEXTURE_GEN_S);
 
282
                glDisable(GL_TEXTURE_GEN_T);
 
283
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
284
                glActiveTexture(GL_TEXTURE0_ARB);
 
285
                glDisable(GL_TEXTURE_2D);
 
286
                glDisable(GL_TEXTURE_GEN_S);
 
287
                glDisable(GL_TEXTURE_GEN_T);
 
288
                
 
289
                glPopMatrix ();
 
290
        }*/
 
291
        
 
292
        _cairo_dock_disable_texture ();
 
293
        
 
294
        if (pData->fEvaporatePercent < 1 && pData->fEvaporatePercent > 0)
 
295
        {
 
296
                glPushMatrix ();
 
297
                glTranslatef (0., - pIcon->fHeight * pIcon->fScale/2, 0.);
 
298
                cairo_dock_render_particles (pData->pEvaporateSystem);
 
299
                glPopMatrix ();
 
300
        }
 
301
}