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-star.h"
37
CairoParticleSystem *cd_icon_effect_init_stars (Icon *pIcon, CairoDock *pDock, double dt)
39
if (myData.iStarTexture == 0)
40
myData.iStarTexture = cd_icon_effect_load_star_texture ();
41
double fMaxScale = (pDock->bAtBottom ? 1. : cairo_dock_get_max_scale (CAIRO_CONTAINER (pDock)));
42
CairoParticleSystem *pStarParticleSystem = cairo_dock_create_particle_system (myConfig.iNbStarParticles, myData.iStarTexture, pIcon->fWidth * pIcon->fScale, pIcon->fHeight * fMaxScale);
43
g_return_val_if_fail (pStarParticleSystem != NULL, NULL);
44
pStarParticleSystem->dt = dt;
45
pStarParticleSystem->bAddLuminance = TRUE;
48
static double epsilon = 0.1;
49
double r = myConfig.iStarParticleSize;
53
for (i = 0; i < myConfig.iNbStarParticles; i ++)
55
p = &pStarParticleSystem->pParticles[i];
57
p->x = 2 * g_random_double () - 1;
58
p->y = g_random_double ();
59
p->z = 2 * g_random_double () - 1;
60
p->fWidth = r*(p->z + 1)/2 * g_random_double ();
61
p->fHeight = p->fWidth;
66
p->iInitialLife = myConfig.iStarDuration / dt;
67
p->iLife = p->iInitialLife * (g_random_double () + a) / (1 + a);
69
if (myConfig.bMysticalStars)
71
p->color[0] = g_random_double ();
72
p->color[1] = g_random_double ();
73
p->color[2] = g_random_double ();
77
fBlend = g_random_double ();
78
p->color[0] = fBlend * myConfig.pStarColor1[0] + (1 - fBlend) * myConfig.pStarColor2[0];
79
p->color[1] = fBlend * myConfig.pStarColor1[1] + (1 - fBlend) * myConfig.pStarColor2[1];
80
p->color[2] = fBlend * myConfig.pStarColor1[2] + (1 - fBlend) * myConfig.pStarColor2[2];
82
p->color[3] = 0.; // on va gerer nous-mêmes la transparence.
88
p->fResizeSpeed = - 1. / myConfig.iStarDuration * dt; // zoom 0 a la fin.
91
return pStarParticleSystem;
94
gboolean cd_icon_effect_update_star_system (CairoParticleSystem *pParticleSystem, CairoDockRewindParticleFunc pRewindParticle)
97
gboolean bAllParticlesEnded = TRUE;
101
for (i = 0; i < pParticleSystem->iNbParticles; i ++)
103
p = &(pParticleSystem->pParticles[i]);
105
if (p->iLife > a * p->iInitialLife)
109
x = 1. * p->iLife / p->iInitialLife;
110
p->color[3] = 1 - fabs (x - a/2) / (a/2);
113
p->fSizeFactor += p->fResizeSpeed;
117
if (pRewindParticle && p->iLife == 0)
119
pRewindParticle (p, pParticleSystem->dt);
121
if (bAllParticlesEnded && p->iLife != 0)
122
bAllParticlesEnded = FALSE;
125
return ! bAllParticlesEnded;
128
void cd_icon_effect_rewind_star_particle (CairoParticle *p, double dt)
131
p->x = 2 * g_random_double () - 1;
132
p->y = g_random_double ();
134
p->iInitialLife = myConfig.iStarDuration / dt;
135
p->iLife = p->iInitialLife * (g_random_double () + a) / (1 + a);