From 4c09e240a4f89653162cb76079bb06b0837e4c8e Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 15 Apr 2009 15:30:24 +0100 Subject: [PATCH] [zoomable] Add Zoomable interface Add a GtkClutterZoomable interface, connecting a ClutterActor to a GtkAdjustment in the same spirit as the Scrollable interface. --- clutter-gtk/Makefile.am | 7 ++- clutter-gtk/clutter-gtk.h | 1 + clutter-gtk/gtk-clutter-zoomable.c | 117 ++++++++++++++++++++++++++++++++++++ clutter-gtk/gtk-clutter-zoomable.h | 49 +++++++++++++++ 4 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 clutter-gtk/gtk-clutter-zoomable.c create mode 100644 clutter-gtk/gtk-clutter-zoomable.h diff --git a/clutter-gtk/Makefile.am b/clutter-gtk/Makefile.am index 7a9e66f..2687e4f 100644 --- a/clutter-gtk/Makefile.am +++ b/clutter-gtk/Makefile.am @@ -2,7 +2,6 @@ CLEANFILES= INCLUDES = \ -I$(srcdir) \ -I$(top_srcdir) \ - $(CLUTTER_CFLAGS) \ -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-viewport.c + gtk-clutter-viewport.c \ + gtk-clutter-zoomable.c 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-viewport.h + gtk-clutter-viewport.h \ + gtk-clutter-zoomable.h if HAVE_INTROSPECTION BUILT_GIRSOURCES = diff --git a/clutter-gtk/clutter-gtk.h b/clutter-gtk/clutter-gtk.h index c4b8c7a..5d56798 100644 --- a/clutter-gtk/clutter-gtk.h +++ b/clutter-gtk/clutter-gtk.h @@ -9,6 +9,7 @@ #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__ diff --git a/clutter-gtk/gtk-clutter-zoomable.c b/clutter-gtk/gtk-clutter-zoomable.c new file mode 100644 index 0000000..58bd93b --- /dev/null +++ b/clutter-gtk/gtk-clutter-zoomable.c @@ -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 index 0000000..1896d0d --- /dev/null +++ b/clutter-gtk/gtk-clutter-zoomable.h @@ -0,0 +1,49 @@ +#if !defined(__CLUTTER_GTK_H_INSIDE__) && !defined(CLUTTER_GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __GTK_CLUTTER_ZOOMABLE_H__ +#define __GTK_CLUTTER_ZOOMABLE_H__ + +#include +#include + +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__ */ -- 1.7.9.5