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

« back to all changes in this revision

Viewing changes to icon-effect/src/applet-fire.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-fire.h"
 
35
 
 
36
 
 
37
CairoParticleSystem *cd_icon_effect_init_fire (Icon *pIcon, CairoDock *pDock, double dt)
 
38
{
 
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;
 
48
        
 
49
        double a = myConfig.fFireParticleSpeed;
 
50
        static double epsilon = 0.1;
 
51
        double r = myConfig.iFireParticleSize;
 
52
        double fBlend;
 
53
        double vmax = 1. / myConfig.iFireDuration;
 
54
        CairoParticle *p;
 
55
        int i;
 
56
        for (i = 0; i < myConfig.iNbFireParticles; i ++)
 
57
        {
 
58
                p = &(pFireParticleSystem->pParticles[i]);
 
59
                
 
60
                p->x = 2 * g_random_double () - 1;
 
61
                p->x = p->x * p->x * (p->x > 0 ? 1 : -1);
 
62
                p->y = 0.;
 
63
                p->z = 2 * g_random_double () - 1;
 
64
                p->fWidth = r*(p->z + 2)/3 * .5 * pDock->fRatio;
 
65
                p->fHeight = p->fWidth;
 
66
                
 
67
                p->vx = 0.;
 
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
 
71
                
 
72
                if (myConfig.bMysticalFire)
 
73
                {
 
74
                        p->color[0] = g_random_double ();
 
75
                        p->color[1] = g_random_double ();
 
76
                        p->color[2] = g_random_double ();
 
77
                }
 
78
                else
 
79
                {
 
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];
 
84
                }
 
85
                p->color[3] = 1.;
 
86
                
 
87
                p->fOscillation = G_PI * (2 * g_random_double () - 1);
 
88
                p->fOmega = 2*G_PI / myConfig.iFireDuration * dt;  // tr/s
 
89
                
 
90
                p->fSizeFactor = 1.;
 
91
                p->fResizeSpeed = -.5 / myConfig.iFireDuration * dt;  // zoom 0.5 a la fin.
 
92
        }
 
93
        
 
94
        return pFireParticleSystem;
 
95
}
 
96
 
 
97
 
 
98
gboolean cd_icon_effect_update_fire_system (CairoParticleSystem *pParticleSystem, CairoDockRewindParticleFunc pRewindParticle)
 
99
{
 
100
        gboolean bAllParticlesEnded = TRUE;
 
101
        CairoParticle *p;
 
102
        int i;
 
103
        for (i = 0; i < pParticleSystem->iNbParticles; i ++)
 
104
        {
 
105
                p = &(pParticleSystem->pParticles[i]);
 
106
                
 
107
                p->fOscillation += p->fOmega;
 
108
                p->x += p->vx + (p->z + 2)/3. * .02 * sin (p->fOscillation);  // 3%
 
109
                p->y += p->vy;
 
110
                p->color[3] = .8*p->iLife / p->iInitialLife;
 
111
                p->fSizeFactor += p->fResizeSpeed;
 
112
                if (p->iLife > 0)
 
113
                {
 
114
                        p->iLife --;
 
115
                        if (pRewindParticle && p->iLife == 0)
 
116
                        {
 
117
                                pRewindParticle (p, pParticleSystem->dt);
 
118
                        }
 
119
                        if (bAllParticlesEnded && p->iLife != 0)
 
120
                                bAllParticlesEnded = FALSE;
 
121
                }
 
122
                else if (pRewindParticle)
 
123
                        pRewindParticle (p, pParticleSystem->dt);
 
124
        }
 
125
        return ! bAllParticlesEnded;
 
126
}
 
127
 
 
128
void cd_icon_effect_rewind_fire_particle (CairoParticle *p, double dt)
 
129
{
 
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);
 
136
        p->y = 0;
 
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;
 
141
        
 
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
 
144
        
 
145
        p->fSizeFactor = 1.;
 
146
        p->color[3] = 1.;
 
147
}
 
148