2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
20
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
27
******************************************************************************/
33
#include "applet-struct.h"
34
#include "applet-storm.h"
36
static double ar = .1; // variation du rayon des particules.
37
static double ad = .5; // dispersion.
38
static double at = .6; // transparence initiale des particules.
39
static double n = 2; // nbre de tours.
41
CairoParticleSystem *cd_icon_effect_init_storm (Icon *pIcon, CairoDock *pDock, double dt)
43
if (myData.iFireTexture == 0)
44
myData.iFireTexture = cd_icon_effect_load_storm_texture ();
45
double fMaxScale = (pDock->bAtBottom ? 1. : cairo_dock_get_max_scale (CAIRO_CONTAINER (pDock)));
46
CairoParticleSystem *pStormParticleSystem = cairo_dock_create_particle_system (myConfig.iNbStormParticles, myData.iFireTexture, pIcon->fWidth * pIcon->fScale, pIcon->fHeight * fMaxScale);
47
g_return_val_if_fail (pStormParticleSystem != NULL, NULL);
48
pStormParticleSystem->dt = dt;
49
if (myConfig.bRotateEffects && ! pDock->bDirectionUp && pDock->bHorizontalDock)
50
pStormParticleSystem->bDirectionUp = FALSE;
52
static double epsilon = 0.1;
53
double r = myConfig.iStormParticleSize;
54
double vmax = 1. / myConfig.iStormDuration * 2;
58
for (i = 0; i < myConfig.iNbStormParticles; i ++)
60
p = &pStormParticleSystem->pParticles[i];
62
p->x = 0.; // on le calculera a la main.
63
p->y = -1. * i /myConfig.iNbStormParticles + .01 * (2 * g_random_double () - 1);
65
p->fWidth = r * (1 + ar * (2 * g_random_double () - 1));
66
p->fHeight = p->fWidth;
68
p->vx = ad * (2 * g_random_double () - 1); // utilisation detournee : dispersion.
69
p->vy = vmax * (1 - ad * g_random_double ()) * dt * 2;
71
p->iInitialLife = MIN ((1 - p->y) / p->vy, ceil (myConfig.iStormDuration/2 / dt));
72
p->iLife = p->iInitialLife;
74
fBlend = g_random_double ();
75
p->color[0] = fBlend * myConfig.pStormColor1[0] + (1 - fBlend) * myConfig.pStormColor2[0];
76
p->color[1] = fBlend * myConfig.pStormColor1[1] + (1 - fBlend) * myConfig.pStormColor2[1];
77
p->color[2] = fBlend * myConfig.pStormColor1[2] + (1 - fBlend) * myConfig.pStormColor2[2];
78
p->color[3] = (p->y < 0 ? 0. : at);
84
p->fResizeSpeed = 0.; // zoom constant.
87
return pStormParticleSystem;
90
gboolean cd_icon_effect_update_storm_system (CairoParticleSystem *pParticleSystem, CairoDockRewindParticleFunc pRewindParticle)
92
gboolean bAllParticlesEnded = TRUE;
96
for (i = 0; i < pParticleSystem->iNbParticles; i ++)
98
p = &(pParticleSystem->pParticles[i]);
101
p->x = (1 + p->vx) * sin (p->y * 2 * n * G_PI); // n tours.
102
p->z = (1 + p->vx) * cos (p->y * 2 * n * G_PI);
103
p->fSizeFactor = 1 - (1 - p->z)/2. * .33; // 33% de variation.
104
//p->color[3] = sqrt (MAX (0, p->y));
105
p->color[3] = (p->y < 0 ? 0. : at * (0.1 + 1.*p->iLife / p->iInitialLife) / 1.1); // on finit a 0.1 en haut, sinon on voit pas bien la derniere boucle.
107
if (p->iLife > 0) // p->y > 1
110
if (pRewindParticle && p->iLife == 0)
112
pRewindParticle (p, pParticleSystem->dt);
114
if (bAllParticlesEnded && p->iLife != 0)
115
bAllParticlesEnded = FALSE;
118
return ! bAllParticlesEnded;
121
void cd_icon_effect_rewind_storm_particle (CairoParticle *p, double dt)
124
p->y = .03 * (2 * g_random_double () - 1);
128
p->iInitialLife = MIN (1. / p->vy, ceil (myConfig.iStormDuration/2 / dt));
129
p->iLife = p->iInitialLife;