Debian Codegraph @

illusion/src/applet-notifications.c

raw
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 #include <math.h>
23
24 #include "applet-struct.h"
25 #include "applet-evaporate.h"
26 #include "applet-fade-out.h"
27 #include "applet-explode.h"
28 #include "applet-break.h"
29 #include "applet-black-hole.h"
30 #include "applet-lightning.h"
31 #include "applet-notifications.h"
32
33
34 gboolean cd_illusion_on_remove_insert_icon (gpointer pUserData, Icon *pIcon, CairoDock *pDock)
35 {
36 if (fabs (pIcon->fInsertRemoveFactor) < .1) // useless or not needed animation.
37 {
38 cd_illusion_free_data (pUserData, pIcon); // be sure we won't handle the animation, in case the previous appearance animation was still here
39 return GLDI_NOTIFICATION_LET_PASS;
40 }
41 if (! CAIRO_CONTAINER_IS_OPENGL (CAIRO_CONTAINER (pDock))) // gere le cas ou pDock est NULL.
42 return GLDI_NOTIFICATION_LET_PASS;
43
44 CDIllusionData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
45 if (pData == NULL)
46 {
47 pData = g_new0 (CDIllusionData, 1);
48 pData->fDeltaT = (double) cairo_dock_get_animation_delta_t (CAIRO_CONTAINER (pDock));
49 pData->sens = (pIcon->fInsertRemoveFactor > .05 ? 1 : -1);
50 CD_APPLET_SET_MY_ICON_DATA (pIcon, pData);
51
52 gboolean bSartAnimation = FALSE;
53 CDIllusionEffect iEffect = (pData->sens == 1 ? myConfig.iDisappearanceEffect : myConfig.iAppearanceEffect);
54 if (iEffect >= CD_ILLUSION_NB_EFFECTS)
55 iEffect = g_random_int_range (0, CD_ILLUSION_NB_EFFECTS);
56 switch (iEffect)
57 {
58 case CD_ILLUSION_EVAPORATE :
59 pData->iEffectDuration = myConfig.iEvaporateDuration;
60 pData->fTimeLimitPercent = .8;
61 if (pData->sens == -1)
62 pData->fTime = pData->iEffectDuration; // on part a rebours.
63 bSartAnimation = cd_illusion_init_evaporate (pIcon, pDock, pData);
64 break ;
65 case CD_ILLUSION_FADE_OUT :
66 pData->iEffectDuration = myConfig.iFadeOutDuration;
67 pData->fTimeLimitPercent = .75;
68 if (pData->sens == -1)
69 pData->fTime = pData->iEffectDuration;
70 bSartAnimation = cd_illusion_init_fade_out (pIcon, pDock, pData);
71 break ;
72 case CD_ILLUSION_EXPLODE :
73 pData->iEffectDuration = myConfig.iExplodeDuration;
74 pData->fTimeLimitPercent = .9;
75 if (pData->sens == -1)
76 pData->fTime = pData->iEffectDuration;
77 bSartAnimation = cd_illusion_init_explode (pIcon, pDock, pData);
78 break ;
79 case CD_ILLUSION_BREAK :
80 pData->iEffectDuration = myConfig.iBreakDuration;
81 pData->fTimeLimitPercent = 1.;
82 if (pData->sens == -1)
83 pData->fTime = pData->iEffectDuration;
84 bSartAnimation = cd_illusion_init_break (pIcon, pDock, pData);
85 break ;
86 case CD_ILLUSION_BLACK_HOLE :
87 pData->iEffectDuration = myConfig.iBlackHoleDuration;
88 pData->fTimeLimitPercent = 1.;
89 if (pData->sens == -1)
90 pData->fTime = pData->iEffectDuration;
91 bSartAnimation = cd_illusion_init_black_hole (pIcon, pDock, pData);
92 break ;
93 case CD_ILLUSION_LIGHTNING :
94 pData->iEffectDuration = myConfig.iLightningDuration;
95 pData->fTimeLimitPercent = 1.;
96 if (pData->sens == -1)
97 pData->fTime = pData->iEffectDuration;
98 bSartAnimation = cd_illusion_init_lightning (pIcon, pDock, pData);
99 break ;
100 default :
101 break ;
102 }
103 if (bSartAnimation)
104 {
105 pData->iCurrentEffect = iEffect;
106 }
107 }
108 else // si on a un pData, c'est qu'on etait deja en pleine animation, on garde la meme, qui partira en sens inverse a partir du temps actuel.
109 {
110 pData->sens = (pIcon->fInsertRemoveFactor > 0 ? 1 : -1);
111 }
112
113 return GLDI_NOTIFICATION_LET_PASS;
114 }
115
116
117 gboolean cd_illusion_render_icon (gpointer pUserData, Icon *pIcon, CairoDock *pDock, gboolean *bHasBeenRendered, cairo_t *pCairoContext)
118 {
119 if (pCairoContext != NULL || *bHasBeenRendered)
120 return GLDI_NOTIFICATION_LET_PASS;
121 CDIllusionData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
122 if (pData == NULL)
123 return GLDI_NOTIFICATION_LET_PASS;
124
125 switch (pData->iCurrentEffect)
126 {
127 case CD_ILLUSION_EVAPORATE :
128 cd_illusion_draw_evaporate_icon (pIcon, pDock, pData);
129 *bHasBeenRendered = TRUE;
130 break ;
131 case CD_ILLUSION_FADE_OUT :
132 cd_illusion_draw_fade_out_icon (pIcon, pDock, pData);
133 break ;
134 case CD_ILLUSION_EXPLODE :
135 cd_illusion_draw_explode_icon (pIcon, pDock, pData);
136 *bHasBeenRendered = TRUE;
137 break ;
138 case CD_ILLUSION_BREAK :
139 cd_illusion_draw_break_icon (pIcon, pDock, pData);
140 *bHasBeenRendered = TRUE;
141 break ;
142 case CD_ILLUSION_BLACK_HOLE :
143 cd_illusion_draw_black_hole_icon (pIcon, pDock, pData);
144 *bHasBeenRendered = TRUE;
145 break ;
146 case CD_ILLUSION_LIGHTNING :
147 cd_illusion_draw_lightning_icon (pIcon, pDock, pData);
148 *bHasBeenRendered = TRUE;
149 break ;
150 default :
151 break ;
152 }
153
154 return GLDI_NOTIFICATION_LET_PASS;
155 }
156
157
158 gboolean cd_illusion_update_icon (gpointer pUserData, Icon *pIcon, CairoDock *pDock, gboolean *bContinueAnimation)
159 {
160 CDIllusionData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
161 if (pData == NULL)
162 return GLDI_NOTIFICATION_LET_PASS;
163
164 pData->fTime += pData->sens * pData->fDeltaT;
165 if (pData->fTime < 0)
166 pData->fTime = 0;
167 switch (pData->iCurrentEffect)
168 {
169 case CD_ILLUSION_EVAPORATE :
170 cd_illusion_update_evaporate (pIcon, pDock, pData);
171 break ;
172 case CD_ILLUSION_FADE_OUT :
173 cd_illusion_update_fade_out (pIcon, pDock, pData);
174 break ;
175 case CD_ILLUSION_EXPLODE :
176 cd_illusion_update_explode (pIcon, pDock, pData);
177 break ;
178 case CD_ILLUSION_BREAK :
179 cd_illusion_update_break (pIcon, pDock, pData);
180 break ;
181 case CD_ILLUSION_BLACK_HOLE :
182 cd_illusion_update_black_hole (pIcon, pDock, pData);
183 break ;
184 case CD_ILLUSION_LIGHTNING :
185 cd_illusion_update_lightning (pIcon, pDock, pData);
186 break ;
187 default :
188 break ;
189 }
190
191 if (pData->sens == 1 && pData->fTime < pData->fTimeLimitPercent * pData->iEffectDuration) // if the icon is disappearing, we keep it at max size until x% of the animation is complete, so that we can see the animation (that's why we register after the core).
192 {
193 pIcon->fInsertRemoveFactor = 1.;
194 *bContinueAnimation = TRUE;
195 }
196
197 if ((pData->sens == 1 && pData->fTime < pData->iEffectDuration)
198 || (pData->sens == -1 && pData->fTime > 0)) // the animation is not yet finished
199 {
200 *bContinueAnimation = TRUE;
201 }
202 else
203 {
204 cd_illusion_free_data (pUserData, pIcon);
205 }
206 return GLDI_NOTIFICATION_LET_PASS;
207 }
208
209
210 gboolean cd_illusion_free_data (gpointer pUserData, Icon *pIcon)
211 {
212 cd_message ("");
213 CDIllusionData *pData = CD_APPLET_GET_MY_ICON_DATA (pIcon);
214 if (pData == NULL)
215 return GLDI_NOTIFICATION_LET_PASS;
216
217 cairo_dock_free_particle_system (pData->pEvaporateSystem);
218
219 g_free (pData->pExplosionPart);
220
221 g_free (pData->pBreakPart);
222
223 g_free (pData->pBlackHolePoints);
224 g_free (pData->pBlackHoleCoords);
225 g_free (pData->pBlackHoleVertices);
226
227 int i;
228 for (i = 0; i < pData->iNbSources; i ++)
229 {
230 g_free (pData->pLightnings[i].pVertexTab);
231 }
232 g_free (pData->pLightnings);
233
234 g_free (pData);
235 CD_APPLET_SET_MY_ICON_DATA (pIcon, NULL);
236 return GLDI_NOTIFICATION_LET_PASS;
237 }