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

« back to all changes in this revision

Viewing changes to Animated-icons/src/applet-busy.c

  • Committer: Package Import Robot
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2012-08-19 00:37:51 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20120819003751-rcy2836qb5jfj31i
Tags: 3.0.99.beta1-0ubuntu1
* New upstream beta release.
* Upstream ChangeLog (main changes):
 - Better integration of Unity: support of the Launcher API and better
    support of indicators
 - All configuration windows have been merged into a single one.
 - Added progress bars in several applets and in the Dbus API
 - The Music Player applet can control players in the systray.
 - Icons of the taskbar can be separated from launchers or not
 - And as always ... various bug fixes and improvements :-)
* Fixed one bug reported on Launchpad:
 - Bookmark name in thunar wrong when shortcut added on plugin (LP: #995634)
* debian: Used 'wrap-and-sort' tool
* debian/control:
 - Bump Cairo-Dock version
 - Updated my email address
* debian/rules:
 - Added Disks, Global-Menu and Doncky applets.
* debian/cairo-dock-plug-ins.install:
 - Added 'appmenu-registrar' ('Global-Menu' applet)
    and 'cairo-dock-unity-bridge' ('Dbus' applet)

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 "applet-struct.h"
 
21
#include "applet-notifications.h"
 
22
#include "applet-busy.h"
 
23
 
 
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
}
 
37
 
 
38
static gboolean update (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, double dt, gboolean bUseOpenGL, gboolean bRepeat)
 
39
{
 
40
        if (! cairo_dock_image_buffer_is_animated (pData->pBusyImage))
 
41
                return FALSE;
 
42
        
 
43
        double fPrevFrame = pData->pBusyImage->iCurrentFrame;
 
44
        cairo_dock_image_buffer_next_frame (pData->pBusyImage);
 
45
        
 
46
        cairo_dock_redraw_icon (pIcon, CAIRO_CONTAINER (pDock));
 
47
        
 
48
        return (pData->pBusyImage->iCurrentFrame > fPrevFrame);
 
49
}
 
50
 
 
51
static void post_render (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, cairo_t *pCairoContext)
 
52
{
 
53
        g_return_if_fail (pData->pBusyImage);
 
54
        
 
55
        if (pCairoContext)
 
56
        {
 
57
                cairo_save (pCairoContext);
 
58
 
 
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);
 
64
 
 
65
                cairo_translate (pCairoContext,
 
66
                        -pData->pBusyImage->iWidth/pData->pBusyImage->iNbFrames/2,
 
67
                        -pData->pBusyImage->iHeight/2);
 
68
 
 
69
                cairo_dock_apply_image_buffer_surface (pData->pBusyImage, pCairoContext);
 
70
 
 
71
                cairo_restore (pCairoContext);
 
72
        }
 
73
        else
 
74
        {
 
75
                _cairo_dock_enable_texture ();
 
76
                if (pIcon->fAlpha == 1)
 
77
                        _cairo_dock_set_blend_over ();
 
78
                else
 
79
                        _cairo_dock_set_blend_alpha ();
 
80
 
 
81
                double z = MIN (pIcon->fScale * pIcon->fWidth / (pData->pBusyImage->iWidth / pData->pBusyImage->iNbFrames), pIcon->fScale * pIcon->fHeight / pData->pBusyImage->iHeight) * myConfig.fBusySize;
 
82
                glScalef (z, z, 1.);
 
83
 
 
84
                cairo_dock_apply_image_buffer_texture (pData->pBusyImage);
 
85
 
 
86
                _cairo_dock_disable_texture ();
 
87
        }
 
88
}
 
89
 
 
90
 
 
91
void cd_animations_register_busy (void)
 
92
{
 
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);
 
104
}