| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <stdlib.h> |
| 21 |
#include <string.h> |
| 22 |
|
| 23 |
#include "applet-struct.h" |
| 24 |
#include "applet-theme.h" |
| 25 |
|
| 26 |
|
| 27 |
static gchar * _penguin_get_animation_properties (GKeyFile *pKeyFile, const gchar *cAnimationName, PenguinAnimation *pAnimation, PenguinAnimation *pDefaultAnimation) |
| 28 |
{ |
| 29 |
if (! g_key_file_has_group (pKeyFile, cAnimationName)) |
| 30 |
return NULL; |
| 31 |
cd_debug ("%s (%s)", __func__, cAnimationName); |
| 32 |
|
| 33 |
gchar *cFileName = g_key_file_get_string (pKeyFile, cAnimationName, "file", NULL); |
| 34 |
if (cFileName != NULL && *cFileName == '\0') |
| 35 |
{ |
| 36 |
g_free (cFileName); |
| 37 |
cFileName = NULL; |
| 38 |
} |
| 39 |
|
| 40 |
GError *erreur = NULL; |
| 41 |
pAnimation->iNbDirections = g_key_file_get_integer (pKeyFile, cAnimationName, "nb directions", &erreur); |
| 42 |
if (erreur != NULL) |
| 43 |
{ |
| 44 |
pAnimation->iNbDirections = pDefaultAnimation->iNbDirections; |
| 45 |
g_error_free (erreur); |
| 46 |
erreur = NULL; |
| 47 |
} |
| 48 |
|
| 49 |
pAnimation->iNbFrames = g_key_file_get_integer (pKeyFile, cAnimationName, "nb frames", &erreur); |
| 50 |
if (erreur != NULL) |
| 51 |
{ |
| 52 |
pAnimation->iNbFrames = pDefaultAnimation->iNbFrames; |
| 53 |
g_error_free (erreur); |
| 54 |
erreur = NULL; |
| 55 |
} |
| 56 |
|
| 57 |
pAnimation->iSpeed = g_key_file_get_integer (pKeyFile, cAnimationName, "speed", &erreur); |
| 58 |
if (erreur != NULL) |
| 59 |
{ |
| 60 |
pAnimation->iSpeed = pDefaultAnimation->iSpeed; |
| 61 |
g_error_free (erreur); |
| 62 |
erreur = NULL; |
| 63 |
} |
| 64 |
|
| 65 |
pAnimation->iAcceleration = g_key_file_get_integer (pKeyFile, cAnimationName, "acceleration", &erreur); |
| 66 |
if (erreur != NULL) |
| 67 |
{ |
| 68 |
pAnimation->iAcceleration = pDefaultAnimation->iAcceleration; |
| 69 |
g_error_free (erreur); |
| 70 |
erreur = NULL; |
| 71 |
} |
| 72 |
|
| 73 |
pAnimation->iTerminalVelocity = g_key_file_get_integer (pKeyFile, cAnimationName, "terminal velocity", &erreur); |
| 74 |
if (erreur != NULL) |
| 75 |
{ |
| 76 |
pAnimation->iTerminalVelocity = pDefaultAnimation->iTerminalVelocity; |
| 77 |
g_error_free (erreur); |
| 78 |
erreur = NULL; |
| 79 |
} |
| 80 |
|
| 81 |
pAnimation->bEnding = g_key_file_get_boolean (pKeyFile, cAnimationName, "ending", &erreur); |
| 82 |
if (erreur != NULL) |
| 83 |
{ |
| 84 |
pAnimation->bEnding = pDefaultAnimation->bEnding; |
| 85 |
g_error_free (erreur); |
| 86 |
erreur = NULL; |
| 87 |
} |
| 88 |
|
| 89 |
pAnimation->iDirection = g_key_file_get_integer (pKeyFile, cAnimationName, "direction", &erreur); |
| 90 |
if (erreur != NULL) |
| 91 |
{ |
| 92 |
pAnimation->iDirection = pDefaultAnimation->iDirection; |
| 93 |
g_error_free (erreur); |
| 94 |
erreur = NULL; |
| 95 |
} |
| 96 |
|
| 97 |
return cFileName; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
void penguin_load_theme (GldiModuleInstance *myApplet, gchar *cThemePath) |
| 102 |
{ |
| 103 |
g_return_if_fail (cThemePath != NULL); |
| 104 |
cd_message ("%s (%s)", __func__, cThemePath); |
| 105 |
|
| 106 |
|
| 107 |
gchar *cConfFilePath = g_strconcat (cThemePath, "/theme.conf", NULL); |
| 108 |
GError *erreur = NULL; |
| 109 |
GKeyFile *pKeyFile = g_key_file_new (); |
| 110 |
g_key_file_load_from_file (pKeyFile, cConfFilePath, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &erreur); |
| 111 |
if (erreur != NULL) |
| 112 |
{ |
| 113 |
cd_warning ("Cairo-Penguin : %s", erreur->message); |
| 114 |
g_error_free (erreur); |
| 115 |
return ; |
| 116 |
} |
| 117 |
|
| 118 |
myData.fFrameDelay = (double) g_key_file_get_integer (pKeyFile, "Theme", "delay", &erreur) * 1e-3; |
| 119 |
if (erreur != NULL) |
| 120 |
{ |
| 121 |
cd_warning ("Cairo-Penguin : %s", erreur->message); |
| 122 |
myData.fFrameDelay = .1; |
| 123 |
g_error_free (erreur); |
| 124 |
erreur = NULL; |
| 125 |
} |
| 126 |
|
| 127 |
_penguin_get_animation_properties (pKeyFile, "Default", &myData.defaultAnimation, &myData.defaultAnimation); |
| 128 |
|
| 129 |
gsize length = 0; |
| 130 |
gchar **pGroupList = g_key_file_get_groups (pKeyFile, &length); |
| 131 |
g_return_if_fail (length > 0); |
| 132 |
|
| 133 |
g_free (myData.pAnimations); |
| 134 |
myData.iNbAnimations = 0; |
| 135 |
myData.pAnimations = g_new0 (PenguinAnimation, length - 1); |
| 136 |
|
| 137 |
g_free (myData.pBeginningAnimations); |
| 138 |
myData.iNbBeginningAnimations = 0; |
| 139 |
myData.pBeginningAnimations = g_new0 (int, length - 1); |
| 140 |
|
| 141 |
g_free (myData.pEndingAnimations); |
| 142 |
myData.iNbEndingAnimations = 0; |
| 143 |
myData.pEndingAnimations = g_new0 (int, length - 1); |
| 144 |
|
| 145 |
g_free (myData.pGoUpAnimations); |
| 146 |
myData.iNbGoUpAnimations = 0; |
| 147 |
myData.pGoUpAnimations = g_new0 (int, length - 1); |
| 148 |
|
| 149 |
g_free (myData.pMovmentAnimations); |
| 150 |
myData.iNbMovmentAnimations = 0; |
| 151 |
myData.pMovmentAnimations = g_new0 (int, length - 1); |
| 152 |
|
| 153 |
g_free (myData.pRestAnimations); |
| 154 |
myData.iNbRestAnimations = 0; |
| 155 |
myData.pRestAnimations = g_new0 (int, length - 1); |
| 156 |
|
| 157 |
PenguinAnimation *pAnimation; |
| 158 |
gchar *cFileName, *cGroupName; |
| 159 |
int i, iNumAnimation = 0; |
| 160 |
for (i = 0; pGroupList[i] != NULL; i++) |
| 161 |
{ |
| 162 |
cGroupName = pGroupList[i]; |
| 163 |
if (strcmp (cGroupName, "Theme") != 0 && strcmp (cGroupName, "Default") != 0) |
| 164 |
{ |
| 165 |
pAnimation = &myData.pAnimations[iNumAnimation]; |
| 166 |
|
| 167 |
cFileName = _penguin_get_animation_properties (pKeyFile, cGroupName, pAnimation, &myData.defaultAnimation); |
| 168 |
if (cFileName != NULL) |
| 169 |
{ |
| 170 |
pAnimation->cFilePath = g_strconcat (cThemePath, "/", cFileName, NULL); |
| 171 |
g_free (cFileName); |
| 172 |
} |
| 173 |
if (pAnimation->bEnding) |
| 174 |
{ |
| 175 |
myData.pEndingAnimations[myData.iNbEndingAnimations++] = iNumAnimation; |
| 176 |
cd_debug (" %s : ending", pAnimation->cFilePath); |
| 177 |
} |
| 178 |
else if (pAnimation->iDirection == PENGUIN_DOWN) |
| 179 |
{ |
| 180 |
myData.pBeginningAnimations[myData.iNbBeginningAnimations++] = iNumAnimation; |
| 181 |
cd_debug (" %s : beginning", pAnimation->cFilePath); |
| 182 |
} |
| 183 |
else if (pAnimation->iDirection == PENGUIN_UP) |
| 184 |
{ |
| 185 |
myData.pGoUpAnimations[myData.iNbGoUpAnimations++] = iNumAnimation; |
| 186 |
cd_debug (" %s : go up", pAnimation->cFilePath); |
| 187 |
} |
| 188 |
else if (pAnimation->iSpeed == 0 && pAnimation->iAcceleration == 0 && pAnimation->iNbFrames == 1) |
| 189 |
{ |
| 190 |
myData.pRestAnimations[myData.iNbRestAnimations++] = iNumAnimation; |
| 191 |
cd_debug (" %s : rest", pAnimation->cFilePath); |
| 192 |
} |
| 193 |
else |
| 194 |
{ |
| 195 |
myData.pMovmentAnimations[myData.iNbMovmentAnimations++] = iNumAnimation; |
| 196 |
cd_debug (" %s : moving", pAnimation->cFilePath); |
| 197 |
} |
| 198 |
|
| 199 |
iNumAnimation ++; |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
g_strfreev (pGroupList); |
| 204 |
g_free (cConfFilePath); |
| 205 |
g_key_file_free (pKeyFile); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
void penguin_load_animation_buffer (PenguinAnimation *pAnimation, cairo_t *pSourceContext, double fAlpha, gboolean bLoadTexture) |
| 210 |
{ |
| 211 |
cd_debug ("%s (%s)", __func__, pAnimation->cFilePath); |
| 212 |
if (pAnimation->cFilePath == NULL) |
| 213 |
return; |
| 214 |
|
| 215 |
CairoDockImageBuffer *pImageBuffer = cairo_dock_create_image_buffer (pAnimation->cFilePath, |
| 216 |
0, |
| 217 |
0, |
| 218 |
0); |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
pAnimation->iFrameWidth = (int) pImageBuffer->iWidth / pAnimation->iNbFrames; |
| 230 |
pAnimation->iFrameHeight = (int) pImageBuffer->iHeight / pAnimation->iNbDirections; |
| 231 |
cd_debug (" surface chargee (%dx%d)", pAnimation->iFrameWidth, pAnimation->iFrameHeight); |
| 232 |
if (bLoadTexture) |
| 233 |
{ |
| 234 |
pAnimation->iTexture = pImageBuffer->iTexture; |
| 235 |
pImageBuffer->iTexture = 0; |
| 236 |
} |
| 237 |
else if (pImageBuffer->pSurface != NULL) |
| 238 |
{ |
| 239 |
pAnimation->pSurfaces = g_new (cairo_surface_t **, pAnimation->iNbDirections); |
| 240 |
int i, j; |
| 241 |
for (i = 0; i < pAnimation->iNbDirections; i ++) |
| 242 |
{ |
| 243 |
pAnimation->pSurfaces[i] = g_new (cairo_surface_t *, pAnimation->iNbFrames); |
| 244 |
for (j = 0; j < pAnimation->iNbFrames; j ++) |
| 245 |
{ |
| 246 |
|
| 247 |
pAnimation->pSurfaces[i][j] = cairo_surface_create_similar (cairo_get_target (pSourceContext), |
| 248 |
CAIRO_CONTENT_COLOR_ALPHA, |
| 249 |
pAnimation->iFrameWidth, |
| 250 |
pAnimation->iFrameHeight); |
| 251 |
cairo_t *pCairoContext = cairo_create (pAnimation->pSurfaces[i][j]); |
| 252 |
|
| 253 |
cairo_set_source_surface (pCairoContext, |
| 254 |
pImageBuffer->pSurface, |
| 255 |
- j * pAnimation->iFrameWidth, |
| 256 |
- i * pAnimation->iFrameHeight); |
| 257 |
cairo_paint (pCairoContext); |
| 258 |
|
| 259 |
cairo_destroy (pCairoContext); |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
cairo_dock_free_image_buffer (pImageBuffer); |
| 264 |
} |