Re: is_item_at



On Mon, May 23, 2011 at 2:01 PM, Damon Chaplin
<damon karuna eclipse co uk> wrote:
> On Mon, 2011-05-23 at 12:05 +0200, control H wrote:
>> dear list,
>>
>> I have made a line-item subclass of GOO_TYPE_CANVAS_ITEM_SIMPLE. This
>> subclass is (so far) only drawing 1 line. I overrule the is_item_at
>> function:
>>
>> static gboolean
>> goo_line_item_is_item_at (GooCanvasItemSimple *simple,
>>                           gdouble              x,
>>                           gdouble              y,
>>                           cairo_t             *cr,
>>                           gboolean             is_pointer_event)
>> {
>>   GooLineItem *line=(GooLineItem*)simple;
>>   gboolean r,r2;
>>   GooCanvasPointerEvents pointer_events = GOO_CANVAS_EVENTS_ALL;
>>   gdouble width;
>>
>>   g_object_get (G_OBJECT(line),"line-width", &width,NULL);
>>
>>   cairo_move_to(cr,0,0);
>>   cairo_line_to(cr,line->dx,line->dy);
>>   cairo_set_line_width(cr,width+4.0);
>>   cairo_set_source_rgb(cr,1,0,0);
>>
>>   r2=goo_canvas_item_simple_check_in_path(simple,x,y,cr,pointer_events);
>>   r=cairo_in_stroke (cr, x, y);
>>   printf(", r: %d, r2: %d\n",r,r2);
>>
>>   return r;
>> }
>>
>> struct _GooLineItem
>> {
>>   GooCanvasItemSimple parent_object;
>>
>>   gdouble dx,dy;
>>   gboolean dragging;
>> };
>>
>> When I put some goolineitem objects on the canvas, the
>> goo_line_item_is_item_at() returns only seldom TRUE. Both r and r2 are
>> FALSE when they should be TRUE. What I am doing wrong?
>>
>> I use gtk 3.0.2 and goocanvas 2.0.0.
>>
>> notes:
>> * I use line-width + 4.0 to make it easier to pick up thin lines.
>> * I want to use cairo_in_stroke() instead of
>> goo_canvas_item_simple_check_in_path() so that dashed lines can be
>> picked up anywhere
>
> The code looks OK. Are you using any transformation matrices anywhere?
> Are you using very large coordinates?
>
> Also check that the x & y coordinates look reasonable compared to the
> line's coordinates.
>
> Damon

I'm not using large coordinates. The x&y coordinates look very reasonable.
The only place where I'm using a transformation matrix (I think) is in
the constructor:

goo_line_item_new (GooCanvasItem      *parent,
		   double x, double y,
		   gdouble dx,
		   gdouble dy,
		   ...)
{
  GooCanvasItem *item;
  GooLineItem *line_item;
  const char *first_property;
  va_list var_args;

  item = g_object_new (GOO_TYPE_LINE_ITEM, NULL);

  line_item = (GooLineItem*) item;
  line_item->dx = dx;
  line_item->dy = dy;

  goo_canvas_item_translate(item,x,y);

  va_start (var_args, dy);
  first_property = va_arg (var_args, char*);
  if (first_property)
    g_object_set_valist ((GObject*) item, first_property, var_args);
  va_end (var_args);

  if (parent)
    {
      goo_canvas_item_add_child (parent, item, -1);
      g_object_unref (item);
    }

  g_object_set(item,"can-focus", TRUE,NULL);

  return item;
}

Example line showing problems:

goo_line_item_new (root, 50,50,140, 30,
			     "stroke-color", "blue",
			     "line-width", 3.0,
			     NULL);

In addition it seems that the line-width + 4.0 in the is_item_at()
code doesn't seem to have any influence.


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