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

« back to all changes in this revision

Viewing changes to icon-effect/src/applet-star.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-star.h"
 
35
 
 
36
 
 
37
CairoParticleSystem *cd_icon_effect_init_stars (Icon *pIcon, CairoDock *pDock, double dt)
 
38
{
 
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;
 
46
        
 
47
        static double a = .4;
 
48
        static double epsilon = 0.1;
 
49
        double r = myConfig.iStarParticleSize;
 
50
        double fBlend;
 
51
        CairoParticle *p;
 
52
        int i;
 
53
        for (i = 0; i < myConfig.iNbStarParticles; i ++)
 
54
        {
 
55
                p = &pStarParticleSystem->pParticles[i];
 
56
                
 
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;
 
62
                
 
63
                p->vx = 0.;
 
64
                p->vy = 0.;
 
65
                
 
66
                p->iInitialLife = myConfig.iStarDuration / dt;
 
67
                p->iLife = p->iInitialLife * (g_random_double () + a) / (1 + a);
 
68
                
 
69
                if (myConfig.bMysticalStars)
 
70
                {
 
71
                        p->color[0] = g_random_double ();
 
72
                        p->color[1] = g_random_double ();
 
73
                        p->color[2] = g_random_double ();
 
74
                }
 
75
                else
 
76
                {
 
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];
 
81
                }
 
82
                p->color[3] = 0.;  // on va gerer nous-mêmes la transparence.
 
83
                
 
84
                p->fOscillation = 0.;
 
85
                p->fOmega = 0.;
 
86
                
 
87
                p->fSizeFactor = 1.;
 
88
                p->fResizeSpeed = - 1. / myConfig.iStarDuration * dt;  // zoom 0 a la fin.
 
89
        }
 
90
        
 
91
        return pStarParticleSystem;
 
92
}
 
93
 
 
94
gboolean cd_icon_effect_update_star_system (CairoParticleSystem *pParticleSystem, CairoDockRewindParticleFunc pRewindParticle)
 
95
{
 
96
        static double a = .4;
 
97
        gboolean bAllParticlesEnded = TRUE;
 
98
        double x;
 
99
        CairoParticle *p;
 
100
        int i;
 
101
        for (i = 0; i < pParticleSystem->iNbParticles; i ++)
 
102
        {
 
103
                p = &(pParticleSystem->pParticles[i]);
 
104
                
 
105
                if (p->iLife > a * p->iInitialLife)
 
106
                        p->color[3] = 0.;
 
107
                else
 
108
                {
 
109
                        x = 1. * p->iLife / p->iInitialLife;
 
110
                        p->color[3] = 1 - fabs (x - a/2) / (a/2);
 
111
                }
 
112
                
 
113
                p->fSizeFactor += p->fResizeSpeed;
 
114
                if (p->iLife > 0)
 
115
                {
 
116
                        p->iLife --;
 
117
                        if (pRewindParticle && p->iLife == 0)
 
118
                        {
 
119
                                pRewindParticle (p, pParticleSystem->dt);
 
120
                        }
 
121
                        if (bAllParticlesEnded && p->iLife != 0)
 
122
                                bAllParticlesEnded = FALSE;
 
123
                }
 
124
        }
 
125
        return ! bAllParticlesEnded;
 
126
}
 
127
 
 
128
void cd_icon_effect_rewind_star_particle (CairoParticle *p, double dt)
 
129
{
 
130
        double a = .2;
 
131
        p->x = 2 * g_random_double () - 1;
 
132
        p->y = g_random_double ();
 
133
        p->fSizeFactor = 1.;
 
134
        p->iInitialLife = myConfig.iStarDuration / dt;
 
135
        p->iLife = p->iInitialLife * (g_random_double () + a) / (1 + a);
 
136
}