[zoomable] Add Zoomable interface
authorEmmanuele Bassi <ebassi@linux.intel.com>
Wed, 15 Apr 2009 14:30:24 +0000 (15:30 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Mon, 22 Jun 2009 11:49:56 +0000 (12:49 +0100)
Add a GtkClutterZoomable interface, connecting a ClutterActor
to a GtkAdjustment in the same spirit as the Scrollable interface.

clutter-gtk/Makefile.am
clutter-gtk/clutter-gtk.h
clutter-gtk/gtk-clutter-zoomable.c [new file with mode: 0644]
clutter-gtk/gtk-clutter-zoomable.h [new file with mode: 0644]

index 7a9e66f..2687e4f 100644 (file)
@@ -2,7 +2,6 @@ CLEANFILES=
 INCLUDES = \
        -I$(srcdir)                             \
        -I$(top_srcdir)                         \
 INCLUDES = \
        -I$(srcdir)                             \
        -I$(top_srcdir)                         \
-       $(CLUTTER_CFLAGS)                       \
        -DG_LOG_DOMAIN=\"Clutter-Gtk\"          \
        -DPREFIX=\""$(prefix)"\"                \
        -DLIBDIR=\""$(libdir)"\"                \
        -DG_LOG_DOMAIN=\"Clutter-Gtk\"          \
        -DPREFIX=\""$(prefix)"\"                \
        -DLIBDIR=\""$(libdir)"\"                \
@@ -26,7 +25,8 @@ libclutter_gtk_0_9_la_SOURCES =       \
         gtk-clutter-embed.c            \
         gtk-clutter-scrollable.c       \
         gtk-clutter-util.c             \
         gtk-clutter-embed.c            \
         gtk-clutter-scrollable.c       \
         gtk-clutter-util.c             \
-        gtk-clutter-viewport.c
+        gtk-clutter-viewport.c         \
+       gtk-clutter-zoomable.c
 
 libclutter_gtk_0_9_la_LIBADD = $(CLUTTER_LIBS) $(GTK_LIBS)
 
 
 libclutter_gtk_0_9_la_LIBADD = $(CLUTTER_LIBS) $(GTK_LIBS)
 
@@ -40,7 +40,8 @@ cluttergtkheaders_HEADERS =           \
         gtk-clutter-embed.h            \
         gtk-clutter-scrollable.h       \
         gtk-clutter-util.h             \
         gtk-clutter-embed.h            \
         gtk-clutter-scrollable.h       \
         gtk-clutter-util.h             \
-        gtk-clutter-viewport.h
+        gtk-clutter-viewport.h         \
+       gtk-clutter-zoomable.h
 
 if HAVE_INTROSPECTION
 BUILT_GIRSOURCES =
 
 if HAVE_INTROSPECTION
 BUILT_GIRSOURCES =
index c4b8c7a..5d56798 100644 (file)
@@ -9,6 +9,7 @@
 #include "gtk-clutter-scrollable.h"
 #include "gtk-clutter-util.h"
 #include "gtk-clutter-viewport.h"
 #include "gtk-clutter-scrollable.h"
 #include "gtk-clutter-util.h"
 #include "gtk-clutter-viewport.h"
+#include "gtk-clutter-zoomable.h"
 
 #undef __CLUTTER_GTK_H_INSIDE__
 
 
 #undef __CLUTTER_GTK_H_INSIDE__
 
diff --git a/clutter-gtk/gtk-clutter-zoomable.c b/clutter-gtk/gtk-clutter-zoomable.c
new file mode 100644 (file)
index 0000000..58bd93b
--- /dev/null
@@ -0,0 +1,117 @@
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gtk-clutter-zoomable.h"
+
+#define I_(str) (g_intern_static_string ((str)))
+
+/**
+ * SECTION:gtk-clutter-zoomable
+ * @short_description: Interface for zoomable actors
+ *
+ * FIXME
+ *
+ * #GtkClutterZoomable is available since Clutter-GTK 1.0
+ */
+
+static void
+gtk_clutter_zoomable_base_init (gpointer g_iface)
+{
+  static gboolean is_initialized = FALSE;
+
+  if (G_UNLIKELY (!is_initialized))
+    {
+      GParamSpec *pspec;
+
+      /**
+       * GtkClutterZoomable:zadjustment:
+       *
+       * The #GtkAdjustment that determines the value of
+       * the zoom factor for this zoomable actor
+       *
+       * Since: 1.0
+       */
+      pspec = g_param_spec_object ("zadjustment",
+                                   "Zoom Adjustment",
+                                   "The GtkAdjustment that determines "
+                                   "the zoom factor",
+                                   GTK_TYPE_ADJUSTMENT,
+                                   G_PARAM_READWRITE |
+                                   G_PARAM_CONSTRUCT);
+      g_object_interface_install_property (g_iface, pspec);
+
+      is_initialized = TRUE;
+    }
+}
+
+GType
+gtk_clutter_zoomable_get_type (void)
+{
+  static GType zoomable_type = 0;
+
+  if (G_UNLIKELY (!zoomable_type))
+    {
+      const GTypeInfo zoomable_info =
+      {
+        sizeof (GtkClutterZoomableIface),
+        (GBaseInitFunc)     gtk_clutter_zoomable_base_init,
+        (GBaseFinalizeFunc) NULL,
+      };
+
+      zoomable_type = g_type_register_static (G_TYPE_INTERFACE,
+                                              I_("GtkClutterZoomable"),
+                                              &zoomable_info, 0);
+    }
+
+  return zoomable_type;
+}
+
+/**
+ * gtk_clutter_zoomable_set_adjustment:
+ * @zoomable: a #GtkClutterZoomable
+ * @z_adjust: a #GtkAdjustment, or %NULL
+ *
+ * Sets the adjustment used to determine the zoom factor of
+ * the zoomable actor
+ *
+ * Since: 1.0
+ */
+void
+gtk_clutter_zoomable_set_adjustment (GtkClutterZoomable *zoomable,
+                                     GtkAdjustment      *z_adjust)
+{
+  GtkClutterZoomableIface *iface;
+
+  g_return_if_fail (GTK_CLUTTER_IS_ZOOMABLE (zoomable));
+  g_return_if_fail (z_adjust == NULL || GTK_IS_ADJUSTMENT (z_adjust));
+
+  iface = GTK_CLUTTER_ZOOMABLE_GET_IFACE (zoomable);
+  if (iface->set_adjustment)
+    iface->set_adjustment (zoomable, z_adjust);
+}
+
+/**
+ * gtk_clutter_zoomable_get_adjustment:
+ * @zoomable: a #GtkClutterZoomable
+ *
+ * Retrieves the adjustment used to determine the zoom factor of
+ * the zoomable actor
+ *
+ * Return value: a #GtkAdjustment
+ *
+ * Since: 1.0
+ */
+GtkAdjustment *
+gtk_clutter_zoomable_get_adjustment (GtkClutterZoomable *zoomable)
+{
+  GtkClutterZoomableIface *iface;
+
+  g_return_val_if_fail (GTK_CLUTTER_IS_ZOOMABLE (zoomable), NULL);
+
+  iface = GTK_CLUTTER_ZOOMABLE_GET_IFACE (zoomable);
+  if (iface->get_adjustment)
+    return iface->get_adjustment (zoomable);
+
+  return NULL;
+}
diff --git a/clutter-gtk/gtk-clutter-zoomable.h b/clutter-gtk/gtk-clutter-zoomable.h
new file mode 100644 (file)
index 0000000..1896d0d
--- /dev/null
@@ -0,0 +1,49 @@
+#if !defined(__CLUTTER_GTK_H_INSIDE__) && !defined(CLUTTER_GTK_COMPILATION)
+#error "Only <clutter-gtk/clutter-gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_CLUTTER_ZOOMABLE_H__
+#define __GTK_CLUTTER_ZOOMABLE_H__
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTK_CLUTTER_TYPE_ZOOMABLE               (gtk_clutter_zoomable_get_type ())
+#define GTK_CLUTTER_ZOOMABLE(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_CLUTTER_TYPE_ZOOMABLE, GtkClutterZoomable))
+#define GTK_CLUTTER_IS_ZOOMABLE(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_CLUTTER_TYPE_ZOOMABLE))
+#define GTK_CLUTTER_ZOOMABLE_GET_IFACE(obj)     (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_CLUTTER_TYPE_ZOOMABLE, GtkClutterZoomableIface))
+
+typedef struct _GtkClutterZoomable      GtkClutterZoomable; /* dummy typedef */
+typedef struct _GtkClutterZoomableIface GtkClutterZoomableIface;
+
+/**
+ * GtkClutterZoomableIface:
+ * @set_adjustment: virtual function for setting the zoom adjustment
+ * @get_adjustment: virtual function for getting the zoom adjustment
+ *
+ * The #GtkClutterZoomableIface structure contains only private data
+ *
+ * Since: 1.0
+ */
+struct _GtkClutterZoomableIface
+{
+  /*< private >*/
+  GTypeInterface parent_iface;
+
+  /*< public >*/
+  void           (* set_adjustment) (GtkClutterZoomable *zoomable,
+                                     GtkAdjustment      *adjustment);
+  GtkAdjustment *(* get_adjustment) (GtkClutterZoomable *zoomable);
+};
+
+GType gtk_clutter_zoomable_get_type (void) G_GNUC_CONST;
+
+void           gtk_clutter_zoomable_set_adjustment (GtkClutterZoomable *zoomable,
+                                                    GtkAdjustment      *z_adjust);
+GtkAdjustment *gtk_clutter_zoomable_get_adjustment (GtkClutterZoomable *zoomable);
+
+G_END_DECLS
+
+#endif /* __GTK_CLUTTER_ZOOMABLE_H__ */