| 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-opacity |
| 26 |
* @Title: ClutterBehaviourOpacity |
| 27 |
* @short_description: A behaviour controlling opacity |
| 28 |
* @Deprecated: 1.6: Use clutter_actor_animate() instead. |
| 29 |
* |
| 30 |
* #ClutterBehaviourOpacity controls the opacity of a set of actors. |
| 31 |
* |
| 32 |
* Since: 0.2 |
| 33 |
* |
| 34 |
* Deprecated: 1.6: Use the #ClutterActor:opacity property and |
| 35 |
* clutter_actor_animate(), or #ClutterAnimator, or #ClutterState |
| 36 |
* instead. |
| 37 |
*/ |
| 38 |
|
| 39 |
#ifdef HAVE_CONFIG_H |
| 40 |
#include "config.h" |
| 41 |
#endif |
| 42 |
|
| 43 |
#include <math.h> |
| 44 |
|
| 45 |
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS |
| 46 |
|
| 47 |
#include "clutter-alpha.h" |
| 48 |
#include "clutter-behaviour.h" |
| 49 |
#include "clutter-behaviour-opacity.h" |
| 50 |
#include "clutter-private.h" |
| 51 |
#include "clutter-debug.h" |
| 52 |
|
| 53 |
struct _ClutterBehaviourOpacityPrivate |
| 54 |
{ |
| 55 |
guint8 opacity_start; |
| 56 |
guint8 opacity_end; |
| 57 |
}; |
| 58 |
|
| 59 |
enum |
| 60 |
{ |
| 61 |
PROP_0, |
| 62 |
|
| 63 |
PROP_OPACITY_START, |
| 64 |
PROP_OPACITY_END, |
| 65 |
|
| 66 |
PROP_LAST |
| 67 |
}; |
| 68 |
|
| 69 |
static GParamSpec *obj_props[PROP_LAST]; |
| 70 |
|
| 71 |
G_DEFINE_TYPE_WITH_PRIVATE (ClutterBehaviourOpacity, |
| 72 |
clutter_behaviour_opacity, |
| 73 |
CLUTTER_TYPE_BEHAVIOUR) |
| 74 |
|
| 75 |
static void |
| 76 |
alpha_notify_foreach (ClutterBehaviour *behaviour, |
| 77 |
ClutterActor *actor, |
| 78 |
gpointer data) |
| 79 |
{ |
| 80 |
clutter_actor_set_opacity (actor, GPOINTER_TO_UINT(data)); |
| 81 |
} |
| 82 |
|
| 83 |
static void |
| 84 |
clutter_behaviour_alpha_notify (ClutterBehaviour *behave, |
| 85 |
gdouble alpha_value) |
| 86 |
{ |
| 87 |
ClutterBehaviourOpacityPrivate *priv; |
| 88 |
guint8 opacity; |
| 89 |
|
| 90 |
priv = CLUTTER_BEHAVIOUR_OPACITY (behave)->priv; |
| 91 |
|
| 92 |
opacity = alpha_value |
| 93 |
* (priv->opacity_end - priv->opacity_start) |
| 94 |
+ priv->opacity_start; |
| 95 |
|
| 96 |
CLUTTER_NOTE (ANIMATION, "alpha: %.4f, opacity: %u", |
| 97 |
alpha_value, |
| 98 |
opacity); |
| 99 |
|
| 100 |
clutter_behaviour_actors_foreach (behave, |
| 101 |
alpha_notify_foreach, |
| 102 |
GUINT_TO_POINTER ((guint) opacity)); |
| 103 |
} |
| 104 |
|
| 105 |
static void |
| 106 |
clutter_behaviour_opacity_set_property (GObject *gobject, |
| 107 |
guint prop_id, |
| 108 |
const GValue *value, |
| 109 |
GParamSpec *pspec) |
| 110 |
{ |
| 111 |
ClutterBehaviourOpacity *self = CLUTTER_BEHAVIOUR_OPACITY (gobject); |
| 112 |
|
| 113 |
switch (prop_id) |
| 114 |
{ |
| 115 |
case PROP_OPACITY_START: |
| 116 |
clutter_behaviour_opacity_set_bounds (self, |
| 117 |
g_value_get_uint (value), |
| 118 |
self->priv->opacity_end); |
| 119 |
break; |
| 120 |
|
| 121 |
case PROP_OPACITY_END: |
| 122 |
clutter_behaviour_opacity_set_bounds (self, |
| 123 |
self->priv->opacity_start, |
| 124 |
g_value_get_uint (value)); |
| 125 |
break; |
| 126 |
|
| 127 |
default: |
| 128 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); |
| 129 |
break; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
static void |
| 134 |
clutter_behaviour_opacity_get_property (GObject *gobject, |
| 135 |
guint prop_id, |
| 136 |
GValue *value, |
| 137 |
GParamSpec *pspec) |
| 138 |
{ |
| 139 |
ClutterBehaviourOpacity *self = CLUTTER_BEHAVIOUR_OPACITY (gobject); |
| 140 |
|
| 141 |
switch (prop_id) |
| 142 |
{ |
| 143 |
case PROP_OPACITY_START: |
| 144 |
g_value_set_uint (value, self->priv->opacity_start); |
| 145 |
break; |
| 146 |
|
| 147 |
case PROP_OPACITY_END: |
| 148 |
g_value_set_uint (value, self->priv->opacity_end); |
| 149 |
break; |
| 150 |
|
| 151 |
default: |
| 152 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); |
| 153 |
break; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
static void |
| 158 |
clutter_behaviour_opacity_class_init (ClutterBehaviourOpacityClass *klass) |
| 159 |
{ |
| 160 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); |
| 161 |
ClutterBehaviourClass *behave_class = CLUTTER_BEHAVIOUR_CLASS (klass); |
| 162 |
GParamSpec *pspec; |
| 163 |
|
| 164 |
gobject_class->set_property = clutter_behaviour_opacity_set_property; |
| 165 |
gobject_class->get_property = clutter_behaviour_opacity_get_property; |
| 166 |
|
| 167 |
/** |
| 168 |
* ClutterBehaviourOpacity:opacity-start: |
| 169 |
* |
| 170 |
* Initial opacity level of the behaviour. |
| 171 |
* |
| 172 |
* Since: 0.2 |
| 173 |
* |
| 174 |
* Deprecated: 1.6 |
| 175 |
*/ |
| 176 |
pspec = g_param_spec_uint ("opacity-start", |
| 177 |
P_("Opacity Start"), |
| 178 |
P_("Initial opacity level"), |
| 179 |
0, 255, |
| 180 |
0, |
| 181 |
CLUTTER_PARAM_READWRITE); |
| 182 |
obj_props[PROP_OPACITY_START] = pspec; |
| 183 |
g_object_class_install_property (gobject_class, PROP_OPACITY_START, pspec); |
| 184 |
|
| 185 |
/** |
| 186 |
* ClutterBehaviourOpacity:opacity-end: |
| 187 |
* |
| 188 |
* Final opacity level of the behaviour. |
| 189 |
* |
| 190 |
* Since: 0.2 |
| 191 |
* |
| 192 |
* Deprecated: 1.6 |
| 193 |
*/ |
| 194 |
pspec = g_param_spec_uint ("opacity-end", |
| 195 |
P_("Opacity End"), |
| 196 |
P_("Final opacity level"), |
| 197 |
0, 255, |
| 198 |
0, |
| 199 |
CLUTTER_PARAM_READWRITE); |
| 200 |
obj_props[PROP_OPACITY_END] = pspec; |
| 201 |
g_object_class_install_property (gobject_class, PROP_OPACITY_END, pspec); |
| 202 |
|
| 203 |
behave_class->alpha_notify = clutter_behaviour_alpha_notify; |
| 204 |
} |
| 205 |
|
| 206 |
static void |
| 207 |
clutter_behaviour_opacity_init (ClutterBehaviourOpacity *self) |
| 208 |
{ |
| 209 |
self->priv = clutter_behaviour_opacity_get_instance_private (self); |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* clutter_behaviour_opacity_new: |
| 214 |
* @alpha: (allow-none): a #ClutterAlpha instance, or %NULL |
| 215 |
* @opacity_start: minimum level of opacity |
| 216 |
* @opacity_end: maximum level of opacity |
| 217 |
* |
| 218 |
* Creates a new #ClutterBehaviourOpacity object, driven by @alpha |
| 219 |
* which controls the opacity property of every actor, making it |
| 220 |
* change in the interval between @opacity_start and @opacity_end. |
| 221 |
* |
| 222 |
* If @alpha is not %NULL, the #ClutterBehaviour will take ownership |
| 223 |
* of the #ClutterAlpha instance. In the case when @alpha is %NULL, |
| 224 |
* it can be set later with clutter_behaviour_set_alpha(). |
| 225 |
* |
| 226 |
* Return value: the newly created #ClutterBehaviourOpacity |
| 227 |
* |
| 228 |
* Since: 0.2 |
| 229 |
* |
| 230 |
* Deprecated: 1.6 |
| 231 |
*/ |
| 232 |
ClutterBehaviour * |
| 233 |
clutter_behaviour_opacity_new (ClutterAlpha *alpha, |
| 234 |
guint8 opacity_start, |
| 235 |
guint8 opacity_end) |
| 236 |
{ |
| 237 |
return g_object_new (CLUTTER_TYPE_BEHAVIOUR_OPACITY, |
| 238 |
"alpha", alpha, |
| 239 |
"opacity-start", opacity_start, |
| 240 |
"opacity-end", opacity_end, |
| 241 |
NULL); |
| 242 |
} |
| 243 |
|
| 244 |
/** |
| 245 |
* clutter_behaviour_opacity_set_bounds: |
| 246 |
* @behaviour: a #ClutterBehaviourOpacity |
| 247 |
* @opacity_start: minimum level of opacity |
| 248 |
* @opacity_end: maximum level of opacity |
| 249 |
* |
| 250 |
* Sets the initial and final levels of the opacity applied by @behaviour |
| 251 |
* on each actor it controls. |
| 252 |
* |
| 253 |
* Since: 0.6 |
| 254 |
* |
| 255 |
* Deprecated: 1.6 |
| 256 |
*/ |
| 257 |
void |
| 258 |
clutter_behaviour_opacity_set_bounds (ClutterBehaviourOpacity *behaviour, |
| 259 |
guint8 opacity_start, |
| 260 |
guint8 opacity_end) |
| 261 |
{ |
| 262 |
ClutterBehaviourOpacityPrivate *priv; |
| 263 |
|
| 264 |
g_return_if_fail (CLUTTER_IS_BEHAVIOUR_OPACITY (behaviour)); |
| 265 |
|
| 266 |
priv = behaviour->priv; |
| 267 |
|
| 268 |
g_object_freeze_notify (G_OBJECT (behaviour)); |
| 269 |
|
| 270 |
if (priv->opacity_start != opacity_start) |
| 271 |
{ |
| 272 |
priv->opacity_start = opacity_start; |
| 273 |
|
| 274 |
g_object_notify_by_pspec (G_OBJECT (behaviour), obj_props[PROP_OPACITY_START]); |
| 275 |
} |
| 276 |
|
| 277 |
if (priv->opacity_end != opacity_end) |
| 278 |
{ |
| 279 |
priv->opacity_end = opacity_end; |
| 280 |
|
| 281 |
g_object_notify_by_pspec (G_OBJECT (behaviour), obj_props[PROP_OPACITY_END]); |
| 282 |
} |
| 283 |
|
| 284 |
g_object_thaw_notify (G_OBJECT (behaviour)); |
| 285 |
} |
| 286 |
|
| 287 |
/** |
| 288 |
* clutter_behaviour_opacity_get_bounds: |
| 289 |
* @behaviour: a #ClutterBehaviourOpacity |
| 290 |
* @opacity_start: (out): return location for the minimum level of opacity, or %NULL |
| 291 |
* @opacity_end: (out): return location for the maximum level of opacity, or %NULL |
| 292 |
* |
| 293 |
* Gets the initial and final levels of the opacity applied by @behaviour |
| 294 |
* on each actor it controls. |
| 295 |
* |
| 296 |
* Since: 0.6 |
| 297 |
* |
| 298 |
* Deprecated: 1.6 |
| 299 |
*/ |
| 300 |
void |
| 301 |
clutter_behaviour_opacity_get_bounds (ClutterBehaviourOpacity *behaviour, |
| 302 |
guint8 *opacity_start, |
| 303 |
guint8 *opacity_end) |
| 304 |
{ |
| 305 |
g_return_if_fail (CLUTTER_IS_BEHAVIOUR_OPACITY (behaviour)); |
| 306 |
|
| 307 |
if (opacity_start) |
| 308 |
*opacity_start = behaviour->priv->opacity_start; |
| 309 |
|
| 310 |
if (opacity_end) |
| 311 |
*opacity_end = behaviour->priv->opacity_end; |
| 312 |
} |