Table of Contents
If the standard PyClutter actors don't meet all your needs then you may create your own custom actor objects.
Implementing a custom actor is much like implementing any new GObject type. You may use the G_DEFINE_TYPE
macro to specify that the type is derived from clutter.Actor
. For instance:
G_DEFINE_TYPE (ClutterTriangle, clutter_triangle, CLUTTER_TYPE_ACTOR);
You should then specify your object's implementation of the clutter.Actor::paint()
virtual function in your __init__
function:
static void clutter_triangle_class_init (ClutterTriangleClass *klass) { ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); actor_class->paint = clutter_triangle_paint; ... }
Your clutter.Actor::paint()
implementation should use the OpenGL API to actually paint something.
You will probably need some information from your object's generic clutter.Actor
base class, for instance
by calling actor.get_geometry()
and actor.get_opacity()
, and by using your object's specific property values.
To make your code work with both OpenGL ES and regular OpenGL (and maybe even future PyClutter backends), you may wish
to use PyClutter's cogl
abstraction API which provides functions such as cogl_rectangle()
and cogl_push_matrix()
. You can also detect whether the platform has support for either the OpenGL or OpenGL ES API by ifdefing for
CLUTTER_COGL_HAS_GL
or CLUTTER_COGL_HAS_GLES
.
You should also implement the clutter.Actor::pick()
virtual function, painting a silhouette of your actor
in the provided color. PyClutter uses this to draw each actor's silhouette offscreen in a unique color, using the color to quickly
identify the actor under the cursor. If your actor is simple then you can probably reuse the code from your paint() implementation.
Most of the rest of clutter.Actor
's virtual functions don't need to be reimplemented, because a suitable default implemention exists in
clutter.Actor
. For instance,
show()
, show_all()
, hide()
, hide_all()
,
request_coord()
.