2005-09-25 14:42:24 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
2008-03-17 16:54:03 -04:00
|
|
|
#include <cairo.h>
|
2005-09-25 18:26:56 -04:00
|
|
|
#include <libgnomecanvas/libgnomecanvas.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include "canvas-simplerect.h"
|
|
|
|
#include "rgb_macros.h"
|
2005-11-25 22:14:16 -05:00
|
|
|
#include "gettext.h"
|
|
|
|
#define _(Text) dgettext (PACKAGE,Text)
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
enum {
|
2005-11-25 22:14:16 -05:00
|
|
|
PROP_0,
|
|
|
|
PROP_X1,
|
|
|
|
PROP_Y1,
|
|
|
|
PROP_X2,
|
|
|
|
PROP_Y2,
|
|
|
|
PROP_OUTLINE_PIXELS,
|
|
|
|
PROP_OUTLINE_WHAT,
|
|
|
|
PROP_FILL,
|
|
|
|
PROP_FILL_COLOR_RGBA,
|
|
|
|
PROP_OUTLINE_COLOR_RGBA,
|
|
|
|
PROP_DRAW
|
2005-09-25 14:42:24 -04:00
|
|
|
};
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
static void gnome_canvas_simplerect_class_init (GnomeCanvasSimpleRectClass *class);
|
|
|
|
|
|
|
|
static void gnome_canvas_simplerect_init (GnomeCanvasSimpleRect *simplerect);
|
|
|
|
|
|
|
|
static void gnome_canvas_simplerect_destroy (GtkObject *object);
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
static void gnome_canvas_simplerect_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2005-11-26 05:28:55 -05:00
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
static void gnome_canvas_simplerect_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2005-11-26 05:28:55 -05:00
|
|
|
|
|
|
|
static void gnome_canvas_simplerect_update (GnomeCanvasItem *item,
|
|
|
|
double *affine,
|
|
|
|
ArtSVP *clip_path,
|
|
|
|
int flags);
|
|
|
|
|
|
|
|
static void gnome_canvas_simplerect_bounds (GnomeCanvasItem *item,
|
|
|
|
double *x1,
|
|
|
|
double *y1,
|
|
|
|
double *x2,
|
|
|
|
double *y2);
|
|
|
|
|
|
|
|
static double gnome_canvas_simplerect_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item);
|
|
|
|
|
|
|
|
static void gnome_canvas_simplerect_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf);
|
|
|
|
|
|
|
|
static void gnome_canvas_simplerect_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_simplerect_get_type (void)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-11-26 05:28:55 -05:00
|
|
|
static GType simplerect_type;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (!simplerect_type) {
|
2005-11-26 05:28:55 -05:00
|
|
|
static const GTypeInfo object_info = {
|
2005-09-25 18:26:56 -04:00
|
|
|
sizeof (GnomeCanvasSimpleRectClass),
|
2005-11-26 05:28:55 -05:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gnome_canvas_simplerect_class_init,
|
|
|
|
(GClassFinalizeFunc) NULL,
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GnomeCanvasSimpleRect),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gnome_canvas_simplerect_init,
|
|
|
|
NULL /* value_table */
|
2005-09-25 14:42:24 -04:00
|
|
|
};
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
simplerect_type = g_type_register_static (GNOME_TYPE_CANVAS_ITEM, "GnomeCanvasSimpleRect",
|
|
|
|
&object_info, 0);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return simplerect_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simplerect_class_init (GnomeCanvasSimpleRectClass *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;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-11-28 02:47:14 -05:00
|
|
|
parent_class = g_type_class_peek_parent (class);
|
2005-09-25 18:26:56 -04:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
gobject_class->set_property = gnome_canvas_simplerect_set_property;
|
|
|
|
gobject_class->get_property = gnome_canvas_simplerect_get_property;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-25 22:14:16 -05:00
|
|
|
PROP_X1,
|
|
|
|
g_param_spec_double ("x1",
|
|
|
|
_("x1"),
|
|
|
|
_("x coordinate of upper left corner of rect"),
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
2009-10-14 12:10:01 -04:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-25 22:14:16 -05:00
|
|
|
PROP_Y1,
|
|
|
|
g_param_spec_double ("y1",
|
|
|
|
_("y1"),
|
|
|
|
_("y coordinate of upper left corner of rect "),
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
2009-10-14 12:10:01 -04:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-25 22:14:16 -05:00
|
|
|
PROP_X2,
|
|
|
|
g_param_spec_double ("x2",
|
|
|
|
_("x2"),
|
|
|
|
_("x coordinate of lower right corner of rect"),
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
2009-10-14 12:10:01 -04:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-25 22:14:16 -05:00
|
|
|
PROP_Y2,
|
|
|
|
g_param_spec_double ("y2",
|
|
|
|
_("y2"),
|
|
|
|
_("y coordinate of lower right corner of rect "),
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
2009-10-14 12:10:01 -04:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-25 22:14:16 -05:00
|
|
|
PROP_OUTLINE_PIXELS,
|
|
|
|
g_param_spec_uint ("outline_pixels",
|
|
|
|
_("outline pixels"),
|
|
|
|
_("width in pixels of outline"),
|
|
|
|
0,
|
2005-11-26 03:14:35 -05:00
|
|
|
G_MAXUINT,
|
2005-11-25 22:14:16 -05:00
|
|
|
0,
|
2009-10-14 12:10:01 -04:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-25 22:14:16 -05:00
|
|
|
PROP_OUTLINE_WHAT,
|
|
|
|
g_param_spec_uint ("outline_what",
|
|
|
|
_("outline what"),
|
|
|
|
_("which boundaries to outline (mask)"),
|
|
|
|
0,
|
2005-11-26 03:14:35 -05:00
|
|
|
G_MAXUINT,
|
2005-11-25 22:14:16 -05:00
|
|
|
0,
|
2009-10-14 12:10:01 -04:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-25 22:14:16 -05:00
|
|
|
PROP_FILL,
|
|
|
|
g_param_spec_boolean ("fill",
|
|
|
|
_("fill"),
|
|
|
|
_("fill rectangle"),
|
|
|
|
TRUE,
|
2009-10-14 12:10:01 -04:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-25 22:14:16 -05:00
|
|
|
PROP_DRAW,
|
|
|
|
g_param_spec_boolean ("draw",
|
|
|
|
_("draw"),
|
|
|
|
_("draw rectangle"),
|
|
|
|
TRUE,
|
2009-10-14 12:10:01 -04:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-25 22:14:16 -05:00
|
|
|
PROP_OUTLINE_COLOR_RGBA,
|
|
|
|
g_param_spec_uint ("outline_color_rgba",
|
2005-11-26 03:14:35 -05:00
|
|
|
_("outline color rgba"),
|
|
|
|
_("color of outline"),
|
|
|
|
0,
|
|
|
|
G_MAXUINT,
|
|
|
|
0,
|
2009-10-14 12:10:01 -04:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_object_class_install_property (gobject_class,
|
2005-11-25 22:14:16 -05:00
|
|
|
PROP_FILL_COLOR_RGBA,
|
|
|
|
g_param_spec_uint ("fill_color_rgba",
|
2005-11-26 03:14:35 -05:00
|
|
|
_("fill color rgba"),
|
|
|
|
_("color of fill"),
|
|
|
|
0,
|
|
|
|
G_MAXUINT,
|
|
|
|
0,
|
2009-10-14 12:10:01 -04:00
|
|
|
G_PARAM_READWRITE));
|
2005-11-26 05:28:55 -05:00
|
|
|
|
|
|
|
object_class->destroy = gnome_canvas_simplerect_destroy;
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
item_class->update = gnome_canvas_simplerect_update;
|
2005-11-26 05:28:55 -05:00
|
|
|
item_class->draw = gnome_canvas_simplerect_draw;
|
2005-09-25 18:26:56 -04:00
|
|
|
item_class->bounds = gnome_canvas_simplerect_bounds;
|
|
|
|
item_class->point = gnome_canvas_simplerect_point;
|
|
|
|
item_class->render = gnome_canvas_simplerect_render;
|
2005-11-26 05:28:55 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simplerect_init (GnomeCanvasSimpleRect *simplerect)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
simplerect->x1 = 0.0;
|
|
|
|
simplerect->y1 = 0.0;
|
|
|
|
simplerect->x2 = 0.0;
|
|
|
|
simplerect->y2 = 0.0;
|
|
|
|
simplerect->fill = TRUE;
|
|
|
|
simplerect->draw = TRUE;
|
|
|
|
simplerect->full_draw_on_update = TRUE;
|
|
|
|
simplerect->fill_color = 0;
|
|
|
|
simplerect->outline_color = 0;
|
|
|
|
simplerect->outline_pixels = 1;
|
|
|
|
simplerect->outline_what = 0xf;
|
|
|
|
}
|
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
static void
|
|
|
|
gnome_canvas_simplerect_destroy (GtkObject *object)
|
|
|
|
{
|
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
|
|
|
|
|
|
|
|
/* remember, destroy can be run multiple times! */
|
|
|
|
|
|
|
|
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_simplerect_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
|
|
|
GnomeCanvasSimpleRect *simplerect = GNOME_CANVAS_SIMPLERECT (item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
*x1 = simplerect->x1;
|
|
|
|
*y1 = simplerect->y1;
|
|
|
|
*x2 = simplerect->x2 + 1;
|
|
|
|
*y2 = simplerect->y2 + 1;
|
|
|
|
}
|
|
|
|
|
2007-03-12 17:03:39 -04:00
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simplerect_reset_bounds (GnomeCanvasItem *item)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasSimpleRect* simplerect;
|
2005-09-25 14:42:24 -04:00
|
|
|
double x1, x2, y1, y2;
|
|
|
|
double old_x1, old_x2, old_y1, old_y2;
|
2007-03-12 17:03:39 -04:00
|
|
|
ArtDRect unionrect, old, new;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2007-03-12 17:03:39 -04:00
|
|
|
old_x1 = item->x1;
|
|
|
|
old_y1 = item->y1;
|
|
|
|
old_x2 = item->x2;
|
|
|
|
old_y2 = item->y2;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simplerect_bounds (item, &x1, &y1, &x2, &y2);
|
|
|
|
gnome_canvas_item_i2w (item, &x1, &y1);
|
|
|
|
gnome_canvas_item_i2w (item, &x2, &y2);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
item->x1 = x1;
|
|
|
|
item->y1 = y1;
|
|
|
|
item->x2 = x2;
|
|
|
|
item->y2 = y2;
|
|
|
|
|
|
|
|
/* now compute bounding box in canvas units */
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
simplerect = GNOME_CANVAS_SIMPLERECT (item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x1, y1, &simplerect->bbox_ulx, &simplerect->bbox_uly);
|
|
|
|
gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x2, y2, &simplerect->bbox_lrx, &simplerect->bbox_lry);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2008-03-17 16:54:03 -04:00
|
|
|
/* now queue redraws for changed areas */
|
2007-03-12 17:03:39 -04:00
|
|
|
|
|
|
|
if (item->x1 == old_x1 && item->x2 == old_x2) {
|
|
|
|
|
|
|
|
/* no change in x-axis position */
|
|
|
|
|
|
|
|
if (item->y1 == old_y1) {
|
|
|
|
/* top didn't change, so just draw bottom */
|
|
|
|
|
2007-03-12 18:19:56 -04:00
|
|
|
double start_y = MIN (item->y2, old_y2);
|
|
|
|
double end_y = MAX (item->y2, old_y2);
|
2007-03-12 17:03:39 -04:00
|
|
|
|
2007-03-18 12:45:43 -04:00
|
|
|
gnome_canvas_request_redraw (item->canvas, item->x1, start_y - 0.5, item->x2, end_y + 1.5);
|
2007-03-12 17:03:39 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
} else if (item->y2 == old_y2) {
|
|
|
|
|
|
|
|
/* bottom didn't change, just draw top */
|
|
|
|
|
2007-03-12 18:19:56 -04:00
|
|
|
double start_y = MIN (item->y1, old_y1);
|
|
|
|
double end_y = MAX (item->y1, old_y1);
|
2007-03-12 17:03:39 -04:00
|
|
|
|
2007-03-18 12:45:43 -04:00
|
|
|
gnome_canvas_request_redraw (item->canvas, item->x1, start_y - 0.5, item->x2, end_y + 1.5);
|
2007-03-12 17:03:39 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (item->y1 == old_y1 && item->y2 == old_y2) {
|
|
|
|
|
|
|
|
/* no change in y-axis position */
|
|
|
|
|
|
|
|
if (item->x1 == old_x1) {
|
|
|
|
/* start didn't change, so just draw at the end */
|
|
|
|
|
2007-03-12 18:19:56 -04:00
|
|
|
double start_x = MIN (item->x2, old_x2);
|
|
|
|
double end_x = MAX (item->x2, old_x2);
|
2007-03-12 17:03:39 -04:00
|
|
|
|
2011-04-18 14:45:25 -04:00
|
|
|
gnome_canvas_request_redraw (item->canvas, start_x - 0.5, item->y1, end_x + 1.5, item->y2 + 0.5);
|
2007-03-12 17:03:39 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
} else if (item->x2 == old_x2) {
|
|
|
|
|
|
|
|
/* end didn't change, so just draw at the start */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-03-12 18:19:56 -04:00
|
|
|
double start_x = MIN (item->x1, old_x1);
|
|
|
|
double end_x = MAX (item->x1, old_x1);
|
2007-03-12 17:03:39 -04:00
|
|
|
|
2007-03-18 12:45:43 -04:00
|
|
|
gnome_canvas_request_redraw (item->canvas, start_x - 0.5, item->y1, end_x + 1.5, item->y2 + 0.5);
|
2007-03-12 17:03:39 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2007-03-12 17:03:39 -04:00
|
|
|
|
|
|
|
new.x0 = x1;
|
|
|
|
new.y0 = y1;
|
|
|
|
new.x1 = x2;
|
|
|
|
new.y1 = y2;
|
|
|
|
|
|
|
|
old.x0 = old_x1;
|
|
|
|
old.y0 = old_y1;
|
|
|
|
old.x1 = old_x2;
|
|
|
|
old.y1 = old_y2;
|
|
|
|
|
|
|
|
art_drect_union (&unionrect, &old, &new);
|
2009-10-14 12:10:01 -04:00
|
|
|
gnome_canvas_request_redraw (item->canvas,
|
2007-03-18 12:45:43 -04:00
|
|
|
unionrect.x0 - 0.5,
|
|
|
|
unionrect.y0 - 0.5,
|
2007-03-20 22:39:12 -04:00
|
|
|
unionrect.x1 + 1.5,
|
|
|
|
unionrect.y1 + 1.5);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
/*
|
|
|
|
* CANVAS CALLBACKS
|
2005-09-25 14:42:24 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2005-11-25 22:14:16 -05:00
|
|
|
gnome_canvas_simplerect_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2009-07-21 11:55:17 -04:00
|
|
|
(void) pspec;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasSimpleRect *simplerect;
|
2005-11-26 03:14:35 -05:00
|
|
|
int update = FALSE;
|
|
|
|
int bounds_changed = FALSE;
|
2005-11-26 05:28:55 -05:00
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
simplerect = GNOME_CANVAS_SIMPLERECT (object);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_X1:
|
|
|
|
if (simplerect->x1 != g_value_get_double (value)) {
|
|
|
|
simplerect->x1 = g_value_get_double (value);
|
2005-09-25 14:42:24 -04:00
|
|
|
bounds_changed = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_Y1:
|
|
|
|
if (simplerect->y1 != g_value_get_double (value)) {
|
|
|
|
simplerect->y1 = g_value_get_double (value);
|
2005-09-25 14:42:24 -04:00
|
|
|
bounds_changed = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_X2:
|
|
|
|
if (simplerect->x2 != g_value_get_double (value)) {
|
|
|
|
simplerect->x2 = g_value_get_double (value);
|
2005-09-25 14:42:24 -04:00
|
|
|
bounds_changed = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_Y2:
|
|
|
|
if (simplerect->y2 != g_value_get_double (value)) {
|
|
|
|
simplerect->y2 = g_value_get_double (value);
|
2005-09-25 14:42:24 -04:00
|
|
|
bounds_changed = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_DRAW:
|
|
|
|
if (simplerect->draw != g_value_get_boolean (value)) {
|
|
|
|
simplerect->draw = g_value_get_boolean (value);
|
2005-09-25 14:42:24 -04:00
|
|
|
update = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_FILL:
|
|
|
|
if (simplerect->fill != g_value_get_boolean (value)) {
|
|
|
|
simplerect->fill = g_value_get_boolean (value);
|
2005-09-25 14:42:24 -04:00
|
|
|
update = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_FILL_COLOR_RGBA:
|
|
|
|
if (simplerect->fill_color != g_value_get_uint(value)) {
|
|
|
|
simplerect->fill_color = g_value_get_uint(value);
|
2005-09-25 14:42:24 -04:00
|
|
|
update = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_OUTLINE_COLOR_RGBA:
|
|
|
|
if (simplerect->outline_color != g_value_get_uint(value)) {
|
|
|
|
simplerect->outline_color = g_value_get_uint(value);
|
2005-09-25 14:42:24 -04:00
|
|
|
update = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_OUTLINE_PIXELS:
|
|
|
|
if (simplerect->outline_pixels != g_value_get_uint(value)) {
|
|
|
|
simplerect->outline_pixels = g_value_get_uint(value);
|
2005-09-25 14:42:24 -04:00
|
|
|
update = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_OUTLINE_WHAT:
|
|
|
|
if (simplerect->outline_what != g_value_get_uint(value)) {
|
|
|
|
simplerect->outline_what = g_value_get_uint(value);
|
2005-09-25 14:42:24 -04:00
|
|
|
update = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-02 19:08:58 -05:00
|
|
|
if (!simplerect->full_draw_on_update) {
|
|
|
|
/* XXX: not sure about this;
|
|
|
|
*
|
|
|
|
* I changed the next line to be conditional, rather than always
|
|
|
|
* being executed. Without the condition, the following bug occurs:
|
|
|
|
*
|
|
|
|
* caller sets a property (e.g. outline colour); this sets update = TRUE and hence full_draw_on_update = TRUE
|
|
|
|
* update is requested (and it is intended, I suppose, that during this update, full_draw_on_update is noted)
|
|
|
|
* ... update does not occur before ...
|
|
|
|
* caller sets the same property again to the same value; this sets update = FALSE and hence full_draw_on_update = FALSE
|
|
|
|
* update now occurs, but full_draw_on_update is FALSE, so the full redraw does not happen,
|
|
|
|
* which results in graphical glitches.
|
|
|
|
*
|
|
|
|
* (Carl, 2/1/2010)
|
|
|
|
*/
|
|
|
|
simplerect->full_draw_on_update = update;
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (update || bounds_changed) {
|
2005-11-25 22:14:16 -05:00
|
|
|
gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(object));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-11-25 22:14:16 -05:00
|
|
|
gnome_canvas_simplerect_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-11-25 22:14:16 -05:00
|
|
|
GnomeCanvasSimpleRect *rect = GNOME_CANVAS_SIMPLERECT (object);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-11-26 05:28:55 -05:00
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (GNOME_IS_CANVAS_SIMPLERECT (object));
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_X1:
|
|
|
|
g_value_set_double (value, rect->x1);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_X2:
|
|
|
|
g_value_set_double (value, rect->x2);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_Y1:
|
|
|
|
g_value_set_double (value, rect->y1);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_Y2:
|
|
|
|
g_value_set_double (value, rect->y2);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_OUTLINE_WHAT:
|
|
|
|
g_value_set_uint (value, rect->outline_what);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_FILL:
|
|
|
|
g_value_set_boolean (value, rect->fill);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_OUTLINE_PIXELS:
|
|
|
|
g_value_set_uint (value, rect->outline_pixels);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_FILL_COLOR_RGBA:
|
|
|
|
g_value_set_uint (value, rect->fill_color);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_OUTLINE_COLOR_RGBA:
|
|
|
|
g_value_set_uint (value, rect->outline_color);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2005-11-25 22:14:16 -05:00
|
|
|
case PROP_DRAW:
|
|
|
|
g_value_set_boolean (value, rect->draw);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
default:
|
2005-11-25 22:14:16 -05:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-25 22:14:16 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simplerect_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
|
|
|
GnomeCanvasSimpleRect *simplerect;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
simplerect = GNOME_CANVAS_SIMPLERECT (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_simplerect_reset_bounds (item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (simplerect->full_draw_on_update) {
|
2009-10-14 12:10:01 -04:00
|
|
|
gnome_canvas_request_redraw (item->canvas,
|
2010-12-28 15:37:44 -05:00
|
|
|
simplerect->bbox_ulx,
|
|
|
|
simplerect->bbox_uly,
|
|
|
|
simplerect->bbox_lrx+0.5,
|
|
|
|
simplerect->bbox_lry+0.5);
|
2005-09-25 14:42:24 -04:00
|
|
|
simplerect->full_draw_on_update = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT_TO_RGBA (simplerect->fill_color, &simplerect->fill_r, &simplerect->fill_g, &simplerect->fill_b, &simplerect->fill_a);
|
2011-03-03 09:46:23 -05:00
|
|
|
UINT_TO_RGBA (simplerect->outline_color, &simplerect->outline_r, &simplerect->outline_g, &simplerect->outline_b, &simplerect->outline_a);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2005-12-08 13:53:43 -05:00
|
|
|
// this can be useful for debugging/understanding how the canvas redraws
|
|
|
|
// stuff.
|
|
|
|
|
|
|
|
#undef HARLEQUIN_DEBUGGING
|
|
|
|
|
|
|
|
#undef SIMPLERECT_FAST_RENDERER
|
2005-09-25 14:42:24 -04:00
|
|
|
#ifdef SIMPLERECT_FAST_RENDERER
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simplerect_render (GnomeCanvasItem *item,
|
|
|
|
GnomeCanvasBuf *buf)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasSimpleRect *simplerect;
|
2005-09-25 14:42:24 -04:00
|
|
|
int end, begin;
|
|
|
|
int ey, sy;
|
|
|
|
unsigned int i;
|
|
|
|
ArtIRect intersection;
|
|
|
|
ArtIRect self;
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
simplerect = GNOME_CANVAS_SIMPLERECT (item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (parent_class->render) {
|
|
|
|
(*parent_class->render) (item, buf);
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
if (buf->is_bg) {
|
|
|
|
|
2005-12-08 13:53:43 -05:00
|
|
|
#ifdef HARLEQUIN_DEBUGGING
|
|
|
|
gint randr, randg, randb;
|
|
|
|
randr = random() % 255;
|
|
|
|
randg = random() % 255;
|
|
|
|
randb = random() % 255;
|
|
|
|
PAINT_BOX(buf, randr, randg, randb, 255, buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1);
|
|
|
|
#endif
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!simplerect->draw) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
self.x0 = simplerect->bbox_ulx;
|
|
|
|
self.y0 = simplerect->bbox_uly;
|
|
|
|
self.x1 = simplerect->bbox_lrx;
|
|
|
|
self.y1 = simplerect->bbox_lry;
|
|
|
|
|
|
|
|
art_irect_intersect (&intersection, &self, &buf->rect);
|
|
|
|
|
|
|
|
begin = MAX(simplerect->bbox_ulx, buf->rect.x0);
|
|
|
|
end = MIN((simplerect->bbox_lrx-1), buf->rect.x1);
|
|
|
|
|
|
|
|
sy = simplerect->bbox_uly;
|
|
|
|
ey = simplerect->bbox_lry-1;
|
|
|
|
|
|
|
|
if (simplerect->fill) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
// this can be useful for debugging/understanding how the canvas redraws
|
|
|
|
// stuff.
|
2005-12-08 13:53:43 -05:00
|
|
|
|
|
|
|
#ifdef HARLEQUIN_DEBUGGING
|
|
|
|
gint randr, randg, randb;
|
|
|
|
randr = random() % 255;
|
|
|
|
randg = random() % 255;
|
|
|
|
randb = random() % 255;
|
|
|
|
PAINT_BOX(buf, randr, randg, randb, simplerect->fill_a, begin, sy, end, ey);
|
2009-10-14 12:10:01 -04:00
|
|
|
#else
|
|
|
|
PAINT_BOX (buf, simplerect->fill_r, simplerect->fill_g, simplerect->fill_b, simplerect->fill_a,
|
2006-02-10 21:34:03 -05:00
|
|
|
intersection.x0, intersection.y0,
|
|
|
|
intersection.x1, intersection.y1);
|
2005-12-08 13:53:43 -05:00
|
|
|
#endif
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2011-03-03 09:46:23 -05:00
|
|
|
if (simplerect->outline_a > 0) {
|
|
|
|
for (i = 0; i < simplerect->outline_pixels; ++i) {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-03 09:46:23 -05:00
|
|
|
if (simplerect->outline_what & 0x1) {
|
|
|
|
if (begin == simplerect->bbox_ulx) {
|
|
|
|
PAINT_VERTA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin + i, sy, ey);
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-03 09:46:23 -05:00
|
|
|
if (simplerect->outline_what & 0x2) {
|
|
|
|
if (end == (simplerect->bbox_lrx - 1)) {
|
|
|
|
PAINT_VERTA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, end - i, sy, ey + 1);
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-03 09:46:23 -05:00
|
|
|
if (simplerect->outline_what & 0x4) {
|
|
|
|
PAINT_HORIZA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin, end, sy+i);
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-03 09:46:23 -05:00
|
|
|
if (simplerect->outline_what & 0x8) {
|
|
|
|
PAINT_HORIZA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin, end + 1, ey-i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* SIMPLERECT_FAST_RENDERER */
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simplerect_render (GnomeCanvasItem *item,
|
|
|
|
GnomeCanvasBuf *buf)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-09-25 18:26:56 -04:00
|
|
|
GnomeCanvasSimpleRect *simplerect;
|
2005-09-25 14:42:24 -04:00
|
|
|
int end, begin;
|
|
|
|
int ey, sy;
|
2011-03-03 09:46:23 -05:00
|
|
|
int i;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
simplerect = GNOME_CANVAS_SIMPLERECT (item);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (parent_class->render) {
|
|
|
|
(*parent_class->render) (item, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf->is_bg) {
|
|
|
|
|
2005-12-08 13:53:43 -05:00
|
|
|
#ifdef HARLEQUIN_DEBUGGING
|
|
|
|
gint randr, randg, randb;
|
|
|
|
randr = random() % 255;
|
|
|
|
randg = random() % 255;
|
|
|
|
randb = random() % 255;
|
|
|
|
PAINT_BOX(buf, randr, randg, randb, 255, buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1);
|
|
|
|
#endif
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!simplerect->draw) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
begin = MAX(simplerect->bbox_ulx,buf->rect.x0);
|
|
|
|
end = MIN((simplerect->bbox_lrx-1),buf->rect.x1);
|
|
|
|
|
|
|
|
sy = simplerect->bbox_uly;
|
|
|
|
ey = simplerect->bbox_lry-1;
|
|
|
|
|
|
|
|
if (simplerect->fill) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-12-08 13:53:43 -05:00
|
|
|
#ifdef HARLEQUIN_DEBUGGING
|
|
|
|
gint randr, randg, randb;
|
|
|
|
randr = random() % 255;
|
|
|
|
randg = random() % 255;
|
|
|
|
randb = random() % 255;
|
|
|
|
PAINT_BOX(buf, randr, randg, randb, simplerect->fill_a, begin, sy, end, ey);
|
2009-10-14 12:10:01 -04:00
|
|
|
#else
|
2005-09-25 14:42:24 -04:00
|
|
|
PAINT_BOX(buf, simplerect->fill_r, simplerect->fill_g, simplerect->fill_b, simplerect->fill_a, begin, sy, end, ey);
|
2005-12-08 13:53:43 -05:00
|
|
|
#endif
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2011-03-03 09:46:23 -05:00
|
|
|
if (simplerect->outline_a) {
|
|
|
|
for (i = 0; i < (int) simplerect->outline_pixels; ++i) {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-03 09:46:23 -05:00
|
|
|
if (simplerect->outline_what & 0x1) {
|
|
|
|
if (begin == simplerect->bbox_ulx) {
|
|
|
|
PAINT_VERTA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin + i, sy, ey);
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-03 09:46:23 -05:00
|
|
|
if (simplerect->outline_what & 0x2) {
|
|
|
|
if (end == (simplerect->bbox_lrx - 1)) {
|
|
|
|
PAINT_VERTA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, end - i, sy, ey + 1);
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-03 09:46:23 -05:00
|
|
|
if (simplerect->outline_what & 0x4) {
|
|
|
|
PAINT_HORIZA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin, end, sy+i);
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-03 09:46:23 -05:00
|
|
|
if (simplerect->outline_what & 0x8) {
|
|
|
|
PAINT_HORIZA(buf, simplerect->outline_r, simplerect->outline_g, simplerect->outline_b, simplerect->outline_a, begin, end + 1, ey-i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
#endif /* SIMPLERECT_FAST_RENDERER */
|
|
|
|
|
|
|
|
static void
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simplerect_draw (GnomeCanvasItem *item,
|
2008-03-17 16:54:03 -04:00
|
|
|
GdkDrawable *drawable,
|
|
|
|
int x, int y,
|
|
|
|
int width, int height)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2008-03-17 16:54:03 -04:00
|
|
|
GnomeCanvasSimpleRect *simplerect;
|
|
|
|
cairo_t* cr;
|
|
|
|
double ulx;
|
|
|
|
double uly;
|
|
|
|
double lrx;
|
|
|
|
double lry;
|
|
|
|
|
|
|
|
simplerect = GNOME_CANVAS_SIMPLERECT (item);
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
cr = gdk_cairo_create (drawable);
|
2008-03-17 16:54:03 -04:00
|
|
|
|
|
|
|
if (x > simplerect->bbox_ulx) {
|
|
|
|
ulx = x;
|
|
|
|
} else {
|
|
|
|
ulx = simplerect->bbox_ulx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y > simplerect->bbox_uly) {
|
|
|
|
uly = y;
|
|
|
|
} else {
|
|
|
|
uly = simplerect->bbox_uly;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x + width > simplerect->bbox_lrx) {
|
|
|
|
lrx = simplerect->bbox_lrx;
|
|
|
|
} else {
|
|
|
|
lrx = x + width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y + height > simplerect->bbox_lry) {
|
|
|
|
lry = simplerect->bbox_lry;
|
|
|
|
} else {
|
|
|
|
lry = y + height;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulx -= x;
|
|
|
|
uly -= y;
|
|
|
|
lrx -= x;
|
|
|
|
lry -= y;
|
|
|
|
|
|
|
|
cairo_rectangle (cr, ulx, uly, lrx - ulx, lry - uly);
|
|
|
|
|
|
|
|
if (simplerect->fill) {
|
|
|
|
cairo_set_source_rgba (cr,
|
2009-10-14 12:10:01 -04:00
|
|
|
simplerect->fill_r/255.0,
|
|
|
|
simplerect->fill_g/255.0,
|
|
|
|
simplerect->fill_b/255.0,
|
2008-03-17 16:54:03 -04:00
|
|
|
simplerect->fill_a/255.0);
|
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-03-17 16:54:03 -04:00
|
|
|
if (simplerect->outline_what && simplerect->outline_pixels) {
|
|
|
|
|
|
|
|
#define x_in_range(a) (x <= (a) && (a) < x + width)
|
|
|
|
#define y_in_range(a) (y <= (a) && (a) < y + height)
|
|
|
|
|
|
|
|
cairo_set_line_width (cr, simplerect->outline_pixels);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-03-17 16:54:03 -04:00
|
|
|
cairo_set_source_rgb (cr,
|
2009-10-14 12:10:01 -04:00
|
|
|
simplerect->outline_r/255.0,
|
|
|
|
simplerect->outline_g/255.0,
|
2008-03-17 16:54:03 -04:00
|
|
|
simplerect->outline_b/255.0);
|
|
|
|
|
|
|
|
if (simplerect->outline_what & 0x1) {
|
|
|
|
/* left edge, if visible */
|
|
|
|
if (x_in_range (simplerect->bbox_ulx)) {
|
|
|
|
cairo_move_to (cr, ulx+0.5, uly+0.5);
|
|
|
|
cairo_line_to (cr, ulx+0.5, lry+0.5);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-03-17 16:54:03 -04:00
|
|
|
if (simplerect->outline_what & 0x2) {
|
|
|
|
/* right edge, if visible */
|
|
|
|
if (x_in_range (simplerect->bbox_lrx)) {
|
|
|
|
cairo_move_to (cr, lrx+0.5, uly+0.5);
|
|
|
|
cairo_line_to (cr, lrx+0.5, lry+0.5);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-03-17 16:54:03 -04:00
|
|
|
if (simplerect->outline_what & 0x4) {
|
|
|
|
/* top edge */
|
|
|
|
if (y_in_range (simplerect->bbox_uly)) {
|
|
|
|
cairo_move_to (cr, ulx+0.5, uly+0.5);
|
|
|
|
cairo_line_to (cr, lrx+0.5, uly+0.5);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-03-17 16:54:03 -04:00
|
|
|
if (simplerect->outline_what & 0x8) {
|
|
|
|
/* bottom edge */
|
|
|
|
if (y_in_range (simplerect->bbox_lry)) {
|
|
|
|
cairo_move_to (cr, ulx+0.5, lry+0.5);
|
|
|
|
cairo_line_to (cr, lrx+0.5, lry+0.5);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simplerect_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2009-07-21 11:55:17 -04:00
|
|
|
(void) cx;
|
|
|
|
(void) cy;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
double x1, y1, x2, y2;
|
|
|
|
double dx, dy;
|
|
|
|
|
|
|
|
*actual_item = item;
|
|
|
|
|
|
|
|
/* Find the bounds for the rectangle plus its outline width */
|
|
|
|
|
2005-09-25 18:26:56 -04:00
|
|
|
gnome_canvas_simplerect_bounds (item, &x1, &y1, &x2, &y2);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
/* Is point inside rectangle */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
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);
|
|
|
|
}
|