[libchamplain] ChamplainPoint: Implement ChamplainExportable interface
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libchamplain] ChamplainPoint: Implement ChamplainExportable interface
- Date: Tue, 12 Jan 2016 19:10:43 +0000 (UTC)
commit c8829c4f86569fe5c75dc96d3578e29edbb327bd
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Sat Jan 9 10:35:50 2016 +0100
ChamplainPoint: Implement ChamplainExportable interface
champlain/champlain-point.c | 64 ++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 63 insertions(+), 1 deletions(-)
---
diff --git a/champlain/champlain-point.c b/champlain/champlain-point.c
index 06d10ad..c878724 100644
--- a/champlain/champlain-point.c
+++ b/champlain/champlain-point.c
@@ -55,6 +55,7 @@ enum
PROP_0,
PROP_COLOR,
PROP_SIZE,
+ PROP_SURFACE,
};
/* static guint champlain_point_signals[LAST_SIGNAL] = { 0, }; */
@@ -64,11 +65,19 @@ struct _ChamplainPointPrivate
ClutterColor *color;
gdouble size;
ClutterContent *canvas;
+ cairo_surface_t *surface;
guint redraw_id;
};
-G_DEFINE_TYPE (ChamplainPoint, champlain_point, CHAMPLAIN_TYPE_MARKER);
+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 (ChamplainPoint, champlain_point, CHAMPLAIN_TYPE_MARKER,
+ G_IMPLEMENT_INTERFACE (CHAMPLAIN_TYPE_EXPORTABLE, exportable_interface_init));
#define GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CHAMPLAIN_TYPE_POINT, ChamplainPointPrivate))
@@ -92,6 +101,10 @@ champlain_point_get_property (GObject *object,
g_value_set_double (value, priv->size);
break;
+ case PROP_SURFACE:
+ g_value_set_boxed (value, get_surface (CHAMPLAIN_EXPORTABLE (object)));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -116,6 +129,10 @@ champlain_point_set_property (GObject *object,
champlain_point_set_size (point, g_value_get_double (value));
break;
+ case PROP_SURFACE:
+ set_surface (CHAMPLAIN_EXPORTABLE (object), g_value_get_boxed (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -146,6 +163,10 @@ pick (ClutterActor *self,
static void
champlain_point_dispose (GObject *object)
{
+ ChamplainPointPrivate *priv = CHAMPLAIN_POINT (object)->priv;
+
+ g_clear_pointer (&priv->surface, cairo_surface_destroy);
+
G_OBJECT_CLASS (champlain_point_parent_class)->dispose (object);
}
@@ -201,6 +222,11 @@ champlain_point_class_init (ChamplainPointClass *klass)
G_MAXDOUBLE,
12,
CHAMPLAIN_PARAM_READWRITE));
+
+ g_object_class_override_property (object_class,
+ PROP_SURFACE,
+ "surface");
+
}
@@ -216,6 +242,8 @@ draw (ClutterCanvas *canvas,
gdouble radius = size / 2.0;
const ClutterColor *color;
+ set_surface (CHAMPLAIN_EXPORTABLE (point), cairo_get_target (cr));
+
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_paint (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
@@ -270,6 +298,40 @@ champlain_point_init (ChamplainPoint *point)
}
+static void
+set_surface (ChamplainExportable *exportable,
+ cairo_surface_t *surface)
+{
+ g_return_if_fail (CHAMPLAIN_POINT (exportable));
+ g_return_if_fail (surface != NULL);
+
+ ChamplainPoint *self = CHAMPLAIN_POINT (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_POINT (exportable), NULL);
+
+ return CHAMPLAIN_POINT (exportable)->priv->surface;
+}
+
+
+static void
+exportable_interface_init (ChamplainExportableIface *iface)
+{
+ iface->get_surface = get_surface;
+ iface->set_surface = set_surface;
+}
+
+
/**
* champlain_point_new:
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]