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-snow.h"
37
CairoParticleSystem *cd_icon_effect_init_snow (Icon *pIcon, CairoDock *pDock, double dt)
39
if (myData.iSnowTexture == 0)
40
myData.iSnowTexture = cd_icon_effect_load_snow_texture ();
41
double fMaxScale = (pDock->bAtBottom ? 1. : cairo_dock_get_max_scale (CAIRO_CONTAINER (pDock)));
42
CairoParticleSystem *pSnowParticleSystem = cairo_dock_create_particle_system (myConfig.iNbSnowParticles, myData.iSnowTexture, pIcon->fWidth * pIcon->fScale, pIcon->fHeight * fMaxScale);
43
g_return_val_if_fail (pSnowParticleSystem != NULL, NULL);
44
pSnowParticleSystem->dt = dt;
45
if (myConfig.bRotateEffects && ! pDock->bDirectionUp && pDock->bHorizontalDock)
46
pSnowParticleSystem->bDirectionUp = FALSE;
48
double a = myConfig.fSnowParticleSpeed;
49
static double epsilon = 0.1;
50
double r = myConfig.iSnowParticleSize;
52
double vmax = 1. / myConfig.iSnowDuration;
55
for (i = 0; i < myConfig.iNbSnowParticles; i ++)
57
p = &(pSnowParticleSystem->pParticles[i]);
59
p->x = 2 * g_random_double () - 1;
61
p->z = 2 * g_random_double () - 1;
62
p->fWidth = r*(p->z + 2)/3 * g_random_double ();
63
p->fHeight = p->fWidth;
66
p->vy = -a * vmax * ((p->z + 1)/2 * g_random_double () + epsilon) * dt;
67
p->iInitialLife = myConfig.iSnowDuration / dt;
68
p->iLife = p->iInitialLife * (g_random_double () + 1)/2;
71
fBlend = g_random_double ();
72
p->color[0] = fBlend * myConfig.pSnowColor1[0] + (1 - fBlend) * myConfig.pSnowColor2[0];
73
p->color[1] = fBlend * myConfig.pSnowColor1[1] + (1 - fBlend) * myConfig.pSnowColor2[1];
74
p->color[2] = fBlend * myConfig.pSnowColor1[2] + (1 - fBlend) * myConfig.pSnowColor2[2];
78
p->fOscillation = G_PI * (2 * g_random_double () - 1);
79
p->fOmega = 2*G_PI / myConfig.iSnowDuration * dt; // tr/s
82
p->fResizeSpeed = - .5 / myConfig.iSnowDuration * dt; // zoom 0.5 a la fin.
85
return pSnowParticleSystem;
90
void cd_icon_effect_rewind_snow_particle (CairoParticle *p, double dt)
92
static double epsilon = 0.1;
93
double a = myConfig.fSnowParticleSpeed/1;
94
double r = myConfig.iSnowParticleSize;
95
double vmax = 1. / myConfig.iSnowDuration;
96
p->x = 2 * g_random_double () - 1;
98
p->z = 2 * g_random_double () - 1;
100
p->fWidth = r*(p->z + 2)/3 * g_random_double ();
101
p->fHeight = p->fWidth;
103
p->vy = -a * vmax * ((p->z + 1)/2 * g_random_double () + epsilon) * dt;
105
p->iInitialLife = myConfig.iSnowDuration / dt;
106
p->iLife = p->iInitialLife * (g_random_double () + 1)/2;