4 #include <libgnomecanvas/libgnomecanvas.h>
6 #include "canvas-simpleline.h"
9 #define _(Text) dgettext (PACKAGE,Text)
51 GnomeCanvasItem **actual_item);
57 GdkDrawable *drawable,
69 static GType simpleline_type;
71 if (!simpleline_type) {
72 static const GTypeInfo object_info = {
73 sizeof (GnomeCanvasSimpleLineClass),
75 (GBaseFinalizeFunc) NULL,
77 (GClassFinalizeFunc) NULL,
79 sizeof (GnomeCanvasSimpleLine),
85 simpleline_type = g_type_register_static (GNOME_TYPE_CANVAS_ITEM,
"GnomeCanvasSimpleLine",
89 return simpleline_type;
95 GObjectClass *gobject_class;
96 GtkObjectClass *object_class;
97 GnomeCanvasItemClass *item_class;
99 gobject_class = (GObjectClass *)
class;
100 object_class = (GtkObjectClass *)
class;
101 item_class = (GnomeCanvasItemClass *)
class;
108 g_object_class_install_property (gobject_class,
110 g_param_spec_double (
"x1",
112 _(
"x coordinate of upper left corner of rect"),
118 g_object_class_install_property (gobject_class,
120 g_param_spec_double (
"y1",
122 _(
"y coordinate of upper left corner of rect "),
129 g_object_class_install_property (gobject_class,
131 g_param_spec_double (
"x2",
133 _(
"x coordinate of lower right corner of rect"),
139 g_object_class_install_property (gobject_class,
141 g_param_spec_double (
"y2",
143 _(
"y coordinate of lower right corner of rect "),
148 g_object_class_install_property (gobject_class,
150 g_param_spec_uint (
"color_rgba",
170 simpleline->x1 = 0.0;
171 simpleline->y1 = 0.0;
172 simpleline->x2 = 0.0;
173 simpleline->y2 = 0.0;
180 g_return_if_fail (
object != NULL);
181 g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (
object));
200 GnomeCanvasSimpleLine *simpleline;
202 int bounds_changed = FALSE;
205 g_return_if_fail (
object != NULL);
206 g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (
object));
208 simpleline = GNOME_CANVAS_SIMPLELINE (
object);
212 d = g_value_get_double (value);
213 if (simpleline->x1 != d) {
215 bounds_changed = TRUE;
220 d = g_value_get_double (value);
221 if (simpleline->y1 != d) {
223 bounds_changed = TRUE;
228 d = g_value_get_double (value);
229 if (simpleline->x2 != d) {
231 bounds_changed = TRUE;
236 d = g_value_get_double (value);
237 if (simpleline->y2 != d) {
239 bounds_changed = TRUE;
244 if (simpleline->color != g_value_get_uint(value)) {
245 simpleline->color = g_value_get_uint(value);
246 UINT_TO_RGBA (simpleline->color, &simpleline->r, &simpleline->g, &simpleline->b, &simpleline->a);
254 if (update || bounds_changed) {
255 gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(
object));
265 g_return_if_fail (
object != NULL);
266 g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (
object));
268 GnomeCanvasSimpleLine *line = GNOME_CANVAS_SIMPLELINE (
object);
272 g_value_set_double (value, line->x1);
275 g_value_set_double (value, line->x2);
278 g_value_set_double (value, line->y1);
281 g_value_set_double (value, line->y2);
284 g_value_set_uint (value, line->color);
287 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
295 GnomeCanvasSimpleLine *simpleline;
296 double x1, x2, y1, y2;
298 simpleline = GNOME_CANVAS_SIMPLELINE (item);
301 (*
parent_class->update) (item, affine, clip_path, flags);
305 gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2);
313 gnome_canvas_item_i2w (item, &x1, &y1);
314 gnome_canvas_item_i2w (item, &x2, &y2);
335 gnome_canvas_w2c_d (GNOME_CANVAS(item->canvas), x1, y1, &item->x1, &item->y1);
336 gnome_canvas_w2c_d (GNOME_CANVAS(item->canvas), x2, y2, &item->x2, &item->y2);
340 gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2);
349 gnome_canvas_item_i2w (item, &x1, &y1);
350 gnome_canvas_item_i2w (item, &x2, &y2);
352 x1 = (int) floor (item->x1);
353 y1 = (int) floor (item->y1);
354 x2 = (int) ceil (item->x2);
355 y2 = (int) ceil (item->y2);
357 gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x1, y1, &simpleline->cx1, &simpleline->cy1);
358 gnome_canvas_w2c (GNOME_CANVAS(item->canvas), x2, y2, &simpleline->cx2, &simpleline->cy2);
365 GnomeCanvasSimpleLine *simpleline;
369 simpleline = GNOME_CANVAS_SIMPLELINE (item);
371 x1 = simpleline->cx1;
372 x2 = simpleline->cx2;
373 y1 = simpleline->cy1;
376 gnome_canvas_buf_ensure_buf (buf);
380 if (simpleline->x1 != simpleline->x2) {
381 PAINT_HORIZA(buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a,
384 y2 = simpleline->cy2;
385 PAINT_VERTA (buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a,
393 GdkDrawable* drawable,
395 int width,
int height)
403 GnomeCanvasSimpleLine *simpleline = GNOME_CANVAS_SIMPLELINE (item);
405 *x1 = simpleline->x1;
406 *y1 = simpleline->y1;
407 *x2 = simpleline->x1;
408 *y2 = simpleline->y2;
417 double x1, y1, x2, y2;
428 if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) {
447 return sqrt (dx * dx + dy * dy);
static void gnome_canvas_simpleline_update(GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
static void gnome_canvas_simpleline_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
static void gnome_canvas_simpleline_class_init(GnomeCanvasSimpleLineClass *class)
static void gnome_canvas_simpleline_destroy(GtkObject *object)
static GnomeCanvasItemClass * parent_class
static void gnome_canvas_simpleline_init(GnomeCanvasSimpleLine *simpleline)
#define UINT_TO_RGBA(u, r, g, b, a)
static void gnome_canvas_simpleline_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
static void gnome_canvas_simpleline_bounds(GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
GType gnome_canvas_simpleline_get_type(void)
#define PAINT_HORIZA(inbuf, colr, colg, colb, cola, ptx0, ptx1, pty)
static double gnome_canvas_simpleline_point(GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item)
static void gnome_canvas_simpleline_draw(GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w, int h)
#define PAINT_VERTA(inbuf, colr, colg, colb, cola, ptx, pty0, pty1)
static void gnome_canvas_simpleline_render(GnomeCanvasItem *item, GnomeCanvasBuf *buf)
#define RGBA_TO_UINT(r, g, b, a)