Aarto Matti <[email protected]> writes:

> It it possible to get a CoglHandle of cloned group? I found two ways
> how to create a 'live' clone, with either clutter_clone_new() or
> clutter_texture_new_from_actor(). But clutter_texture_new_from_actor()
> seems not to work with ClutterGroup and clutter_clone_new() returns
> not a ClutterTexture object. In both I can't get a proper CoglHandle.

clutter_texture_new_from_actor should work for a group and let you get a
CoglHandle for the texture and it at least works for me. Please see the
attached example adaptation of your code showing a reflection.

Note however there's currently a bug with clutter_texture_new_from_actor
which means the clone in your example will be slightly too small to
contain the label. You could workaround this by putting your rectangle
at the origin rather than at 20,20. See this for more details:
http://bugzilla.openedhand.com/show_bug.cgi?id=1825

- Neil

#include <clutter/clutter.h>

static void
paint_reflection (ClutterActor *actor)
{
  ClutterGeometry geom;

  clutter_actor_get_allocation_geometry (actor, &geom);

  guint8 opacity = clutter_actor_get_paint_opacity (actor);

  CoglTextureVertex vertices[] =
    { { geom.width, geom.height, 0,
        1, 1.0 },
      { 0, geom.height, 0,
        0, 1.0 },
      { 0, geom.height * 1.8, 0,
        0, 0.2 },
      { geom.width, geom.height * 1.8, 0,
        1, 0.2 } };
  cogl_color_set_from_4ub (&vertices[0].color,
                           opacity, opacity, opacity, opacity);
  cogl_color_set_from_4ub (&vertices[1].color,
                           opacity, opacity, opacity, opacity);
  cogl_color_set_from_4ub (&vertices[2].color, 0, 0, 0, 0);
  cogl_color_set_from_4ub (&vertices[3].color, 0, 0, 0, 0);

  cogl_set_source (clutter_texture_get_cogl_material (CLUTTER_TEXTURE (actor)));
  cogl_polygon (vertices, G_N_ELEMENTS (vertices), TRUE);
}

int
main (int argc, char **argv)
{
  clutter_init (&argc, &argv);

  clutter_stage_set_color (CLUTTER_STAGE (clutter_stage_get_default ()),
                           &(ClutterColor) { 0x00, 0x00, 0x00, 0xff });

  ClutterColor actor_color = { 0xff, 0xff, 0xff, 0xff };
  ClutterActor *rect = clutter_rectangle_new_with_color (&actor_color);
  clutter_actor_set_size (rect, 120, 100);
  clutter_actor_set_position (rect, 20, 20);

  ClutterActor *text = clutter_text_new_with_text("Courier 20", "Hello!");
  clutter_actor_set_position (text, 20, 50);

  ClutterActor *group = clutter_group_new();
  clutter_group_add(group, rect);
  clutter_group_add(group, text);
  clutter_stage_add(CLUTTER_GROUP(clutter_stage_get_default()), group);

  ClutterActor* clone = clutter_texture_new_from_actor(group);

  clutter_stage_add(CLUTTER_GROUP(clutter_stage_get_default()), clone);
  clutter_actor_set_x(clone, 300);

  g_signal_connect (clone, "paint", G_CALLBACK (paint_reflection), NULL);

  clutter_actor_show (clutter_stage_get_default ());

  clutter_main ();

  return 0;
}

Reply via email to