~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-updates

« back to all changes in this revision

Viewing changes to Toons/src/applet-theme.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

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
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
******************************************************************************/
 
28
 
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
 
 
32
#include "applet-struct.h"
 
33
#include "applet-theme.h"
 
34
 
 
35
#define _print_error(erreur) \
 
36
        if (erreur != NULL) {\
 
37
                cd_warning (erreur->message);\
 
38
                g_error_free (erreur);\
 
39
                erreur = NULL; }
 
40
 
 
41
static gchar *group[2] = {"Left eye", "Right eye"};
 
42
 
 
43
gboolean cd_xeyes_load_theme (CairoDockModuleInstance *myApplet)
 
44
{
 
45
        GString *sPath = g_string_new ("");
 
46
        g_string_printf (sPath, "%s/theme.conf", myConfig.cThemePath);
 
47
        
 
48
        GKeyFile *pKeyFile = cairo_dock_open_key_file (sPath->str);
 
49
        g_return_val_if_fail (pKeyFile != NULL, FALSE);
 
50
        GError *erreur = NULL;
 
51
        
 
52
        gboolean bEyeVisible[2] = {FALSE, FALSE};
 
53
        gint iPupilWidth[2], iPupilHeight[2];
 
54
        gint iEyesWidth[2], iEyesHeight[2];
 
55
        gint iXeyes[2], iYeyes[2];
 
56
        gint iXeyelid, iYeyelid;
 
57
        gint iEyelidWidth, iEyelidHeight;
 
58
        gint iXbg, iYbg;
 
59
        gint iToonWidth, iToonHeight;
 
60
        gint iBgWidth, iBgHeight;
 
61
        gchar *cBgImage, *cPupilImage, *cEyelidImage, *cToonImage;
 
62
        
 
63
        cBgImage = g_key_file_get_string (pKeyFile, "Files", "bg image", &erreur);
 
64
        _print_error(erreur);
 
65
        cPupilImage = g_key_file_get_string (pKeyFile, "Files", "pupil image", &erreur);
 
66
        _print_error(erreur);
 
67
        cEyelidImage = g_key_file_get_string (pKeyFile, "Files", "eyelid image", &erreur);
 
68
        _print_error(erreur);
 
69
        cToonImage = g_key_file_get_string (pKeyFile, "Files", "toon image", &erreur);
 
70
        _print_error(erreur);
 
71
        
 
72
        const gchar *cGroupName;
 
73
        int i;
 
74
        for (i = 0; i < 2; i ++)
 
75
        {
 
76
                cGroupName = group[i];
 
77
                if (! g_key_file_has_group (pKeyFile, cGroupName))
 
78
                        continue;
 
79
                
 
80
                bEyeVisible[i] = TRUE;
 
81
                
 
82
                iXeyes[i] = g_key_file_get_integer (pKeyFile, cGroupName, "x center", &erreur);
 
83
                _print_error(erreur);
 
84
                iYeyes[i] = g_key_file_get_integer (pKeyFile, cGroupName, "y center", &erreur);
 
85
                _print_error(erreur);
 
86
                
 
87
                iEyesWidth[i] = g_key_file_get_integer (pKeyFile, cGroupName, "eye width", &erreur);
 
88
                _print_error(erreur);
 
89
                iEyesHeight[i] = g_key_file_get_integer (pKeyFile, cGroupName, "eye height", &erreur);
 
90
                _print_error(erreur);
 
91
                
 
92
                iPupilWidth[i] = g_key_file_get_integer (pKeyFile, cGroupName, "pupil width", &erreur);
 
93
                _print_error(erreur);
 
94
                iPupilHeight[i] = g_key_file_get_integer (pKeyFile, cGroupName, "pupil height", &erreur);
 
95
                _print_error(erreur);
 
96
        }
 
97
        
 
98
        iXeyelid = g_key_file_get_integer (pKeyFile, "Eyelid", "x", &erreur);
 
99
        _print_error(erreur);
 
100
        iYeyelid = g_key_file_get_integer (pKeyFile, "Eyelid", "y", &erreur);
 
101
        _print_error(erreur);
 
102
        iEyelidWidth = g_key_file_get_integer (pKeyFile, "Eyelid", "width", &erreur);
 
103
        _print_error(erreur);
 
104
        iEyelidHeight = g_key_file_get_integer (pKeyFile, "Eyelid", "height", &erreur);
 
105
        _print_error(erreur);
 
106
        
 
107
        iXbg = g_key_file_get_integer (pKeyFile, "Background", "x", &erreur);
 
108
        _print_error(erreur);
 
109
        iYbg = g_key_file_get_integer (pKeyFile, "Background", "y", &erreur);
 
110
        _print_error(erreur);
 
111
        iBgWidth = g_key_file_get_integer (pKeyFile, "Background", "width", &erreur);
 
112
        _print_error(erreur);
 
113
        iBgHeight = g_key_file_get_integer (pKeyFile, "Background", "height", &erreur);
 
114
        _print_error(erreur);
 
115
        
 
116
        int iWidth, iHeight;
 
117
        CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
 
118
        
 
119
        double fImageWidth, fImageHeight;
 
120
        double fZoomX = 1., fZoomY = 1.;
 
121
        g_string_printf (sPath, "%s/%s", myConfig.cThemePath, cToonImage);
 
122
        myData.pToonSurface = cairo_dock_create_surface_from_image (sPath->str,
 
123
                myDrawContext,
 
124
                1.,
 
125
                iWidth, iHeight,
 
126
                myConfig.iLoadingModifier,
 
127
                &fImageWidth, &fImageHeight,
 
128
                &fZoomX, &fZoomY);
 
129
        myData.iToonWidth = fImageWidth;
 
130
        myData.iToonHeight = fImageHeight;
 
131
        
 
132
        double dx = .5*(iWidth - myData.iToonWidth);  // offset du au 'keep ratio'.
 
133
        double dy = .5*(iHeight - myData.iToonHeight);
 
134
        
 
135
        g_string_printf (sPath, "%s/%s", myConfig.cThemePath, cPupilImage);
 
136
        for (i = 0; i < 2; i ++)
 
137
        {
 
138
                if (bEyeVisible[i])
 
139
                {
 
140
                        myData.pPupilSurface[i] = cairo_dock_create_surface_from_image (sPath->str,
 
141
                                myDrawContext,
 
142
                                1.,
 
143
                                iPupilWidth[i] * fZoomX, iPupilHeight[i] * fZoomY,
 
144
                                myConfig.iLoadingModifier,
 
145
                                &fImageWidth, &fImageHeight,
 
146
                                NULL, NULL);
 
147
                        myData.iPupilWidth[i] = fImageWidth;
 
148
                        myData.iPupilHeight[i] = fImageHeight;
 
149
                        
 
150
                        myData.iXeyes[i] = iXeyes[i] * fZoomX + dx;
 
151
                        myData.iYeyes[i] = iYeyes[i] * fZoomY + dy;
 
152
                        
 
153
                        myData.iEyesWidth[i] = iEyesWidth[i] * fZoomX;
 
154
                        myData.iEyesHeight[i] = iEyesHeight[i] * fZoomY;
 
155
                }
 
156
        }
 
157
        
 
158
        g_string_printf (sPath, "%s/%s", myConfig.cThemePath, cEyelidImage);
 
159
        myData.pEyelidSurface = cairo_dock_create_surface_from_image (sPath->str,
 
160
                myDrawContext,
 
161
                1.,
 
162
                iEyelidWidth * fZoomX, iEyelidHeight * fZoomY,
 
163
                myConfig.iLoadingModifier,
 
164
                &fImageWidth, &fImageHeight,
 
165
                NULL, NULL);
 
166
        myData.iEyelidWidth = fImageWidth;
 
167
        myData.iEyelidHeight = fImageHeight;
 
168
        myData.iXeyelid = iXeyelid * fZoomX + dx;
 
169
        myData.iYeyelid = iYeyelid * fZoomY + dy;
 
170
        //g_print ("eyelid : %dx%d ; (%d;%d)\n", myData.iEyelidWidth, myData.iEyelidHeight, myData.iXeyelid, myData.iYeyelid);
 
171
        
 
172
        if (cBgImage != NULL && *cBgImage != '\0')
 
173
        {
 
174
                g_string_printf (sPath, "%s/%s", myConfig.cThemePath, cBgImage);
 
175
                myData.pBgSurface = cairo_dock_create_surface_from_image (sPath->str,
 
176
                        myDrawContext,
 
177
                        1.,
 
178
                        iBgWidth * fZoomX, iBgHeight * fZoomY,
 
179
                        myConfig.iLoadingModifier,
 
180
                        &fImageWidth, &fImageHeight,
 
181
                        NULL, NULL);
 
182
                myData.iBgWidth = fImageWidth;
 
183
                myData.iBgHeight = fImageHeight;
 
184
                myData.iXbg = iXbg * fZoomX + dx;
 
185
                myData.iYbg = iYbg * fZoomY + dy;
 
186
        }
 
187
        
 
188
        if (g_bUseOpenGL)
 
189
        {
 
190
                myData.iBgTexture = cairo_dock_create_texture_from_surface (myData.pBgSurface);
 
191
                if (myData.pPupilSurface[0])
 
192
                        myData.iPupilTexture[0] = cairo_dock_create_texture_from_surface (myData.pPupilSurface[0]);
 
193
                if (myData.pPupilSurface[1])
 
194
                        myData.iPupilTexture[1] = cairo_dock_create_texture_from_surface (myData.pPupilSurface[1]);
 
195
                myData.iEyelidTexture = cairo_dock_create_texture_from_surface (myData.pEyelidSurface);
 
196
                if (myData.pToonSurface)
 
197
                        myData.iToonTexture = cairo_dock_create_texture_from_surface (myData.pToonSurface);
 
198
        }
 
199
        
 
200
        g_free (cBgImage);
 
201
        g_free (cPupilImage);
 
202
        g_free (cEyelidImage);
 
203
        g_free (cToonImage);
 
204
        g_string_free (sPath, TRUE);
 
205
        g_key_file_free (pKeyFile);
 
206
        
 
207
        return TRUE;
 
208
}
 
209
 
 
210
 
 
211
void cd_xeyes_unload_theme (CairoDockModuleInstance *myApplet)
 
212
{
 
213
        int i;
 
214
        for (i = 0; i < 2; i ++)
 
215
        {
 
216
                if (myData.pPupilSurface[i])
 
217
                {
 
218
                        cairo_surface_destroy (myData.pPupilSurface[i]);
 
219
                        myData.pPupilSurface[i] = NULL;
 
220
                }
 
221
                if (myData.iPupilTexture[i])
 
222
                {
 
223
                        _cairo_dock_delete_texture (myData.iPupilTexture[i]);
 
224
                        myData.iPupilTexture[i] = 0;
 
225
                }
 
226
        }
 
227
        
 
228
        if (myData.pBgSurface)
 
229
        {
 
230
                cairo_surface_destroy (myData.pBgSurface);
 
231
                myData.pBgSurface = NULL;
 
232
        }
 
233
        if (myData.iBgTexture)
 
234
        {
 
235
                _cairo_dock_delete_texture (myData.iBgTexture);
 
236
                myData.iBgTexture = 0;
 
237
        }
 
238
        
 
239
        if (myData.pEyelidSurface)
 
240
        {
 
241
                cairo_surface_destroy (myData.pEyelidSurface);
 
242
                myData.pEyelidSurface = NULL;
 
243
        }
 
244
        if (myData.iEyelidTexture)
 
245
        {
 
246
                _cairo_dock_delete_texture (myData.iEyelidTexture);
 
247
                myData.iEyelidTexture = 0;
 
248
        }
 
249
        
 
250
        if (myData.pToonSurface)
 
251
        {
 
252
                cairo_surface_destroy (myData.pToonSurface);
 
253
                myData.pToonSurface = NULL;
 
254
        }
 
255
        if (myData.iToonTexture)
 
256
        {
 
257
                _cairo_dock_delete_texture (myData.iToonTexture);
 
258
                myData.iToonTexture = 0;
 
259
        }
 
260
}