2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
20
#include "applet-struct.h"
21
#include "applet-notifications.h"
22
#include "applet-busy.h"
24
static void init (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, double dt, gboolean bUseOpenGL)
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",
30
CAIRO_DOCK_ANIMATED_IMAGE);
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);
38
static gboolean update (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, double dt, gboolean bUseOpenGL, gboolean bRepeat)
40
if (! cairo_dock_image_buffer_is_animated (pData->pBusyImage))
43
double fPrevFrame = pData->pBusyImage->iCurrentFrame;
44
cairo_dock_image_buffer_next_frame (pData->pBusyImage);
46
cairo_dock_redraw_icon (pIcon, CAIRO_CONTAINER (pDock));
48
return (pData->pBusyImage->iCurrentFrame > fPrevFrame);
51
static void post_render (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, cairo_t *pCairoContext)
53
g_return_if_fail (pData->pBusyImage);
57
cairo_save (pCairoContext);
59
cairo_translate (pCairoContext,
60
pIcon->fWidth * pIcon->fScale / 2,
61
pIcon->fHeight * pIcon->fScale / 2);
62
double z = MIN (pIcon->fScale * pIcon->fWidth / (pData->pBusyImage->iWidth / pData->pBusyImage->iNbFrames), pIcon->fScale * pIcon->fHeight / pData->pBusyImage->iHeight) * myConfig.fBusySize;
63
cairo_scale (pCairoContext, z, z);
65
cairo_translate (pCairoContext,
66
-pData->pBusyImage->iWidth/pData->pBusyImage->iNbFrames/2,
67
-pData->pBusyImage->iHeight/2);
69
cairo_dock_apply_image_buffer_surface (pData->pBusyImage, pCairoContext);
71
cairo_restore (pCairoContext);
75
_cairo_dock_enable_texture ();
76
if (pIcon->fAlpha == 1)
77
_cairo_dock_set_blend_over ();
79
_cairo_dock_set_blend_alpha ();
81
double z = MIN (pIcon->fScale * pIcon->fWidth / (pData->pBusyImage->iWidth / pData->pBusyImage->iNbFrames), pIcon->fScale * pIcon->fHeight / pData->pBusyImage->iHeight) * myConfig.fBusySize;
84
cairo_dock_apply_image_buffer_texture (pData->pBusyImage);
86
_cairo_dock_disable_texture ();
91
void cd_animations_register_busy (void)
93
CDAnimation *pAnimation = &myData.pAnimations[CD_ANIMATIONS_BUSY];
94
pAnimation->cName = "busy";
95
pAnimation->cDisplayedName = D_("Busy");
96
pAnimation->id = CD_ANIMATIONS_BUSY;
97
pAnimation->bDrawIcon = FALSE;
98
pAnimation->bDrawReflect = FALSE;
99
pAnimation->init = init;
100
pAnimation->update = update;
101
pAnimation->render = NULL;
102
pAnimation->post_render = post_render;
103
cd_animations_register_animation (pAnimation);