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-03-16 15:00:55 +00:00
|
|
|
* SECTION:clutter-clone
|
2009-01-27 15:18:45 +00:00
|
|
|
* @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.
|
|
|
|
*
|
2014-03-17 23:07:58 +00:00
|
|
|
* Unlike clutter_texture_new_from_actor(), #ClutterClone does not require
|
|
|
|
* the presence of support for FBOs in the underlying GL or GLES
|
|
|
|
* implementation.
|
2009-01-27 15:18:45 +00:00
|
|
|
*
|
|
|
|
* #ClutterClone is available since Clutter 1.0
|
2009-01-17 16:51:03 +00:00
|
|
|
*/
|
2009-01-27 15:18:45 +00:00
|
|
|
|
2016-05-05 14:21:51 +00:00
|
|
|
#include "clutter-build-config.h"
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2012-06-04 21:42:04 +00:00
|
|
|
#define CLUTTER_ENABLE_EXPERIMENTAL_API
|
2010-10-21 11:16:05 +00:00
|
|
|
#include "clutter-actor-private.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"
|
2010-10-21 10:59:50 +00:00
|
|
|
#include "clutter-paint-volume-private.h"
|
2009-01-17 16:51:03 +00:00
|
|
|
#include "clutter-private.h"
|
|
|
|
|
|
|
|
#include "cogl/cogl.h"
|
|
|
|
|
2013-07-03 13:14:01 +00:00
|
|
|
struct _ClutterClonePrivate
|
|
|
|
{
|
|
|
|
ClutterActor *clone_source;
|
2017-03-02 18:18:43 +00:00
|
|
|
gulong source_destroy_id;
|
2013-07-03 13:14:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (ClutterClone, clutter_clone, CLUTTER_TYPE_ACTOR)
|
2009-01-17 16:51:03 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
2010-06-21 09:20:32 +00:00
|
|
|
PROP_SOURCE,
|
|
|
|
|
|
|
|
PROP_LAST
|
2009-01-17 16:51:03 +00:00
|
|
|
};
|
|
|
|
|
2010-06-21 09:20:32 +00:00
|
|
|
static GParamSpec *obj_props[PROP_LAST];
|
|
|
|
|
2009-02-27 19:43:47 +00:00
|
|
|
static void clutter_clone_set_source_internal (ClutterClone *clone,
|
|
|
|
ClutterActor *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,
|
Remove Units from the public API
With the recent change to internal floating point values, ClutterUnit
has become a redundant type, defined to be a float. All integer entry
points are being internally converted to floating point values to be
passed to the GL pipeline with the least amount of conversion.
ClutterUnit is thus exposed as just a "pixel with fractionary bits",
and not -- as users might think -- as generic, resolution and device
independent units. not that it was the case, but a definitive amount
of people was convinced it did provide this "feature", and was flummoxed
about the mere existence of this type.
So, having ClutterUnit exposed in the public API doubles the entry
points and has the following disadvantages:
- we have to maintain twice the amount of entry points in ClutterActor
- we still do an integer-to-float implicit conversion
- we introduce a weird impedance between pixels and "pixels with
fractionary bits"
- language bindings will have to choose what to bind, and resort
to manually overriding the API
+ *except* for language bindings based on GObject-Introspection, as
they cannot do manual overrides, thus will replicate the entire
set of entry points
For these reason, we should coalesces every Actor entry point for
pixels and for ClutterUnit into a single entry point taking a float,
like:
void clutter_actor_set_x (ClutterActor *self,
gfloat x);
void clutter_actor_get_size (ClutterActor *self,
gfloat *width,
gfloat *height);
gfloat clutter_actor_get_height (ClutterActor *self);
etc.
The issues I have identified are:
- we'll have a two cases of compiler warnings:
- printf() format of the return values from %d to %f
- clutter_actor_get_size() taking floats instead of unsigned ints
- we'll have a problem with varargs when passing an integer instead
of a floating point value, except on 64bit platforms where the
size of a float is the same as the size of an int
To be clear: the *intent* of the API should not change -- we still use
pixels everywhere -- but:
- we remove ambiguity in the API with regard to pixels and units
- we remove entry points we get to maintain for the whole 1.0
version of the API
- we make things simpler to bind for both manual language bindings
and automatic (gobject-introspection based) ones
- we have the simplest API possible while still exposing the
capabilities of the underlying GL implementation
2009-05-06 15:44:47 +00:00
|
|
|
gfloat for_height,
|
|
|
|
gfloat *min_width_p,
|
|
|
|
gfloat *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
|
|
|
|
Remove Units from the public API
With the recent change to internal floating point values, ClutterUnit
has become a redundant type, defined to be a float. All integer entry
points are being internally converted to floating point values to be
passed to the GL pipeline with the least amount of conversion.
ClutterUnit is thus exposed as just a "pixel with fractionary bits",
and not -- as users might think -- as generic, resolution and device
independent units. not that it was the case, but a definitive amount
of people was convinced it did provide this "feature", and was flummoxed
about the mere existence of this type.
So, having ClutterUnit exposed in the public API doubles the entry
points and has the following disadvantages:
- we have to maintain twice the amount of entry points in ClutterActor
- we still do an integer-to-float implicit conversion
- we introduce a weird impedance between pixels and "pixels with
fractionary bits"
- language bindings will have to choose what to bind, and resort
to manually overriding the API
+ *except* for language bindings based on GObject-Introspection, as
they cannot do manual overrides, thus will replicate the entire
set of entry points
For these reason, we should coalesces every Actor entry point for
pixels and for ClutterUnit into a single entry point taking a float,
like:
void clutter_actor_set_x (ClutterActor *self,
gfloat x);
void clutter_actor_get_size (ClutterActor *self,
gfloat *width,
gfloat *height);
gfloat clutter_actor_get_height (ClutterActor *self);
etc.
The issues I have identified are:
- we'll have a two cases of compiler warnings:
- printf() format of the return values from %d to %f
- clutter_actor_get_size() taking floats instead of unsigned ints
- we'll have a problem with varargs when passing an integer instead
of a floating point value, except on 64bit platforms where the
size of a float is the same as the size of an int
To be clear: the *intent* of the API should not change -- we still use
pixels everywhere -- but:
- we remove ambiguity in the API with regard to pixels and units
- we remove entry points we get to maintain for the whole 1.0
version of the API
- we make things simpler to bind for both manual language bindings
and automatic (gobject-introspection based) ones
- we have the simplest API possible while still exposing the
capabilities of the underlying GL implementation
2009-05-06 15:44:47 +00:00
|
|
|
if (clone_source == NULL)
|
2009-01-26 11:03:12 +00:00
|
|
|
{
|
|
|
|
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,
|
Remove Units from the public API
With the recent change to internal floating point values, ClutterUnit
has become a redundant type, defined to be a float. All integer entry
points are being internally converted to floating point values to be
passed to the GL pipeline with the least amount of conversion.
ClutterUnit is thus exposed as just a "pixel with fractionary bits",
and not -- as users might think -- as generic, resolution and device
independent units. not that it was the case, but a definitive amount
of people was convinced it did provide this "feature", and was flummoxed
about the mere existence of this type.
So, having ClutterUnit exposed in the public API doubles the entry
points and has the following disadvantages:
- we have to maintain twice the amount of entry points in ClutterActor
- we still do an integer-to-float implicit conversion
- we introduce a weird impedance between pixels and "pixels with
fractionary bits"
- language bindings will have to choose what to bind, and resort
to manually overriding the API
+ *except* for language bindings based on GObject-Introspection, as
they cannot do manual overrides, thus will replicate the entire
set of entry points
For these reason, we should coalesces every Actor entry point for
pixels and for ClutterUnit into a single entry point taking a float,
like:
void clutter_actor_set_x (ClutterActor *self,
gfloat x);
void clutter_actor_get_size (ClutterActor *self,
gfloat *width,
gfloat *height);
gfloat clutter_actor_get_height (ClutterActor *self);
etc.
The issues I have identified are:
- we'll have a two cases of compiler warnings:
- printf() format of the return values from %d to %f
- clutter_actor_get_size() taking floats instead of unsigned ints
- we'll have a problem with varargs when passing an integer instead
of a floating point value, except on 64bit platforms where the
size of a float is the same as the size of an int
To be clear: the *intent* of the API should not change -- we still use
pixels everywhere -- but:
- we remove ambiguity in the API with regard to pixels and units
- we remove entry points we get to maintain for the whole 1.0
version of the API
- we make things simpler to bind for both manual language bindings
and automatic (gobject-introspection based) ones
- we have the simplest API possible while still exposing the
capabilities of the underlying GL implementation
2009-05-06 15:44:47 +00:00
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *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;
|
|
|
|
|
Remove Units from the public API
With the recent change to internal floating point values, ClutterUnit
has become a redundant type, defined to be a float. All integer entry
points are being internally converted to floating point values to be
passed to the GL pipeline with the least amount of conversion.
ClutterUnit is thus exposed as just a "pixel with fractionary bits",
and not -- as users might think -- as generic, resolution and device
independent units. not that it was the case, but a definitive amount
of people was convinced it did provide this "feature", and was flummoxed
about the mere existence of this type.
So, having ClutterUnit exposed in the public API doubles the entry
points and has the following disadvantages:
- we have to maintain twice the amount of entry points in ClutterActor
- we still do an integer-to-float implicit conversion
- we introduce a weird impedance between pixels and "pixels with
fractionary bits"
- language bindings will have to choose what to bind, and resort
to manually overriding the API
+ *except* for language bindings based on GObject-Introspection, as
they cannot do manual overrides, thus will replicate the entire
set of entry points
For these reason, we should coalesces every Actor entry point for
pixels and for ClutterUnit into a single entry point taking a float,
like:
void clutter_actor_set_x (ClutterActor *self,
gfloat x);
void clutter_actor_get_size (ClutterActor *self,
gfloat *width,
gfloat *height);
gfloat clutter_actor_get_height (ClutterActor *self);
etc.
The issues I have identified are:
- we'll have a two cases of compiler warnings:
- printf() format of the return values from %d to %f
- clutter_actor_get_size() taking floats instead of unsigned ints
- we'll have a problem with varargs when passing an integer instead
of a floating point value, except on 64bit platforms where the
size of a float is the same as the size of an int
To be clear: the *intent* of the API should not change -- we still use
pixels everywhere -- but:
- we remove ambiguity in the API with regard to pixels and units
- we remove entry points we get to maintain for the whole 1.0
version of the API
- we make things simpler to bind for both manual language bindings
and automatic (gobject-introspection based) ones
- we have the simplest API possible while still exposing the
capabilities of the underlying GL implementation
2009-05-06 15:44:47 +00:00
|
|
|
if (clone_source == NULL)
|
2009-01-26 11:03:12 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-09-11 01:31:03 +00:00
|
|
|
static void
|
|
|
|
clutter_clone_apply_transform (ClutterActor *self, CoglMatrix *matrix)
|
|
|
|
{
|
|
|
|
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv;
|
2012-08-10 13:06:14 +00:00
|
|
|
ClutterActorBox box, source_box;
|
|
|
|
gfloat x_scale, y_scale;
|
2010-09-11 01:31:03 +00:00
|
|
|
|
|
|
|
/* First chain up and apply all the standard ClutterActor
|
|
|
|
* transformations... */
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_clone_parent_class)->apply_transform (self,
|
|
|
|
matrix);
|
|
|
|
|
2010-10-24 12:45:16 +00:00
|
|
|
/* if we don't have a source, nothing else to do */
|
|
|
|
if (priv->clone_source == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-09-11 01:31:03 +00:00
|
|
|
/* get our allocated size */
|
2012-08-10 13:06:14 +00:00
|
|
|
clutter_actor_get_allocation_box (self, &box);
|
2010-09-11 01:31:03 +00:00
|
|
|
|
|
|
|
/* and get the allocated size of the source */
|
2012-08-10 13:06:14 +00:00
|
|
|
clutter_actor_get_allocation_box (priv->clone_source, &source_box);
|
2010-09-11 01:31:03 +00:00
|
|
|
|
|
|
|
/* We need to scale what the clone-source actor paints to fill our own
|
|
|
|
* allocation...
|
|
|
|
*/
|
2012-08-10 13:06:14 +00:00
|
|
|
x_scale = clutter_actor_box_get_width (&box)
|
|
|
|
/ clutter_actor_box_get_width (&source_box);
|
|
|
|
y_scale = clutter_actor_box_get_height (&box)
|
|
|
|
/ clutter_actor_box_get_height (&source_box);
|
2010-09-11 01:31:03 +00:00
|
|
|
|
|
|
|
cogl_matrix_scale (matrix, x_scale, y_scale, x_scale);
|
|
|
|
}
|
|
|
|
|
2009-01-17 16:51:03 +00:00
|
|
|
static void
|
2019-11-13 21:21:58 +00:00
|
|
|
clutter_clone_paint (ClutterActor *actor,
|
|
|
|
ClutterPaintContext *paint_context)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2011-10-19 14:23:55 +00:00
|
|
|
ClutterClone *self = CLUTTER_CLONE (actor);
|
|
|
|
ClutterClonePrivate *priv = self->priv;
|
2009-05-01 11:33:42 +00:00
|
|
|
gboolean was_unmapped = FALSE;
|
2009-01-26 11:03:12 +00:00
|
|
|
|
2010-10-11 12:32:26 +00:00
|
|
|
if (priv->clone_source == NULL)
|
2009-01-26 11:03:12 +00:00
|
|
|
return;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2011-10-19 14:23:55 +00:00
|
|
|
CLUTTER_NOTE (PAINT, "painting clone actor '%s'",
|
|
|
|
_clutter_actor_get_debug_name (actor));
|
2009-01-17 16:51:03 +00:00
|
|
|
|
|
|
|
/* The final bits of magic:
|
2011-02-03 13:58:20 +00:00
|
|
|
* - We need to override the paint opacity of the actor with our own
|
|
|
|
* opacity.
|
|
|
|
* - We need to inform the actor that it's in a clone paint (for the function
|
|
|
|
* clutter_actor_is_in_clone_paint())
|
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.
|
|
|
|
*/
|
2011-02-03 13:58:20 +00:00
|
|
|
_clutter_actor_set_in_clone_paint (priv->clone_source, TRUE);
|
2012-06-04 21:42:04 +00:00
|
|
|
clutter_actor_set_opacity_override (priv->clone_source,
|
2011-10-19 14:23:55 +00:00
|
|
|
clutter_actor_get_paint_opacity (actor));
|
2009-01-17 16:51:03 +00:00
|
|
|
_clutter_actor_set_enable_model_view_transform (priv->clone_source, FALSE);
|
|
|
|
|
2015-04-23 16:39:30 +00:00
|
|
|
if (!clutter_actor_is_mapped (priv->clone_source))
|
2009-05-01 11:33:42 +00:00
|
|
|
{
|
|
|
|
_clutter_actor_set_enable_paint_unmapped (priv->clone_source, TRUE);
|
|
|
|
was_unmapped = TRUE;
|
|
|
|
}
|
|
|
|
|
2015-09-29 18:15:16 +00:00
|
|
|
/* If the source isn't ultimately parented to a toplevel, it can't be
|
|
|
|
* realized or painted.
|
|
|
|
*/
|
|
|
|
if (clutter_actor_is_realized (priv->clone_source))
|
|
|
|
{
|
|
|
|
_clutter_actor_push_clone_paint ();
|
2019-11-13 21:21:58 +00:00
|
|
|
clutter_actor_paint (priv->clone_source, paint_context);
|
2015-09-29 18:15:16 +00:00
|
|
|
_clutter_actor_pop_clone_paint ();
|
|
|
|
}
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2009-05-01 11:33:42 +00:00
|
|
|
if (was_unmapped)
|
|
|
|
_clutter_actor_set_enable_paint_unmapped (priv->clone_source, FALSE);
|
|
|
|
|
2009-01-17 16:51:03 +00:00
|
|
|
_clutter_actor_set_enable_model_view_transform (priv->clone_source, TRUE);
|
2012-06-04 21:42:04 +00:00
|
|
|
clutter_actor_set_opacity_override (priv->clone_source, -1);
|
2011-02-03 13:58:20 +00:00
|
|
|
_clutter_actor_set_in_clone_paint (priv->clone_source, FALSE);
|
2009-01-17 16:51:03 +00:00
|
|
|
}
|
|
|
|
|
2011-03-18 14:09:57 +00:00
|
|
|
static gboolean
|
2011-10-19 14:23:55 +00:00
|
|
|
clutter_clone_get_paint_volume (ClutterActor *actor,
|
2010-09-11 01:39:23 +00:00
|
|
|
ClutterPaintVolume *volume)
|
|
|
|
{
|
2011-10-19 14:23:55 +00:00
|
|
|
ClutterClonePrivate *priv = CLUTTER_CLONE (actor)->priv;
|
2010-09-11 01:39:23 +00:00
|
|
|
const ClutterPaintVolume *source_volume;
|
|
|
|
|
2010-10-07 20:00:47 +00:00
|
|
|
/* if the source is not set the paint volume is defined to be empty */
|
|
|
|
if (priv->clone_source == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
2010-09-11 01:39:23 +00:00
|
|
|
/* query the volume of the source actor and simply masquarade it as
|
|
|
|
* the clones volume... */
|
|
|
|
source_volume = clutter_actor_get_paint_volume (priv->clone_source);
|
2011-10-19 14:23:55 +00:00
|
|
|
if (source_volume == NULL)
|
2010-09-11 01:39:23 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
_clutter_paint_volume_set_from_volume (volume, source_volume);
|
2011-10-19 14:23:55 +00:00
|
|
|
_clutter_paint_volume_set_reference_actor (volume, actor);
|
|
|
|
|
2010-09-11 01:39:23 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-03-14 16:30:53 +00:00
|
|
|
static gboolean
|
2011-10-19 14:23:55 +00:00
|
|
|
clutter_clone_has_overlaps (ClutterActor *actor)
|
2011-03-14 16:30:53 +00:00
|
|
|
{
|
2011-10-19 14:23:55 +00:00
|
|
|
ClutterClonePrivate *priv = CLUTTER_CLONE (actor)->priv;
|
2011-03-14 16:30:53 +00:00
|
|
|
|
|
|
|
/* The clone has overlaps iff the source has overlaps */
|
|
|
|
|
|
|
|
if (priv->clone_source == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return clutter_actor_has_overlaps (priv->clone_source);
|
|
|
|
}
|
|
|
|
|
2009-02-02 11:59:39 +00:00
|
|
|
static void
|
2009-06-03 13:02:06 +00:00
|
|
|
clutter_clone_allocate (ClutterActor *self,
|
|
|
|
const ClutterActorBox *box,
|
|
|
|
ClutterAllocationFlags flags)
|
2009-02-02 11:59:39 +00:00
|
|
|
{
|
|
|
|
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv;
|
|
|
|
ClutterActorClass *parent_class;
|
|
|
|
|
|
|
|
/* chain up */
|
|
|
|
parent_class = CLUTTER_ACTOR_CLASS (clutter_clone_parent_class);
|
2009-06-03 13:02:06 +00:00
|
|
|
parent_class->allocate (self, box, flags);
|
2009-02-02 11:59:39 +00:00
|
|
|
|
2010-10-11 12:32:26 +00:00
|
|
|
if (priv->clone_source == NULL)
|
2009-02-02 11:59:39 +00:00
|
|
|
return;
|
|
|
|
|
2019-07-22 19:38:33 +00:00
|
|
|
/* ClutterActor delays allocating until the actor is shown; however
|
|
|
|
* we cannot paint it correctly in that case, so force an allocation.
|
|
|
|
*/
|
|
|
|
if (clutter_actor_get_parent (priv->clone_source) != NULL &&
|
|
|
|
!clutter_actor_has_allocation (priv->clone_source))
|
|
|
|
clutter_actor_allocate_preferred_size (priv->clone_source, flags);
|
|
|
|
|
2011-10-19 14:23:55 +00:00
|
|
|
#if 0
|
|
|
|
/* XXX - this is wrong: ClutterClone cannot clone unparented
|
|
|
|
* actors, as it will break all invariants
|
|
|
|
*/
|
|
|
|
|
2009-02-02 11:59:39 +00:00
|
|
|
/* 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
|
2011-10-19 14:23:55 +00:00
|
|
|
* within our paint() implementation. since the actor does not
|
2009-02-02 11:59:39 +00:00
|
|
|
* 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)
|
2009-06-03 13:02:06 +00:00
|
|
|
clutter_actor_allocate_preferred_size (priv->clone_source, flags);
|
2011-10-19 14:23:55 +00:00
|
|
|
#endif
|
2009-02-02 11:59:39 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2011-10-19 14:23:55 +00:00
|
|
|
ClutterClone *self = 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:
|
2011-10-19 14:23:55 +00:00
|
|
|
clutter_clone_set_source (self, 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-02-27 19:43:47 +00:00
|
|
|
clutter_clone_set_source_internal (CLUTTER_CLONE (gobject), NULL);
|
2009-01-26 11:03:12 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2011-10-19 14:23:55 +00:00
|
|
|
actor_class->apply_transform = clutter_clone_apply_transform;
|
|
|
|
actor_class->paint = clutter_clone_paint;
|
|
|
|
actor_class->get_paint_volume = clutter_clone_get_paint_volume;
|
|
|
|
actor_class->get_preferred_width = clutter_clone_get_preferred_width;
|
2009-01-26 11:03:12 +00:00
|
|
|
actor_class->get_preferred_height = clutter_clone_get_preferred_height;
|
2011-10-19 14:23:55 +00:00
|
|
|
actor_class->allocate = clutter_clone_allocate;
|
|
|
|
actor_class->has_overlaps = clutter_clone_has_overlaps;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2011-10-19 14:23:55 +00:00
|
|
|
gobject_class->dispose = clutter_clone_dispose;
|
2009-01-26 11:03:12 +00:00
|
|
|
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
|
|
|
|
*/
|
2010-10-15 14:24:27 +00:00
|
|
|
obj_props[PROP_SOURCE] =
|
|
|
|
g_param_spec_object ("source",
|
|
|
|
P_("Source"),
|
|
|
|
P_("Specifies the actor to be cloned"),
|
|
|
|
CLUTTER_TYPE_ACTOR,
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
CLUTTER_PARAM_READWRITE);
|
|
|
|
|
2011-10-19 14:23:55 +00:00
|
|
|
g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
|
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
|
|
|
{
|
2013-07-03 13:14:01 +00:00
|
|
|
self->priv = clutter_clone_get_instance_private (self);
|
2009-01-17 16:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
}
|
|
|
|
|
2017-03-02 18:18:43 +00:00
|
|
|
static void
|
|
|
|
on_source_destroyed (ClutterActor *source,
|
|
|
|
ClutterClone *self)
|
|
|
|
{
|
|
|
|
clutter_clone_set_source_internal (self, NULL);
|
|
|
|
}
|
|
|
|
|
2009-02-27 19:43:47 +00:00
|
|
|
static void
|
2011-10-19 14:23:55 +00:00
|
|
|
clutter_clone_set_source_internal (ClutterClone *self,
|
2009-02-27 19:43:47 +00:00
|
|
|
ClutterActor *source)
|
2009-01-17 16:51:03 +00:00
|
|
|
{
|
2011-10-19 14:23:55 +00:00
|
|
|
ClutterClonePrivate *priv = self->priv;
|
2009-01-17 16:51:03 +00:00
|
|
|
|
2013-03-07 18:09:33 +00:00
|
|
|
if (priv->clone_source == source)
|
|
|
|
return;
|
|
|
|
|
2011-10-19 14:23:55 +00:00
|
|
|
if (priv->clone_source != NULL)
|
2009-01-26 11:03:12 +00:00
|
|
|
{
|
2019-11-16 00:25:52 +00:00
|
|
|
g_clear_signal_handler (&priv->source_destroy_id, priv->clone_source);
|
2013-03-07 18:09:33 +00:00
|
|
|
_clutter_actor_detach_clone (priv->clone_source, CLUTTER_ACTOR (self));
|
2009-01-26 11:03:12 +00:00
|
|
|
g_object_unref (priv->clone_source);
|
|
|
|
priv->clone_source = NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-19 14:23:55 +00:00
|
|
|
if (source != NULL)
|
2009-02-27 19:43:47 +00:00
|
|
|
{
|
|
|
|
priv->clone_source = g_object_ref (source);
|
2013-03-07 18:09:33 +00:00
|
|
|
_clutter_actor_attach_clone (priv->clone_source, CLUTTER_ACTOR (self));
|
2017-03-02 18:18:43 +00:00
|
|
|
priv->source_destroy_id = g_signal_connect (priv->clone_source, "destroy",
|
|
|
|
G_CALLBACK (on_source_destroyed), self);
|
2009-02-27 19:43:47 +00:00
|
|
|
}
|
2009-01-26 11:03:12 +00:00
|
|
|
|
2011-10-19 14:23:55 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_SOURCE]);
|
2009-01-26 11:03:12 +00:00
|
|
|
|
2011-10-19 14:23:55 +00:00
|
|
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (self));
|
2009-01-17 16:51:03 +00:00
|
|
|
}
|
|
|
|
|
2009-02-27 19:43:47 +00:00
|
|
|
/**
|
|
|
|
* clutter_clone_set_source:
|
2011-10-19 14:23:55 +00:00
|
|
|
* @self: a #ClutterClone
|
|
|
|
* @source: (allow-none): a #ClutterActor, or %NULL
|
2009-02-27 19:43:47 +00:00
|
|
|
*
|
2011-10-19 14:23:55 +00:00
|
|
|
* Sets @source as the source actor to be cloned by @self.
|
2009-02-27 19:43:47 +00:00
|
|
|
*
|
|
|
|
* Since: 1.0
|
|
|
|
*/
|
|
|
|
void
|
2011-10-19 14:23:55 +00:00
|
|
|
clutter_clone_set_source (ClutterClone *self,
|
2009-02-27 19:43:47 +00:00
|
|
|
ClutterActor *source)
|
|
|
|
{
|
2011-10-19 14:23:55 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_CLONE (self));
|
2009-02-27 19:43:47 +00:00
|
|
|
g_return_if_fail (source == NULL || CLUTTER_IS_ACTOR (source));
|
|
|
|
|
2011-10-19 14:23:55 +00:00
|
|
|
clutter_clone_set_source_internal (self, source);
|
|
|
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (self));
|
2009-02-27 19:43:47 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 11:03:12 +00:00
|
|
|
/**
|
|
|
|
* clutter_clone_get_source:
|
2011-10-19 14:23:55 +00:00
|
|
|
* @self: a #ClutterClone
|
2009-01-26 11:03:12 +00:00
|
|
|
*
|
2011-10-19 14:23:55 +00:00
|
|
|
* Retrieves the source #ClutterActor being cloned by @self.
|
2009-01-26 11:03:12 +00:00
|
|
|
*
|
2009-02-17 00:25:20 +00:00
|
|
|
* Return value: (transfer none): the actor source for the clone
|
2009-01-26 11:03:12 +00:00
|
|
|
*
|
|
|
|
* Since: 1.0
|
|
|
|
*/
|
|
|
|
ClutterActor *
|
2011-10-19 14:23:55 +00:00
|
|
|
clutter_clone_get_source (ClutterClone *self)
|
2009-01-26 11:03:12 +00:00
|
|
|
{
|
2011-10-19 14:23:55 +00:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_CLONE (self), NULL);
|
2009-01-26 11:03:12 +00:00
|
|
|
|
2011-10-19 14:23:55 +00:00
|
|
|
return self->priv->clone_source;
|
2009-01-26 11:03:12 +00:00
|
|
|
}
|