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

« back to all changes in this revision

Viewing changes to show-mouse/src/applet-notifications.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-notifications.h"
 
34
#include "star-tex.h"
 
35
 
 
36
static double fRadius = .33;
 
37
static double a = .2;
 
38
 
 
39
 
 
40
gboolean cd_show_mouse_render (gpointer pUserData, CairoContainer *pContainer, cairo_t *pCairoContext)
 
41
{
 
42
        CDShowMouseData *pData = CD_APPLET_GET_MY_CONTAINER_DATA (pContainer);
 
43
        if (pData == NULL)
 
44
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
45
        
 
46
        glPushMatrix();
 
47
        
 
48
        if (CAIRO_DOCK_IS_DESKLET (pContainer))
 
49
        {
 
50
                CairoDesklet *pDesklet = CAIRO_DESKLET (pContainer);
 
51
                glTranslatef (-pDesklet->iWidth/2, -pDesklet->iHeight/2, -pDesklet->iHeight*(sqrt(3)/2));
 
52
        }
 
53
        if (pContainer->bIsHorizontal)
 
54
                glTranslatef (pContainer->iMouseX, pContainer->iHeight - pContainer->iMouseY, 0.);
 
55
        else
 
56
                glTranslatef (pContainer->iMouseY, pContainer->iWidth - pContainer->iMouseX, 0.);
 
57
        cairo_dock_render_particles (pData->pSystem);
 
58
        
 
59
        glPopMatrix();
 
60
        
 
61
        return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
62
}
 
63
 
 
64
 
 
65
#define _compute_area(area, pContainer, pData) do {\
 
66
if (pContainer->bIsHorizontal) {\
 
67
        area.x = pContainer->iMouseX - pData->pSystem->fWidth/2;\
 
68
        area.y = MAX (0, pContainer->iMouseY - pData->pSystem->fHeight);\
 
69
        area.width = pData->pSystem->fWidth;\
 
70
        area.height = pData->pSystem->fHeight*2; }\
 
71
else {\
 
72
        area.y = pContainer->iMouseX - pData->pSystem->fWidth/2;\
 
73
        area.x = MAX (0, pContainer->iMouseY - pData->pSystem->fHeight);\
 
74
        area.height = pData->pSystem->fWidth;\
 
75
        area.width = pData->pSystem->fHeight*2; } } while (0)
 
76
gboolean cd_show_mouse_update_container (gpointer pUserData, CairoContainer *pContainer, gboolean *bContinueAnimation)
 
77
{
 
78
        CDShowMouseData *pData = CD_APPLET_GET_MY_CONTAINER_DATA (pContainer);
 
79
        if (pData == NULL)
 
80
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
81
        
 
82
        GdkRectangle area;
 
83
        if (! pContainer->bInside)
 
84
        {
 
85
                pData->fAlpha -= .05;
 
86
                if (pData->fAlpha <= 0)
 
87
                {
 
88
                        _compute_area (area, pContainer, pData);
 
89
                        cairo_dock_redraw_container_area (pContainer, &area);
 
90
                        
 
91
                        cairo_dock_free_particle_system (pData->pSystem);
 
92
                        g_free (pData);
 
93
                        CD_APPLET_SET_MY_CONTAINER_DATA (pContainer, NULL);
 
94
                        
 
95
                        return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
96
                }
 
97
        }
 
98
        else if (pData->fAlpha != 1)
 
99
                pData->fAlpha = MIN (1., pData->fAlpha + .05);
 
100
        
 
101
        pData->fRotationAngle += 2*G_PI * myConfig.fRotationSpeed * mySystem.iGLAnimationDeltaT / 1000.;
 
102
        
 
103
        cd_show_mouse_update_sources (pData);
 
104
        pData->pSystem->fWidth = 2 * MIN (96, pContainer->iHeight);
 
105
        pData->pSystem->fHeight =  MIN (96, pContainer->iHeight);
 
106
        cd_show_mouse_update_particle_system (pData->pSystem, pData);
 
107
        
 
108
        _compute_area (area, pContainer, pData);
 
109
        cairo_dock_redraw_container_area (pContainer, &area);
 
110
        
 
111
        *bContinueAnimation = TRUE;
 
112
        return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
113
}
 
114
 
 
115
 
 
116
gboolean cd_show_mouse_enter_container (gpointer pUserData, CairoContainer *pContainer, gboolean *bStartAnimation)
 
117
{
 
118
        if (! CAIRO_DOCK_CONTAINER_IS_OPENGL (pContainer))
 
119
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
120
        
 
121
        CDShowMouseData *pData = CD_APPLET_GET_MY_CONTAINER_DATA (pContainer);
 
122
        if (pData == NULL)
 
123
        {
 
124
                pData = g_new0 (CDShowMouseData, 1);
 
125
                pData->fAlpha = 1.;
 
126
                
 
127
                double dt = mySystem.iGLAnimationDeltaT;
 
128
                pData->pSourceCoords = cd_show_mouse_init_sources ();
 
129
                pData->pSystem = cd_show_mouse_init_system (pContainer, dt, pData->pSourceCoords);
 
130
                
 
131
                CD_APPLET_SET_MY_CONTAINER_DATA (pContainer, pData);
 
132
        }
 
133
        
 
134
        
 
135
        *bStartAnimation = TRUE;
 
136
        return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
137
}
 
138
 
 
139
 
 
140
 
 
141
gdouble *cd_show_mouse_init_sources (void)
 
142
{
 
143
        double *pSourceCoords = g_new (double, myConfig.iNbSources * 2);
 
144
        double fTheta;
 
145
        int i;
 
146
        for (i = 0; i < myConfig.iNbSources; i ++)
 
147
        {
 
148
                fTheta = 2*G_PI * i / myConfig.iNbSources;
 
149
                pSourceCoords[2*i] = fRadius * cos (fTheta);
 
150
                pSourceCoords[2*i+1] = fRadius * sin (fTheta);
 
151
        }
 
152
        return pSourceCoords;
 
153
}
 
154
 
 
155
CairoParticleSystem *cd_show_mouse_init_system (CairoContainer *pContainer, double dt, double *pSourceCoords)
 
156
{
 
157
        if (myData.iTexture == 0)
 
158
                myData.iTexture = cairo_dock_load_texture_from_raw_data (starTex, 32, 32);  /// 32 = sqrt (4096/4)
 
159
        double fHeight = pContainer->iHeight;  // iMaxDockHeight ?
 
160
        CairoParticleSystem *pParticleSystem = cairo_dock_create_particle_system (myConfig.iNbParticles * myConfig.iNbSources, myData.iTexture, 2*fHeight, fHeight);
 
161
        pParticleSystem->dt = dt;
 
162
        
 
163
        int iNumSource;
 
164
        double fBlend;
 
165
        double r = myConfig.iParticleSize / (1 + a);
 
166
        double sigma = myConfig.fScattering;
 
167
        CairoParticle *p;
 
168
        int i;
 
169
        for (i = 0; i < pParticleSystem->iNbParticles; i ++)
 
170
        {
 
171
                p = &(pParticleSystem->pParticles[i]);
 
172
                
 
173
                iNumSource = i / myConfig.iNbParticles;
 
174
                
 
175
                p->x = pSourceCoords[2*iNumSource];
 
176
                p->y = pSourceCoords[2*iNumSource+1];
 
177
                p->z = 0;
 
178
                p->fWidth = r * (a + g_random_double ());
 
179
                p->fHeight = p->fWidth;
 
180
                
 
181
                p->vx = sigma * (2 * g_random_double () - 1) * dt / myConfig.iParticleLifeTime;
 
182
                p->vy = sigma * (2 * g_random_double () - 1) * dt / myConfig.iParticleLifeTime;
 
183
                p->iInitialLife = ceil (myConfig.iParticleLifeTime / dt);
 
184
                p->iLife = g_random_int_range (1, p->iInitialLife+1);
 
185
                
 
186
                if (myConfig.bMysticalFire)
 
187
                {
 
188
                        p->color[0] = g_random_double ();
 
189
                        p->color[1] = g_random_double ();
 
190
                        p->color[2] = g_random_double ();
 
191
                }
 
192
                else
 
193
                {
 
194
                        fBlend = g_random_double ();
 
195
                        p->color[0] = fBlend * myConfig.pColor1[0] + (1 - fBlend) * myConfig.pColor2[0];
 
196
                        p->color[1] = fBlend * myConfig.pColor1[1] + (1 - fBlend) * myConfig.pColor2[1];
 
197
                        p->color[2] = fBlend * myConfig.pColor1[2] + (1 - fBlend) * myConfig.pColor2[2];
 
198
                }
 
199
                p->color[3] = 1.;
 
200
                
 
201
                p->fSizeFactor = 1.;
 
202
                p->fResizeSpeed = .5 / myConfig.iParticleLifeTime * dt;  // zoom 1.5 a la fin.
 
203
        }
 
204
        
 
205
        return pParticleSystem;
 
206
        
 
207
}
 
208
 
 
209
void cd_show_mouse_update_sources (CDShowMouseData *pData)
 
210
{
 
211
        double *pSourceCoords = pData->pSourceCoords;
 
212
        double fTheta;
 
213
        int i;
 
214
        for (i = 0; i < myConfig.iNbSources; i ++)
 
215
        {
 
216
                fTheta = 2*G_PI * i / myConfig.iNbSources + pData->fRotationAngle;
 
217
                pSourceCoords[2*i] = fRadius * cos (fTheta);
 
218
                pSourceCoords[2*i+1] = fRadius * sin (fTheta);
 
219
        }
 
220
}
 
221
 
 
222
 
 
223
void cd_show_mouse_update_particle_system (CairoParticleSystem *pParticleSystem, CDShowMouseData *pData)
 
224
{
 
225
        double *pSourceCoords = pData->pSourceCoords;
 
226
        CairoParticle *p;
 
227
        double dt = pParticleSystem->dt;
 
228
        int i;
 
229
        double sigma = myConfig.fScattering;
 
230
        for (i = 0; i < pParticleSystem->iNbParticles; i ++)
 
231
        {
 
232
                p = &(pParticleSystem->pParticles[i]);
 
233
                
 
234
                p->x += p->vx;
 
235
                p->y += p->vy;
 
236
                p->color[3] = pData->fAlpha * p->iLife / p->iInitialLife;
 
237
                p->fSizeFactor += p->fResizeSpeed;
 
238
                if (p->iLife > 0)
 
239
                {
 
240
                        p->iLife --;
 
241
                        if (p->iLife == 0)
 
242
                        {
 
243
                                int iNumSource = i / myConfig.iNbParticles;
 
244
                                p->x = pSourceCoords[2*iNumSource];
 
245
                                p->y = pSourceCoords[2*iNumSource+1];
 
246
                                
 
247
                                p->vx = sigma * (2 * g_random_double () - 1) * dt / myConfig.iParticleLifeTime;
 
248
                                p->vy = sigma * (2 * g_random_double () - 1) * dt / myConfig.iParticleLifeTime;
 
249
                                
 
250
                                p->color[3] = pData->fAlpha;
 
251
                                p->fSizeFactor = 1.;
 
252
                                
 
253
                                p->iLife = g_random_int_range (1, p->iInitialLife+1);
 
254
                        }
 
255
                }
 
256
        }
 
257
}
 
258
 
 
259
gboolean cd_show_mouse_free_data (gpointer pUserData, CairoContainer *pContainer)
 
260
{
 
261
        cd_message ("");
 
262
        CDShowMouseData *pData = CD_APPLET_GET_MY_CONTAINER_DATA (pContainer);
 
263
        if (pData == NULL)
 
264
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
265
        
 
266
        cairo_dock_free_particle_system (pData->pSystem);
 
267
        g_free (pData);
 
268
        CD_APPLET_SET_MY_CONTAINER_DATA (pContainer, NULL);
 
269
        return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
270
}