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

« back to all changes in this revision

Viewing changes to icon-effect/src/applet-snow.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-snow.h"
 
35
 
 
36
 
 
37
CairoParticleSystem *cd_icon_effect_init_snow (Icon *pIcon, CairoDock *pDock, double dt)
 
38
{
 
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;
 
47
        
 
48
        double a = myConfig.fSnowParticleSpeed;
 
49
        static double epsilon = 0.1;
 
50
        double r = myConfig.iSnowParticleSize;
 
51
        double fBlend;
 
52
        double vmax = 1. / myConfig.iSnowDuration;
 
53
        CairoParticle *p;
 
54
        int i;
 
55
        for (i = 0; i < myConfig.iNbSnowParticles; i ++)
 
56
        {
 
57
                p = &(pSnowParticleSystem->pParticles[i]);
 
58
                
 
59
                p->x = 2 * g_random_double () - 1;
 
60
                p->y = 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;
 
64
                
 
65
                p->vx = 0.;
 
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;
 
69
                
 
70
                {
 
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];
 
75
                }
 
76
                p->color[3] = 0.;
 
77
                
 
78
                p->fOscillation = G_PI * (2 * g_random_double () - 1);
 
79
                p->fOmega = 2*G_PI / myConfig.iSnowDuration * dt;  // tr/s
 
80
                
 
81
                p->fSizeFactor = 1.;
 
82
                p->fResizeSpeed = - .5 / myConfig.iSnowDuration * dt;  // zoom 0.5 a la fin.
 
83
        }
 
84
        
 
85
        return pSnowParticleSystem;
 
86
}
 
87
 
 
88
 
 
89
 
 
90
void cd_icon_effect_rewind_snow_particle (CairoParticle *p, double dt)
 
91
{
 
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;
 
97
        p->y = 1.;
 
98
        p->z = 2 * g_random_double () - 1;
 
99
        
 
100
        p->fWidth = r*(p->z + 2)/3 * g_random_double ();
 
101
        p->fHeight = p->fWidth;
 
102
        
 
103
        p->vy = -a * vmax * ((p->z + 1)/2 * g_random_double () + epsilon) * dt;
 
104
        
 
105
        p->iInitialLife = myConfig.iSnowDuration / dt;
 
106
        p->iLife = p->iInitialLife * (g_random_double () + 1)/2;
 
107
        
 
108
        p->fSizeFactor = 1.;
 
109
}
 
110