On Thu, 2008-11-13 at 20:46 +1000, Saul Lethbridge wrote:
> Doesn't appear to work!

you code, no. once I fixed it, it does.

compile with:

  gcc -Wall \
        `pkg-config --cflags clutter-0.9 clutter-gtk-0.9` \
        -o test-viewport \
        `pkg-config --libs clutter-0.9 clutter-gtk-0.9` \
        test-viewport.c

and run with:

  test-viewport /path/to/image1 /path/to/image2

you have to set the size of the stage and the viewport, as they are (as
I already told you) limitless containers.

as a side note: GtkClutterViewport is not the end-all, be-all of Clutter
containers. it's a "proof-of-concept turned useful" kind of actor. the
logic it provides is easily re-implementable into your own containers.

ciao,
 Emmanuele.

-- 
Emmanuele Bassi, Intel Open Source Technology Center
#include <gtk/gtk.h>
#include <clutter/clutter.h>
#include <clutter-gtk/clutter-gtk.h>

int
main (int argc, char *argv[])
{
  ClutterActor    *stage, *viewport, *tex, *group;
  ClutterColor     stage_color = { 0x61, 0x64, 0x8c, 0xff };
  GtkWidget       *window, *embed; 
  GtkWidget       *table, *scrollbar;
  GtkAdjustment   *h_adjustment, *v_adjustment;
  guint            tex_width;

  if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    g_error ("Unable to initialize GtkClutter");

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  table = gtk_table_new (2, 2, FALSE);
  gtk_container_add (GTK_CONTAINER (window), table);
  gtk_widget_show (table);

  embed = gtk_clutter_embed_new ();
  gtk_table_attach (GTK_TABLE (table), embed,
                    0, 1,
                    0, 1,
                    GTK_EXPAND | GTK_FILL,
                    GTK_EXPAND | GTK_FILL,
                    0, 0);
  gtk_widget_show (embed);

  stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (embed));
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
  clutter_actor_set_size (stage, 640, 480);

  viewport = gtk_clutter_viewport_new (NULL, NULL);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), viewport);

  group = clutter_group_new ();
  clutter_container_add_actor (CLUTTER_CONTAINER (viewport), group);

  tex = clutter_texture_new_from_file (argv[1], NULL);
  clutter_container_add_actor (CLUTTER_CONTAINER (group), tex);
  clutter_actor_set_position (tex, 0, 0);
  tex_width = clutter_actor_get_width (tex);

  tex = clutter_texture_new_from_file (argv[2], NULL);
  clutter_container_add_actor (CLUTTER_CONTAINER (group), tex);
  clutter_actor_set_position (tex, tex_width + 6, 0);

  g_print ("group size: %d x %d\n",
           clutter_actor_get_width (group),
           clutter_actor_get_height (group));

  clutter_actor_set_position (viewport, 0, 0);
  clutter_actor_set_size (viewport, 640, 480);

  gtk_clutter_scrollable_get_adjustments (GTK_CLUTTER_SCROLLABLE (viewport),
                                          &h_adjustment,
                                          &v_adjustment);

  scrollbar = gtk_vscrollbar_new (v_adjustment);
  gtk_table_attach (GTK_TABLE (table), scrollbar,
                    1, 2,
                    0, 1,
                    0, GTK_EXPAND | GTK_FILL,
                    0, 0);
  gtk_widget_show (scrollbar);

  scrollbar = gtk_hscrollbar_new (h_adjustment);
  gtk_table_attach (GTK_TABLE (table), scrollbar,
                    0, 1,
                    1, 2,
                    GTK_EXPAND | GTK_FILL, 0,
                    0, 0);
  gtk_widget_show (scrollbar);

  gtk_widget_show (window);

  gtk_main();

  return 0;
}

Reply via email to