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 "applet-struct.h"
21 #include "applet-notifications.h"
22 #include "applet-busy.h"
23
init(Icon * pIcon,CairoDock * pDock,CDAnimationData * pData,double dt,gboolean bUseOpenGL)24 static void init (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, double dt, gboolean bUseOpenGL)
25 {
26 // load the busy animation image once, to avoid loading it for each icon.
27 if (myData.pBusyImage == NULL)
28 myData.pBusyImage = cairo_dock_create_image_buffer (myConfig.cBusyImage ? myConfig.cBusyImage : MY_APPLET_SHARE_DATA_DIR"/busy.svg",
29 0, 0,
30 CAIRO_DOCK_ANIMATED_IMAGE);
31
32 // copy the image buffer on the icon, because we'll update the frame number for each icon.
33 g_free (pData->pBusyImage);
34 pData->pBusyImage = g_memdup (myData.pBusyImage, sizeof (CairoDockImageBuffer));
35 cairo_dock_image_buffer_set_timelength (pData->pBusyImage, 1.e-3 * myConfig.iBusyDuration);
36 cairo_dock_image_buffer_rewind (pData->pBusyImage);
37 }
38
update(Icon * pIcon,CairoDock * pDock,CDAnimationData * pData,double dt,gboolean bUseOpenGL,gboolean bRepeat)39 static gboolean update (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, double dt, gboolean bUseOpenGL, gboolean bRepeat)
40 {
41 if (! cairo_dock_image_buffer_is_animated (pData->pBusyImage))
42 return FALSE;
43
44 double fPrevFrame = pData->pBusyImage->iCurrentFrame;
45 cairo_dock_image_buffer_next_frame (pData->pBusyImage);
46
47 cairo_dock_redraw_icon (pIcon);
48
49 return (pData->pBusyImage->iCurrentFrame > fPrevFrame);
50 }
51
post_render(Icon * pIcon,CairoDock * pDock,CDAnimationData * pData,cairo_t * pCairoContext)52 static void post_render (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, cairo_t *pCairoContext)
53 {
54 g_return_if_fail (pData->pBusyImage);
55
56 double s = MIN (pIcon->fScale * pIcon->fWidth, pIcon->fScale * pIcon->fHeight) * myConfig.fBusySize; // size of the drawing (square)
57 if (pCairoContext)
58 {
59 cairo_dock_apply_image_buffer_surface_at_size (pData->pBusyImage, pCairoContext,
60 s, s, // s x s
61 (pIcon->fWidth * pIcon->fScale - s)/2, (pIcon->fHeight * pIcon->fScale - s)/2, // centered on the icon
62 1.);
63 /**cairo_translate (pCairoContext,
64 pIcon->fWidth * pIcon->fScale / 2,
65 pIcon->fHeight * pIcon->fScale / 2);
66
67
68 cairo_save (pCairoContext);
69
70 cairo_translate (pCairoContext,
71 pIcon->fWidth * pIcon->fScale / 2,
72 pIcon->fHeight * pIcon->fScale / 2);
73 double z = MIN (pIcon->fScale * pIcon->fWidth / (pData->pBusyImage->iWidth / pData->pBusyImage->iNbFrames), pIcon->fScale * pIcon->fHeight / pData->pBusyImage->iHeight) * myConfig.fBusySize;
74 cairo_scale (pCairoContext, z, z);
75
76 cairo_translate (pCairoContext,
77 -pData->pBusyImage->iWidth/pData->pBusyImage->iNbFrames/2,
78 -pData->pBusyImage->iHeight/2);
79
80 cairo_dock_apply_image_buffer_surface (pData->pBusyImage, pCairoContext);
81
82 cairo_restore (pCairoContext);*/
83 }
84 else
85 {
86 _cairo_dock_enable_texture ();
87 _cairo_dock_set_blend_over ();
88 _cairo_dock_set_alpha (1.);
89 cairo_dock_apply_image_buffer_texture_at_size (pData->pBusyImage, s, s, 0, 0);
90 _cairo_dock_disable_texture ();
91 /**_cairo_dock_enable_texture ();
92 if (pIcon->fAlpha == 1)
93 _cairo_dock_set_blend_over ();
94 else
95 _cairo_dock_set_blend_alpha ();
96
97 double z = MIN (pIcon->fScale * pIcon->fWidth / (pData->pBusyImage->iWidth / pData->pBusyImage->iNbFrames), pIcon->fScale * pIcon->fHeight / pData->pBusyImage->iHeight) * myConfig.fBusySize;
98 glScalef (z, z, 1.);
99
100 cairo_dock_apply_image_buffer_texture (pData->pBusyImage);
101
102 _cairo_dock_disable_texture ();*/
103 }
104 }
105
106
cd_animations_register_busy(void)107 void cd_animations_register_busy (void)
108 {
109 CDAnimation *pAnimation = &myData.pAnimations[CD_ANIMATIONS_BUSY];
110 pAnimation->cName = "busy";
111 pAnimation->cDisplayedName = D_("Busy");
112 pAnimation->id = CD_ANIMATIONS_BUSY;
113 pAnimation->bDrawIcon = FALSE;
114 pAnimation->bDrawReflect = FALSE;
115 pAnimation->init = init;
116 pAnimation->update = update;
117 pAnimation->render = NULL;
118 pAnimation->post_render = post_render;
119 cd_animations_register_animation (pAnimation);
120 }
121