#include <stdio.h>
#include <math.h>
+#include <cairo.h>
#include <libgnomecanvas/libgnomecanvas.h>
#include "canvas-simpleline.h"
gobject_class->set_property = gnome_canvas_simpleline_set_property;
gobject_class->get_property = gnome_canvas_simpleline_get_property;
-
+
g_object_class_install_property (gobject_class,
PROP_X1,
g_param_spec_double ("x1",
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
- G_PARAM_READWRITE));
-
+ G_PARAM_READWRITE));
+
g_object_class_install_property (gobject_class,
PROP_Y1,
g_param_spec_double ("y1",
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
- G_PARAM_READWRITE));
-
+ G_PARAM_READWRITE));
+
g_object_class_install_property (gobject_class,
PROP_X2,
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
- G_PARAM_READWRITE));
-
+ G_PARAM_READWRITE));
+
g_object_class_install_property (gobject_class,
PROP_Y2,
g_param_spec_double ("y2",
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
- G_PARAM_READWRITE));
+ G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_COLOR_RGBA,
g_param_spec_uint ("color_rgba",
0,
G_MAXUINT,
0,
- G_PARAM_READWRITE));
-
+ G_PARAM_READWRITE));
+
object_class->destroy = gnome_canvas_simpleline_destroy;
item_class->update = gnome_canvas_simpleline_update;
i1.y = y1;
i2.x = x2;
i2.y = y2;
-
+
gnome_canvas_item_i2w_affine (item, i2w);
art_affine_point (&w1, &i1, i2w);
art_affine_point (&w2, &i2, i2w);
}
}
-static void
+static void
gnome_canvas_simpleline_reset_bounds (GnomeCanvasItem *item)
{
int Ix1, Ix2, Iy1, Iy2;
gnome_canvas_update_bbox (item, Ix1, Iy1, Ix2, Iy2);
}
-/*
- * CANVAS CALLBACKS
+/*
+ * CANVAS CALLBACKS
*/
static void
GParamSpec *pspec)
{
+ (void) pspec;
+
GnomeCanvasSimpleLine *simpleline;
int update = FALSE;
int bounds_changed = FALSE;
bounds_changed = TRUE;
}
break;
-
+
case PROP_COLOR_RGBA:
if (simpleline->color != g_value_get_uint(value)) {
simpleline->color = g_value_get_uint(value);
{
g_return_if_fail (object != NULL);
g_return_if_fail (GNOME_IS_CANVAS_SIMPLELINE (object));
-
+
GnomeCanvasSimpleLine *line = GNOME_CANVAS_SIMPLELINE (object);
switch (prop_id) {
//begin = MAX(simpleline->bbox_ulx,buf->rect.x0);
//end = MIN(simpleline->bbox_lrx,buf->rect.x1);
-
+
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,
+ PAINT_HORIZA(buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a,
begin, end, simpleline->bbox_uly);
} else {
PAINT_VERTA(buf, simpleline->r, simpleline->g, simpleline->b, simpleline->a,
int width, int height)
{
GnomeCanvasSimpleLine *simpleline;
+ cairo_t* cr;
+ double ulx;
+ double uly;
+ double lrx;
+ double lry;
simpleline = GNOME_CANVAS_SIMPLELINE (item);
- if (parent_class->draw) {
- (* parent_class->draw) (item, drawable, x, y, width, height);
+ cr = gdk_cairo_create (drawable);
+
+ if (x > simpleline->bbox_ulx) {
+ ulx = x;
+ } else {
+ ulx = simpleline->bbox_ulx;
+ }
+
+ if (y > simpleline->bbox_uly) {
+ uly = y;
+ } else {
+ uly = simpleline->bbox_uly;
+ }
+
+ if (x + width > simpleline->bbox_lrx) {
+ lrx = simpleline->bbox_lrx;
+ } else {
+ lrx = x + width;
+ }
+
+ if (y + height > simpleline->bbox_lry) {
+ lry = simpleline->bbox_lry;
+ } else {
+ lry = y + height;
}
- fprintf (stderr, "please don't use the CanvasSimpleLine item in a non-aa Canvas\n");
- abort ();
+ ulx -= x;
+ uly -= y;
+ lrx -= x;
+ lry -= y;
+
+ cairo_set_source_rgba (cr,
+ simpleline->r/255.0,
+ simpleline->g/255.0,
+ simpleline->b/255.0,
+ simpleline->a/255.0);
+ cairo_set_line_width (cr, 1);
+ cairo_move_to (cr, ulx+0.5, uly+0.5);
+ cairo_line_to (cr, lrx+0.5, lry+0.5);
+ cairo_stroke (cr);
}
static void
static double
gnome_canvas_simpleline_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item)
{
+ (void) cx;
+ (void) cy;
+
GnomeCanvasSimpleLine *simpleline;
double x1, y1, x2, y2;
double dx, dy;
*actual_item = item;
- /* Find the bounds for the rectangle plus its outline width */
+ /* Find the bounds for the line plus its outline width */
gnome_canvas_simpleline_bounds (item, &x1, &y1, &x2, &y2);
- /* Is point inside rectangle */
-
+ /* Is point inside line */
+
if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) {
return 0.0;
}
- /* Point is outside rectangle */
+ /* Point is outside line */
if (x < x1)
dx = x1 - x;