412
433
return GTK_WIDGET (g_object_new (GOO_TYPE_CANVAS, NULL));
417
goo_canvas_finalize (GObject *object)
437
goo_canvas_dispose (GObject *object)
419
439
GooCanvas *canvas = (GooCanvas*) object;
441
if (canvas->model_to_item)
443
g_hash_table_destroy (canvas->model_to_item);
444
canvas->model_to_item = NULL;
421
447
if (canvas->root_item)
422
g_object_unref (canvas->root_item);
449
g_object_unref (canvas->root_item);
450
canvas->root_item = NULL;
424
453
if (canvas->root_item_model)
425
g_object_unref (canvas->root_item_model);
455
g_object_unref (canvas->root_item_model);
456
canvas->root_item_model = NULL;
427
459
if (canvas->idle_id)
428
g_source_remove (canvas->idle_id);
461
g_source_remove (canvas->idle_id);
430
465
/* Release any references we hold to items. */
431
466
set_item_pointer (&canvas->pointer_item, NULL);
587
650
canvas->resolution_y = g_value_get_double (value);
588
651
need_reconfigure = TRUE;
653
case PROP_BACKGROUND_COLOR:
654
if (!g_value_get_string (value))
655
gtk_widget_modify_base ((GtkWidget*) canvas, GTK_STATE_NORMAL, NULL);
656
else if (gdk_color_parse (g_value_get_string (value), &color))
657
gtk_widget_modify_base ((GtkWidget*) canvas, GTK_STATE_NORMAL, &color);
659
g_warning ("Unknown color: %s", g_value_get_string (value));
661
case PROP_BACKGROUND_COLOR_RGB:
662
rgb = g_value_get_uint (value);
663
color.red = ((rgb >> 16) & 0xFF) * 257;
664
color.green = ((rgb >> 8) & 0xFF) * 257;
665
color.blue = ((rgb) & 0xFF) * 257;
666
gtk_widget_modify_base ((GtkWidget*) canvas, GTK_STATE_NORMAL, &color);
592
670
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
782
866
gboolean is_pointer_event)
785
GooCanvasItem *found;
787
/* If no canvas model is set, just return NULL. */
788
if (!canvas->root_item)
791
cr = goo_canvas_create_cairo (canvas);
792
found = goo_canvas_item_get_item_at (canvas->root_item, x, y, cr,
793
is_pointer_event, TRUE);
869
GooCanvasItem *result = NULL;
872
g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
874
/* If no root item is set, just return NULL. */
875
if (!canvas->root_item)
878
cr = goo_canvas_create_cairo_context (canvas);
879
list = goo_canvas_item_get_items_at (canvas->root_item, x, y, cr,
880
is_pointer_event, TRUE, NULL);
883
/* We just return the top item in the list. */
894
* goo_canvas_get_items_at:
895
* @canvas: a #GooCanvas.
896
* @x: the x coordinate of the point.
897
* @y: the y coordinate of the point
898
* @is_pointer_event: %TRUE if the "pointer-events" property of
899
* items should be used to determine which parts of the item are tested.
901
* Gets all items at the given point.
903
* Returns: a list of items found at the given point, with the top item at
904
* the start of the list, or %NULL if no items were found. The list must be
905
* freed with g_list_free().
908
goo_canvas_get_items_at (GooCanvas *canvas,
911
gboolean is_pointer_event)
916
g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
918
/* If no root item is set, just return NULL. */
919
if (!canvas->root_item)
922
cr = goo_canvas_create_cairo_context (canvas);
923
result = goo_canvas_item_get_items_at (canvas->root_item, x, y, cr,
924
is_pointer_event, TRUE, NULL);
932
goo_canvas_get_items_in_area_recurse (GooCanvas *canvas,
934
const GooCanvasBounds *area,
935
gboolean inside_area,
936
gboolean allow_overlaps,
937
gboolean include_containers,
940
GooCanvasBounds bounds;
941
gboolean completely_inside = FALSE, completely_outside = FALSE;
942
gboolean is_container, add_item = FALSE;
945
/* First check the item/container itself. */
946
goo_canvas_item_get_bounds (item, &bounds);
948
is_container = goo_canvas_item_is_container (item);
950
if (bounds.x1 >= area->x1 && bounds.x2 <= area->x2
951
&& bounds.y1 >= area->y1 && bounds.y2 <= area->y2)
952
completely_inside = TRUE;
954
if (bounds.x1 > area->x2 || bounds.x2 < area->x1
955
|| bounds.y1 > area->y2 || bounds.y2 < area->y1)
956
completely_outside = TRUE;
960
if (completely_inside
961
|| (allow_overlaps && !completely_outside))
966
if (completely_outside
967
|| (allow_overlaps && !completely_inside))
971
if (add_item && (!is_container || include_containers))
972
found_items = g_list_prepend (found_items, item);
974
/* Now check any children, if appropriate. */
975
if ((inside_area && !completely_outside)
976
|| (!inside_area && !completely_inside))
978
n_children = goo_canvas_item_get_n_children (item);
979
for (i = 0; i < n_children; i++)
981
GooCanvasItem *child = goo_canvas_item_get_child (item, i);
982
found_items = goo_canvas_get_items_in_area_recurse (canvas, child,
996
* goo_canvas_get_items_in_area:
997
* @canvas: a #GooCanvas.
998
* @area: the area to compare with each item's bounds.
999
* @inside_area: %TRUE if items inside @area should be returned, or %FALSE if
1000
* items outside @area should be returned.
1001
* @allow_overlaps: %TRUE if items which are partly inside and partly outside
1002
* should be returned.
1003
* @include_containers: %TRUE if containers should be checked as well as
1006
* Gets a list of items inside or outside a given area.
1008
* Returns: a list of items in the given area, or %NULL if no items are found.
1009
* The list should be freed with g_list_free().
1012
goo_canvas_get_items_in_area (GooCanvas *canvas,
1013
const GooCanvasBounds *area,
1014
gboolean inside_area,
1015
gboolean allow_overlaps,
1016
gboolean include_containers)
1018
g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
1020
/* If no root item is set, just return NULL. */
1021
if (!canvas->root_item)
1024
return goo_canvas_get_items_in_area_recurse (canvas, canvas->root_item,
1027
include_containers, NULL);
1817
2062
* Renders all or part of a canvas to the given cairo context.
1820
goo_canvas_render (GooCanvas *canvas,
1822
GooCanvasBounds *bounds,
2065
goo_canvas_render (GooCanvas *canvas,
2067
const GooCanvasBounds *bounds,
1825
2070
/* Set the default line width based on the current units setting. */
1826
2071
cairo_set_line_width (cr, goo_canvas_get_default_line_width (canvas));
1829
goo_canvas_item_paint (canvas->root_item, cr, bounds, scale);
2075
/* Clip to the given bounds. */
2076
cairo_new_path (cr);
2077
cairo_move_to (cr, bounds->x1, bounds->y1);
2078
cairo_line_to (cr, bounds->x2, bounds->y1);
2079
cairo_line_to (cr, bounds->x2, bounds->y2);
2080
cairo_line_to (cr, bounds->x1, bounds->y2);
2081
cairo_close_path (cr);
2084
goo_canvas_item_paint (canvas->root_item, cr, bounds, scale);
1831
goo_canvas_item_paint (canvas->root_item, cr, &canvas->bounds, scale);
2088
goo_canvas_item_paint (canvas->root_item, cr, &canvas->bounds, scale);