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-fire.h"
37
CairoParticleSystem *cd_icon_effect_init_fire (Icon *pIcon, CairoDock *pDock, double dt)
39
if (myData.iFireTexture == 0)
40
myData.iFireTexture = cd_icon_effect_load_fire_texture ();
41
double fMaxScale = (pDock->bAtBottom ? 1. : 1. + g_fAmplitude * pDock->fMagnitudeMax);
42
CairoParticleSystem *pFireParticleSystem = cairo_dock_create_particle_system (myConfig.iNbFireParticles, myData.iFireTexture, pIcon->fWidth * pIcon->fScale, pIcon->fHeight * fMaxScale);
43
g_return_val_if_fail (pFireParticleSystem != NULL, NULL);
44
pFireParticleSystem->dt = dt;
45
if (myConfig.bRotateEffects && ! pDock->bDirectionUp && pDock->bHorizontalDock)
46
pFireParticleSystem->bDirectionUp = FALSE;
47
pFireParticleSystem->bAddLuminance = myConfig.bFireLuminance;
49
double a = myConfig.fFireParticleSpeed;
50
static double epsilon = 0.1;
51
double r = myConfig.iFireParticleSize;
53
double vmax = 1. / myConfig.iFireDuration;
56
for (i = 0; i < myConfig.iNbFireParticles; i ++)
58
p = &(pFireParticleSystem->pParticles[i]);
60
p->x = 2 * g_random_double () - 1;
61
p->x = p->x * p->x * (p->x > 0 ? 1 : -1);
63
p->z = 2 * g_random_double () - 1;
64
p->fWidth = r*(p->z + 2)/3 * .5 * pDock->fRatio;
65
p->fHeight = p->fWidth;
68
p->vy = a * vmax * ((p->z + 1)/2 * 1. + epsilon) * dt;
69
p->iInitialLife = MIN (1./ p->vy, ceil (myConfig.iFireDuration / dt));
70
p->iLife = p->iInitialLife * (.8+.3*g_random_double ()); // dispersion entre .8 et 1.1
72
if (myConfig.bMysticalFire)
74
p->color[0] = g_random_double ();
75
p->color[1] = g_random_double ();
76
p->color[2] = g_random_double ();
80
fBlend = g_random_double ();
81
p->color[0] = fBlend * myConfig.pFireColor1[0] + (1 - fBlend) * myConfig.pFireColor2[0];
82
p->color[1] = fBlend * myConfig.pFireColor1[1] + (1 - fBlend) * myConfig.pFireColor2[1];
83
p->color[2] = fBlend * myConfig.pFireColor1[2] + (1 - fBlend) * myConfig.pFireColor2[2];
87
p->fOscillation = G_PI * (2 * g_random_double () - 1);
88
p->fOmega = 2*G_PI / myConfig.iFireDuration * dt; // tr/s
91
p->fResizeSpeed = -.5 / myConfig.iFireDuration * dt; // zoom 0.5 a la fin.
94
return pFireParticleSystem;
98
gboolean cd_icon_effect_update_fire_system (CairoParticleSystem *pParticleSystem, CairoDockRewindParticleFunc pRewindParticle)
100
gboolean bAllParticlesEnded = TRUE;
103
for (i = 0; i < pParticleSystem->iNbParticles; i ++)
105
p = &(pParticleSystem->pParticles[i]);
107
p->fOscillation += p->fOmega;
108
p->x += p->vx + (p->z + 2)/3. * .02 * sin (p->fOscillation); // 3%
110
p->color[3] = .8*p->iLife / p->iInitialLife;
111
p->fSizeFactor += p->fResizeSpeed;
115
if (pRewindParticle && p->iLife == 0)
117
pRewindParticle (p, pParticleSystem->dt);
119
if (bAllParticlesEnded && p->iLife != 0)
120
bAllParticlesEnded = FALSE;
122
else if (pRewindParticle)
123
pRewindParticle (p, pParticleSystem->dt);
125
return ! bAllParticlesEnded;
128
void cd_icon_effect_rewind_fire_particle (CairoParticle *p, double dt)
130
static double epsilon = 0.1;
131
double a = myConfig.fFireParticleSpeed/myConfig.fFireParticleSpeed;
132
double r = myConfig.iFireParticleSize;
133
double vmax = 1. / myConfig.iFireDuration;
134
p->x = 2 * g_random_double () - 1;
135
p->x = p->x * p->x * (p->x > 0 ? 1 : -1);
137
p->z = 2 * g_random_double () - 1;
138
p->fWidth = r*(p->z + 2)/3 * .5;
139
p->fHeight = p->fWidth;
140
p->vy = a * vmax * ((p->z + 1)/2 * 1. + epsilon) * dt;
142
p->iInitialLife = MIN (1./ p->vy, ceil (myConfig.iFireDuration / dt));
143
p->iLife = p->iInitialLife * (.9+.2*g_random_double ()); // dispersion entre .9 et 1.1