~ubuntu-branches/ubuntu/trusty/goocanvas/trusty-proposed

« back to all changes in this revision

Viewing changes to src/goocanvasgroup.c

  • Committer: Bazaar Package Importer
  • Author(s): Jose Carlos Garcia Sogo
  • Date: 2007-05-14 22:49:11 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070514224911-vyv39khpicv46oe2
Tags: 0.8-2
Link gtk-doc to /usr/share/doc/libgoocanvas-dev (Closes: #423410)

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include "goocanvasatk.h"
42
42
 
43
43
 
 
44
static void goo_canvas_group_dispose      (GObject            *object);
44
45
static void goo_canvas_group_finalize     (GObject            *object);
45
46
static void canvas_item_interface_init    (GooCanvasItemIface *iface);
46
47
 
55
56
{
56
57
  GObjectClass *gobject_class = (GObjectClass*) klass;
57
58
 
 
59
  gobject_class->dispose  = goo_canvas_group_dispose;
58
60
  gobject_class->finalize = goo_canvas_group_finalize;
59
61
 
60
62
  /* Register our accessible factory, but only if accessibility is enabled. */
114
116
 
115
117
 
116
118
static void
 
119
goo_canvas_group_dispose (GObject *object)
 
120
{
 
121
  GooCanvasGroup *group = (GooCanvasGroup*) object;
 
122
  gint i;
 
123
 
 
124
  /* Unref all the items in the group. */
 
125
  for (i = 0; i < group->items->len; i++)
 
126
    {
 
127
      GooCanvasItem *item = group->items->pdata[i];
 
128
      goo_canvas_item_set_parent (item, NULL);
 
129
      g_object_unref (item);
 
130
    }
 
131
 
 
132
  g_ptr_array_set_size (group->items, 0);
 
133
 
 
134
  G_OBJECT_CLASS (goo_canvas_group_parent_class)->dispose (object);
 
135
}
 
136
 
 
137
 
 
138
static void
117
139
goo_canvas_group_finalize (GObject *object)
118
140
{
119
141
  GooCanvasGroup *group = (GooCanvasGroup*) object;
120
 
  gint i;
121
 
 
122
 
  /* Unref all the items in the group. */
123
 
  for (i = 0; i < group->items->len; i++)
124
 
    {
125
 
      GooCanvasItem *item = group->items->pdata[i];
126
 
      goo_canvas_item_set_parent (item, NULL);
127
 
      g_object_unref (item);
128
 
    }
129
142
 
130
143
  g_ptr_array_free (group->items, TRUE);
131
144
 
393
406
}
394
407
 
395
408
 
396
 
static GooCanvasItem*
397
 
goo_canvas_group_get_item_at (GooCanvasItem  *item,
398
 
                              gdouble         x,
399
 
                              gdouble         y,
400
 
                              cairo_t        *cr,
401
 
                              gboolean        is_pointer_event,
402
 
                              gboolean        parent_visible)
 
409
static GList*
 
410
goo_canvas_group_get_items_at (GooCanvasItem  *item,
 
411
                               gdouble         x,
 
412
                               gdouble         y,
 
413
                               cairo_t        *cr,
 
414
                               gboolean        is_pointer_event,
 
415
                               gboolean        parent_visible,
 
416
                               GList          *found_items)
403
417
{
404
418
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
405
419
  GooCanvasItemSimpleData *simple_data = simple->simple_data;
406
420
  GooCanvasGroup *group = (GooCanvasGroup*) item;
407
 
  GooCanvasItem *found_item = NULL;
408
421
  gboolean visible = parent_visible;
409
422
  int i;
410
423
 
411
424
  if (simple->need_update)
412
425
    goo_canvas_item_ensure_updated (item);
413
426
 
 
427
  /* Skip the item if the point isn't in the item's bounds. */
 
428
  if (simple->bounds.x1 > x || simple->bounds.x2 < x
 
429
      || simple->bounds.y1 > y || simple->bounds.y2 < y)
 
430
    return found_items;
 
431
 
414
432
  if (simple_data->visibility <= GOO_CANVAS_ITEM_INVISIBLE
415
433
      || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
416
434
          && simple->canvas->scale < simple_data->visibility_threshold))
421
439
      && (simple_data->pointer_events == GOO_CANVAS_EVENTS_NONE
422
440
          || ((simple_data->pointer_events & GOO_CANVAS_EVENTS_VISIBLE_MASK)
423
441
              && !visible)))
424
 
    return NULL;
 
442
    return found_items;
425
443
 
426
 
  /* Step down from the top item to the bottom in the stack/layer, and return
427
 
     the first item found that contains the given point. */
428
444
  cairo_save (cr);
429
445
  if (simple_data->transform)
430
446
    cairo_transform (cr, simple_data->transform);
431
447
 
432
 
  for (i = group->items->len - 1; i >= 0; i--)
 
448
  /* If the group has a clip path, check if the point is inside it. */
 
449
  if (simple_data->clip_path_commands)
 
450
    {
 
451
      double user_x = x, user_y = y;
 
452
 
 
453
      cairo_device_to_user (cr, &user_x, &user_y);
 
454
      goo_canvas_create_path (simple_data->clip_path_commands, cr);
 
455
      cairo_set_fill_rule (cr, simple_data->clip_fill_rule);
 
456
      if (!cairo_in_fill (cr, user_x, user_y))
 
457
        {
 
458
          cairo_restore (cr);
 
459
          return found_items;
 
460
        }
 
461
    }
 
462
 
 
463
  /* Step up from the bottom of the children to the top, adding any items
 
464
     found to the start of the list. */
 
465
  for (i = 0; i < group->items->len; i++)
433
466
    {
434
467
      GooCanvasItem *child = group->items->pdata[i];
435
468
 
436
 
      found_item = goo_canvas_item_get_item_at (child, x, y, cr,
437
 
                                                is_pointer_event, visible);
438
 
      if (found_item)
439
 
        break;
 
469
      found_items = goo_canvas_item_get_items_at (child, x, y, cr,
 
470
                                                  is_pointer_event, visible,
 
471
                                                  found_items);
440
472
    }
441
473
  cairo_restore (cr);
442
474
 
443
 
  return found_item;
 
475
  return found_items;
444
476
}
445
477
 
446
478
 
447
479
static void
448
 
goo_canvas_group_paint (GooCanvasItem     *item,
449
 
                        cairo_t           *cr,
450
 
                        GooCanvasBounds   *bounds,
451
 
                        gdouble            scale)
 
480
goo_canvas_group_paint (GooCanvasItem         *item,
 
481
                        cairo_t               *cr,
 
482
                        const GooCanvasBounds *bounds,
 
483
                        gdouble                scale)
452
484
{
453
485
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
454
486
  GooCanvasItemSimpleData *simple_data = simple->simple_data;
455
487
  GooCanvasGroup *group = (GooCanvasGroup*) item;
456
488
  gint i;
457
489
 
 
490
  /* Skip the item if the bounds don't intersect the expose rectangle. */
 
491
  if (simple->bounds.x1 > bounds->x2 || simple->bounds.x2 < bounds->x1
 
492
      || simple->bounds.y1 > bounds->y2 || simple->bounds.y2 < bounds->y1)
 
493
    return;
 
494
 
458
495
  /* Check if the item should be visible. */
459
496
  if (simple_data->visibility <= GOO_CANVAS_ITEM_INVISIBLE
460
497
      || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
466
503
  if (simple_data->transform)
467
504
    cairo_transform (cr, simple_data->transform);
468
505
 
 
506
  /* Clip with the group's clip path, if it is set. */
 
507
  if (simple_data->clip_path_commands)
 
508
    {
 
509
      goo_canvas_create_path (simple_data->clip_path_commands, cr);
 
510
      cairo_set_fill_rule (cr, simple_data->clip_fill_rule);
 
511
      cairo_clip (cr);
 
512
    }
 
513
 
469
514
  for (i = 0; i < group->items->len; i++)
470
515
    {
471
516
      GooCanvasItem *child = group->items->pdata[i];
487
532
  iface->move_child     = goo_canvas_group_move_child;
488
533
  iface->remove_child   = goo_canvas_group_remove_child;
489
534
 
490
 
  iface->get_item_at    = goo_canvas_group_get_item_at;
 
535
  iface->get_items_at   = goo_canvas_group_get_items_at;
491
536
  iface->update         = goo_canvas_group_update;
492
537
  iface->paint          = goo_canvas_group_paint;
493
538
 
525
570
 * (See goo_canvas_get_item() and #GooCanvas::item-created.)
526
571
 */
527
572
static void item_model_interface_init (GooCanvasItemModelIface *iface);
 
573
static void goo_canvas_group_model_dispose      (GObject            *object);
528
574
static void goo_canvas_group_model_finalize     (GObject            *object);
529
575
 
530
576
G_DEFINE_TYPE_WITH_CODE (GooCanvasGroupModel, goo_canvas_group_model,
538
584
{
539
585
  GObjectClass *gobject_class = (GObjectClass*) klass;
540
586
 
 
587
  gobject_class->dispose  = goo_canvas_group_model_dispose;
541
588
  gobject_class->finalize = goo_canvas_group_model_finalize;
542
589
}
543
590
 
589
636
 
590
637
 
591
638
static void
592
 
goo_canvas_group_model_finalize (GObject *object)
 
639
goo_canvas_group_model_dispose (GObject *object)
593
640
{
594
641
  GooCanvasGroupModel *gmodel = (GooCanvasGroupModel*) object;
595
642
  gint i;
602
649
      g_object_unref (child);
603
650
    }
604
651
 
 
652
  g_ptr_array_set_size (gmodel->children, 0);
 
653
 
 
654
  G_OBJECT_CLASS (goo_canvas_group_model_parent_class)->dispose (object);
 
655
}
 
656
 
 
657
 
 
658
static void
 
659
goo_canvas_group_model_finalize (GObject *object)
 
660
{
 
661
  GooCanvasGroupModel *gmodel = (GooCanvasGroupModel*) object;
 
662
 
605
663
  g_ptr_array_free (gmodel->children, TRUE);
606
664
 
607
665
  G_OBJECT_CLASS (goo_canvas_group_model_parent_class)->finalize (object);