Code

Split SPCanvasItem and SPCanvasGroup to individual .h files. Removed forward header.
[inkscape.git] / src / display / canvas-bpath.cpp
index 714538d1b455cc9fdfd1b48fefc3b991e9d54c98..f8a8ef22c64352f46d0e378584b6f658bb5314b1 100644 (file)
@@ -1,5 +1,3 @@
-#define __SP_CANVAS_BPATH_C__
-
 /*
  * Simple bezier bpath CanvasItem for inkscape
  *
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
+#include <sstream>
+#include <string.h>
+#include <desktop.h>
+
 #include "color.h"
 #include "sp-canvas-util.h"
 #include "inkscape-cairo.h"
 #include "canvas-bpath.h"
-#include "display/display-forward.h"
+#include "display/sp-canvas-group.h"
 #include "display/curve.h"
 #include "display/inkscape-cairo.h"
-#include "libnr/nr-matrix-fns.h"
-#include <libnr/nr-pixops.h>
-#include <libnr/nr-convert2geom.h>
-#include <libnr/nr-path.h>
+#include "libnr/nr-pixops.h"
+#include "helper/geom.h"
+
 
 void nr_pixblock_render_bpath_rgba (Shape* theS,uint32_t color,NRRectL &area,char* destBuf,int stride);
 
@@ -33,9 +34,9 @@ static void sp_canvas_bpath_class_init (SPCanvasBPathClass *klass);
 static void sp_canvas_bpath_init (SPCanvasBPath *path);
 static void sp_canvas_bpath_destroy (GtkObject *object);
 
-static void sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
+static void sp_canvas_bpath_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags);
 static void sp_canvas_bpath_render (SPCanvasItem *item, SPCanvasBuf *buf);
-static double sp_canvas_bpath_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item);
+static double sp_canvas_bpath_point (SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item);
 
 static SPCanvasItemClass *parent_class;
 
@@ -102,7 +103,7 @@ sp_canvas_bpath_destroy (GtkObject *object)
 }
 
 static void
-sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
+sp_canvas_bpath_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
 {
     SPCanvasBPath *cbp = SP_CANVAS_BPATH (item);
 
@@ -117,16 +118,19 @@ sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i
 
     cbp->affine = affine;
 
-    const_NRBPath bp;
-    bp.path = cbp->curve->get_bpath();
-    NRRect bbox;
-    nr_path_matrix_bbox_union(&bp, affine, &bbox);
-
-    item->x1 = (int)bbox.x0 - 1;
-    item->y1 = (int)bbox.y0 - 1;
-    item->x2 = (int)bbox.x1 + 1;
-    item->y2 = (int)bbox.y1 + 1;
-
+    Geom::OptRect bbox = bounds_exact_transformed(cbp->curve->get_pathvector(), affine);
+
+    if (bbox) {
+        item->x1 = (int)bbox->min()[Geom::X] - 1;
+        item->y1 = (int)bbox->min()[Geom::Y] - 1;
+        item->x2 = (int)bbox->max()[Geom::X] + 1;
+        item->y2 = (int)bbox->max()[Geom::Y] + 1;
+    } else {
+        item->x1 = 0;
+        item->y1 = 0;
+        item->x2 = 0;
+        item->y2 = 0;
+    }
     sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
 }
 
@@ -137,11 +141,11 @@ sp_canvas_bpath_render (SPCanvasItem *item, SPCanvasBuf *buf)
 
     sp_canvas_prepare_buffer(buf);
 
-    NR::Rect area (NR::Point(buf->rect.x0, buf->rect.y0), NR::Point(buf->rect.x1, buf->rect.y1));
+    Geom::Rect area (Geom::Point(buf->rect.x0, buf->rect.y0), Geom::Point(buf->rect.x1, buf->rect.y1));
 
     if ( !cbp->curve  || 
          ((cbp->stroke_rgba & 0xff) == 0 && (cbp->fill_rgba & 0xff) == 0 ) || 
-         cbp->curve->get_length() <= 1)
+         cbp->curve->get_segment_count() < 1)
         return;
 
     if (!buf->ct)
@@ -154,9 +158,9 @@ sp_canvas_bpath_render (SPCanvasItem *item, SPCanvasBuf *buf)
     cairo_new_path(buf->ct);
 
     if (!dofill)
-        feed_pathvector_to_cairo (buf->ct, cbp->curve->get_pathvector(), to_2geom(cbp->affine), area, true, 1);
+        feed_pathvector_to_cairo (buf->ct, cbp->curve->get_pathvector(), cbp->affine, area, true, 1);
     else
-        feed_pathvector_to_cairo (buf->ct, cbp->curve->get_pathvector(), to_2geom(cbp->affine), area, false, 1);
+        feed_pathvector_to_cairo (buf->ct, cbp->curve->get_pathvector(), cbp->affine, area, false, 1);
 
     if (dofill) {
         // RGB / BGR
@@ -173,28 +177,28 @@ sp_canvas_bpath_render (SPCanvasItem *item, SPCanvasBuf *buf)
         // RGB / BGR
         cairo_set_source_rgba(buf->ct, SP_RGBA32_B_F(cbp->stroke_rgba), SP_RGBA32_G_F(cbp->stroke_rgba), SP_RGBA32_R_F(cbp->stroke_rgba), SP_RGBA32_A_F(cbp->stroke_rgba));
         cairo_set_line_width(buf->ct, 1);
+        if (cbp->dashes[0] != 0 && cbp->dashes[1] != 0) {
+            cairo_set_dash (buf->ct, cbp->dashes, 2, 0);
+        }
         cairo_stroke(buf->ct);
     }
 }
 
 static double
-sp_canvas_bpath_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item)
+sp_canvas_bpath_point (SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item)
 {
     SPCanvasBPath *cbp = SP_CANVAS_BPATH (item);
 
-    const_NRBPath bp;
     if ( !cbp->curve  || 
          ((cbp->stroke_rgba & 0xff) == 0 && (cbp->fill_rgba & 0xff) == 0 ) || 
-         cbp->curve->get_length() <= 1)
+         cbp->curve->get_segment_count() < 1)
         return NR_HUGE;
 
-    bp.path = cbp->curve->get_bpath();
-
     double width = 0.5;
-    NR::Rect viewbox = item->canvas->getViewbox();
-        viewbox.growBy (width);
+    Geom::Rect viewbox = item->canvas->getViewbox();
+    viewbox.expandBy (width);
     double dist = NR_HUGE;
-    nr_path_matrix_point_bbox_wind_distance(&bp, cbp->affine, p, NULL, NULL, &dist, 0.5, &viewbox);
+    pathv_matrix_point_bbox_wind_distance(cbp->curve->get_pathvector(), cbp->affine, p, NULL, NULL, &dist, 0.5, &viewbox);
 
     if (dist <= 1.0) {
         *actual_item = item;
@@ -246,7 +250,7 @@ sp_canvas_bpath_set_fill (SPCanvasBPath *cbp, guint32 rgba, SPWindRule rule)
 }
 
 void
-sp_canvas_bpath_set_stroke (SPCanvasBPath *cbp, guint32 rgba, gdouble width, SPStrokeJoinType join, SPStrokeCapType cap)
+sp_canvas_bpath_set_stroke (SPCanvasBPath *cbp, guint32 rgba, gdouble width, SPStrokeJoinType join, SPStrokeCapType cap, double dash, double gap)
 {
     g_return_if_fail (cbp != NULL);
     g_return_if_fail (SP_IS_CANVAS_BPATH (cbp));
@@ -255,13 +259,12 @@ sp_canvas_bpath_set_stroke (SPCanvasBPath *cbp, guint32 rgba, gdouble width, SPS
     cbp->stroke_width = MAX (width, 0.1);
     cbp->stroke_linejoin = join;
     cbp->stroke_linecap = cap;
+    cbp->dashes[0] = dash;
+    cbp->dashes[1] = gap;
 
     sp_canvas_item_request_update (SP_CANVAS_ITEM (cbp));
 }
 
-
-
-
 /*
   Local Variables:
   mode:c++
@@ -271,4 +274,4 @@ sp_canvas_bpath_set_stroke (SPCanvasBPath *cbp, guint32 rgba, gdouble width, SPS
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :