From bbde5dbeeb06611e99f9fa7f73dafe3bf70df01c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 27 Aug 2017 12:55:26 +0200 Subject: Working on preview over powerpencil --- src/ui/tools/freehand-base.cpp | 65 +++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 33 deletions(-) (limited to 'src/ui/tools/freehand-base.cpp') diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index 05afd8058..fba3c8397 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -237,40 +237,36 @@ static void spdc_apply_powerstroke_shape(std::vector points, Freeha Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 3) { SPShape *sp_shape = dynamic_cast(item); - Geom::PathVector pathvector; if (sp_shape) { - pathvector = sp_shape->getCurve()->get_pathvector(); - size_t counter = 0; + SPCurve * c = sp_shape->getCurve(); + if (!c) { + return; + } auto wps = pt->wps.begin(); - double previous_pos = 0.0; for (auto pps = pt->pps.begin(); pps != pt->pps.end(); ++pps,++wps) { - counter++; - Geom::Affine transformCoordinate = item->i2dt_affine(); - Geom::Point position = *pps; - position *= transformCoordinate.inverse(); - double pos = Geom::nearest_time(position, paths_to_pw(pathvector)); - double width = *wps; - if(pos > 1e6) { - pos = 0;; - } - if(pos > pathvector[0].size() ) { - pos = pathvector[0].size(); - } - if ((pos - previous_pos) < pt->min_distance || - (counter == pt->wps.size() || (pos - previous_pos) < 0.1) ) - { - continue; - } - previous_pos = pos; - if (!Geom::are_near(width, 0.0, 0.1) ) { - points.push_back(Geom::Point(pos,width)); - } + pt->addPowerStrokePoint(c, *pps, *wps); + } + } + if(pt->points.empty()){ + //if use mouse give a line + double zoom = SP_EVENT_CONTEXT(dc)->desktop->current_zoom() * 5.0; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + double min = prefs->getIntLimited("/tools/freehand/pencil/minpressure", 0, 1, 100) / 100.0; + double max = prefs->getIntLimited("/tools/freehand/pencil/maxpressure", 100, 1, 100) / 100.0; + if (min > max){ + min = max; } + Geom::Affine transformCoordinate = SP_ITEM(SP_ACTIVE_DESKTOP->currentLayer())->i2dt_affine(); + Geom::Coord scale = transformCoordinate.expansionX(); + double pressure_shirnked = (1.0 * (max - min)) + min; + double pressure_computed = (pressure_shirnked * 8.0 * scale) / zoom; + pt->points.push_back(Geom::Point(0,pressure_computed)); } Effect::createAndApply(POWERSTROKE, dc->desktop->doc(), item); Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE(); - static_cast(lpe)->offset_points.param_set_and_write_new_value(points); + static_cast(lpe)->offset_points.param_set_and_write_new_value(pt->points); + pt->points.clear(); return; } } @@ -389,13 +385,7 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, if (sp_shape) { curve = sp_shape->getCurve(); } - if (SP_IS_PENCIL_CONTEXT(dc)) { - if (prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 3) { - std::vector points; - spdc_apply_powerstroke_shape(points, dc, item); - shape = NONE; - } - } + 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"); @@ -407,6 +397,15 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, if (!swidth) { swidth = swidth/2; } + if (SP_IS_PENCIL_CONTEXT(dc)) { + if (prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 3) { + std::vector points; + spdc_apply_powerstroke_shape(points, dc, item); + shape = NONE; + //To allow retain color + shape_applied = true; + } + } #define SHAPE_LENGTH 10 #define SHAPE_HEIGHT 10 -- cgit v1.2.3