Implemented the ::point() method. We do a simple containment test instead

1999-11-02  Federico Mena Quintero  <federico@redhat.com>

	* src/gnome-canvas-pixbuf.c (gnome_canvas_pixbuf_point):
	Implemented the ::point() method.  We do a simple containment test
	instead of a full distance calculation since the canvas is going
	to change to that scheme, anyways.
This commit is contained in:
Federico Mena Quintero 1999-11-02 23:11:09 +00:00 committed by Arturo Espinosa
parent d611593ffd
commit cacae33871
2 changed files with 65 additions and 30 deletions

View File

@ -1,4 +1,12 @@
1999-11-02 Federico Mena Quintero <federico@redhat.com>
* src/gnome-canvas-pixbuf.c (gnome_canvas_pixbuf_point):
Implemented the ::point() method. We do a simple containment test
instead of a full distance calculation since the canvas is going
to change to that scheme, anyways.
1999-11-02 Elliot Lee <sopwith@redhat.com>
* src/testpixbuf.c: Allow using $TBF_READLEN to specify the size of the chunks
that are read from the input file.

View File

@ -22,6 +22,8 @@
#include <config.h>
#include <math.h>
#include <libgnomeui/gnome-canvas.h>
#include <libgnomeui/gnome-canvas-util.h>
#include "gdk-pixbuf.h"
#include "gnome-canvas-pixbuf.h"
#include "libart_lgpl/art_rgb_pixbuf_affine.h"
@ -76,11 +78,11 @@ static void gnome_canvas_pixbuf_update (GnomeCanvasItem *item, double *affine,
ArtSVP *clip_path, int flags);
static void gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height);
static void gnome_canvas_pixbuf_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf);
static double gnome_canvas_pixbuf_point (GnomeCanvasItem *item, double x, double y, int cx, int cy,
GnomeCanvasItem **actual_item);
static void gnome_canvas_pixbuf_bounds (GnomeCanvasItem *item,
double *x1, double *y1, double *x2, double *y2);
static void gnome_canvas_pixbuf_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf);
static GnomeCanvasItemClass *parent_class;
@ -152,9 +154,9 @@ gnome_canvas_pixbuf_class_init (GnomeCanvasPixbufClass *class)
item_class->update = gnome_canvas_pixbuf_update;
item_class->draw = gnome_canvas_pixbuf_draw;
item_class->render = gnome_canvas_pixbuf_render;
item_class->point = gnome_canvas_pixbuf_point;
item_class->bounds = gnome_canvas_pixbuf_bounds;
item_class->render = gnome_canvas_pixbuf_render;
}
/* Object initialization function for the pixbuf canvas item */
@ -674,34 +676,6 @@ transform_pixbuf (guchar *dest, int x, int y, int width, int height, int rowstri
}
}
/* Render for the pixbuf canvas item */
static void
gnome_canvas_pixbuf_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf)
{
GnomeCanvasPixbuf *gcp;
PixbufPrivate *priv;
double i2c[6], render_affine[6];
gcp = GNOME_CANVAS_PIXBUF (item);
priv = gcp->priv;
if (!priv->pixbuf)
return;
gnome_canvas_item_i2c_affine (item, i2c);
compute_render_affine (gcp, render_affine, i2c);
gnome_canvas_buf_ensure_buf (buf);
art_rgb_pixbuf_affine (buf->buf,
buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1,
buf->buf_rowstride,
priv->pixbuf->art_pixbuf,
render_affine,
ART_FILTER_NEAREST, NULL);
buf->is_bg = 0;
}
/* Draw handler for the pixbuf canvas item */
static void
gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
@ -742,6 +716,34 @@ gnome_canvas_pixbuf_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
g_free (buf);
}
/* Render handler for the pixbuf canvas item */
static void
gnome_canvas_pixbuf_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf)
{
GnomeCanvasPixbuf *gcp;
PixbufPrivate *priv;
double i2c[6], render_affine[6];
gcp = GNOME_CANVAS_PIXBUF (item);
priv = gcp->priv;
if (!priv->pixbuf)
return;
gnome_canvas_item_i2c_affine (item, i2c);
compute_render_affine (gcp, render_affine, i2c);
gnome_canvas_buf_ensure_buf (buf);
art_rgb_pixbuf_affine (buf->buf,
buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1,
buf->buf_rowstride,
priv->pixbuf->art_pixbuf,
render_affine,
ART_FILTER_NEAREST, NULL);
buf->is_bg = 0;
}
/* Point handler for the pixbuf canvas item */
@ -753,12 +755,23 @@ gnome_canvas_pixbuf_point (GnomeCanvasItem *item, double x, double y, int cx, in
PixbufPrivate *priv;
double i2c[6], render_affine[6], inv[6];
ArtPoint c, p;
int px, py;
double no_hit;
ArtPixBuf *apb;
guchar *src;
gcp = GNOME_CANVAS_PIXBUF (item);
priv = gcp->priv;
*actual_item = item;
no_hit = item->canvas->pixels_per_unit * 2 + 10;
if (!priv->pixbuf)
return no_hit;
apb = priv->pixbuf->art_pixbuf;
gnome_canvas_item_i2c_affine (item, i2c);
compute_render_affine (gcp, render_affine, i2c);
art_affine_invert (inv, render_affine);
@ -766,7 +779,21 @@ gnome_canvas_pixbuf_point (GnomeCanvasItem *item, double x, double y, int cx, in
c.x = cx;
c.y = cy;
art_affine_point (&p, &c, inv);
px = p.x;
py = p.y;
if (px < 0 || px >= apb->width || py < 0 || py >= apb->height)
return no_hit;
if (!apb->has_alpha)
return TRUE;
src = apb->pixels + py * apb->rowstride + px * apb->n_channels;
if (src[3] < 128)
return no_hit;
else
return 0.0;
}