#include <clutter/clutter.h>

static gboolean
draw_green_square (ClutterCanvas *canvas,
            cairo_t       *cr,
            int            width,
            int            height)
{
  cairo_set_source_rgba (cr, 0, 1, 0, 1);
  cairo_rectangle (cr, 0, 0, width, height);
  cairo_fill (cr);
  return TRUE;
}

#define ANCHOR 400 // try 399
#define TILE_SIZE 400
int
main (int argc,
    char *argv[])
{
  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return -1;

  // Actor tree just like in champlain_view
  ClutterActor *stage = clutter_stage_new ();
  ClutterActor *viewport_container = clutter_actor_new ();
  ClutterActor *map_layer = clutter_actor_new ();
  ClutterActor *tile = clutter_actor_new ();

  clutter_actor_add_child (stage, viewport_container);
  clutter_actor_add_child (viewport_container, map_layer);
  clutter_actor_add_child (map_layer, tile);
  clutter_actor_set_size (stage, 1960, 1080);

  //A green square tile
  clutter_actor_set_size (tile, TILE_SIZE, TILE_SIZE);
  ClutterContent *canvas = clutter_canvas_new ();
  clutter_canvas_set_size (CLUTTER_CANVAS(canvas), TILE_SIZE, TILE_SIZE);
  clutter_actor_set_content (tile, canvas);
  g_signal_connect (canvas, "draw", G_CALLBACK (draw_green_square), NULL);
  clutter_content_invalidate (canvas);
  
  // This simulates relocation
  clutter_actor_set_position (tile, -ANCHOR, -ANCHOR);
  clutter_actor_set_position (viewport_container, ANCHOR, ANCHOR);

  // Map layer clone
  ClutterActor *clone = clutter_clone_new (map_layer);
  clutter_actor_add_child (viewport_container, clone);
  clutter_actor_set_x (clone, 400);

  clutter_actor_show (stage);
  clutter_main ();

  return 0;
}
