summaryrefslogtreecommitdiffstats
path: root/src/ui/tools/freehand-base.cpp
diff options
context:
space:
mode:
authorLiam P. White <inkscapebrony@gmail.com>2014-08-08 15:04:56 +0000
committerLiam P. White <inkscapebrony@gmail.com>2014-08-08 15:04:56 +0000
commitca8023872ae0d9f7b99688502b9bdba232ec5627 (patch)
tree73092b0aa6ea3e697da66d1d6316d3a2d78a4f3e /src/ui/tools/freehand-base.cpp
parentUpdate to experimental r13440 (diff)
parentSmall tweak to bbox calculation (diff)
downloadinkscape-ca8023872ae0d9f7b99688502b9bdba232ec5627.tar.gz
inkscape-ca8023872ae0d9f7b99688502b9bdba232ec5627.zip
Update to experimental r13464
(bzr r13341.5.14)
Diffstat (limited to 'src/ui/tools/freehand-base.cpp')
-rw-r--r--src/ui/tools/freehand-base.cpp73
1 files changed, 67 insertions, 6 deletions
diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp
index 1c5b7b8e3..aad924844 100644
--- a/src/ui/tools/freehand-base.cpp
+++ b/src/ui/tools/freehand-base.cpp
@@ -44,6 +44,8 @@
#include "live_effects/lpe-powerstroke.h"
#include "style.h"
#include "ui/control-manager.h"
+// clipboard support
+#include "ui/clipboard.h"
#include "ui/tools/freehand-base.h"
#include <gdk/gdkkeysyms.h>
@@ -238,6 +240,31 @@ static void spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points
Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE();
static_cast<LPEPowerStroke*>(lpe)->offset_points.param_set_and_write_new_value(points);
+ // find out stroke width (TODO: is there an easier way??)
+ SPDesktop *desktop = dc->desktop;
+ Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
+ Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
+ Inkscape::GC::release(repr);
+
+ char const* tool = SP_IS_PEN_CONTEXT(dc) ? "/tools/freehand/pen" : "/tools/freehand/pencil";
+
+ // apply the tool's current style
+ sp_desktop_apply_style_tool(desktop, repr, tool, false);
+
+ double stroke_width = 1.0;
+ char const *style_str = NULL;
+ style_str = repr->attribute("style");
+ if (style_str) {
+ SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT);
+ sp_style_merge_from_style_string(style, style_str);
+ stroke_width = style->stroke_width.computed;
+ style->stroke_width.computed = 0;
+ sp_style_unref(style);
+ }
+
+ char * width_str = new char[50];
+ sprintf(width_str, "0,%f", stroke_width / 2.);
+
// write powerstroke parameters:
lpe->getRepr()->setAttribute("start_linecap_type", "zerowidth");
lpe->getRepr()->setAttribute("end_linecap_type", "zerowidth");
@@ -245,6 +272,9 @@ static void spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points
lpe->getRepr()->setAttribute("sort_points", "true");
lpe->getRepr()->setAttribute("interpolator_type", "CubicBezierJohan");
lpe->getRepr()->setAttribute("interpolator_beta", "0.2");
+ lpe->getRepr()->setAttribute("offset_points", width_str);
+
+ delete [] width_str;
}
static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, SPCurve *curve)
@@ -261,7 +291,13 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
Effect::createAndApply(BSPLINE, dc->desktop->doc(), item);
}
- int shape = prefs->getInt(tool_name(dc) + "/shape", 0);
+ //Store the clipboard path to apply in the future without the use of clipboard
+ static Geom::PathVector previous_shape_pathv;
+ enum shapeType { NONE, TRIANGLE_IN, TRIANGLE_OUT, ELLIPSE, CLIPBOARD, LAST_APPLIED };
+ static shapeType previous_shape_type = NONE;
+
+
+ shapeType shape = (shapeType)prefs->getInt(tool_name(dc) + "/shape", 0);
bool shape_applied = false;
SPCSSAttr *css_item = sp_css_attr_from_object(item, SP_STYLE_FLAG_ALWAYS);
const char *cstroke = sp_repr_css_property(css_item, "stroke", "none");
@@ -269,11 +305,18 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
#define SHAPE_LENGTH 10
#define SHAPE_HEIGHT 10
+ if(shape == LAST_APPLIED){
+ shape = previous_shape_type;
+ if(shape == CLIPBOARD){
+ shape = LAST_APPLIED;
+ }
+ }
+
switch (shape) {
- case 0:
+ case NONE:
// don't apply any shape
break;
- case 1:
+ case TRIANGLE_IN:
{
// "triangle in"
std::vector<Geom::Point> points(1);
@@ -283,7 +326,7 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
shape_applied = true;
break;
}
- case 2:
+ case TRIANGLE_OUT:
{
// "triangle out"
guint curve_length = curve->get_segment_count();
@@ -294,7 +337,7 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
shape_applied = true;
break;
}
- case 3:
+ case ELLIPSE:
{
// "ellipse"
SPCurve *c = new SPCurve();
@@ -307,22 +350,40 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
c->closepath();
spdc_paste_curve_as_freehand_shape(c, dc, item);
c->unref();
+
shape_applied = true;
break;
}
- case 4:
+ case CLIPBOARD:
{
// take shape from clipboard; TODO: catch the case where clipboard is empty
Effect::createAndApply(PATTERN_ALONG_PATH, dc->desktop->doc(), item);
Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE();
static_cast<LPEPatternAlongPath*>(lpe)->pattern.on_paste_button_click();
+ Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
+ Glib::ustring svgd = cm->getPathParameter(SP_ACTIVE_DESKTOP);
+ previous_shape_pathv = sp_svg_read_pathv(svgd.data());
shape_applied = true;
break;
}
+ case LAST_APPLIED:
+ {
+ if(previous_shape_pathv.size() != 0){
+ SPCurve * c = new SPCurve();
+ c->set_pathvector(previous_shape_pathv);
+ spdc_paste_curve_as_freehand_shape(c, dc, item);
+ c->unref();
+
+ shape_applied = true;
+ }
+ break;
+ }
default:
break;
}
+ previous_shape_type = shape;
+
if (shape_applied) {
// apply original stroke color as fill and unset stroke; then return
SPCSSAttr *css = sp_repr_css_attr_new();