~cairo-dock-team/cairo-dock-plug-ins/plug-ins

« back to all changes in this revision

Viewing changes to icon-effect/src/applet-notifications.c

  • Committer: Matthieu Baerts
  • Date: 2014-10-19 00:26:10 UTC
  • Revision ID: matttbe@gmail.com-20141019002610-ulf26s9b4c4rw10r
We just switched from BZR to Git.
Follow us on Github: https://github.com/Cairo-Dock

Note: we will only use Github to manage our source code and all pull requests.
Please continue to report your bugs/ideas/messages on our forum or Launchpad! 

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
 
#include <stdlib.h>
21
 
#include <string.h>
22
 
 
23
 
#include "applet-fire.h"
24
 
#include "applet-rain.h"
25
 
#include "applet-snow.h"
26
 
#include "applet-star.h"
27
 
#include "applet-storm.h"
28
 
#include "applet-firework.h"
29
 
#include "applet-struct.h"
30
 
#include "applet-notifications.h"
31
 
 
32
 
 
33
 
static gboolean _cd_icon_effect_start (gpointer pUserData, Icon *pIcon, CairoDock *pDock, CDIconEffectsEnum *pWantedEffects)
34
 
{
35
 
        if (! CAIRO_DOCK_CONTAINER_IS_OPENGL (CAIRO_CONTAINER (pDock)))
36
 
                return FALSE;
37
 
        CDIconEffectData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
38
 
        if (pData == NULL)
39
 
        {
40
 
                pData = g_new0 (CDIconEffectData, 1);
41
 
                CD_APPLET_SET_MY_ICON_DATA (pIcon, pData);
42
 
        }
43
 
        double dt = cairo_dock_get_animation_delta_t (CAIRO_CONTAINER (pDock));
44
 
        
45
 
        CDIconEffectsEnum iEffect;
46
 
        CDIconEffect *pEffect;
47
 
        gboolean r, bStart = FALSE;
48
 
        int i, j=0;
49
 
        for (i = 0; i < CD_ICON_EFFECT_NB_EFFECTS; i ++)
50
 
        {
51
 
                iEffect = pWantedEffects[i];
52
 
                if (iEffect > CD_ICON_EFFECT_NB_EFFECTS - 1)
53
 
                        break;
54
 
                
55
 
                pEffect = &myData.pEffects[iEffect];
56
 
                r = pEffect->init (pIcon, pDock, dt, pData);
57
 
                if (r)
58
 
                {
59
 
                        bStart = TRUE;
60
 
                        pData->pCurrentEffects[j++] = pEffect;
61
 
                }
62
 
        }
63
 
        return bStart;
64
 
}
65
 
 
66
 
gboolean cd_icon_effect_on_enter (gpointer pUserData, Icon *pIcon, CairoDock *pDock, gboolean *bStartAnimation)
67
 
{
68
 
        if (pIcon->iAnimationState > CAIRO_DOCK_STATE_MOUSE_HOVERED)
69
 
                return GLDI_NOTIFICATION_LET_PASS;
70
 
        gboolean bStart = _cd_icon_effect_start (pUserData, pIcon, pDock, myConfig.iEffectsUsed);
71
 
        if (bStart)
72
 
        {
73
 
                *bStartAnimation = TRUE;
74
 
                CDIconEffectData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
75
 
                pData->iRequestTime = 0;
76
 
                cairo_dock_mark_icon_as_hovered_by_mouse (pIcon);
77
 
        }
78
 
        return GLDI_NOTIFICATION_LET_PASS;
79
 
}
80
 
 
81
 
gboolean cd_icon_effect_on_click (gpointer pUserData, Icon *pIcon, CairoDock *pDock, gint iButtonState)
82
 
{
83
 
        if (! CAIRO_DOCK_IS_DOCK (pDock) || pIcon == NULL || pIcon->iAnimationState > CAIRO_DOCK_STATE_CLICKED)
84
 
                return GLDI_NOTIFICATION_LET_PASS;
85
 
        
86
 
        CairoDockIconGroup iType = cairo_dock_get_icon_type (pIcon);
87
 
        if (iType == CAIRO_DOCK_LAUNCHER && CAIRO_DOCK_IS_APPLI (pIcon) && ! (iButtonState & GDK_SHIFT_MASK))
88
 
                iType = CAIRO_DOCK_APPLI;
89
 
        
90
 
        gboolean bStartAnimation = _cd_icon_effect_start (pUserData, pIcon, pDock, myConfig.iEffectsOnClick[iType]);
91
 
        if (bStartAnimation)
92
 
        {
93
 
                CDIconEffectData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
94
 
                pData->iRequestTime = 0;
95
 
                cairo_dock_mark_icon_as_clicked (pIcon);
96
 
        }
97
 
        
98
 
        return GLDI_NOTIFICATION_LET_PASS;
99
 
}
100
 
 
101
 
gboolean cd_icon_effect_on_request (gpointer pUserData, Icon *pIcon, CairoDock *pDock, const gchar *cAnimation, gint iNbRounds)
102
 
{
103
 
        if (pIcon == NULL || pIcon->iAnimationState > CAIRO_DOCK_STATE_CLICKED)
104
 
                return GLDI_NOTIFICATION_LET_PASS;
105
 
        
106
 
        CDIconEffectsEnum iEffect = -1;
107
 
        if (strcmp (cAnimation, "default") == 0)
108
 
        {
109
 
                CairoDockIconGroup iType = cairo_dock_get_icon_type (pIcon);
110
 
                iEffect = myConfig.iEffectsOnClick[iType][0];
111
 
        }
112
 
        else
113
 
        {
114
 
                int iAnimationID = cairo_dock_get_animation_id (cAnimation);
115
 
                if (iAnimationID == myData.iAnimationID[CD_ICON_EFFECT_FIRE])
116
 
                {
117
 
                        iEffect = CD_ICON_EFFECT_FIRE;
118
 
                }
119
 
                else if (iAnimationID == myData.iAnimationID[CD_ICON_EFFECT_STARS])
120
 
                {
121
 
                        iEffect = CD_ICON_EFFECT_STARS;
122
 
                }
123
 
                else if (iAnimationID == myData.iAnimationID[CD_ICON_EFFECT_RAIN])
124
 
                {
125
 
                        iEffect = CD_ICON_EFFECT_RAIN;
126
 
                }
127
 
                else if (iAnimationID == myData.iAnimationID[CD_ICON_EFFECT_SNOW])
128
 
                {
129
 
                        iEffect = CD_ICON_EFFECT_SNOW;
130
 
                }
131
 
                else if (iAnimationID == myData.iAnimationID[CD_ICON_EFFECT_SAND])
132
 
                {
133
 
                        iEffect = CD_ICON_EFFECT_SAND;
134
 
                }
135
 
                else if (iAnimationID == myData.iAnimationID[CD_ICON_EFFECT_FIREWORK])
136
 
                {
137
 
                        iEffect = CD_ICON_EFFECT_FIREWORK;
138
 
                }
139
 
        }
140
 
        if (iEffect >= CD_ICON_EFFECT_NB_EFFECTS)
141
 
                return GLDI_NOTIFICATION_LET_PASS;
142
 
        
143
 
        CDIconEffectsEnum anim[2] = {iEffect, -1};
144
 
        int iRoundDuration = myData.pEffects[iEffect].iDuration;
145
 
        
146
 
        gboolean bStartAnimation = _cd_icon_effect_start (pUserData, pIcon, pDock, anim);
147
 
        if (bStartAnimation)
148
 
        {
149
 
                CDIconEffectData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
150
 
                pData->iRequestTime = iNbRounds * iRoundDuration;
151
 
                cairo_dock_mark_icon_as_hovered_by_mouse (pIcon);
152
 
        }
153
 
        return GLDI_NOTIFICATION_LET_PASS;
154
 
}
155
 
 
156
 
 
157
 
static void _cd_icon_effect_render_effects (Icon *pIcon, CairoDock *pDock, CDIconEffectData *pData, gboolean bPreRender)
158
 
{
159
 
        glPushMatrix ();
160
 
        if (!pDock->container.bIsHorizontal && myConfig.bRotateEffects)
161
 
                glRotatef (pDock->container.bDirectionUp ? 90:-90, 0., 0., 1.);
162
 
        glTranslatef (0., - pIcon->fHeight * pIcon->fScale/2, 0.);  // en bas au milieu de l'icone.
163
 
        
164
 
        CDIconEffect *pEffect;
165
 
        int i;
166
 
        for (i = 0; i < CD_ICON_EFFECT_NB_EFFECTS; i ++)
167
 
        {
168
 
                pEffect = pData->pCurrentEffects[i];
169
 
                if (pEffect == NULL)
170
 
                        break;
171
 
                
172
 
                if (bPreRender)
173
 
                {
174
 
                        if (myConfig.bBackGround || (pEffect->render && pEffect->post_render))
175
 
                                pEffect->render (pData);
176
 
                }
177
 
                else
178
 
                {
179
 
                        if (!myConfig.bBackGround || (pEffect->render && pEffect->post_render))
180
 
                        {
181
 
                                if (pEffect->post_render)
182
 
                                        pEffect->post_render (pData);
183
 
                                else
184
 
                                        pEffect->render (pData);
185
 
                        }
186
 
                }
187
 
        }
188
 
        
189
 
        glPopMatrix ();
190
 
}
191
 
 
192
 
 
193
 
gboolean cd_icon_effect_pre_render_icon (gpointer pUserData, Icon *pIcon, CairoDock *pDock, cairo_t *ctx)
194
 
{
195
 
        CDIconEffectData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
196
 
        if (pData == NULL)
197
 
                return GLDI_NOTIFICATION_LET_PASS;
198
 
        
199
 
        _cd_icon_effect_render_effects (pIcon, pDock, pData, TRUE);
200
 
        
201
 
        return GLDI_NOTIFICATION_LET_PASS;
202
 
}
203
 
 
204
 
gboolean cd_icon_effect_render_icon (gpointer pUserData, Icon *pIcon, CairoDock *pDock, gboolean *bHasBeenRendered, cairo_t *pCairoContext)
205
 
{
206
 
        if (pCairoContext != NULL)
207
 
                return GLDI_NOTIFICATION_LET_PASS;
208
 
        CDIconEffectData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
209
 
        if (pData == NULL)
210
 
                return GLDI_NOTIFICATION_LET_PASS;
211
 
        
212
 
        _cd_icon_effect_render_effects (pIcon, pDock, pData, FALSE);
213
 
        
214
 
        return GLDI_NOTIFICATION_LET_PASS;
215
 
}
216
 
 
217
 
 
218
 
#define _will_continue(bRepeat) ((pData->iRequestTime > 0) || (pIcon->iAnimationState == CAIRO_DOCK_STATE_MOUSE_HOVERED && bRepeat && pIcon->bPointed && pDock->container.bInside) || (pIcon->iAnimationState == CAIRO_DOCK_STATE_CLICKED && myConfig.bOpeningAnimation && gldi_icon_is_launching (pIcon)))
219
 
 
220
 
gboolean cd_icon_effect_update_icon (gpointer pUserData, Icon *pIcon, CairoDock *pDock, gboolean *bContinueAnimation)
221
 
{
222
 
        CDIconEffectData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
223
 
        if (pData == NULL)
224
 
                return GLDI_NOTIFICATION_LET_PASS;
225
 
        
226
 
        if (pData->iRequestTime > 0)
227
 
        {
228
 
                int dt = cairo_dock_get_animation_delta_t (CAIRO_CONTAINER (pDock));
229
 
                pData->iRequestTime -= dt;
230
 
                if (pData->iRequestTime < 0)
231
 
                        pData->iRequestTime = 0;
232
 
        }
233
 
        
234
 
        gboolean bContinue, bRepeat;
235
 
        
236
 
        CDIconEffect *pEffect;
237
 
        int i;
238
 
        for (i = 0; i < CD_ICON_EFFECT_NB_EFFECTS; i ++)
239
 
        {
240
 
                pEffect = pData->pCurrentEffects[i];
241
 
                if (pEffect == NULL)
242
 
                        break;
243
 
                
244
 
                bRepeat = _will_continue (pEffect->bRepeat);
245
 
                bContinue = pEffect->update (pIcon, pDock, bRepeat, pData);
246
 
                
247
 
                if (bContinue)
248
 
                        *bContinueAnimation = TRUE;
249
 
                else
250
 
                        pEffect->free (pData);
251
 
        }
252
 
        
253
 
        GdkRectangle area;
254
 
        if (pDock->container.bIsHorizontal)
255
 
        {
256
 
                area.x = pIcon->fDrawX + pIcon->fWidth * pIcon->fScale / 2 - pData->fAreaWidth/2;
257
 
                area.width = pData->fAreaWidth;
258
 
                area.height = pData->fAreaHeight;
259
 
                if (pDock->container.bDirectionUp || ! myConfig.bRotateEffects)
260
 
                {
261
 
                        area.y = pIcon->fDrawY + pIcon->fHeight * pIcon->fScale + pData->fBottomGap - pData->fAreaHeight;
262
 
                }
263
 
                else
264
 
                {
265
 
                        area.y = pIcon->fDrawY - pData->fBottomGap;
266
 
                }
267
 
                /*area.x = pIcon->fDrawX - .25 * pIcon->fWidth * fMaxScale;
268
 
                area.y = pIcon->fDrawY;
269
 
                area.width = pIcon->fWidth * fMaxScale * 1.5;
270
 
                area.height = pIcon->fHeight * fMaxScale + myIconsParam.iconTextDescription.iSize + 20 * fMaxScale;  // 20 = rayon max des particules, environ.
271
 
                if (pDock->container.bDirectionUp)
272
 
                {
273
 
                        area.y -= myIconsParam.iconTextDescription.iSize + pIcon->fHeight * (fMaxScale - 1);
274
 
                }
275
 
                else
276
 
                {
277
 
                        area.y -= 20 * fMaxScale;
278
 
                }*/
279
 
        }
280
 
        else
281
 
        {
282
 
                /*area.y = pIcon->fDrawX - .25 * pIcon->fWidth * fMaxScale;
283
 
                area.x = pIcon->fDrawY;
284
 
                area.height = pIcon->fWidth * fMaxScale * 1.5;
285
 
                area.width = pIcon->fHeight * fMaxScale + myIconsParam.iconTextDescription.iSize + 20 * fMaxScale;
286
 
                if (pDock->container.bDirectionUp)
287
 
                {
288
 
                        area.x -= myIconsParam.iconTextDescription.iSize + pIcon->fHeight * (fMaxScale - 1);
289
 
                }
290
 
                else
291
 
                {
292
 
                        area.x -= 20 * fMaxScale;  // rayon max des particules, environ.
293
 
                }*/
294
 
                area.y = pIcon->fDrawX + pIcon->fWidth * pIcon->fScale / 2 - pData->fAreaWidth/2;
295
 
                area.height = pData->fAreaWidth;
296
 
                area.width = pData->fAreaHeight;
297
 
                if (pDock->container.bDirectionUp || ! myConfig.bRotateEffects)
298
 
                {
299
 
                        area.x = pIcon->fDrawY + pIcon->fHeight * pIcon->fScale + pData->fBottomGap - pData->fAreaHeight;
300
 
                }
301
 
                else
302
 
                {
303
 
                        area.x = pIcon->fDrawY - pData->fBottomGap;
304
 
                }
305
 
        }
306
 
        if (pIcon->fOrientation == 0)
307
 
                cairo_dock_redraw_container_area (CAIRO_CONTAINER (pDock), &area);
308
 
        else
309
 
                cairo_dock_redraw_container (CAIRO_CONTAINER (pDock));  /// il faudrait gerer la diagonale ...
310
 
        if (! *bContinueAnimation)
311
 
                cd_icon_effect_free_data (pUserData, pIcon);
312
 
        
313
 
        return GLDI_NOTIFICATION_LET_PASS;
314
 
}
315
 
 
316
 
 
317
 
gboolean cd_icon_effect_free_data (gpointer pUserData, Icon *pIcon)
318
 
{
319
 
        cd_message ("");
320
 
        CDIconEffectData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
321
 
        if (pData == NULL)
322
 
                return GLDI_NOTIFICATION_LET_PASS;
323
 
        
324
 
        CDIconEffect *pEffect;
325
 
        int i;
326
 
        for (i = 0; i < CD_ICON_EFFECT_NB_EFFECTS; i ++)
327
 
        {
328
 
                pEffect = pData->pCurrentEffects[i];
329
 
                if (pEffect == NULL)
330
 
                        break;
331
 
                
332
 
                pEffect->free (pData);
333
 
        }
334
 
        g_free (pData);
335
 
        CD_APPLET_SET_MY_ICON_DATA (pIcon, NULL);
336
 
        return GLDI_NOTIFICATION_LET_PASS;
337
 
}