[cairo-commit] goocanvas/src goocanvasitem.c, 1.34, 1.35 goocanvasitem.h, 1.23, 1.24 goocanvasitemmodel.c, 1.17, 1.18 goocanvasitemmodel.h, 1.13, 1.14 goocanvasitemsimple.h, 1.24, 1.25

Damon Chaplin commit at pdx.freedesktop.org
Thu Mar 27 07:05:06 PDT 2008


Committed by: damon

Update of /cvs/cairo/goocanvas/src
In directory kemper:/tmp/cvs-serv15281/src

Modified Files:
	goocanvasitem.c goocanvasitem.h goocanvasitemmodel.c 
	goocanvasitemmodel.h goocanvasitemsimple.h 
Log Message:
2008-03-27  Damon Chaplin  <damon at gnome.org>

	    * src/goocanvasitem.c (goo_canvas_item_get_simple_transform): 
	    * src/goocanvasitemmodel.c (goo_canvas_item_model_get_simple_transform): 
	    new functions to do opposite of set_simple_transform().

	    * demo/mv-demo.c (test_simple_transforms): 
	    * demo/demo.c (test_simple_transforms): added some test code for above.




Index: goocanvasitem.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitem.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- goocanvasitem.c	18 Nov 2007 13:57:40 -0000	1.34
+++ goocanvasitem.c	27 Mar 2008 14:08:55 -0000	1.35
@@ -657,9 +657,24 @@
  * @parent: the new parent item.
  * 
  * This function is only intended to be used when implementing new canvas
- * items, specifically container items such as #GooCanvasGroup.
+ * items (specifically container items such as #GooCanvasGroup).
+ * It sets the parent of the child item.
+ * <!--PARAMETERS-->
+ * <note><para>
+ * This function cannot be used to add an item to a group
+ * or to change the parent of an item.
  *
- * It sets the parent of the item.
+ * To add an item to a group use goo_canvas_item_add_child().
+ *
+ * To move an item from one parent to another do something like this:
+ *
+ * <informalexample><programlisting>
+ *  g_object_ref (item);
+ *  goo_canvas_item_remove (item);
+ *  goo_canvas_item_add_child (new_parent, item, -1);
+ *  g_object_unref (item);
+ * </programlisting></informalexample>
+ * </para></note>
  **/
 void
 goo_canvas_item_set_parent (GooCanvasItem *item,
@@ -848,6 +863,61 @@
 
 
 /**
+ * goo_canvas_item_get_simple_transform:
+ * @item: an item.
+ * @x: returns the x coordinate of the origin of the item's coordinate space.
+ * @y: returns the y coordinate of the origin of the item's coordinate space.
+ * @scale: returns the scale of the item.
+ * @rotation: returns the clockwise rotation of the item, in degrees (0-360).
+ * 
+ * This function can be used to get the position, scale and rotation of an
+ * item, providing that the item has a simple transformation matrix
+ * (e.g. set with goo_canvas_item_set_simple_transform(), or using a
+ * combination of simple translate, scale and rotate operations). If the item
+ * has a complex transformation matrix the results will be incorrect.
+ * 
+ * Returns: %TRUE if a transform is set.
+ **/
+gboolean
+goo_canvas_item_get_simple_transform (GooCanvasItem   *item,
+				      gdouble         *x,
+				      gdouble         *y,
+				      gdouble         *scale,
+				      gdouble         *rotation)
+{
+  GooCanvasItemIface *iface = GOO_CANVAS_ITEM_GET_IFACE (item);
+  cairo_matrix_t matrix = { 1, 0, 0, 1, 0, 0 };
+  double x1 = 1.0, y1 = 0.0, radians;
+  gboolean has_transform = FALSE;
+
+  if (iface->get_transform)
+    has_transform = iface->get_transform (item, &matrix);
+
+  if (!has_transform)
+    {
+      *x = *y = *rotation = 0.0;
+      *scale = 1.0;
+      return FALSE;
+    }
+
+  *x = matrix.x0;
+  *y = matrix.y0;
+
+  matrix.x0 = 0.0;
+  matrix.y0 = 0.0;
+
+  cairo_matrix_transform_point (&matrix, &x1, &y1);
+  *scale = sqrt (x1 * x1 + y1 * y1);
+  radians = atan2 (y1, x1);
+  *rotation = radians * (180 / M_PI);
+  if (*rotation < 0)
+    *rotation += 360;
+
+  return TRUE;
+}
+
+
+/**
  * goo_canvas_item_set_simple_transform:
  * @item: an item.
  * @x: the x coordinate of the origin of the item's coordinate space.

Index: goocanvasitem.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitem.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- goocanvasitem.h	18 Nov 2007 13:57:41 -0000	1.23
+++ goocanvasitem.h	27 Mar 2008 14:08:55 -0000	1.24
@@ -360,6 +360,11 @@
 						   cairo_matrix_t  *transform);
 void               goo_canvas_item_set_transform  (GooCanvasItem         *item,
 						   const cairo_matrix_t  *transform);
+gboolean	   goo_canvas_item_get_simple_transform (GooCanvasItem   *item,
+							 gdouble         *x,
+							 gdouble         *y,
+							 gdouble         *scale,
+							 gdouble         *rotation);
 void               goo_canvas_item_set_simple_transform (GooCanvasItem   *item,
 							 gdouble          x,
 							 gdouble          y,

Index: goocanvasitemmodel.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitemmodel.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- goocanvasitemmodel.c	18 Nov 2007 13:57:41 -0000	1.17
+++ goocanvasitemmodel.c	27 Mar 2008 14:08:55 -0000	1.18
@@ -580,6 +580,61 @@
 
 
 /**
+ * goo_canvas_item_model_get_simple_transform:
+ * @model: an item model.
+ * @x: returns the x coordinate of the origin of the model's coordinate space.
+ * @y: returns the y coordinate of the origin of the model's coordinate space.
+ * @scale: returns the scale of the model.
+ * @rotation: returns the clockwise rotation of the model, in degrees (0-360).
+ * 
+ * This function can be used to get the position, scale and rotation of an
+ * item model, providing that the model has a simple transformation matrix
+ * (e.g. set with goo_canvas_item_model_set_simple_transform(), or using a
+ * combination of simple translate, scale and rotate operations). If the model
+ * has a complex transformation matrix the results will be incorrect.
+ * 
+ * Returns: %TRUE if a transform is set.
+ **/
+gboolean
+goo_canvas_item_model_get_simple_transform (GooCanvasItemModel *model,
+					    gdouble            *x,
+					    gdouble            *y,
+					    gdouble            *scale,
+					    gdouble            *rotation)
+{
+  GooCanvasItemModelIface *iface = GOO_CANVAS_ITEM_MODEL_GET_IFACE (model);
+  cairo_matrix_t matrix = { 1, 0, 0, 1, 0, 0 };
+  double x1 = 1.0, y1 = 0.0, radians;
+  gboolean has_transform = FALSE;
+
+  if (iface->get_transform)
+    has_transform = iface->get_transform (model, &matrix);
+
+  if (!has_transform)
+    {
+      *x = *y = *rotation = 0.0;
+      *scale = 1.0;
+      return FALSE;
+    }
+
+  *x = matrix.x0;
+  *y = matrix.y0;
+
+  matrix.x0 = 0.0;
+  matrix.y0 = 0.0;
+
+  cairo_matrix_transform_point (&matrix, &x1, &y1);
+  *scale = sqrt (x1 * x1 + y1 * y1);
+  radians = atan2 (y1, x1);
+  *rotation = radians * (180 / M_PI);
+  if (*rotation < 0)
+    *rotation += 360;
+
+  return TRUE;
+}
+
+
+/**
  * goo_canvas_item_model_set_simple_transform:
  * @model: an item model.
  * @x: the x coordinate of the origin of the model's coordinate space.

Index: goocanvasitemmodel.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitemmodel.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- goocanvasitemmodel.h	18 Nov 2007 13:57:41 -0000	1.13
+++ goocanvasitemmodel.h	27 Mar 2008 14:08:55 -0000	1.14
@@ -209,6 +209,11 @@
 							  cairo_matrix_t     *transform);
 void                goo_canvas_item_model_set_transform  (GooCanvasItemModel   *model,
 							  const cairo_matrix_t *transform);
+gboolean	    goo_canvas_item_model_get_simple_transform (GooCanvasItemModel *model,
+								gdouble            *x,
+								gdouble            *y,
+								gdouble            *scale,
+								gdouble            *rotation);
 void                goo_canvas_item_model_set_simple_transform (GooCanvasItemModel *model,
 								gdouble             x,
 								gdouble             y,

Index: goocanvasitemsimple.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitemsimple.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- goocanvasitemsimple.h	11 May 2007 16:30:49 -0000	1.24
+++ goocanvasitemsimple.h	27 Mar 2008 14:08:55 -0000	1.25
@@ -117,6 +117,8 @@
  *  All updating, painting and hit-testing is provided automatically by the
  *  #GooCanvasItemSimple class. (This method is used by the builtin
  *  #GooCanvasEllipse, #GooCanvasRect and #GooCanvasPath items.)
+ *  More complicated subclasses must override @simple_update, @simple_paint and
+ *  @simple_is_item_at instead.
  * @simple_update: subclasses should override this to calculate their new
  *  bounds, in user space.
  * @simple_paint: subclasses should override this to paint their item.
@@ -126,7 +128,7 @@
  * subclasses can override.
  *
  * Simple items need only implement the create_path() method. More complex
- * items must override the update(), paint() and is_item_at() methods.
+ * items must override the update(), paint() and is_item_at() methods instead.
  */
 struct _GooCanvasItemSimpleClass
 {



More information about the cairo-commit mailing list