Code

No more NRMatrix or NRPoint.
[inkscape.git] / src / display / sp-ctrlline.cpp
index d6dbdf0224a6fe90b4cda1f7743f03af03a59d59..a3c7839c765d2092c543a605301e3a21ddf5c6e9 100644 (file)
@@ -5,7 +5,9 @@
  *
  * Author:
  *   Lauris Kaplinski <lauris@kaplinski.com>
+ *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
  *
+ * Copyright (C) 2007 Johan Engelen
  * Copyright (C) 1999-2002 Lauris Kaplinski
  *
  * Released under GNU GPL
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
-#include <livarot/Shape.h>
 #include <livarot/Path.h>
+#include <color.h>
 
-struct SPCtrlLine : public SPCanvasItem{
-    guint32 rgba;
-    NRPoint s, e;
-    Shape* shp;
-};
-
-struct SPCtrlLineClass : public SPCanvasItemClass{};
 
 static void sp_ctrlline_class_init (SPCtrlLineClass *klass);
 static void sp_ctrlline_init (SPCtrlLine *ctrlline);
@@ -81,8 +76,9 @@ static void
 sp_ctrlline_init (SPCtrlLine *ctrlline)
 {
     ctrlline->rgba = 0x0000ff7f;
-    ctrlline->s.x = ctrlline->s.y = ctrlline->e.x = ctrlline->e.y = 0.0;
+    ctrlline->s[NR::X] = ctrlline->s[NR::Y] = ctrlline->e[NR::X] = ctrlline->e[NR::Y] = 0.0;
     ctrlline->shp=NULL;
+    ctrlline->item=NULL;
 }
 
 static void
@@ -98,6 +94,8 @@ sp_ctrlline_destroy (GtkObject *object)
         ctrlline->shp = NULL;
     }
 
+    ctrlline->item=NULL;
+
     if (GTK_OBJECT_CLASS (parent_class)->destroy)
         (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
 }
@@ -113,6 +111,33 @@ sp_ctrlline_render (SPCanvasItem *item, SPCanvasBuf *buf)
     area.y0=buf->rect.y0;
     area.y1=buf->rect.y1;
 
+/*
+// CAIRO FIXME: after SPCanvasBuf is switched to unpacked 32bit rgb, rendering can be done via cairo:
+    cairo_surface_t* cst = cairo_image_surface_create_for_data (
+        buf->buf,
+        CAIRO_FORMAT_RGB24,
+        buf->rect.x1 - buf->rect.x0,
+        buf->rect.y1 - buf->rect.y0,
+        buf->buf_rowstride
+        );
+    cairo_t *ct = cairo_create (cst);
+
+    guint32 rgba = ctrlline->rgba;
+    cairo_set_source_rgba(ct, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba), SP_RGBA32_A_F(rgba));
+
+    cairo_set_line_width(ct, 0.5);
+    cairo_new_path(ct);
+
+    cairo_move_to (ct, ctrlline->s.x - buf->rect.x0, ctrlline->s.y - buf->rect.y0);
+    cairo_line_to (ct, ctrlline->e.x - buf->rect.x0, ctrlline->e.y - buf->rect.y0);
+
+    cairo_stroke(ct);
+    cairo_destroy (ct);
+    cairo_surface_finish (cst);
+    cairo_surface_destroy (cst);
+*/
+
+// CAIRO FIXME: instead of this:
     if (ctrlline->shp) {
         sp_canvas_prepare_buffer (buf);
         nr_pixblock_render_ctrl_rgba (ctrlline->shp,ctrlline->rgba,area,(char*)buf->buf, buf->buf_rowstride);
@@ -122,8 +147,6 @@ sp_ctrlline_render (SPCanvasItem *item, SPCanvasBuf *buf)
 static void
 sp_ctrlline_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
 {
-    NRRect dbox;
-
     SPCtrlLine *cl = SP_CTRLLINE (item);
 
     sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
@@ -133,20 +156,38 @@ sp_ctrlline_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int f
 
     sp_canvas_item_reset_bounds (item);
 
+/*
+// CAIRO FIXME: all that is needed for update with cairo:
+    NR::Point s = NR::Point(cl->s.x, cl->s.y) * affine;
+    NR::Point e = NR::Point(cl->e.x, cl->e.y) * affine;
+
+    cl->s.x = s[NR::X];
+    cl->s.y = s[NR::Y];
+    cl->e.x = e[NR::X];
+    cl->e.y = e[NR::Y];
+
+    item->x1 = (int)(MIN(s[NR::X], e[NR::X]) - 1);
+    item->y1 = (int)(MIN(s[NR::Y], e[NR::Y]) - 1);
+    item->x2 = (int)(MAX(s[NR::X], e[NR::X]) + 1);
+    item->y2 = (int)(MAX(s[NR::Y], e[NR::Y]) + 1);
+*/
+
+// CAIRO FIXME: instead of:
+    NRRect dbox;
     dbox.x0=dbox.x1=dbox.y0=dbox.y1=0;
     if (cl->shp) {
         delete cl->shp;
         cl->shp = NULL;
     }
     Path* thePath = new Path;
-    thePath->MoveTo(NR::Point(cl->s.x, cl->s.y) * affine);
-    thePath->LineTo(NR::Point(cl->e.x, cl->e.y) * affine);
+    thePath->MoveTo(NR::Point(cl->s[NR::X], cl->s[NR::Y]) * affine);
+    thePath->LineTo(NR::Point(cl->e[NR::X], cl->e[NR::Y]) * affine);
 
     NRRectL  area;
-    area.x0=(double)item->x1;
-    area.x1=(double)item->x2;
-    area.y0=(double)item->y1;
-    area.y1=(double)item->y2;
+    area.x0=(NR::ICoord)(double)item->x1;
+    area.x1=(NR::ICoord)(double)item->x2;
+    area.y0=(NR::ICoord)(double)item->y1;
+    area.y1=(NR::ICoord)(double)item->y2;
     thePath->Convert(&area, 1.0);
     if ( cl->shp == NULL ) cl->shp=new Shape;
     thePath->Stroke(cl->shp,false,0.5,join_straight,butt_straight,20.0,false);
@@ -195,11 +236,11 @@ sp_ctrlline_set_coords (SPCtrlLine *cl, gdouble x0, gdouble y0, gdouble x1, gdou
     g_return_if_fail (cl != NULL);
     g_return_if_fail (SP_IS_CTRLLINE (cl));
 
-    if (DIFFER (x0, cl->s.x) || DIFFER (y0, cl->s.y) || DIFFER (x1, cl->e.x) || DIFFER (y1, cl->e.y)) {
-        cl->s.x = x0;
-        cl->s.y = y0;
-        cl->e.x = x1;
-        cl->e.y = y1;
+    if (DIFFER (x0, cl->s[NR::X]) || DIFFER (y0, cl->s[NR::Y]) || DIFFER (x1, cl->e[NR::X]) || DIFFER (y1, cl->e[NR::Y])) {
+        cl->s[NR::X] = x0;
+        cl->s[NR::Y] = y0;
+        cl->e[NR::X] = x1;
+        cl->e[NR::Y] = y1;
         sp_canvas_item_request_update (SP_CANVAS_ITEM (cl));
     }
 }