[libchamplain] Add ChamplainExportable interface



commit 1f061e27e7e6d1666e01e5a30cc5b7f7acb55464
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Thu Nov 12 11:54:17 2015 +0100

    Add ChamplainExportable interface
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757350

 champlain/Makefile.am                    |    7 ++-
 champlain/champlain-exportable.c         |   88 ++++++++++++++++++++++++++++++
 champlain/champlain-exportable.h         |   76 ++++++++++++++++++++++++++
 docs/reference/libchamplain-sections.txt |   16 ++++++
 4 files changed, 185 insertions(+), 2 deletions(-)
---
diff --git a/champlain/Makefile.am b/champlain/Makefile.am
index c04498d..c313f67 100644
--- a/champlain/Makefile.am
+++ b/champlain/Makefile.am
@@ -45,7 +45,9 @@ libchamplain_headers_public =                                 \
        $(srcdir)/champlain-adjustment.h                \
        $(srcdir)/champlain-kinetic-scroll-view.h               \
        $(srcdir)/champlain-viewport.h          \
-       $(srcdir)/champlain-bounding-box.h
+       $(srcdir)/champlain-bounding-box.h              \
+       $(srcdir)/champlain-exportable.h
+
 
 libchamplain_headers_private = \
        $(srcdir)/champlain-debug.h     \
@@ -91,7 +93,8 @@ libchamplain_sources =                                        \
        champlain-adjustment.c \
        champlain-kinetic-scroll-view.c \
        champlain-viewport.c    \
-       champlain-bounding-box.c
+       champlain-bounding-box.c                \
+       $(srcdir)/champlain-exportable.c
 
 champlain-features.h: $(top_builddir)/config.status
        $(AM_V_GEN) ( cd $(top_builddir) && ./config.status champlain/$@ )
diff --git a/champlain/champlain-exportable.c b/champlain/champlain-exportable.c
new file mode 100644
index 0000000..5d5eb7a
--- /dev/null
+++ b/champlain/champlain-exportable.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2015 Jonas Danielsson
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+ /**
+ * SECTION:champlain-exportable
+ * @short_description: An interface for objects exportable to a cairo surface
+ *
+ * By implementing #ChamplainExportable the object declares that it has a cairo
+ * surface (#cairo_surface_t) representation of it self.
+ */
+
+#include "champlain-exportable.h"
+#include "champlain-private.h"
+
+#include <cairo-gobject.h>
+
+typedef ChamplainExportableIface ChamplainExportableInterface;
+
+G_DEFINE_INTERFACE (ChamplainExportable, champlain_exportable, G_TYPE_OBJECT);
+
+
+static void
+champlain_exportable_default_init (ChamplainExportableInterface *iface)
+{
+  /**
+   * ChamplainExportable:surface:
+   *
+   * A #cairo_surface_t representation
+   *
+   * Since: 0.12.12
+   */
+  g_object_interface_install_property (iface,
+      g_param_spec_boxed ("surface",
+          "Surface",
+          "Cairo surface representaion",
+          CAIRO_GOBJECT_TYPE_SURFACE,
+          G_PARAM_READWRITE));
+}
+
+
+/**
+ * champlain_exportable_set_surface:
+ * @exportable: the #ChamplainExportable
+ * @surface: the #cairo_surface_t
+ *
+ * Set a #cairo_surface_t to be associated with this tile.
+ *
+ * Since: 0.12.12
+ */
+void
+champlain_exportable_set_surface (ChamplainExportable *exportable,
+    cairo_surface_t     *surface)
+{
+  g_return_if_fail (CHAMPLAIN_EXPORTABLE (exportable));
+  g_return_if_fail (surface != NULL);
+
+  CHAMPLAIN_EXPORTABLE_GET_IFACE (exportable)->set_surface (exportable, surface);
+}
+
+
+/**
+ * champlain_exportable_get_surface:
+ * @exportable: a #ChamplainExportable
+ *
+ * Gets the surface
+ *
+ * Returns: (transfer none): the #cairo_surface_t of the object
+ *
+ * Since: 0.12.12
+ */
+cairo_surface_t *
+champlain_exportable_get_surface (ChamplainExportable *exportable)
+{
+  return CHAMPLAIN_EXPORTABLE_GET_IFACE (exportable)->get_surface (exportable);
+}
diff --git a/champlain/champlain-exportable.h b/champlain/champlain-exportable.h
new file mode 100644
index 0000000..e3523eb
--- /dev/null
+++ b/champlain/champlain-exportable.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2015 Jonas Danielsson
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#if !defined (__CHAMPLAIN_CHAMPLAIN_H_INSIDE__) && !defined (CHAMPLAIN_COMPILATION)
+#error "Only <champlain/champlain.h> can be included directly."
+#endif
+
+#ifndef __CHAMPLAIN_EXPORTABLE_H__
+#define __CHAMPLAIN_EXPORTABLE_H__
+
+#include <glib-object.h>
+#include <cairo.h>
+
+G_BEGIN_DECLS
+
+#define CHAMPLAIN_TYPE_EXPORTABLE (champlain_exportable_get_type ())
+
+#define CHAMPLAIN_EXPORTABLE(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHAMPLAIN_TYPE_EXPORTABLE, ChamplainExportable))
+
+#define CHAMPLAIN_IS_EXPORTABLE(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CHAMPLAIN_TYPE_EXPORTABLE))
+
+#define CHAMPLAIN_EXPORTABLE_GET_IFACE(inst) \
+  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), CHAMPLAIN_TYPE_EXPORTABLE, ChamplainExportableIface))
+
+typedef struct _ChamplainExportable ChamplainExportable; /* Dummy object */
+typedef struct _ChamplainExportableIface ChamplainExportableIface;
+
+/**
+ * ChamplainExportable:
+ *
+ * An interface common to objects having a #cairo_surface_t representation.
+ */
+
+/**
+ * ChamplainExportableIface:
+ * @get_surface: virtual function for obtaining the cairo surface.
+ * @set_surface: virtual function for setting a cairo surface.
+ *
+ * An interface common to objects having a #cairo_surface_t representation.
+ */
+struct _ChamplainExportableIface
+{
+  /*< private >*/
+  GTypeInterface g_iface;
+
+  /*< public >*/
+  cairo_surface_t *(*get_surface)(ChamplainExportable *exportable);
+  void (*set_surface)(ChamplainExportable *exportable,
+      cairo_surface_t *surface);
+};
+
+GType champlain_exportable_get_type (void) G_GNUC_CONST;
+
+void champlain_exportable_set_surface (ChamplainExportable *exportable,
+    cairo_surface_t *surface);
+cairo_surface_t * champlain_exportable_get_surface (ChamplainExportable *exportable);
+
+G_END_DECLS
+
+#endif /* __CHAMPLAIN_EXPORTABLE_H__ */
diff --git a/docs/reference/libchamplain-sections.txt b/docs/reference/libchamplain-sections.txt
index 5c08af8..1acdbc7 100644
--- a/docs/reference/libchamplain-sections.txt
+++ b/docs/reference/libchamplain-sections.txt
@@ -158,6 +158,7 @@ champlain_view_get_zoom_on_double_click
 champlain_view_get_animate_zoom
 champlain_view_get_background_pattern
 champlain_view_reload_tiles
+champlain_view_to_surface
 champlain_view_x_to_longitude
 champlain_view_y_to_latitude
 champlain_view_longitude_to_x
@@ -785,3 +786,18 @@ CHAMPLAIN_TYPE_LOCATION
 champlain_location_get_type
 CHAMPLAIN_LOCATION_GET_IFACE
 </SECTION>
+
+<SECTION>
+<FILE>champlain-exportable</FILE>
+<TITLE>ChamplainExportable</TITLE>
+ChamplainExportable
+ChamplainExportableIface
+champlain_exportable_set_surface
+champlain_location_get_surface
+<SUBSECTION Standard>
+CHAMPLAIN_EXPORTABLE
+CHAMPLAIN_IS_EXPORTABLE
+CHAMPLAIN_TYPE_EXPORTABLE
+champlain_exportable_get_type
+CHAMPLAIN_EXPORTABLE_GET_IFACE
+</SECTION>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]