Debian Codegraph @

clutter/deprecated/clutter-behaviour-scale.c

raw
1 /*
2 * Clutter.
3 *
4 * An OpenGL based 'interactive canvas' library.
5 *
6 * Authored By Matthew Allum <[email protected]>
7 *
8 * Copyright (C) 2006 OpenedHand
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 /**
25 * SECTION:clutter-behaviour-scale
26 * @Title: ClutterBehaviourScale
27 * @short_description: A behaviour controlling scale
28 * @Deprecated: 1.6: Use clutter_actor_animate() with #ClutterActor:scale-x
29 * and #ClutterActor:scale-y instead.
30 *
31 * A #ClutterBehaviourScale interpolates actors size between two values.
32 *
33 * Deprecated: 1.6: Use the #ClutterActor:scale-x and #ClutterActor:scale-y
34 * properties, and clutter_actor_animate(), or #ClutterAnimator or
35 * #ClutterState instead.
36 */
37
38 #ifdef HAVE_CONFIG_H
39 #include "config.h"
40 #endif
41
42 #include <math.h>
43
44 #define CLUTTER_DISABLE_DEPRECATION_WARNINGS
45 #include "deprecated/clutter-actor.h"
46
47 #include "clutter-alpha.h"
48 #include "clutter-behaviour.h"
49 #include "clutter-behaviour-scale.h"
50 #include "clutter-debug.h"
51 #include "clutter-main.h"
52 #include "clutter-private.h"
53
54 struct _ClutterBehaviourScalePrivate
55 {
56 gdouble x_scale_start;
57 gdouble y_scale_start;
58
59 gdouble x_scale_end;
60 gdouble y_scale_end;
61 };
62
63 enum
64 {
65 PROP_0,
66
67 PROP_X_SCALE_START,
68 PROP_Y_SCALE_START,
69 PROP_X_SCALE_END,
70 PROP_Y_SCALE_END,
71
72 PROP_LAST
73 };
74
75 static GParamSpec *obj_props[PROP_LAST];
76
77 G_DEFINE_TYPE_WITH_PRIVATE (ClutterBehaviourScale,
78 clutter_behaviour_scale,
79 CLUTTER_TYPE_BEHAVIOUR)
80
81 typedef struct {
82 gdouble scale_x;
83 gdouble scale_y;
84 } ScaleFrameClosure;
85
86 static void
87 scale_frame_foreach (ClutterBehaviour *behaviour,
88 ClutterActor *actor,
89 gpointer data)
90 {
91 ScaleFrameClosure *closure = data;
92
93 clutter_actor_set_scale (actor, closure->scale_x, closure->scale_y);
94 }
95
96 static void
97 clutter_behaviour_scale_alpha_notify (ClutterBehaviour *behave,
98 gdouble alpha_value)
99 {
100 ClutterBehaviourScalePrivate *priv;
101 ScaleFrameClosure closure = { 0, };
102
103 priv = CLUTTER_BEHAVIOUR_SCALE (behave)->priv;
104
105 /* Fix the start/end values, avoids potential rounding errors on large
106 * values.
107 */
108 if (alpha_value == 1.0)
109 {
110 closure.scale_x = priv->x_scale_end;
111 closure.scale_y = priv->y_scale_end;
112 }
113 else if (alpha_value == 0)
114 {
115 closure.scale_x = priv->x_scale_start;
116 closure.scale_y = priv->y_scale_start;
117 }
118 else
119 {
120 closure.scale_x = (priv->x_scale_end - priv->x_scale_start)
121 * alpha_value
122 + priv->x_scale_start;
123
124 closure.scale_y = (priv->y_scale_end - priv->y_scale_start)
125 * alpha_value
126 + priv->y_scale_start;
127 }
128
129 clutter_behaviour_actors_foreach (behave,
130 scale_frame_foreach,
131 &closure);
132 }
133
134 static void
135 clutter_behaviour_scale_set_property (GObject *gobject,
136 guint prop_id,
137 const GValue *value,
138 GParamSpec *pspec)
139 {
140 ClutterBehaviourScalePrivate *priv;
141
142 priv = CLUTTER_BEHAVIOUR_SCALE (gobject)->priv;
143
144 switch (prop_id)
145 {
146 case PROP_X_SCALE_START:
147 priv->x_scale_start = g_value_get_double (value);
148 break;
149
150 case PROP_X_SCALE_END:
151 priv->x_scale_end = g_value_get_double (value);
152 break;
153
154 case PROP_Y_SCALE_START:
155 priv->y_scale_start = g_value_get_double (value);
156 break;
157
158 case PROP_Y_SCALE_END:
159 priv->y_scale_end = g_value_get_double (value);
160 break;
161
162 default:
163 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
164 break;
165 }
166 }
167
168 static void
169 clutter_behaviour_scale_get_property (GObject *gobject,
170 guint prop_id,
171 GValue *value,
172 GParamSpec *pspec)
173 {
174 ClutterBehaviourScalePrivate *priv;
175
176 priv = CLUTTER_BEHAVIOUR_SCALE (gobject)->priv;
177
178 switch (prop_id)
179 {
180 case PROP_X_SCALE_START:
181 g_value_set_double (value, priv->x_scale_start);
182 break;
183
184 case PROP_X_SCALE_END:
185 g_value_set_double (value, priv->x_scale_end);
186 break;
187
188 case PROP_Y_SCALE_START:
189 g_value_set_double (value, priv->y_scale_start);
190 break;
191
192 case PROP_Y_SCALE_END:
193 g_value_set_double (value, priv->y_scale_end);
194 break;
195
196 default:
197 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
198 break;
199 }
200 }
201
202 static void
203 clutter_behaviour_scale_class_init (ClutterBehaviourScaleClass *klass)
204 {
205 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
206 ClutterBehaviourClass *behave_class = CLUTTER_BEHAVIOUR_CLASS (klass);
207 GParamSpec *pspec = NULL;
208
209 gobject_class->set_property = clutter_behaviour_scale_set_property;
210 gobject_class->get_property = clutter_behaviour_scale_get_property;
211
212 /**
213 * ClutterBehaviourScale:x-scale-start:
214 *
215 * The initial scaling factor on the X axis for the actors.
216 *
217 * Since: 0.6
218 *
219 * Deprecated: 1.6
220 */
221 pspec = g_param_spec_double ("x-scale-start",
222 P_("X Start Scale"),
223 P_("Initial scale on the X axis"),
224 0.0, G_MAXDOUBLE,
225 1.0,
226 CLUTTER_PARAM_READWRITE);
227 obj_props[PROP_X_SCALE_START] = pspec;
228 g_object_class_install_property (gobject_class,
229 PROP_X_SCALE_START,
230 pspec);
231 /**
232 * ClutterBehaviourScale:x-scale-end:
233 *
234 * The final scaling factor on the X axis for the actors.
235 *
236 * Since: 0.6
237 *
238 * Deprecated: 1.6
239 */
240 pspec = g_param_spec_double ("x-scale-end",
241 P_("X End Scale"),
242 P_("Final scale on the X axis"),
243 0.0, G_MAXDOUBLE,
244 1.0,
245 CLUTTER_PARAM_READWRITE);
246 obj_props[PROP_X_SCALE_END] = pspec;
247 g_object_class_install_property (gobject_class,
248 PROP_X_SCALE_END,
249 pspec);
250 /**
251 * ClutterBehaviourScale:y-scale-start:
252 *
253 * The initial scaling factor on the Y axis for the actors.
254 *
255 * Since: 0.6
256 *
257 * Deprecated: 1.6
258 */
259 pspec = g_param_spec_double ("y-scale-start",
260 P_("Y Start Scale"),
261 P_("Initial scale on the Y axis"),
262 0.0, G_MAXDOUBLE,
263 1.0,
264 CLUTTER_PARAM_READWRITE);
265 obj_props[PROP_Y_SCALE_START] = pspec;
266 g_object_class_install_property (gobject_class,
267 PROP_Y_SCALE_START,
268 pspec);
269 /**
270 * ClutterBehaviourScale:y-scale-end:
271 *
272 * The final scaling factor on the Y axis for the actors.
273 *
274 * Since: 0.6
275 *
276 * Deprecated: 1.6
277 */
278 pspec = g_param_spec_double ("y-scale-end",
279 P_("Y End Scale"),
280 P_("Final scale on the Y axis"),
281 0.0, G_MAXDOUBLE,
282 1.0,
283 CLUTTER_PARAM_READWRITE);
284 obj_props[PROP_Y_SCALE_END] = pspec;
285 g_object_class_install_property (gobject_class,
286 PROP_Y_SCALE_END,
287 pspec);
288
289 behave_class->alpha_notify = clutter_behaviour_scale_alpha_notify;
290 }
291
292 static void
293 clutter_behaviour_scale_init (ClutterBehaviourScale *self)
294 {
295 ClutterBehaviourScalePrivate *priv;
296
297 self->priv = priv = clutter_behaviour_scale_get_instance_private (self);
298
299 priv->x_scale_start = priv->x_scale_end = 1.0;
300 priv->y_scale_start = priv->y_scale_end = 1.0;
301 }
302
303 /**
304 * clutter_behaviour_scale_new:
305 * @alpha: (allow-none): a #ClutterAlpha instance, or %NULL
306 * @x_scale_start: initial scale factor on the X axis
307 * @y_scale_start: initial scale factor on the Y axis
308 * @x_scale_end: final scale factor on the X axis
309 * @y_scale_end: final scale factor on the Y axis
310 *
311 * Creates a new #ClutterBehaviourScale instance.
312 *
313 * If @alpha is not %NULL, the #ClutterBehaviour will take ownership
314 * of the #ClutterAlpha instance. In the case when @alpha is %NULL,
315 * it can be set later with clutter_behaviour_set_alpha().
316 *
317 * Return value: (transfer full): the newly created #ClutterBehaviourScale
318 *
319 * Since: 0.2
320 *
321 * Deprecated: 1.6
322 */
323 ClutterBehaviour *
324 clutter_behaviour_scale_new (ClutterAlpha *alpha,
325 gdouble x_scale_start,
326 gdouble y_scale_start,
327 gdouble x_scale_end,
328 gdouble y_scale_end)
329 {
330 g_return_val_if_fail (alpha == NULL || CLUTTER_IS_ALPHA (alpha), NULL);
331
332 return g_object_new (CLUTTER_TYPE_BEHAVIOUR_SCALE,
333 "alpha", alpha,
334 "x-scale-start", x_scale_start,
335 "y-scale-start", y_scale_start,
336 "x-scale-end", x_scale_end,
337 "y-scale-end", y_scale_end,
338 NULL);
339 }
340
341 /**
342 * clutter_behaviour_scale_set_bounds:
343 * @scale: a #ClutterBehaviourScale
344 * @x_scale_start: initial scale factor on the X axis
345 * @y_scale_start: initial scale factor on the Y axis
346 * @x_scale_end: final scale factor on the X axis
347 * @y_scale_end: final scale factor on the Y axis
348 *
349 * Sets the bounds used by scale behaviour.
350 *
351 * Since: 0.6
352 *
353 * Deprecated: 1.6
354 */
355 void
356 clutter_behaviour_scale_set_bounds (ClutterBehaviourScale *scale,
357 gdouble x_scale_start,
358 gdouble y_scale_start,
359 gdouble x_scale_end,
360 gdouble y_scale_end)
361 {
362 ClutterBehaviourScalePrivate *priv;
363
364 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_SCALE (scale));
365
366 priv = scale->priv;
367
368 g_object_freeze_notify (G_OBJECT (scale));
369
370 if (priv->x_scale_start != x_scale_start)
371 {
372 priv->x_scale_start = x_scale_start;
373 g_object_notify_by_pspec (G_OBJECT (scale), obj_props[PROP_X_SCALE_START]);
374 }
375
376 if (priv->y_scale_start != y_scale_start)
377 {
378 priv->y_scale_start = y_scale_start;
379 g_object_notify_by_pspec (G_OBJECT (scale), obj_props[PROP_Y_SCALE_START]);
380 }
381
382 if (priv->x_scale_end != x_scale_end)
383 {
384 priv->x_scale_end = x_scale_end;
385 g_object_notify_by_pspec (G_OBJECT (scale), obj_props[PROP_X_SCALE_END]);
386 }
387
388 if (priv->y_scale_end != y_scale_end)
389 {
390 priv->y_scale_end = y_scale_end;
391 g_object_notify_by_pspec (G_OBJECT (scale), obj_props[PROP_Y_SCALE_END]);
392 }
393
394 g_object_thaw_notify (G_OBJECT (scale));
395 }
396
397 /**
398 * clutter_behaviour_scale_get_bounds:
399 * @scale: a #ClutterBehaviourScale
400 * @x_scale_start: (out): return location for the initial scale factor on the X
401 * axis, or %NULL
402 * @y_scale_start: (out): return location for the initial scale factor on the Y
403 * axis, or %NULL
404 * @x_scale_end: (out): return location for the final scale factor on the X axis,
405 * or %NULL
406 * @y_scale_end: (out): return location for the final scale factor on the Y axis,
407 * or %NULL
408 *
409 * Retrieves the bounds used by scale behaviour.
410 *
411 * Since: 0.4
412 *
413 * Deprecated: 1.6
414 */
415 void
416 clutter_behaviour_scale_get_bounds (ClutterBehaviourScale *scale,
417 gdouble *x_scale_start,
418 gdouble *y_scale_start,
419 gdouble *x_scale_end,
420 gdouble *y_scale_end)
421 {
422 ClutterBehaviourScalePrivate *priv;
423
424 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_SCALE (scale));
425
426 priv = scale->priv;
427
428 if (x_scale_start)
429 *x_scale_start = priv->x_scale_start;
430
431 if (x_scale_end)
432 *x_scale_end = priv->x_scale_end;
433
434 if (y_scale_start)
435 *y_scale_start = priv->y_scale_start;
436
437 if (y_scale_end)
438 *y_scale_end = priv->y_scale_end;
439 }