2005-09-25 14:42:24 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
2005-09-25 18:26:56 -04:00
|
|
|
#include <libgnomecanvas/libgnomecanvas.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include "canvas-simpleline.h"
|
|
|
|
#include "rgb_macros.h"
|
2005-11-26 03:14:35 -05:00
|
|
|
#include "gettext.h"
|
|
|
|
#define _(Text) dgettext (PACKAGE,Text)
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
enum {
|
2005-11-26 03:14:35 -05:00
|
|
|
PROP_0,
|
|
|
|
PROP_X1,
|
|
|
|
PROP_Y1,
|
|
|
|
PROP_X2,
|
|
|
|
PROP_Y2,
|
|
|
|
PROP_COLOR_RGBA
|
2005-09-25 14:42:24 -04:00
|
|
|
};
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
static void gnome_canvas_simpleline_class_init (GnomeCanvasSimpleLineClass *class);
|
|
|
|
|
|
|
|
static void gnome_canvas_simpleline_init (GnomeCanvasSimpleLine *simpleline);
|
|
|
|
|
|
|
|
static void gnome_canvas_simpleline_destroy (GtkObject *object);
|
|
|
|
|
2005-11-26 03:14:35 -05:00
|
|
|
static void gnome_canvas_simpleline_set_property (GObject *object,
|
2005-11-26 05:28:55 -05:00
|
|
|
guint prop_id,
|
2005-11-26 03:14:35 -05:00
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gnome_canvas_simpleline_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
static void gnome_canvas_simpleline_update (GnomeCanvasItem *item,
|
|
|
|
double *affine,
|
|
|
|
ArtSVP *clip_path,
|
|
|
|
int flags);
|
|
|
|
|
|
|
|
static void gnome_canvas_simpleline_bounds (GnomeCanvasItem *item,
|
|
|
|
double *x1,
|
|
|
|
double *y1,
|
|
|
|
double *x2,
|
|
|
|
double *y2);
|
|
|
|
|
|
|
|
static double gnome_canvas_simpleline_point (GnomeCanvasItem *item,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
int cx,
|
|
|
|
int cy,
|
|
|
|
GnomeCanvasItem **actual_item);
|
|
|
|
|
|
|
|
static void gnome_canvas_simpleline_render (GnomeCanvasItem *item,
|
|
|
|
GnomeCanvasBuf *buf);
|
|
|
|
|
|
|
|
static void gnome_canvas_simpleline_draw (GnomeCanvasItem *item,
|
|
|
|
GdkDrawable *drawable,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
int h);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
static GnomeCanvasItemClass *parent_class;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
GType
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_get_type (void)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-11-26 05:28:55 -05:00
|
|
|
static GType simpleline_type;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (!simpleline_type) {
|
2005-11-26 05:28:55 -05:00
|
|
|
static const GTypeInfo object_info = {
|
2005-09-25 18:26:56 -04:00
|
|
|
sizeof (GnomeCanvasSimpleLineClass),
|
2005-11-26 05:28:55 -05:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gnome_canvas_simpleline_class_init,
|
|
|
|
(GClassFinalizeFunc) NULL,
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GnomeCanvasSimpleLine),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gnome_canvas_simpleline_init,
|
|
|
|
NULL /* value_table */
|
2005-09-25 14:42:24 -04:00
|
|
|
};
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
simpleline_type = g_type_register_static (GNOME_TYPE_CANVAS_ITEM, "GnomeCanvasSimpleLine",
|
|
|
|
&object_info, 0);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return simpleline_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_class_init (GnomeCanvasSimpleLineClass *class)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-11-26 05:28:55 -05:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GtkObjectClass *object_class;
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasItemClass *item_class;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
gobject_class = (GObjectClass *) class;
|
|
|
|
object_class = (GtkObjectClass *) class;
|
2005-09-25 18:26:56 -04:00
|
|
|
item_class = (GnomeCanvasItemClass *) class;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
parent_class = g_type_class_peek_parent (class);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
gobject_class->set_property = gnome_canvas_simpleline_set_property;
|
|
|
|
gobject_class->get_property = gnome_canvas_simpleline_get_property;
|
2005-11-26 03:14:35 -05:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-26 03:14:35 -05:00
|
|
|
PROP_X1,
|
|
|
|
g_param_spec_double ("x1",
|
|
|
|
_("x1"),
|
|
|
|
_("x coordinate of upper left corner of rect"),
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-26 03:14:35 -05:00
|
|
|
PROP_Y1,
|
|
|
|
g_param_spec_double ("y1",
|
|
|
|
_("y1"),
|
|
|
|
_("y coordinate of upper left corner of rect "),
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-26 03:14:35 -05:00
|
|
|
PROP_X2,
|
|
|
|
g_param_spec_double ("x2",
|
|
|
|
_("x2"),
|
|
|
|
_("x coordinate of lower right corner of rect"),
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-26 03:14:35 -05:00
|
|
|
PROP_Y2,
|
|
|
|
g_param_spec_double ("y2",
|
|
|
|
_("y2"),
|
|
|
|
_("y coordinate of lower right corner of rect "),
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
|
|
|
G_PARAM_READWRITE));
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-26 03:14:35 -05:00
|
|
|
PROP_COLOR_RGBA,
|
|
|
|
g_param_spec_uint ("color_rgba",
|
|
|
|
_("color rgba"),
|
|
|
|
_("color of line"),
|
|
|
|
0,
|
|
|
|
G_MAXUINT,
|
|
|
|
0,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
object_class->destroy = gnome_canvas_simpleline_destroy;
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
item_class->update = gnome_canvas_simpleline_update;
|
|
|
|
item_class->bounds = gnome_canvas_simpleline_bounds;
|
|
|
|
item_class->point = gnome_canvas_simpleline_point;
|
|
|
|
item_class->render = gnome_canvas_simpleline_render;
|
|
|
|
item_class->draw = gnome_canvas_simpleline_draw;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_init (GnomeCanvasSimpleLine *simpleline)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
simpleline->x1 = 0.0;
|
|
|
|
simpleline->y1 = 0.0;
|
|
|
|
simpleline->x2 = 0.0;
|
|
|
|
simpleline->y2 = 0.0;
|
|
|
|
simpleline->color = RGBA_TO_UINT(98,123,174,241);
|
|
|
|
simpleline->horizontal = TRUE; /* reset in the _update() method */
|
2005-10-10 16:38:53 -04:00
|
|
|
// GTK2FIX
|
|
|
|
// GNOME_CANVAS_ITEM(simpleline)->object.flags |= GNOME_CANVAS_ITEM_NO_AUTO_REDRAW;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
static void
|
|
|
|
gnome_canvas_simpleline_destroy (GtkObject *object)
|
|
|
|
{
|
|
|
|
GnomeCanvasSimpleLine *line;
|
|
|
|
|
|
|
|
g_return_if_fail (object != NULL);
|
2005-11-28 21:46:46 -05:00
|
|
|
g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (object));
|
2005-11-26 05:28:55 -05:00
|
|
|
|
|
|
|
line = GNOME_CANVAS_SIMPLELINE (object);
|
|
|
|
|
|
|
|
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
|
|
|
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_bounds_world (GnomeCanvasItem *item, int* ix1, int* iy1, int* ix2, int* iy2)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
double x1, x2, y1, y2;
|
|
|
|
ArtPoint i1, i2;
|
|
|
|
ArtPoint w1, w2;
|
|
|
|
double i2w[6];
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasSimpleLine *simpleline = GNOME_CANVAS_SIMPLELINE(item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_bounds (item, &x1, &y1, &x2, &y2);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
i1.x = x1;
|
|
|
|
i1.y = y1;
|
|
|
|
i2.x = x2;
|
|
|
|
i2.y = y2;
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_item_i2w_affine (item, i2w);
|
2005-09-25 14:42:24 -04:00
|
|
|
art_affine_point (&w1, &i1, i2w);
|
|
|
|
art_affine_point (&w2, &i2, i2w);
|
|
|
|
|
|
|
|
*ix1 = (int) rint(w1.x);
|
|
|
|
*ix2 = (int) rint(w2.x);
|
|
|
|
*iy1 = (int) rint(w1.y);
|
|
|
|
*iy2 = (int) rint(w2.y);
|
|
|
|
|
|
|
|
/* the update rect has to be of non-zero width and height */
|
|
|
|
|
|
|
|
if (x1 == x2) {
|
|
|
|
simpleline->horizontal = FALSE;
|
|
|
|
*ix2 += 1;
|
|
|
|
} else {
|
|
|
|
simpleline->horizontal = TRUE;
|
|
|
|
*iy2 += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_reset_bounds (GnomeCanvasItem *item)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
int Ix1, Ix2, Iy1, Iy2;
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_bounds_world (item, &Ix1, &Iy1, &Ix2, &Iy2);
|
|
|
|
gnome_canvas_update_bbox (item, Ix1, Iy1, Ix2, Iy2);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CANVAS CALLBACKS
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2005-11-26 03:14:35 -05:00
|
|
|
gnome_canvas_simpleline_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasSimpleLine *simpleline;
|
2005-11-26 03:14:35 -05:00
|
|
|
int update = FALSE;
|
|
|
|
int bounds_changed = FALSE;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (object));
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
simpleline = GNOME_CANVAS_SIMPLELINE (object);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-26 03:14:35 -05:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_X1:
|
|
|
|
if (simpleline->x1 != g_value_get_double (value)) {
|
|
|
|
simpleline->x1 = g_value_get_double (value);
|
|
|
|
bounds_changed = TRUE;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-26 03:14:35 -05:00
|
|
|
case PROP_Y1:
|
|
|
|
if (simpleline->y1 != g_value_get_double (value)) {
|
|
|
|
simpleline->y1 = g_value_get_double (value);
|
|
|
|
bounds_changed = TRUE;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-26 03:14:35 -05:00
|
|
|
case PROP_X2:
|
|
|
|
if (simpleline->x2 != g_value_get_double (value)) {
|
|
|
|
simpleline->x2 = g_value_get_double (value);
|
|
|
|
bounds_changed = TRUE;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-26 03:14:35 -05:00
|
|
|
case PROP_Y2:
|
|
|
|
if (simpleline->y2 != g_value_get_double (value)) {
|
|
|
|
simpleline->y2 = g_value_get_double (value);
|
|
|
|
bounds_changed = TRUE;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
break;
|
2005-11-26 03:14:35 -05:00
|
|
|
|
|
|
|
case PROP_COLOR_RGBA:
|
|
|
|
if (simpleline->color != g_value_get_uint(value)) {
|
|
|
|
simpleline->color = g_value_get_uint(value);
|
2006-01-28 08:33:54 -05:00
|
|
|
UINT_TO_RGBA (simpleline->color, &simpleline->r, &simpleline->g, &simpleline->b, &simpleline->a);
|
2005-11-26 03:14:35 -05:00
|
|
|
update = TRUE;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-11-26 03:14:35 -05:00
|
|
|
if (update || bounds_changed) {
|
|
|
|
gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(object));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-11-26 03:14:35 -05:00
|
|
|
gnome_canvas_simpleline_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-11-26 05:28:55 -05:00
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (object));
|
2005-11-26 03:14:35 -05:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
GnomeCanvasSimpleLine *line = GNOME_CANVAS_SIMPLELINE (object);
|
|
|
|
|
2005-11-26 03:14:35 -05:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_X1:
|
|
|
|
g_value_set_double (value, line->x1);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-26 03:14:35 -05:00
|
|
|
case PROP_X2:
|
|
|
|
g_value_set_double (value, line->x2);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-26 03:14:35 -05:00
|
|
|
case PROP_Y1:
|
|
|
|
g_value_set_double (value, line->y1);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-26 03:14:35 -05:00
|
|
|
case PROP_Y2:
|
|
|
|
g_value_set_double (value, line->y2);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-26 03:14:35 -05:00
|
|
|
case PROP_COLOR_RGBA:
|
|
|
|
g_value_set_uint (value, line->color);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
default:
|
2005-11-26 03:14:35 -05:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasSimpleLine *simpleline;
|
2005-09-25 14:42:24 -04:00
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
simpleline = GNOME_CANVAS_SIMPLELINE (item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (parent_class->update)
|
|
|
|
(* parent_class->update) (item, affine, clip_path, flags);
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_reset_bounds (item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
x = simpleline->x1;
|
|
|
|
y = simpleline->y1;
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_item_i2w (item, &x, &y);
|
|
|
|
gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x, y, &simpleline->bbox_ulx, &simpleline->bbox_uly);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
x = simpleline->x2;
|
|
|
|
y = simpleline->y2;
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_item_i2w (item, &x, &y);
|
|
|
|
gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x, y, &simpleline->bbox_lrx, &simpleline->bbox_lry);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_render (GnomeCanvasItem *item,
|
|
|
|
GnomeCanvasBuf *buf)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasSimpleLine *simpleline;
|
2005-09-25 14:42:24 -04:00
|
|
|
int end, begin;
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
simpleline = GNOME_CANVAS_SIMPLELINE (item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (parent_class->render) {
|
|
|
|
(*parent_class->render) (item, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf->is_bg) {
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_buf_ensure_buf (buf);
|
2005-09-25 14:42:24 -04:00
|
|
|
buf->is_bg = FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-28 08:33:54 -05:00
|
|
|
//begin = MAX(simpleline->bbox_ulx,buf->rect.x0);
|
|
|
|
//end = MIN(simpleline->bbox_lrx,buf->rect.x1);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
begin = simpleline->bbox_ulx;
|
|
|
|
end = simpleline->bbox_lrx;
|
|
|
|
|
|
|
|
if (simpleline->color != 0) {
|
|
|
|
if (simpleline->horizontal) {
|
|
|
|
PAINT_HORIZA(buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a,
|
|
|
|
begin, end, simpleline->bbox_uly);
|
|
|
|
} else {
|
2006-01-28 08:33:54 -05:00
|
|
|
PAINT_VERTA(buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a,
|
2005-09-25 14:42:24 -04:00
|
|
|
begin, simpleline->bbox_uly, simpleline->bbox_lry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_draw (GnomeCanvasItem *item,
|
2005-09-25 14:42:24 -04:00
|
|
|
GdkDrawable *drawable,
|
|
|
|
int x, int y,
|
|
|
|
int width, int height)
|
|
|
|
{
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasSimpleLine *simpleline;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
simpleline = GNOME_CANVAS_SIMPLELINE (item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (parent_class->draw) {
|
|
|
|
(* parent_class->draw) (item, drawable, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf (stderr, "please don't use the CanvasSimpleLine item in a non-aa Canvas\n");
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasSimpleLine *simpleline = GNOME_CANVAS_SIMPLELINE (item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
*x1 = simpleline->x1;
|
|
|
|
*y1 = simpleline->y1;
|
|
|
|
*x2 = simpleline->x2;
|
|
|
|
*y2 = simpleline->y2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasSimpleLine *simpleline;
|
2005-09-25 14:42:24 -04:00
|
|
|
double x1, y1, x2, y2;
|
|
|
|
double dx, dy;
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
simpleline = GNOME_CANVAS_SIMPLELINE (item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
*actual_item = item;
|
|
|
|
|
|
|
|
/* Find the bounds for the rectangle plus its outline width */
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simpleline_bounds (item, &x1, &y1, &x2, &y2);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
/* Is point inside rectangle */
|
|
|
|
|
|
|
|
if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Point is outside rectangle */
|
|
|
|
|
|
|
|
if (x < x1)
|
|
|
|
dx = x1 - x;
|
|
|
|
else if (x > x2)
|
|
|
|
dx = x - x2;
|
|
|
|
else
|
|
|
|
dx = 0.0;
|
|
|
|
|
|
|
|
if (y < y1)
|
|
|
|
dy = y1 - y;
|
|
|
|
else if (y > y2)
|
|
|
|
dy = y - y2;
|
|
|
|
else
|
|
|
|
dy = 0.0;
|
|
|
|
|
|
|
|
return sqrt (dx * dx + dy * dy);
|
|
|
|
}
|