2009-01-17 16:51:03 +00:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Intel Corporation.
|
|
|
|
*
|
|
|
|
* Authored By: Robert Bragg <robert@linux.intel.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-01-27 15:18:45 +00:00
|
|
|
* SECTION:clutterclone
|
|
|
|
* @short_description: An actor that displays a clone of a source actor
|
2009-01-17 16:51:03 +00:00
|
|
|
*
|
2009-01-26 11:03:12 +00:00
|
|
|
* #ClutterClone is a #ClutterActor which draws with the paint
|
2009-01-17 16:51:03 +00:00
|
|
|
* function of another actor, scaled to fit its own allocation.
|
2009-01-27 15:18:45 +00:00
|
|
|
*
|
|
|
|
* #ClutterClone can be used to efficiently clone any other actor.
|
|
|
|
*
|
|
|
|
* <note><para>This is different from clutter_texture_new_from_actor()
|
|
|
|
* which requires support for FBOs in the underlying GL
|
|
|
|
* implementation.</para></note>
|
|
|
|
*
|
|
|
|
* #ClutterClone is available since Clutter 1.0
|
2009-01-17 16:51:03 +00:00
|
|
|
*/
|
2009-01-27 15:18:45 +00:00
|
|
|
|
2009-01-17 16:51:03 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "clutter-color.h"
|
2009-01-26 10:32:53 +00:00
|
|
|
#include "clutter-clone.h"
|
2009-01-17 16:51:03 +00:00
|
|
|
#include "clutter-debug.h"
|
|
|
|
#include "clutter-main.h"
|
|
|
|
#include "clutter-private.h"
|
|
|
|
|
|
|
|
#include "cogl/cogl.h"
|
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
G_DEFINE_TYPE (ClutterClone, clutter_clone, CLUTTER_TYPE_ACTOR);
|
2009-01-17 16:51:03 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
PROP_SOURCE
|
2009-01-17 16:51:03 +00:00
|
|
|
};
|
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
#define CLUTTER_CLONE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_CLONE, ClutterClonePrivate))
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
struct _ClutterClonePrivate
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
ClutterActor *clone_source;
|
2009-01-17 16:51:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2009-01-26 11:03:12 +00:00
|
|
|
clutter_clone_get_preferred_width (ClutterActor *self,
|
|
|
|
ClutterUnit for_height,
|
|
|
|
ClutterUnit *min_width_p,
|
|
|
|
ClutterUnit *natural_width_p)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv;
|
|
|
|
ClutterActor *clone_source = priv->clone_source;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
if (G_UNLIKELY (clone_source == NULL))
|
|
|
|
{
|
|
|
|
if (min_width_p)
|
|
|
|
*min_width_p = 0;
|
|
|
|
|
|
|
|
if (natural_width_p)
|
|
|
|
*natural_width_p = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
clutter_actor_get_preferred_width (clone_source,
|
|
|
|
for_height,
|
|
|
|
min_width_p,
|
|
|
|
natural_width_p);
|
2009-01-17 16:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-01-26 11:03:12 +00:00
|
|
|
clutter_clone_get_preferred_height (ClutterActor *self,
|
|
|
|
ClutterUnit for_width,
|
|
|
|
ClutterUnit *min_height_p,
|
|
|
|
ClutterUnit *natural_height_p)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv;
|
|
|
|
ClutterActor *clone_source = priv->clone_source;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (clone_source == NULL))
|
|
|
|
{
|
|
|
|
if (min_height_p)
|
|
|
|
*min_height_p = 0;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
if (natural_height_p)
|
|
|
|
*natural_height_p = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
clutter_actor_get_preferred_height (clone_source,
|
|
|
|
for_width,
|
|
|
|
min_height_p,
|
|
|
|
natural_height_p);
|
2009-01-17 16:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-01-26 11:03:12 +00:00
|
|
|
clutter_clone_paint (ClutterActor *self)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
ClutterClone *clone = CLUTTER_CLONE (self);
|
|
|
|
ClutterClonePrivate *priv = clone->priv;
|
2009-02-02 11:59:39 +00:00
|
|
|
ClutterGeometry geom, clone_geom;
|
2009-01-26 11:03:12 +00:00
|
|
|
gfloat x_scale, y_scale;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (priv->clone_source == NULL))
|
|
|
|
return;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
|
|
|
CLUTTER_NOTE (PAINT,
|
|
|
|
"painting clone actor '%s'",
|
|
|
|
clutter_actor_get_name (self) ? clutter_actor_get_name (self)
|
|
|
|
: "unknown");
|
|
|
|
|
2009-02-02 11:59:39 +00:00
|
|
|
/* get our allocated size */
|
2009-01-17 16:51:03 +00:00
|
|
|
clutter_actor_get_allocation_geometry (self, &geom);
|
|
|
|
|
2009-02-02 11:59:39 +00:00
|
|
|
/* and get the allocated size of the source */
|
|
|
|
clutter_actor_get_allocation_geometry (priv->clone_source, &clone_geom);
|
2009-01-19 19:11:00 +00:00
|
|
|
|
2009-02-02 11:59:39 +00:00
|
|
|
/* We need to scale what the clone-source actor paints to fill our own
|
|
|
|
* allocation...
|
|
|
|
*/
|
|
|
|
x_scale = (gfloat) geom.width / clone_geom.width;
|
|
|
|
y_scale = (gfloat) geom.height / clone_geom.height;
|
2009-01-19 19:11:00 +00:00
|
|
|
|
2009-01-27 16:12:30 +00:00
|
|
|
cogl_scale (x_scale, y_scale, 1.0);
|
2009-01-17 16:51:03 +00:00
|
|
|
|
|
|
|
/* The final bits of magic:
|
2009-02-04 00:14:16 +00:00
|
|
|
* - We need to make sure that when the clone-source actor's paint
|
|
|
|
* method calls clutter_actor_get_paint_opacity, it traverses to
|
|
|
|
* us and our parent not it's real parent.
|
2009-01-17 16:51:03 +00:00
|
|
|
* - We need to stop clutter_actor_paint applying the model view matrix of
|
|
|
|
* the clone source actor.
|
|
|
|
*/
|
2009-02-04 00:14:16 +00:00
|
|
|
_clutter_actor_set_opacity_parent (priv->clone_source, self);
|
2009-01-17 16:51:03 +00:00
|
|
|
_clutter_actor_set_enable_model_view_transform (priv->clone_source, FALSE);
|
|
|
|
|
|
|
|
clutter_actor_paint (priv->clone_source);
|
|
|
|
|
|
|
|
_clutter_actor_set_enable_model_view_transform (priv->clone_source, TRUE);
|
|
|
|
_clutter_actor_set_opacity_parent (priv->clone_source, NULL);
|
|
|
|
}
|
|
|
|
|
2009-02-02 11:59:39 +00:00
|
|
|
static void
|
|
|
|
clutter_clone_allocate (ClutterActor *self,
|
|
|
|
const ClutterActorBox *box,
|
|
|
|
gboolean origin_changed)
|
|
|
|
{
|
|
|
|
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv;
|
|
|
|
ClutterActorClass *parent_class;
|
|
|
|
|
|
|
|
/* chain up */
|
|
|
|
parent_class = CLUTTER_ACTOR_CLASS (clutter_clone_parent_class);
|
|
|
|
parent_class->allocate (self, box, origin_changed);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (priv->clone_source == NULL))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* we act like a "foster parent" for the source we are cloning;
|
|
|
|
* if the source has not been parented we have to force an
|
|
|
|
* allocation on it, so that we can paint it correctly from
|
|
|
|
* within out paint() implementation. since the actor does not
|
|
|
|
* have a parent, and thus it won't be painted by the usual
|
|
|
|
* paint cycle, we can safely give it as much size as it requires
|
|
|
|
*/
|
|
|
|
if (clutter_actor_get_parent (priv->clone_source) == NULL)
|
|
|
|
{
|
|
|
|
clutter_actor_allocate_preferred_size (priv->clone_source,
|
|
|
|
origin_changed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-17 16:51:03 +00:00
|
|
|
static void
|
2009-01-26 11:03:12 +00:00
|
|
|
clutter_clone_set_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
ClutterClone *clone = CLUTTER_CLONE (gobject);
|
2009-01-17 16:51:03 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
case PROP_SOURCE:
|
|
|
|
clutter_clone_set_source (clone, g_value_get_object (value));
|
2009-01-17 16:51:03 +00:00
|
|
|
break;
|
2009-01-26 11:03:12 +00:00
|
|
|
|
2009-01-17 16:51:03 +00:00
|
|
|
default:
|
2009-01-26 11:03:12 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
2009-01-17 16:51:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-01-26 11:03:12 +00:00
|
|
|
clutter_clone_get_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
ClutterClonePrivate *priv = CLUTTER_CLONE (gobject)->priv;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
case PROP_SOURCE:
|
2009-01-17 16:51:03 +00:00
|
|
|
g_value_set_object (value, priv->clone_source);
|
|
|
|
break;
|
2009-01-26 11:03:12 +00:00
|
|
|
|
2009-01-17 16:51:03 +00:00
|
|
|
default:
|
2009-01-26 11:03:12 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
2009-01-17 16:51:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-01-26 11:03:12 +00:00
|
|
|
clutter_clone_dispose (GObject *gobject)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
ClutterClonePrivate *priv = CLUTTER_CLONE (gobject)->priv;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
if (priv->clone_source)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->clone_source);
|
|
|
|
priv->clone_source = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_clone_parent_class)->dispose (gobject);
|
2009-01-17 16:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-01-26 11:03:12 +00:00
|
|
|
clutter_clone_class_init (ClutterCloneClass *klass)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2009-01-17 16:51:03 +00:00
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
2009-01-26 11:03:12 +00:00
|
|
|
GParamSpec *pspec = NULL;
|
|
|
|
|
|
|
|
g_type_class_add_private (gobject_class, sizeof (ClutterClonePrivate));
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
actor_class->paint = clutter_clone_paint;
|
|
|
|
actor_class->get_preferred_width = clutter_clone_get_preferred_width;
|
|
|
|
actor_class->get_preferred_height = clutter_clone_get_preferred_height;
|
2009-02-02 11:59:39 +00:00
|
|
|
actor_class->allocate = clutter_clone_allocate;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
gobject_class->dispose = clutter_clone_dispose;
|
|
|
|
gobject_class->set_property = clutter_clone_set_property;
|
|
|
|
gobject_class->get_property = clutter_clone_get_property;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
|
|
|
/**
|
2009-01-26 11:03:12 +00:00
|
|
|
* ClutterClone:source:
|
2009-01-17 16:51:03 +00:00
|
|
|
*
|
2009-01-26 11:03:12 +00:00
|
|
|
* This property specifies the source actor being cloned.
|
2009-01-17 16:51:03 +00:00
|
|
|
*
|
|
|
|
* Since: 1.0
|
|
|
|
*/
|
2009-01-26 11:03:12 +00:00
|
|
|
pspec = g_param_spec_object ("source",
|
|
|
|
"Source",
|
|
|
|
"Specifies the actor to be cloned",
|
|
|
|
CLUTTER_TYPE_ACTOR,
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
CLUTTER_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SOURCE, pspec);
|
2009-01-17 16:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-01-26 11:03:12 +00:00
|
|
|
clutter_clone_init (ClutterClone *self)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
ClutterClonePrivate *priv;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
self->priv = priv = CLUTTER_CLONE_GET_PRIVATE (self);
|
2009-01-17 16:51:03 +00:00
|
|
|
|
|
|
|
priv->clone_source = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-26 11:03:12 +00:00
|
|
|
* clutter_clone_new:
|
|
|
|
* @source: a #ClutterActor, or %NULL
|
2009-01-17 16:51:03 +00:00
|
|
|
*
|
2009-01-26 11:03:12 +00:00
|
|
|
* Creates a new #ClutterActor which clones @source/
|
2009-01-17 16:51:03 +00:00
|
|
|
*
|
2009-01-26 11:03:12 +00:00
|
|
|
* Return value: the newly created #ClutterClone
|
2009-01-17 16:51:03 +00:00
|
|
|
*
|
|
|
|
* Since: 1.0
|
|
|
|
*/
|
|
|
|
ClutterActor *
|
2009-01-26 11:03:12 +00:00
|
|
|
clutter_clone_new (ClutterActor *source)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
return g_object_new (CLUTTER_TYPE_CLONE, "source", source, NULL);
|
2009-01-17 16:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-26 11:03:12 +00:00
|
|
|
* clutter_clone_set_source:
|
|
|
|
* @clone: a #ClutterClone
|
|
|
|
* @source: a #ClutterActor, or %NULL
|
2009-01-17 16:51:03 +00:00
|
|
|
*
|
2009-01-26 11:03:12 +00:00
|
|
|
* Sets @source as the source actor to be cloned by @clone.
|
2009-01-17 16:51:03 +00:00
|
|
|
*
|
|
|
|
* Since: 1.0
|
|
|
|
*/
|
2009-01-26 11:03:12 +00:00
|
|
|
void
|
|
|
|
clutter_clone_set_source (ClutterClone *clone,
|
|
|
|
ClutterActor *source)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2009-01-26 11:03:12 +00:00
|
|
|
ClutterClonePrivate *priv;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_CLONE (clone));
|
|
|
|
g_return_if_fail (source == NULL || CLUTTER_IS_ACTOR (source));
|
2009-01-17 16:51:03 +00:00
|
|
|
|
|
|
|
priv = clone->priv;
|
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
if (priv->clone_source)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->clone_source);
|
|
|
|
priv->clone_source = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source)
|
|
|
|
priv->clone_source = g_object_ref (source);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (clone), "source");
|
|
|
|
|
|
|
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (clone));
|
2009-01-17 16:51:03 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
/**
|
|
|
|
* clutter_clone_get_source:
|
|
|
|
* @clone: a #ClutterClone
|
|
|
|
*
|
|
|
|
* Retrieves the source #ClutterActor being cloned by @clone
|
|
|
|
*
|
|
|
|
* Return value: the actor source for the clone
|
|
|
|
*
|
|
|
|
* Since: 1.0
|
|
|
|
*/
|
|
|
|
ClutterActor *
|
2009-01-27 20:06:58 +00:00
|
|
|
clutter_clone_get_source (ClutterClone *clone)
|
2009-01-26 11:03:12 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_CLONE (clone), NULL);
|
|
|
|
|
|
|
|
return clone->priv->clone_source;
|
|
|
|
}
|