[cairo-commit] goocanvas/src goocanvas.c, 1.11, 1.12 goocanvas.h,
1.8, 1.9
Damon Chaplin
commit at pdx.freedesktop.org
Tue Feb 27 06:45:14 PST 2007
- Previous message: [cairo-commit] goocanvas/src goocanvasitem.c, 1.22,
1.23 goocanvasitem.h, 1.15, 1.16 goocanvasitemmodel.c, 1.10,
1.11 goocanvasitemmodel.h, 1.8, 1.9
- Next message: [cairo-commit] goocanvas/demo demo.c,1.19,1.20
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: damon
Update of /cvs/cairo/goocanvas/src
In directory kemper:/tmp/cvs-serv26732/src
Modified Files:
goocanvas.c goocanvas.h
Log Message:
2007-02-27 Damon Chaplin <damon at gnome.org>
* Released GooCanvas 0.7
2007-02-27 Damon Chaplin <damon at gnome.org>
* src/goocanvas.c (goo_canvas_get_items_in_area): new function to
get items inside or outside a given area.
* demo/demo.c: added little test for goo_canvas_get_items_at() and
goo_canvas_get_items_in_area().
Index: goocanvas.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvas.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- goocanvas.c 27 Feb 2007 01:01:39 -0000 1.11
+++ goocanvas.c 27 Feb 2007 14:45:08 -0000 1.12
@@ -667,6 +667,7 @@
GooCanvasItemModel *model)
{
g_return_if_fail (GOO_IS_CANVAS (canvas));
+ g_return_if_fail (GOO_IS_CANVAS_ITEM_MODEL (model));
if (canvas->root_item_model == model)
return;
@@ -735,6 +736,7 @@
GooCanvasItem *item)
{
g_return_if_fail (GOO_IS_CANVAS (canvas));
+ g_return_if_fail (GOO_IS_CANVAS_ITEM (item));
if (canvas->root_item == item)
return;
@@ -791,6 +793,9 @@
{
GooCanvasItem *item;
+ g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
+ g_return_val_if_fail (GOO_IS_CANVAS_ITEM_MODEL (model), NULL);
+
if (canvas->model_to_item)
item = g_hash_table_lookup (canvas->model_to_item, model);
@@ -823,6 +828,8 @@
GooCanvasItem *result = NULL;
GList *list;
+ g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
+
/* If no root item is set, just return NULL. */
if (!canvas->root_item)
return NULL;
@@ -853,7 +860,8 @@
* Gets all items at the given point.
*
* Returns: a list of items found at the given point, with the top item at
- * the start of the list, or %NULL if no items were found.
+ * the start of the list, or %NULL if no items were found. The list must be
+ * freed with g_list_free().
**/
GList*
goo_canvas_get_items_at (GooCanvas *canvas,
@@ -864,6 +872,8 @@
cairo_t *cr;
GList *result;
+ g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
+
/* If no root item is set, just return NULL. */
if (!canvas->root_item)
return NULL;
@@ -877,6 +887,106 @@
}
+static GList*
+goo_canvas_get_items_in_area_recurse (GooCanvas *canvas,
+ GooCanvasItem *item,
+ GooCanvasBounds *area,
+ gboolean inside_area,
+ gboolean allow_overlaps,
+ gboolean include_containers,
+ GList *found_items)
+{
+ GooCanvasBounds bounds;
+ gboolean completely_inside = FALSE, completely_outside = FALSE;
+ gboolean is_container, add_item = FALSE;
+ gint n_children, i;
+
+ /* First check the item/container itself. */
+ goo_canvas_item_get_bounds (item, &bounds);
+
+ is_container = goo_canvas_item_is_container (item);
+
+ if (bounds.x1 >= area->x1 && bounds.x2 <= area->x2
+ && bounds.y1 >= area->y1 && bounds.y2 <= area->y2)
+ completely_inside = TRUE;
+
+ if (bounds.x1 > area->x2 || bounds.x2 < area->x1
+ || bounds.y1 > area->y2 || bounds.y2 < area->y1)
+ completely_outside = TRUE;
+
+ if (inside_area)
+ {
+ if (completely_inside
+ || (allow_overlaps && !completely_outside))
+ add_item = TRUE;
+ }
+ else
+ {
+ if (completely_outside
+ || (allow_overlaps && !completely_inside))
+ add_item = TRUE;
+ }
+
+ if (add_item && (!is_container || include_containers))
+ found_items = g_list_prepend (found_items, item);
+
+ /* Now check any children, if appropriate. */
+ if ((inside_area && !completely_outside)
+ || (!inside_area && !completely_inside))
+ {
+ n_children = goo_canvas_item_get_n_children (item);
+ for (i = 0; i < n_children; i++)
+ {
+ GooCanvasItem *child = goo_canvas_item_get_child (item, i);
+ found_items = goo_canvas_get_items_in_area_recurse (canvas, child,
+ area,
+ inside_area,
+ allow_overlaps,
+ include_containers,
+ found_items);
+ }
+ }
+
+ return found_items;
+}
+
+
+/**
+ * goo_canvas_get_items_in_area:
+ * @canvas: a #GooCanvas.
+ * @area: the area to compare with each item's bounds.
+ * @inside_area: %TRUE if items inside @area should be returned, or %FALSE if
+ * items outside @area should be returned.
+ * @allow_overlaps: %TRUE if items which are partly inside and partly outside
+ * should be returned.
+ * @include_containers: %TRUE if containers should be checked as well as
+ * normal items.
+ *
+ * Gets a list of items inside or outside a given area.
+ *
+ * Returns: a list of items in the given area, or %NULL if no items are found.
+ * The list should be freed with g_list_free().
+ **/
+GList*
+goo_canvas_get_items_in_area (GooCanvas *canvas,
+ GooCanvasBounds *area,
+ gboolean inside_area,
+ gboolean allow_overlaps,
+ gboolean include_containers)
+{
+ g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
+
+ /* If no root item is set, just return NULL. */
+ if (!canvas->root_item)
+ return NULL;
+
+ return goo_canvas_get_items_in_area_recurse (canvas, canvas->root_item,
+ area, inside_area,
+ allow_overlaps,
+ include_containers, NULL);
+}
+
+
static void
goo_canvas_realize (GtkWidget *widget)
{
Index: goocanvas.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvas.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- goocanvas.h 27 Feb 2007 01:01:39 -0000 1.8
+++ goocanvas.h 27 Feb 2007 14:45:08 -0000 1.9
@@ -186,6 +186,11 @@
gdouble x,
gdouble y,
gboolean is_pointer_event);
+GList* goo_canvas_get_items_in_area(GooCanvas *canvas,
+ GooCanvasBounds *area,
+ gboolean inside_area,
+ gboolean allow_overlaps,
+ gboolean include_containers);
gdouble goo_canvas_get_scale (GooCanvas *canvas);
void goo_canvas_set_scale (GooCanvas *canvas,
- Previous message: [cairo-commit] goocanvas/src goocanvasitem.c, 1.22,
1.23 goocanvasitem.h, 1.15, 1.16 goocanvasitemmodel.c, 1.10,
1.11 goocanvasitemmodel.h, 1.8, 1.9
- Next message: [cairo-commit] goocanvas/demo demo.c,1.19,1.20
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cairo-commit
mailing list