Re: gnome-canvas search item set with bounding box



Lauris Kaplinski wrote:

> I see 4 problems, which are not easily addressed
> - there seem (at least last time) not to be clear consensus, if bounds
> should be in item or world coordinates
> - last time I checked, bounds method was deprecated anyway
> - You have to be sure, update is not pending, as bounds will be correct
> only after updating
> - bounds should return sufficent, not exact bounding box, which may be
> confusing
> Anyway, instead of using _get bounds method you can use item bounding box
> stored in item object:
> item->x1 etc.
> These too are (almost) correct after updating. To make sure, update is not
> pending, you can check canvas->need_update flag. But probably canvas does
> not like invoking (as opposed to requesting) update from user program.
> request_update simply sets flag and guarantees, that
> gnome_canvas_item_invoke_update (root) will be called during canvas idle
> loop,

I see.
I rewrite that.

/**
 * gnome_canvas_get_items_at:
 * @canvas: A canvas.
 * @x1: X1 position in world coordinates.
 * @y1: Y1 position in world coordinates.
 * @x2: X2 position in world coordinates.
 * @y2: Y2 position in world coordinates.
 *
 * Looks for the item sets that is in bounding box, which must be
 * specified in world coordinates.
 *
 * Return value: item list;
 **/

GList* gnome_canvas_get_items_at(GnomeCanvas *canvas, double x1, double
y1,
double x2, double y2)
{
  GList* ret = (GList*)NULL;
  GnomeCanvasGroup * group;
  GList *node;
  GnomeCanvasItem* item;

  g_return_val_if_fail (canvas != NULL, (GList*)NULL);
  g_return_val_if_fail (GNOME_IS_CANVAS (canvas),(GList*)NULL);

  group = gnome_canvas_root (canvas);
  if (canvas->need_update) {
    double affine[6];
    art_affine_identity (affine);
    gnome_canvas_item_invoke_update (canvas->root, affine, NULL, 0);
    canvas->need_update = FALSE;
  }
  for (node = group->item_list; node; node = node->next){
    item = (GnomeCanvasItem*)node->data;
    if ((x1 <= item->x1)&&(item->x1 <= x2)&&(x1 <= item->x2)&&(item->x2
<=
x2)&&
 (y1 <= item->y1)&&(item->y1 <= y2)&&(y1 <= item->y2)&&(item->y2 <=
y2)){
      if (item->object.flags | GNOME_CANVAS_ITEM_VISIBLE) {
 ret = g_list_append(ret,item);
      }
    }
  }
  return ret;
}

##########################################
#NEC Informatec Systems
#Advanced Technical System 1st
#TANGE Toshio


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