| File: | ctk/ctkcsskeyframes.c |
| Warning: | line 408, column 15 Access of 'unsigned int' element in the heap area at index 1 |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* CTK - The GIMP Toolkit | |||
| 2 | * Copyright (C) 2011 Red Hat, Inc. | |||
| 3 | * | |||
| 4 | * This library is free software; you can redistribute it and/or | |||
| 5 | * modify it under the terms of the GNU Lesser General Public | |||
| 6 | * License as published by the Free Software Foundation; either | |||
| 7 | * version 2 of the License, or (at your option) any later version. | |||
| 8 | * | |||
| 9 | * This library is distributed in the hope that it will be useful, | |||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 12 | * Lesser General Public License for more details. | |||
| 13 | * | |||
| 14 | * You should have received a copy of the GNU Lesser General Public | |||
| 15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||
| 16 | */ | |||
| 17 | ||||
| 18 | #include "config.h" | |||
| 19 | ||||
| 20 | #include "ctkcsskeyframesprivate.h" | |||
| 21 | ||||
| 22 | #include "ctkcssarrayvalueprivate.h" | |||
| 23 | #include "ctkcssshorthandpropertyprivate.h" | |||
| 24 | #include "ctkcssstylepropertyprivate.h" | |||
| 25 | #include "ctkstylepropertyprivate.h" | |||
| 26 | ||||
| 27 | #include <stdlib.h> | |||
| 28 | #include <string.h> | |||
| 29 | ||||
| 30 | struct _CtkCssKeyframes { | |||
| 31 | int ref_count; /* ref count */ | |||
| 32 | int n_keyframes; /* number of keyframes (at least 2 for 0% and 100% */ | |||
| 33 | double *keyframe_progress; /* ordered array of n_keyframes of [0..1] */ | |||
| 34 | int n_properties; /* number of properties used by keyframes */ | |||
| 35 | guint *property_ids; /* ordered array of n_properties property ids */ | |||
| 36 | CtkCssValue **values; /* 2D array: n_keyframes * n_properties of (value or NULL) for all the keyframes */ | |||
| 37 | }; | |||
| 38 | ||||
| 39 | #define KEYFRAMES_VALUE(keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)]) ((keyframes)->values[(k) * (keyframes)->n_properties + (p)]) | |||
| 40 | ||||
| 41 | CtkCssKeyframes * | |||
| 42 | _ctk_css_keyframes_ref (CtkCssKeyframes *keyframes) | |||
| 43 | { | |||
| 44 | g_return_val_if_fail (keyframes != NULL, NULL)do { if ((keyframes != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "keyframes != NULL"); return (((void*)0)); } } while (0); | |||
| 45 | ||||
| 46 | keyframes->ref_count++; | |||
| 47 | ||||
| 48 | return keyframes; | |||
| 49 | } | |||
| 50 | ||||
| 51 | void | |||
| 52 | _ctk_css_keyframes_unref (CtkCssKeyframes *keyframes) | |||
| 53 | { | |||
| 54 | guint k, p; | |||
| 55 | ||||
| 56 | g_return_if_fail (keyframes != NULL)do { if ((keyframes != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "keyframes != NULL"); return ; } } while (0); | |||
| 57 | ||||
| 58 | keyframes->ref_count--; | |||
| 59 | if (keyframes->ref_count > 0) | |||
| 60 | return; | |||
| 61 | ||||
| 62 | g_free (keyframes->keyframe_progress); | |||
| 63 | g_free (keyframes->property_ids); | |||
| 64 | ||||
| 65 | for (k = 0; k < keyframes->n_keyframes; k++) | |||
| 66 | { | |||
| 67 | for (p = 0; p < keyframes->n_properties; p++) | |||
| 68 | { | |||
| 69 | _ctk_css_value_unref (KEYFRAMES_VALUE (keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)])); | |||
| 70 | KEYFRAMES_VALUE (keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)]) = NULL((void*)0); | |||
| 71 | } | |||
| 72 | } | |||
| 73 | g_free (keyframes->values); | |||
| 74 | ||||
| 75 | g_slice_free (CtkCssKeyframes, keyframes)do { if (1) g_slice_free1 (sizeof (CtkCssKeyframes), (keyframes )); else (void) ((CtkCssKeyframes*) 0 == (keyframes)); } while (0); | |||
| 76 | } | |||
| 77 | ||||
| 78 | static guint | |||
| 79 | ctk_css_keyframes_add_keyframe (CtkCssKeyframes *keyframes, | |||
| 80 | double progress) | |||
| 81 | { | |||
| 82 | guint k, p; | |||
| 83 | ||||
| 84 | for (k = 0; k < keyframes->n_keyframes; k++) | |||
| 85 | { | |||
| 86 | if (keyframes->keyframe_progress[k] == progress) | |||
| 87 | { | |||
| 88 | for (p = 0; p < keyframes->n_properties; p++) | |||
| 89 | { | |||
| 90 | if (KEYFRAMES_VALUE (keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)]) == NULL((void*)0)) | |||
| 91 | continue; | |||
| 92 | ||||
| 93 | _ctk_css_value_unref (KEYFRAMES_VALUE (keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)])); | |||
| 94 | KEYFRAMES_VALUE (keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)]) = NULL((void*)0); | |||
| 95 | ||||
| 96 | /* XXX: GC properties that are now unset | |||
| 97 | * in all keyframes? */ | |||
| 98 | } | |||
| 99 | return k; | |||
| 100 | } | |||
| 101 | else if (keyframes->keyframe_progress[k] > progress) | |||
| 102 | break; | |||
| 103 | } | |||
| 104 | ||||
| 105 | keyframes->n_keyframes++; | |||
| 106 | keyframes->keyframe_progress = g_realloc (keyframes->keyframe_progress, sizeof (double) * keyframes->n_keyframes); | |||
| 107 | memmove (keyframes->keyframe_progress + k + 1, keyframes->keyframe_progress + k, sizeof (double) * (keyframes->n_keyframes - k - 1)); | |||
| 108 | keyframes->keyframe_progress[k] = progress; | |||
| 109 | ||||
| 110 | if (keyframes->n_properties) | |||
| 111 | { | |||
| 112 | gsize size = sizeof (CtkCssValue *) * keyframes->n_properties; | |||
| 113 | ||||
| 114 | keyframes->values = g_realloc (keyframes->values, sizeof (CtkCssValue *) * keyframes->n_keyframes * keyframes->n_properties); | |||
| 115 | memmove (&KEYFRAMES_VALUE (keyframes, k + 1, 0)((keyframes)->values[(k + 1) * (keyframes)->n_properties + (0)]), &KEYFRAMES_VALUE (keyframes, k, 0)((keyframes)->values[(k) * (keyframes)->n_properties + ( 0)]), size * (keyframes->n_keyframes - k - 1)); | |||
| 116 | memset (&KEYFRAMES_VALUE (keyframes, k, 0)((keyframes)->values[(k) * (keyframes)->n_properties + ( 0)]), 0, size); | |||
| 117 | } | |||
| 118 | ||||
| 119 | return k; | |||
| 120 | } | |||
| 121 | ||||
| 122 | static guint | |||
| 123 | ctk_css_keyframes_lookup_property (CtkCssKeyframes *keyframes, | |||
| 124 | guint property_id) | |||
| 125 | { | |||
| 126 | guint p; | |||
| 127 | ||||
| 128 | for (p = 0; p < keyframes->n_properties; p++) | |||
| 129 | { | |||
| 130 | if (keyframes->property_ids[p] == property_id) | |||
| 131 | return p; | |||
| 132 | else if (keyframes->property_ids[p] > property_id) | |||
| 133 | break; | |||
| 134 | } | |||
| 135 | ||||
| 136 | keyframes->n_properties++; | |||
| 137 | keyframes->property_ids = g_realloc (keyframes->property_ids, sizeof (guint) * keyframes->n_properties); | |||
| 138 | memmove (keyframes->property_ids + p + 1, keyframes->property_ids + p, sizeof (guint) * (keyframes->n_properties - p - 1)); | |||
| 139 | keyframes->property_ids[p] = property_id; | |||
| 140 | ||||
| 141 | if (keyframes->n_properties > 1) | |||
| 142 | { | |||
| 143 | guint old_n_properties = keyframes->n_properties - 1; | |||
| 144 | int k; | |||
| 145 | ||||
| 146 | keyframes->values = g_realloc (keyframes->values, sizeof (CtkCssValue *) * keyframes->n_keyframes * keyframes->n_properties); | |||
| 147 | ||||
| 148 | if (p + 1 < keyframes->n_properties) | |||
| 149 | { | |||
| 150 | memmove (&KEYFRAMES_VALUE (keyframes, keyframes->n_keyframes - 1, p + 1)((keyframes)->values[(keyframes->n_keyframes - 1) * (keyframes )->n_properties + (p + 1)]), | |||
| 151 | &keyframes->values[(keyframes->n_keyframes - 1) * old_n_properties + p], | |||
| 152 | sizeof (CtkCssValue *) * (keyframes->n_properties - p - 1)); | |||
| 153 | } | |||
| 154 | KEYFRAMES_VALUE (keyframes, keyframes->n_keyframes - 1, p)((keyframes)->values[(keyframes->n_keyframes - 1) * (keyframes )->n_properties + (p)]) = NULL((void*)0); | |||
| 155 | ||||
| 156 | for (k = keyframes->n_keyframes - 2; k >= 0; k--) | |||
| 157 | { | |||
| 158 | memmove (&KEYFRAMES_VALUE (keyframes, k, p + 1)((keyframes)->values[(k) * (keyframes)->n_properties + ( p + 1)]), | |||
| 159 | &keyframes->values[k * old_n_properties + p], | |||
| 160 | sizeof (CtkCssValue *) * old_n_properties); | |||
| 161 | KEYFRAMES_VALUE (keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)]) = NULL((void*)0); | |||
| 162 | } | |||
| 163 | } | |||
| 164 | else | |||
| 165 | { | |||
| 166 | keyframes->values = g_new0 (CtkCssValue *, keyframes->n_keyframes)((CtkCssValue * *) g_malloc0_n ((keyframes->n_keyframes), sizeof (CtkCssValue *))); | |||
| 167 | } | |||
| 168 | ||||
| 169 | return p; | |||
| 170 | } | |||
| 171 | ||||
| 172 | static CtkCssKeyframes * | |||
| 173 | ctk_css_keyframes_alloc (void) | |||
| 174 | { | |||
| 175 | CtkCssKeyframes *keyframes; | |||
| 176 | ||||
| 177 | keyframes = g_slice_new0 (CtkCssKeyframes)((CtkCssKeyframes*) g_slice_alloc0 (sizeof (CtkCssKeyframes)) ); | |||
| 178 | keyframes->ref_count = 1; | |||
| 179 | ||||
| 180 | return keyframes; | |||
| 181 | } | |||
| 182 | ||||
| 183 | static CtkCssKeyframes * | |||
| 184 | ctk_css_keyframes_new (void) | |||
| 185 | { | |||
| 186 | CtkCssKeyframes *keyframes; | |||
| 187 | ||||
| 188 | keyframes = ctk_css_keyframes_alloc (); | |||
| 189 | ||||
| 190 | ctk_css_keyframes_add_keyframe (keyframes, 0); | |||
| 191 | ctk_css_keyframes_add_keyframe (keyframes, 1); | |||
| 192 | ||||
| 193 | return keyframes; | |||
| 194 | } | |||
| 195 | ||||
| 196 | static gboolean | |||
| 197 | keyframes_set_value (CtkCssKeyframes *keyframes, | |||
| 198 | guint k, | |||
| 199 | CtkCssStyleProperty *property, | |||
| 200 | CtkCssValue *value) | |||
| 201 | { | |||
| 202 | guint p; | |||
| 203 | ||||
| 204 | if (!_ctk_css_style_property_is_animated (property)) | |||
| 205 | return FALSE(0); | |||
| 206 | ||||
| 207 | p = ctk_css_keyframes_lookup_property (keyframes, _ctk_css_style_property_get_id (property)); | |||
| 208 | ||||
| 209 | if (KEYFRAMES_VALUE (keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)])) | |||
| 210 | _ctk_css_value_unref (KEYFRAMES_VALUE (keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)])); | |||
| 211 | ||||
| 212 | KEYFRAMES_VALUE (keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)]) = _ctk_css_value_ref (value); | |||
| 213 | ||||
| 214 | return TRUE(!(0)); | |||
| 215 | } | |||
| 216 | ||||
| 217 | static gboolean | |||
| 218 | parse_declaration (CtkCssKeyframes *keyframes, | |||
| 219 | guint k, | |||
| 220 | CtkCssParser *parser) | |||
| 221 | { | |||
| 222 | CtkStyleProperty *property; | |||
| 223 | CtkCssValue *value; | |||
| 224 | char *name; | |||
| 225 | ||||
| 226 | while (_ctk_css_parser_try (parser, ";", TRUE(!(0)))) | |||
| 227 | { | |||
| 228 | /* SKIP ALL THE THINGS! */ | |||
| 229 | } | |||
| 230 | ||||
| 231 | name = _ctk_css_parser_try_ident (parser, TRUE(!(0))); | |||
| 232 | if (name == NULL((void*)0)) | |||
| 233 | { | |||
| 234 | _ctk_css_parser_error (parser, "No property name given"); | |||
| 235 | return FALSE(0); | |||
| 236 | } | |||
| 237 | ||||
| 238 | property = _ctk_style_property_lookup (name); | |||
| 239 | if (property == NULL((void*)0)) | |||
| 240 | { | |||
| 241 | /* should be CTK_CSS_PROVIDER_ERROR_NAME */ | |||
| 242 | _ctk_css_parser_error (parser, "No property named '%s'", name); | |||
| 243 | g_free (name); | |||
| 244 | return FALSE(0); | |||
| 245 | } | |||
| 246 | ||||
| 247 | g_free (name); | |||
| 248 | ||||
| 249 | if (!_ctk_css_parser_try (parser, ":", TRUE(!(0)))) | |||
| 250 | { | |||
| 251 | _ctk_css_parser_error (parser, "Expected a ':'"); | |||
| 252 | return FALSE(0); | |||
| 253 | } | |||
| 254 | ||||
| 255 | value = _ctk_style_property_parse_value (property, parser); | |||
| 256 | if (value == NULL((void*)0)) | |||
| 257 | return FALSE(0); | |||
| 258 | ||||
| 259 | if (!_ctk_css_parser_try (parser, ";", TRUE(!(0))) && | |||
| 260 | !_ctk_css_parser_begins_with (parser, '}')) | |||
| 261 | { | |||
| 262 | _ctk_css_parser_error (parser, "Junk at end of value"); | |||
| 263 | _ctk_css_value_unref (value); | |||
| 264 | return FALSE(0); | |||
| 265 | } | |||
| 266 | ||||
| 267 | if (CTK_IS_CSS_SHORTHAND_PROPERTY (property)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( property); GType __t = ((_ctk_css_shorthand_property_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
| 268 | { | |||
| 269 | CtkCssShorthandProperty *shorthand = CTK_CSS_SHORTHAND_PROPERTY (property)((((CtkCssShorthandProperty*) (void *) g_type_check_instance_cast ((GTypeInstance*) (property), ((_ctk_css_shorthand_property_get_type ())))))); | |||
| 270 | gboolean animatable = FALSE(0); | |||
| 271 | guint i; | |||
| 272 | ||||
| 273 | for (i = 0; i < _ctk_css_shorthand_property_get_n_subproperties (shorthand); i++) | |||
| 274 | { | |||
| 275 | CtkCssStyleProperty *child = _ctk_css_shorthand_property_get_subproperty (shorthand, i); | |||
| 276 | CtkCssValue *sub = _ctk_css_array_value_get_nth (value, i); | |||
| 277 | ||||
| 278 | animatable |= keyframes_set_value (keyframes, k, child, sub); | |||
| 279 | } | |||
| 280 | ||||
| 281 | if (!animatable) | |||
| 282 | _ctk_css_parser_error (parser, "shorthand '%s' cannot be animated", _ctk_style_property_get_name (property)); | |||
| 283 | } | |||
| 284 | else if (CTK_IS_CSS_STYLE_PROPERTY (property)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( property); GType __t = ((_ctk_css_style_property_get_type ()) ); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
| 285 | { | |||
| 286 | if (!keyframes_set_value (keyframes, k, CTK_CSS_STYLE_PROPERTY (property)((((CtkCssStyleProperty*) (void *) g_type_check_instance_cast ((GTypeInstance*) (property), ((_ctk_css_style_property_get_type ())))))), value)) | |||
| 287 | _ctk_css_parser_error (parser, "Cannot animate property '%s'", _ctk_style_property_get_name (property)); | |||
| 288 | } | |||
| 289 | else | |||
| 290 | { | |||
| 291 | g_assert_not_reached ()do { g_assertion_message_expr ("Ctk", "ctkcsskeyframes.c", 291 , ((const char*) (__func__)), ((void*)0)); } while (0); | |||
| 292 | } | |||
| 293 | ||||
| 294 | _ctk_css_value_unref (value); | |||
| 295 | ||||
| 296 | return TRUE(!(0)); | |||
| 297 | } | |||
| 298 | ||||
| 299 | static gboolean | |||
| 300 | parse_block (CtkCssKeyframes *keyframes, | |||
| 301 | guint k, | |||
| 302 | CtkCssParser *parser) | |||
| 303 | { | |||
| 304 | if (!_ctk_css_parser_try (parser, "{", TRUE(!(0)))) | |||
| 305 | { | |||
| 306 | _ctk_css_parser_error (parser, "Expected closing bracket after keyframes block"); | |||
| 307 | return FALSE(0); | |||
| 308 | } | |||
| 309 | ||||
| 310 | while (!_ctk_css_parser_try (parser, "}", TRUE(!(0)))) | |||
| 311 | { | |||
| 312 | if (!parse_declaration (keyframes, k, parser)) | |||
| 313 | _ctk_css_parser_resync (parser, TRUE(!(0)), '}'); | |||
| 314 | ||||
| 315 | if (_ctk_css_parser_is_eof (parser)) | |||
| 316 | { | |||
| 317 | _ctk_css_parser_error (parser, "Expected closing '}' after keyframes block"); | |||
| 318 | return FALSE(0); | |||
| 319 | } | |||
| 320 | } | |||
| 321 | ||||
| 322 | return TRUE(!(0)); | |||
| 323 | } | |||
| 324 | ||||
| 325 | CtkCssKeyframes * | |||
| 326 | _ctk_css_keyframes_parse (CtkCssParser *parser) | |||
| 327 | { | |||
| 328 | CtkCssKeyframes *keyframes; | |||
| 329 | double progress; | |||
| 330 | guint k; | |||
| 331 | ||||
| 332 | g_return_val_if_fail (parser != NULL, NULL)do { if ((parser != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "parser != NULL"); return (((void*)0)); } } while (0); | |||
| 333 | ||||
| 334 | keyframes = ctk_css_keyframes_new (); | |||
| 335 | ||||
| 336 | while (!_ctk_css_parser_begins_with (parser, '}')) | |||
| 337 | { | |||
| 338 | if (_ctk_css_parser_try (parser, "from", TRUE(!(0)))) | |||
| 339 | progress = 0; | |||
| 340 | else if (_ctk_css_parser_try (parser, "to", TRUE(!(0)))) | |||
| 341 | progress = 1; | |||
| 342 | else if (_ctk_css_parser_try_double (parser, &progress) && | |||
| 343 | _ctk_css_parser_try (parser, "%", TRUE(!(0)))) | |||
| 344 | { | |||
| 345 | if (progress < 0 || progress > 100) | |||
| 346 | { | |||
| 347 | /* XXX: should we skip over the block here? */ | |||
| 348 | _ctk_css_parser_error (parser, "percentages must be between 0%% and 100%%"); | |||
| 349 | _ctk_css_keyframes_unref (keyframes); | |||
| 350 | return NULL((void*)0); | |||
| 351 | } | |||
| 352 | progress /= 100; | |||
| 353 | } | |||
| 354 | else | |||
| 355 | { | |||
| 356 | _ctk_css_parser_error (parser, "expected a percentage"); | |||
| 357 | _ctk_css_keyframes_unref (keyframes); | |||
| 358 | return NULL((void*)0); | |||
| 359 | } | |||
| 360 | ||||
| 361 | k = ctk_css_keyframes_add_keyframe (keyframes, progress); | |||
| 362 | ||||
| 363 | if (!parse_block (keyframes, k, parser)) | |||
| 364 | { | |||
| 365 | _ctk_css_keyframes_unref (keyframes); | |||
| 366 | return NULL((void*)0); | |||
| 367 | } | |||
| 368 | } | |||
| 369 | ||||
| 370 | return keyframes; | |||
| 371 | } | |||
| 372 | ||||
| 373 | static int | |||
| 374 | compare_property_by_name (gconstpointer a, | |||
| 375 | gconstpointer b, | |||
| 376 | gpointer data) | |||
| 377 | { | |||
| 378 | CtkCssKeyframes *keyframes = data; | |||
| 379 | ||||
| 380 | return strcmp (_ctk_style_property_get_name (CTK_STYLE_PROPERTY (((((CtkStyleProperty*) (void *) g_type_check_instance_cast (( GTypeInstance*) (_ctk_css_style_property_lookup_by_id (keyframes ->property_ids[*(const guint *) a])), ((_ctk_style_property_get_type ())))))) | |||
| 381 | _ctk_css_style_property_lookup_by_id (keyframes->property_ids[*(const guint *) a]))((((CtkStyleProperty*) (void *) g_type_check_instance_cast (( GTypeInstance*) (_ctk_css_style_property_lookup_by_id (keyframes ->property_ids[*(const guint *) a])), ((_ctk_style_property_get_type ()))))))), | |||
| 382 | _ctk_style_property_get_name (CTK_STYLE_PROPERTY (((((CtkStyleProperty*) (void *) g_type_check_instance_cast (( GTypeInstance*) (_ctk_css_style_property_lookup_by_id (keyframes ->property_ids[*(const guint *) b])), ((_ctk_style_property_get_type ())))))) | |||
| 383 | _ctk_css_style_property_lookup_by_id (keyframes->property_ids[*(const guint *) b]))((((CtkStyleProperty*) (void *) g_type_check_instance_cast (( GTypeInstance*) (_ctk_css_style_property_lookup_by_id (keyframes ->property_ids[*(const guint *) b])), ((_ctk_style_property_get_type ())))))))); | |||
| 384 | } | |||
| 385 | ||||
| 386 | void | |||
| 387 | _ctk_css_keyframes_print (CtkCssKeyframes *keyframes, | |||
| 388 | GString *string) | |||
| 389 | { | |||
| 390 | guint k, p; | |||
| 391 | guint *sorted; | |||
| 392 | ||||
| 393 | g_return_if_fail (keyframes != NULL)do { if ((keyframes != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "keyframes != NULL"); return ; } } while (0); | |||
| ||||
| 394 | g_return_if_fail (string != NULL)do { if ((string != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "string != NULL"); return ; } } while (0); | |||
| 395 | ||||
| 396 | sorted = g_new (guint, keyframes->n_properties)((guint *) g_malloc_n ((keyframes->n_properties), sizeof ( guint))); | |||
| 397 | for (p = 0; p
| |||
| 398 | sorted[p] = p; | |||
| 399 | g_sort_array (sorted, keyframes->n_properties, sizeof (guint), compare_property_by_name, keyframes); | |||
| 400 | ||||
| 401 | for (k = 0; k < keyframes->n_keyframes; k++) | |||
| 402 | { | |||
| 403 | /* useful for 0% and 100% which might be empty */ | |||
| 404 | gboolean opened = FALSE(0); | |||
| 405 | ||||
| 406 | for (p = 0; p < keyframes->n_properties; p++) | |||
| 407 | { | |||
| 408 | if (KEYFRAMES_VALUE (keyframes, k, sorted[p])((keyframes)->values[(k) * (keyframes)->n_properties + ( sorted[p])]) == NULL((void*)0)) | |||
| ||||
| 409 | continue; | |||
| 410 | ||||
| 411 | if (!opened) | |||
| 412 | { | |||
| 413 | if (keyframes->keyframe_progress[k] == 0.0) | |||
| 414 | g_string_append (string, " from {\n")(__builtin_constant_p (" from {\n") ? __extension__ ({ const char * const __val = (" from {\n"); g_string_append_len_inline (string, __val, (__val != ((void*)0)) ? (gssize) strlen (((__val ) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline (string, " from {\n", (gssize) -1)); | |||
| 415 | else if (keyframes->keyframe_progress[k] == 1.0) | |||
| 416 | g_string_append (string, " to {\n")(__builtin_constant_p (" to {\n") ? __extension__ ({ const char * const __val = (" to {\n"); g_string_append_len_inline (string , __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + ! (__val))) : (gssize) -1); }) : g_string_append_len_inline (string , " to {\n", (gssize) -1)); | |||
| 417 | else | |||
| 418 | g_string_append_printf (string, " %g%% {\n", keyframes->keyframe_progress[k] * 100); | |||
| 419 | opened = TRUE(!(0)); | |||
| 420 | } | |||
| 421 | ||||
| 422 | g_string_append_printf (string, " %s: ", _ctk_style_property_get_name ( | |||
| 423 | CTK_STYLE_PROPERTY (((((CtkStyleProperty*) (void *) g_type_check_instance_cast (( GTypeInstance*) (_ctk_css_style_property_lookup_by_id ( keyframes ->property_ids[sorted[p]])), ((_ctk_style_property_get_type ())))))) | |||
| 424 | _ctk_css_style_property_lookup_by_id (((((CtkStyleProperty*) (void *) g_type_check_instance_cast (( GTypeInstance*) (_ctk_css_style_property_lookup_by_id ( keyframes ->property_ids[sorted[p]])), ((_ctk_style_property_get_type ())))))) | |||
| 425 | keyframes->property_ids[sorted[p]]))((((CtkStyleProperty*) (void *) g_type_check_instance_cast (( GTypeInstance*) (_ctk_css_style_property_lookup_by_id ( keyframes ->property_ids[sorted[p]])), ((_ctk_style_property_get_type ())))))))); | |||
| 426 | _ctk_css_value_print (KEYFRAMES_VALUE (keyframes, k, sorted[p])((keyframes)->values[(k) * (keyframes)->n_properties + ( sorted[p])]), string); | |||
| 427 | g_string_append (string, ";\n")(__builtin_constant_p (";\n") ? __extension__ ({ const char * const __val = (";\n"); g_string_append_len_inline (string, __val , (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val ))) : (gssize) -1); }) : g_string_append_len_inline (string, ";\n" , (gssize) -1)); | |||
| 428 | } | |||
| 429 | ||||
| 430 | if (opened) | |||
| 431 | g_string_append (string, " }\n")(__builtin_constant_p (" }\n") ? __extension__ ({ const char * const __val = (" }\n"); g_string_append_len_inline (string , __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + ! (__val))) : (gssize) -1); }) : g_string_append_len_inline (string , " }\n", (gssize) -1)); | |||
| 432 | } | |||
| 433 | ||||
| 434 | g_free (sorted); | |||
| 435 | } | |||
| 436 | ||||
| 437 | CtkCssKeyframes * | |||
| 438 | _ctk_css_keyframes_compute (CtkCssKeyframes *keyframes, | |||
| 439 | CtkStyleProviderPrivate *provider, | |||
| 440 | CtkCssStyle *style, | |||
| 441 | CtkCssStyle *parent_style) | |||
| 442 | { | |||
| 443 | CtkCssKeyframes *resolved; | |||
| 444 | guint k, p; | |||
| 445 | ||||
| 446 | g_return_val_if_fail (keyframes != NULL, NULL)do { if ((keyframes != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "keyframes != NULL"); return (((void*)0)); } } while (0); | |||
| 447 | g_return_val_if_fail (CTK_IS_STYLE_PROVIDER_PRIVATE (provider), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((provider)); GType __t = ((_ctk_style_provider_private_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_STYLE_PROVIDER_PRIVATE (provider)" ); return (((void*)0)); } } while (0); | |||
| 448 | g_return_val_if_fail (CTK_IS_CSS_STYLE (style), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) (style); GType __t = ((ctk_css_style_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_CSS_STYLE (style)"); return (((void*)0)); } } while (0); | |||
| 449 | g_return_val_if_fail (parent_style == NULL || CTK_IS_CSS_STYLE (parent_style), NULL)do { if ((parent_style == ((void*)0) || (((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (parent_style); GType __t = ((ctk_css_style_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "parent_style == NULL || CTK_IS_CSS_STYLE (parent_style)" ); return (((void*)0)); } } while (0); | |||
| 450 | ||||
| 451 | resolved = ctk_css_keyframes_alloc (); | |||
| 452 | resolved->n_keyframes = keyframes->n_keyframes; | |||
| 453 | resolved->keyframe_progress = g_memdup2 (keyframes->keyframe_progress, keyframes->n_keyframes * sizeof (double)); | |||
| 454 | resolved->n_properties = keyframes->n_properties; | |||
| 455 | resolved->property_ids = g_memdup2 (keyframes->property_ids, keyframes->n_properties * sizeof (guint)); | |||
| 456 | resolved->values = g_new0 (CtkCssValue *, resolved->n_keyframes * resolved->n_properties)((CtkCssValue * *) g_malloc0_n ((resolved->n_keyframes * resolved ->n_properties), sizeof (CtkCssValue *))); | |||
| 457 | ||||
| 458 | for (p = 0; p < resolved->n_properties; p++) | |||
| 459 | { | |||
| 460 | for (k = 0; k < resolved->n_keyframes; k++) | |||
| 461 | { | |||
| 462 | if (KEYFRAMES_VALUE (keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)]) == NULL((void*)0)) | |||
| 463 | continue; | |||
| 464 | ||||
| 465 | KEYFRAMES_VALUE (resolved, k, p)((resolved)->values[(k) * (resolved)->n_properties + (p )]) = _ctk_css_value_compute (KEYFRAMES_VALUE (keyframes, k, p)((keyframes)->values[(k) * (keyframes)->n_properties + ( p)]), | |||
| 466 | resolved->property_ids[p], | |||
| 467 | provider, | |||
| 468 | style, | |||
| 469 | parent_style); | |||
| 470 | } | |||
| 471 | } | |||
| 472 | ||||
| 473 | return resolved; | |||
| 474 | } | |||
| 475 | ||||
| 476 | guint | |||
| 477 | _ctk_css_keyframes_get_n_properties (CtkCssKeyframes *keyframes) | |||
| 478 | { | |||
| 479 | g_return_val_if_fail (keyframes != NULL, 0)do { if ((keyframes != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "keyframes != NULL"); return (0); } } while (0); | |||
| 480 | ||||
| 481 | return keyframes->n_properties; | |||
| 482 | } | |||
| 483 | ||||
| 484 | guint | |||
| 485 | _ctk_css_keyframes_get_property_id (CtkCssKeyframes *keyframes, | |||
| 486 | guint id) | |||
| 487 | { | |||
| 488 | g_return_val_if_fail (keyframes != NULL, 0)do { if ((keyframes != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "keyframes != NULL"); return (0); } } while (0); | |||
| 489 | g_return_val_if_fail (id < keyframes->n_properties, 0)do { if ((id < keyframes->n_properties)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "id < keyframes->n_properties" ); return (0); } } while (0); | |||
| 490 | ||||
| 491 | return keyframes->property_ids[id]; | |||
| 492 | } | |||
| 493 | ||||
| 494 | CtkCssValue * | |||
| 495 | _ctk_css_keyframes_get_value (CtkCssKeyframes *keyframes, | |||
| 496 | guint id, | |||
| 497 | double progress, | |||
| 498 | CtkCssValue *default_value) | |||
| 499 | { | |||
| 500 | CtkCssValue *start_value, *end_value, *result; | |||
| 501 | double start_progress, end_progress; | |||
| 502 | guint k; | |||
| 503 | ||||
| 504 | g_return_val_if_fail (keyframes != NULL, 0)do { if ((keyframes != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "keyframes != NULL"); return (0); } } while (0); | |||
| 505 | g_return_val_if_fail (id < keyframes->n_properties, 0)do { if ((id < keyframes->n_properties)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "id < keyframes->n_properties" ); return (0); } } while (0); | |||
| 506 | ||||
| 507 | start_value = default_value; | |||
| 508 | start_progress = 0.0; | |||
| 509 | end_value = default_value; | |||
| 510 | end_progress = 1.0; | |||
| 511 | ||||
| 512 | for (k = 0; k < keyframes->n_keyframes; k++) | |||
| 513 | { | |||
| 514 | if (KEYFRAMES_VALUE (keyframes, k, id)((keyframes)->values[(k) * (keyframes)->n_properties + ( id)]) == NULL((void*)0)) | |||
| 515 | continue; | |||
| 516 | ||||
| 517 | if (keyframes->keyframe_progress[k] == progress) | |||
| 518 | { | |||
| 519 | return _ctk_css_value_ref (KEYFRAMES_VALUE (keyframes, k, id)((keyframes)->values[(k) * (keyframes)->n_properties + ( id)])); | |||
| 520 | } | |||
| 521 | else if (keyframes->keyframe_progress[k] < progress) | |||
| 522 | { | |||
| 523 | start_value = KEYFRAMES_VALUE (keyframes, k, id)((keyframes)->values[(k) * (keyframes)->n_properties + ( id)]); | |||
| 524 | start_progress = keyframes->keyframe_progress[k]; | |||
| 525 | } | |||
| 526 | else | |||
| 527 | { | |||
| 528 | end_value = KEYFRAMES_VALUE (keyframes, k, id)((keyframes)->values[(k) * (keyframes)->n_properties + ( id)]); | |||
| 529 | end_progress = keyframes->keyframe_progress[k]; | |||
| 530 | break; | |||
| 531 | } | |||
| 532 | } | |||
| 533 | ||||
| 534 | progress = (progress - start_progress) / (end_progress - start_progress); | |||
| 535 | ||||
| 536 | result = _ctk_css_value_transition (start_value, | |||
| 537 | end_value, | |||
| 538 | keyframes->property_ids[id], | |||
| 539 | progress); | |||
| 540 | ||||
| 541 | /* XXX: Dear spec, what's the correct thing to do here? */ | |||
| 542 | if (result == NULL((void*)0)) | |||
| 543 | return _ctk_css_value_ref (start_value); | |||
| 544 | ||||
| 545 | return result; | |||
| 546 | } | |||
| 547 |