1
/******************************************************************************
3
This file is a part of the cairo-dock program,
4
released under the terms of the GNU General Public License.
6
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
8
******************************************************************************/
13
#include "applet-struct.h"
14
#include "applet-theme.h"
16
#define _print_error(erreur) \
17
if (erreur != NULL) {\
18
cd_warning (erreur->message);\
19
g_error_free (erreur);\
22
static gchar *group[2] = {"Left eye", "Right eye"};
24
gboolean cd_xeyes_load_theme (CairoDockModuleInstance *myApplet)
26
GString *sPath = g_string_new ("");
27
g_string_printf (sPath, "%s/theme.conf", myConfig.cThemePath);
28
g_print ("theme conf : %s\n", sPath->str);
30
GKeyFile *pKeyFile = cairo_dock_open_key_file (sPath->str);
31
g_return_val_if_fail (pKeyFile != NULL, FALSE);
32
GError *erreur = NULL;
34
gboolean bEyeVisible[2] = {FALSE, FALSE};
35
gint iPupilWidth[2], iPupilHeight[2];
36
gint iEyesWidth[2], iEyesHeight[2];
37
gint iXeyes[2], iYeyes[2];
38
gint iXeyelid, iYeyelid;
39
gint iEyelidWidth, iEyelidHeight;
41
gint iToonWidth, iToonHeight;
42
gint iBgWidth, iBgHeight;
43
gchar *cBgImage, *cPupilImage, *cEyelidImage, *cToonImage;
45
cBgImage = g_key_file_get_string (pKeyFile, "Files", "bg image", &erreur);
47
cPupilImage = g_key_file_get_string (pKeyFile, "Files", "pupil image", &erreur);
49
cEyelidImage = g_key_file_get_string (pKeyFile, "Files", "eyelid image", &erreur);
51
cToonImage = g_key_file_get_string (pKeyFile, "Files", "toon image", &erreur);
54
const gchar *cGroupName;
56
for (i = 0; i < 2; i ++)
58
cGroupName = group[i];
59
if (! g_key_file_has_group (pKeyFile, cGroupName))
62
bEyeVisible[i] = TRUE;
64
iXeyes[i] = g_key_file_get_integer (pKeyFile, cGroupName, "x center", &erreur);
66
iYeyes[i] = g_key_file_get_integer (pKeyFile, cGroupName, "y center", &erreur);
69
iEyesWidth[i] = g_key_file_get_integer (pKeyFile, cGroupName, "eye width", &erreur);
71
iEyesHeight[i] = g_key_file_get_integer (pKeyFile, cGroupName, "eye height", &erreur);
74
iPupilWidth[i] = g_key_file_get_integer (pKeyFile, cGroupName, "pupil width", &erreur);
76
iPupilHeight[i] = g_key_file_get_integer (pKeyFile, cGroupName, "pupil height", &erreur);
80
iXeyelid = g_key_file_get_integer (pKeyFile, "Eyelid", "x", &erreur);
82
iYeyelid = g_key_file_get_integer (pKeyFile, "Eyelid", "y", &erreur);
84
iEyelidWidth = g_key_file_get_integer (pKeyFile, "Eyelid", "width", &erreur);
86
iEyelidHeight = g_key_file_get_integer (pKeyFile, "Eyelid", "height", &erreur);
89
iXbg = g_key_file_get_integer (pKeyFile, "Background", "x", &erreur);
91
iYbg = g_key_file_get_integer (pKeyFile, "Background", "y", &erreur);
93
iBgWidth = g_key_file_get_integer (pKeyFile, "Background", "width", &erreur);
95
iBgHeight = g_key_file_get_integer (pKeyFile, "Background", "height", &erreur);
99
CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
101
double fImageWidth, fImageHeight;
102
double fZoomX = 1., fZoomY = 1.;
103
g_string_printf (sPath, "%s/%s", myConfig.cThemePath, cToonImage);
104
myData.pToonSurface = cairo_dock_create_surface_from_image (sPath->str,
108
myConfig.iLoadingModifier,
109
&fImageWidth, &fImageHeight,
111
myData.iToonWidth = fImageWidth;
112
myData.iToonHeight = fImageHeight;
114
double dx = .5*(iWidth - myData.iToonWidth); // offset du au 'keep ratio'.
115
double dy = .5*(iHeight - myData.iToonHeight);
117
g_string_printf (sPath, "%s/%s", myConfig.cThemePath, cPupilImage);
118
for (i = 0; i < 2; i ++)
122
myData.pPupilSurface[i] = cairo_dock_create_surface_from_image (sPath->str,
125
iPupilWidth[i] * fZoomX, iPupilHeight[i] * fZoomY,
126
myConfig.iLoadingModifier,
127
&fImageWidth, &fImageHeight,
129
myData.iPupilWidth[i] = fImageWidth;
130
myData.iPupilHeight[i] = fImageHeight;
132
myData.iXeyes[i] = iXeyes[i] * fZoomX + dx;
133
myData.iYeyes[i] = iYeyes[i] * fZoomY + dy;
135
myData.iEyesWidth[i] = iEyesWidth[i] * fZoomX;
136
myData.iEyesHeight[i] = iEyesHeight[i] * fZoomY;
140
g_string_printf (sPath, "%s/%s", myConfig.cThemePath, cEyelidImage);
141
myData.pEyelidSurface = cairo_dock_create_surface_from_image (sPath->str,
144
iEyelidWidth * fZoomX, iEyelidHeight * fZoomY,
145
myConfig.iLoadingModifier,
146
&fImageWidth, &fImageHeight,
148
g_print ("eyelid : %.2fx%.2f\n", fImageWidth, fImageHeight);
149
myData.iEyelidWidth = fImageWidth;
150
myData.iEyelidHeight = fImageHeight;
151
myData.iXeyelid = iXeyelid * fZoomX + dx;
152
myData.iYeyelid = iYeyelid * fZoomY + dy;
153
//g_print ("eyelid : %dx%d ; (%d;%d)\n", myData.iEyelidWidth, myData.iEyelidHeight, myData.iXeyelid, myData.iYeyelid);
155
if (cBgImage != NULL && *cBgImage != '\0')
157
g_string_printf (sPath, "%s/%s", myConfig.cThemePath, cBgImage);
158
myData.pBgSurface = cairo_dock_create_surface_from_image (sPath->str,
161
iBgWidth * fZoomX, iBgHeight * fZoomY,
162
myConfig.iLoadingModifier,
163
&fImageWidth, &fImageHeight,
165
myData.iBgWidth = fImageWidth;
166
myData.iBgHeight = fImageHeight;
167
myData.iXbg = iXbg * fZoomX + dx;
168
myData.iYbg = iYbg * fZoomY + dy;
173
myData.iBgTexture = cairo_dock_create_texture_from_surface (myData.pBgSurface);
174
if (myData.pPupilSurface[0])
175
myData.iPupilTexture[0] = cairo_dock_create_texture_from_surface (myData.pPupilSurface[0]);
176
if (myData.pPupilSurface[1])
177
myData.iPupilTexture[1] = cairo_dock_create_texture_from_surface (myData.pPupilSurface[1]);
178
myData.iEyelidTexture = cairo_dock_create_texture_from_surface (myData.pEyelidSurface);
179
if (myData.pToonSurface)
180
myData.iToonTexture = cairo_dock_create_texture_from_surface (myData.pToonSurface);
184
g_free (cPupilImage);
185
g_free (cEyelidImage);
187
g_string_free (sPath, TRUE);
188
g_key_file_free (pKeyFile);
194
void cd_xeyes_unload_theme (CairoDockModuleInstance *myApplet)
197
for (i = 0; i < 2; i ++)
199
if (myData.pPupilSurface[i])
201
cairo_surface_destroy (myData.pPupilSurface[i]);
202
myData.pPupilSurface[i] = NULL;
204
if (myData.iPupilTexture[i])
206
_cairo_dock_delete_texture (myData.iPupilTexture[i]);
207
myData.iPupilTexture[i] = 0;
211
if (myData.pBgSurface)
213
cairo_surface_destroy (myData.pBgSurface);
214
myData.pBgSurface = NULL;
216
if (myData.iBgTexture)
218
_cairo_dock_delete_texture (myData.iBgTexture);
219
myData.iBgTexture = 0;
222
if (myData.pEyelidSurface)
224
cairo_surface_destroy (myData.pEyelidSurface);
225
myData.pEyelidSurface = NULL;
227
if (myData.iEyelidTexture)
229
_cairo_dock_delete_texture (myData.iEyelidTexture);
230
myData.iEyelidTexture = 0;
233
if (myData.pToonSurface)
235
cairo_surface_destroy (myData.pToonSurface);
236
myData.pToonSurface = NULL;
238
if (myData.iToonTexture)
240
_cairo_dock_delete_texture (myData.iToonTexture);
241
myData.iToonTexture = 0;