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
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
27
******************************************************************************/
32
#include "applet-struct.h"
33
#include "applet-theme.h"
35
#define _print_error(erreur) \
36
if (erreur != NULL) {\
37
cd_warning (erreur->message);\
38
g_error_free (erreur);\
41
static gchar *group[2] = {"Left eye", "Right eye"};
43
gboolean cd_xeyes_load_theme (CairoDockModuleInstance *myApplet)
45
GString *sPath = g_string_new ("");
46
g_string_printf (sPath, "%s/theme.conf", myConfig.cThemePath);
48
GKeyFile *pKeyFile = cairo_dock_open_key_file (sPath->str);
49
g_return_val_if_fail (pKeyFile != NULL, FALSE);
50
GError *erreur = NULL;
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;
59
gint iToonWidth, iToonHeight;
60
gint iBgWidth, iBgHeight;
61
gchar *cBgImage, *cPupilImage, *cEyelidImage, *cToonImage;
63
cBgImage = g_key_file_get_string (pKeyFile, "Files", "bg image", &erreur);
65
cPupilImage = g_key_file_get_string (pKeyFile, "Files", "pupil image", &erreur);
67
cEyelidImage = g_key_file_get_string (pKeyFile, "Files", "eyelid image", &erreur);
69
cToonImage = g_key_file_get_string (pKeyFile, "Files", "toon image", &erreur);
72
const gchar *cGroupName;
74
for (i = 0; i < 2; i ++)
76
cGroupName = group[i];
77
if (! g_key_file_has_group (pKeyFile, cGroupName))
80
bEyeVisible[i] = TRUE;
82
iXeyes[i] = g_key_file_get_integer (pKeyFile, cGroupName, "x center", &erreur);
84
iYeyes[i] = g_key_file_get_integer (pKeyFile, cGroupName, "y center", &erreur);
87
iEyesWidth[i] = g_key_file_get_integer (pKeyFile, cGroupName, "eye width", &erreur);
89
iEyesHeight[i] = g_key_file_get_integer (pKeyFile, cGroupName, "eye height", &erreur);
92
iPupilWidth[i] = g_key_file_get_integer (pKeyFile, cGroupName, "pupil width", &erreur);
94
iPupilHeight[i] = g_key_file_get_integer (pKeyFile, cGroupName, "pupil height", &erreur);
98
iXeyelid = g_key_file_get_integer (pKeyFile, "Eyelid", "x", &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);
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);
117
CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
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,
126
myConfig.iLoadingModifier,
127
&fImageWidth, &fImageHeight,
129
myData.iToonWidth = fImageWidth;
130
myData.iToonHeight = fImageHeight;
132
double dx = .5*(iWidth - myData.iToonWidth); // offset du au 'keep ratio'.
133
double dy = .5*(iHeight - myData.iToonHeight);
135
g_string_printf (sPath, "%s/%s", myConfig.cThemePath, cPupilImage);
136
for (i = 0; i < 2; i ++)
140
myData.pPupilSurface[i] = cairo_dock_create_surface_from_image (sPath->str,
143
iPupilWidth[i] * fZoomX, iPupilHeight[i] * fZoomY,
144
myConfig.iLoadingModifier,
145
&fImageWidth, &fImageHeight,
147
myData.iPupilWidth[i] = fImageWidth;
148
myData.iPupilHeight[i] = fImageHeight;
150
myData.iXeyes[i] = iXeyes[i] * fZoomX + dx;
151
myData.iYeyes[i] = iYeyes[i] * fZoomY + dy;
153
myData.iEyesWidth[i] = iEyesWidth[i] * fZoomX;
154
myData.iEyesHeight[i] = iEyesHeight[i] * fZoomY;
158
g_string_printf (sPath, "%s/%s", myConfig.cThemePath, cEyelidImage);
159
myData.pEyelidSurface = cairo_dock_create_surface_from_image (sPath->str,
162
iEyelidWidth * fZoomX, iEyelidHeight * fZoomY,
163
myConfig.iLoadingModifier,
164
&fImageWidth, &fImageHeight,
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);
172
if (cBgImage != NULL && *cBgImage != '\0')
174
g_string_printf (sPath, "%s/%s", myConfig.cThemePath, cBgImage);
175
myData.pBgSurface = cairo_dock_create_surface_from_image (sPath->str,
178
iBgWidth * fZoomX, iBgHeight * fZoomY,
179
myConfig.iLoadingModifier,
180
&fImageWidth, &fImageHeight,
182
myData.iBgWidth = fImageWidth;
183
myData.iBgHeight = fImageHeight;
184
myData.iXbg = iXbg * fZoomX + dx;
185
myData.iYbg = iYbg * fZoomY + dy;
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);
201
g_free (cPupilImage);
202
g_free (cEyelidImage);
204
g_string_free (sPath, TRUE);
205
g_key_file_free (pKeyFile);
211
void cd_xeyes_unload_theme (CairoDockModuleInstance *myApplet)
214
for (i = 0; i < 2; i ++)
216
if (myData.pPupilSurface[i])
218
cairo_surface_destroy (myData.pPupilSurface[i]);
219
myData.pPupilSurface[i] = NULL;
221
if (myData.iPupilTexture[i])
223
_cairo_dock_delete_texture (myData.iPupilTexture[i]);
224
myData.iPupilTexture[i] = 0;
228
if (myData.pBgSurface)
230
cairo_surface_destroy (myData.pBgSurface);
231
myData.pBgSurface = NULL;
233
if (myData.iBgTexture)
235
_cairo_dock_delete_texture (myData.iBgTexture);
236
myData.iBgTexture = 0;
239
if (myData.pEyelidSurface)
241
cairo_surface_destroy (myData.pEyelidSurface);
242
myData.pEyelidSurface = NULL;
244
if (myData.iEyelidTexture)
246
_cairo_dock_delete_texture (myData.iEyelidTexture);
247
myData.iEyelidTexture = 0;
250
if (myData.pToonSurface)
252
cairo_surface_destroy (myData.pToonSurface);
253
myData.pToonSurface = NULL;
255
if (myData.iToonTexture)
257
_cairo_dock_delete_texture (myData.iToonTexture);
258
myData.iToonTexture = 0;