Blame examples/gtk-clutter-window-test.c

Packit Service 6a0f92
/* Clutter-Gtk Window Test
Packit Service 6a0f92
 *
Packit Service 6a0f92
 * (c) 2009, Collabora Ltd.
Packit Service 6a0f92
 *
Packit Service 6a0f92
 * Written by Davyd Madeley <davyd.madeley@collabora.co.uk>
Packit Service 6a0f92
 */
Packit Service 6a0f92
Packit Service 6a0f92
#include <stdlib.h>
Packit Service 6a0f92
#include <gtk/gtk.h>
Packit Service 6a0f92
#include <clutter/clutter.h>
Packit Service 6a0f92
#include <clutter-gtk/clutter-gtk.h>
Packit Service 6a0f92
Packit Service 6a0f92
enum
Packit Service 6a0f92
{
Packit Service 6a0f92
    NAME_COLUMN,
Packit Service 6a0f92
    PIXBUF_COLUMN,
Packit Service 6a0f92
    N_COLUMNS
Packit Service 6a0f92
};
Packit Service 6a0f92
Packit Service 6a0f92
static void
Packit Service 6a0f92
add_liststore_rows (GtkListStore *store,
Packit Service 6a0f92
                    const char *first, ...)
Packit Service 6a0f92
{
Packit Service 6a0f92
    GtkIconTheme *theme;
Packit Service 6a0f92
    va_list var_args;
Packit Service 6a0f92
    char *icon;
Packit Service 6a0f92
Packit Service 6a0f92
    theme = gtk_icon_theme_get_default ();
Packit Service 6a0f92
Packit Service 6a0f92
    va_start (var_args, first);
Packit Service 6a0f92
Packit Service 6a0f92
    for (icon = (char *) first; icon != NULL; icon = va_arg (var_args, char *))
Packit Service 6a0f92
    {
Packit Service 6a0f92
        GdkPixbuf *pixbuf = gtk_icon_theme_load_icon (theme, icon, 48,
Packit Service 6a0f92
                                                      0,
Packit Service 6a0f92
                                                      NULL);
Packit Service 6a0f92
Packit Service 6a0f92
        gtk_list_store_insert_with_values (store, NULL, -1,
Packit Service 6a0f92
                                           NAME_COLUMN, icon,
Packit Service 6a0f92
                                           PIXBUF_COLUMN, pixbuf,
Packit Service 6a0f92
                                           -1);
Packit Service 6a0f92
        if (pixbuf != NULL)
Packit Service 6a0f92
          g_object_unref (pixbuf);
Packit Service 6a0f92
    }
Packit Service 6a0f92
Packit Service 6a0f92
    va_end (var_args);
Packit Service 6a0f92
}
Packit Service 6a0f92
Packit Service 6a0f92
static void
Packit Service 6a0f92
add_toolbar_items (GtkToolbar *toolbar,
Packit Service 6a0f92
                   const char *first, ...)
Packit Service 6a0f92
{
Packit Service 6a0f92
    va_list var_args;
Packit Service 6a0f92
    char *stock_id;
Packit Service 6a0f92
Packit Service 6a0f92
    va_start (var_args, first);
Packit Service 6a0f92
Packit Service 6a0f92
    for (stock_id = (char *) first; stock_id != NULL;
Packit Service 6a0f92
         stock_id = va_arg (var_args, char *))
Packit Service 6a0f92
    {
Packit Service 6a0f92
        GtkToolItem *item = g_object_new (GTK_TYPE_TOOL_BUTTON,
Packit Service 6a0f92
                                          "icon-name", stock_id,
Packit Service 6a0f92
                                          "label", NULL,
Packit Service 6a0f92
                                          NULL);
Packit Service 6a0f92
        gtk_toolbar_insert (toolbar, item, -1);
Packit Service 6a0f92
    }
Packit Service 6a0f92
Packit Service 6a0f92
    va_end (var_args);
Packit Service 6a0f92
}
Packit Service 6a0f92
Packit Service 6a0f92
static gboolean
Packit Service 6a0f92
on_toolbar_enter (ClutterActor *actor,
Packit Service 6a0f92
                  ClutterEvent *event,
Packit Service 6a0f92
                  gpointer      dummy G_GNUC_UNUSED)
Packit Service 6a0f92
{
Packit Service 6a0f92
  clutter_actor_save_easing_state (actor);
Packit Service 6a0f92
  clutter_actor_set_easing_mode (actor, CLUTTER_LINEAR);
Packit Service 6a0f92
Packit Service 6a0f92
  clutter_actor_set_opacity (actor, 255);
Packit Service 6a0f92
  clutter_actor_set_y (actor, 0);
Packit Service 6a0f92
Packit Service 6a0f92
  clutter_actor_restore_easing_state (actor);
Packit Service 6a0f92
Packit Service 6a0f92
  return CLUTTER_EVENT_STOP;
Packit Service 6a0f92
}
Packit Service 6a0f92
Packit Service 6a0f92
static gboolean
Packit Service 6a0f92
on_toolbar_leave (ClutterActor *actor,
Packit Service 6a0f92
                  ClutterEvent *event,
Packit Service 6a0f92
                  gpointer      dummy G_GNUC_UNUSED)
Packit Service 6a0f92
{
Packit Service 6a0f92
  clutter_actor_save_easing_state (actor);
Packit Service 6a0f92
  clutter_actor_set_easing_mode (actor, CLUTTER_LINEAR);
Packit Service 6a0f92
Packit Service 6a0f92
  clutter_actor_set_opacity (actor, 128);
Packit Service 6a0f92
  clutter_actor_set_y (actor, clutter_actor_get_height (actor) * -0.5f);
Packit Service 6a0f92
Packit Service 6a0f92
  clutter_actor_restore_easing_state (actor);
Packit Service 6a0f92
Packit Service 6a0f92
  return CLUTTER_EVENT_STOP;
Packit Service 6a0f92
}
Packit Service 6a0f92
Packit Service 6a0f92
int
Packit Service 6a0f92
main (int argc, char **argv)
Packit Service 6a0f92
{
Packit Service 6a0f92
    GtkWidget *window, *iconview, *sw, *toolbar;
Packit Service 6a0f92
    GtkListStore *store;
Packit Service 6a0f92
    ClutterActor *stage, *actor;
Packit Service 6a0f92
Packit Service 6a0f92
    if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
Packit Service 6a0f92
      return EXIT_FAILURE;
Packit Service 6a0f92
Packit Service 6a0f92
    window = gtk_clutter_window_new ();
Packit Service 6a0f92
    g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
Packit Service 6a0f92
    gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
Packit Service 6a0f92
Packit Service 6a0f92
    store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, GDK_TYPE_PIXBUF);
Packit Service 6a0f92
    add_liststore_rows (store,
Packit Service 6a0f92
                        "devhelp",
Packit Service 6a0f92
                        "empathy",
Packit Service 6a0f92
                        "evince",
Packit Service 6a0f92
                        "gnome-panel",
Packit Service 6a0f92
                        "seahorse",
Packit Service 6a0f92
                        "sound-juicer",
Packit Service 6a0f92
                        "totem",
Packit Service 6a0f92
                        NULL);
Packit Service 6a0f92
Packit Service 6a0f92
    iconview = gtk_icon_view_new_with_model (GTK_TREE_MODEL (store));
Packit Service 6a0f92
    gtk_icon_view_set_text_column (GTK_ICON_VIEW (iconview), NAME_COLUMN);
Packit Service 6a0f92
    gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (iconview), PIXBUF_COLUMN);
Packit Service 6a0f92
Packit Service 6a0f92
    sw = gtk_scrolled_window_new (NULL, NULL);
Packit Service 6a0f92
    gtk_container_add (GTK_CONTAINER (window), sw);
Packit Service 6a0f92
    gtk_container_add (GTK_CONTAINER (sw), iconview);
Packit Service 6a0f92
    gtk_widget_show_all (sw);
Packit Service 6a0f92
Packit Service 6a0f92
    /* Widget 2 is a toolbar */
Packit Service 6a0f92
    stage = gtk_clutter_window_get_stage (GTK_CLUTTER_WINDOW (window));
Packit Service 6a0f92
Packit Service 6a0f92
    toolbar = gtk_toolbar_new ();
Packit Service 6a0f92
    add_toolbar_items (GTK_TOOLBAR (toolbar),
Packit Service 6a0f92
                       "list-add",
Packit Service 6a0f92
                       "format-text-bold",
Packit Service 6a0f92
                       "format-text-italic",
Packit Service 6a0f92
                       "media-optical",
Packit Service 6a0f92
                       "edit-copy",
Packit Service 6a0f92
                       NULL);
Packit Service 6a0f92
Packit Service 6a0f92
    gtk_widget_show_all (toolbar);
Packit Service 6a0f92
    actor = gtk_clutter_actor_new_with_contents (toolbar);
Packit Service 6a0f92
    clutter_actor_add_constraint (actor, clutter_bind_constraint_new (stage, CLUTTER_BIND_WIDTH, 0.0));
Packit Service 6a0f92
    g_signal_connect (actor, "enter-event", G_CALLBACK (on_toolbar_enter), NULL);
Packit Service 6a0f92
    g_signal_connect (actor, "leave-event", G_CALLBACK (on_toolbar_leave), NULL);
Packit Service 6a0f92
Packit Service 6a0f92
    clutter_actor_set_y (actor, clutter_actor_get_height (actor) * -0.5);
Packit Service 6a0f92
    clutter_actor_set_opacity (actor, 128);
Packit Service 6a0f92
    clutter_actor_set_reactive (actor, TRUE);
Packit Service 6a0f92
    clutter_actor_add_child (stage, actor);
Packit Service 6a0f92
Packit Service 6a0f92
    gtk_widget_show_all (window);
Packit Service 6a0f92
    gtk_main ();
Packit Service 6a0f92
Packit Service 6a0f92
    return 0;
Packit Service 6a0f92
}