Table of Contents
If the standard Clutter 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 Glib::Object subclass.
class Triangle : public Clutter::Actor { // ... };
You should then override the Clutter::Actor::on_paint()
virtual method
in your class:
class Triangle : public Clutter::Actor { // ... protected: virtual void on_paint(); }; void Triangle::on_paint() { // ... }
Your Clutter::Actor::on_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
Clutter::Actor::get_geometry()
and
Clutter::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 Clutter
backends), you may wish to use Clutter'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
testing for the preprocessor macro CLUTTER_COGL_HAS_GL
or
CLUTTER_COGL_HAS_GLES
.
You should also implement the ClutterActor::pick_vfunc()
virtual
function, painting a silhouette of your actor in the provided color. Clutter 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
on_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, on_show()
,
on_show_all()
, on_hide()
,
on_hide_all()
, allocate_vfunc()
.