From cea94017f3a35b0f678affd5b0a012a84885dea6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 19 Oct 2015 19:48:53 +0200 Subject: fixing roughen (bzr r14422.1.1) --- src/live_effects/lpe-roughen.cpp | 69 +++++++++++++++++++++------------------- src/live_effects/lpe-roughen.h | 3 +- 2 files changed, 39 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index cea91509e..44f9c6be5 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -183,19 +183,15 @@ double LPERoughen::sign(double random_number) return random_number; } -Geom::Point LPERoughen::randomize(double max_lenght, double direction) +Geom::Point LPERoughen::randomize(double max_lenght, bool is_node) { - double displace_x_parsed = displace_x * global_randomize; - double displace_y_parsed = displace_y * global_randomize; - Geom::Point output = Geom::Point(sign(displace_x_parsed), sign(displace_y_parsed)); - if( direction != 0){ - int angle = (int)max_smooth_angle; - if (angle == 0){ - angle = 1; - } - double dist = Geom::distance(Geom::Point(0,0),output); - output = Geom::Point::polar(direction + sign(Geom::deg_to_rad(rand() % angle)), dist); + double factor = 1.0/3.0; + if(is_node){ + factor = 1.0; } + double displace_x_parsed = displace_x * global_randomize * factor; + double displace_y_parsed = displace_y * global_randomize * factor; + Geom::Point output = Geom::Point(sign(displace_x_parsed), sign(displace_y_parsed)); if( fixed_displacement ){ Geom::Ray ray(Geom::Point(0,0),output); output = Geom::Point::polar(ray.angle(), max_lenght); @@ -203,6 +199,19 @@ Geom::Point LPERoughen::randomize(double max_lenght, double direction) return output; } +Geom::Point LPERoughen::randomize(double lenght, Geom::Point start, Geom::Point end) +{ + int angle = (int)max_smooth_angle; + if (angle == 0){ + angle = 1; + } + Geom::Ray ray(start, end); + if(!fixed_displacement ){ + lenght = Geom::distance(start, end); + } + return Geom::Point::polar(ray.angle() + sign(Geom::deg_to_rad(rand() % angle)), lenght) + start; +} + void LPERoughen::doEffect(SPCurve *curve) { Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(curve->get_pathvector()); @@ -317,9 +326,9 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point Geom::Point point_b2(0, 0); Geom::Point point_b3(0, 0); if (shift_nodes) { - point_a3 = randomize(max_lenght); + point_a3 = randomize(max_lenght, true); if(last){ - point_b3 = randomize(max_lenght); + point_b3 = randomize(max_lenght, true); } } if (handles == HM_RAND || handles == HM_SMOOTH) { @@ -350,42 +359,38 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point std::pair div = cubic->subdivide(t); std::vector seg1 = div.first.controlPoints(), seg2 = div.second.controlPoints(); + point_b3 = seg2[3] + point_b3; + point_a3 = seg1[3] + point_a3; + point_b1 = randomize(max_lenght, point_a3, seg2[1]); + point_b2 = seg1[2] + point_b2; Geom::Ray ray(prev,A->initialPoint()); - point_a1 = Geom::Point::polar(ray.angle(), max_lenght); + point_a1 = A->initialPoint() + Geom::Point::polar(ray.angle(), max_lenght); if(prev == Geom::Point(0,0)){ point_a1 = randomize(max_lenght); } - ray.setPoints(seg1[3] + point_a3, seg2[1] + point_a3); - point_b1 = randomize(max_lenght, ray.angle()); if(last){ - ray.setPoints(seg2[3] + point_b3, A->pointAt(1 - (t / 3)) + point_b3); - point_b2 = randomize(max_lenght, ray.angle()); + ray.setPoints(point_b3, point_a3); + point_b2 = randomize(max_lenght, point_b3, ray.pointAt(100.0/3.0)); } - ray.setPoints(seg2[1] + point_a3 + point_b1, seg2[0] + point_a3); - point_a2 = Geom::Point::polar(ray.angle(), max_lenght); + ray.setPoints(point_b1, point_a3); + point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); if(last){ - prev = A->pointAt(1 - (t / 3)) + point_b2 + point_b3; + prev = point_b2; } else { - prev = seg1[3] + point_a2 + point_a3; + prev = point_a2; } out->moveto(seg1[0]); - out->curveto(seg1[0] + point_a1, seg1[3] + point_a2 + point_a3, seg1[3] + point_a3); - if(last){ - out->curveto(seg2[1] + point_a3 + point_b1, A->pointAt(1 - (t / 3)) + point_b2 + point_b3, seg2[3] + point_b3); - } else { - out->curveto(seg2[1] + point_a3 + point_b1, seg2[2] + point_b2 + point_b3, seg2[3] + point_b3); - } + out->curveto(point_a1,point_a2,point_a3); + out->curveto(point_b1, point_b2, point_b3); } else if(handles == HM_SMOOTH && !cubic) { Geom::Ray ray(prev,A->initialPoint()); point_a1 = Geom::Point::polar(ray.angle(), max_lenght); if(prev==Geom::Point(0,0)){ point_a1 = randomize(max_lenght); } - ray.setPoints(A->pointAt(t) + point_a3, A->pointAt(t + (t / 3)) + point_a3); - point_b1 = randomize(max_lenght, ray.angle()); + point_b1 = randomize(max_lenght, A->pointAt(t) + point_a3, A->pointAt(t + (t / 3)) + point_a3); if(last){ - ray.setPoints(A->finalPoint() + point_b3, A->pointAt(t +((t / 3) * 2)) + point_b3); - point_b2 = randomize(max_lenght, ray.angle()); + point_b2 = randomize(max_lenght, A->finalPoint() + point_b3, A->pointAt(t +((t / 3) * 2)) + point_b3); } ray.setPoints(A->pointAt(t + (t / 3)) + point_a3 + point_b1, A->pointAt(t) + point_a3); point_a2 = Geom::Point::polar(ray.angle(), max_lenght); diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index e3ede2c2d..6224c09fa 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -45,7 +45,8 @@ public: virtual void doEffect(SPCurve *curve); virtual double sign(double randNumber); - virtual Geom::Point randomize(double max_lenght, double direction = 0); + virtual Geom::Point randomize(double max_lenght, bool is_node = false); + virtual Geom::Point randomize(double lenght, Geom::Point start, Geom::Point end); virtual void doBeforeEffect(SPLPEItem const * lpeitem); virtual SPCurve const * addNodesAndJitter(Geom::Curve const * A, Geom::Point &prev, Geom::Point &last_move, double t, bool last); virtual SPCurve *jitter(Geom::Curve const * A, Geom::Point &prev, Geom::Point &last_move); -- cgit v1.2.3 From ccdb4ca4cc4aa57445c770c8410d68f777cf6ba2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 20 Oct 2015 01:06:16 +0200 Subject: working 2 ways (bzr r14422.1.2) --- src/live_effects/lpe-roughen.cpp | 34 +++++++++++++++++++-------------- src/ui/tools/spray-tool.cpp | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 44f9c6be5..55ca77e9c 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -359,18 +359,19 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point std::pair div = cubic->subdivide(t); std::vector seg1 = div.first.controlPoints(), seg2 = div.second.controlPoints(); + point_b1 = randomize(max_lenght, seg1[3] + point_a3, seg2[1] + point_a3); + point_b2 = seg1[2]; point_b3 = seg2[3] + point_b3; point_a3 = seg1[3] + point_a3; - point_b1 = randomize(max_lenght, point_a3, seg2[1]); - point_b2 = seg1[2] + point_b2; Geom::Ray ray(prev,A->initialPoint()); point_a1 = A->initialPoint() + Geom::Point::polar(ray.angle(), max_lenght); if(prev == Geom::Point(0,0)){ point_a1 = randomize(max_lenght); } if(last){ - ray.setPoints(point_b3, point_a3); - point_b2 = randomize(max_lenght, point_b3, ray.pointAt(100.0/3.0)); + Geom::Path b2(point_b3); + b2.appendNew(point_a3); + point_b2 = randomize(max_lenght, point_b3, b2.pointAt(1.0/3.0)); } ray.setPoints(point_b1, point_a3); point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); @@ -383,25 +384,30 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point out->curveto(point_a1,point_a2,point_a3); out->curveto(point_b1, point_b2, point_b3); } else if(handles == HM_SMOOTH && !cubic) { + point_b1 = randomize(max_lenght, A->pointAt(t) + point_a3, A->pointAt(t + (t / 3))); + point_b2 = A->pointAt(t +((t / 3) * 2)); + point_b3 = A->finalPoint() + point_b3; + point_a3 = A->pointAt(t) + point_a3; Geom::Ray ray(prev,A->initialPoint()); - point_a1 = Geom::Point::polar(ray.angle(), max_lenght); - if(prev==Geom::Point(0,0)){ + point_a1 = A->initialPoint() + Geom::Point::polar(ray.angle(), max_lenght); + if(prev == Geom::Point(0,0)){ point_a1 = randomize(max_lenght); } - point_b1 = randomize(max_lenght, A->pointAt(t) + point_a3, A->pointAt(t + (t / 3)) + point_a3); if(last){ - point_b2 = randomize(max_lenght, A->finalPoint() + point_b3, A->pointAt(t +((t / 3) * 2)) + point_b3); + Geom::Path b2(point_b3); + b2.appendNew(point_a3); + point_b2 = randomize(max_lenght, point_b3, b2.pointAt(1.0/3.0)); } - ray.setPoints(A->pointAt(t + (t / 3)) + point_a3 + point_b1, A->pointAt(t) + point_a3); - point_a2 = Geom::Point::polar(ray.angle(), max_lenght); + ray.setPoints(point_b1, point_a3); + point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); if(last){ - prev = A->pointAt(t +((t / 3) * 2)) + point_b2 + point_b3; + prev = point_b2; } else { - prev = A->pointAt(t) + point_a3 + point_a2; + prev = point_a2; } out->moveto(A->initialPoint()); - out->curveto(A->initialPoint() + point_a1, A->pointAt(t) + point_a3 + point_a2, A->pointAt(t) + point_a3); - out->curveto(A->pointAt(t + (t / 3)) + point_a3 + point_b1, A->pointAt(t +((t / 3) * 2)) + point_b2 + point_b3, A->finalPoint() + point_b3); + out->curveto(point_a1,point_a2,point_a3); + out->curveto(point_b1, point_b2, point_b3); } else if (cubic) { std::pair div = cubic->subdivide(t); std::vector seg1 = div.first.controlPoints(), diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index e2be5ca4b..240d002ae 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -380,6 +380,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, Inkscape::XML::Node *old_repr = item->getRepr(); Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + copy->setAttribute("inkscape:spray-origin", item->getId()); parent->appendChild(copy); SPObject *new_obj = doc->getObjectByRepr(copy); @@ -393,6 +394,46 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); did = true; + Geom::OptRect bbox = item_copied->desktopGeometricBounds(); + std::vector items = desktop->getDocument()->getItemsInBox(desktop->dkey, *bbox); + for (std::vector::const_iterator i=items.begin(); i!=items.end(); i++) { + SPItem *item_down = *i; + std::cout << item_down->getAttribute("inkscape:spray-origin") << "asdgfasdasas\n"; + if(item_down->getAttribute("inkscape:spray-origin") &&( strcmp(item_down->getAttribute("inkscape:spray-origin"),item->getId()) == 0 || strcmp(item_down->getId(),item->getId()) == 0)){ + if(!SP_IS_GROUP(item)){ + SPShape *down_item_shape = dynamic_cast(item_down); + if (down_item_shape) { + Geom::PathVector c; + SPPath *down_item_path = dynamic_cast(down_item_shape); + if (down_item_path) { + c = down_item_path->get_curve()->get_pathvector(); + } else { + c = down_item_shape->getCurve()->get_pathvector(); + } + if (c) { + SPShape *copied_item_shape = dynamic_cast(item_copied); + if (copied_item_shape) { + Geom::PathVector d; + SPPath *copied_item_path = dynamic_cast(copied_item_shape); + if (copied_item_path) { + d = copied_item_path->get_curve()->get_pathvector(); + } else { + d = copied_item_shape->getCurve()->get_pathvector(); + } + if (d) { + Geom::CrossingSet cs = Geom::crossings(c,d); + if(cs[0].size() == 0){ + continue; + } + } + } + } + } + item_copied->deleteObject(); + std::cout << item_down->getAttribute("inkscape:spray-origin") << "hasssss\n"; + did = false; + } + } } } #ifdef ENABLE_SPRAY_MODE_SINGLE_PATH -- cgit v1.2.3 From 913cb932fefc97f72cc834beb4129f833ccdd25a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 22 Oct 2015 08:25:32 +0200 Subject: improving spray tool (bzr r14422.2.1) --- src/ui/tools/spray-tool.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 240d002ae..c6448f818 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -57,6 +57,9 @@ #include "livarot/Shape.h" #include <2geom/circle.h> #include <2geom/transforms.h> +#include <2geom/path-intersection.h> +#include <2geom/pathvector.h> +#include <2geom/crossing.h> #include "preferences.h" #include "style.h" #include "box3d.h" @@ -380,7 +383,10 @@ static bool sp_spray_recursive(SPDesktop *desktop, Inkscape::XML::Node *old_repr = item->getRepr(); Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - copy->setAttribute("inkscape:spray-origin", item->getId()); + std::stringstream original_id; + original_id << "#" << item->getId(); + gchar const * spray_origin = original_id.str().c_str()); + copy->setAttribute("inkscape:spray-origin", spray_origin); parent->appendChild(copy); SPObject *new_obj = doc->getObjectByRepr(copy); @@ -394,44 +400,46 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); did = true; - Geom::OptRect bbox = item_copied->desktopGeometricBounds(); + Geom::OptRect bbox = item_copied->documentVisualBounds(); std::vector items = desktop->getDocument()->getItemsInBox(desktop->dkey, *bbox); for (std::vector::const_iterator i=items.begin(); i!=items.end(); i++) { SPItem *item_down = *i; std::cout << item_down->getAttribute("inkscape:spray-origin") << "asdgfasdasas\n"; - if(item_down->getAttribute("inkscape:spray-origin") &&( strcmp(item_down->getAttribute("inkscape:spray-origin"),item->getId()) == 0 || strcmp(item_down->getId(),item->getId()) == 0)){ + if(item_down->getAttribute("inkscape:spray-origin") &&( strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 || strcmp(item_down->getId(),item->getId()) == 0)){ if(!SP_IS_GROUP(item)){ SPShape *down_item_shape = dynamic_cast(item_down); if (down_item_shape) { - Geom::PathVector c; + Geom::PathVector pathv; SPPath *down_item_path = dynamic_cast(down_item_shape); if (down_item_path) { - c = down_item_path->get_curve()->get_pathvector(); + pathv = down_item_path->get_curve()->get_pathvector(); } else { - c = down_item_shape->getCurve()->get_pathvector(); + pathv = down_item_shape->getCurve()->get_pathvector(); } - if (c) { + if (!pathv.empty()) { SPShape *copied_item_shape = dynamic_cast(item_copied); if (copied_item_shape) { - Geom::PathVector d; + Geom::PathVector pathv_other; SPPath *copied_item_path = dynamic_cast(copied_item_shape); if (copied_item_path) { - d = copied_item_path->get_curve()->get_pathvector(); + pathv_other = copied_item_path->get_curve()->get_pathvector(); } else { - d = copied_item_shape->getCurve()->get_pathvector(); + pathv_other = copied_item_shape->getCurve()->get_pathvector(); } - if (d) { - Geom::CrossingSet cs = Geom::crossings(c,d); + if (!pathv_other.empty()) { + Geom::CrossingSet cs = Geom::crossings(pathv, pathv_other); if(cs[0].size() == 0){ continue; } } + } } } } item_copied->deleteObject(); std::cout << item_down->getAttribute("inkscape:spray-origin") << "hasssss\n"; did = false; + break; } } } -- cgit v1.2.3 From 955f8ffeb6debbbd215314624def36f1fe8276b9 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 23 Oct 2015 02:22:31 +0200 Subject: Improving spray tool (bzr r14422.1.5) --- src/ui/tools/spray-tool.cpp | 46 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index ad390ed0d..3085a870b 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -341,6 +341,8 @@ static bool fit_item(SPDesktop *desktop, Geom::Point center, double scale, double scale_variation, + Geom::Point p, + Geom::Point move, size_t limit){ Geom::OptRect bbox = item_copied->desktopVisualBounds(); std::vector items = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox); @@ -378,16 +380,20 @@ static bool fit_item(SPDesktop *desktop, // } // } // } - if(limit > 10){ + if(limit > 3){ item_copied->deleteObject(); return false; } else { sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(-scale, -scale)); - scale = (1.0 - scale_variation / 100.0) + ((1.0 + scale_variation / 100.0)/limit); + sp_item_move_rel(item_copied, Geom::Translate(Geom::Point(-move[Geom::X], move[Geom::Y]))); + Geom::Path path; + path.start(Geom::Point(move[Geom::X],-move[Geom::Y])); + path.appendNew(p); + scale = (1.0 - scale_variation / 100.0) + (scale/(limit+2)); sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale, scale)); - sp_item_move_rel(item_copied, Geom::Translate(rand() % 20 -10, rand() % 20 -10)); + sp_item_move_rel(item_copied, Geom::Translate(path.pointAt(1/(limit+2)))); limit += 1; - return fit_item(desktop, item_copied, item, spray_origin, center, scale, scale_variation, limit); + return fit_item(desktop, item_copied, item, spray_origin, center, scale, scale_variation, p, move, limit); } } } @@ -442,10 +448,13 @@ static bool sp_spray_recursive(SPDesktop *desktop, Inkscape::XML::Node *old_repr = item->getRepr(); Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - std::stringstream original_id; - original_id << "#" << item->getId(); - gchar const * spray_origin = original_id.str().c_str(); - copy->setAttribute("inkscape:spray-origin", spray_origin); + gchar const * spray_origin; + if(!copy->attribute("inkscape:spray-origin")){ + spray_origin = g_strdup_printf("#%s", old_repr->attribute("id")); + copy->setAttribute("inkscape:spray-origin", spray_origin); + } else { + spray_origin = copy->attribute("inkscape:spray-origin"); + } parent->appendChild(copy); SPObject *new_obj = doc->getObjectByRepr(copy); @@ -458,7 +467,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, // Move the cursor p Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); - did = fit_item(desktop, item_copied, item, spray_origin, center, scale_variation, _scale, 0); + Inkscape::GC::release(copy); + did = fit_item(desktop, item_copied, item, spray_origin, center, scale_variation, _scale, p , move , 9); } } #ifdef ENABLE_SPRAY_MODE_SINGLE_PATH @@ -491,6 +501,13 @@ static bool sp_spray_recursive(SPDesktop *desktop, if (_fid <= population) { // Rules the population of objects sprayed // Duplicates the parent item Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + gchar const * spray_origin; + if(!copy->attribute("inkscape:spray-origin")){ + spray_origin = g_strdup_printf("#%s", old_repr->attribute("id")); + copy->setAttribute("inkscape:spray-origin", spray_origin); + } else { + spray_origin = copy->attribute("inkscape:spray-origin"); + } parent->appendChild(copy); SPObject *new_obj = doc->getObjectByRepr(copy); item_copied = dynamic_cast(new_obj); @@ -513,7 +530,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, sp_selected_path_union_skip_undo(selection, selection->desktop()); selection->add(parent_item); Inkscape::GC::release(copy); - did = true; + did = fit_item(desktop, item_copied, parent_item, spray_origin, center, scale_variation, _scale, p , move , 9); } } } @@ -533,6 +550,13 @@ static bool sp_spray_recursive(SPDesktop *desktop, // Ad the clone to the list of the parent's children parent->appendChild(clone); // Generates the link between parent and child attributes + gchar const * spray_origin; + if(!clone->attribute("inkscape:spray-origin")){ + spray_origin = g_strdup_printf("#%s", old_repr->attribute("id")); + clone->setAttribute("inkscape:spray-origin", spray_origin); + } else { + spray_origin = clone->attribute("inkscape:spray-origin"); + } gchar *href_str = g_strdup_printf("#%s", old_repr->attribute("id")); clone->setAttribute("xlink:href", href_str, false); g_free(href_str); @@ -549,7 +573,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, Inkscape::GC::release(clone); - did = true; + did = fit_item(desktop, item_copied, item, spray_origin, center, scale_variation, _scale, p , move , 9); } } } -- cgit v1.2.3 From 51c0ac71d4f52566be5f084274a64eb0a2ee38be Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 23 Oct 2015 21:25:43 +0200 Subject: Working on spray tool (bzr r14422.1.6) --- src/ui/tools/spray-tool.cpp | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 3085a870b..040678b51 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -339,16 +339,17 @@ static bool fit_item(SPDesktop *desktop, SPItem * item, gchar const * spray_origin, Geom::Point center, - double scale, + double _scale, double scale_variation, + double &scale, + double angle, Geom::Point p, - Geom::Point move, - size_t limit){ + Geom::Point move){ Geom::OptRect bbox = item_copied->desktopVisualBounds(); std::vector items = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox); for (std::vector::const_iterator i=items.begin(); i!=items.end(); i++) { SPItem *item_down = *i; - Geom::OptRect bbox = item_down->desktopVisualBounds(); + bbox = item_down->desktopVisualBounds(); if(item_down->getId() == item->getId() || (item_down->getAttribute("inkscape:spray-origin") && item_down != item_copied && strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0)){ // if(!SP_IS_GROUP(item) && 1>2){ // SPShape *down_item_shape = dynamic_cast(item_down); @@ -380,20 +381,26 @@ static bool fit_item(SPDesktop *desktop, // } // } // } - if(limit > 3){ + sp_item_move_rel(item_copied, Geom::Translate(-move[Geom::X], move[Geom::Y])); + sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle).inverse()); + sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale).inverse()); + sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale, _scale).inverse()); + + double min_scale = (1.0 - scale_variation / 100.0); + _scale = min_scale + ((_scale - min_scale)/2); + sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale, _scale)); + sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale)); + sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle)); + sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); + bbox = item_copied->desktopVisualBounds(); + if(bbox->intersects(item_down->desktopVisualBounds())){ + std::cout << "deleted\n"; item_copied->deleteObject(); return false; } else { - sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(-scale, -scale)); - sp_item_move_rel(item_copied, Geom::Translate(Geom::Point(-move[Geom::X], move[Geom::Y]))); - Geom::Path path; - path.start(Geom::Point(move[Geom::X],-move[Geom::Y])); - path.appendNew(p); - scale = (1.0 - scale_variation / 100.0) + (scale/(limit+2)); - sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale, scale)); - sp_item_move_rel(item_copied, Geom::Translate(path.pointAt(1/(limit+2)))); - limit += 1; - return fit_item(desktop, item_copied, item, spray_origin, center, scale, scale_variation, p, move, limit); + std::cout << "applied\n"; + //if the element fit no other can be down so saefly return + return true; } } } @@ -468,7 +475,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); Inkscape::GC::release(copy); - did = fit_item(desktop, item_copied, item, spray_origin, center, scale_variation, _scale, p , move , 9); + did = fit_item(desktop, item_copied, item, spray_origin, center, scale_variation, _scale, scale, angle, p , move); } } #ifdef ENABLE_SPRAY_MODE_SINGLE_PATH @@ -530,7 +537,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, sp_selected_path_union_skip_undo(selection, selection->desktop()); selection->add(parent_item); Inkscape::GC::release(copy); - did = fit_item(desktop, item_copied, parent_item, spray_origin, center, scale_variation, _scale, p , move , 9); + did = fit_item(desktop, item_copied, parent_item, spray_origin, center, scale_variation, _scale, scale, angle, p , move); } } } @@ -573,7 +580,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, Inkscape::GC::release(clone); - did = fit_item(desktop, item_copied, item, spray_origin, center, scale_variation, _scale, p , move , 9); + did = fit_item(desktop, item_copied, item, spray_origin, center, scale_variation, _scale, scale, angle, p , move); } } } -- cgit v1.2.3 From 2bd48486ba7584cc0eb6aa2c034f08b9c589ea5f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 24 Oct 2015 16:55:14 +0200 Subject: working in a new way (bzr r14422.1.7) --- src/ui/tools/spray-tool.cpp | 162 +++++++++++++++++++++++++++--------------- src/ui/tools/spray-tool.h | 4 +- src/widgets/spray-toolbar.cpp | 38 ++++++++++ src/widgets/toolbox.cpp | 4 ++ 4 files changed, 151 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 040678b51..21fbeccd0 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -154,6 +154,9 @@ SprayTool::SprayTool() , is_dilating(false) , has_dilated(false) , dilate_area(NULL) + , overlap(false) + , offset(0) + , hidding_items() { } @@ -226,6 +229,8 @@ void SprayTool::setup() { sp_event_context_read(this, "standard_deviation"); sp_event_context_read(this, "usepressure"); sp_event_context_read(this, "Scale"); + sp_event_context_read(this, "offset"); + sp_event_context_read(this, "overlap"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/spray/selcue")) { @@ -263,6 +268,10 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->tilt = CLAMP(val.getDouble(0.1), 0, 1000.0); } else if (path == "ratio") { this->ratio = CLAMP(val.getDouble(), 0.0, 0.9); + } else if (path == "offset") { + this->offset = CLAMP(val.getDouble(), -1000.0, 1000.0); + } else if (path == "overlap") { + this->overlap = val.getBool(); } } @@ -307,6 +316,16 @@ static double get_move_standard_deviation(SprayTool *tc) return tc->standard_deviation; } +static double get_offset(SprayTool *tc) +{ + return tc->offset; +} + +static double get_overlap(SprayTool *tc) +{ + return tc->overlap; +} + /** * Method to handle the distribution of the items * @param[out] radius : radius of the position of the sprayed object @@ -335,22 +354,22 @@ static void random_position(double &radius, double &angle, double &a, double &s, } static bool fit_item(SPDesktop *desktop, - SPItem * item_copied, + Geom::OptRect bbox, SPItem * item, gchar const * spray_origin, - Geom::Point center, - double _scale, + double scale, double scale_variation, - double &scale, - double angle, - Geom::Point p, - Geom::Point move){ - Geom::OptRect bbox = item_copied->desktopVisualBounds(); - std::vector items = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox); - for (std::vector::const_iterator i=items.begin(); i!=items.end(); i++) { + std::vector hidding_items) +{ + std::vector items_down = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox); + for (std::vector::const_iterator i=items_down.begin(); i!=items_down.end(); i++) { SPItem *item_down = *i; - bbox = item_down->desktopVisualBounds(); - if(item_down->getId() == item->getId() || (item_down->getAttribute("inkscape:spray-origin") && item_down != item_copied && strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0)){ + gchar const * item_down_sharp = g_strdup_printf("#%s", item_down->getId()); + if(item_down_sharp == spray_origin || + (item_down->getAttribute("inkscape:spray-origin") && + strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 + ) + ){ // if(!SP_IS_GROUP(item) && 1>2){ // SPShape *down_item_shape = dynamic_cast(item_down); // if (down_item_shape) { @@ -381,28 +400,38 @@ static bool fit_item(SPDesktop *desktop, // } // } // } - sp_item_move_rel(item_copied, Geom::Translate(-move[Geom::X], move[Geom::Y])); - sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle).inverse()); - sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale).inverse()); - sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale, _scale).inverse()); - - double min_scale = (1.0 - scale_variation / 100.0); - _scale = min_scale + ((_scale - min_scale)/2); - sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale, _scale)); - sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale)); - sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle)); - sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); - bbox = item_copied->desktopVisualBounds(); - if(bbox->intersects(item_down->desktopVisualBounds())){ - std::cout << "deleted\n"; - item_copied->deleteObject(); - return false; - } else { - std::cout << "applied\n"; - //if the element fit no other can be down so saefly return - return true; - } +// sp_item_move_rel(item_copied, Geom::Translate(-move[Geom::X], move[Geom::Y])); +// sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle).inverse()); +// sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale).inverse()); +// sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale, _scale).inverse()); +// +// double min_scale = (1.0 - scale_variation / 100.0); +// _scale = min_scale + ((_scale - min_scale)/2); +// sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale, _scale)); +// sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale)); +// sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle)); +// sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); +// Geom::Point center = item_copied->getCenter(); +// sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale).inverse()); +// double min_scale = (1.0 - scale_variation / 100.0); +// scale = g_random_double_range(min_scale, 0.8); +// sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(scale)); +// bbox = item_copied->desktopVisualBounds(); +// if(bbox->intersects(item_down->desktopVisualBounds()) || +// bbox->contains(item_down->desktopVisualBounds()) +// ) +// { +// //this hack is for speed draw, moved and on release delete all at this point +// //item_copied->deleteObject(); +// item_copied->setHidden(true); +// hidding_items.push_back(item_copied); +// return true; +// } else { +// std::cout << "applied\n"; +// } + return false; } + std::cout << "not\n"; } return true; } @@ -423,7 +452,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, double ratio, double tilt, double rotation_variation, - gint _distrib) + gint _distrib, + std::vector hidding_items) { bool did = false; @@ -446,36 +476,52 @@ static bool sp_spray_recursive(SPDesktop *desktop, if (mode == SPRAY_MODE_COPY) { Geom::OptRect a = item->documentVisualBounds(); if (a) { - SPItem *item_copied; if(_fid <= population) { + gchar const * spray_origin; + if(!item->getAttribute("inkscape:spray-origin")){ + spray_origin = g_strdup_printf("#%s", item->getId()); + } else { + spray_origin = item->getAttribute("inkscape:spray-origin"); + } + Geom::Point center=item->getCenter(); + Geom::Rect rect(Geom::Point(a->top(), a->left()),Geom::Point(a->bottom(), a->right())); + Geom::Translate const s(center); + rect *= item->i2dt_affine() * s.inverse() * Geom::Scale(_scale) * s; + rect *= item->i2dt_affine() * s.inverse() * Geom::Scale(scale) * s; + rect *= item->i2dt_affine() * s.inverse() * Geom::Rotate(angle) * s; + Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); + rect *= item->i2dt_affine() * s.inverse() * Geom::Translate(move[Geom::X], -move[Geom::Y]) * s; + Geom::OptRect bbox_transformed(Geom::Point(rect.top(), rect.left()),Geom::Point(rect.bottom(), rect.right())); + if(!fit_item(desktop, bbox_transformed, item, spray_origin, _scale, scale_variation, hidding_items)){ + double min_scale = (1.0 - scale_variation / 100.0); + _scale = g_random_double_range(min_scale, 0.8); + center=item->getCenter(); + Geom::Translate const moved_center(center); + rect *= item->i2dt_affine() * moved_center.inverse() * Geom::Scale(_scale) * moved_center; + Geom::OptRect bbox_transformed2(Geom::Point(rect.top(), rect.left()),Geom::Point(rect.bottom(), rect.right())); + if(!fit_item(desktop, bbox_transformed2, item, spray_origin, _scale, scale_variation, hidding_items)){ + return false; + } + } + SPItem *item_copied; // Duplicate SPDocument *doc = item->document; Inkscape::XML::Document* xml_doc = doc->getReprDoc(); Inkscape::XML::Node *old_repr = item->getRepr(); Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - gchar const * spray_origin; - if(!copy->attribute("inkscape:spray-origin")){ - spray_origin = g_strdup_printf("#%s", old_repr->attribute("id")); - copy->setAttribute("inkscape:spray-origin", spray_origin); - } else { - spray_origin = copy->attribute("inkscape:spray-origin"); - } parent->appendChild(copy); - + copy->setAttribute("inkscape:spray-origin", spray_origin); SPObject *new_obj = doc->getObjectByRepr(copy); item_copied = dynamic_cast(new_obj); // Conversion object->item - Geom::Point center=item->getCenter(); sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale,_scale)); sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale)); - sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle)); // Move the cursor p - Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); Inkscape::GC::release(copy); - did = fit_item(desktop, item_copied, item, spray_origin, center, scale_variation, _scale, scale, angle, p , move); + did = true; } } #ifdef ENABLE_SPRAY_MODE_SINGLE_PATH @@ -537,7 +583,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, sp_selected_path_union_skip_undo(selection, selection->desktop()); selection->add(parent_item); Inkscape::GC::release(copy); - did = fit_item(desktop, item_copied, parent_item, spray_origin, center, scale_variation, _scale, scale, angle, p , move); + did = true; } } } @@ -579,8 +625,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); Inkscape::GC::release(clone); - - did = fit_item(desktop, item_copied, item, spray_origin, center, scale_variation, _scale, scale, angle, p , move); + did = true; } } } @@ -588,7 +633,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, return did; } -static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point p, Geom::Point vector, bool reverse) +static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point p, Geom::Point vector, bool reverse, std::vector hidding_items) { SPDesktop *desktop = tc->desktop; Inkscape::Selection *selection = desktop->getSelection(); @@ -627,7 +672,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point SPItem *item = *i; g_assert(item != NULL); - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib)) { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, hidding_items)) { did = true; } } @@ -687,7 +732,7 @@ bool SprayTool::root_handler(GdkEvent* event) { this->has_dilated = false; if(this->is_dilating && event->button.button == 1 && !this->space_panning) { - sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event)); + sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event), this->hidding_items); } this->has_dilated = true; @@ -717,7 +762,7 @@ bool SprayTool::root_handler(GdkEvent* event) { // Dilating: if (this->is_drawing && ( event->motion.state & GDK_BUTTON1_MASK )) { - sp_spray_dilate(this, motion_w, motion_doc, motion_doc - this->last_push, event->button.state & GDK_SHIFT_MASK? true : false); + sp_spray_dilate(this, motion_w, motion_doc, motion_doc - this->last_push, event->button.state & GDK_SHIFT_MASK? true : false, this->hidding_items); //this->last_push = motion_doc; this->has_dilated = true; @@ -750,7 +795,7 @@ bool SprayTool::root_handler(GdkEvent* event) { this->is_dilating = true; this->has_dilated = false; if(this->is_dilating && !this->space_panning) { - sp_spray_dilate(this, scroll_w, desktop->dt2doc(scroll_dt), Geom::Point(0,0), false); + sp_spray_dilate(this, scroll_w, desktop->dt2doc(scroll_dt), Geom::Point(0,0), false, this->hidding_items); } this->has_dilated = true; @@ -780,7 +825,7 @@ bool SprayTool::root_handler(GdkEvent* event) { if (!this->has_dilated) { // If we did not rub, do a light tap this->pressure = 0.03; - sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event)); + sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event), this->hidding_items); } this->is_dilating = false; this->has_dilated = false; @@ -798,6 +843,11 @@ bool SprayTool::root_handler(GdkEvent* event) { SP_VERB_CONTEXT_SPRAY, _("Spray in single path")); break; } + for (std::vector::const_iterator i=this->hidding_items.begin(); i!=this->hidding_items.end(); i++) { + SPItem *item = *i; + this->hidding_items.erase(i); + item->deleteObject(); + } } break; } diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index 8df730201..1a931135f 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -86,7 +86,9 @@ public: bool has_dilated; Geom::Point last_push; SPCanvasItem *dilate_area; - + bool overlap; + double offset; + std::vector hidding_items; sigc::connection style_set_connection; static const std::string prefsPath; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 183814b7e..1d45f1796 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -102,6 +102,19 @@ static void sp_spray_scale_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ gtk_adjustment_get_value(adj)); } +static void sp_spray_offset_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble( "/tools/spray/offset", + gtk_adjustment_get_value(adj)); +} + +static void sp_not_overlap( GtkAdjustment *adj, GObject * /*tbl*/ ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble( "/tools/spray/overlap", + gtk_adjustment_get_value(adj)); +} void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { @@ -266,6 +279,31 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); g_object_set_data( holder, "spray_scale", eact ); } + + /* dont_overlap */ + { + InkAction* act = ink_action_new( "SprayNotOverlapAction", + _("Not overlap"), + _("Not overlap"), + INKSCAPE_ICON("distribute-randomize"), + secondarySize ); + g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_not_overlap), 0 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Offset */ + { + EgeAdjustmentAction *eact = create_adjustment_action( "SprayToolOffsetAction", + _("Min offset"), _("Min offset:"), + _("The min offset size"), + "/tools/spray/offset", 0.0, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + -9000.0, 9000.0, 1.0, 4.0, + 0, 0, 0, + sp_spray_offset_value_changed, NULL, 0 , 2); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + } + diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index a1c32352c..c904fc356 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -317,6 +317,10 @@ static gchar const * ui_descr = " " " " " " + " " + " " + " " + " " " " -- cgit v1.2.3 From 648022706dc3a441eb79436f319540dd53cba629 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 24 Oct 2015 23:42:10 +0200 Subject: Improving Spray tool (bzr r14422.1.8) --- src/ui/tools/spray-tool.cpp | 125 +++++++++++++++++++++++++++++--------------- src/ui/tools/spray-tool.h | 1 - 2 files changed, 82 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 21fbeccd0..cc5536173 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -49,6 +49,7 @@ #include "path-chemistry.h" #include "sp-text.h" +#include "sp-root.h" #include "sp-flowtext.h" #include "display/sp-canvas.h" #include "display/canvas-bpath.h" @@ -131,6 +132,29 @@ static void sp_spray_scale_rel(Geom::Point c, SPDesktop */*desktop*/, SPItem *it item->set_i2d_affine(item->i2dt_affine() * s.inverse() * scale * s); item->doWriteTransform(item->getRepr(), item->transform); } +///* Method to scale items */ +//static Geom::Affine sp_spray_scale_rel(Geom::Point c, SPDesktop *desktop, SPItem *item, Geom::Scale const &scale, bool write) +//{ +// //Maybe isbetter create a metod inverse to set_i2d_affine to calculate transforms +// // whith objects not in tree +// Geom::Translate const s(c); +// Geom::Affine scale_computed = item->i2dt_affine() * s.inverse() * scale * s; +// Geom::Affine dt2p; /* desktop to item parent transform */ +// if (item->parent) { +// dt2p = static_cast(item->parent)->i2dt_affine().inverse(); +// } else { +// dt2p = desktop->dt2doc(); +// } +// Geom::Affine i2p( scale_computed * dt2p ); +// if(!write){ +// i2p = scale_computed * dt2p * desktop->dt2doc().inverse(); +// } +// if(write) { +// item->set_item_transform(i2p); +// item->doWriteTransform(item->getRepr(), item->transform); +// } +// return i2p; +//} SprayTool::SprayTool() : ToolBase(cursor_spray_xpm, 4, 4, false) @@ -156,7 +180,6 @@ SprayTool::SprayTool() , dilate_area(NULL) , overlap(false) , offset(0) - , hidding_items() { } @@ -355,21 +378,21 @@ static void random_position(double &radius, double &angle, double &a, double &s, } static bool fit_item(SPDesktop *desktop, Geom::OptRect bbox, - SPItem * item, - gchar const * spray_origin, - double scale, - double scale_variation, - std::vector hidding_items) + gchar const * spray_origin) { std::vector items_down = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox); + //std::cout << bbox->top() << "top" << bbox->left() << "left" << bbox->bottom() << "bottom" << bbox->right() << "rightINSIDE\n"; + std::cout << "eeeeeenter\n"; for (std::vector::const_iterator i=items_down.begin(); i!=items_down.end(); i++) { SPItem *item_down = *i; gchar const * item_down_sharp = g_strdup_printf("#%s", item_down->getId()); - if(item_down_sharp == spray_origin || + std::cout << "BUUUCCCLLLLEEEE\n"; + if(strcmp(item_down_sharp, spray_origin) == 0 || (item_down->getAttribute("inkscape:spray-origin") && strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 ) ){ + // if(!SP_IS_GROUP(item) && 1>2){ // SPShape *down_item_shape = dynamic_cast(item_down); // if (down_item_shape) { @@ -429,11 +452,12 @@ static bool fit_item(SPDesktop *desktop, // } else { // std::cout << "applied\n"; // } - return false; +std::cout << "coincide\n"; + return true; } std::cout << "not\n"; } - return true; + return false; } static bool sp_spray_recursive(SPDesktop *desktop, @@ -452,8 +476,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, double ratio, double tilt, double rotation_variation, - gint _distrib, - std::vector hidding_items) + gint _distrib) { bool did = false; @@ -478,6 +501,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, if (a) { if(_fid <= population) { + SPDocument *doc = item->document; gchar const * spray_origin; if(!item->getAttribute("inkscape:spray-origin")){ spray_origin = g_strdup_printf("#%s", item->getId()); @@ -485,43 +509,63 @@ static bool sp_spray_recursive(SPDesktop *desktop, spray_origin = item->getAttribute("inkscape:spray-origin"); } Geom::Point center=item->getCenter(); - Geom::Rect rect(Geom::Point(a->top(), a->left()),Geom::Point(a->bottom(), a->right())); + Geom::Path path; + path.start(Geom::Point(a->left(), a->top())); + path.appendNew(Geom::Point(a->right(), a->top())); + path.appendNew(Geom::Point(a->right(), a->bottom())); + path.appendNew(Geom::Point(a->left(), a->bottom())); + path.close(true); Geom::Translate const s(center); - rect *= item->i2dt_affine() * s.inverse() * Geom::Scale(_scale) * s; - rect *= item->i2dt_affine() * s.inverse() * Geom::Scale(scale) * s; - rect *= item->i2dt_affine() * s.inverse() * Geom::Rotate(angle) * s; + path *= item->transform.inverse() * doc->getRoot()->c2p.inverse() * item->i2dt_affine() * s.inverse() * Geom::Scale(_scale) * s * item->i2dt_affine().inverse() * doc->getRoot()->c2p * item->transform; + path *= item->transform.inverse() * doc->getRoot()->c2p.inverse() * item->i2dt_affine() * s.inverse() * Geom::Scale(scale) * s * item->i2dt_affine().inverse() * doc->getRoot()->c2p * item->transform; + path *= item->transform.inverse() * doc->getRoot()->c2p.inverse() * item->i2dt_affine() * s.inverse() * Geom::Rotate(angle) * s * item->i2dt_affine().inverse() * doc->getRoot()->c2p * item->transform; Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); - rect *= item->i2dt_affine() * s.inverse() * Geom::Translate(move[Geom::X], -move[Geom::Y]) * s; - Geom::OptRect bbox_transformed(Geom::Point(rect.top(), rect.left()),Geom::Point(rect.bottom(), rect.right())); - if(!fit_item(desktop, bbox_transformed, item, spray_origin, _scale, scale_variation, hidding_items)){ - double min_scale = (1.0 - scale_variation / 100.0); - _scale = g_random_double_range(min_scale, 0.8); - center=item->getCenter(); - Geom::Translate const moved_center(center); - rect *= item->i2dt_affine() * moved_center.inverse() * Geom::Scale(_scale) * moved_center; - Geom::OptRect bbox_transformed2(Geom::Point(rect.top(), rect.left()),Geom::Point(rect.bottom(), rect.right())); - if(!fit_item(desktop, bbox_transformed2, item, spray_origin, _scale, scale_variation, hidding_items)){ - return false; - } - } + path *= Geom::Translate(move[Geom::X], move[Geom::Y]); + path *= desktop->doc2dt(); + //std::cout << rect.top() << "top" << rect.left() << "left" << rect.bottom() << "bottom" << rect.right() << "transformed\n"; + Geom::OptRect bbox = path.boundsFast(); + std::cout << bbox->top() << "top" << bbox->left() << "left" << bbox->bottom() << "bottom" << bbox->right() << "PREV\n"; + //std::cout << "ppp\n"; + if(!fit_item(desktop, bbox, spray_origin)){ + //std::cout << "aaa\n"; + + //return true; + +// double min_scale = (1.0 - scale_variation / 100.0); +// _scale = g_random_double_range(min_scale, 0.8); +// center=item->getCenter(); +// Geom::Translate const moved_center(center); +// rect *= item->i2dt_affine() * moved_center.inverse() * Geom::Scale(_scale) * moved_center; +// Geom::OptRect bbox_transformed2(Geom::Point(rect.left(), rect.top()),Geom::Point(rect.right(), rect.bottom())); +// if(!fit_item(desktop, bbox_transformed2, spray_origin)){ +// return true; +// } + + //std::cout << "ccc"; SPItem *item_copied; // Duplicate - SPDocument *doc = item->document; Inkscape::XML::Document* xml_doc = doc->getReprDoc(); Inkscape::XML::Node *old_repr = item->getRepr(); Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + if(!copy->attribute("inkscape:spray-origin")){ + copy->setAttribute("inkscape:spray-origin", spray_origin); + } parent->appendChild(copy); - copy->setAttribute("inkscape:spray-origin", spray_origin); SPObject *new_obj = doc->getObjectByRepr(copy); item_copied = dynamic_cast(new_obj); // Conversion object->item - sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale,_scale)); - sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale)); + sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale)); + sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale)); sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle)); // Move the cursor p sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); + bbox = item_copied->documentVisualBounds(); + std::cout << bbox->top() << "top" << bbox->left() << "left" << bbox->bottom() << "bottom" << bbox->right() << "POST\n"; Inkscape::GC::release(copy); did = true; + } else { + did = false; + } } } #ifdef ENABLE_SPRAY_MODE_SINGLE_PATH @@ -633,7 +677,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, return did; } -static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point p, Geom::Point vector, bool reverse, std::vector hidding_items) +static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point p, Geom::Point vector, bool reverse) { SPDesktop *desktop = tc->desktop; Inkscape::Selection *selection = desktop->getSelection(); @@ -672,7 +716,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point SPItem *item = *i; g_assert(item != NULL); - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, hidding_items)) { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib)) { did = true; } } @@ -732,7 +776,7 @@ bool SprayTool::root_handler(GdkEvent* event) { this->has_dilated = false; if(this->is_dilating && event->button.button == 1 && !this->space_panning) { - sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event), this->hidding_items); + sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event)); } this->has_dilated = true; @@ -762,7 +806,7 @@ bool SprayTool::root_handler(GdkEvent* event) { // Dilating: if (this->is_drawing && ( event->motion.state & GDK_BUTTON1_MASK )) { - sp_spray_dilate(this, motion_w, motion_doc, motion_doc - this->last_push, event->button.state & GDK_SHIFT_MASK? true : false, this->hidding_items); + sp_spray_dilate(this, motion_w, motion_doc, motion_doc - this->last_push, event->button.state & GDK_SHIFT_MASK? true : false); //this->last_push = motion_doc; this->has_dilated = true; @@ -795,7 +839,7 @@ bool SprayTool::root_handler(GdkEvent* event) { this->is_dilating = true; this->has_dilated = false; if(this->is_dilating && !this->space_panning) { - sp_spray_dilate(this, scroll_w, desktop->dt2doc(scroll_dt), Geom::Point(0,0), false, this->hidding_items); + sp_spray_dilate(this, scroll_w, desktop->dt2doc(scroll_dt), Geom::Point(0,0), false); } this->has_dilated = true; @@ -825,7 +869,7 @@ bool SprayTool::root_handler(GdkEvent* event) { if (!this->has_dilated) { // If we did not rub, do a light tap this->pressure = 0.03; - sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event), this->hidding_items); + sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event)); } this->is_dilating = false; this->has_dilated = false; @@ -843,11 +887,6 @@ bool SprayTool::root_handler(GdkEvent* event) { SP_VERB_CONTEXT_SPRAY, _("Spray in single path")); break; } - for (std::vector::const_iterator i=this->hidding_items.begin(); i!=this->hidding_items.end(); i++) { - SPItem *item = *i; - this->hidding_items.erase(i); - item->deleteObject(); - } } break; } diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index 1a931135f..acdff4cb0 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -88,7 +88,6 @@ public: SPCanvasItem *dilate_area; bool overlap; double offset; - std::vector hidding_items; sigc::connection style_set_connection; static const std::string prefsPath; -- cgit v1.2.3 From 6b73445c7de7d4dd58b47056f6ace72e3e49223c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 25 Oct 2015 17:47:19 +0100 Subject: End adding no overlap to spray tool (bzr r14422.1.9) --- src/ui/tools/spray-tool.cpp | 275 +++++++++++++++++++----------------------- src/ui/tools/spray-tool.h | 1 + src/widgets/spray-toolbar.cpp | 31 ++--- src/widgets/spray-toolbar.h | 2 +- src/widgets/toolbox.cpp | 3 +- 5 files changed, 143 insertions(+), 169 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index cc5536173..69a6f0435 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -12,6 +12,7 @@ * Steren GIANNINI (steren.giannini@gmail.com) * Jon A. Cruz * Abhishek Sharma + * Jabiertxo Arraiza * * Copyright (C) 2009 authors * @@ -132,29 +133,6 @@ static void sp_spray_scale_rel(Geom::Point c, SPDesktop */*desktop*/, SPItem *it item->set_i2d_affine(item->i2dt_affine() * s.inverse() * scale * s); item->doWriteTransform(item->getRepr(), item->transform); } -///* Method to scale items */ -//static Geom::Affine sp_spray_scale_rel(Geom::Point c, SPDesktop *desktop, SPItem *item, Geom::Scale const &scale, bool write) -//{ -// //Maybe isbetter create a metod inverse to set_i2d_affine to calculate transforms -// // whith objects not in tree -// Geom::Translate const s(c); -// Geom::Affine scale_computed = item->i2dt_affine() * s.inverse() * scale * s; -// Geom::Affine dt2p; /* desktop to item parent transform */ -// if (item->parent) { -// dt2p = static_cast(item->parent)->i2dt_affine().inverse(); -// } else { -// dt2p = desktop->dt2doc(); -// } -// Geom::Affine i2p( scale_computed * dt2p ); -// if(!write){ -// i2p = scale_computed * dt2p * desktop->dt2doc().inverse(); -// } -// if(write) { -// item->set_item_transform(i2p); -// item->doWriteTransform(item->getRepr(), item->transform); -// } -// return i2p; -//} SprayTool::SprayTool() : ToolBase(cursor_spray_xpm, 4, 4, false) @@ -339,16 +317,6 @@ static double get_move_standard_deviation(SprayTool *tc) return tc->standard_deviation; } -static double get_offset(SprayTool *tc) -{ - return tc->offset; -} - -static double get_overlap(SprayTool *tc) -{ - return tc->overlap; -} - /** * Method to handle the distribution of the items * @param[out] radius : radius of the position of the sprayed object @@ -376,88 +344,63 @@ static void random_position(double &radius, double &angle, double &a, double &s, radius = pow(radius_temp, 0.5); } + +static void sp_spray_transform_path(SPItem * item, Geom::Path &path, Geom::Affine affine, Geom::Point center){ + SPDocument *doc = item->document; + path *= doc->getRoot()->c2p.inverse(); + path *= item->transform.inverse(); + Geom::Affine dt2p; + if (item->parent) { + dt2p = static_cast(item->parent)->i2dt_affine().inverse(); + } else { + SPDesktop *dt = SP_ACTIVE_DESKTOP; + dt2p = dt->dt2doc(); + } + Geom::Affine i2dt = item->i2dt_affine() * Geom::Translate(center).inverse() * affine * Geom::Translate(center); + path *= i2dt * dt2p; + path *= doc->getRoot()->c2p; +} + static bool fit_item(SPDesktop *desktop, + SPItem *item, Geom::OptRect bbox, - gchar const * spray_origin) + gchar const * spray_origin, + Geom::Point move, + Geom::Point center, + double angle, + double _scale, + double scale, + double offset) { + if(offset < 0){ + offset = std::min(std::min(std::abs(offset), bbox->width()/2.0),std::min(std::abs(offset), bbox->height()/2.0)) * -1; + } + bbox = Geom::Rect(Geom::Point(bbox->left() - offset, bbox->top() - offset),Geom::Point(bbox->right() + offset, bbox->bottom() + offset)); + Geom::Path path; + path.start(Geom::Point(bbox->left(), bbox->top())); + path.appendNew(Geom::Point(bbox->right(), bbox->top())); + path.appendNew(Geom::Point(bbox->right(), bbox->bottom())); + path.appendNew(Geom::Point(bbox->left(), bbox->bottom())); + path.close(true); + Geom::Translate const s(center); + sp_spray_transform_path(item, path, Geom::Scale(_scale), center); + sp_spray_transform_path(item, path, Geom::Scale(scale), center); + sp_spray_transform_path(item, path, Geom::Rotate(angle), center); + path *= Geom::Translate(move[Geom::X], move[Geom::Y]); + path *= desktop->doc2dt(); + bbox = path.boundsFast(); std::vector items_down = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox); - //std::cout << bbox->top() << "top" << bbox->left() << "left" << bbox->bottom() << "bottom" << bbox->right() << "rightINSIDE\n"; - std::cout << "eeeeeenter\n"; for (std::vector::const_iterator i=items_down.begin(); i!=items_down.end(); i++) { SPItem *item_down = *i; gchar const * item_down_sharp = g_strdup_printf("#%s", item_down->getId()); - std::cout << "BUUUCCCLLLLEEEE\n"; if(strcmp(item_down_sharp, spray_origin) == 0 || (item_down->getAttribute("inkscape:spray-origin") && - strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 - ) - ){ - -// if(!SP_IS_GROUP(item) && 1>2){ -// SPShape *down_item_shape = dynamic_cast(item_down); -// if (down_item_shape) { -// Geom::PathVector pathv; -// SPPath *down_item_path = dynamic_cast(down_item_shape); -// if (down_item_path) { -// pathv = down_item_path->get_curve()->get_pathvector(); -// } else { -// pathv = down_item_shape->getCurve()->get_pathvector(); -// } -// if (!pathv.empty()) { -// SPShape *copied_item_shape = dynamic_cast(item_copied); -// if (copied_item_shape) { -// Geom::PathVector pathv_other; -// SPPath *copied_item_path = dynamic_cast(copied_item_shape); -// if (copied_item_path) { -// pathv_other = copied_item_path->get_curve()->get_pathvector(); -// } else { -// pathv_other = copied_item_shape->getCurve()->get_pathvector(); -// } -// if (!pathv_other.empty()) { -// Geom::CrossingSet cs = Geom::crossings(pathv, pathv_other); -// if(cs[0].size() == 0){ -// continue; -// } -// } -// } -// } -// } -// } -// sp_item_move_rel(item_copied, Geom::Translate(-move[Geom::X], move[Geom::Y])); -// sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle).inverse()); -// sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale).inverse()); -// sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale, _scale).inverse()); -// -// double min_scale = (1.0 - scale_variation / 100.0); -// _scale = min_scale + ((_scale - min_scale)/2); -// sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale, _scale)); -// sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale)); -// sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle)); -// sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); -// Geom::Point center = item_copied->getCenter(); -// sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale).inverse()); -// double min_scale = (1.0 - scale_variation / 100.0); -// scale = g_random_double_range(min_scale, 0.8); -// sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(scale)); -// bbox = item_copied->desktopVisualBounds(); -// if(bbox->intersects(item_down->desktopVisualBounds()) || -// bbox->contains(item_down->desktopVisualBounds()) -// ) -// { -// //this hack is for speed draw, moved and on release delete all at this point -// //item_copied->deleteObject(); -// item_copied->setHidden(true); -// hidding_items.push_back(item_copied); -// return true; -// } else { -// std::cout << "applied\n"; -// } -std::cout << "coincide\n"; - return true; + strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) + { + return false; } - std::cout << "not\n"; } - return false; + return true; } static bool sp_spray_recursive(SPDesktop *desktop, @@ -476,7 +419,10 @@ static bool sp_spray_recursive(SPDesktop *desktop, double ratio, double tilt, double rotation_variation, - gint _distrib) + gint _distrib, + bool overlap, + double offset, + size_t &limit) { bool did = false; @@ -508,40 +454,39 @@ static bool sp_spray_recursive(SPDesktop *desktop, } else { spray_origin = item->getAttribute("inkscape:spray-origin"); } - Geom::Point center=item->getCenter(); - Geom::Path path; - path.start(Geom::Point(a->left(), a->top())); - path.appendNew(Geom::Point(a->right(), a->top())); - path.appendNew(Geom::Point(a->right(), a->bottom())); - path.appendNew(Geom::Point(a->left(), a->bottom())); - path.close(true); - Geom::Translate const s(center); - path *= item->transform.inverse() * doc->getRoot()->c2p.inverse() * item->i2dt_affine() * s.inverse() * Geom::Scale(_scale) * s * item->i2dt_affine().inverse() * doc->getRoot()->c2p * item->transform; - path *= item->transform.inverse() * doc->getRoot()->c2p.inverse() * item->i2dt_affine() * s.inverse() * Geom::Scale(scale) * s * item->i2dt_affine().inverse() * doc->getRoot()->c2p * item->transform; - path *= item->transform.inverse() * doc->getRoot()->c2p.inverse() * item->i2dt_affine() * s.inverse() * Geom::Rotate(angle) * s * item->i2dt_affine().inverse() * doc->getRoot()->c2p * item->transform; + Geom::Point center = item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); - path *= Geom::Translate(move[Geom::X], move[Geom::Y]); - path *= desktop->doc2dt(); - //std::cout << rect.top() << "top" << rect.left() << "left" << rect.bottom() << "bottom" << rect.right() << "transformed\n"; - Geom::OptRect bbox = path.boundsFast(); - std::cout << bbox->top() << "top" << bbox->left() << "left" << bbox->bottom() << "bottom" << bbox->right() << "PREV\n"; - //std::cout << "ppp\n"; - if(!fit_item(desktop, bbox, spray_origin)){ - //std::cout << "aaa\n"; - - //return true; - -// double min_scale = (1.0 - scale_variation / 100.0); -// _scale = g_random_double_range(min_scale, 0.8); -// center=item->getCenter(); -// Geom::Translate const moved_center(center); -// rect *= item->i2dt_affine() * moved_center.inverse() * Geom::Scale(_scale) * moved_center; -// Geom::OptRect bbox_transformed2(Geom::Point(rect.left(), rect.top()),Geom::Point(rect.right(), rect.bottom())); -// if(!fit_item(desktop, bbox_transformed2, spray_origin)){ -// return true; -// } - - //std::cout << "ccc"; + if(overlap){ + if(!fit_item(desktop, item, a, spray_origin, move, center, angle, _scale, scale, offset)){ + limit += 1; + //Limit recursion to 10 levels + //Seems enoght to chech if thete is place to put new copie + if(limit < 11){ + return sp_spray_recursive(desktop, + selection, + item, + p, + Geom::Point(), + mode, + radius, + population, + scale, + scale_variation, + false, + mean, + standard_deviation, + ratio, + tilt, + rotation_variation, + _distrib, + overlap, + offset, + limit); + } else { + return false; + } + } + } SPItem *item_copied; // Duplicate Inkscape::XML::Document* xml_doc = doc->getReprDoc(); @@ -559,13 +504,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle)); // Move the cursor p sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); - bbox = item_copied->documentVisualBounds(); - std::cout << bbox->top() << "top" << bbox->left() << "left" << bbox->bottom() << "bottom" << bbox->right() << "POST\n"; Inkscape::GC::release(copy); did = true; - } else { - did = false; - } } } #ifdef ENABLE_SPRAY_MODE_SINGLE_PATH @@ -636,8 +576,45 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::OptRect a = item->documentVisualBounds(); if (a) { if(_fid <= population) { - SPItem *item_copied; SPDocument *doc = item->document; + gchar const * spray_origin; + if(!item->getAttribute("inkscape:spray-origin")){ + spray_origin = g_strdup_printf("#%s", item->getId()); + } else { + spray_origin = item->getAttribute("inkscape:spray-origin"); + } + Geom::Point center=item->getCenter(); + Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); + if(overlap){ + if(!fit_item(desktop, item, a, spray_origin, move, center, angle, _scale, scale, offset)){ + limit += 1; + if(limit < 11){ + return sp_spray_recursive(desktop, + selection, + item, + p, + Geom::Point(), + mode, + radius, + population, + scale, + scale_variation, + false, + mean, + standard_deviation, + ratio, + tilt, + rotation_variation, + _distrib, + overlap, + offset, + limit); + } else { + return false; + } + } + } + SPItem *item_copied; Inkscape::XML::Document* xml_doc = doc->getReprDoc(); Inkscape::XML::Node *old_repr = item->getRepr(); Inkscape::XML::Node *parent = old_repr->parent(); @@ -647,12 +624,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, // Ad the clone to the list of the parent's children parent->appendChild(clone); // Generates the link between parent and child attributes - gchar const * spray_origin; if(!clone->attribute("inkscape:spray-origin")){ - spray_origin = g_strdup_printf("#%s", old_repr->attribute("id")); clone->setAttribute("inkscape:spray-origin", spray_origin); - } else { - spray_origin = clone->attribute("inkscape:spray-origin"); } gchar *href_str = g_strdup_printf("#%s", old_repr->attribute("id")); clone->setAttribute("xlink:href", href_str, false); @@ -661,11 +634,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPObject *clone_object = doc->getObjectByRepr(clone); // Conversion object->item item_copied = dynamic_cast(clone_object); - Geom::Point center = item->getCenter(); sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(_scale, _scale)); sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(scale, scale)); sp_spray_rotate_rel(center, desktop, item_copied, Geom::Rotate(angle)); - Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); Inkscape::GC::release(clone); @@ -715,8 +686,8 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = *i; g_assert(item != NULL); - - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib)) { + size_t limit = 0; + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->offset, limit)) { did = true; } } diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index acdff4cb0..a46f2cc90 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -12,6 +12,7 @@ * Benoît LAVORATA * Vincent MONTAGNE * Pierre BARBRY-BLOT + * Jabiertxo Arraiza JABIERTXOF * * Copyright (C) 2009 authors * diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 1d45f1796..6a062bc46 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -15,10 +15,11 @@ * Tavmjong Bah * Abhishek Sharma * Kris De Gussem + * Jabiertxo Arraiza * * Copyright (C) 2004 David Turner * Copyright (C) 2003 MenTaLguY - * Copyright (C) 1999-2011 authors + * Copyright (C) 1999-2015 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -109,11 +110,11 @@ static void sp_spray_offset_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ gtk_adjustment_get_value(adj)); } -static void sp_not_overlap( GtkAdjustment *adj, GObject * /*tbl*/ ) +static void sp_toggle_not_overlap( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble( "/tools/spray/overlap", - gtk_adjustment_get_value(adj)); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/overlap", active); } void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) @@ -279,26 +280,26 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); g_object_set_data( holder, "spray_scale", eact ); } - - /* dont_overlap */ + { - InkAction* act = ink_action_new( "SprayNotOverlapAction", - _("Not overlap"), - _("Not overlap"), - INKSCAPE_ICON("distribute-randomize"), - secondarySize ); - g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_not_overlap), 0 ); + InkToggleAction* act = ink_toggle_action_new( "SprayNotOverlapAction", + _("Not overlap"), + _("Not overlap"), + INKSCAPE_ICON("distribute-randomize"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/overlap", true) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_not_overlap), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } /* Offset */ { EgeAdjustmentAction *eact = create_adjustment_action( "SprayToolOffsetAction", - _("Min offset"), _("Min offset:"), - _("The min offset size"), + _("Offset"), _("Offset:"), + _("Base offset size"), "/tools/spray/offset", 0.0, GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, - -9000.0, 9000.0, 1.0, 4.0, + -1000.0, 1000.0, 1.0, 4.0, 0, 0, 0, sp_spray_offset_value_changed, NULL, 0 , 2); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); diff --git a/src/widgets/spray-toolbar.h b/src/widgets/spray-toolbar.h index d1d5c7b4c..30d8233ca 100644 --- a/src/widgets/spray-toolbar.h +++ b/src/widgets/spray-toolbar.h @@ -21,7 +21,7 @@ * * Copyright (C) 2004 David Turner * Copyright (C) 2003 MenTaLguY - * Copyright (C) 1999-2011 authors + * Copyright (C) 1999-2015 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index c904fc356..f512819e9 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -16,10 +16,11 @@ * Tavmjong Bah * Abhishek Sharma * Kris De Gussem + * Jabiertxo Arraiza * * Copyright (C) 2004 David Turner * Copyright (C) 2003 MenTaLguY - * Copyright (C) 1999-2011 authors + * Copyright (C) 1999-2015 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information -- cgit v1.2.3 From cd7e100476cf935ebbac947109012bcba2f44875 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 25 Oct 2015 17:52:07 +0100 Subject: Removing new roughen changes to create a new Spray branch (bzr r14422.1.11) --- src/live_effects/lpe-roughen.cpp | 91 ++++++++++++++++++---------------------- src/live_effects/lpe-roughen.h | 3 +- 2 files changed, 41 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 55ca77e9c..cea91509e 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -183,15 +183,19 @@ double LPERoughen::sign(double random_number) return random_number; } -Geom::Point LPERoughen::randomize(double max_lenght, bool is_node) +Geom::Point LPERoughen::randomize(double max_lenght, double direction) { - double factor = 1.0/3.0; - if(is_node){ - factor = 1.0; - } - double displace_x_parsed = displace_x * global_randomize * factor; - double displace_y_parsed = displace_y * global_randomize * factor; + double displace_x_parsed = displace_x * global_randomize; + double displace_y_parsed = displace_y * global_randomize; Geom::Point output = Geom::Point(sign(displace_x_parsed), sign(displace_y_parsed)); + if( direction != 0){ + int angle = (int)max_smooth_angle; + if (angle == 0){ + angle = 1; + } + double dist = Geom::distance(Geom::Point(0,0),output); + output = Geom::Point::polar(direction + sign(Geom::deg_to_rad(rand() % angle)), dist); + } if( fixed_displacement ){ Geom::Ray ray(Geom::Point(0,0),output); output = Geom::Point::polar(ray.angle(), max_lenght); @@ -199,19 +203,6 @@ Geom::Point LPERoughen::randomize(double max_lenght, bool is_node) return output; } -Geom::Point LPERoughen::randomize(double lenght, Geom::Point start, Geom::Point end) -{ - int angle = (int)max_smooth_angle; - if (angle == 0){ - angle = 1; - } - Geom::Ray ray(start, end); - if(!fixed_displacement ){ - lenght = Geom::distance(start, end); - } - return Geom::Point::polar(ray.angle() + sign(Geom::deg_to_rad(rand() % angle)), lenght) + start; -} - void LPERoughen::doEffect(SPCurve *curve) { Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(curve->get_pathvector()); @@ -326,9 +317,9 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point Geom::Point point_b2(0, 0); Geom::Point point_b3(0, 0); if (shift_nodes) { - point_a3 = randomize(max_lenght, true); + point_a3 = randomize(max_lenght); if(last){ - point_b3 = randomize(max_lenght, true); + point_b3 = randomize(max_lenght); } } if (handles == HM_RAND || handles == HM_SMOOTH) { @@ -359,55 +350,53 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point std::pair div = cubic->subdivide(t); std::vector seg1 = div.first.controlPoints(), seg2 = div.second.controlPoints(); - point_b1 = randomize(max_lenght, seg1[3] + point_a3, seg2[1] + point_a3); - point_b2 = seg1[2]; - point_b3 = seg2[3] + point_b3; - point_a3 = seg1[3] + point_a3; Geom::Ray ray(prev,A->initialPoint()); - point_a1 = A->initialPoint() + Geom::Point::polar(ray.angle(), max_lenght); + point_a1 = Geom::Point::polar(ray.angle(), max_lenght); if(prev == Geom::Point(0,0)){ point_a1 = randomize(max_lenght); } + ray.setPoints(seg1[3] + point_a3, seg2[1] + point_a3); + point_b1 = randomize(max_lenght, ray.angle()); if(last){ - Geom::Path b2(point_b3); - b2.appendNew(point_a3); - point_b2 = randomize(max_lenght, point_b3, b2.pointAt(1.0/3.0)); + ray.setPoints(seg2[3] + point_b3, A->pointAt(1 - (t / 3)) + point_b3); + point_b2 = randomize(max_lenght, ray.angle()); } - ray.setPoints(point_b1, point_a3); - point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); + ray.setPoints(seg2[1] + point_a3 + point_b1, seg2[0] + point_a3); + point_a2 = Geom::Point::polar(ray.angle(), max_lenght); if(last){ - prev = point_b2; + prev = A->pointAt(1 - (t / 3)) + point_b2 + point_b3; } else { - prev = point_a2; + prev = seg1[3] + point_a2 + point_a3; } out->moveto(seg1[0]); - out->curveto(point_a1,point_a2,point_a3); - out->curveto(point_b1, point_b2, point_b3); + out->curveto(seg1[0] + point_a1, seg1[3] + point_a2 + point_a3, seg1[3] + point_a3); + if(last){ + out->curveto(seg2[1] + point_a3 + point_b1, A->pointAt(1 - (t / 3)) + point_b2 + point_b3, seg2[3] + point_b3); + } else { + out->curveto(seg2[1] + point_a3 + point_b1, seg2[2] + point_b2 + point_b3, seg2[3] + point_b3); + } } else if(handles == HM_SMOOTH && !cubic) { - point_b1 = randomize(max_lenght, A->pointAt(t) + point_a3, A->pointAt(t + (t / 3))); - point_b2 = A->pointAt(t +((t / 3) * 2)); - point_b3 = A->finalPoint() + point_b3; - point_a3 = A->pointAt(t) + point_a3; Geom::Ray ray(prev,A->initialPoint()); - point_a1 = A->initialPoint() + Geom::Point::polar(ray.angle(), max_lenght); - if(prev == Geom::Point(0,0)){ + point_a1 = Geom::Point::polar(ray.angle(), max_lenght); + if(prev==Geom::Point(0,0)){ point_a1 = randomize(max_lenght); } + ray.setPoints(A->pointAt(t) + point_a3, A->pointAt(t + (t / 3)) + point_a3); + point_b1 = randomize(max_lenght, ray.angle()); if(last){ - Geom::Path b2(point_b3); - b2.appendNew(point_a3); - point_b2 = randomize(max_lenght, point_b3, b2.pointAt(1.0/3.0)); + ray.setPoints(A->finalPoint() + point_b3, A->pointAt(t +((t / 3) * 2)) + point_b3); + point_b2 = randomize(max_lenght, ray.angle()); } - ray.setPoints(point_b1, point_a3); - point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); + ray.setPoints(A->pointAt(t + (t / 3)) + point_a3 + point_b1, A->pointAt(t) + point_a3); + point_a2 = Geom::Point::polar(ray.angle(), max_lenght); if(last){ - prev = point_b2; + prev = A->pointAt(t +((t / 3) * 2)) + point_b2 + point_b3; } else { - prev = point_a2; + prev = A->pointAt(t) + point_a3 + point_a2; } out->moveto(A->initialPoint()); - out->curveto(point_a1,point_a2,point_a3); - out->curveto(point_b1, point_b2, point_b3); + out->curveto(A->initialPoint() + point_a1, A->pointAt(t) + point_a3 + point_a2, A->pointAt(t) + point_a3); + out->curveto(A->pointAt(t + (t / 3)) + point_a3 + point_b1, A->pointAt(t +((t / 3) * 2)) + point_b2 + point_b3, A->finalPoint() + point_b3); } else if (cubic) { std::pair div = cubic->subdivide(t); std::vector seg1 = div.first.controlPoints(), diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index 6224c09fa..e3ede2c2d 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -45,8 +45,7 @@ public: virtual void doEffect(SPCurve *curve); virtual double sign(double randNumber); - virtual Geom::Point randomize(double max_lenght, bool is_node = false); - virtual Geom::Point randomize(double lenght, Geom::Point start, Geom::Point end); + virtual Geom::Point randomize(double max_lenght, double direction = 0); virtual void doBeforeEffect(SPLPEItem const * lpeitem); virtual SPCurve const * addNodesAndJitter(Geom::Curve const * A, Geom::Point &prev, Geom::Point &last_move, double t, bool last); virtual SPCurve *jitter(Geom::Curve const * A, Geom::Point &prev, Geom::Point &last_move); -- cgit v1.2.3 From 0ab5eb11dba2f130c7582753f5717ab002dd383e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 26 Oct 2015 10:36:22 +0100 Subject: Fixed typos from Mc Removed unnecesary added headers Put overlap default to false (bzr r14422.1.12) --- src/ui/tools/spray-tool.cpp | 5 +---- src/ui/tools/spray-tool.h | 2 +- src/widgets/spray-toolbar.cpp | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 69a6f0435..67502591f 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -59,9 +59,6 @@ #include "livarot/Shape.h" #include <2geom/circle.h> #include <2geom/transforms.h> -#include <2geom/path-intersection.h> -#include <2geom/pathvector.h> -#include <2geom/crossing.h> #include "preferences.h" #include "style.h" #include "box3d.h" @@ -460,7 +457,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, if(!fit_item(desktop, item, a, spray_origin, move, center, angle, _scale, scale, offset)){ limit += 1; //Limit recursion to 10 levels - //Seems enoght to chech if thete is place to put new copie + //Seems enough to chech if there is place to put new copie if(limit < 11){ return sp_spray_recursive(desktop, selection, diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index a46f2cc90..20c59bcf7 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -12,7 +12,7 @@ * Benoît LAVORATA * Vincent MONTAGNE * Pierre BARBRY-BLOT - * Jabiertxo Arraiza JABIERTXOF + * Jabiertxo ARRAIZA * * Copyright (C) 2009 authors * diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 6a062bc46..2279845de 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -287,7 +287,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("Not overlap"), INKSCAPE_ICON("distribute-randomize"), secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/overlap", true) ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/overlap", false) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_not_overlap), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } -- cgit v1.2.3 From 7211d5adafb749b04d2de1ed3a2e679f4f9f869e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 26 Oct 2015 17:22:18 +0100 Subject: Add option to not overlap if multiple elements are selected to spray (bzr r14422.1.13) --- src/ui/tools/spray-tool.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 67502591f..a49887f89 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -361,7 +361,6 @@ static void sp_spray_transform_path(SPItem * item, Geom::Path &path, Geom::Affin static bool fit_item(SPDesktop *desktop, SPItem *item, Geom::OptRect bbox, - gchar const * spray_origin, Geom::Point move, Geom::Point center, double angle, @@ -387,14 +386,28 @@ static bool fit_item(SPDesktop *desktop, path *= desktop->doc2dt(); bbox = path.boundsFast(); std::vector items_down = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox); + Inkscape::Selection *selection = desktop->getSelection(); + if (selection->isEmpty()) { + return false; + } + std::vector const items_selected(selection->itemList()); for (std::vector::const_iterator i=items_down.begin(); i!=items_down.end(); i++) { SPItem *item_down = *i; gchar const * item_down_sharp = g_strdup_printf("#%s", item_down->getId()); - if(strcmp(item_down_sharp, spray_origin) == 0 || - (item_down->getAttribute("inkscape:spray-origin") && - strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) - { - return false; + for (std::vector::const_iterator j=items_selected.begin(); j!=items_selected.end(); j++) { + SPItem *item_selected = *j; + gchar const * spray_origin; + if(!item->getAttribute("inkscape:spray-origin")){ + spray_origin = g_strdup_printf("#%s", item_selected->getId()); + } else { + spray_origin = item_selected->getAttribute("inkscape:spray-origin"); + } + if(strcmp(item_down_sharp, spray_origin) == 0 || + (item_down->getAttribute("inkscape:spray-origin") && + strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) + { + return false; + } } } return true; @@ -454,7 +467,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center = item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); if(overlap){ - if(!fit_item(desktop, item, a, spray_origin, move, center, angle, _scale, scale, offset)){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, offset)){ limit += 1; //Limit recursion to 10 levels //Seems enough to chech if there is place to put new copie @@ -583,7 +596,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center=item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); if(overlap){ - if(!fit_item(desktop, item, a, spray_origin, move, center, angle, _scale, scale, offset)){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, offset)){ limit += 1; if(limit < 11){ return sp_spray_recursive(desktop, -- cgit v1.2.3 From ce4d5cefcf234870d5f345f184256c9fab354777 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 27 Oct 2015 00:07:29 +0100 Subject: Added a option to pick down color (bzr r14422.1.14) --- src/ui/tools/spray-tool.cpp | 70 +++++++++++++++++++++++++++++++++++++++---- src/ui/tools/spray-tool.h | 1 + src/widgets/spray-toolbar.cpp | 20 +++++++++++++ src/widgets/toolbox.cpp | 1 + 4 files changed, 86 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index a49887f89..4f02d9b33 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -49,6 +49,13 @@ #include "sp-path.h" #include "path-chemistry.h" +// For color picking +#include "display/drawing.h" +#include "display/drawing-context.h" +#include "display/cairo-utils.h" +#include "desktop-style.h" +#include "svg/svg-color.h" + #include "sp-text.h" #include "sp-root.h" #include "sp-flowtext.h" @@ -154,6 +161,7 @@ SprayTool::SprayTool() , has_dilated(false) , dilate_area(NULL) , overlap(false) + , picker(false) , offset(0) { } @@ -228,6 +236,7 @@ void SprayTool::setup() { sp_event_context_read(this, "usepressure"); sp_event_context_read(this, "Scale"); sp_event_context_read(this, "offset"); + sp_event_context_read(this, "picker"); sp_event_context_read(this, "overlap"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -268,6 +277,8 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->ratio = CLAMP(val.getDouble(), 0.0, 0.9); } else if (path == "offset") { this->offset = CLAMP(val.getDouble(), -1000.0, 1000.0); + } else if (path == "picker") { + this->picker = val.getBool(); } else if (path == "overlap") { this->overlap = val.getBool(); } @@ -366,7 +377,9 @@ static bool fit_item(SPDesktop *desktop, double angle, double _scale, double scale, - double offset) + bool picker, + double offset, + SPCSSAttr *css) { if(offset < 0){ offset = std::min(std::min(std::abs(offset), bbox->width()/2.0),std::min(std::abs(offset), bbox->height()/2.0)) * -1; @@ -378,7 +391,6 @@ static bool fit_item(SPDesktop *desktop, path.appendNew(Geom::Point(bbox->right(), bbox->bottom())); path.appendNew(Geom::Point(bbox->left(), bbox->bottom())); path.close(true); - Geom::Translate const s(center); sp_spray_transform_path(item, path, Geom::Scale(_scale), center); sp_spray_transform_path(item, path, Geom::Scale(scale), center); sp_spray_transform_path(item, path, Geom::Rotate(angle), center); @@ -410,6 +422,42 @@ static bool fit_item(SPDesktop *desktop, } } } + if(picker){ + Geom::IntRect area = Geom::IntRect::from_xywh(floor(desktop->d2w(bbox->midpoint())[Geom::X]), floor(desktop->d2w(bbox->midpoint())[Geom::Y]), 1, 1); + double R = 0, G = 0, B = 0, A = 0; + cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); + sp_canvas_arena_render_surface(SP_CANVAS_ARENA(desktop->getDrawing()), s, area); + ink_cairo_surface_average_color_premul(s, R, G, B, A); + cairo_surface_destroy(s); + + // Inkscape::Drawing *pick_drawing = new Inkscape::Drawing(); + // pick_drawing->update(); + // Geom::Rect box( center_bbox[Geom::X]-1, center_bbox[Geom::Y]-1, + // center_bbox[Geom::X]+1, center_bbox[Geom::Y]+1 ); + + // /* Item integer bbox in points */ + // Geom::IntRect ibox = box.roundOutwards(); + + // /* Find visible area */ + // cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ibox.width(), ibox.height()); + // Inkscape::DrawingContext dc(s, ibox.min()); + + // /* Render copy and pick color */ + // pick_drawing->render(dc, ibox); + // double R = 0, G = 0, B = 0, A = 0; + // ink_cairo_surface_average_color(s, R, G, B, A); + // cairo_surface_destroy(s); + // status message + guint32 c32 = SP_RGBA32_F_COMPOSE(R, G, B, A); + gchar c[64]; + sp_svg_write_color(c, sizeof(c), c32); + sp_repr_css_set_property(css, "fill", c); + gchar const * fill_opacity = g_strdup_printf("%f", A); + sp_repr_css_set_property(css, "fill-opacity", fill_opacity); + if(R == 1 && G == 1 && B == 1 && A == 0){ + return false; + } + } return true; } @@ -431,6 +479,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, double rotation_variation, gint _distrib, bool overlap, + bool picker, double offset, size_t &limit) { @@ -466,8 +515,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, } Geom::Point center = item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); + SPCSSAttr *css = sp_repr_css_attr_new(); if(overlap){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, offset)){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, offset, css)){ limit += 1; //Limit recursion to 10 levels //Seems enough to chech if there is place to put new copie @@ -490,6 +540,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, rotation_variation, _distrib, overlap, + picker, offset, limit); } else { @@ -515,6 +566,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, // Move the cursor p sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); Inkscape::GC::release(copy); + if(picker){ + sp_desktop_apply_css_recursive(item_copied, css, true); + } did = true; } } @@ -595,8 +649,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, } Geom::Point center=item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); + SPCSSAttr *css = sp_repr_css_attr_new(); if(overlap){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, offset)){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, offset, css)){ limit += 1; if(limit < 11){ return sp_spray_recursive(desktop, @@ -617,6 +672,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, rotation_variation, _distrib, overlap, + picker, offset, limit); } else { @@ -648,7 +704,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(scale, scale)); sp_spray_rotate_rel(center, desktop, item_copied, Geom::Rotate(angle)); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); - + if(picker){ + sp_desktop_apply_css_recursive(item_copied, css, true); + } Inkscape::GC::release(clone); did = true; } @@ -697,7 +755,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point SPItem *item = *i; g_assert(item != NULL); size_t limit = 0; - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->offset, limit)) { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap,tc->picker, tc->offset, limit)) { did = true; } } diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index 20c59bcf7..f65e0a223 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -88,6 +88,7 @@ public: Geom::Point last_push; SPCanvasItem *dilate_area; bool overlap; + bool picker; double offset; sigc::connection style_set_connection; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 2279845de..944355053 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -117,6 +117,13 @@ static void sp_toggle_not_overlap( GtkToggleAction* act, gpointer data ) prefs->setBool("/tools/spray/overlap", active); } +static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/picker", active); +} + void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); @@ -281,6 +288,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj g_object_set_data( holder, "spray_scale", eact ); } + /* Overlap */ { InkToggleAction* act = ink_toggle_action_new( "SprayNotOverlapAction", _("Not overlap"), @@ -291,6 +299,18 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_not_overlap), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } + + /* Picker */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPickColorAction", + _("Pick down color"), + _("Pick down color"), + INKSCAPE_ICON("color-picker"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/picker", false) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_picker), desktop) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } /* Offset */ { diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index f512819e9..57f804d99 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -320,6 +320,7 @@ static gchar const * ui_descr = " " " " " " + " " " " " " -- cgit v1.2.3 From bb1f811f9932106d5fd4aaba87f3194fc55de6be Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 27 Oct 2015 00:09:21 +0100 Subject: removed dead code (bzr r14422.1.16) --- src/ui/tools/spray-tool.cpp | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 4f02d9b33..bacb1105c 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -429,25 +429,6 @@ static bool fit_item(SPDesktop *desktop, sp_canvas_arena_render_surface(SP_CANVAS_ARENA(desktop->getDrawing()), s, area); ink_cairo_surface_average_color_premul(s, R, G, B, A); cairo_surface_destroy(s); - - // Inkscape::Drawing *pick_drawing = new Inkscape::Drawing(); - // pick_drawing->update(); - // Geom::Rect box( center_bbox[Geom::X]-1, center_bbox[Geom::Y]-1, - // center_bbox[Geom::X]+1, center_bbox[Geom::Y]+1 ); - - // /* Item integer bbox in points */ - // Geom::IntRect ibox = box.roundOutwards(); - - // /* Find visible area */ - // cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ibox.width(), ibox.height()); - // Inkscape::DrawingContext dc(s, ibox.min()); - - // /* Render copy and pick color */ - // pick_drawing->render(dc, ibox); - // double R = 0, G = 0, B = 0, A = 0; - // ink_cairo_surface_average_color(s, R, G, B, A); - // cairo_surface_destroy(s); - // status message guint32 c32 = SP_RGBA32_F_COMPOSE(R, G, B, A); gchar c[64]; sp_svg_write_color(c, sizeof(c), c32); -- cgit v1.2.3 From 8e0ef884486bac630f021bb1b33155e4826edb0d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 27 Oct 2015 00:51:58 +0100 Subject: Fixed some typos pointed by Mc (bzr r14422.1.17) --- src/widgets/spray-toolbar.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 944355053..57b582903 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -128,6 +128,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj { Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool overlap = prefs->getBool("/tools/spray/overlap", false); { /* Width */ @@ -291,8 +293,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Overlap */ { InkToggleAction* act = ink_toggle_action_new( "SprayNotOverlapAction", - _("Not overlap"), - _("Not overlap"), + _("Prevent overlapping objects"), + _("Prevent overlapping objects"), INKSCAPE_ICON("distribute-randomize"), secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/overlap", false) ); @@ -303,30 +305,39 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Picker */ { InkToggleAction* act = ink_toggle_action_new( "SprayPickColorAction", - _("Pick down color"), - _("Pick down color"), + _("Pick down color. Fill must be unset on original when spraying clones"), + _("Pick down color. Fill must be unset on original when spraying clones"), INKSCAPE_ICON("color-picker"), secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/picker", false) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_picker), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + + //if ( offset ) { + // gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + //} else { + // gtk_action_set_sensitive( GTK_ACTION(eact), FALSE ); + //} } /* Offset */ { EgeAdjustmentAction *eact = create_adjustment_action( "SprayToolOffsetAction", _("Offset"), _("Offset:"), - _("Base offset size"), + _("Increase to segregate objects more (value in px)"), "/tools/spray/offset", 0.0, GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -1000.0, 1000.0, 1.0, 4.0, 0, 0, 0, sp_spray_offset_value_changed, NULL, 0 , 2); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); - } - - + //if ( offset ) { + // gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + //} else { + // gtk_action_set_sensitive( GTK_ACTION(eact), FALSE ); + //} + } } -- cgit v1.2.3 From b0de24888aea4410596e237f947a201b349b0097 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 27 Oct 2015 20:10:06 +0100 Subject: Now the picker work with alphas and also in no overlap mode Offset dropdown disabled if no overlap Changed offset to percent based (bzr r14422.1.18) --- src/ui/tools/spray-tool.cpp | 78 +++++++++++++++++++++++++++++++++++-------- src/widgets/spray-toolbar.cpp | 70 ++++++++++++++++++++------------------ src/widgets/toolbox.cpp | 2 +- 3 files changed, 102 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index bacb1105c..25e9dbd73 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -378,13 +378,19 @@ static bool fit_item(SPDesktop *desktop, double _scale, double scale, bool picker, + bool overlap, double offset, SPCSSAttr *css) { - if(offset < 0){ - offset = std::min(std::min(std::abs(offset), bbox->width()/2.0),std::min(std::abs(offset), bbox->height()/2.0)) * -1; + SPDocument *doc = item->document; + double width = bbox->width(); + double height = bbox->height(); + double size = std::min(width,height); + double offset_min = (offset * size)/100.0 - (size); + if(offset_min < 0 ){ + offset_min = 0; } - bbox = Geom::Rect(Geom::Point(bbox->left() - offset, bbox->top() - offset),Geom::Point(bbox->right() + offset, bbox->bottom() + offset)); + bbox = Geom::Rect(Geom::Point(bbox->left() - offset_min, bbox->top() - offset_min),Geom::Point(bbox->right() + offset_min, bbox->bottom() + offset_min)); Geom::Path path; path.start(Geom::Point(bbox->left(), bbox->top())); path.appendNew(Geom::Point(bbox->right(), bbox->top())); @@ -397,6 +403,16 @@ static bool fit_item(SPDesktop *desktop, path *= Geom::Translate(move[Geom::X], move[Geom::Y]); path *= desktop->doc2dt(); bbox = path.boundsFast(); + double bbox_left_main = bbox->left(); + double bbox_top_main = bbox->top(); + double width_transformed = bbox->width(); + double height_transformed = bbox->height(); + size = std::min(width_transformed,height_transformed); + if(offset < 100 ){ + offset_min = ((99.0 - offset) * size)/100.0 - size; + } else { + offset_min = 0; + } std::vector items_down = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox); Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { @@ -405,6 +421,11 @@ static bool fit_item(SPDesktop *desktop, std::vector const items_selected(selection->itemList()); for (std::vector::const_iterator i=items_down.begin(); i!=items_down.end(); i++) { SPItem *item_down = *i; + Geom::OptRect bbox_down = item_down->documentVisualBounds(); + width = bbox_down->width(); + height = bbox_down->height(); + double bbox_left = bbox_down->left(); + double bbox_top = bbox_down->top(); gchar const * item_down_sharp = g_strdup_printf("#%s", item_down->getId()); for (std::vector::const_iterator j=items_selected.begin(); j!=items_selected.end(); j++) { SPItem *item_selected = *j; @@ -415,27 +436,56 @@ static bool fit_item(SPDesktop *desktop, spray_origin = item_selected->getAttribute("inkscape:spray-origin"); } if(strcmp(item_down_sharp, spray_origin) == 0 || - (item_down->getAttribute("inkscape:spray-origin") && - strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) + (item_down->getAttribute("inkscape:spray-origin") && + strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) { - return false; + if(overlap){ + if(!(offset_min < 0 && std::abs(bbox_left - bbox_left_main) > std::abs(offset_min) && + std::abs(bbox_top - bbox_top_main) > std::abs(offset_min))){ + return false; + } + } else if(picker){ + item_down->setHidden(true); + item_down->updateRepr(); + } } } } if(picker){ - Geom::IntRect area = Geom::IntRect::from_xywh(floor(desktop->d2w(bbox->midpoint())[Geom::X]), floor(desktop->d2w(bbox->midpoint())[Geom::Y]), 1, 1); + if(!overlap){ + doc->ensureUpToDate(); + } + Geom::Point mid_point = bbox->midpoint(); + Geom::IntRect area = Geom::IntRect::from_xywh(floor(desktop->d2w(mid_point)[Geom::X]), floor(desktop->d2w(mid_point)[Geom::Y]), 1, 1); double R = 0, G = 0, B = 0, A = 0; cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); sp_canvas_arena_render_surface(SP_CANVAS_ARENA(desktop->getDrawing()), s, area); ink_cairo_surface_average_color_premul(s, R, G, B, A); cairo_surface_destroy(s); + if (fabs(A) < 1e-4) { + A = 0; // suppress exponentials, CSS does not allow that + } + if (A > 0) { + R /= A; + G /= A; + B /= A; + } guint32 c32 = SP_RGBA32_F_COMPOSE(R, G, B, A); gchar c[64]; sp_svg_write_color(c, sizeof(c), c32); sp_repr_css_set_property(css, "fill", c); - gchar const * fill_opacity = g_strdup_printf("%f", A); - sp_repr_css_set_property(css, "fill-opacity", fill_opacity); - if(R == 1 && G == 1 && B == 1 && A == 0){ + std::stringstream fill_opacity; + fill_opacity.imbue(std::locale::classic()); + fill_opacity << float(A); + sp_repr_css_set_property(css, "fill-opacity", fill_opacity.str().c_str()); + if(!overlap){ + for (std::vector::const_iterator k=items_down.begin(); k!=items_down.end(); k++) { + SPItem *item_hidden = *k; + item_hidden->setHidden(false); + item_hidden->updateRepr(); + } + } + if(A == 0){ return false; } } @@ -497,8 +547,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center = item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); - if(overlap){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, offset, css)){ + if(overlap || picker){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, overlap, offset, css)){ limit += 1; //Limit recursion to 10 levels //Seems enough to chech if there is place to put new copie @@ -631,8 +681,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center=item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); - if(overlap){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, offset, css)){ + if(overlap || picker){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, overlap, offset, css)){ limit += 1; if(limit < 11){ return sp_spray_recursive(desktop, diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 57b582903..9f7a7cb1d 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -54,6 +54,17 @@ using Inkscape::UI::PrefPusher; //## Spray ## //######################## +static void sp_stb_sensitivize( GObject *tbl ) +{ + GtkAction* offset = GTK_ACTION( g_object_get_data(tbl, "offset") ); + GtkToggleAction *overlap = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "overlap") ); + if (gtk_toggle_action_get_active(overlap)) { + gtk_action_set_sensitive( offset, TRUE ); + } else { + gtk_action_set_sensitive( offset, FALSE ); + } +} + static void sp_spray_width_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -110,11 +121,14 @@ static void sp_spray_offset_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ gtk_adjustment_get_value(adj)); } -static void sp_toggle_not_overlap( GtkToggleAction* act, gpointer data ) +static void sp_toggle_not_overlap( GtkToggleAction* act, gpointer data) { + + GObject *tbl = G_OBJECT(data); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); prefs->setBool("/tools/spray/overlap", active); + sp_stb_sensitivize(tbl); } static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) @@ -128,9 +142,6 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj { Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - bool overlap = prefs->getBool("/tools/spray/overlap", false); - { /* Width */ gchar const* labels[] = {_("(narrow spray)"), 0, 0, 0, _("(default)"), 0, 0, 0, 0, _("(broad spray)")}; @@ -290,18 +301,6 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj g_object_set_data( holder, "spray_scale", eact ); } - /* Overlap */ - { - InkToggleAction* act = ink_toggle_action_new( "SprayNotOverlapAction", - _("Prevent overlapping objects"), - _("Prevent overlapping objects"), - INKSCAPE_ICON("distribute-randomize"), - secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/overlap", false) ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_not_overlap), desktop) ; - gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); - } - /* Picker */ { InkToggleAction* act = ink_toggle_action_new( "SprayPickColorAction", @@ -310,35 +309,40 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj INKSCAPE_ICON("color-picker"), secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/picker", false) ); + g_object_set_data( holder, "picker", act ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_picker), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } - //if ( offset ) { - // gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); - //} else { - // gtk_action_set_sensitive( GTK_ACTION(eact), FALSE ); - //} + /* Overlap */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayNotOverlapAction", + _("Prevent overlapping objects"), + _("Prevent overlapping objects"), + INKSCAPE_ICON("distribute-randomize"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/overlap", false) ); + g_object_set_data( holder, "overlap", act ); + //g_object_set_data (context_object, "holder", holder); + //g_object_set_data (context_object, "desktop", desktop); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_not_overlap), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } /* Offset */ { EgeAdjustmentAction *eact = create_adjustment_action( "SprayToolOffsetAction", - _("Offset"), _("Offset:"), - _("Increase to segregate objects more (value in px)"), - "/tools/spray/offset", 0.0, + _("Offset precent"), _("Offset percent:"), + _("Increase to segregate objects more (value in percent)"), + "/tools/spray/offset", 100, GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, - -1000.0, 1000.0, 1.0, 4.0, + 0, 10000, 1, 4, 0, 0, 0, - sp_spray_offset_value_changed, NULL, 0 , 2); + sp_spray_offset_value_changed, NULL, 0 , 0); + g_object_set_data( holder, "offset", eact ); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); - - //if ( offset ) { - // gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); - //} else { - // gtk_action_set_sensitive( GTK_ACTION(eact), FALSE ); - //} } - + sp_stb_sensitivize(holder); } diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 57f804d99..f4bc367d0 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -319,8 +319,8 @@ static gchar const * ui_descr = " " " " " " - " " " " + " " " " " " -- cgit v1.2.3 From 18dd2576ee9fa17b4d8d31f6d6e4150e4e92caac Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 27 Oct 2015 20:45:58 +0100 Subject: little tweak (bzr r14422.1.19) --- src/ui/tools/spray-tool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 25e9dbd73..269afbbbf 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -455,8 +455,8 @@ static bool fit_item(SPDesktop *desktop, if(!overlap){ doc->ensureUpToDate(); } - Geom::Point mid_point = bbox->midpoint(); - Geom::IntRect area = Geom::IntRect::from_xywh(floor(desktop->d2w(mid_point)[Geom::X]), floor(desktop->d2w(mid_point)[Geom::Y]), 1, 1); + Geom::Point mid_point = desktop->d2w(bbox->midpoint()); + Geom::IntRect area = Geom::IntRect::from_xywh(floor(mid_point[Geom::X]), floor(mid_point[Geom::Y]), 1, 1); double R = 0, G = 0, B = 0, A = 0; cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); sp_canvas_arena_render_surface(SP_CANVAS_ARENA(desktop->getDrawing()), s, area); -- cgit v1.2.3 From db7f8af5407653016d6b2847f779ce59f568cdaa Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 28 Oct 2015 18:43:39 +0100 Subject: Fix the problems on transformed layers (bzr r14422.1.20) --- src/ui/tools/spray-tool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 269afbbbf..fd7c99d91 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -355,7 +355,7 @@ static void random_position(double &radius, double &angle, double &a, double &s, static void sp_spray_transform_path(SPItem * item, Geom::Path &path, Geom::Affine affine, Geom::Point center){ SPDocument *doc = item->document; - path *= doc->getRoot()->c2p.inverse(); + path *= i2anc_affine(static_cast(item->parent), NULL).inverse(); path *= item->transform.inverse(); Geom::Affine dt2p; if (item->parent) { @@ -366,7 +366,7 @@ static void sp_spray_transform_path(SPItem * item, Geom::Path &path, Geom::Affin } Geom::Affine i2dt = item->i2dt_affine() * Geom::Translate(center).inverse() * affine * Geom::Translate(center); path *= i2dt * dt2p; - path *= doc->getRoot()->c2p; + path *= i2anc_affine(static_cast(item->parent), NULL); } static bool fit_item(SPDesktop *desktop, -- cgit v1.2.3 From 598dbc9628a3f31e877a4848896b9d0421683106 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 28 Oct 2015 19:09:21 +0100 Subject: add a ignore transparent areas option (bzr r14422.1.21) --- src/ui/tools/spray-tool.cpp | 49 +++++++++++++++++++++++++------------------ src/ui/tools/spray-tool.h | 1 + src/widgets/spray-toolbar.cpp | 37 +++++++++++++++++++++++++++++--- src/widgets/toolbox.cpp | 1 + 4 files changed, 65 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index fd7c99d91..e1c5b36b2 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -162,6 +162,7 @@ SprayTool::SprayTool() , dilate_area(NULL) , overlap(false) , picker(false) + , visible(false) , offset(0) { } @@ -237,6 +238,7 @@ void SprayTool::setup() { sp_event_context_read(this, "Scale"); sp_event_context_read(this, "offset"); sp_event_context_read(this, "picker"); + sp_event_context_read(this, "visible"); sp_event_context_read(this, "overlap"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -279,6 +281,8 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->offset = CLAMP(val.getDouble(), -1000.0, 1000.0); } else if (path == "picker") { this->picker = val.getBool(); + } else if (path == "visible") { + this->visible = val.getBool(); } else if (path == "overlap") { this->overlap = val.getBool(); } @@ -354,7 +358,6 @@ static void random_position(double &radius, double &angle, double &a, double &s, } static void sp_spray_transform_path(SPItem * item, Geom::Path &path, Geom::Affine affine, Geom::Point center){ - SPDocument *doc = item->document; path *= i2anc_affine(static_cast(item->parent), NULL).inverse(); path *= item->transform.inverse(); Geom::Affine dt2p; @@ -378,6 +381,7 @@ static bool fit_item(SPDesktop *desktop, double _scale, double scale, bool picker, + bool visible, bool overlap, double offset, SPCSSAttr *css) @@ -444,14 +448,14 @@ static bool fit_item(SPDesktop *desktop, std::abs(bbox_top - bbox_top_main) > std::abs(offset_min))){ return false; } - } else if(picker){ + } else if(picker || visible){ item_down->setHidden(true); item_down->updateRepr(); } } } } - if(picker){ + if(picker || visible){ if(!overlap){ doc->ensureUpToDate(); } @@ -465,19 +469,21 @@ static bool fit_item(SPDesktop *desktop, if (fabs(A) < 1e-4) { A = 0; // suppress exponentials, CSS does not allow that } - if (A > 0) { - R /= A; - G /= A; - B /= A; + if(picker){ + if (A > 0) { + R /= A; + G /= A; + B /= A; + } + guint32 c32 = SP_RGBA32_F_COMPOSE(R, G, B, A); + gchar c[64]; + sp_svg_write_color(c, sizeof(c), c32); + sp_repr_css_set_property(css, "fill", c); + std::stringstream fill_opacity; + fill_opacity.imbue(std::locale::classic()); + fill_opacity << float(A); + sp_repr_css_set_property(css, "fill-opacity", fill_opacity.str().c_str()); } - guint32 c32 = SP_RGBA32_F_COMPOSE(R, G, B, A); - gchar c[64]; - sp_svg_write_color(c, sizeof(c), c32); - sp_repr_css_set_property(css, "fill", c); - std::stringstream fill_opacity; - fill_opacity.imbue(std::locale::classic()); - fill_opacity << float(A); - sp_repr_css_set_property(css, "fill-opacity", fill_opacity.str().c_str()); if(!overlap){ for (std::vector::const_iterator k=items_down.begin(); k!=items_down.end(); k++) { SPItem *item_hidden = *k; @@ -511,6 +517,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, gint _distrib, bool overlap, bool picker, + bool visible, double offset, size_t &limit) { @@ -547,8 +554,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center = item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); - if(overlap || picker){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, overlap, offset, css)){ + if(overlap || picker || visible){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, visible, overlap, offset, css)){ limit += 1; //Limit recursion to 10 levels //Seems enough to chech if there is place to put new copie @@ -572,6 +579,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, _distrib, overlap, picker, + visible, offset, limit); } else { @@ -681,8 +689,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center=item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); - if(overlap || picker){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, overlap, offset, css)){ + if(overlap || picker || visible){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, visible, overlap, offset, css)){ limit += 1; if(limit < 11){ return sp_spray_recursive(desktop, @@ -704,6 +712,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, _distrib, overlap, picker, + visible, offset, limit); } else { @@ -786,7 +795,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point SPItem *item = *i; g_assert(item != NULL); size_t limit = 0; - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap,tc->picker, tc->offset, limit)) { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->picker, tc->visible, tc->offset, limit)) { did = true; } } diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index f65e0a223..8f000e095 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -89,6 +89,7 @@ public: SPCanvasItem *dilate_area; bool overlap; bool picker; + bool visible; double offset; sigc::connection style_set_connection; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 9f7a7cb1d..7831c0fe7 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -123,19 +123,37 @@ static void sp_spray_offset_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ static void sp_toggle_not_overlap( GtkToggleAction* act, gpointer data) { - - GObject *tbl = G_OBJECT(data); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); prefs->setBool("/tools/spray/overlap", active); + GObject *tbl = G_OBJECT(data); sp_stb_sensitivize(tbl); } +static void sp_toggle_visible( GtkToggleAction* act, gpointer data) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/visible", active); + if(active == true){ + prefs->setBool("/tools/spray/picker", false); + GObject *tbl = G_OBJECT(data); + GtkToggleAction *picker = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "picker") ); + gtk_toggle_action_set_active(picker, false); + } +} + static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); prefs->setBool("/tools/spray/picker", active); + if(active == true){ + prefs->setBool("/tools/spray/visible", false); + GObject *tbl = G_OBJECT(data); + GtkToggleAction *visible = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "visible") ); + gtk_toggle_action_set_active(visible, false); + } } void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) @@ -310,7 +328,20 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/picker", false) ); g_object_set_data( holder, "picker", act ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_picker), desktop) ; + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_picker), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Visible */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayOverVisibleAction", + _("Apply on non transparent areas"), + _("Apply on non transparent areas"), + INKSCAPE_ICON("object-visible"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/visible", false) ); + g_object_set_data( holder, "visible", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_visible), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index f4bc367d0..ef2d89103 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -320,6 +320,7 @@ static gchar const * ui_descr = " " " " " " + " " " " " " -- cgit v1.2.3 From b0541736ec1d94e0c3db41c5dae5a11fefa65989 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 28 Oct 2015 20:12:17 +0100 Subject: Improvement to the css stored on change colors (bzr r14422.1.22) --- src/ui/tools/spray-tool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index e1c5b36b2..41e209cc1 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -553,7 +553,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, } Geom::Point center = item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); - SPCSSAttr *css = sp_repr_css_attr_new(); + SPCSSAttr *css = sp_repr_css_attr(item->getRepr(), "style"); if(overlap || picker || visible){ if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, visible, overlap, offset, css)){ limit += 1; @@ -688,7 +688,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, } Geom::Point center=item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); - SPCSSAttr *css = sp_repr_css_attr_new(); + SPCSSAttr *css = sp_repr_css_attr(item->getRepr(), "style"); if(overlap || picker || visible){ if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, visible, overlap, offset, css)){ limit += 1; -- cgit v1.2.3 From eb0dca3297aed737b3c0fdae7473413da9204346 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 28 Oct 2015 21:23:02 +0100 Subject: Increase recursion levels (bzr r14422.1.23) --- src/ui/tools/spray-tool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 41e209cc1..6376f1e19 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -559,7 +559,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, limit += 1; //Limit recursion to 10 levels //Seems enough to chech if there is place to put new copie - if(limit < 11){ + if(limit < 21){ return sp_spray_recursive(desktop, selection, item, @@ -692,7 +692,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, if(overlap || picker || visible){ if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, visible, overlap, offset, css)){ limit += 1; - if(limit < 11){ + if(limit < 21){ return sp_spray_recursive(desktop, selection, item, -- cgit v1.2.3 From f0c7823bd854087fcd2989d205a178d9deea1a9a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 28 Oct 2015 23:14:01 +0100 Subject: Fix a regression updating CSS data (bzr r14422.1.24) --- src/ui/tools/spray-tool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 6376f1e19..f64e56a5b 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -553,7 +553,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, } Geom::Point center = item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); - SPCSSAttr *css = sp_repr_css_attr(item->getRepr(), "style"); + SPCSSAttr *css = sp_repr_css_attr_new(); if(overlap || picker || visible){ if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, visible, overlap, offset, css)){ limit += 1; @@ -688,7 +688,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, } Geom::Point center=item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); - SPCSSAttr *css = sp_repr_css_attr(item->getRepr(), "style"); + SPCSSAttr *css = sp_repr_css_attr_new(); if(overlap || picker || visible){ if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, visible, overlap, offset, css)){ limit += 1; -- cgit v1.2.3 From 6a0b7c70e7e07839551be32aba63ae4a6badee81 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 29 Oct 2015 02:37:02 +0100 Subject: Removed recursion from code because no speed improvements Added swith to 100 on toogle no overlap button pointed by Mc. Fixed crash pointed by Mc selecting all+no overlap+click (bzr r14422.1.25) --- src/ui/tools/spray-tool.cpp | 66 ++++--------------------------------------- src/widgets/spray-toolbar.cpp | 2 ++ 2 files changed, 7 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index f64e56a5b..29bfe1641 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -434,7 +434,7 @@ static bool fit_item(SPDesktop *desktop, for (std::vector::const_iterator j=items_selected.begin(); j!=items_selected.end(); j++) { SPItem *item_selected = *j; gchar const * spray_origin; - if(!item->getAttribute("inkscape:spray-origin")){ + if(!item_selected->getAttribute("inkscape:spray-origin")){ spray_origin = g_strdup_printf("#%s", item_selected->getId()); } else { spray_origin = item_selected->getAttribute("inkscape:spray-origin"); @@ -518,8 +518,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, bool overlap, bool picker, bool visible, - double offset, - size_t &limit) + double offset) { bool did = false; @@ -556,35 +555,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPCSSAttr *css = sp_repr_css_attr_new(); if(overlap || picker || visible){ if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, visible, overlap, offset, css)){ - limit += 1; - //Limit recursion to 10 levels - //Seems enough to chech if there is place to put new copie - if(limit < 21){ - return sp_spray_recursive(desktop, - selection, - item, - p, - Geom::Point(), - mode, - radius, - population, - scale, - scale_variation, - false, - mean, - standard_deviation, - ratio, - tilt, - rotation_variation, - _distrib, - overlap, - picker, - visible, - offset, - limit); - } else { - return false; - } + return false; } } SPItem *item_copied; @@ -691,33 +662,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPCSSAttr *css = sp_repr_css_attr_new(); if(overlap || picker || visible){ if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, visible, overlap, offset, css)){ - limit += 1; - if(limit < 21){ - return sp_spray_recursive(desktop, - selection, - item, - p, - Geom::Point(), - mode, - radius, - population, - scale, - scale_variation, - false, - mean, - standard_deviation, - ratio, - tilt, - rotation_variation, - _distrib, - overlap, - picker, - visible, - offset, - limit); - } else { - return false; - } + return false; } } SPItem *item_copied; @@ -794,8 +739,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = *i; g_assert(item != NULL); - size_t limit = 0; - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->picker, tc->visible, tc->offset, limit)) { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->picker, tc->visible, tc->offset)) { did = true; } } diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 7831c0fe7..a335a6c4f 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -57,7 +57,9 @@ using Inkscape::UI::PrefPusher; static void sp_stb_sensitivize( GObject *tbl ) { GtkAction* offset = GTK_ACTION( g_object_get_data(tbl, "offset") ); + GtkAdjustment *adj_offset = ege_adjustment_action_get_adjustment( EGE_ADJUSTMENT_ACTION(offset) ); GtkToggleAction *overlap = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "overlap") ); + gtk_adjustment_set_value( adj_offset, 100.0 ); if (gtk_toggle_action_get_active(overlap)) { gtk_action_set_sensitive( offset, TRUE ); } else { -- cgit v1.2.3 From 109427b9ee5b74661b6bb2d5eb9efcc83d1a1082 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 30 Oct 2015 01:38:22 +0100 Subject: Add optional presure to width and to size Start showing trace dialog (bzr r14422.1.27) --- src/ui/dialog/clonetiler.cpp | 11 +++++--- src/ui/tools/spray-tool.cpp | 43 ++++++++++++++++++++++------ src/ui/tools/spray-tool.h | 4 ++- src/widgets/spray-toolbar.cpp | 66 ++++++++++++++++++++++++++++++++++++++++--- src/widgets/toolbox.cpp | 4 ++- 5 files changed, 110 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index da1c6d9fb..0b1d0ecf2 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -85,7 +85,7 @@ CloneTiler::CloneTiler () : { Gtk::Box *contents = _getContents(); contents->set_spacing(0); - + { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -777,7 +777,6 @@ CloneTiler::CloneTiler () : { GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace")); - { #if GTK_CHECK_VERSION(3,0,0) GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, VB_MARGIN); @@ -787,7 +786,12 @@ CloneTiler::CloneTiler () : #endif gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0); - GtkWidget *b = gtk_check_button_new_with_label (_("Trace the drawing under the tiles")); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if(prefs->getBool("/dialogs/clonetiler/opentrace", false)){ + gtk_notebook_set_current_page (GTK_NOTEBOOK(nb),5); + } + + GtkWidget *b = gtk_check_button_new_with_label (_("Trace the drawing under the tiles/spray tool")); g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE)); bool old = prefs->getBool(prefs_path + "dotrace"); gtk_toggle_button_set_active ((GtkToggleButton *) b, old); @@ -1289,7 +1293,6 @@ CloneTiler::CloneTiler () : } gtk_widget_show_all (mainbox); - } show_all(); diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 29bfe1641..e78f5787e 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -142,7 +142,9 @@ SprayTool::SprayTool() : ToolBase(cursor_spray_xpm, 4, 4, false) , pressure(TC_DEFAULT_PRESSURE) , dragging(false) - , usepressure(false) + , usepressurewidth(false) + , usepressurepopulation(false) + , usepressurescale(false) , usetilt(false) , usetext(false) , width(0.2) @@ -234,7 +236,9 @@ void SprayTool::setup() { sp_event_context_read(this, "population"); sp_event_context_read(this, "mean"); sp_event_context_read(this, "standard_deviation"); - sp_event_context_read(this, "usepressure"); + sp_event_context_read(this, "usepressurewidth"); + sp_event_context_read(this, "usepressurepopulation"); + sp_event_context_read(this, "usepressurescale"); sp_event_context_read(this, "Scale"); sp_event_context_read(this, "offset"); sp_event_context_read(this, "picker"); @@ -258,8 +262,12 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->update_cursor(false); } else if (path == "width") { this->width = 0.01 * CLAMP(val.getInt(10), 1, 100); - } else if (path == "usepressure") { - this->usepressure = val.getBool(); + } else if (path == "usepressurewidth") { + this->usepressurewidth = val.getBool(); + } else if (path == "usepressurepopulation") { + this->usepressurepopulation = val.getBool(); + } else if (path == "usepressurescale") { + this->usepressurescale = val.getBool(); } else if (path == "population") { this->population = 0.01 * CLAMP(val.getInt(10), 1, 100); } else if (path == "rotation_variation") { @@ -297,9 +305,16 @@ static void sp_spray_extinput(SprayTool *tc, GdkEvent *event) } } +static double get_width(SprayTool *tc) +{ + double pressure = (tc->usepressurewidth? tc->pressure / TC_DEFAULT_PRESSURE : 1); + //g_warning("Pressure, population: %f, %f", pressure, pressure * tc->population); + return pressure * tc->width; +} + static double get_dilate_radius(SprayTool *tc) { - return 250 * tc->width/SP_EVENT_CONTEXT(tc)->desktop->current_zoom(); + return 250 * get_width(tc)/SP_EVENT_CONTEXT(tc)->desktop->current_zoom(); } static double get_path_mean(SprayTool *tc) @@ -314,11 +329,18 @@ static double get_path_standard_deviation(SprayTool *tc) static double get_population(SprayTool *tc) { - double pressure = (tc->usepressure? tc->pressure / TC_DEFAULT_PRESSURE : 1); + double pressure = (tc->usepressurepopulation? tc->pressure / TC_DEFAULT_PRESSURE : 1); //g_warning("Pressure, population: %f, %f", pressure, pressure * tc->population); return pressure * tc->population; } +static double get_pressure(SprayTool *tc) +{ + double pressure = (tc->usepressurepopulation? tc->pressure / TC_DEFAULT_PRESSURE : 1); + //g_warning("Pressure, population: %f, %f", pressure, pressure * tc->population); + return pressure; +} + static double get_move_mean(SprayTool *tc) { return tc->mean; @@ -518,7 +540,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, bool overlap, bool picker, bool visible, - double offset) + double offset, + bool usepressurescale, + double pressure) { bool did = false; @@ -534,6 +558,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, double _fid = g_random_double_range(0, 1); double angle = g_random_double_range( - rotation_variation / 100.0 * M_PI , rotation_variation / 100.0 * M_PI ); double _scale = g_random_double_range( 1.0 - scale_variation / 100.0, 1.0 + scale_variation / 100.0 ); + if(usepressurescale){ + _scale = pressure * 2.0; + } double dr; double dp; random_position( dr, dp, mean, standard_deviation, _distrib ); dr=dr*radius; @@ -739,7 +766,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = *i; g_assert(item != NULL); - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->picker, tc->visible, tc->offset)) { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->picker, tc->visible, tc->offset, tc->usepressurescale, get_pressure(tc))) { did = true; } } diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index 8f000e095..112ab77e9 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -63,7 +63,9 @@ public: /* attributes */ bool dragging; /* mouse state: mouse is dragging */ - bool usepressure; + bool usepressurewidth; + bool usepressurepopulation; + bool usepressurescale; bool usetilt; bool usetext; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index a335a6c4f..3b175b715 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -29,18 +29,23 @@ # include "config.h" #endif -#include +#include #include "spray-toolbar.h" #include "desktop.h" +#include "inkscape.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" #include "widgets/ink-action.h" #include "preferences.h" #include "toolbox.h" +#include "ui/dialog/clonetiler.h" +#include "ui/dialog/dialog-manager.h" #include "ui/icon-names.h" +#include + using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; @@ -57,14 +62,23 @@ using Inkscape::UI::PrefPusher; static void sp_stb_sensitivize( GObject *tbl ) { GtkAction* offset = GTK_ACTION( g_object_get_data(tbl, "offset") ); + GtkAction* spray_scale = GTK_ACTION( g_object_get_data(tbl, "spray_scale") ); GtkAdjustment *adj_offset = ege_adjustment_action_get_adjustment( EGE_ADJUSTMENT_ACTION(offset) ); + GtkAdjustment *adj_scale = ege_adjustment_action_get_adjustment( EGE_ADJUSTMENT_ACTION(spray_scale) ); GtkToggleAction *overlap = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "overlap") ); + GtkToggleAction *usepressurescale = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "usepressurescale") ); gtk_adjustment_set_value( adj_offset, 100.0 ); if (gtk_toggle_action_get_active(overlap)) { gtk_action_set_sensitive( offset, TRUE ); } else { gtk_action_set_sensitive( offset, FALSE ); } + if (gtk_toggle_action_get_active(usepressurescale)) { + gtk_adjustment_set_value( adj_scale, 0.0 ); + gtk_action_set_sensitive( spray_scale, FALSE ); + } else { + gtk_action_set_sensitive( spray_scale, TRUE ); + } } static void sp_spray_width_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) @@ -132,6 +146,18 @@ static void sp_toggle_not_overlap( GtkToggleAction* act, gpointer data) sp_stb_sensitivize(tbl); } +static void sp_toggle_pressure_scale( GtkToggleAction* act, gpointer data) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/usepressurescale", active); + if(active == true){ + prefs->setDouble("/tools/spray/scale_variation", 0); + } + GObject *tbl = G_OBJECT(data); + sp_stb_sensitivize( tbl ); +} + static void sp_toggle_visible( GtkToggleAction* act, gpointer data) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -155,6 +181,11 @@ static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) GObject *tbl = G_OBJECT(data); GtkToggleAction *visible = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "visible") ); gtk_toggle_action_set_active(visible, false); + prefs->setBool("/dialogs/clonetiler/dotrace", true); + prefs->setBool("/dialogs/clonetiler/opentrace", true); + SPDesktop *dt = SP_ACTIVE_DESKTOP; + dt->_dlg_mgr->showDialog("CloneTiler"); + prefs->setBool("/dialogs/clonetiler/opentrace", false); } } @@ -177,7 +208,20 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); } + + /* Use Pressure Width button */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPressureWidthAction", + _("Pressure"), + _("Use the pressure of the input device to alter the width of spray area"), + INKSCAPE_ICON("draw-use-pressure"), + Inkscape::ICON_SIZE_DECORATION ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/spray/usepressurewidth"); + g_signal_connect(holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + } + { /* Mean */ gchar const* labels[] = {_("(default)"), 0, 0, 0, 0, 0, 0, _("(maximum mean)")}; @@ -272,15 +316,15 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj g_object_set_data( holder, "spray_population", eact ); } - /* Use Pressure button */ + /* Use Pressure Population button */ { - InkToggleAction* act = ink_toggle_action_new( "SprayPressureAction", + InkToggleAction* act = ink_toggle_action_new( "SprayPressurePopulationAction", _("Pressure"), _("Use the pressure of the input device to alter the amount of sprayed objects"), INKSCAPE_ICON("draw-use-pressure"), Inkscape::ICON_SIZE_DECORATION ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); - PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/spray/usepressure"); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/spray/usepressurepopulation"); g_signal_connect(holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); } @@ -321,6 +365,20 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj g_object_set_data( holder, "spray_scale", eact ); } + /* Use Pressure Scale button */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPressureScaleAction", + _("Pressure"), + _("Use the pressure of the input device to alter the scale of new items"), + INKSCAPE_ICON("draw-use-pressure"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/usepressurescale", false) ); + g_object_set_data( holder, "usepressurescale", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pressure_scale), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Picker */ { InkToggleAction* act = ink_toggle_action_new( "SprayPickColorAction", diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index ef2d89103..892d90cc1 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -310,11 +310,13 @@ static gchar const * ui_descr = " " " " " " + " " " " - " " + " " " " " " " " + " " " " " " " " -- cgit v1.2.3 From 670abe866479007812bdd5c5b29eff5116e06c8a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 30 Oct 2015 11:58:17 +0100 Subject: Some fixes to new pressure options (bzr r14422.1.29) --- src/ui/tools/spray-tool.cpp | 4 ++-- src/widgets/spray-toolbar.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index e78f5787e..a763e50a7 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -336,7 +336,7 @@ static double get_population(SprayTool *tc) static double get_pressure(SprayTool *tc) { - double pressure = (tc->usepressurepopulation? tc->pressure / TC_DEFAULT_PRESSURE : 1); + double pressure = tc->pressure / TC_DEFAULT_PRESSURE; //g_warning("Pressure, population: %f, %f", pressure, pressure * tc->population); return pressure; } @@ -559,7 +559,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, double angle = g_random_double_range( - rotation_variation / 100.0 * M_PI , rotation_variation / 100.0 * M_PI ); double _scale = g_random_double_range( 1.0 - scale_variation / 100.0, 1.0 + scale_variation / 100.0 ); if(usepressurescale){ - _scale = pressure * 2.0; + _scale = pressure; } double dr; double dp; random_position( dr, dp, mean, standard_deviation, _distrib ); diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 3b175b715..bc994d1b7 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -371,7 +371,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("Pressure"), _("Use the pressure of the input device to alter the scale of new items"), INKSCAPE_ICON("draw-use-pressure"), - secondarySize ); + Inkscape::ICON_SIZE_DECORATION); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/usepressurescale", false) ); g_object_set_data( holder, "usepressurescale", act ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pressure_scale), holder) ; -- cgit v1.2.3 From 0798ff4618d8e961cab364fdf827993c18aa69ac Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 30 Oct 2015 17:45:39 +0100 Subject: Open trace dialog on click on pick toogle (bzr r14422.1.30) --- src/ui/dialog/clonetiler.cpp | 14 ++++++++++---- src/ui/dialog/clonetiler.h | 4 +++- src/widgets/spray-toolbar.cpp | 22 +++++++++++++++++++--- 3 files changed, 32 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index 0b1d0ecf2..266d61ed5 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -101,7 +101,7 @@ CloneTiler::CloneTiler () : contents->pack_start (*Gtk::manage(Glib::wrap(mainbox)), true, true, 0); - GtkWidget *nb = gtk_notebook_new (); + nb = gtk_notebook_new (); gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0); @@ -776,7 +776,6 @@ CloneTiler::CloneTiler () : // Trace { GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace")); - { #if GTK_CHECK_VERSION(3,0,0) GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, VB_MARGIN); @@ -791,11 +790,11 @@ CloneTiler::CloneTiler () : gtk_notebook_set_current_page (GTK_NOTEBOOK(nb),5); } - GtkWidget *b = gtk_check_button_new_with_label (_("Trace the drawing under the tiles/spray tool")); + b = gtk_check_button_new_with_label (_("Trace the drawing under the tiles/spray tool")); g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE)); bool old = prefs->getBool(prefs_path + "dotrace"); gtk_toggle_button_set_active ((GtkToggleButton *) b, old); - gtk_widget_set_tooltip_text (b, _("For each clone, pick a value from the drawing in that clone's location and apply it to the clone")); + gtk_widget_set_tooltip_text (b, _("For each clone/ Sprayed item, pick a value from the drawing in that clone's or item spayed location and apply it")); gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(b), "toggled", @@ -3008,6 +3007,13 @@ void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg) } } +void CloneTiler::show_page_trace() +{ + gtk_notebook_set_current_page(GTK_NOTEBOOK(nb),6); + gtk_toggle_button_set_active ((GtkToggleButton *) b, true); +} + + } } } diff --git a/src/ui/dialog/clonetiler.h b/src/ui/dialog/clonetiler.h index e5f5638b2..a8f1df0a0 100644 --- a/src/ui/dialog/clonetiler.h +++ b/src/ui/dialog/clonetiler.h @@ -31,7 +31,7 @@ public: virtual ~CloneTiler(); static CloneTiler &getInstance() { return *new CloneTiler(); } - + void show_page_trace(); protected: GtkWidget * clonetiler_new_tab(GtkWidget *nb, const gchar *label); @@ -113,6 +113,8 @@ private: CloneTiler& operator=(CloneTiler const &d); GtkWidget *dlg; + GtkWidget *nb; + GtkWidget *b; SPDesktop *desktop; DesktopTracker deskTrack; Inkscape::UI::Widget::ColorPicker *color_picker; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index bc994d1b7..1e7d42378 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -42,6 +42,7 @@ #include "toolbox.h" #include "ui/dialog/clonetiler.h" #include "ui/dialog/dialog-manager.h" +#include "ui/dialog/panel-dialog.h" #include "ui/icon-names.h" #include @@ -81,6 +82,20 @@ static void sp_stb_sensitivize( GObject *tbl ) } } +Inkscape::UI::Dialog::CloneTiler *get_clone_tiler_panel(SPDesktop *desktop) +{ + if (Inkscape::UI::Dialog::PanelDialogBase *panel_dialog = + dynamic_cast(desktop->_dlg_mgr->getDialog("CloneTiler"))) { + try { + Inkscape::UI::Dialog::CloneTiler &clone_tiler = + dynamic_cast(panel_dialog->getPanel()); + return &clone_tiler; + } catch (std::exception &e) { } + } + + return 0; +} + static void sp_spray_width_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -182,10 +197,11 @@ static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) GtkToggleAction *visible = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "visible") ); gtk_toggle_action_set_active(visible, false); prefs->setBool("/dialogs/clonetiler/dotrace", true); - prefs->setBool("/dialogs/clonetiler/opentrace", true); SPDesktop *dt = SP_ACTIVE_DESKTOP; - dt->_dlg_mgr->showDialog("CloneTiler"); - prefs->setBool("/dialogs/clonetiler/opentrace", false); + if (Inkscape::UI::Dialog::CloneTiler *ct = get_clone_tiler_panel(dt)){ + dt->_dlg_mgr->showDialog("CloneTiler"); + ct->show_page_trace(); + } } } -- cgit v1.2.3 From 2b4566e6d203b6b3cf90bca23b7de48f576cc361 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 30 Oct 2015 19:45:10 +0100 Subject: Now picker use all features of trace clones (bzr r14422.1.31) --- src/ui/tools/spray-tool.cpp | 218 ++++++++++++++++++++++++++++++++++-------- src/widgets/spray-toolbar.cpp | 26 ----- src/widgets/toolbox.cpp | 1 - 3 files changed, 176 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index a763e50a7..d0ea62caa 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -97,6 +97,17 @@ namespace Inkscape { namespace UI { namespace Tools { +enum { + PICK_COLOR, + PICK_OPACITY, + PICK_R, + PICK_G, + PICK_B, + PICK_H, + PICK_S, + PICK_L +}; + const std::string& SprayTool::getPrefsPath() { return SprayTool::prefsPath; } @@ -164,7 +175,6 @@ SprayTool::SprayTool() , dilate_area(NULL) , overlap(false) , picker(false) - , visible(false) , offset(0) { } @@ -242,7 +252,6 @@ void SprayTool::setup() { sp_event_context_read(this, "Scale"); sp_event_context_read(this, "offset"); sp_event_context_read(this, "picker"); - sp_event_context_read(this, "visible"); sp_event_context_read(this, "overlap"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -289,8 +298,6 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->offset = CLAMP(val.getDouble(), -1000.0, 1000.0); } else if (path == "picker") { this->picker = val.getBool(); - } else if (path == "visible") { - this->visible = val.getBool(); } else if (path == "overlap") { this->overlap = val.getBool(); } @@ -394,19 +401,33 @@ static void sp_spray_transform_path(SPItem * item, Geom::Path &path, Geom::Affin path *= i2anc_affine(static_cast(item->parent), NULL); } +/** +Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same +probability of being displaced. + */ +double randomize01(double val, double rand) +{ + double base = MIN (val - rand, 1 - 2*rand); + if (base < 0) { + base = 0; + } + val = base + g_random_double_range (0, MIN (2 * rand, 1 - base)); + return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case... +} + static bool fit_item(SPDesktop *desktop, SPItem *item, Geom::OptRect bbox, Geom::Point move, Geom::Point center, double angle, - double _scale, + double &_scale, double scale, bool picker, - bool visible, bool overlap, double offset, - SPCSSAttr *css) + SPCSSAttr *css, + bool trace_scale) { SPDocument *doc = item->document; double width = bbox->width(); @@ -416,30 +437,30 @@ static bool fit_item(SPDesktop *desktop, if(offset_min < 0 ){ offset_min = 0; } - bbox = Geom::Rect(Geom::Point(bbox->left() - offset_min, bbox->top() - offset_min),Geom::Point(bbox->right() + offset_min, bbox->bottom() + offset_min)); + Geom::OptRect bbox_procesed = Geom::Rect(Geom::Point(bbox->left() - offset_min, bbox->top() - offset_min),Geom::Point(bbox->right() + offset_min, bbox->bottom() + offset_min)); Geom::Path path; - path.start(Geom::Point(bbox->left(), bbox->top())); - path.appendNew(Geom::Point(bbox->right(), bbox->top())); - path.appendNew(Geom::Point(bbox->right(), bbox->bottom())); - path.appendNew(Geom::Point(bbox->left(), bbox->bottom())); + path.start(Geom::Point(bbox_procesed->left(), bbox_procesed->top())); + path.appendNew(Geom::Point(bbox_procesed->right(), bbox_procesed->top())); + path.appendNew(Geom::Point(bbox_procesed->right(), bbox_procesed->bottom())); + path.appendNew(Geom::Point(bbox_procesed->left(), bbox_procesed->bottom())); path.close(true); sp_spray_transform_path(item, path, Geom::Scale(_scale), center); sp_spray_transform_path(item, path, Geom::Scale(scale), center); sp_spray_transform_path(item, path, Geom::Rotate(angle), center); path *= Geom::Translate(move[Geom::X], move[Geom::Y]); path *= desktop->doc2dt(); - bbox = path.boundsFast(); - double bbox_left_main = bbox->left(); - double bbox_top_main = bbox->top(); - double width_transformed = bbox->width(); - double height_transformed = bbox->height(); + bbox_procesed = path.boundsFast(); + double bbox_left_main = bbox_procesed->left(); + double bbox_top_main = bbox_procesed->top(); + double width_transformed = bbox_procesed->width(); + double height_transformed = bbox_procesed->height(); size = std::min(width_transformed,height_transformed); if(offset < 100 ){ offset_min = ((99.0 - offset) * size)/100.0 - size; } else { offset_min = 0; } - std::vector items_down = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox); + std::vector items_down = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox_procesed); Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { return false; @@ -470,18 +491,29 @@ static bool fit_item(SPDesktop *desktop, std::abs(bbox_top - bbox_top_main) > std::abs(offset_min))){ return false; } - } else if(picker || visible){ + } else if(picker){ item_down->setHidden(true); item_down->updateRepr(); } } } } - if(picker || visible){ + if(picker){ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if(!overlap){ doc->ensureUpToDate(); } - Geom::Point mid_point = desktop->d2w(bbox->midpoint()); + int pick = prefs->getInt("/dialogs/clonetiler/pick"); + bool pick_to_presence = prefs->getBool("/dialogs/clonetiler/pick_to_presence"); + bool pick_to_size = prefs->getBool("/dialogs/clonetiler/pick_to_size"); + bool pick_to_color = prefs->getBool("/dialogs/clonetiler/pick_to_color"); + bool pick_to_opacity = prefs->getBool("/dialogs/clonetiler/pick_to_opacity"); + double rand_picked = 0.01 * prefs->getDoubleLimited("/dialogs/clonetiler/rand_picked", 0, 0, 100); + bool invert_picked = prefs->getBool("/dialogs/clonetiler/invert_picked"); + double gamma_picked = prefs->getDoubleLimited("/dialogs/clonetiler/gamma_picked", 0, -10, 10); + double opacity = 1.0; + gchar color_string[32]; *color_string = 0; + Geom::Point mid_point = desktop->d2w(bbox_procesed->midpoint()); Geom::IntRect area = Geom::IntRect::from_xywh(floor(mid_point[Geom::X]), floor(mid_point[Geom::Y]), 1, 1); double R = 0, G = 0, B = 0, A = 0; cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); @@ -491,20 +523,126 @@ static bool fit_item(SPDesktop *desktop, if (fabs(A) < 1e-4) { A = 0; // suppress exponentials, CSS does not allow that } + if(A == 0 && R == 0 && G == 0 && B == 0){ + R = 1; + G = 1; + B = 1; + } if(picker){ - if (A > 0) { - R /= A; - G /= A; - B /= A; +// if (A > 0) { +// R /= A; +// G /= A; +// B /= A; +// } + guint32 rgba = SP_RGBA32_F_COMPOSE(R, G, B, A); + float r = SP_RGBA32_R_F(rgba); + float g = SP_RGBA32_G_F(rgba); + float b = SP_RGBA32_B_F(rgba); + float a = SP_RGBA32_A_F(rgba); + + float hsl[3]; + sp_color_rgb_to_hsl_floatv (hsl, r, g, b); + + gdouble val = 0; + switch (pick) { + case PICK_COLOR: + val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max + break; + case PICK_OPACITY: + val = a; + break; + case PICK_R: + val = r; + break; + case PICK_G: + val = g; + break; + case PICK_B: + val = b; + break; + case PICK_H: + val = hsl[0]; + break; + case PICK_S: + val = hsl[1]; + break; + case PICK_L: + val = 1 - hsl[2]; + break; + default: + break; + } + + if (rand_picked > 0) { + val = randomize01 (val, rand_picked); + r = randomize01 (r, rand_picked); + g = randomize01 (g, rand_picked); + b = randomize01 (b, rand_picked); + } + + if (gamma_picked != 0) { + double power; + if (gamma_picked > 0) + power = 1/(1 + fabs(gamma_picked)); + else + power = 1 + fabs(gamma_picked); + + val = pow (val, power); + r = pow (r, power); + g = pow (g, power); + b = pow (b, power); + } + + if (invert_picked) { + val = 1 - val; + r = 1 - r; + g = 1 - g; + b = 1 - b; + } + + val = CLAMP (val, 0, 1); + r = CLAMP (r, 0, 1); + g = CLAMP (g, 0, 1); + b = CLAMP (b, 0, 1); + + // recompose tweaked color + rgba = SP_RGBA32_F_COMPOSE(r, g, b, a); + if (pick_to_presence) { + //this line I think is wrong in original code clonetiler + //if (g_random_double_range (0, 1) > val) { + if(a == 0){ + return false; + } + } + if (pick_to_size) { + if(!trace_scale){ + _scale = 2 - (val * 1.7); + return fit_item(desktop, + item, + bbox, + move, + center, + angle, + _scale, + scale, + picker, + overlap, + offset, + css, + true); + } + } + if (pick_to_opacity) { + opacity *= a; + std::stringstream fill_opacity; + fill_opacity.imbue(std::locale::classic()); + fill_opacity << float(opacity); + sp_repr_css_set_property(css, "fill-opacity", fill_opacity.str().c_str()); + } + if (pick_to_color) { + sp_svg_write_color(color_string, sizeof(color_string), rgba); + sp_repr_css_set_property(css, "fill", color_string); } - guint32 c32 = SP_RGBA32_F_COMPOSE(R, G, B, A); - gchar c[64]; - sp_svg_write_color(c, sizeof(c), c32); - sp_repr_css_set_property(css, "fill", c); - std::stringstream fill_opacity; - fill_opacity.imbue(std::locale::classic()); - fill_opacity << float(A); - sp_repr_css_set_property(css, "fill-opacity", fill_opacity.str().c_str()); } if(!overlap){ for (std::vector::const_iterator k=items_down.begin(); k!=items_down.end(); k++) { @@ -513,9 +651,6 @@ static bool fit_item(SPDesktop *desktop, item_hidden->updateRepr(); } } - if(A == 0){ - return false; - } } return true; } @@ -539,7 +674,6 @@ static bool sp_spray_recursive(SPDesktop *desktop, gint _distrib, bool overlap, bool picker, - bool visible, double offset, bool usepressurescale, double pressure) @@ -580,8 +714,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center = item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); - if(overlap || picker || visible){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, visible, overlap, offset, css)){ + if(overlap || picker){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, overlap, offset, css, false)){ return false; } } @@ -687,8 +821,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center=item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); - if(overlap || picker || visible){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, visible, overlap, offset, css)){ + if(overlap || picker){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, overlap, offset, css, false)){ return false; } } @@ -766,7 +900,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = *i; g_assert(item != NULL); - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->picker, tc->visible, tc->offset, tc->usepressurescale, get_pressure(tc))) { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->picker, tc->offset, tc->usepressurescale, get_pressure(tc))) { did = true; } } diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 1e7d42378..842b8e0aa 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -173,19 +173,6 @@ static void sp_toggle_pressure_scale( GtkToggleAction* act, gpointer data) sp_stb_sensitivize( tbl ); } -static void sp_toggle_visible( GtkToggleAction* act, gpointer data) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gboolean active = gtk_toggle_action_get_active(act); - prefs->setBool("/tools/spray/visible", active); - if(active == true){ - prefs->setBool("/tools/spray/picker", false); - GObject *tbl = G_OBJECT(data); - GtkToggleAction *picker = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "picker") ); - gtk_toggle_action_set_active(picker, false); - } -} - static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -408,19 +395,6 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - /* Visible */ - { - InkToggleAction* act = ink_toggle_action_new( "SprayOverVisibleAction", - _("Apply on non transparent areas"), - _("Apply on non transparent areas"), - INKSCAPE_ICON("object-visible"), - secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/visible", false) ); - g_object_set_data( holder, "visible", act ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_visible), holder) ; - gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); - } - /* Overlap */ { InkToggleAction* act = ink_toggle_action_new( "SprayNotOverlapAction", diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 892d90cc1..0c72242e0 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -322,7 +322,6 @@ static gchar const * ui_descr = " " " " " " - " " " " " " -- cgit v1.2.3 From 0f6203288f49de2a3958b4adf3318b5777817169 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 30 Oct 2015 20:58:42 +0100 Subject: Fix a bug compiling on pow (bzr r14422.1.32) --- src/ui/tools/spray-tool.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index d0ea62caa..f81a274d1 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -588,9 +588,9 @@ static bool fit_item(SPDesktop *desktop, power = 1 + fabs(gamma_picked); val = pow (val, power); - r = pow (r, power); - g = pow (g, power); - b = pow (b, power); + r = pow ((double)r, (double)power); + g = pow ((double)g, (double)power); + b = pow ((double)b, (double)power); } if (invert_picked) { -- cgit v1.2.3 From ee0d08e599aae484a6e8354499b126596dc4aa73 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 31 Oct 2015 21:51:10 +0100 Subject: Working on picker (bzr r14422.1.33) --- src/ui/dialog/clonetiler.cpp | 16 +++++- src/ui/tools/spray-tool.cpp | 128 ++++++++++++++++++++++++++++-------------- src/ui/tools/spray-tool.h | 3 + src/widgets/spray-toolbar.cpp | 103 +++++++++++++++++++++++++++++++-- src/widgets/toolbox.cpp | 4 ++ 5 files changed, 203 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index 266d61ed5..da6cc5192 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -662,7 +662,7 @@ CloneTiler::CloneTiler () : gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0); guint32 rgba = 0x000000ff | sp_svg_read_color (prefs->getString(prefs_path + "initial_color").data(), 0x000000ff); - color_picker = new Inkscape::UI::Widget::ColorPicker (*new Glib::ustring(_("Initial color of tiled clones")), *new Glib::ustring(_("Initial color for clones (works only if the original has unset fill or stroke)")), rgba, false); + color_picker = new Inkscape::UI::Widget::ColorPicker (*new Glib::ustring(_("Initial color of tiled clones")), *new Glib::ustring(_("Initial color for clones (works only if the original has unset fill or stroke or on spray tool in copy mode)")), rgba, false); color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed)); gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast(color_picker->gobj()), FALSE, FALSE, 0); @@ -1003,7 +1003,19 @@ CloneTiler::CloneTiler () : gtk_widget_set_sensitive (vvb, prefs->getBool(prefs_path + "dotrace")); } } - + // Info + { +#if GTK_CHECK_VERSION(3,0,0) + GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, VB_MARGIN); + gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); +#else + GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN); +#endif + gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0); + GtkWidget *l = gtk_label_new(_("")); + gtk_label_set_markup (GTK_LABEL(l), _("Apply to tiled clones:")); + gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0); + } // Rows/columns, width/height { #if GTK_CHECK_VERSION(3,0,0) diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index f81a274d1..0b54d3779 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -175,6 +175,10 @@ SprayTool::SprayTool() , dilate_area(NULL) , overlap(false) , picker(false) + , pickinversescale(false) + , pickfill(false) + , pickstroke(false) + , visible(false) , offset(0) { } @@ -252,6 +256,10 @@ void SprayTool::setup() { sp_event_context_read(this, "Scale"); sp_event_context_read(this, "offset"); sp_event_context_read(this, "picker"); + sp_event_context_read(this, "pickinversescale"); + sp_event_context_read(this, "pickfill"); + sp_event_context_read(this, "pickstroke"); + sp_event_context_read(this, "visible"); sp_event_context_read(this, "overlap"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -298,6 +306,14 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->offset = CLAMP(val.getDouble(), -1000.0, 1000.0); } else if (path == "picker") { this->picker = val.getBool(); + } else if (path == "pickinversescale") { + this->pickinversescale = val.getBool(); + } else if (path == "pickfill") { + this->pickfill = val.getBool(); + } else if (path == "pickstroke") { + this->pickstroke = val.getBool(); + } else if (path == "visible") { + this->visible = val.getBool(); } else if (path == "overlap") { this->overlap = val.getBool(); } @@ -424,6 +440,10 @@ static bool fit_item(SPDesktop *desktop, double &_scale, double scale, bool picker, + bool pickinversescale, + bool pickfill, + bool pickstroke, + bool visible, bool overlap, double offset, SPCSSAttr *css, @@ -491,21 +511,21 @@ static bool fit_item(SPDesktop *desktop, std::abs(bbox_top - bbox_top_main) > std::abs(offset_min))){ return false; } - } else if(picker){ + } else if(picker || visible){ item_down->setHidden(true); item_down->updateRepr(); } } } } - if(picker){ + if(picker || visible){ Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if(!overlap){ doc->ensureUpToDate(); } int pick = prefs->getInt("/dialogs/clonetiler/pick"); - bool pick_to_presence = prefs->getBool("/dialogs/clonetiler/pick_to_presence"); bool pick_to_size = prefs->getBool("/dialogs/clonetiler/pick_to_size"); + bool pick_to_presence = prefs->getBool("/dialogs/clonetiler/pick_to_presence", false); bool pick_to_color = prefs->getBool("/dialogs/clonetiler/pick_to_color"); bool pick_to_opacity = prefs->getBool("/dialogs/clonetiler/pick_to_opacity"); double rand_picked = 0.01 * prefs->getDoubleLimited("/dialogs/clonetiler/rand_picked", 0, 0, 100); @@ -518,28 +538,24 @@ static bool fit_item(SPDesktop *desktop, double R = 0, G = 0, B = 0, A = 0; cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); sp_canvas_arena_render_surface(SP_CANVAS_ARENA(desktop->getDrawing()), s, area); - ink_cairo_surface_average_color_premul(s, R, G, B, A); + ink_cairo_surface_average_color(s, R, G, B, A); cairo_surface_destroy(s); - if (fabs(A) < 1e-4) { - A = 0; // suppress exponentials, CSS does not allow that + guint32 rgba = SP_RGBA32_F_COMPOSE(R, G, B, A); + float r = SP_RGBA32_R_F(rgba); + float g = SP_RGBA32_G_F(rgba); + float b = SP_RGBA32_B_F(rgba); + float a = SP_RGBA32_A_F(rgba); + //this can fix the bug #1511998 if confirmed + if( a == 0 && r == 0 && g == 0 && b == 0){ + r = 1; + g = 1; + b = 1; } - if(A == 0 && R == 0 && G == 0 && B == 0){ - R = 1; - G = 1; - B = 1; + if(visible && (a == 0 || a < 1e-6)){ + return false; } - if(picker){ -// if (A > 0) { -// R /= A; -// G /= A; -// B /= A; -// } - guint32 rgba = SP_RGBA32_F_COMPOSE(R, G, B, A); - float r = SP_RGBA32_R_F(rgba); - float g = SP_RGBA32_G_F(rgba); - float b = SP_RGBA32_B_F(rgba); - float a = SP_RGBA32_A_F(rgba); + if(picker){ float hsl[3]; sp_color_rgb_to_hsl_floatv (hsl, r, g, b); @@ -607,17 +623,17 @@ static bool fit_item(SPDesktop *desktop, // recompose tweaked color rgba = SP_RGBA32_F_COMPOSE(r, g, b, a); - if (pick_to_presence) { - //this line I think is wrong in original code clonetiler - //if (g_random_double_range (0, 1) > val) { - if(a == 0){ - return false; - } - } if (pick_to_size) { if(!trace_scale){ - _scale = 2 - (val * 1.7); - return fit_item(desktop, + if(pickinversescale){ + _scale = 1.0 - val; + } else { + _scale = val; + } + if _scale == 0.0){ + return false; + } + if(!fit_item(desktop, item, bbox, move, @@ -626,25 +642,47 @@ static bool fit_item(SPDesktop *desktop, _scale, scale, picker, + pickinversescale, + pickfill, + pickstroke, + visible, overlap, offset, css, - true); + true)){ + return false; + } } } + if (pick_to_opacity) { - opacity *= a; - std::stringstream fill_opacity; - fill_opacity.imbue(std::locale::classic()); - fill_opacity << float(opacity); - sp_repr_css_set_property(css, "fill-opacity", fill_opacity.str().c_str()); + opacity *= val; + std::stringstream opacity_str; + opacity_str.imbue(std::locale::classic()); + opacity_str << opacity; + sp_repr_css_set_property(css, "opacity", opacity_str.str().c_str()); + } + if (pick_to_presence) { + if (g_random_double_range (0, 1) > val) { + //Hidding the element is a way to retain original + //beabiohur of tiled clones for presence option. + sp_repr_css_set_property(css, "opacity", "0"); + } } if (pick_to_color) { sp_svg_write_color(color_string, sizeof(color_string), rgba); - sp_repr_css_set_property(css, "fill", color_string); + if(pickfill){ + sp_repr_css_set_property(css, "fill", color_string); + } + if(pickstroke){ + sp_repr_css_set_property(css, "stroke", color_string); + } + } + if (opacity < 1e-6) { // invisibly transparent, skip + return false; } } - if(!overlap){ + if(!overlap && (picker || visible)){ for (std::vector::const_iterator k=items_down.begin(); k!=items_down.end(); k++) { SPItem *item_hidden = *k; item_hidden->setHidden(false); @@ -674,6 +712,10 @@ static bool sp_spray_recursive(SPDesktop *desktop, gint _distrib, bool overlap, bool picker, + bool pickinversescale, + bool pickfill, + bool pickstroke, + bool visible, double offset, bool usepressurescale, double pressure) @@ -714,8 +756,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center = item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); - if(overlap || picker){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, overlap, offset, css, false)){ + if(overlap || picker || visible){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversescale, pickfill, pickstroke, visible, overlap, offset, css, false)){ return false; } } @@ -821,8 +863,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center=item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); - if(overlap || picker){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, overlap, offset, css, false)){ + if(overlap || picker || visible){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversescale, pickfill, pickstroke, visible, overlap, offset, css, false)){ return false; } } @@ -900,7 +942,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = *i; g_assert(item != NULL); - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->picker, tc->offset, tc->usepressurescale, get_pressure(tc))) { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->picker, tc->pickinversescale, tc->pickfill, tc->pickstroke, tc->visible, tc->offset, tc->usepressurescale, get_pressure(tc))) { did = true; } } diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index 112ab77e9..89a06dee9 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -91,6 +91,9 @@ public: SPCanvasItem *dilate_area; bool overlap; bool picker; + bool pickinversescale; + bool pickfill; + bool pickstroke; bool visible; double offset; sigc::connection style_set_connection; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 842b8e0aa..ce37ac9f7 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -67,7 +67,11 @@ static void sp_stb_sensitivize( GObject *tbl ) GtkAdjustment *adj_offset = ege_adjustment_action_get_adjustment( EGE_ADJUSTMENT_ACTION(offset) ); GtkAdjustment *adj_scale = ege_adjustment_action_get_adjustment( EGE_ADJUSTMENT_ACTION(spray_scale) ); GtkToggleAction *overlap = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "overlap") ); + GtkToggleAction *picker = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "picker") ); GtkToggleAction *usepressurescale = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "usepressurescale") ); + GtkAction *pickfill = GTK_ACTION( g_object_get_data(tbl, "pickfill") ); + GtkAction *pickstroke = GTK_ACTION( g_object_get_data(tbl, "pickstroke") ); + GtkAction *pickinversescale = GTK_ACTION( g_object_get_data(tbl, "pickinversescale") ); gtk_adjustment_set_value( adj_offset, 100.0 ); if (gtk_toggle_action_get_active(overlap)) { gtk_action_set_sensitive( offset, TRUE ); @@ -80,6 +84,15 @@ static void sp_stb_sensitivize( GObject *tbl ) } else { gtk_action_set_sensitive( spray_scale, TRUE ); } + if(gtk_toggle_action_get_active(picker)){ + gtk_action_set_sensitive( pickfill, TRUE ); + gtk_action_set_sensitive( pickstroke, TRUE ); + gtk_action_set_sensitive( pickinversescale, TRUE ); + } else { + gtk_action_set_sensitive( pickfill, FALSE ); + gtk_action_set_sensitive( pickstroke, FALSE ); + gtk_action_set_sensitive( pickinversescale, FALSE ); + } } Inkscape::UI::Dialog::CloneTiler *get_clone_tiler_panel(SPDesktop *desktop) @@ -173,16 +186,19 @@ static void sp_toggle_pressure_scale( GtkToggleAction* act, gpointer data) sp_stb_sensitivize( tbl ); } +static void sp_toggle_visible( GtkToggleAction* act, gpointer data) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/visible", active); +} + static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); prefs->setBool("/tools/spray/picker", active); if(active == true){ - prefs->setBool("/tools/spray/visible", false); - GObject *tbl = G_OBJECT(data); - GtkToggleAction *visible = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "visible") ); - gtk_toggle_action_set_active(visible, false); prefs->setBool("/dialogs/clonetiler/dotrace", true); SPDesktop *dt = SP_ACTIVE_DESKTOP; if (Inkscape::UI::Dialog::CloneTiler *ct = get_clone_tiler_panel(dt)){ @@ -190,6 +206,29 @@ static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) ct->show_page_trace(); } } + GObject *tbl = G_OBJECT(data); + sp_stb_sensitivize(tbl); +} + +static void sp_toggle_pickfill( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/pickfill", active); +} + +static void sp_toggle_pickinversescale( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/pickinversescale", active); +} + +static void sp_toggle_pickstroke( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/pickstroke", active); } void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) @@ -385,8 +424,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Picker */ { InkToggleAction* act = ink_toggle_action_new( "SprayPickColorAction", - _("Pick down color. Fill must be unset on original when spraying clones"), - _("Pick down color. Fill must be unset on original when spraying clones"), + _("Pick down. Fill or Stroke must be unset on original when spraying color to clones"), + _("Pick down. Fill or Stroke must be unset on original when spraying color to clones"), INKSCAPE_ICON("color-picker"), secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/picker", false) ); @@ -395,6 +434,58 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } + /* Inverse Scale */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayOverPickInverseScaleAction", + _("Apply inversed scale to pick"), + _("Apply inversed scale to pick"), + INKSCAPE_ICON("object-tweak-shrink"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickinversescale", false) ); + g_object_set_data( holder, "pickinversescale", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pickinversescale), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Pick Fill */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayOverPickFillAction", + _("Apply picked color to fill"), + _("Apply picked color to fill"), + INKSCAPE_ICON("paint-solid"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickfill", false) ); + g_object_set_data( holder, "pickfill", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pickfill), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Pick Stroke */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayOverPickStrokeAction", + _("Apply picked color to stroke"), + _("Apply picked color to stroke"), + INKSCAPE_ICON("no-marker"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickstroke", false) ); + g_object_set_data( holder, "pickstroke", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pickstroke), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Visible */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayOverVisibleAction", + _("Apply only over non transparent areas"), + _("Apply only over non transparent areas"), + INKSCAPE_ICON("object-visible"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/visible", false) ); + g_object_set_data( holder, "visible", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_visible), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + /* Overlap */ { InkToggleAction* act = ink_toggle_action_new( "SprayNotOverlapAction", diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 0c72242e0..0188beef0 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -322,6 +322,10 @@ static gchar const * ui_descr = " " " " " " + " " + " " + " " + " " " " " " -- cgit v1.2.3 From be64ba3e07ac16e14712929756739de6b4465fef Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 31 Oct 2015 23:50:21 +0100 Subject: 'End' of picker work (bzr r14422.1.35) --- src/ui/dialog/clonetiler.cpp | 5 ----- src/ui/tools/spray-tool.cpp | 48 +++++++++++++++++++++---------------------- src/ui/tools/spray-tool.h | 4 ++-- src/widgets/spray-toolbar.cpp | 48 +++++++++++++++++++++---------------------- src/widgets/toolbox.cpp | 5 +++-- 5 files changed, 53 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index da6cc5192..e842cf78f 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -785,11 +785,6 @@ CloneTiler::CloneTiler () : #endif gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if(prefs->getBool("/dialogs/clonetiler/opentrace", false)){ - gtk_notebook_set_current_page (GTK_NOTEBOOK(nb),5); - } - b = gtk_check_button_new_with_label (_("Trace the drawing under the tiles/spray tool")); g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE)); bool old = prefs->getBool(prefs_path + "dotrace"); diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 0b54d3779..d9a5de377 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -173,9 +173,9 @@ SprayTool::SprayTool() , is_dilating(false) , has_dilated(false) , dilate_area(NULL) - , overlap(false) + , nooverlap(false) , picker(false) - , pickinversescale(false) + , pickinversesize(false) , pickfill(false) , pickstroke(false) , visible(false) @@ -256,11 +256,11 @@ void SprayTool::setup() { sp_event_context_read(this, "Scale"); sp_event_context_read(this, "offset"); sp_event_context_read(this, "picker"); - sp_event_context_read(this, "pickinversescale"); + sp_event_context_read(this, "pickinversesize"); sp_event_context_read(this, "pickfill"); sp_event_context_read(this, "pickstroke"); sp_event_context_read(this, "visible"); - sp_event_context_read(this, "overlap"); + sp_event_context_read(this, "nooverlap"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/spray/selcue")) { @@ -306,16 +306,16 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->offset = CLAMP(val.getDouble(), -1000.0, 1000.0); } else if (path == "picker") { this->picker = val.getBool(); - } else if (path == "pickinversescale") { - this->pickinversescale = val.getBool(); + } else if (path == "pickinversesize") { + this->pickinversesize = val.getBool(); } else if (path == "pickfill") { this->pickfill = val.getBool(); } else if (path == "pickstroke") { this->pickstroke = val.getBool(); } else if (path == "visible") { this->visible = val.getBool(); - } else if (path == "overlap") { - this->overlap = val.getBool(); + } else if (path == "nooverlap") { + this->nooverlap = val.getBool(); } } @@ -440,11 +440,11 @@ static bool fit_item(SPDesktop *desktop, double &_scale, double scale, bool picker, - bool pickinversescale, + bool pickinversesize, bool pickfill, bool pickstroke, bool visible, - bool overlap, + bool nooverlap, double offset, SPCSSAttr *css, bool trace_scale) @@ -506,7 +506,7 @@ static bool fit_item(SPDesktop *desktop, (item_down->getAttribute("inkscape:spray-origin") && strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) { - if(overlap){ + if(nooverlap){ if(!(offset_min < 0 && std::abs(bbox_left - bbox_left_main) > std::abs(offset_min) && std::abs(bbox_top - bbox_top_main) > std::abs(offset_min))){ return false; @@ -520,7 +520,7 @@ static bool fit_item(SPDesktop *desktop, } if(picker || visible){ Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if(!overlap){ + if(!nooverlap){ doc->ensureUpToDate(); } int pick = prefs->getInt("/dialogs/clonetiler/pick"); @@ -625,12 +625,12 @@ static bool fit_item(SPDesktop *desktop, rgba = SP_RGBA32_F_COMPOSE(r, g, b, a); if (pick_to_size) { if(!trace_scale){ - if(pickinversescale){ + if(pickinversesize) { _scale = 1.0 - val; } else { _scale = val; } - if _scale == 0.0){ + if(_scale == 0.0) { return false; } if(!fit_item(desktop, @@ -642,11 +642,11 @@ static bool fit_item(SPDesktop *desktop, _scale, scale, picker, - pickinversescale, + pickinversesize, pickfill, pickstroke, visible, - overlap, + nooverlap, offset, css, true)){ @@ -682,7 +682,7 @@ static bool fit_item(SPDesktop *desktop, return false; } } - if(!overlap && (picker || visible)){ + if(!nooverlap && (picker || visible)){ for (std::vector::const_iterator k=items_down.begin(); k!=items_down.end(); k++) { SPItem *item_hidden = *k; item_hidden->setHidden(false); @@ -710,9 +710,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, double tilt, double rotation_variation, gint _distrib, - bool overlap, + bool nooverlap, bool picker, - bool pickinversescale, + bool pickinversesize, bool pickfill, bool pickstroke, bool visible, @@ -756,8 +756,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center = item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); - if(overlap || picker || visible){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversescale, pickfill, pickstroke, visible, overlap, offset, css, false)){ + if(nooverlap || picker || visible){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversesize, pickfill, pickstroke, visible, nooverlap, offset, css, false)){ return false; } } @@ -863,8 +863,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point center=item->getCenter(); Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); - if(overlap || picker || visible){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversescale, pickfill, pickstroke, visible, overlap, offset, css, false)){ + if(nooverlap || picker || visible){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversesize, pickfill, pickstroke, visible, nooverlap, offset, css, false)){ return false; } } @@ -942,7 +942,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = *i; g_assert(item != NULL); - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->overlap, tc->picker, tc->pickinversescale, tc->pickfill, tc->pickstroke, tc->visible, tc->offset, tc->usepressurescale, get_pressure(tc))) { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->nooverlap, tc->picker, tc->pickinversesize, tc->pickfill, tc->pickstroke, tc->visible, tc->offset, tc->usepressurescale, get_pressure(tc))) { did = true; } } diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index 89a06dee9..212948c77 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -89,9 +89,9 @@ public: bool has_dilated; Geom::Point last_push; SPCanvasItem *dilate_area; - bool overlap; + bool nooverlap; bool picker; - bool pickinversescale; + bool pickinversesize; bool pickfill; bool pickstroke; bool visible; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index ce37ac9f7..c7013b6a1 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -66,14 +66,14 @@ static void sp_stb_sensitivize( GObject *tbl ) GtkAction* spray_scale = GTK_ACTION( g_object_get_data(tbl, "spray_scale") ); GtkAdjustment *adj_offset = ege_adjustment_action_get_adjustment( EGE_ADJUSTMENT_ACTION(offset) ); GtkAdjustment *adj_scale = ege_adjustment_action_get_adjustment( EGE_ADJUSTMENT_ACTION(spray_scale) ); - GtkToggleAction *overlap = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "overlap") ); + GtkToggleAction *nooverlap = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "nooverlap") ); GtkToggleAction *picker = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "picker") ); GtkToggleAction *usepressurescale = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "usepressurescale") ); GtkAction *pickfill = GTK_ACTION( g_object_get_data(tbl, "pickfill") ); GtkAction *pickstroke = GTK_ACTION( g_object_get_data(tbl, "pickstroke") ); - GtkAction *pickinversescale = GTK_ACTION( g_object_get_data(tbl, "pickinversescale") ); + GtkAction *pickinversesize = GTK_ACTION( g_object_get_data(tbl, "pickinversesize") ); gtk_adjustment_set_value( adj_offset, 100.0 ); - if (gtk_toggle_action_get_active(overlap)) { + if (gtk_toggle_action_get_active(nooverlap)) { gtk_action_set_sensitive( offset, TRUE ); } else { gtk_action_set_sensitive( offset, FALSE ); @@ -87,11 +87,11 @@ static void sp_stb_sensitivize( GObject *tbl ) if(gtk_toggle_action_get_active(picker)){ gtk_action_set_sensitive( pickfill, TRUE ); gtk_action_set_sensitive( pickstroke, TRUE ); - gtk_action_set_sensitive( pickinversescale, TRUE ); + gtk_action_set_sensitive( pickinversesize, TRUE ); } else { gtk_action_set_sensitive( pickfill, FALSE ); gtk_action_set_sensitive( pickstroke, FALSE ); - gtk_action_set_sensitive( pickinversescale, FALSE ); + gtk_action_set_sensitive( pickinversesize, FALSE ); } } @@ -165,11 +165,11 @@ static void sp_spray_offset_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ gtk_adjustment_get_value(adj)); } -static void sp_toggle_not_overlap( GtkToggleAction* act, gpointer data) +static void sp_toggle_nooverlap( GtkToggleAction* act, gpointer data) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setBool("/tools/spray/overlap", active); + prefs->setBool("/tools/spray/nooverlap", active); GObject *tbl = G_OBJECT(data); sp_stb_sensitivize(tbl); } @@ -210,21 +210,21 @@ static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) sp_stb_sensitivize(tbl); } -static void sp_toggle_pickfill( GtkToggleAction* act, gpointer data ) +static void sp_toggle_pick_fill( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); prefs->setBool("/tools/spray/pickfill", active); } -static void sp_toggle_pickinversescale( GtkToggleAction* act, gpointer data ) +static void sp_toggle_pick_inverse_size( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setBool("/tools/spray/pickinversescale", active); + prefs->setBool("/tools/spray/pickinversesize", active); } -static void sp_toggle_pickstroke( GtkToggleAction* act, gpointer data ) +static void sp_toggle_pick_stroke( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); @@ -434,16 +434,16 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - /* Inverse Scale */ + /* Inverse Value Size */ { - InkToggleAction* act = ink_toggle_action_new( "SprayOverPickInverseScaleAction", - _("Apply inversed scale to pick"), - _("Apply inversed scale to pick"), + InkToggleAction* act = ink_toggle_action_new( "SprayOverPickInverseSizeAction", + _("Apply inversed to pick value size"), + _("Apply inversed to pick value size"), INKSCAPE_ICON("object-tweak-shrink"), secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickinversescale", false) ); - g_object_set_data( holder, "pickinversescale", act ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pickinversescale), holder) ; + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickinversesize", false) ); + g_object_set_data( holder, "pickinversesize", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_inverse_size), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } @@ -456,7 +456,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickfill", false) ); g_object_set_data( holder, "pickfill", act ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pickfill), holder) ; + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_fill), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } @@ -469,7 +469,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickstroke", false) ); g_object_set_data( holder, "pickstroke", act ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pickstroke), holder) ; + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_stroke), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } @@ -488,16 +488,16 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Overlap */ { - InkToggleAction* act = ink_toggle_action_new( "SprayNotOverlapAction", + InkToggleAction* act = ink_toggle_action_new( "SprayNoOverlapAction", _("Prevent overlapping objects"), _("Prevent overlapping objects"), INKSCAPE_ICON("distribute-randomize"), secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/overlap", false) ); - g_object_set_data( holder, "overlap", act ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/nooverlap", false) ); + g_object_set_data( holder, "nooverlap", act ); //g_object_set_data (context_object, "holder", holder); //g_object_set_data (context_object, "desktop", desktop); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_not_overlap), holder) ; + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_nooverlap), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 0188beef0..6457b7c7e 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -322,11 +322,12 @@ static gchar const * ui_descr = " " " " " " - " " + " " " " " " + " " " " - " " + " " " " " " -- cgit v1.2.3 From e5ef21e284cd3bd7da7f15fcee7f4d1999457b2e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 1 Nov 2015 00:51:14 +0100 Subject: Order disposition of icons Add inverse also to opacity (bzr r14422.1.37) --- src/ui/tools/spray-tool.cpp | 28 ++++++++++++++++------------ src/ui/tools/spray-tool.h | 2 +- src/widgets/spray-toolbar.cpp | 22 +++++++++++----------- src/widgets/toolbox.cpp | 10 +++++----- 4 files changed, 33 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index d9a5de377..f7762ad8a 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -175,7 +175,7 @@ SprayTool::SprayTool() , dilate_area(NULL) , nooverlap(false) , picker(false) - , pickinversesize(false) + , pickinversevalue(false) , pickfill(false) , pickstroke(false) , visible(false) @@ -256,7 +256,7 @@ void SprayTool::setup() { sp_event_context_read(this, "Scale"); sp_event_context_read(this, "offset"); sp_event_context_read(this, "picker"); - sp_event_context_read(this, "pickinversesize"); + sp_event_context_read(this, "pickinversevalue"); sp_event_context_read(this, "pickfill"); sp_event_context_read(this, "pickstroke"); sp_event_context_read(this, "visible"); @@ -306,8 +306,8 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->offset = CLAMP(val.getDouble(), -1000.0, 1000.0); } else if (path == "picker") { this->picker = val.getBool(); - } else if (path == "pickinversesize") { - this->pickinversesize = val.getBool(); + } else if (path == "pickinversevalue") { + this->pickinversevalue = val.getBool(); } else if (path == "pickfill") { this->pickfill = val.getBool(); } else if (path == "pickstroke") { @@ -440,7 +440,7 @@ static bool fit_item(SPDesktop *desktop, double &_scale, double scale, bool picker, - bool pickinversesize, + bool pickinversevalue, bool pickfill, bool pickstroke, bool visible, @@ -625,7 +625,7 @@ static bool fit_item(SPDesktop *desktop, rgba = SP_RGBA32_F_COMPOSE(r, g, b, a); if (pick_to_size) { if(!trace_scale){ - if(pickinversesize) { + if(pickinversevalue) { _scale = 1.0 - val; } else { _scale = val; @@ -642,7 +642,7 @@ static bool fit_item(SPDesktop *desktop, _scale, scale, picker, - pickinversesize, + pickinversevalue, pickfill, pickstroke, visible, @@ -656,7 +656,11 @@ static bool fit_item(SPDesktop *desktop, } if (pick_to_opacity) { - opacity *= val; + if(pickinversevalue) { + opacity *= 1.0 - val; + } else { + opacity *= val; + } std::stringstream opacity_str; opacity_str.imbue(std::locale::classic()); opacity_str << opacity; @@ -712,7 +716,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, gint _distrib, bool nooverlap, bool picker, - bool pickinversesize, + bool pickinversevalue, bool pickfill, bool pickstroke, bool visible, @@ -757,7 +761,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); if(nooverlap || picker || visible){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversesize, pickfill, pickstroke, visible, nooverlap, offset, css, false)){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversevalue, pickfill, pickstroke, visible, nooverlap, offset, css, false)){ return false; } } @@ -864,7 +868,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); SPCSSAttr *css = sp_repr_css_attr_new(); if(nooverlap || picker || visible){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversesize, pickfill, pickstroke, visible, nooverlap, offset, css, false)){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversevalue, pickfill, pickstroke, visible, nooverlap, offset, css, false)){ return false; } } @@ -942,7 +946,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = *i; g_assert(item != NULL); - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->nooverlap, tc->picker, tc->pickinversesize, tc->pickfill, tc->pickstroke, tc->visible, tc->offset, tc->usepressurescale, get_pressure(tc))) { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib, tc->nooverlap, tc->picker, tc->pickinversevalue, tc->pickfill, tc->pickstroke, tc->visible, tc->offset, tc->usepressurescale, get_pressure(tc))) { did = true; } } diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index 212948c77..ca0c20375 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -91,7 +91,7 @@ public: SPCanvasItem *dilate_area; bool nooverlap; bool picker; - bool pickinversesize; + bool pickinversevalue; bool pickfill; bool pickstroke; bool visible; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index c7013b6a1..fa9722bdb 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -71,7 +71,7 @@ static void sp_stb_sensitivize( GObject *tbl ) GtkToggleAction *usepressurescale = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "usepressurescale") ); GtkAction *pickfill = GTK_ACTION( g_object_get_data(tbl, "pickfill") ); GtkAction *pickstroke = GTK_ACTION( g_object_get_data(tbl, "pickstroke") ); - GtkAction *pickinversesize = GTK_ACTION( g_object_get_data(tbl, "pickinversesize") ); + GtkAction *pickinversevalue = GTK_ACTION( g_object_get_data(tbl, "pickinversevalue") ); gtk_adjustment_set_value( adj_offset, 100.0 ); if (gtk_toggle_action_get_active(nooverlap)) { gtk_action_set_sensitive( offset, TRUE ); @@ -87,11 +87,11 @@ static void sp_stb_sensitivize( GObject *tbl ) if(gtk_toggle_action_get_active(picker)){ gtk_action_set_sensitive( pickfill, TRUE ); gtk_action_set_sensitive( pickstroke, TRUE ); - gtk_action_set_sensitive( pickinversesize, TRUE ); + gtk_action_set_sensitive( pickinversevalue, TRUE ); } else { gtk_action_set_sensitive( pickfill, FALSE ); gtk_action_set_sensitive( pickstroke, FALSE ); - gtk_action_set_sensitive( pickinversesize, FALSE ); + gtk_action_set_sensitive( pickinversevalue, FALSE ); } } @@ -217,11 +217,11 @@ static void sp_toggle_pick_fill( GtkToggleAction* act, gpointer data ) prefs->setBool("/tools/spray/pickfill", active); } -static void sp_toggle_pick_inverse_size( GtkToggleAction* act, gpointer data ) +static void sp_toggle_pick_inverse_value( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setBool("/tools/spray/pickinversesize", active); + prefs->setBool("/tools/spray/pickinversevalue", active); } static void sp_toggle_pick_stroke( GtkToggleAction* act, gpointer data ) @@ -436,14 +436,14 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Inverse Value Size */ { - InkToggleAction* act = ink_toggle_action_new( "SprayOverPickInverseSizeAction", - _("Apply inversed to pick value size"), - _("Apply inversed to pick value size"), + InkToggleAction* act = ink_toggle_action_new( "SprayOverPickInverseValueAction", + _("Inversed pick value retaining color"), + _("Inversed pick value retaining color"), INKSCAPE_ICON("object-tweak-shrink"), secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickinversesize", false) ); - g_object_set_data( holder, "pickinversesize", act ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_inverse_size), holder) ; + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickinversevalue", false) ); + g_object_set_data( holder, "pickinversevalue", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_inverse_value), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 6457b7c7e..bab317f16 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -321,14 +321,14 @@ static gchar const * ui_descr = " " " " " " - " " - " " - " " - " " - " " " " " " " " + " " + " " + " " + " " + " " " " -- cgit v1.2.3 From a555ac58d0b5827d577d61f810e9df668fa55470 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 1 Nov 2015 17:13:04 +0100 Subject: improve apply value to clones in scale mode (bzr r14422.1.38) --- src/ui/tools/spray-tool.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index f7762ad8a..03a225b6e 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -434,7 +434,7 @@ double randomize01(double val, double rand) static bool fit_item(SPDesktop *desktop, SPItem *item, Geom::OptRect bbox, - Geom::Point move, + Geom::Point &move, Geom::Point center, double angle, double &_scale, @@ -457,6 +457,11 @@ static bool fit_item(SPDesktop *desktop, if(offset_min < 0 ){ offset_min = 0; } + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool pick_to_size = prefs->getBool("/dialogs/clonetiler/pick_to_size"); + if(picker && pick_to_size && !trace_scale){ + _scale = 0.1; + } Geom::OptRect bbox_procesed = Geom::Rect(Geom::Point(bbox->left() - offset_min, bbox->top() - offset_min),Geom::Point(bbox->right() + offset_min, bbox->bottom() + offset_min)); Geom::Path path; path.start(Geom::Point(bbox_procesed->left(), bbox_procesed->top())); @@ -467,13 +472,24 @@ static bool fit_item(SPDesktop *desktop, sp_spray_transform_path(item, path, Geom::Scale(_scale), center); sp_spray_transform_path(item, path, Geom::Scale(scale), center); sp_spray_transform_path(item, path, Geom::Rotate(angle), center); - path *= Geom::Translate(move[Geom::X], move[Geom::Y]); + path *= Geom::Translate(move); path *= desktop->doc2dt(); bbox_procesed = path.boundsFast(); double bbox_left_main = bbox_procesed->left(); double bbox_top_main = bbox_procesed->top(); double width_transformed = bbox_procesed->width(); double height_transformed = bbox_procesed->height(); + Geom::Point mid_point = desktop->d2w(bbox_procesed->midpoint()); + Geom::IntRect area = Geom::IntRect::from_xywh(floor(mid_point[Geom::X]), floor(mid_point[Geom::Y]), 1, 1); + double R = 0, G = 0, B = 0, A = 0; + cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); + sp_canvas_arena_render_surface(SP_CANVAS_ARENA(desktop->getDrawing()), s, area); + ink_cairo_surface_average_color(s, R, G, B, A); + cairo_surface_destroy(s); + guint32 rgba = SP_RGBA32_F_COMPOSE(R, G, B, A); + if(nooverlap && visible && (A==0 || A < 1e-6)){ + return false; + } size = std::min(width_transformed,height_transformed); if(offset < 100 ){ offset_min = ((99.0 - offset) * size)/100.0 - size; @@ -519,12 +535,10 @@ static bool fit_item(SPDesktop *desktop, } } if(picker || visible){ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if(!nooverlap){ doc->ensureUpToDate(); } int pick = prefs->getInt("/dialogs/clonetiler/pick"); - bool pick_to_size = prefs->getBool("/dialogs/clonetiler/pick_to_size"); bool pick_to_presence = prefs->getBool("/dialogs/clonetiler/pick_to_presence", false); bool pick_to_color = prefs->getBool("/dialogs/clonetiler/pick_to_color"); bool pick_to_opacity = prefs->getBool("/dialogs/clonetiler/pick_to_opacity"); @@ -533,20 +547,12 @@ static bool fit_item(SPDesktop *desktop, double gamma_picked = prefs->getDoubleLimited("/dialogs/clonetiler/gamma_picked", 0, -10, 10); double opacity = 1.0; gchar color_string[32]; *color_string = 0; - Geom::Point mid_point = desktop->d2w(bbox_procesed->midpoint()); - Geom::IntRect area = Geom::IntRect::from_xywh(floor(mid_point[Geom::X]), floor(mid_point[Geom::Y]), 1, 1); - double R = 0, G = 0, B = 0, A = 0; - cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); - sp_canvas_arena_render_surface(SP_CANVAS_ARENA(desktop->getDrawing()), s, area); - ink_cairo_surface_average_color(s, R, G, B, A); - cairo_surface_destroy(s); - guint32 rgba = SP_RGBA32_F_COMPOSE(R, G, B, A); float r = SP_RGBA32_R_F(rgba); float g = SP_RGBA32_G_F(rgba); float b = SP_RGBA32_B_F(rgba); float a = SP_RGBA32_A_F(rgba); //this can fix the bug #1511998 if confirmed - if( a == 0 && r == 0 && g == 0 && b == 0){ + if( a == 0 || a < 1e-6){ r = 1; g = 1; b = 1; -- cgit v1.2.3 From ac14e8884b153cf94b7c88d21ad06efadd9373ce Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 7 Nov 2015 21:57:55 +0100 Subject: Use color if trace dialog is disabled (bzr r14422.1.43) --- src/ui/dialog/clonetiler.cpp | 2 +- src/ui/tools/spray-tool.cpp | 14 ++++++++++++-- src/widgets/spray-toolbar.cpp | 6 +++--- 3 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index e842cf78f..1ea80e9f7 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -3017,7 +3017,7 @@ void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg) void CloneTiler::show_page_trace() { gtk_notebook_set_current_page(GTK_NOTEBOOK(nb),6); - gtk_toggle_button_set_active ((GtkToggleButton *) b, true); + gtk_toggle_button_set_active ((GtkToggleButton *) b, false); } diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 03a225b6e..a57d1db5e 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -538,6 +538,7 @@ static bool fit_item(SPDesktop *desktop, if(!nooverlap){ doc->ensureUpToDate(); } + bool trace = prefs->getBool("/dialogs/clonetiler/dotrace"); int pick = prefs->getInt("/dialogs/clonetiler/pick"); bool pick_to_presence = prefs->getBool("/dialogs/clonetiler/pick_to_presence", false); bool pick_to_color = prefs->getBool("/dialogs/clonetiler/pick_to_color"); @@ -561,7 +562,7 @@ static bool fit_item(SPDesktop *desktop, return false; } - if(picker){ + if(picker && trace){ float hsl[3]; sp_color_rgb_to_hsl_floatv (hsl, r, g, b); @@ -675,7 +676,7 @@ static bool fit_item(SPDesktop *desktop, if (pick_to_presence) { if (g_random_double_range (0, 1) > val) { //Hidding the element is a way to retain original - //beabiohur of tiled clones for presence option. + //behabiohur of tiled clones for presence option. sp_repr_css_set_property(css, "opacity", "0"); } } @@ -692,6 +693,15 @@ static bool fit_item(SPDesktop *desktop, return false; } } + if(!trace){ + sp_svg_write_color(color_string, sizeof(color_string), rgba); + if(pickfill){ + sp_repr_css_set_property(css, "fill", color_string); + } + if(pickstroke){ + sp_repr_css_set_property(css, "stroke", color_string); + } + } if(!nooverlap && (picker || visible)){ for (std::vector::const_iterator k=items_down.begin(); k!=items_down.end(); k++) { SPItem *item_hidden = *k; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index fa9722bdb..cfd3c6332 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -424,8 +424,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Picker */ { InkToggleAction* act = ink_toggle_action_new( "SprayPickColorAction", - _("Pick down. Fill or Stroke must be unset on original when spraying color to clones"), - _("Pick down. Fill or Stroke must be unset on original when spraying color to clones"), + _("Pick down. You can use trace clones dialog for avanced effects. In clone mode original fill or stroke colors must be unset"), + _("Pick down. You can use trace clones dialog for avanced effects. In clone mode original fill or stroke colors must be unset"), INKSCAPE_ICON("color-picker"), secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/picker", false) ); @@ -504,7 +504,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Offset */ { EgeAdjustmentAction *eact = create_adjustment_action( "SprayToolOffsetAction", - _("Offset precent"), _("Offset percent:"), + _("Offset %"), _("Offset %:"), _("Increase to segregate objects more (value in percent)"), "/tools/spray/offset", 100, GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -- cgit v1.2.3 From d2b9a1e46cd23379f3800ea65cd3f3337f4d1f1e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 7 Nov 2015 22:27:41 +0100 Subject: Fix for scale bug pointed by Mc- (bzr r14422.1.45) --- src/ui/tools/spray-tool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index a57d1db5e..6af30b5fc 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -459,7 +459,8 @@ static bool fit_item(SPDesktop *desktop, } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool pick_to_size = prefs->getBool("/dialogs/clonetiler/pick_to_size"); - if(picker && pick_to_size && !trace_scale){ + bool trace = prefs->getBool("/dialogs/clonetiler/dotrace"); + if(picker && pick_to_size && !trace_scale && trace){ _scale = 0.1; } Geom::OptRect bbox_procesed = Geom::Rect(Geom::Point(bbox->left() - offset_min, bbox->top() - offset_min),Geom::Point(bbox->right() + offset_min, bbox->bottom() + offset_min)); @@ -538,7 +539,6 @@ static bool fit_item(SPDesktop *desktop, if(!nooverlap){ doc->ensureUpToDate(); } - bool trace = prefs->getBool("/dialogs/clonetiler/dotrace"); int pick = prefs->getInt("/dialogs/clonetiler/pick"); bool pick_to_presence = prefs->getBool("/dialogs/clonetiler/pick_to_presence", false); bool pick_to_color = prefs->getBool("/dialogs/clonetiler/pick_to_color"); -- cgit v1.2.3 From 26783ada6dd88c1f2df732707628bae6a4d68e42 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Nov 2015 00:18:24 +0100 Subject: Fixes from review form Mc- (bzr r14422.1.46) --- src/ui/dialog/clonetiler.cpp | 6 +++--- src/ui/tools/spray-tool.cpp | 5 +---- src/widgets/spray-toolbar.cpp | 6 ++---- 3 files changed, 6 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index 1ea80e9f7..fd8afd4a3 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -785,11 +785,11 @@ CloneTiler::CloneTiler () : #endif gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0); - b = gtk_check_button_new_with_label (_("Trace the drawing under the tiles/spray tool")); + b = gtk_check_button_new_with_label (_("Trace the drawing under the clones/sprayed items")); g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE)); bool old = prefs->getBool(prefs_path + "dotrace"); gtk_toggle_button_set_active ((GtkToggleButton *) b, old); - gtk_widget_set_tooltip_text (b, _("For each clone/ Sprayed item, pick a value from the drawing in that clone's or item spayed location and apply it")); + gtk_widget_set_tooltip_text (b, _("For each clone/sparayed item, pick a value from the drawing in its location and apply it")); gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(b), "toggled", @@ -998,7 +998,7 @@ CloneTiler::CloneTiler () : gtk_widget_set_sensitive (vvb, prefs->getBool(prefs_path + "dotrace")); } } - // Info + { #if GTK_CHECK_VERSION(3,0,0) GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, VB_MARGIN); diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 6af30b5fc..17b82fe1d 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -331,7 +331,6 @@ static void sp_spray_extinput(SprayTool *tc, GdkEvent *event) static double get_width(SprayTool *tc) { double pressure = (tc->usepressurewidth? tc->pressure / TC_DEFAULT_PRESSURE : 1); - //g_warning("Pressure, population: %f, %f", pressure, pressure * tc->population); return pressure * tc->width; } @@ -353,14 +352,12 @@ static double get_path_standard_deviation(SprayTool *tc) static double get_population(SprayTool *tc) { double pressure = (tc->usepressurepopulation? tc->pressure / TC_DEFAULT_PRESSURE : 1); - //g_warning("Pressure, population: %f, %f", pressure, pressure * tc->population); return pressure * tc->population; } static double get_pressure(SprayTool *tc) { double pressure = tc->pressure / TC_DEFAULT_PRESSURE; - //g_warning("Pressure, population: %f, %f", pressure, pressure * tc->population); return pressure; } @@ -676,7 +673,7 @@ static bool fit_item(SPDesktop *desktop, if (pick_to_presence) { if (g_random_double_range (0, 1) > val) { //Hidding the element is a way to retain original - //behabiohur of tiled clones for presence option. + //behaviour of tiled clones for presence option. sp_repr_css_set_property(css, "opacity", "0"); } } diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index cfd3c6332..5e0d81964 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -424,8 +424,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Picker */ { InkToggleAction* act = ink_toggle_action_new( "SprayPickColorAction", - _("Pick down. You can use trace clones dialog for avanced effects. In clone mode original fill or stroke colors must be unset"), - _("Pick down. You can use trace clones dialog for avanced effects. In clone mode original fill or stroke colors must be unset"), + _("Pick color from the drawing. You can use clonetiler trace dialog for avanced effects. In clone mode original fill or stroke colors must be unset."), + _("Pick color from the drawing. You can use clonetiler trace dialog for avanced effects. In clone mode original fill or stroke colors must be unset."), INKSCAPE_ICON("color-picker"), secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/picker", false) ); @@ -495,8 +495,6 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/nooverlap", false) ); g_object_set_data( holder, "nooverlap", act ); - //g_object_set_data (context_object, "holder", holder); - //g_object_set_data (context_object, "desktop", desktop); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_nooverlap), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } -- cgit v1.2.3 From 298e5a9a28984e062b3901172cdc356836266d58 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Nov 2015 10:49:26 +0100 Subject: Fix a typo (bzr r14422.1.47) --- src/ui/dialog/clonetiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index fd8afd4a3..fbd050f8e 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -789,7 +789,7 @@ CloneTiler::CloneTiler () : g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE)); bool old = prefs->getBool(prefs_path + "dotrace"); gtk_toggle_button_set_active ((GtkToggleButton *) b, old); - gtk_widget_set_tooltip_text (b, _("For each clone/sparayed item, pick a value from the drawing in its location and apply it")); + gtk_widget_set_tooltip_text (b, _("For each clone/sprayed item, pick a value from the drawing in its location and apply it")); gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(b), "toggled", -- cgit v1.2.3