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

« back to all changes in this revision

Viewing changes to icon-effect/src/applet-storm.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-storm.h"
 
35
 
 
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.
 
40
 
 
41
CairoParticleSystem *cd_icon_effect_init_storm (Icon *pIcon, CairoDock *pDock, double dt)
 
42
{
 
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;
 
51
        
 
52
        static double epsilon = 0.1;
 
53
        double r = myConfig.iStormParticleSize;
 
54
        double vmax = 1. / myConfig.iStormDuration * 2;
 
55
        double fBlend;
 
56
        CairoParticle *p;
 
57
        int i;
 
58
        for (i = 0; i < myConfig.iNbStormParticles; i ++)
 
59
        {
 
60
                p = &pStormParticleSystem->pParticles[i];
 
61
                
 
62
                p->x = 0.;  // on le calculera a la main.
 
63
                p->y = -1. * i /myConfig.iNbStormParticles + .01 * (2 * g_random_double () - 1);
 
64
                p->z = 1.;  // idem.
 
65
                p->fWidth = r * (1 + ar * (2 * g_random_double () - 1));
 
66
                p->fHeight = p->fWidth;
 
67
                
 
68
                p->vx = ad * (2 * g_random_double () - 1);  // utilisation detournee : dispersion.
 
69
                p->vy = vmax * (1 - ad * g_random_double ()) * dt * 2;
 
70
                
 
71
                p->iInitialLife = MIN ((1 - p->y) / p->vy, ceil (myConfig.iStormDuration/2 / dt));
 
72
                p->iLife = p->iInitialLife;
 
73
                
 
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);
 
79
                
 
80
                p->fOscillation = 0.;
 
81
                p->fOmega = 0.;
 
82
                
 
83
                p->fSizeFactor = 1.;
 
84
                p->fResizeSpeed = 0.;  // zoom constant.
 
85
        }
 
86
        
 
87
        return pStormParticleSystem;
 
88
}
 
89
 
 
90
gboolean cd_icon_effect_update_storm_system (CairoParticleSystem *pParticleSystem, CairoDockRewindParticleFunc pRewindParticle)
 
91
{
 
92
        gboolean bAllParticlesEnded = TRUE;
 
93
        double x;
 
94
        CairoParticle *p;
 
95
        int i;
 
96
        for (i = 0; i < pParticleSystem->iNbParticles; i ++)
 
97
        {
 
98
                p = &(pParticleSystem->pParticles[i]);
 
99
                
 
100
                p->y += p->vy;
 
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.
 
106
                
 
107
                if (p->iLife > 0)  // p->y > 1
 
108
                {
 
109
                        p->iLife --;
 
110
                        if (pRewindParticle && p->iLife == 0)
 
111
                        {
 
112
                                pRewindParticle (p, pParticleSystem->dt);
 
113
                        }
 
114
                        if (bAllParticlesEnded && p->iLife != 0)
 
115
                                bAllParticlesEnded = FALSE;
 
116
                }
 
117
        }
 
118
        return ! bAllParticlesEnded;
 
119
}
 
120
 
 
121
void cd_icon_effect_rewind_storm_particle (CairoParticle *p, double dt)
 
122
{
 
123
        p->x = 0;
 
124
        p->y = .03 * (2 * g_random_double () - 1);
 
125
        p->z = 1.;
 
126
        p->fSizeFactor = 1.;
 
127
        p->color[3] = at;
 
128
        p->iInitialLife = MIN (1. / p->vy, ceil (myConfig.iStormDuration/2 / dt));
 
129
        p->iLife = p->iInitialLife;
 
130
}