2 * Copyright (C) 2007 OpenedHand Limited
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library 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.
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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Author: Neil Jagdish Patel <njp@o-hand.com>
23 #include "astro-reflection.h"
25 #include <libastro-desktop/astro-defines.h>
26 #include <libastro-desktop/astro-utils.h>
28 #include "clutter-reflect-texture.h"
30 G_DEFINE_TYPE (AstroReflection, astro_reflection, CLUTTER_TYPE_GROUP);
32 #define ASTRO_REFLECTION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\
33 ASTRO_TYPE_REFLECTION, AstroReflectionPrivate))
35 static GdkPixbuf *disc_bg = NULL;
37 struct _AstroReflectionPrivate
40 ClutterActor *songs_reflect;
41 ClutterActor *texture;
42 ClutterActor *reflect;
45 ClutterEffectTemplate *songs_temp;
46 ClutterTimeline *songs_time;
57 fix_clip (ClutterTimeline *timeline,
59 AstroReflection *reflection)
61 AstroReflectionPrivate *priv;
64 g_return_if_fail (ASTRO_IS_REFLECTION (reflection));
65 priv = reflection->priv;
67 size = clutter_actor_get_width (priv->songs);
69 astro_utils_set_clip (priv->songs_reflect,
70 size - clutter_actor_get_x (priv->songs_reflect),
75 astro_reflection_set_active (AstroReflection *reflection,
78 AstroReflectionPrivate *priv;
79 static ClutterTimeline *fade_time = NULL;
83 g_return_if_fail (ASTRO_IS_REFLECTION (reflection));
84 priv = reflection->priv;
88 x = clutter_actor_get_width (priv->texture);
92 clutter_effect_move (priv->songs_temp,
94 x, clutter_actor_get_y (priv->songs),
96 clutter_effect_move (priv->songs_temp,
98 x, clutter_actor_get_y (priv->songs_reflect),
101 fade_time = clutter_effect_fade (priv->songs_temp,
105 g_signal_connect (fade_time, "new-frame",
106 G_CALLBACK (fix_clip), reflection);
111 astro_reflection_set_pixbuf (AstroReflection *reflection,
114 AstroReflectionPrivate *priv;
117 g_return_if_fail (ASTRO_IS_REFLECTION (reflection));
118 priv = reflection->priv;
120 if (CLUTTER_IS_ACTOR (priv->texture))
121 clutter_actor_destroy (priv->texture);
123 if (CLUTTER_IS_ACTOR (priv->reflect))
124 clutter_actor_destroy (priv->reflect);
126 height = gdk_pixbuf_get_height (pixbuf);
131 disc_bg = gdk_pixbuf_new_from_file_at_size (PKGDATADIR"/disc_bg.svg",
132 height, height, NULL);
134 priv->songs = clutter_texture_new_from_pixbuf (disc_bg);
135 clutter_container_add_actor (CLUTTER_CONTAINER (reflection), priv->songs);
136 clutter_actor_set_size (priv->songs, height, height);
137 clutter_actor_set_position (priv->songs, 0, 0);
139 priv->songs_reflect = clutter_reflect_texture_new (CLUTTER_TEXTURE (priv->songs),
141 clutter_actor_set_opacity (priv->songs_reflect, 0);
142 clutter_container_add_actor (CLUTTER_CONTAINER (reflection),
143 priv->songs_reflect);
144 clutter_actor_set_position (priv->songs_reflect, 0, height+1);
147 priv->texture = g_object_new (CLUTTER_TYPE_TEXTURE,
152 clutter_container_add_actor (CLUTTER_CONTAINER (reflection),
154 clutter_actor_set_position (priv->texture, 0, 0);
156 priv->reflect = clutter_reflect_texture_new (CLUTTER_TEXTURE (priv->texture),
158 clutter_actor_set_opacity (priv->reflect, 100);
159 clutter_container_add_actor (CLUTTER_CONTAINER (reflection),
161 clutter_actor_set_position (priv->reflect, 0, height+1);
163 clutter_actor_set_anchor_point (CLUTTER_ACTOR (reflection),
164 clutter_actor_get_width (priv->texture)/2,
167 clutter_actor_show_all (CLUTTER_ACTOR (reflection));
172 astro_reflection_set_property (GObject *object,
177 AstroReflectionPrivate *priv;
179 g_return_if_fail (ASTRO_IS_REFLECTION (object));
180 priv = ASTRO_REFLECTION (object)->priv;
185 astro_reflection_set_pixbuf (ASTRO_REFLECTION (object),
186 GDK_PIXBUF (g_value_get_object (value)));
189 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
195 astro_reflection_get_property (GObject *object,
200 AstroReflectionPrivate *priv;
202 g_return_if_fail (ASTRO_IS_REFLECTION (object));
203 priv = ASTRO_REFLECTION (object)->priv;
208 g_value_set_object (value, G_OBJECT (priv->pixbuf));
211 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
217 astro_reflection_class_init (AstroReflectionClass *klass)
219 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
221 gobject_class->set_property = astro_reflection_set_property;
222 gobject_class->get_property = astro_reflection_get_property;
224 g_object_class_install_property (
227 g_param_spec_object ("pixbuf",
233 g_type_class_add_private (gobject_class, sizeof (AstroReflectionPrivate));
237 astro_reflection_init (AstroReflection *reflection)
239 AstroReflectionPrivate *priv;
240 priv = reflection->priv = ASTRO_REFLECTION_GET_PRIVATE (reflection);
242 priv->texture = NULL;
243 priv->reflect = NULL;
245 priv->songs_time = clutter_timeline_new_for_duration (600);
246 priv->songs_temp = clutter_effect_template_new (priv->songs_time,
247 clutter_sine_inc_func);
251 astro_reflection_new (GdkPixbuf *pixbuf)
253 ClutterActor *reflection = g_object_new (ASTRO_TYPE_REFLECTION,
256 return CLUTTER_ACTOR (reflection);