Code

New crosshairs cursor for geometry context
[inkscape.git] / src / tweak-context.cpp
index aa5b2f3cceead3021178f86e7eb0aff2677d6c1b..9c69811282d67fc31662199de0d7fdb29388426d 100644 (file)
@@ -40,9 +40,7 @@
 #include "pixmaps/cursor-push.xpm"
 #include "pixmaps/cursor-roughen.xpm"
 #include "pixmaps/cursor-color.xpm"
-#include "libnr/n-art-bpath.h"
-#include "libnr/nr-path.h"
-#include "libnr/nr-maybe.h"
+#include <boost/optional.hpp>
 #include "libnr/nr-matrix-ops.h"
 #include "libnr/nr-scale-translate-ops.h"
 #include "xml/repr.h"
@@ -67,8 +65,9 @@
 #include "sp-flowtext.h"
 #include "display/canvas-bpath.h"
 #include "display/canvas-arena.h"
+#include "display/curve.h"
 #include "livarot/Shape.h"
-#include "isnan.h"
+#include "2geom/isnan.h"
 #include "prefs-utils.h"
 #include "style.h"
 #include "box3d.h"
 
 #define DYNA_MIN_WIDTH 1.0e-6
 
-// FIXME: move it to some shared file to be reused by both calligraphy and dropper
-#define C1 0.552
-static NArtBpath const hatch_area_circle[] = {
-    { NR_MOVETO, 0, 0, 0, 0, -1, 0 },
-    { NR_CURVETO, -1, C1, -C1, 1, 0, 1 },
-    { NR_CURVETO, C1, 1, 1, C1, 1, 0 },
-    { NR_CURVETO, 1, -C1, C1, -1, 0, -1 },
-    { NR_CURVETO, -C1, -1, -1, -C1, -1, 0 },
-    { NR_END, 0, 0, 0, 0, 0, 0 }
-};
-#undef C1
-
-
 static void sp_tweak_context_class_init(SPTweakContextClass *klass);
 static void sp_tweak_context_init(SPTweakContext *ddc);
 static void sp_tweak_context_dispose(GObject *object);
@@ -239,9 +225,17 @@ sp_tweak_context_setup(SPEventContext *ec)
         ((SPEventContextClass *) parent_class)->setup(ec);
 
     {
-        SPCurve *c = sp_curve_new_from_foreign_bpath(hatch_area_circle);
+        /* TODO: have a look at sp_dyna_draw_context_setup where the same is done.. generalize? at least make it an arcto! */
+        SPCurve *c = new SPCurve();
+        const double C1 = 0.552;
+        c->moveto(-1,0);
+        c->curveto(-1, C1, -C1, 1, 0, 1 );
+        c->curveto(C1, 1, 1, C1, 1, 0 );
+        c->curveto(1, -C1, C1, -1, 0, -1 );
+        c->curveto(-C1, -1, -1, -C1, -1, 0 );
+        c->closepath();
         tc->dilate_area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c);
-        sp_curve_unref(c);
+        c->unref();
         sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(tc->dilate_area), 0x00000000,(SPWindRule)0);
         sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(tc->dilate_area), 0xff9900ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
         sp_canvas_item_hide(tc->dilate_area);
@@ -372,7 +366,7 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, NR::Poi
 
 
         // skip those paths whose bboxes are entirely out of reach with our radius
-        NR::Maybe<NR::Rect> bbox = item->getBounds(sp_item_i2doc_affine(item));
+        boost::optional<NR::Rect> bbox = item->getBounds(sp_item_i2doc_affine(item));
         if (bbox) {
             bbox->growBy(radius);
             if (!bbox->contains(p)) {
@@ -450,7 +444,7 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, NR::Poi
             double th_max = (0.6 - 0.59*sqrt(fidelity)) / NR::expansion(i2doc);
             double threshold = MAX(th_max, th_max*force);
             res->ConvertEvenLines(threshold);
-            res->Simplify(threshold / (SP_ACTIVE_DESKTOP->current_zoom()));
+            res->Simplify(threshold / (selection->desktop()->current_zoom()));
 
             if (newrepr) { // converting to path, need to replace the repr
                 bool is_selected = selection->includes(item);
@@ -609,7 +603,7 @@ tweak_colors_in_gradient (SPItem *item, bool fill_or_stroke,
     if (!gradient || !SP_IS_GRADIENT(gradient))
         return;
 
-    NR::Matrix i2d = sp_item_i2doc_affine (item);
+    NR::Matrix i2d (sp_item_i2doc_affine (item));
     NR::Point p = p_w * i2d.inverse();
     p *= (gradient->gradientTransform).inverse();
     // now p is in gradient's original coordinates
@@ -732,7 +726,7 @@ sp_tweak_color_recursive (guint mode, SPItem *item, SPItem *item_at_point,
                                           fill_goal, do_fill,
                                           stroke_goal, do_stroke,
                                           opacity_goal, do_opacity,
-                                          p, radius, force, do_h, do_s, do_l, do_o));
+                                          p, radius, force, do_h, do_s, do_l, do_o))
                     did = true;
             }
         }
@@ -742,7 +736,7 @@ sp_tweak_color_recursive (guint mode, SPItem *item, SPItem *item_at_point,
         if (!style) {
             return false;
         }
-        NR::Maybe<NR::Rect> bbox = item->getBounds(sp_item_i2doc_affine(item),
+        boost::optional<NR::Rect> bbox = item->getBounds(sp_item_i2doc_affine(item),
                                                         SPItem::GEOMETRIC_BBOX);
         if (!bbox) {
             return false;
@@ -805,6 +799,7 @@ bool
 sp_tweak_dilate (SPTweakContext *tc, NR::Point event_p, NR::Point p, NR::Point vector)
 {
     Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(tc)->desktop);
+    SPDesktop *desktop = SP_EVENT_CONTEXT(tc)->desktop;
 
     if (selection->isEmpty()) {
         return false;
@@ -819,30 +814,11 @@ sp_tweak_dilate (SPTweakContext *tc, NR::Point event_p, NR::Point p, NR::Point v
     double color_force = MIN(sqrt(force)/20.0, 1);
 
     SPItem *item_at_point = SP_EVENT_CONTEXT(tc)->desktop->item_at_point(event_p, TRUE);
-    Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, "tools.tweak");
-    SPCSSAttr *css = sp_repr_css_attr_inherited(tool_repr, "style");
-    if (tc->mode == TWEAK_MODE_COLORPAINT && !css)
-        return false;
 
     bool do_fill = false, do_stroke = false, do_opacity = false;
-    guint32 fill_goal = 0, stroke_goal = 0;
-    float opacity_goal = 1;
-
-    const gchar *fill_prop = sp_repr_css_property(css, "fill", NULL);
-    if (fill_prop && strcmp(fill_prop, "none")) {
-        do_fill = true;
-        fill_goal = sp_svg_read_color(fill_prop, 0);
-    }
-    const gchar *stroke_prop = sp_repr_css_property(css, "stroke", NULL);
-    if (stroke_prop && strcmp(stroke_prop, "none")) {
-        do_stroke = true;
-        stroke_goal = sp_svg_read_color(stroke_prop, 0);
-    }
-    const gchar *opacity_prop = sp_repr_css_property(css, "opacity", NULL);
-    if (opacity_prop) {
-        do_opacity = true;
-        sp_svg_number_read_f(opacity_prop, &opacity_goal);
-    }
+    guint32 fill_goal = sp_desktop_get_color_tool(desktop, "tools.tweak", true, &do_fill);
+    guint32 stroke_goal = sp_desktop_get_color_tool(desktop, "tools.tweak", false, &do_stroke);
+    double opacity_goal = sp_desktop_get_master_opacity_tool(desktop, "tools.tweak", &do_opacity);
 
     for (GSList *items = g_slist_copy((GSList *) selection->itemList());
          items != NULL;