Compare commits

...

2 Commits

Author SHA1 Message Date
Emmanuele Bassi 19fa3f0fcb Snapshot/WIP: actor: Use ActorModel 2012-02-06 12:07:31 +00:00
Emmanuele Bassi 6e509fae7a Snapshot/WIP: Add ActorModel 2012-02-06 12:07:31 +00:00
8 changed files with 377 additions and 0 deletions

View File

@ -51,6 +51,7 @@ pc_files =
source_h = \
$(srcdir)/clutter-action.h \
$(srcdir)/clutter-actor-meta.h \
$(srcdir)/clutter-actor-model.h \
$(srcdir)/clutter-actor.h \
$(srcdir)/clutter-align-constraint.h \
$(srcdir)/clutter-alpha.h \
@ -124,6 +125,7 @@ source_c = \
$(srcdir)/clutter-action.c \
$(srcdir)/clutter-actor-box.c \
$(srcdir)/clutter-actor-meta.c \
$(srcdir)/clutter-actor-model.c \
$(srcdir)/clutter-actor.c \
$(srcdir)/clutter-align-constraint.c \
$(srcdir)/clutter-alpha.c \
@ -196,6 +198,7 @@ source_c = \
# private headers; these should not be distributed or introspected
source_h_priv = \
$(srcdir)/clutter-actor-meta-private.h \
$(srcdir)/clutter-actor-model-private.h \
$(srcdir)/clutter-actor-private.h \
$(srcdir)/clutter-backend-private.h \
$(srcdir)/clutter-bezier.h \

View File

@ -0,0 +1,39 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2012 Intel Corporation.
*
* 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/>.
*
* Author:
* Emmanuele Bassi <ebassi@linux.intel.com>
*/
#ifndef __CLUTTER_ACTOR_MODEL_PRIVATE_H__
#define __CLUTTER_ACTOR_MODEL_PRIVATE_H__
#include <clutter/clutter-actor-model.h>
G_BEGIN_DECLS
void _clutter_actor_model_attached (ClutterActorModel *model,
ClutterActor *actor);
void _clutter_actor_model_detached (ClutterActorModel *model,
ClutterActor *actor);
G_END_DECLS
#endif /* __CLUTTER_ACTOR_MODEL_PRIVATE_H__ */

View File

@ -0,0 +1,151 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2012 Intel Corporation.
*
* 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/>.
*
* Author:
* Emmanuele Bassi <ebassi@linux.intel.com>
*/
/**
* SECTION:clutter-actor-model
* @Title: ClutterActorModel
* @Short_Description: A model for actors
*
* FIXME
*
* #ClutterActorModel is available since Clutter 1.10
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "clutter-actor-model.h"
typedef struct _ClutterActorModelIface ClutterActorModelInterface;
G_DEFINE_INTERFACE_TYPE (ClutterActorModel, clutter_actor_model, G_TYPE_OBJECT)
static void
clutter_actor_model_default_init (ClutterActorModelIface *iface)
{
}
void
_clutter_actor_model_attached (ClutterActorModel *model,
ClutterActor *actor)
{
GHashTable *actors;
GObject *obj;
obj = G_OBJECT (model);
actors = g_object_get_data (obj, "-clutter-actor-model-actors");
if (actors == NULL)
{
actors = g_hash_table_new (NULL, NULL);
g_object_set_data_full (obj, "-clutter-actor-model-actors",
actors,
(GDestroyNotify) g_hash_table_unref);
}
g_hash_table_insert (actors, actor, actor);
}
void
_clutter_actor_model_detached (ClutterActorModel *model,
ClutterActor *actor)
{
GHashTable *actors;
GObject *obj;
obj = G_OBJECT (model);
actors = g_object_get_data (obj, "-clutter-actor-model-actors");
g_assert (actors != NULL);
g_hash_table_remove (actors, actor);
if (g_hash_table_size (actors) == 0)
g_object_set_data (obj, "-clutter-actor-model-actors", NULL);
}
static inline void
clutter_actor_model_foreach_actor (ClutterActorModel *model,
ClutterCallback func,
gpointer data)
{
GHashTableIter iter;
GHashTable *actors;
actors = g_object_get_data (G_OBJECT (model), "-clutter-actor-model-actors");
if (actors == NULL)
return;
g_hash_table_iter_init (&iter, actors);
while (g_hash_table_iter_next (&iter, &key, NULL))
{
ClutterActor *actor = key;
callback (actor, data);
}
}
/**
* clutter_actor_model_invalidate_content:
* @model: a #ClutterActorModel
*
* Queues a redraw on every #ClutterActor using @model.
*
* This function should be called by #ClutterActorModel implementations
* whenever the content of the model changes.
*
* Since: 1.10
*/
void
clutter_actor_model_invalidate_content (ClutterActorModel *model)
{
g_return_if_fail (CLUTTER_IS_ACTOR_MODEL (model));
clutter_actor_model_foreach_actor (model,
CLUTTER_CALLBACK (clutter_actor_queue_redraw),
NULL);
}
/**
* clutter_actor_model_invalidate_layout:
* @model: a #ClutterActorModel
*
* Queues a relayout on every #ClutterActor using @model.
*
* This function should be called by #ClutterActorModel implementations
* whenever the size of the model changes.
*
* Since: 1.10
*/
void
clutter_actor_model_invalidate_layout (ClutterActorModel *model)
{
g_return_if_fail (CLUTTER_IS_ACTOR_MODEL (model));
clutter_actor_model_foreach_actor (model,
CLUTTER_CALLBACK (clutter_actor_queue_relayout),
NULL);
}

View File

@ -0,0 +1,80 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2012 Intel Corporation.
*
* 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/>.
*
* Author:
* Emmanuele Bassi <ebassi@linux.intel.com>
*/
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
#error "Only <clutter/clutter.h> can be included directly."
#endif
#ifndef __CLUTTER_ACTOR_MODEL_H__
#define __CLUTTER_ACTOR_MODEL_H__
#include <clutter/clutter-types.h>
G_BEGIN_DECLS
#define CLUTTER_TYPE_ACTOR_MODEL (clutter_actor_model_get_type ())
#define CLUTTER_ACTOR_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_ACTOR_MODEL, ClutterActorModel))
#define CLUTTER_IS_ACTOR_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_ACTOR_MODEL))
#define CLUTTER_ACTOR_MODEL_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), CLUTTER_TYPE_ACTOR_MODEL, ClutterActorModelIface))
typedef struct _ClutterActorModelIface ClutterActorModelIface;
struct _ClutterActorModelIface
{
/*< private >*/
GTypeInterface g_iface;
/*< public >*/
void (* get_preferred_width) (ClutterActorModel *self,
gfloat for_height,
gfloat *minimum_width_p,
gfloat *natural_width_p);
void (* get_preferred_height) (ClutterActorModel *self,
gfloat for_width,
gfloat *minimum_height_p,
gfloat *natural_height_p);
void (* allocate) (ClutterActorModel *model,
const ClutterActorBox *allocation,
ClutterAllocationFlags flags);
void (* paint_node) (ClutterActorModel *model,
ClutterPaintNode *node);
void (* apply_transform) (ClutterActorModel *model,
CoglMatrix *ctm);
void (* attached) (ClutterActorModel *model,
ClutterActor *actor);
void (* detached) (ClutterActorModel *model,
ClutterActor *actor);
};
GType clutter_actor_model_get_type (void) G_GNUC_CONST;
void clutter_actor_model_invalidate_content (ClutterActorModel *model);
void clutter_actor_model_invalidate_layout (ClutterActorModel *model);
G_END_DECLS
#endif /* __CLUTTER_ACTOR_MODEL_H__ */

View File

@ -328,6 +328,7 @@
#include "clutter-action.h"
#include "clutter-actor-meta-private.h"
#include "clutter-actor-model-private.h"
#include "clutter-animatable.h"
#include "clutter-color-static.h"
#include "clutter-color.h"
@ -455,6 +456,9 @@ struct _ClutterActorPrivate
/* delegate object used to allocate the children of this actor */
ClutterLayoutManager *layout_manager;
/* model, used to drive the actor */
ClutterActorModel *model;
/* used when painting, to update the paint volume */
ClutterEffect *current_effect;
@ -617,6 +621,8 @@ enum
PROP_FIRST_CHILD,
PROP_LAST_CHILD,
PROP_MODEL,
PROP_LAST
};
@ -4142,6 +4148,10 @@ clutter_actor_set_property (GObject *object,
clutter_actor_set_background_color (actor, g_value_get_boxed (value));
break;
case PROP_MODEL:
clutter_actor_set_model (actor, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -4540,6 +4550,10 @@ clutter_actor_get_property (GObject *object,
g_value_set_object (value, priv->last_child);
break;
case PROP_MODEL:
g_value_set_object (value, priv->model);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -5775,6 +5789,23 @@ clutter_actor_class_init (ClutterActorClass *klass)
CLUTTER_TYPE_ACTOR,
CLUTTER_PARAM_READABLE);
/**
* ClutterActor:model:
*
* The #ClutterActorModel controlling the actor.
*
* The #ClutterActor will defer its preferred size, allocation, painting,
* and picking to the model's implementation.
*
* Since: 1.10
*/
obj_props[PROP_MODEL] =
g_param_spec_object ("model",
P_("Model"),
P_("The model controlling the actor"),
CLUTTER_TYPE_ACTOR_MODEL,
CLUTTER_PARAM_READWRITE);
g_object_class_install_properties (object_class, PROP_LAST, obj_props);
/**
@ -15723,3 +15754,71 @@ clutter_actor_iter_remove (ClutterActorIter *iter)
ri->age += 1;
}
}
/**
* clutter_actor_set_model:
* @self: a #ClutterActor
* @model: (allow-none): a #ClutterActorModel, or %NULL to unset the
* currently set model
*
* Sets the model that will be used by a #ClutterActor to provide the
* implementation of its preferred size, allocation, painting, and
* picking.
*
* This function will acquire a reference on the @model, which will
* be released when the actor is destroyed or when this function is
* called with a %NULL argument.
*
* Since: 1.10
*/
void
clutter_actor_set_model (ClutterActor *self,
ClutterActorModel *model)
{
ClutterActorPrivate *priv;
g_return_if_fail (CLUTTER_IS_ACTOR (self));
g_return_if_fail (model == NULL || CLUTTER_IS_ACTOR_MODEL (model));
priv = self->priv;
if (priv->model == model)
return;
if (priv->model != NULL)
{
_clutter_actor_model_detached (priv->model, self);
g_clear_object (&priv->model);
}
if (model != NULL)
{
if (g_object_is_floating (G_OBJECT (model)))
priv->model = g_object_ref_sink (model);
else
priv->model = g_object_ref (model);
_clutter_actor_model_attached (priv->model, self);
}
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MODEL]);
}
/**
* clutter_actor_get_model:
* @self: a #ClutterActor
*
* Retrieves the #ClutterActorModel set for @self.
*
* Return value: (transfer none): a #ClutterActorModel, or %NULL if none
* is set
*
* Since: 1.10
*/
ClutterActorModel *
clutter_actor_get_model (ClutterActor *self)
{
g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
return self->priv->model;
}

View File

@ -521,6 +521,9 @@ gboolean clutter_actor_iter_next
gboolean clutter_actor_iter_prev (ClutterActorIter *iter,
ClutterActor **child);
void clutter_actor_iter_remove (ClutterActorIter *iter);
void clutter_actor_set_model (ClutterActor *self,
ClutterActorModel *model);
ClutterActorModel * clutter_actor_get_model (ClutterActor *self);
/* Transformations */
gboolean clutter_actor_is_rotated (ClutterActor *self);

View File

@ -78,6 +78,7 @@ typedef struct _ClutterLayoutMeta ClutterLayoutMeta;
typedef struct _ClutterActorMeta ClutterActorMeta;
typedef struct _ClutterLayoutManager ClutterLayoutManager;
typedef struct _ClutterActorIter ClutterActorIter;
typedef struct _ClutterActorModel ClutterActorModel; /* dummy */
typedef struct _ClutterAlpha ClutterAlpha;
typedef struct _ClutterAnimatable ClutterAnimatable; /* dummy */

View File

@ -34,6 +34,7 @@
#include "clutter-action.h"
#include "clutter-actor.h"
#include "clutter-actor-meta.h"
#include "clutter-actor-model.h"
#include "clutter-align-constraint.h"
#include "clutter-alpha.h"
#include "clutter-animatable.h"