diff options
author | Jonas Danielsson <jonas@threetimestwo.org> | 2015-11-12 11:55:42 +0100 |
---|---|---|
committer | Jiří Techet <techet@gmail.com> | 2015-11-16 21:03:03 +0100 |
commit | e50da6817569186ae854fdb2ac7453accb38077e (patch) | |
tree | a5f79df8bd9d18ee1727084b601a9505072b83fd | |
parent | 1f061e27e7e6d1666e01e5a30cc5b7f7acb55464 (diff) | |
download | libchamplain-e50da6817569186ae854fdb2ac7453accb38077e.tar.gz |
ChamplainTile: Implement ChamplainExportable
https://bugzilla.gnome.org/show_bug.cgi?id=757350
-rw-r--r-- | champlain/champlain-tile.c | 60 | ||||
-rw-r--r-- | champlain/champlain-tile.h | 1 |
2 files changed, 59 insertions, 2 deletions
diff --git a/champlain/champlain-tile.c b/champlain/champlain-tile.c index ec48007..4c2e6d1 100644 --- a/champlain/champlain-tile.c +++ b/champlain/champlain-tile.c @@ -35,8 +35,15 @@ #include <libsoup/soup.h> #include <gio/gio.h> #include <clutter/clutter.h> +#include <cairo-gobject.h> -G_DEFINE_TYPE (ChamplainTile, champlain_tile, CLUTTER_TYPE_ACTOR) +static void set_surface (ChamplainExportable *exportable, + cairo_surface_t *surface); +static cairo_surface_t *get_surface (ChamplainExportable *exportable); +static void exportable_interface_init (ChamplainExportableIface *iface); + +G_DEFINE_TYPE_WITH_CODE (ChamplainTile, champlain_tile, CLUTTER_TYPE_ACTOR, + G_IMPLEMENT_INTERFACE (CHAMPLAIN_TYPE_EXPORTABLE, exportable_interface_init)); #define GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHAMPLAIN_TYPE_TILE, ChamplainTilePrivate)) @@ -52,7 +59,8 @@ enum PROP_STATE, PROP_CONTENT, PROP_ETAG, - PROP_FADE_IN + PROP_FADE_IN, + PROP_SURFACE }; enum @@ -79,6 +87,7 @@ struct _ChamplainTilePrivate GTimeVal *modified_time; /* The last modified time of the cache */ gchar *etag; /* The HTTP ETag sent by the server */ gboolean content_displayed; + cairo_surface_t *surface; }; static void @@ -123,6 +132,10 @@ champlain_tile_get_property (GObject *object, g_value_set_boolean (value, champlain_tile_get_fade_in (self)); break; + case PROP_SURFACE: + g_value_set_boxed (value, get_surface (CHAMPLAIN_EXPORTABLE (self))); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -171,6 +184,10 @@ champlain_tile_set_property (GObject *object, champlain_tile_set_fade_in (self, g_value_get_boolean (value)); break; + case PROP_SURFACE: + set_surface (CHAMPLAIN_EXPORTABLE (self), g_value_get_boxed (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -188,6 +205,7 @@ champlain_tile_dispose (GObject *object) priv->content_actor = NULL; } + g_clear_pointer (&priv->surface, cairo_surface_destroy); G_OBJECT_CLASS (champlain_tile_parent_class)->dispose (object); } @@ -348,6 +366,10 @@ champlain_tile_class_init (ChamplainTileClass *klass) FALSE, G_PARAM_READWRITE)); + g_object_class_override_property (object_class, + PROP_SURFACE, + "surface"); + /** * ChamplainTile::render-complete: * @self: a #ChamplainTile @@ -395,6 +417,40 @@ champlain_tile_init (ChamplainTile *self) } +static void +set_surface (ChamplainExportable *exportable, + cairo_surface_t *surface) +{ + g_return_if_fail (CHAMPLAIN_TILE (exportable)); + g_return_if_fail (surface != NULL); + + ChamplainTile *self = CHAMPLAIN_TILE (exportable); + + if (self->priv->surface == surface) + return; + + cairo_surface_destroy (self->priv->surface); + self->priv->surface = cairo_surface_reference (surface); + g_object_notify (G_OBJECT (self), "surface"); +} + + +static cairo_surface_t * +get_surface (ChamplainExportable *exportable) +{ + g_return_val_if_fail (CHAMPLAIN_IS_TILE (exportable), NULL); + + return CHAMPLAIN_TILE (exportable)->priv->surface; +} + + +static void +exportable_interface_init (ChamplainExportableIface *iface) +{ + iface->get_surface = get_surface; + iface->set_surface = set_surface; +} + /** * champlain_tile_new: * diff --git a/champlain/champlain-tile.h b/champlain/champlain-tile.h index 8ebac55..ca2224b 100644 --- a/champlain/champlain-tile.h +++ b/champlain/champlain-tile.h @@ -21,6 +21,7 @@ #define CHAMPLAIN_MAP_TILE_H #include <champlain/champlain-defines.h> +#include <champlain/champlain-exportable.h> #include <glib.h> #include <clutter/clutter.h> |