mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 16:10:41 -05:00
Rename ActorClone to Clone/2
Step two: rename the object and its methods. While we're at it, adhere more strictly to the coding style practises; rename :clone-source to :source; add a setter method for the :source property; take a reference on the source actor to avoid it disappearing while we're still accessing it.
This commit is contained in:
parent
9197646d25
commit
86e4e89bf1
@ -26,7 +26,7 @@
|
||||
* @short_description: An actor that displays a scaled clone of another
|
||||
* actor.
|
||||
*
|
||||
* #ClutterActorClone is a #ClutterActor which draws with the paint
|
||||
* #ClutterClone is a #ClutterActor which draws with the paint
|
||||
* function of another actor, scaled to fit its own allocation.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
@ -41,64 +41,81 @@
|
||||
|
||||
#include "cogl/cogl.h"
|
||||
|
||||
G_DEFINE_TYPE (ClutterActorClone, clutter_actor_clone, CLUTTER_TYPE_ACTOR);
|
||||
G_DEFINE_TYPE (ClutterClone, clutter_clone, CLUTTER_TYPE_ACTOR);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
|
||||
PROP_CLONE_SOURCE
|
||||
PROP_SOURCE
|
||||
};
|
||||
|
||||
#define CLUTTER_ACTOR_CLONE_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
|
||||
CLUTTER_TYPE_ACTOR_CLONE, \
|
||||
ClutterActorClonePrivate))
|
||||
#define CLUTTER_CLONE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_CLONE, ClutterClonePrivate))
|
||||
|
||||
struct _ClutterActorClonePrivate
|
||||
struct _ClutterClonePrivate
|
||||
{
|
||||
ClutterActor *clone_source;
|
||||
ClutterActor *clone_source;
|
||||
};
|
||||
|
||||
static void
|
||||
clutter_actor_clone_get_preferred_width (ClutterActor *self,
|
||||
ClutterUnit for_height,
|
||||
ClutterUnit *min_width_p,
|
||||
ClutterUnit *natural_width_p)
|
||||
clutter_clone_get_preferred_width (ClutterActor *self,
|
||||
ClutterUnit for_height,
|
||||
ClutterUnit *min_width_p,
|
||||
ClutterUnit *natural_width_p)
|
||||
{
|
||||
ClutterActorClonePrivate *priv = CLUTTER_ACTOR_CLONE (self)->priv;
|
||||
ClutterActor *clone_source = priv->clone_source;
|
||||
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv;
|
||||
ClutterActor *clone_source = priv->clone_source;
|
||||
|
||||
clutter_actor_get_preferred_width (clone_source,
|
||||
for_height,
|
||||
min_width_p,
|
||||
natural_width_p);
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_actor_clone_get_preferred_height (ClutterActor *self,
|
||||
ClutterUnit for_width,
|
||||
ClutterUnit *min_height_p,
|
||||
ClutterUnit *natural_height_p)
|
||||
clutter_clone_get_preferred_height (ClutterActor *self,
|
||||
ClutterUnit for_width,
|
||||
ClutterUnit *min_height_p,
|
||||
ClutterUnit *natural_height_p)
|
||||
{
|
||||
ClutterActorClonePrivate *priv = CLUTTER_ACTOR_CLONE (self)->priv;
|
||||
ClutterActor *clone_source = priv->clone_source;
|
||||
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv;
|
||||
ClutterActor *clone_source = priv->clone_source;
|
||||
|
||||
clutter_actor_get_preferred_height (clone_source,
|
||||
for_width,
|
||||
min_height_p,
|
||||
natural_height_p);
|
||||
if (G_UNLIKELY (clone_source == NULL))
|
||||
{
|
||||
if (min_height_p)
|
||||
*min_height_p = 0;
|
||||
|
||||
if (natural_height_p)
|
||||
*natural_height_p = 0;
|
||||
}
|
||||
else
|
||||
clutter_actor_get_preferred_height (clone_source,
|
||||
for_width,
|
||||
min_height_p,
|
||||
natural_height_p);
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_actor_clone_paint (ClutterActor *self)
|
||||
clutter_clone_paint (ClutterActor *self)
|
||||
{
|
||||
ClutterActorClone *clone = CLUTTER_ACTOR_CLONE (self);
|
||||
ClutterActorClonePrivate *priv = clone->priv;
|
||||
ClutterGeometry geom;
|
||||
ClutterGeometry clone_source_geom;
|
||||
float x_scale;
|
||||
float y_scale;
|
||||
ClutterClone *clone = CLUTTER_CLONE (self);
|
||||
ClutterClonePrivate *priv = clone->priv;
|
||||
ClutterGeometry geom;
|
||||
ClutterGeometry clone_source_geom;
|
||||
gfloat x_scale, y_scale;
|
||||
|
||||
if (G_UNLIKELY (priv->clone_source == NULL))
|
||||
return;
|
||||
|
||||
CLUTTER_NOTE (PAINT,
|
||||
"painting clone actor '%s'",
|
||||
@ -112,10 +129,11 @@ clutter_actor_clone_paint (ClutterActor *self)
|
||||
/* We need to scale what the clone-source actor paints to fill our own
|
||||
* allocation... */
|
||||
|
||||
x_scale = (float)geom.width / clone_source_geom.width;
|
||||
y_scale = (float)geom.height / clone_source_geom.height;
|
||||
x_scale = (gfloat) geom.width / clone_source_geom.width;
|
||||
y_scale = (gfloat) geom.height / clone_source_geom.height;
|
||||
|
||||
cogl_scale (COGL_FIXED_FROM_FLOAT (x_scale), COGL_FIXED_FROM_FLOAT (y_scale));
|
||||
cogl_scale (COGL_FIXED_FROM_FLOAT (x_scale),
|
||||
COGL_FIXED_FROM_FLOAT (y_scale));
|
||||
|
||||
/* The final bits of magic:
|
||||
* - We need to make sure that when the clone-source actor's paint method
|
||||
@ -135,140 +153,166 @@ clutter_actor_clone_paint (ClutterActor *self)
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_actor_clone_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
clutter_clone_set_property (GObject *gobject,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ClutterActorClone *clone = CLUTTER_ACTOR_CLONE(object);
|
||||
ClutterClone *clone = CLUTTER_CLONE (gobject);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CLONE_SOURCE:
|
||||
clone->priv->clone_source = g_value_get_object (value);
|
||||
case PROP_SOURCE:
|
||||
clutter_clone_set_source (clone, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_actor_clone_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
clutter_clone_get_property (GObject *gobject,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ClutterActorClonePrivate *priv = CLUTTER_ACTOR_CLONE(object)->priv;
|
||||
ClutterClonePrivate *priv = CLUTTER_CLONE (gobject)->priv;
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CLONE_SOURCE:
|
||||
case PROP_SOURCE:
|
||||
g_value_set_object (value, priv->clone_source);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_actor_clone_finalize (GObject *object)
|
||||
clutter_clone_dispose (GObject *gobject)
|
||||
{
|
||||
G_OBJECT_CLASS (clutter_actor_clone_parent_class)->finalize (object);
|
||||
ClutterClonePrivate *priv = CLUTTER_CLONE (gobject)->priv;
|
||||
|
||||
if (priv->clone_source)
|
||||
{
|
||||
g_object_unref (priv->clone_source);
|
||||
priv->clone_source = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (clutter_clone_parent_class)->dispose (gobject);
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_actor_clone_dispose (GObject *object)
|
||||
clutter_clone_class_init (ClutterCloneClass *klass)
|
||||
{
|
||||
G_OBJECT_CLASS (clutter_actor_clone_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_actor_clone_class_init (ClutterActorCloneClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
||||
GParamSpec *pspec = NULL;
|
||||
|
||||
actor_class->paint = clutter_actor_clone_paint;
|
||||
actor_class->get_preferred_width =
|
||||
clutter_actor_clone_get_preferred_width;
|
||||
actor_class->get_preferred_height =
|
||||
clutter_actor_clone_get_preferred_height;
|
||||
g_type_class_add_private (gobject_class, sizeof (ClutterClonePrivate));
|
||||
|
||||
gobject_class->finalize = clutter_actor_clone_finalize;
|
||||
gobject_class->dispose = clutter_actor_clone_dispose;
|
||||
gobject_class->set_property = clutter_actor_clone_set_property;
|
||||
gobject_class->get_property = clutter_actor_clone_get_property;
|
||||
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;
|
||||
|
||||
gobject_class->dispose = clutter_clone_dispose;
|
||||
gobject_class->set_property = clutter_clone_set_property;
|
||||
gobject_class->get_property = clutter_clone_get_property;
|
||||
|
||||
/**
|
||||
* ClutterActorClone:clone-source
|
||||
* ClutterClone:source:
|
||||
*
|
||||
* This specifies the source actor being cloned
|
||||
* This property specifies the source actor being cloned.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_CLONE_SOURCE,
|
||||
g_param_spec_object ("clone-source",
|
||||
"Clone Source",
|
||||
"Specifies the actor to be cloned",
|
||||
CLUTTER_TYPE_ACTOR,
|
||||
G_PARAM_CONSTRUCT_ONLY
|
||||
|G_PARAM_WRITABLE
|
||||
|G_PARAM_READABLE));
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof (ClutterActorClonePrivate));
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_actor_clone_init (ClutterActorClone *self)
|
||||
clutter_clone_init (ClutterClone *self)
|
||||
{
|
||||
ClutterActorClonePrivate *priv;
|
||||
ClutterClonePrivate *priv;
|
||||
|
||||
self->priv = priv = CLUTTER_ACTOR_CLONE_GET_PRIVATE (self);
|
||||
self->priv = priv = CLUTTER_CLONE_GET_PRIVATE (self);
|
||||
|
||||
priv->clone_source = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_actor_clone_new:
|
||||
* clutter_clone_new:
|
||||
* @source: a #ClutterActor, or %NULL
|
||||
*
|
||||
* Creates a new #ClutterActor which clones clone_source.
|
||||
* Creates a new #ClutterActor which clones @source/
|
||||
*
|
||||
* Return value: a new #ClutterActor
|
||||
* Return value: the newly created #ClutterClone
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
ClutterActor *
|
||||
clutter_actor_clone_new (ClutterActor *clone_source)
|
||||
clutter_clone_new (ClutterActor *source)
|
||||
{
|
||||
return g_object_new (CLUTTER_TYPE_ACTOR_CLONE,
|
||||
"clone-source", clone_source,
|
||||
NULL);
|
||||
return g_object_new (CLUTTER_TYPE_CLONE, "source", source, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_actor_clone_get_clone_source:
|
||||
* clutter_clone_set_source:
|
||||
* @clone: a #ClutterClone
|
||||
* @source: a #ClutterActor, or %NULL
|
||||
*
|
||||
* @clone: a #ClutterActorClone
|
||||
* Sets @source as the source actor to be cloned by @clone.
|
||||
*
|
||||
* Retrieves the source #ClutterActor being clone by @clone
|
||||
* Since: 1.0
|
||||
*/
|
||||
void
|
||||
clutter_clone_set_source (ClutterClone *clone,
|
||||
ClutterActor *source)
|
||||
{
|
||||
ClutterClonePrivate *priv;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_CLONE (clone));
|
||||
g_return_if_fail (source == NULL || CLUTTER_IS_ACTOR (source));
|
||||
|
||||
priv = clone->priv;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 *
|
||||
clutter_actor_clone_get_clone_source (ClutterActorClone *clone)
|
||||
clutter_clone_get_clone_source (ClutterClone *clone)
|
||||
{
|
||||
ClutterActorClonePrivate *priv;
|
||||
g_return_val_if_fail (CLUTTER_IS_CLONE (clone), NULL);
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_ACTOR_CLONE (clone), NULL);
|
||||
|
||||
priv = clone->priv;
|
||||
|
||||
return priv->clone_source;
|
||||
return clone->priv->clone_source;
|
||||
}
|
||||
|
||||
|
@ -25,35 +25,33 @@
|
||||
#error "Only <clutter/clutter.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __CLUTTER_ACTOR_CLONE_H__
|
||||
#define __CLUTTER_ACTOR_CLONE_H__
|
||||
#ifndef __CLUTTER_CLONE_H__
|
||||
#define __CLUTTER_CLONE_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <clutter/clutter-actor.h>
|
||||
#include <clutter/clutter-color.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_ACTOR_CLONE (clutter_actor_clone_get_type())
|
||||
#define CLUTTER_ACTOR_CLONE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_ACTOR_CLONE, ClutterActorClone))
|
||||
#define CLUTTER_ACTOR_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_ACTOR_CLONE, ClutterActorCloneClass))
|
||||
#define CLUTTER_IS_ACTOR_CLONE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_ACTOR_CLONE))
|
||||
#define CLUTTER_IS_ACTOR_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_ACTOR_CLONE))
|
||||
#define CLUTTER_ACTOR_CLONE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_ACTOR_CLONE, ClutterActorCloneClass))
|
||||
#define CLUTTER_TYPE_CLONE (clutter_clone_get_type())
|
||||
#define CLUTTER_CLONE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_CLONE, ClutterClone))
|
||||
#define CLUTTER_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_CLONE, ClutterCloneClass))
|
||||
#define CLUTTER_IS_CLONE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_CLONE))
|
||||
#define CLUTTER_IS_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_CLONE))
|
||||
#define CLUTTER_CLONE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_CLONE, ClutterCloneClass))
|
||||
|
||||
typedef struct _ClutterActorClone ClutterActorClone;
|
||||
typedef struct _ClutterActorCloneClass ClutterActorCloneClass;
|
||||
typedef struct _ClutterActorClonePrivate ClutterActorClonePrivate;
|
||||
typedef struct _ClutterClone ClutterClone;
|
||||
typedef struct _ClutterCloneClass ClutterCloneClass;
|
||||
typedef struct _ClutterClonePrivate ClutterClonePrivate;
|
||||
|
||||
struct _ClutterActorClone
|
||||
struct _ClutterClone
|
||||
{
|
||||
/*< private >*/
|
||||
ClutterActor parent;
|
||||
ClutterActor parent_instance;
|
||||
|
||||
ClutterActorClonePrivate *priv;
|
||||
ClutterClonePrivate *priv;
|
||||
};
|
||||
|
||||
struct _ClutterActorCloneClass
|
||||
struct _ClutterCloneClass
|
||||
{
|
||||
/*< private >*/
|
||||
ClutterActorClass parent_class;
|
||||
@ -65,12 +63,13 @@ struct _ClutterActorCloneClass
|
||||
void (*_clutter_actor_clone4) (void);
|
||||
};
|
||||
|
||||
GType clutter_actor_clone_get_type (void) G_GNUC_CONST;
|
||||
GType clutter_clone_get_type (void) G_GNUC_CONST;
|
||||
|
||||
ClutterActor *clutter_actor_clone_new (ClutterActor *clone_source);
|
||||
|
||||
ClutterActor *clutter_actor_clone_get_clone_source (ClutterActorClone *clone);
|
||||
ClutterActor *clutter_clone_new (ClutterActor *source);
|
||||
void clutter_clone_set_source (ClutterClone *clone,
|
||||
ClutterActor *source);
|
||||
ClutterActor *clutter_clone_get_source (ClutterClone *clone);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_ACTOR_CLONE_H__ */
|
||||
#endif /* __CLUTTER_CLONE_H__ */
|
||||
|
@ -55,7 +55,7 @@ input_cb (ClutterActor *stage,
|
||||
|
||||
e = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (stage), x, y);
|
||||
|
||||
if (e && (CLUTTER_IS_TEXTURE (e) || CLUTTER_IS_CLONE_TEXTURE (e)))
|
||||
if (e && (CLUTTER_IS_TEXTURE (e) || CLUTTER_IS_CLONE (e)))
|
||||
{
|
||||
clutter_actor_hide (e);
|
||||
return TRUE;
|
||||
@ -212,7 +212,7 @@ test_actor_clone_main (int argc, char *argv[])
|
||||
gint x, y, w, h;
|
||||
|
||||
/* Create a texture from file, then clone in to same resources */
|
||||
oh->hand[i] = clutter_actor_clone_new (real_hand);
|
||||
oh->hand[i] = clutter_clone_new (real_hand);
|
||||
clutter_actor_set_size (oh->hand[i], 200, 213);
|
||||
|
||||
/* Place around a circle */
|
||||
|
Loading…
Reference in New Issue
Block a user