[glide] Shape serializes



commit b5dd802b83b05f10ce2017ff916254f9236923df
Author: Robert Carr <racarr Valentine localdomain>
Date:   Thu May 6 07:30:28 2010 -0400

    Shape serializes

 libglide/glide-json-util.c |   20 ++++++++++++++++++++
 libglide/glide-json-util.h |    3 +++
 libglide/glide-shape.c     |   42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/libglide/glide-json-util.c b/libglide/glide-json-util.c
index f63d28b..92b7cb9 100644
--- a/libglide/glide-json-util.c
+++ b/libglide/glide-json-util.c
@@ -43,6 +43,26 @@ glide_json_object_get_string (JsonObject *obj, const gchar *prop)
 }
 
 void
+glide_json_object_set_boolean (JsonObject *obj, const gchar *prop, gboolean value)
+{
+  JsonNode *n = json_node_new (JSON_NODE_VALUE);
+  
+  json_node_set_boolean (n, value);
+  json_object_set_member (obj, prop, n);
+}
+
+gboolean
+glide_json_object_get_boolean (JsonObject *obj, const gchar *prop)
+{
+  JsonNode *n = json_object_get_member (obj, prop);
+  
+  if (!n)
+    return FALSE;
+  
+  return json_node_get_boolean (n);
+}
+
+void
 glide_json_object_get_animation (JsonObject *obj,
 				const gchar *prop,
 				GlideAnimationInfo *info)
diff --git a/libglide/glide-json-util.h b/libglide/glide-json-util.h
index b3ed93d..a1fe73b 100644
--- a/libglide/glide-json-util.h
+++ b/libglide/glide-json-util.h
@@ -26,6 +26,9 @@
 void glide_json_object_set_string (JsonObject *obj, const gchar *prop, const gchar *value);
 const gchar *glide_json_object_get_string (JsonObject *obj, const gchar *prop);
 
+void glide_json_object_set_boolean (JsonObject *obj, const gchar *prop, gboolean value);
+gboolean glide_json_object_get_boolean (JsonObject *obj, const gchar *prop);
+
 void glide_json_object_set_double (JsonObject *obj, const gchar *prop, gdouble value);
 gdouble glide_json_object_get_double (JsonObject *obj, const gchar *prop);
 
diff --git a/libglide/glide-shape.c b/libglide/glide-shape.c
index c2b8367..7105987 100644
--- a/libglide/glide-shape.c
+++ b/libglide/glide-shape.c
@@ -239,6 +239,48 @@ glide_shape_finalize (GObject *object)
 {
   G_OBJECT_CLASS (glide_shape_parent_class)->finalize (object);
 }
+static void
+glide_json_object_add_shape_properties (JsonObject *obj, GlideShape *shape)
+{
+  JsonNode *n = json_node_new (JSON_NODE_OBJECT);
+  JsonObject *shape_obj = json_object_new ();
+  ClutterColor c;
+  gchar *cs;
+  
+  json_node_set_object (n, shape_obj);
+  
+  glide_shape_get_color (shape, &c);
+  cs = clutter_color_to_string (&c);
+  glide_json_object_set_string (shape_obj, "color", cs);
+  g_free (cs);
+  
+  glide_shape_get_border_color (shape, &c);
+  cs = clutter_color_to_string (&c);
+  glide_json_object_set_string (shape_obj, "border-color", cs);
+  g_free (cs);
+  
+  glide_json_object_set_double (shape_obj, "border-width",
+				glide_shape_get_border_width (shape));
+  glide_json_object_set_boolean (shape_obj, "has-border",
+				 glide_shape_get_has_border (shape));
+  
+  json_object_set_member (obj, "shape-properties", n);
+}
+
+static JsonNode *
+glide_shape_serialize (GlideActor *self)
+{
+  JsonNode *node = json_node_new (JSON_NODE_OBJECT);
+  JsonObject *obj = json_object_new ();
+  
+  json_node_set_object (node, obj);
+  
+  glide_json_object_set_string (obj, "type", "shape");
+  glide_json_object_add_actor_geometry (obj, CLUTTER_ACTOR (self));
+  glide_json_object_add_shape_properties (obj, GLIDE_SHAPE (self));
+    
+  return node;
+}
 			    
 
 static void



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