From 6b61296109001d15cd1e2a43c38385b5fdba81c7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 4 Oct 2015 03:31:27 +0200 Subject: Add improvements to measure tool: more responsive add option to handle only active layer or all add a option to hide/show first and last segment add a option to compute only one global sice (bzr r14393.1.1) --- src/document.cpp | 20 +- src/document.h | 2 +- src/ui/tools/measure-tool.cpp | 731 ++++++++++++++++++++-------------------- src/ui/tools/measure-tool.h | 4 +- src/widgets/measure-toolbar.cpp | 36 ++ src/widgets/toolbox.cpp | 3 + 6 files changed, 426 insertions(+), 370 deletions(-) (limited to 'src') diff --git a/src/document.cpp b/src/document.cpp index c64bf3ed5..97113cb25 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1450,7 +1450,7 @@ std::vector SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom: return find_items_in_area(x, SP_GROUP(this->root), dkey, box, overlaps); } -std::vector SPDocument::getItemsAtPoints(unsigned const key, std::vector points) const +std::vector SPDocument::getItemsAtPoints(unsigned const key, std::vector points, bool all_layers, size_t limit) const { std::vector items; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -1464,11 +1464,25 @@ std::vector SPDocument::getItemsAtPoints(unsigned const key, std::vecto // Cache a flattened SVG DOM to speed up selection. std::deque nodes; build_flat_item_list(&nodes, key, SP_GROUP(this->root), true, false, NULL); - + SPObject *current_layer = SP_ACTIVE_DESKTOP->currentLayer(); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Inkscape::LayerModel *layer_model = NULL; + if(desktop){ + layer_model = desktop->layers; + } + size_t h = 0; for(int i = points.size()-1;i>=0; i--) { SPItem *item = find_item_at_point(&nodes, key, points[i]); if (item && items.end()==find(items.begin(),items.end(), item)) - items.push_back(item); + if(all_layers || (layer_model && layer_model->layerForObject(item) == current_layer)){ + items.push_back(item); + h++; + //limit 0 = no limit + if(h == limit){ + prefs->setDouble("/options/cursortolerance/value", saved_delta); + return items; + } + } } // and now we restore it back diff --git a/src/document.h b/src/document.h index dd1e295a2..be3f106d8 100644 --- a/src/document.h +++ b/src/document.h @@ -262,7 +262,7 @@ public: std::vector getItemsInBox(unsigned int dkey, Geom::Rect const &box) const; std::vector getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const; SPItem *getItemAtPoint(unsigned int key, Geom::Point const &p, bool into_groups, SPItem *upto = NULL) const; - std::vector getItemsAtPoints(unsigned const key, std::vector points) const; + std::vector getItemsAtPoints(unsigned const key, std::vector points, bool all_layers = true, size_t limit = 0) const; SPItem *getGroupAtPoint(unsigned int key, Geom::Point const &p) const; void changeUriAndHrefs(char const *uri); diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 570f3e796..aadc8790a 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -15,6 +15,7 @@ #include #include "util/units.h" #include "macros.h" +#include "rubberband.h" #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" @@ -296,22 +297,18 @@ static void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom: } bool MeasureTool::root_handler(GdkEvent* event) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); - gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: { Geom::Point const button_w(event->button.x, event->button.y); explicitBase = boost::none; - lastEnd = boost::none; + last_end = boost::none; start_point = desktop->w2d(button_w); if (event->button.button == 1 && !this->space_panning) { // save drag origin - xp = static_cast(event->button.x); - yp = static_cast(event->button.y); + start_point = desktop->w2d(Geom::Point(event->button.x, event->button.y)); within_tolerance = true; ret = TRUE; @@ -330,417 +327,423 @@ bool MeasureTool::root_handler(GdkEvent* event) { } case GDK_KEY_PRESS: { if ((event->key.keyval == GDK_KEY_Shift_L) || (event->key.keyval == GDK_KEY_Shift_R)) { - if (lastEnd) { - explicitBase = lastEnd; + if (last_end) { + explicitBase = last_end; } } break; } case GDK_MOTION_NOTIFY: { - if (!((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning)) { - if (!(event->motion.state & GDK_SHIFT_MASK)) { - Geom::Point const motion_w(event->motion.x, event->motion.y); - Geom::Point const motion_dt(desktop->w2d(motion_w)); + if (!(event->motion.state & GDK_BUTTON1_MASK) && !(event->motion.state & GDK_SHIFT_MASK)) { + Geom::Point const motion_w(event->motion.x, event->motion.y); + Geom::Point const motion_dt(desktop->w2d(motion_w)); - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); - Inkscape::SnapCandidatePoint scp(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); + Inkscape::SnapCandidatePoint scp(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_point); - m.preSnap(scp); - m.unSetup(); - } + m.preSnap(scp); + m.unSetup(); } else { ret = TRUE; - - if ( within_tolerance - && ( abs( static_cast(event->motion.x) - xp ) < tolerance ) - && ( abs( static_cast(event->motion.y) - yp ) < tolerance ) ) { - break; // do not drag if we're within tolerance from origin + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + Geom::Point const motion_w(event->motion.x, event->motion.y); + if ( within_tolerance){ + if ( Geom::LInfty( motion_w - start_point ) < tolerance) { + return false; // Do not drag if we're within tolerance from origin. + } } // Once the user has moved farther than tolerance from the original location // (indicating they intend to move the object, not click), then always process the // motion notify coordinates as given (no snapping back to origin) within_tolerance = false; - - //clear previous temporary canvas items, we'll draw new ones - for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { - desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); - } - - measure_tmp_items.clear(); - - Geom::Point const motion_w(event->motion.x, event->motion.y); - Geom::Point const motion_dt(desktop->w2d(motion_w)); - Geom::Point end_point = motion_dt; - - if (event->motion.state & GDK_CONTROL_MASK) { - spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); - } else { - if (!(event->motion.state & GDK_SHIFT_MASK)) { - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); - Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); - Inkscape::SnappedPoint sp = m.freeSnap(scp); - end_point = sp.getPoint(); - m.unSetup(); - } + if(event->motion.time == 0 || !last_end || Geom::LInfty( motion_w - *last_end ) > (tolerance/2)){ + showCanvasItems(event->motion); + last_end = motion_w ; } + gobble_motion_events(GDK_BUTTON1_MASK); + } + break; + } + case GDK_BUTTON_RELEASE: { + sp_event_context_discard_delayed_snap_event(this); + explicitBase = boost::none; + last_end = boost::none; - Geom::PathVector lineseg; - Geom::Path p; - p.start(desktop->dt2doc(start_point)); - p.appendNew(desktop->dt2doc(end_point)); - lineseg.push_back(p); - - double deltax = end_point[Geom::X] - start_point[Geom::X]; - double deltay = end_point[Geom::Y] - start_point[Geom::Y]; - double angle = atan2(deltay, deltax); - double baseAngle = 0; + //clear all temporary canvas items related to the measurement tool. + for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { + desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); + } - if (explicitBase) { - double deltax2 = explicitBase.get()[Geom::X] - start_point[Geom::X]; - double deltay2 = explicitBase.get()[Geom::Y] - start_point[Geom::Y]; + measure_tmp_items.clear(); - baseAngle = atan2(deltay2, deltax2); - angle -= baseAngle; + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; + } - if (angle < -M_PI) { - angle += 2 * M_PI; - } else if (angle > M_PI) { - angle -= 2 * M_PI; - } - } + start_point = Geom::Point(); + break; + } + default: + break; + } + if (!ret) { + ret = ToolBase::root_handler(event); + } + + return ret; +} -//TODO: calculate NPOINTS -//800 seems to be a good value for 800x600 resolution -#define NPOINTS 800 +void MeasureTool::showCanvasItems(GdkEventMotion const &mevent){ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Geom::Point const motion_w(mevent.x, mevent.y); + bool show_in_between = prefs->getBool("/tools/measure/show_in_between"); + bool all_layers = prefs->getBool("/tools/measure/all_layers"); + //clear previous temporary canvas items, we'll draw new ones + for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { + desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); + } - std::vector points; + measure_tmp_items.clear(); + Geom::Point const motion_dt(desktop->w2d(motion_w)); + Geom::Point end_point = motion_dt; - for (double i = 0; i < NPOINTS; i++) { - points.push_back(desktop->d2w(start_point + (i / NPOINTS) * (end_point - start_point))); - } + if (mevent.state & GDK_CONTROL_MASK) { + spdc_endpoint_snap_rotation(this, end_point, start_point, mevent.state); + } else { + if (!(mevent.state & GDK_SHIFT_MASK)) { + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_point); + Inkscape::SnappedPoint sp = m.freeSnap(scp); + end_point = sp.getPoint(); + m.unSetup(); + } + } - // TODO: Felipe, why don't you simply iterate over all items, and test whether their bounding boxes intersect - // with the measurement line, instead of interpolating over 800 points? E.g. bbox_of_measurement_line.intersects(*bbox_of_item). - // That's also how the object-snapper works, see _findCandidates() in object-snapper.cpp. - - // TODO switch to a different variable name. The single letter 'l' is easy to misread. - - //select elements crossed by line segment: - std::vector items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, points); - std::vector intersection_times; - for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { - SPItem *item = *i; - - if (SP_IS_SHAPE(item)) { - calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times); - } else { - if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { - Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); - do { - Inkscape::Text::Layout::iterator iter_next = iter; - iter_next.nextGlyph(); // iter_next is one glyph ahead from iter - if (iter == iter_next) { - break; - } - - // get path from iter to iter_next: - SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next); - iter = iter_next; // shift to next glyph - if (!curve) { - continue; // error converting this glyph - } - if (curve->is_empty()) { // whitespace glyph? - curve->unref(); - continue; - } - - curve->transform(item->i2doc_affine()); - - calculate_intersections(desktop, item, lineseg, curve, intersection_times); - - if (iter == te_get_layout(item)->end()) { - break; - } - } while (true); - } - } - } + Geom::PathVector lineseg; + Geom::Path p; + p.start(desktop->dt2doc(start_point)); + p.appendNew(desktop->dt2doc(end_point)); + lineseg.push_back(p); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true)) { - intersection_times.push_back(0); - intersection_times.push_back(1); - } + double deltax = end_point[Geom::X] - start_point[Geom::X]; + double deltay = end_point[Geom::Y] - start_point[Geom::Y]; + double angle = atan2(deltay, deltax); + double baseAngle = 0; - Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); - if (!unit_name.compare("")) { - unit_name = "px"; - } + if (explicitBase) { + double deltax2 = explicitBase.get()[Geom::X] - start_point[Geom::X]; + double deltay2 = explicitBase.get()[Geom::Y] - start_point[Geom::Y]; - double fontsize = prefs->getInt("/tools/measure/fontsize"); + baseAngle = atan2(deltay2, deltax2); + angle -= baseAngle; - // Normal will be used for lines and text - Geom::Point windowNormal = Geom::unit_vector(Geom::rot90(desktop->d2w(end_point - start_point))); - Geom::Point normal = desktop->w2d(windowNormal); + if (angle < -M_PI) { + angle += 2 * M_PI; + } else if (angle > M_PI) { + angle -= 2 * M_PI; + } + } + std::vector items; + Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); + r->setMode(RUBBERBAND_MODE_TOUCHPATH); + if(!show_in_between){ + r->start(desktop,start_point); + r->move(end_point); + items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers, 2); + r->stop(); + r->setMode(RUBBERBAND_MODE_TOUCHPATH); + r->start(desktop,end_point); + r->move(start_point); + std::vector items_reverse = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers, 2); + r->stop(); + if(items_reverse.size() == 2){ + items.push_back(items_reverse[1]); + } + if(items_reverse.size() >= 1){ + items.push_back(items_reverse[0]); + } + } else { + r->start(desktop,start_point); + r->move(end_point); + items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers); + r->stop(); + } + std::vector intersection_times; + for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { + SPItem *item = *i; + if (SP_IS_SHAPE(item)) { + calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times); + } else { + if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { + Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); + do { + Inkscape::Text::Layout::iterator iter_next = iter; + iter_next.nextGlyph(); // iter_next is one glyph ahead from iter + if (iter == iter_next) { + break; + } - std::vector intersections; - std::sort(intersection_times.begin(), intersection_times.end()); - for (std::vector::iterator iter_t = intersection_times.begin(); iter_t != intersection_times.end(); iter_t++) { - intersections.push_back(lineseg[0].pointAt(*iter_t)); - } + // get path from iter to iter_next: + SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next); + iter = iter_next; // shift to next glyph + if (!curve) { + continue; // error converting this glyph + } + if (curve->is_empty()) { // whitespace glyph? + curve->unref(); + continue; + } - std::vector placements; - for (size_t idx = 1; idx < intersections.size(); ++idx) { - LabelPlacement placement; - placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length(); - placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, "px", unit_name); - placement.offset = DIMENSION_OFFSET; - placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 ); - placement.end = placement.start - (normal * placement.offset); + curve->transform(item->i2doc_affine()); - placements.push_back(placement); - } + calculate_intersections(desktop, item, lineseg, curve, intersection_times); + if (iter == te_get_layout(item)->end()) { + break; + } + } while (true); + } + } + } + Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); + if (!unit_name.compare("")) { + unit_name = "px"; + } - // Adjust positions - repositionOverlappingLabels(placements, desktop, windowNormal, fontsize); - - for (std::vector::iterator it = placements.begin(); it != placements.end(); ++it) - { - LabelPlacement &place = *it; - - // TODO cleanup memory, Glib::ustring, etc.: - gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit_name.c_str()); - SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - place.end, - measure_str); - sp_canvastext_set_fontsize(canvas_tooltip, fontsize); - canvas_tooltip->rgba = 0xffffffff; - canvas_tooltip->rgba_background = 0x0000007f; - canvas_tooltip->outline = false; - canvas_tooltip->background = true; - canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; - - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); - g_free(measure_str); - } + double fontsize = prefs->getInt("/tools/measure/fontsize"); - Geom::Point angleDisplayPt = calcAngleDisplayAnchor(desktop, angle, baseAngle, - start_point, end_point, - fontsize); - - { - // TODO cleanup memory, Glib::ustring, etc.: - gchar *angle_str = g_strdup_printf("%.2f °", angle * 180/M_PI); - - SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - angleDisplayPt, - angle_str); - sp_canvastext_set_fontsize(canvas_tooltip, fontsize); - canvas_tooltip->rgba = 0xffffffff; - canvas_tooltip->rgba_background = 0x337f337f; - canvas_tooltip->outline = false; - canvas_tooltip->background = true; - canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; - - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); - g_free(angle_str); - } + // Normal will be used for lines and text + Geom::Point windowNormal = Geom::unit_vector(Geom::rot90(desktop->d2w(end_point - start_point))); + Geom::Point normal = desktop->w2d(windowNormal); - { - double totallengthval = (end_point - start_point).length(); - totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); - - // TODO cleanup memory, Glib::ustring, etc.: - gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); - SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), - totallength_str); - sp_canvastext_set_fontsize(canvas_tooltip, fontsize); - canvas_tooltip->rgba = 0xffffffff; - canvas_tooltip->rgba_background = 0x3333337f; - canvas_tooltip->outline = false; - canvas_tooltip->background = true; - canvas_tooltip->anchor_position = TEXT_ANCHOR_LEFT; - - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); - g_free(totallength_str); - } + std::vector intersections; + std::sort(intersection_times.begin(), intersection_times.end()); + for (std::vector::iterator iter_t = intersection_times.begin(); iter_t != intersection_times.end(); iter_t++) { + if(show_in_between){ + intersections.push_back(lineseg[0].pointAt(*iter_t)); + } + } + if(!show_in_between && intersection_times.size() > 1){ + intersections.push_back(lineseg[0].pointAt(intersection_times[0])); + intersections.push_back(lineseg[0].pointAt(intersection_times[intersection_times.size()-1])); + } + if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true)) { + intersections.insert(intersections.begin(),lineseg[0].pointAt(0)); + intersections.push_back(lineseg[0].pointAt(1)); + } + std::vector placements; + for (size_t idx = 1; idx < intersections.size(); ++idx) { + LabelPlacement placement; + placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length(); + placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, "px", unit_name); + placement.offset = DIMENSION_OFFSET; + placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 ); + placement.end = placement.start - (normal * placement.offset); + + placements.push_back(placement); + } - if (intersections.size() > 2) { - double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length(); - totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); - - // TODO cleanup memory, Glib::ustring, etc.: - gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); - SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60, - total_str); - sp_canvastext_set_fontsize(canvas_tooltip, fontsize); - canvas_tooltip->rgba = 0xffffffff; - canvas_tooltip->rgba_background = 0x33337f7f; - canvas_tooltip->outline = false; - canvas_tooltip->background = true; - canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; - - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); - g_free(total_str); - } + // Adjust positions + repositionOverlappingLabels(placements, desktop, windowNormal, fontsize); + for (std::vector::iterator it = placements.begin(); it != placements.end(); ++it) + { + LabelPlacement &place = *it; + + // TODO cleanup memory, Glib::ustring, etc.: + gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit_name.c_str()); + SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), + desktop, + place.end, + measure_str); + sp_canvastext_set_fontsize(canvas_tooltip, fontsize); + canvas_tooltip->rgba = 0xffffffff; + canvas_tooltip->rgba_background = 0x0000007f; + canvas_tooltip->outline = false; + canvas_tooltip->background = true; + canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; + + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); + g_free(measure_str); + } - // Now that text has been added, we can add lines and controls so that they go underneath - - for (size_t idx = 0; idx < intersections.size(); ++idx) { - // Display the intersection indicator (i.e. the cross) - SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), - SP_TYPE_CTRL, - "anchor", SP_ANCHOR_CENTER, - "size", 8.0, - "stroked", TRUE, - "stroke_color", 0xff0000ff, - "mode", SP_KNOT_MODE_XOR, - "shape", SP_KNOT_SHAPE_CROSS, - NULL ); - - SP_CTRL(canvasitem)->moveto(desktop->doc2dt(intersections[idx])); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvasitem, 0)); - } + Geom::Point angleDisplayPt = calcAngleDisplayAnchor(desktop, angle, baseAngle, + start_point, end_point, + fontsize); - // Since adding goes to the bottom, do all lines last. - - // draw main control line - { - SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), - start_point, - end_point); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - - if ((end_point[Geom::X] != start_point[Geom::X]) && (end_point[Geom::Y] != start_point[Geom::Y])) { - double length = std::abs((end_point - start_point).length()); - Geom::Point anchorEnd = start_point; - anchorEnd[Geom::X] += length; - if (explicitBase) { - anchorEnd *= (Geom::Affine(Geom::Translate(-start_point)) - * Geom::Affine(Geom::Rotate(baseAngle)) - * Geom::Affine(Geom::Translate(start_point))); - } - - SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), - start_point, - anchorEnd, - CTLINE_SECONDARY); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - - createAngleDisplayCurve(desktop, start_point, end_point, angleDisplayPt, angle); - } - } + { + // TODO cleanup memory, Glib::ustring, etc.: + gchar *angle_str = g_strdup_printf("%.2f °", angle * 180/M_PI); + + SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), + desktop, + angleDisplayPt, + angle_str); + sp_canvastext_set_fontsize(canvas_tooltip, fontsize); + canvas_tooltip->rgba = 0xffffffff; + canvas_tooltip->rgba_background = 0x337f337f; + canvas_tooltip->outline = false; + canvas_tooltip->background = true; + canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; + + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); + g_free(angle_str); + } - if (intersections.size() > 2) { - ControlManager &mgr = ControlManager::getManager(); - SPCtrlLine *control_line = 0; - control_line = mgr.createControlLine(desktop->getTempGroup(), - desktop->doc2dt(intersections[0]) + normal * 60, - desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 60); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - - control_line = mgr.createControlLine(desktop->getTempGroup(), - desktop->doc2dt(intersections[0]), - desktop->doc2dt(intersections[0]) + normal * 65); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - - control_line = mgr.createControlLine(desktop->getTempGroup(), - desktop->doc2dt(intersections[intersections.size() - 1]), - desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 65); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - } + { + double totallengthval = (end_point - start_point).length(); + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); + + // TODO cleanup memory, Glib::ustring, etc.: + gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); + SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), + desktop, + end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), + totallength_str); + sp_canvastext_set_fontsize(canvas_tooltip, fontsize); + canvas_tooltip->rgba = 0xffffffff; + canvas_tooltip->rgba_background = 0x3333337f; + canvas_tooltip->outline = false; + canvas_tooltip->background = true; + canvas_tooltip->anchor_position = TEXT_ANCHOR_LEFT; + + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); + g_free(totallength_str); + } - // call-out lines - for (std::vector::iterator it = placements.begin(); it != placements.end(); ++it) - { - LabelPlacement &place = *it; - - ControlManager &mgr = ControlManager::getManager(); - SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), - place.start, - place.end, - CTLINE_SECONDARY); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - } + if (intersections.size() > 2) { + double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length(); + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); + + // TODO cleanup memory, Glib::ustring, etc.: + gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); + SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), + desktop, + desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60, + total_str); + sp_canvastext_set_fontsize(canvas_tooltip, fontsize); + canvas_tooltip->rgba = 0xffffffff; + canvas_tooltip->rgba_background = 0x33337f7f; + canvas_tooltip->outline = false; + canvas_tooltip->background = true; + canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; + + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); + g_free(total_str); + } - { - for (size_t idx = 1; idx < intersections.size(); ++idx) { - Geom::Point measure_text_pos = (intersections[idx - 1] + intersections[idx]) / 2; + // Now that text has been added, we can add lines and controls so that they go underneath + for (size_t idx = 0; idx < intersections.size(); ++idx) { + // Display the intersection indicator (i.e. the cross) + SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), + SP_TYPE_CTRL, + "anchor", SP_ANCHOR_CENTER, + "size", 8.0, + "stroked", TRUE, + "stroke_color", 0xff0000ff, + "mode", SP_KNOT_MODE_XOR, + "shape", SP_KNOT_SHAPE_CROSS, + NULL ); + + SP_CTRL(canvasitem)->moveto(desktop->doc2dt(intersections[idx])); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvasitem, 0)); + } - ControlManager &mgr = ControlManager::getManager(); - SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), - desktop->doc2dt(measure_text_pos), - desktop->doc2dt(measure_text_pos) - (normal * DIMENSION_OFFSET), - CTLINE_SECONDARY); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - } - } + // Since adding goes to the bottom, do all lines last. - // Initial point - { - SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), - SP_TYPE_CTRL, - "anchor", SP_ANCHOR_CENTER, - "size", 8.0, - "stroked", TRUE, - "stroke_color", 0xff0000ff, - "mode", SP_KNOT_MODE_XOR, - "shape", SP_KNOT_SHAPE_CROSS, - NULL ); - - SP_CTRL(canvasitem)->moveto(start_point); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvasitem, 0)); - } + // draw main control line + { + SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), + start_point, + end_point); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); + + if ((end_point[Geom::X] != start_point[Geom::X]) && (end_point[Geom::Y] != start_point[Geom::Y])) { + double length = std::abs((end_point - start_point).length()); + Geom::Point anchorEnd = start_point; + anchorEnd[Geom::X] += length; + if (explicitBase) { + anchorEnd *= (Geom::Affine(Geom::Translate(-start_point)) + * Geom::Affine(Geom::Rotate(baseAngle)) + * Geom::Affine(Geom::Translate(start_point))); + } - lastEnd = end_point; // track in case we get a anchoring key-press later + SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), + start_point, + anchorEnd, + CTLINE_SECONDARY); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - gobble_motion_events(GDK_BUTTON1_MASK); - } - break; + createAngleDisplayCurve(desktop, start_point, end_point, angleDisplayPt, angle); } - case GDK_BUTTON_RELEASE: { - sp_event_context_discard_delayed_snap_event(this); - explicitBase = boost::none; - lastEnd = boost::none; - - //clear all temporary canvas items related to the measurement tool. - for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { - desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); - } + } - measure_tmp_items.clear(); + if (intersections.size() > 2) { + ControlManager &mgr = ControlManager::getManager(); + SPCtrlLine *control_line = 0; + control_line = mgr.createControlLine(desktop->getTempGroup(), + desktop->doc2dt(intersections[0]) + normal * 60, + desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 60); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); + + control_line = mgr.createControlLine(desktop->getTempGroup(), + desktop->doc2dt(intersections[0]), + desktop->doc2dt(intersections[0]) + normal * 65); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); + + control_line = mgr.createControlLine(desktop->getTempGroup(), + desktop->doc2dt(intersections[intersections.size() - 1]), + desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 65); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); + } - if (this->grabbed) { - sp_canvas_item_ungrab(this->grabbed, event->button.time); - this->grabbed = NULL; - } + // call-out lines + for (std::vector::iterator it = placements.begin(); it != placements.end(); ++it) + { + LabelPlacement &place = *it; + + ControlManager &mgr = ControlManager::getManager(); + SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), + place.start, + place.end, + CTLINE_SECONDARY); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); + } - xp = 0; - yp = 0; - break; + { + for (size_t idx = 1; idx < intersections.size(); ++idx) { + Geom::Point measure_text_pos = (intersections[idx - 1] + intersections[idx]) / 2; + + ControlManager &mgr = ControlManager::getManager(); + SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), + desktop->doc2dt(measure_text_pos), + desktop->doc2dt(measure_text_pos) - (normal * DIMENSION_OFFSET), + CTLINE_SECONDARY); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); } - default: - break; } - if (!ret) { - ret = ToolBase::root_handler(event); + // Initial point + { + SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), + SP_TYPE_CTRL, + "anchor", SP_ANCHOR_CENTER, + "size", 8.0, + "stroked", TRUE, + "stroke_color", 0xff0000ff, + "mode", SP_KNOT_MODE_XOR, + "shape", SP_KNOT_SHAPE_CROSS, + NULL ); + + SP_CTRL(canvasitem)->moveto(start_point); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvasitem, 0)); } - - return ret; } - } } } diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index 9701ba6ea..4673e0f0a 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -32,15 +32,15 @@ public: virtual void finish(); virtual bool root_handler(GdkEvent* event); + virtual void showCanvasItems(GdkEventMotion const &event); virtual const std::string& getPrefsPath(); private: SPCanvasItem* grabbed; - Geom::Point start_point; boost::optional explicitBase; - boost::optional lastEnd; + boost::optional last_end; }; } diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 5a4785b1f..ca79b5792 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -38,6 +38,8 @@ #include "widgets/ege-output-action.h" #include "preferences.h" #include "toolbox.h" +#include "widgets/ink-action.h" +#include "ui/icon-names.h" #include "ui/widget/unit-tracker.h" using Inkscape::UI::Widget::UnitTracker; @@ -79,6 +81,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_object_set_data( holder, "tracker", tracker ); EgeAdjustmentAction *eact = 0; + Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); /* Font Size */ { @@ -108,6 +111,39 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(measure_unit_changed), holder ); gtk_action_group_add_action( mainActions, act ); } + // ignore_1st_and_last + { + InkToggleAction* act = ink_toggle_action_new( "MeasureIgnore1stAndLast", + _("Ignore first and last"), + _("Ignore first and last"), + INKSCAPE_ICON("draw-geometry-line-segment"), + secondarySize ); + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/measure/ignore_1st_and_last"); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + } + // measure imbetweens + { + InkToggleAction* act = ink_toggle_action_new( "MeasureInBettween", + _("Show meassures between items"), + _("Show meassures between items"), + INKSCAPE_ICON("distribute-randomize"), + secondarySize ); + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/measure/show_in_between"); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + } + // measure only current layer + { + InkToggleAction* act = ink_toggle_action_new( "MeasureAllLayers", + _("Measure all layers"), + _("Measure all layers"), + INKSCAPE_ICON("dialog-layers"), + secondarySize ); + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/measure/all_layers"); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + } } // end of sp_measure_toolbox_prep() diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index cdf39e9ef..ba02adb92 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -341,6 +341,9 @@ static gchar const * ui_descr = " " " " " " + " " + " " + " " " " " " -- cgit v1.2.3 From bd4a5a52a3aae4a9c871a9ea766ab490a5e25d84 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 4 Oct 2015 20:15:20 +0200 Subject: Added knots to post editing the measure and make it persistant throught tools (bzr r14393.1.3) --- src/ui/tools/measure-tool.cpp | 139 ++++++++++++++++++++++++++++-------------- src/ui/tools/measure-tool.h | 30 ++++++--- 2 files changed, 114 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index aadc8790a..142c04fc3 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -30,7 +30,7 @@ #include "pixmaps/cursor-measure.xpm" #include "preferences.h" #include "inkscape.h" - +#include "knot.h" #include "ui/tools/measure-tool.h" #include "ui/tools/freehand-base.h" #include "display/canvas-text.h" @@ -45,11 +45,15 @@ #include "enums.h" #include "ui/control-manager.h" #include "knot-enums.h" +#include using Inkscape::ControlManager; using Inkscape::CTLINE_SECONDARY; using Inkscape::Util::unit_table; +#define MT_KNOT_COLOR_NORMAL 0xffffff00 +#define MT_KNOT_COLOR_MOUSEOVER 0xff000000 + namespace Inkscape { namespace UI { namespace Tools { @@ -57,7 +61,7 @@ namespace Tools { std::vector measure_tmp_items; const std::string& MeasureTool::getPrefsPath() { - return MeasureTool::prefsPath; + return MeasureTool::prefsPath; } const std::string MeasureTool::prefsPath = "/tools/measure"; @@ -227,14 +231,61 @@ void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom } // namespace - +static Geom::Point start_p = Geom::Point(); +static Geom::Point end_p = Geom::Point(); MeasureTool::MeasureTool() : ToolBase(cursor_measure_xpm, 4, 4) , grabbed(NULL) { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + // create the knot + this->knot_start = new SPKnot(desktop, N_("Measure start")); + this->knot_start->setMode(SP_KNOT_MODE_XOR); + this->knot_start->setFill(MT_KNOT_COLOR_NORMAL, MT_KNOT_COLOR_MOUSEOVER, MT_KNOT_COLOR_MOUSEOVER); + this->knot_start->setStroke(0x0000007f, 0x0000007f, 0x0000007f); + this->knot_start->setShape(SP_KNOT_SHAPE_CIRCLE); + this->knot_start->updateCtrl(); + this->knot_end = new SPKnot(desktop, N_("Measure end")); + this->knot_end->setMode(SP_KNOT_MODE_XOR); + this->knot_end->setFill(MT_KNOT_COLOR_NORMAL, MT_KNOT_COLOR_MOUSEOVER, MT_KNOT_COLOR_MOUSEOVER); + this->knot_end->setStroke(0x0000007f, 0x0000007f, 0x0000007f); + this->knot_end->setShape(SP_KNOT_SHAPE_CIRCLE); + this->knot_end->updateCtrl(); + if(end_p != Geom::Point()){ + this->knot_start->setPosition(start_p, SP_KNOT_STATE_NORMAL); + this->knot_start->show(); + this->knot_end->setPosition(end_p, SP_KNOT_STATE_NORMAL); + this->knot_end->show(); + this->showCanvasItems(this->knot_start->position(), this->knot_end->position()); + } + this->_knot_start_moved_connection = this->knot_start->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotMovedHandler)); + this->_knot_start_ungrabbed_connection = this->knot_start->ungrabbed_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotUngrabbedHandler)); + this->_knot_end_moved_connection = this->knot_end->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotMovedHandler)); + this->_knot_end_ungrabbed_connection = this->knot_end->ungrabbed_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotUngrabbedHandler)); + } MeasureTool::~MeasureTool() { + this->_knot_start_moved_connection.disconnect(); + this->_knot_start_ungrabbed_connection.disconnect(); + this->_knot_end_moved_connection.disconnect(); + this->_knot_end_ungrabbed_connection.disconnect(); + + /* unref should call destroy */ + knot_unref(this->knot_start); + knot_unref(this->knot_end); + for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { + desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); + } + measure_tmp_items.clear(); +} + +void MeasureTool::knotMovedHandler(SPKnot */*knot*/, Geom::Point const /*&ppointer*/, guint /*state*/){ + showCanvasItems(this->knot_start->position(), this->knot_end->position()); +} + +void MeasureTool::knotUngrabbedHandler(SPKnot */*knot*/, unsigned int /*state*/){ + showCanvasItems(this->knot_start->position(), this->knot_end->position()); } void MeasureTool::finish() { @@ -249,12 +300,12 @@ void MeasureTool::finish() { } //void MeasureTool::setup() { -// ToolBase* ec = this; +// ToolBase* ec = this; // //// if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup) { //// SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup(ec); //// } -// ToolBase::setup(); +// ToolBase::setup(); //} //gint MeasureTool::item_handler(SPItem* item, GdkEvent* event) { @@ -301,6 +352,8 @@ bool MeasureTool::root_handler(GdkEvent* event) { switch (event->type) { case GDK_BUTTON_PRESS: { + this->knot_start->hide(); + this->knot_end->hide(); Geom::Point const button_w(event->button.x, event->button.y); explicitBase = boost::none; last_end = boost::none; @@ -353,7 +406,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { Geom::Point const motion_w(event->motion.x, event->motion.y); if ( within_tolerance){ if ( Geom::LInfty( motion_w - start_point ) < tolerance) { - return false; // Do not drag if we're within tolerance from origin. + return FALSE; // Do not drag if we're within tolerance from origin. } } // Once the user has moved farther than tolerance from the original location @@ -361,7 +414,24 @@ bool MeasureTool::root_handler(GdkEvent* event) { // motion notify coordinates as given (no snapping back to origin) within_tolerance = false; if(event->motion.time == 0 || !last_end || Geom::LInfty( motion_w - *last_end ) > (tolerance/2)){ - showCanvasItems(event->motion); + Geom::Point const motion_w(event->motion.x, event->motion.y); + Geom::Point const motion_dt(desktop->w2d(motion_w)); + Geom::Point end_point = motion_dt; + + if (event->motion.state & GDK_CONTROL_MASK) { + spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); + } else { + if (!(event->motion.state & GDK_SHIFT_MASK)) { + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_point); + Inkscape::SnappedPoint sp = m.freeSnap(scp); + end_point = sp.getPoint(); + m.unSetup(); + } + } + showCanvasItems(start_point, end_point); last_end = motion_w ; } gobble_motion_events(GDK_BUTTON1_MASK); @@ -369,63 +439,42 @@ bool MeasureTool::root_handler(GdkEvent* event) { break; } case GDK_BUTTON_RELEASE: { - sp_event_context_discard_delayed_snap_event(this); - explicitBase = boost::none; - last_end = boost::none; - - //clear all temporary canvas items related to the measurement tool. - for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { - desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); + this->knot_start->setPosition(start_point, SP_KNOT_STATE_NORMAL); + this->knot_start->show(); + if(last_end){ + Geom::Point end_point = desktop->w2d(*last_end); + this->knot_end->setPosition(end_point, SP_KNOT_STATE_NORMAL); + this->knot_end->show(); } - - measure_tmp_items.clear(); - if (this->grabbed) { sp_canvas_item_ungrab(this->grabbed, event->button.time); this->grabbed = NULL; } - - start_point = Geom::Point(); + sp_event_context_discard_delayed_snap_event(this); break; } default: break; } if (!ret) { - ret = ToolBase::root_handler(event); + ret = ToolBase::root_handler(event); } return ret; } -void MeasureTool::showCanvasItems(GdkEventMotion const &mevent){ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Geom::Point const motion_w(mevent.x, mevent.y); - bool show_in_between = prefs->getBool("/tools/measure/show_in_between"); - bool all_layers = prefs->getBool("/tools/measure/all_layers"); +void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point){ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + start_p = start_point; + end_p = end_point; //clear previous temporary canvas items, we'll draw new ones for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); } - measure_tmp_items.clear(); - Geom::Point const motion_dt(desktop->w2d(motion_w)); - Geom::Point end_point = motion_dt; - - if (mevent.state & GDK_CONTROL_MASK) { - spdc_endpoint_snap_rotation(this, end_point, start_point, mevent.state); - } else { - if (!(mevent.state & GDK_SHIFT_MASK)) { - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); - Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); - Inkscape::SnappedPoint sp = m.freeSnap(scp); - end_point = sp.getPoint(); - m.unSetup(); - } - } - + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool show_in_between = prefs->getBool("/tools/measure/show_in_between"); + bool all_layers = prefs->getBool("/tools/measure/all_layers"); Geom::PathVector lineseg; Geom::Path p; p.start(desktop->dt2doc(start_point)); @@ -463,10 +512,10 @@ void MeasureTool::showCanvasItems(GdkEventMotion const &mevent){ r->move(start_point); std::vector items_reverse = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers, 2); r->stop(); - if(items_reverse.size() == 2){ + if(items_reverse.size() == 2 && items_reverse[1] != items[0] && items_reverse[1] != items[1]){ items.push_back(items_reverse[1]); } - if(items_reverse.size() >= 1){ + if(items_reverse.size() >= 1 && items_reverse[0] != items[1]){ items.push_back(items_reverse[0]); } } else { diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index 4673e0f0a..8a1eb2203 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -11,7 +11,8 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include +#include #include "ui/tools/tool-base.h" #include <2geom/point.h> #include @@ -19,28 +20,37 @@ #define SP_MEASURE_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_MEASURE_CONTEXT(obj) (dynamic_cast((const Inkscape::UI::Tools::ToolBase*)obj) != NULL) +class SPKnot; + namespace Inkscape { namespace UI { namespace Tools { class MeasureTool : public ToolBase { public: - MeasureTool(); - virtual ~MeasureTool(); - - static const std::string prefsPath; + MeasureTool(); + virtual ~MeasureTool(); - virtual void finish(); - virtual bool root_handler(GdkEvent* event); - virtual void showCanvasItems(GdkEventMotion const &event); + static const std::string prefsPath; - virtual const std::string& getPrefsPath(); + virtual void finish(); + virtual bool root_handler(GdkEvent* event); + virtual void showCanvasItems(Geom::Point start_point, Geom::Point end_point); + virtual const std::string& getPrefsPath(); + void knotMovedHandler(SPKnot */*knot*/, Geom::Point const /*&ppointer*/, guint /*state*/); + void knotUngrabbedHandler(SPKnot */*knot*/, unsigned int /*state*/); private: - SPCanvasItem* grabbed; + SPCanvasItem* grabbed; Geom::Point start_point; boost::optional explicitBase; boost::optional last_end; + SPKnot *knot_start; + SPKnot *knot_end; + sigc::connection _knot_start_moved_connection; + sigc::connection _knot_start_ungrabbed_connection; + sigc::connection _knot_end_moved_connection; + sigc::connection _knot_end_ungrabbed_connection; }; } -- cgit v1.2.3 From ef0299883a7bc9402c96856eeebba118ef7f49c8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 4 Oct 2015 20:33:00 +0200 Subject: Add snap and CTRL constrain (bzr r14393.1.5) --- src/ui/tools/measure-tool.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 142c04fc3..5521dd6e8 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -420,16 +420,14 @@ bool MeasureTool::root_handler(GdkEvent* event) { if (event->motion.state & GDK_CONTROL_MASK) { spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); - } else { - if (!(event->motion.state & GDK_SHIFT_MASK)) { - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); - Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); - Inkscape::SnappedPoint sp = m.freeSnap(scp); - end_point = sp.getPoint(); - m.unSetup(); - } + } else if (!(event->motion.state & GDK_SHIFT_MASK)) { + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_point); + Inkscape::SnappedPoint sp = m.freeSnap(scp); + end_point = sp.getPoint(); + m.unSetup(); } showCanvasItems(start_point, end_point); last_end = motion_w ; @@ -443,6 +441,17 @@ bool MeasureTool::root_handler(GdkEvent* event) { this->knot_start->show(); if(last_end){ Geom::Point end_point = desktop->w2d(*last_end); + if (event->button.state & GDK_CONTROL_MASK) { + spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); + } else if (!(event->button.state & GDK_SHIFT_MASK)) { + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_point); + Inkscape::SnappedPoint sp = m.freeSnap(scp); + end_point = sp.getPoint(); + m.unSetup(); + } this->knot_end->setPosition(end_point, SP_KNOT_STATE_NORMAL); this->knot_end->show(); } -- cgit v1.2.3 From 88f15a973fc593be36a423864526c7e064bf3dd3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 5 Oct 2015 19:30:47 +0200 Subject: Add redraw to meassure when use toolbar (bzr r14393.1.6) --- src/ui/tools/measure-tool.cpp | 6 ++- src/ui/tools/measure-tool.h | 1 + src/widgets/measure-toolbar.cpp | 99 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 94 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 5521dd6e8..c275a6d79 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -256,7 +256,7 @@ MeasureTool::MeasureTool() this->knot_start->show(); this->knot_end->setPosition(end_p, SP_KNOT_STATE_NORMAL); this->knot_end->show(); - this->showCanvasItems(this->knot_start->position(), this->knot_end->position()); + this->showCanvasItems(); } this->_knot_start_moved_connection = this->knot_start->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotMovedHandler)); this->_knot_start_ungrabbed_connection = this->knot_start->ungrabbed_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotUngrabbedHandler)); @@ -472,6 +472,10 @@ bool MeasureTool::root_handler(GdkEvent* event) { return ret; } +void MeasureTool::showCanvasItems(){ + showCanvasItems(start_p, end_p); +} + void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point){ SPDesktop *desktop = SP_ACTIVE_DESKTOP; start_p = start_point; diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index 8a1eb2203..412de8b72 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -35,6 +35,7 @@ public: virtual void finish(); virtual bool root_handler(GdkEvent* event); + virtual void showCanvasItems(); virtual void showCanvasItems(Geom::Point start_point, Geom::Point end_point); virtual const std::string& getPrefsPath(); void knotMovedHandler(SPKnot */*knot*/, Geom::Point const /*&ppointer*/, guint /*state*/); diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index ca79b5792..e3536b6a7 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -33,6 +33,8 @@ #include "measure-toolbar.h" #include "desktop.h" +#include "inkscape.h" +#include "message-stack.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" #include "widgets/ege-output-action.h" @@ -40,6 +42,7 @@ #include "toolbox.h" #include "widgets/ink-action.h" #include "ui/icon-names.h" +#include "ui/tools/measure-tool.h" #include "ui/widget/unit-tracker.h" using Inkscape::UI::Widget::UnitTracker; @@ -47,11 +50,26 @@ using Inkscape::Util::Unit; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; +using Inkscape::UI::Tools::MeasureTool; //######################## //## Measure Toolbox ## //######################## +/** Temporary hack: Returns the node tool in the active desktop. + * Will go away during tool refactoring. */ +static MeasureTool *get_measure_tool() +{ + MeasureTool *tool = 0; + if (SP_ACTIVE_DESKTOP ) { + Inkscape::UI::Tools::ToolBase *ec = SP_ACTIVE_DESKTOP->event_context; + if (SP_IS_MEASURE_CONTEXT(ec)) { + tool = static_cast(ec); + } + } + return tool; +} + static void sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl) { @@ -61,6 +79,10 @@ sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setInt(Glib::ustring("/tools/measure/fontsize"), gtk_adjustment_get_value(adj)); + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } } } @@ -70,6 +92,61 @@ static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl) Glib::ustring const unit = tracker->getActiveUnit()->abbr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setString("/tools/measure/unit", unit); + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } +} + +static void toggle_ignore_1st_and_last( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setInt("/tools/measure/ignore_1st_and_last", active); + SPDesktop *desktop = static_cast(data); + if ( active ) { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Start and end measures inactive.")); + } else { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Start and end measures active.")); + } + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } +} + +static void toggle_all_layers( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setInt("/tools/measure/all_layers", active); + SPDesktop *desktop = static_cast(data); + if ( active ) { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Use all layers in the measure.")); + } else { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Use current layer in the measure.")); + } + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } +} + +static void toggle_show_in_between( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setInt("/tools/measure/show_in_between", active); + SPDesktop *desktop = static_cast(data); + if ( active ) { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Compute all elements.")); + } else { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Compute max lenght.")); + } + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } } void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder) @@ -118,20 +195,20 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G _("Ignore first and last"), INKSCAPE_ICON("draw-geometry-line-segment"), secondarySize ); - gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); - PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/measure/ignore_1st_and_last"); - g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/ignore_1st_and_last", true) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_ignore_1st_and_last), desktop) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } // measure imbetweens { InkToggleAction* act = ink_toggle_action_new( "MeasureInBettween", - _("Show meassures between items"), - _("Show meassures between items"), + _("Show measures between items"), + _("Show measures between items"), INKSCAPE_ICON("distribute-randomize"), secondarySize ); - gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); - PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/measure/show_in_between"); - g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/show_in_between", true) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_in_between), desktop) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } // measure only current layer { @@ -140,9 +217,9 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G _("Measure all layers"), INKSCAPE_ICON("dialog-layers"), secondarySize ); - gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); - PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/measure/all_layers"); - g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/all_layers", true) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_all_layers), desktop) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } } // end of sp_measure_toolbox_prep() -- cgit v1.2.3 From ae0a08f8986529a81c7bd239c7cde548c8bdacc3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 5 Oct 2015 20:13:58 +0200 Subject: add reverse to meassure output (bzr r14393.1.8) --- src/ui/tools/measure-tool.cpp | 10 ++++++++++ src/ui/tools/measure-tool.h | 1 + src/widgets/measure-toolbar.cpp | 17 ++++++++++++++++- src/widgets/toolbox.cpp | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index c275a6d79..8d838fc06 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -280,6 +280,16 @@ MeasureTool::~MeasureTool() { measure_tmp_items.clear(); } +void MeasureTool::reverseKnots(){ + Geom::Point start = start_p; + Geom::Point end = end_p; + this->knot_start->setPosition(end, SP_KNOT_STATE_NORMAL); + this->knot_start->show(); + this->knot_end->setPosition(start, SP_KNOT_STATE_NORMAL); + this->knot_end->show(); + this->showCanvasItems(end, start); +} + void MeasureTool::knotMovedHandler(SPKnot */*knot*/, Geom::Point const /*&ppointer*/, guint /*state*/){ showCanvasItems(this->knot_start->position(), this->knot_end->position()); } diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index 412de8b72..944b14ed8 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -37,6 +37,7 @@ public: virtual bool root_handler(GdkEvent* event); virtual void showCanvasItems(); virtual void showCanvasItems(Geom::Point start_point, Geom::Point end_point); + virtual void reverseKnots(); virtual const std::string& getPrefsPath(); void knotMovedHandler(SPKnot */*knot*/, Geom::Point const /*&ppointer*/, guint /*state*/); void knotUngrabbedHandler(SPKnot */*knot*/, unsigned int /*state*/); diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index e3536b6a7..5abd099d6 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -148,7 +148,12 @@ static void toggle_show_in_between( GtkToggleAction* act, gpointer data ) mt->showCanvasItems(); } } - +static void sp_reverse_knots(void){ + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->reverseKnots(); + } +} void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder) { UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); @@ -221,6 +226,16 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_all_layers), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } + //toogle start end + { + InkAction* act = ink_action_new( "MeasureReverse", + _("Reverse measure"), + _("Reverse measure"), + INKSCAPE_ICON("draw-geometry-mirror"), + secondarySize ); + g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_reverse_knots), 0 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } } // end of sp_measure_toolbox_prep() diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index ba02adb92..769829313 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -344,6 +344,7 @@ static gchar const * ui_descr = " " " " " " + " " " " " " -- cgit v1.2.3 From 8db12376ba038c323068c14955fac45f00fcb0e6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 6 Oct 2015 18:34:19 +0200 Subject: add snaping to knots and stating convert measure to items (bzr r14393.1.9) --- src/ui/tools/measure-tool.cpp | 148 +++++++++++++++++++++++++++++++++++++--- src/ui/tools/measure-tool.h | 7 +- src/widgets/measure-toolbar.cpp | 18 +++++ src/widgets/toolbox.cpp | 1 + 4 files changed, 162 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 8d838fc06..2a89189dd 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -17,15 +17,13 @@ #include "macros.h" #include "rubberband.h" #include "display/curve.h" -#include "sp-shape.h" -#include "sp-text.h" -#include "sp-flowtext.h" #include "text-editing.h" #include "display/sp-ctrlline.h" #include "display/sodipodi-ctrl.h" #include "display/sp-canvas-item.h" #include "display/sp-canvas-util.h" #include "desktop.h" +#include "svg/svg.h" #include "document.h" #include "pixmaps/cursor-measure.xpm" #include "preferences.h" @@ -42,6 +40,10 @@ #include <2geom/angle.h> #include "snap.h" #include "sp-namedview.h" +#include "sp-shape.h" +#include "sp-text.h" +#include "sp-flowtext.h" +#include "sp-defs.h" #include "enums.h" #include "ui/control-manager.h" #include "knot-enums.h" @@ -258,9 +260,9 @@ MeasureTool::MeasureTool() this->knot_end->show(); this->showCanvasItems(); } - this->_knot_start_moved_connection = this->knot_start->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotMovedHandler)); + this->_knot_start_moved_connection = this->knot_start->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotStartMovedHandler)); this->_knot_start_ungrabbed_connection = this->knot_start->ungrabbed_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotUngrabbedHandler)); - this->_knot_end_moved_connection = this->knot_end->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotMovedHandler)); + this->_knot_end_moved_connection = this->knot_end->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotEndMovedHandler)); this->_knot_end_ungrabbed_connection = this->knot_end->ungrabbed_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotUngrabbedHandler)); } @@ -290,14 +292,44 @@ void MeasureTool::reverseKnots(){ this->showCanvasItems(end, start); } -void MeasureTool::knotMovedHandler(SPKnot */*knot*/, Geom::Point const /*&ppointer*/, guint /*state*/){ - showCanvasItems(this->knot_start->position(), this->knot_end->position()); +void MeasureTool::knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state){ + if (!(state & GDK_SHIFT_MASK)) { + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + Inkscape::SnapCandidatePoint scp(ppointer, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(end_p); + Inkscape::SnappedPoint sp = m.freeSnap(scp); + if(start_p != sp.getPoint()){ + start_p = sp.getPoint(); + this->knot_end->setPosition(start_p, SP_KNOT_STATE_MOUSEOVER); + } + m.unSetup(); + } + showCanvasItems(start_point, this->knot_end->position()); +} + +void MeasureTool::knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state){ + if (!(state & GDK_SHIFT_MASK)) { + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + Inkscape::SnapCandidatePoint scp(ppointer, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_p); + Inkscape::SnappedPoint sp = m.freeSnap(scp); + if(end_p != sp.getPoint()){ + end_p = sp.getPoint(); + this->knot_end->setPosition(end_p, SP_KNOT_STATE_MOUSEOVER); + } + m.unSetup(); + } + showCanvasItems(this->knot_start->position(), end_p); } -void MeasureTool::knotUngrabbedHandler(SPKnot */*knot*/, unsigned int /*state*/){ - showCanvasItems(this->knot_start->position(), this->knot_end->position()); +void MeasureTool::knotUngrabbedHandler(SPKnot */*knot*/, unsigned int state){ + showCanvasItems(this->knot_start->position(), end_p); } + + void MeasureTool::finish() { this->enableGrDrag(false); @@ -482,6 +514,100 @@ bool MeasureTool::root_handler(GdkEvent* event) { return ret; } +void MeasureTool::setMarkers(){ + SPDesktop *desktop = this->desktop; + SPDocument *doc = desktop->getDocument(); + SPObject *arrowStart = doc->getObjectById("Arrow2Sstart"); + SPObject *arrowEnd = doc->getObjectById("Arrow2Send"); + if (!arrowStart) { + setMarker(true); + } + if(!arrowEnd){ + setMarker(false); + } +} +void MeasureTool::setMarker(bool isStart){ + SPDesktop *desktop = this->desktop; + SPDocument *doc = desktop->getDocument(); + SPDefs *defs = doc->getDefs(); + Inkscape::XML::Node *repr; + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + repr = xml_doc->createElement("svg:marker"); + if(isStart){ + repr->setAttribute("id", "Arrow2Sstart"); + } else { + repr->setAttribute("id", "Arrow2Send"); + } + repr->setAttribute("inkscape:isstock", "true"); + if(isStart){ + repr->setAttribute("inkscape:stockid", "Arrow2Sstart"); + } else { + repr->setAttribute("inkscape:stockid", "Arrow2Send"); + } + repr->setAttribute("orient", "auto"); + repr->setAttribute("refX", "0.0"); + repr->setAttribute("refY", "0.0"); + repr->setAttribute("style", "overflow:visible;"); + SPItem *item = SP_ITEM(defs->appendChildRepr(repr)); + Inkscape::GC::release(repr); + item->updateRepr(); + Inkscape::XML::Node *repr2; + repr2 = xml_doc->createElement("svg:path"); + repr2->setAttribute("d", "M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.9730900,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z"); + if(isStart){ + repr2->setAttribute("id", "Arrow2SstartPath"); + } else { + repr2->setAttribute("id", "Arrow2SendPath"); + } + repr2->setAttribute("style", "fill-rule:evenodd;stroke-width:0.625;stroke-linejoin:round;stroke:#000000;stroke-opacity:1;fill:#000000;fill-opacity:1"); + if(isStart){ + repr2->setAttribute("transform", "scale(0.3) translate(-2.3,0)"); + } else { + repr2->setAttribute("transform", "scale(0.3) rotate(180) translate(-2.3,0)"); + } + SPItem *item2 = SP_ITEM(item->appendChildRepr(repr2)); + Inkscape::GC::release(repr2); + item2->updateRepr(); +} + +void MeasureTool::toMarkDimension(){ + setMarkers(); + Geom::PathVector c; + Geom::Path p; + p.start(start_p); + p.appendNew(end_p); + c.push_back(p); + SPDesktop *desktop = this->desktop; + SPDocument *doc = desktop->getDocument(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + if (c.size() == 1) { + Inkscape::XML::Node *repr; + repr = xml_doc->createElement("svg:path"); + gchar const *str = sp_svg_write_path(c); + gchar const *style_str = "fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-start:url(#Arrow2Sstart);marker-end:url(#Arrow2Send)"; + g_assert( str != NULL ); + repr->setAttribute("d", str); + repr->setAttribute("style", style_str); + // Attach repr + SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); + Inkscape::GC::release(repr); + item->updateRepr(); + } + + // Flush pending updates + doc->ensureUpToDate(); + reset(); +} + +void MeasureTool::reset(){ + this->knot_start->hide(); + this->knot_end->hide(); + for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { + desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); + } + measure_tmp_items.clear(); +} + void MeasureTool::showCanvasItems(){ showCanvasItems(start_p, end_p); } @@ -765,12 +891,12 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(intersections[0]), - desktop->doc2dt(intersections[0]) + normal * 65); + desktop->doc2dt(intersections[0]) + normal * 60); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(intersections[intersections.size() - 1]), - desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 65); + desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 60); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); } diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index 944b14ed8..44153a144 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -38,8 +38,13 @@ public: virtual void showCanvasItems(); virtual void showCanvasItems(Geom::Point start_point, Geom::Point end_point); virtual void reverseKnots(); + virtual void toMarkDimension(); + virtual void reset(); + virtual void setMarkers(); + virtual void setMarker(bool isStart); virtual const std::string& getPrefsPath(); - void knotMovedHandler(SPKnot */*knot*/, Geom::Point const /*&ppointer*/, guint /*state*/); + void knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state); + void knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state); void knotUngrabbedHandler(SPKnot */*knot*/, unsigned int /*state*/); private: diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 5abd099d6..a619418db 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -154,6 +154,14 @@ static void sp_reverse_knots(void){ mt->reverseKnots(); } } + +static void sp_to_mark_dimension(void){ + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->toMarkDimension(); + } +} + void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder) { UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); @@ -236,6 +244,16 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_reverse_knots), 0 ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } + //to mark dimensions + { + InkAction* act = ink_action_new( "MeasureMarkDimension", + _("Mark Dimension"), + _("Mark Dimension"), + INKSCAPE_ICON("draw-geometry-mirror"), + secondarySize ); + g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_mark_dimension), 0 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } } // end of sp_measure_toolbox_prep() diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 769829313..765e91629 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -345,6 +345,7 @@ static gchar const * ui_descr = " " " " " " + " " " " " " -- cgit v1.2.3 From bfe639d1e476a1144cecae26d5959569aae79dcd Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 6 Oct 2015 18:57:43 +0200 Subject: fix a bug on snapping with start knot (bzr r14393.1.10) --- src/ui/tools/measure-tool.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 2a89189dd..894687919 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -296,24 +296,24 @@ void MeasureTool::knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppo if (!(state & GDK_SHIFT_MASK)) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - Inkscape::SnapCandidatePoint scp(ppointer, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(end_p); + Inkscape::SnapCandidatePoint scp(this->knot_start->position(), Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(this->knot_end->position()); Inkscape::SnappedPoint sp = m.freeSnap(scp); if(start_p != sp.getPoint()){ start_p = sp.getPoint(); - this->knot_end->setPosition(start_p, SP_KNOT_STATE_MOUSEOVER); + this->knot_start->setPosition(start_p, SP_KNOT_STATE_MOUSEOVER); } m.unSetup(); } - showCanvasItems(start_point, this->knot_end->position()); + showCanvasItems(start_p, this->knot_end->position()); } void MeasureTool::knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state){ if (!(state & GDK_SHIFT_MASK)) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - Inkscape::SnapCandidatePoint scp(ppointer, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_p); + Inkscape::SnapCandidatePoint scp(this->knot_end->position(), Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(this->knot_start->position()); Inkscape::SnappedPoint sp = m.freeSnap(scp); if(end_p != sp.getPoint()){ end_p = sp.getPoint(); -- cgit v1.2.3 From 98b86a476c3b26d341a4c175d90bc5611b0899cf Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 6 Oct 2015 19:14:44 +0200 Subject: fix a bug rendering the angle line in diferent units than pixels (bzr r14393.1.11) --- src/ui/tools/measure-tool.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 894687919..8a9340b07 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -190,12 +190,14 @@ Geom::Point calcAngleDisplayAnchor(SPDesktop *desktop, double angle, double base * @param anchor the anchor point for displaying the text label. * @param angle the angle of the arc segment to draw. */ -void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom::Point const &end, Geom::Point const &anchor, double angle) +void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom::Point const &end, Geom::Point const &anchor, double angle, Glib::ustring unit_name) { // Given that we have a point on the arc's edge and the angle of the arc, we need to get the two endpoints. double textLen = std::abs((anchor - center).length()); + textLen = Inkscape::Util::Quantity::convert(textLen, "px", unit_name); double sideLen = std::abs((end - center).length()); + sideLen = Inkscape::Util::Quantity::convert(sideLen, "px", unit_name); if (sideLen > 0.0) { double factor = std::min(1.0, textLen / sideLen); @@ -877,7 +879,7 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point CTLINE_SECONDARY); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - createAngleDisplayCurve(desktop, start_point, end_point, angleDisplayPt, angle); + createAngleDisplayCurve(desktop, start_point, end_point, angleDisplayPt, angle, unit_name); } } -- cgit v1.2.3 From 8ffe79882b3a4e746088d75b76b51251c87aa4a9 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 6 Oct 2015 19:33:01 +0200 Subject: Remove wrong code for angle helper path (bzr r14393.1.12) --- src/ui/tools/measure-tool.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 8a9340b07..894687919 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -190,14 +190,12 @@ Geom::Point calcAngleDisplayAnchor(SPDesktop *desktop, double angle, double base * @param anchor the anchor point for displaying the text label. * @param angle the angle of the arc segment to draw. */ -void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom::Point const &end, Geom::Point const &anchor, double angle, Glib::ustring unit_name) +void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom::Point const &end, Geom::Point const &anchor, double angle) { // Given that we have a point on the arc's edge and the angle of the arc, we need to get the two endpoints. double textLen = std::abs((anchor - center).length()); - textLen = Inkscape::Util::Quantity::convert(textLen, "px", unit_name); double sideLen = std::abs((end - center).length()); - sideLen = Inkscape::Util::Quantity::convert(sideLen, "px", unit_name); if (sideLen > 0.0) { double factor = std::min(1.0, textLen / sideLen); @@ -879,7 +877,7 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point CTLINE_SECONDARY); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - createAngleDisplayCurve(desktop, start_point, end_point, angleDisplayPt, angle, unit_name); + createAngleDisplayCurve(desktop, start_point, end_point, angleDisplayPt, angle); } } -- cgit v1.2.3 From 4f5e6cf51b5fdd584d57fa225d3cdba407f01561 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 7 Oct 2015 18:13:48 +0200 Subject: working in dimension to item (bzr r14393.1.13) --- src/ui/tools/measure-tool.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 894687919..32f164a96 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -25,6 +25,7 @@ #include "desktop.h" #include "svg/svg.h" #include "document.h" +#include #include "pixmaps/cursor-measure.xpm" #include "preferences.h" #include "inkscape.h" @@ -38,12 +39,14 @@ #include <2geom/pathvector.h> #include <2geom/crossing.h> #include <2geom/angle.h> +#include <2geom/transforms.h> #include "snap.h" #include "sp-namedview.h" #include "sp-shape.h" #include "sp-text.h" #include "sp-flowtext.h" #include "sp-defs.h" +#include "sp-item.h" #include "enums.h" #include "ui/control-manager.h" #include "knot-enums.h" @@ -571,12 +574,17 @@ void MeasureTool::setMarker(bool isStart){ } void MeasureTool::toMarkDimension(){ + Geom::Point windowNormal = Geom::unit_vector(Geom::rot90(desktop->d2w(end_p - start_p))); + Geom::Point normal = desktop->w2d(windowNormal); setMarkers(); Geom::PathVector c; Geom::Path p; - p.start(start_p); - p.appendNew(end_p); + p.start(desktop->doc2dt(start_p) + normal * 60); + p.appendNew(desktop->doc2dt(end_p) + normal * 60); c.push_back(p); + c *= desktop->doc2dt(); + c *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + c *= Geom::Scale(95.0); SPDesktop *desktop = this->desktop; SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); @@ -596,7 +604,7 @@ void MeasureTool::toMarkDimension(){ // Flush pending updates doc->ensureUpToDate(); - reset(); + //reset(); } void MeasureTool::reset(){ -- cgit v1.2.3 From 17f2a27dfcfbf68d218193a830faa9580ce8a363 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 10 Oct 2015 21:17:34 +0200 Subject: Added new button to get global measure as a dimension (bzr r14393.1.15) --- src/ui/tools/measure-tool.cpp | 169 ++++++++++++++++++++++++++++------------ src/ui/tools/measure-tool.h | 1 + src/widgets/measure-toolbar.cpp | 35 ++++++++- src/widgets/toolbox.cpp | 2 + 4 files changed, 155 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 32f164a96..585128135 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -25,6 +25,7 @@ #include "desktop.h" #include "svg/svg.h" #include "document.h" +#include "document-undo.h" #include #include "pixmaps/cursor-measure.xpm" #include "preferences.h" @@ -50,11 +51,14 @@ #include "enums.h" #include "ui/control-manager.h" #include "knot-enums.h" +#include "desktop-style.h" +#include "verbs.h" #include using Inkscape::ControlManager; using Inkscape::CTLINE_SECONDARY; using Inkscape::Util::unit_table; +using Inkscape::DocumentUndo; #define MT_KNOT_COLOR_NORMAL 0xffffff00 #define MT_KNOT_COLOR_MOUSEOVER 0xff000000 @@ -74,7 +78,7 @@ const std::string MeasureTool::prefsPath = "/tools/measure"; namespace { -gint const DIMENSION_OFFSET = 35; +gint dimension_offset = 35; /** * Simple class to use for removing label overlap. @@ -236,8 +240,10 @@ void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom } // namespace -static Geom::Point start_p = Geom::Point(); -static Geom::Point end_p = Geom::Point(); +Geom::Point const MAGIC_POINT = Geom::Point(-0.0003432532004303,-0.006745034004304); +static Geom::Point start_p = MAGIC_POINT; +static Geom::Point end_p = MAGIC_POINT; + MeasureTool::MeasureTool() : ToolBase(cursor_measure_xpm, 4, 4) , grabbed(NULL) @@ -256,10 +262,10 @@ MeasureTool::MeasureTool() this->knot_end->setStroke(0x0000007f, 0x0000007f, 0x0000007f); this->knot_end->setShape(SP_KNOT_SHAPE_CIRCLE); this->knot_end->updateCtrl(); - if(end_p != Geom::Point()){ - this->knot_start->setPosition(start_p, SP_KNOT_STATE_NORMAL); + if(end_p != MAGIC_POINT){ + this->knot_start->moveto(start_p); this->knot_start->show(); - this->knot_end->setPosition(end_p, SP_KNOT_STATE_NORMAL); + this->knot_end->moveto(end_p); this->knot_end->show(); this->showCanvasItems(); } @@ -288,9 +294,9 @@ MeasureTool::~MeasureTool() { void MeasureTool::reverseKnots(){ Geom::Point start = start_p; Geom::Point end = end_p; - this->knot_start->setPosition(end, SP_KNOT_STATE_NORMAL); + this->knot_start->moveto(end); this->knot_start->show(); - this->knot_end->setPosition(start, SP_KNOT_STATE_NORMAL); + this->knot_end->moveto(start); this->knot_end->show(); this->showCanvasItems(end, start); } @@ -304,7 +310,7 @@ void MeasureTool::knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppo Inkscape::SnappedPoint sp = m.freeSnap(scp); if(start_p != sp.getPoint()){ start_p = sp.getPoint(); - this->knot_start->setPosition(start_p, SP_KNOT_STATE_MOUSEOVER); + this->knot_start->moveto(start_p); } m.unSetup(); } @@ -320,7 +326,7 @@ void MeasureTool::knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppoin Inkscape::SnappedPoint sp = m.freeSnap(scp); if(end_p != sp.getPoint()){ end_p = sp.getPoint(); - this->knot_end->setPosition(end_p, SP_KNOT_STATE_MOUSEOVER); + this->knot_end->moveto(end_p); } m.unSetup(); } @@ -328,7 +334,7 @@ void MeasureTool::knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppoin } void MeasureTool::knotUngrabbedHandler(SPKnot */*knot*/, unsigned int state){ - showCanvasItems(this->knot_start->position(), end_p); + showCanvasItems(this->knot_start->position(), this->knot_end->position()); } @@ -432,18 +438,20 @@ bool MeasureTool::root_handler(GdkEvent* event) { break; } case GDK_MOTION_NOTIFY: { - if (!(event->motion.state & GDK_BUTTON1_MASK) && !(event->motion.state & GDK_SHIFT_MASK)) { - Geom::Point const motion_w(event->motion.x, event->motion.y); - Geom::Point const motion_dt(desktop->w2d(motion_w)); + if (!(event->motion.state & GDK_BUTTON1_MASK)){ + if(!(event->motion.state & GDK_SHIFT_MASK)) { + Geom::Point const motion_w(event->motion.x, event->motion.y); + Geom::Point const motion_dt(desktop->w2d(motion_w)); - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); - Inkscape::SnapCandidatePoint scp(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); + Inkscape::SnapCandidatePoint scp(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_point); - m.preSnap(scp); - m.unSetup(); + m.preSnap(scp); + m.unSetup(); + } } else { ret = TRUE; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -482,12 +490,13 @@ bool MeasureTool::root_handler(GdkEvent* event) { break; } case GDK_BUTTON_RELEASE: { - this->knot_start->setPosition(start_point, SP_KNOT_STATE_NORMAL); + this->knot_start->moveto(start_point); this->knot_start->show(); + Geom::Point end_point = end_p; if(last_end){ - Geom::Point end_point = desktop->w2d(*last_end); + end_point = desktop->w2d(*last_end); if (event->button.state & GDK_CONTROL_MASK) { - spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); + spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); } else if (!(event->button.state & GDK_SHIFT_MASK)) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); @@ -497,14 +506,14 @@ bool MeasureTool::root_handler(GdkEvent* event) { end_point = sp.getPoint(); m.unSetup(); } - this->knot_end->setPosition(end_point, SP_KNOT_STATE_NORMAL); - this->knot_end->show(); } + this->knot_end->moveto(end_point); + this->knot_end->show(); + showCanvasItems(start_point, end_point); if (this->grabbed) { sp_canvas_item_ungrab(this->grabbed, event->button.time); this->grabbed = NULL; } - sp_event_context_discard_delayed_snap_event(this); break; } default: @@ -562,7 +571,7 @@ void MeasureTool::setMarker(bool isStart){ } else { repr2->setAttribute("id", "Arrow2SendPath"); } - repr2->setAttribute("style", "fill-rule:evenodd;stroke-width:0.625;stroke-linejoin:round;stroke:#000000;stroke-opacity:1;fill:#000000;fill-opacity:1"); + repr2->setAttribute("style", "stroke:#000000;stroke-opacity:1;fill:#000000;fill-opacity:1"); if(isStart){ repr2->setAttribute("transform", "scale(0.3) translate(-2.3,0)"); } else { @@ -574,17 +583,18 @@ void MeasureTool::setMarker(bool isStart){ } void MeasureTool::toMarkDimension(){ - Geom::Point windowNormal = Geom::unit_vector(Geom::rot90(desktop->d2w(end_p - start_p))); - Geom::Point normal = desktop->w2d(windowNormal); setMarkers(); Geom::PathVector c; Geom::Path p; - p.start(desktop->doc2dt(start_p) + normal * 60); - p.appendNew(desktop->doc2dt(end_p) + normal * 60); + Geom::Ray ray(start_p,end_p); + Geom::Point start = start_p + Geom::Point::polar(ray.angle(), 5); + start = desktop->doc2dt(start + Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -(dimension_offset / 4.0))); + Geom::Point end = end_p + Geom::Point::polar(ray.angle(), -5); + end = desktop->doc2dt(end+ Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -(dimension_offset / 4.0))); + p.start(start); + p.appendNew(end); c.push_back(p); - c *= desktop->doc2dt(); c *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); - c *= Geom::Scale(95.0); SPDesktop *desktop = this->desktop; SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); @@ -592,21 +602,79 @@ void MeasureTool::toMarkDimension(){ Inkscape::XML::Node *repr; repr = xml_doc->createElement("svg:path"); gchar const *str = sp_svg_write_path(c); - gchar const *style_str = "fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-start:url(#Arrow2Sstart);marker-end:url(#Arrow2Send)"; + Geom::Point stroke_width = Geom::Point(1,1) * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + std::stringstream style_str; + style_str.imbue(std::locale::classic()); + style_str << "fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:" << stroke_width[Geom::X] << ";stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-start:url(#Arrow2Sstart);marker-end:url(#Arrow2Send)"; g_assert( str != NULL ); repr->setAttribute("d", str); - repr->setAttribute("style", style_str); - // Attach repr + repr->setAttribute("style", style_str.str().c_str()); SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); Inkscape::GC::release(repr); item->updateRepr(); } + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); + if (!unit_name.compare("")) { + unit_name = "px"; + } + double fontsize = prefs->getInt("/tools/measure/fontsize") * (96/72); + Geom::Point middle = Geom::middle_point(start, end); + double totallengthval = (end_p - start_p).length(); + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); + gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); + setLabelText(totallength_str, middle, fontsize, Geom::deg_to_rad(180) - ray.angle()); // Flush pending updates doc->ensureUpToDate(); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE, + _("Add global meassure line")); //reset(); } +void MeasureTool::setLabelText(const char *value, Geom::Point pos, double fontsize, Geom::Coord angle) +{ + /* Create */ + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Node *rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + + + /* Set style */ + sp_desktop_apply_style_tool(desktop, rtext, "/tools/text", true); + + sp_repr_set_svg_double(rtext, "x", 0); + sp_repr_set_svg_double(rtext, "y", 0); + + /* Create */ + Inkscape::XML::Node *rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); // otherwise, why bother creating the tspan? + std::stringstream text_style; + text_style.imbue(std::locale::classic()); + text_style << "font-style:normal;font-weight:normal;font-size:" << fontsize << "px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"; + rtspan->setAttribute("style", text_style.str().c_str()); + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + /* Create TEXT */ + Inkscape::XML::Node *rstring = xml_doc->createTextNode(value); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + SPItem *text_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + text_item->updateRepr(); + Geom::OptRect bbox = text_item->geometricBounds(); + if (bbox) { + Geom::Coord posX = Geom::middle_point(Geom::Point(bbox->left(), bbox->top()), Geom::Point(bbox->right(), bbox->top()))[Geom::X]; + Geom::Coord posY = Geom::middle_point(Geom::Point(bbox->left(), bbox->top()), Geom::Point(bbox->left(), bbox->bottom()))[Geom::Y]; + text_item->transform *= Geom::Translate(Geom::Point(posX, posY)).inverse(); + pos = pos + Geom::Point::polar(angle + Geom::deg_to_rad(90), -Geom::distance(Geom::Point(bbox->left(), bbox->top()), Geom::Point(bbox->left(), bbox->bottom()))); + } + text_item->transform *= Geom::Rotate(angle); + text_item->transform *= Geom::Translate(pos); + text_item->transform *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + text_item->doWriteTransform(text_item->getRepr(), text_item->transform, NULL, true); +} + void MeasureTool::reset(){ this->knot_start->hide(); this->knot_end->hide(); @@ -622,6 +690,9 @@ void MeasureTool::showCanvasItems(){ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point){ SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !start_point.isFinite() || !end_point.isFinite() || end_point == MAGIC_POINT){ + return; + } start_p = start_point; end_p = end_point; //clear previous temporary canvas items, we'll draw new ones @@ -632,6 +703,7 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool show_in_between = prefs->getBool("/tools/measure/show_in_between"); bool all_layers = prefs->getBool("/tools/measure/all_layers"); + dimension_offset = prefs->getDouble("/tools/measure/offset"); Geom::PathVector lineseg; Geom::Path p; p.start(desktop->dt2doc(start_point)); @@ -660,13 +732,13 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); r->setMode(RUBBERBAND_MODE_TOUCHPATH); if(!show_in_between){ - r->start(desktop,start_point); - r->move(end_point); + r->start(desktop,start_p); + r->move(end_p); items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers, 2); r->stop(); r->setMode(RUBBERBAND_MODE_TOUCHPATH); - r->start(desktop,end_point); - r->move(start_point); + r->start(desktop,end_p); + r->move(start_p); std::vector items_reverse = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers, 2); r->stop(); if(items_reverse.size() == 2 && items_reverse[1] != items[0] && items_reverse[1] != items[1]){ @@ -722,8 +794,7 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point unit_name = "px"; } - double fontsize = prefs->getInt("/tools/measure/fontsize"); - + double fontsize = prefs->getInt("/tools/measure/fontsize") * (96/72); // Normal will be used for lines and text Geom::Point windowNormal = Geom::unit_vector(Geom::rot90(desktop->d2w(end_point - start_point))); Geom::Point normal = desktop->w2d(windowNormal); @@ -748,7 +819,7 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point LabelPlacement placement; placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length(); placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, "px", unit_name); - placement.offset = DIMENSION_OFFSET; + placement.offset = dimension_offset; placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 ); placement.end = placement.start - (normal * placement.offset); @@ -830,7 +901,7 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, - desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60, + desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * (dimension_offset * 2), total_str); sp_canvastext_set_fontsize(canvas_tooltip, fontsize); canvas_tooltip->rgba = 0xffffffff; @@ -893,18 +964,18 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point ControlManager &mgr = ControlManager::getManager(); SPCtrlLine *control_line = 0; control_line = mgr.createControlLine(desktop->getTempGroup(), - desktop->doc2dt(intersections[0]) + normal * 60, - desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 60); + desktop->doc2dt(intersections[0]) + normal * (dimension_offset * 2), + desktop->doc2dt(intersections[intersections.size() - 1]) + normal * (dimension_offset * 2)); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(intersections[0]), - desktop->doc2dt(intersections[0]) + normal * 60); + desktop->doc2dt(intersections[0]) + normal * (dimension_offset * 2)); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(intersections[intersections.size() - 1]), - desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 60); + desktop->doc2dt(intersections[intersections.size() - 1]) + normal * (dimension_offset * 2)); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); } @@ -928,7 +999,7 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point ControlManager &mgr = ControlManager::getManager(); SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(measure_text_pos), - desktop->doc2dt(measure_text_pos) - (normal * DIMENSION_OFFSET), + desktop->doc2dt(measure_text_pos) - (normal * dimension_offset), CTLINE_SECONDARY); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); } diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index 44153a144..0670fb9f7 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -43,6 +43,7 @@ public: virtual void setMarkers(); virtual void setMarker(bool isStart); virtual const std::string& getPrefsPath(); + void setLabelText(const char *value, Geom::Point pos, double fontsize, Geom::Coord angle); void knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state); void knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state); void knotUngrabbedHandler(SPKnot */*knot*/, unsigned int /*state*/); diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index a619418db..9c782b4b6 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -86,6 +86,22 @@ sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl) } } +static void +sp_measure_offset_value_changed(GtkAdjustment *adj, GObject *tbl) +{ + SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); + + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt(Glib::ustring("/tools/measure/offset"), + gtk_adjustment_get_value(adj)); + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } + } +} + static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl) { UnitTracker* tracker = reinterpret_cast(g_object_get_data(tbl, "tracker")); @@ -180,13 +196,12 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G _("The font size to be used in the measurement labels"), "/tools/measure/fontsize", 0.0, GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, - 10, 36, 1.0, 4.0, + 1, 36, 1.0, 4.0, 0, 0, 0, sp_measure_fontsize_value_changed); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); } - // units label { EgeOutputAction* act = ege_output_action_new( "measure_units_label", _("Units:"), _("The units to be used for the measurements"), 0 ); @@ -201,6 +216,20 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(measure_unit_changed), holder ); gtk_action_group_add_action( mainActions, act ); } + + /* Offset */ + { + eact = create_adjustment_action( "MeasureOffsetAction", + _("Offset"), _("Offset:"), + _("The offset size"), + "/tools/measure/offset", 30.0, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + 0.0, 90000.0, 1.0, 4.0, + 0, 0, 0, + sp_measure_offset_value_changed); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + } + // ignore_1st_and_last { InkToggleAction* act = ink_toggle_action_new( "MeasureIgnore1stAndLast", @@ -249,7 +278,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G InkAction* act = ink_action_new( "MeasureMarkDimension", _("Mark Dimension"), _("Mark Dimension"), - INKSCAPE_ICON("draw-geometry-mirror"), + INKSCAPE_ICON("tool-pointer"), secondarySize ); g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_mark_dimension), 0 ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 765e91629..65a0cd9cb 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -339,6 +339,8 @@ static gchar const * ui_descr = " " " " " " + " " + " " " " " " " " -- cgit v1.2.3 From 2653fd7c3a138f91181f7bb64e1fd342c943ee7b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 12 Oct 2015 12:37:15 +0200 Subject: Convert Measure to Item done (bzr r14393.1.17) --- src/ui/tools/measure-tool.cpp | 905 ++++++++++++++++++++++++++-------------- src/ui/tools/measure-tool.h | 21 +- src/widgets/measure-toolbar.cpp | 17 + src/widgets/toolbox.cpp | 1 + 4 files changed, 638 insertions(+), 306 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 585128135..76b8e931e 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -4,6 +4,7 @@ * Authors: * Felipe Correa da Silva Sanches * Jon A. Cruz + * Jabiertxo Arraiza * * Copyright (C) 2011 Authors * @@ -14,42 +15,44 @@ #include #include #include "util/units.h" -#include "macros.h" -#include "rubberband.h" +#include "display/canvas-text.h" #include "display/curve.h" -#include "text-editing.h" -#include "display/sp-ctrlline.h" #include "display/sodipodi-ctrl.h" +#include "display/sp-ctrlline.h" +#include "display/sp-canvas.h" #include "display/sp-canvas-item.h" #include "display/sp-canvas-util.h" -#include "desktop.h" #include "svg/svg.h" -#include "document.h" -#include "document-undo.h" -#include -#include "pixmaps/cursor-measure.xpm" -#include "preferences.h" -#include "inkscape.h" -#include "knot.h" +#include "svg/svg-color.h" #include "ui/tools/measure-tool.h" #include "ui/tools/freehand-base.h" -#include "display/canvas-text.h" -#include "path-chemistry.h" -#include "2geom/line.h" +#include "ui/control-manager.h" +#include <2geom/line.h> #include <2geom/path-intersection.h> #include <2geom/pathvector.h> #include <2geom/crossing.h> #include <2geom/angle.h> #include <2geom/transforms.h> -#include "snap.h" #include "sp-namedview.h" #include "sp-shape.h" #include "sp-text.h" #include "sp-flowtext.h" #include "sp-defs.h" #include "sp-item.h" +#include "macros.h" +#include "rubberband.h" +#include "path-chemistry.h" +#include "desktop.h" +#include "document.h" +#include "document-undo.h" +#include "viewbox.h" +#include "snap.h" +#include "text-editing.h" +#include "pixmaps/cursor-measure.xpm" +#include "preferences.h" +#include "inkscape.h" +#include "knot.h" #include "enums.h" -#include "ui/control-manager.h" #include "knot-enums.h" #include "desktop-style.h" #include "verbs.h" @@ -63,20 +66,21 @@ using Inkscape::DocumentUndo; #define MT_KNOT_COLOR_NORMAL 0xffffff00 #define MT_KNOT_COLOR_MOUSEOVER 0xff000000 + namespace Inkscape { namespace UI { namespace Tools { std::vector measure_tmp_items; -const std::string& MeasureTool::getPrefsPath() { +const std::string& MeasureTool::getPrefsPath() +{ return MeasureTool::prefsPath; } const std::string MeasureTool::prefsPath = "/tools/measure"; -namespace -{ +namespace { gint dimension_offset = 35; @@ -196,8 +200,9 @@ Geom::Point calcAngleDisplayAnchor(SPDesktop *desktop, double angle, double base * @param end the point that ends at the edge of the arc segment. * @param anchor the anchor point for displaying the text label. * @param angle the angle of the arc segment to draw. + * @param measure_rpr the container of the curve if converted to items. */ -void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom::Point const &end, Geom::Point const &anchor, double angle) +void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom::Point const &end, Geom::Point const &anchor, double angle, Inkscape::XML::Node *measure_repr = NULL) { // Given that we have a point on the arc's edge and the angle of the arc, we need to get the two endpoints. @@ -205,7 +210,7 @@ void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom double sideLen = std::abs((end - center).length()); if (sideLen > 0.0) { double factor = std::min(1.0, textLen / sideLen); - + // arc start Geom::Point p1 = end * (Geom::Affine(Geom::Translate(-center)) * Geom::Affine(Geom::Scale(factor)) @@ -235,9 +240,47 @@ void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom SPCtrlCurve *curve = ControlManager::getManager().createControlCurve(desktop->getTempGroup(), p1, p2, p3, p4, CTLINE_SECONDARY); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(SP_CANVAS_ITEM(curve), 0, true)); + if(measure_repr) { + Geom::PathVector c; + Geom::Path p; + p.start(desktop->doc2dt(p1)); + p.appendNew(desktop->doc2dt(p2),desktop->doc2dt(p3),desktop->doc2dt(p4)); + c.push_back(p); + c *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + SPDocument *doc = desktop->getDocument(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + if (c.size() == 1) { + Inkscape::XML::Node *repr; + repr = xml_doc->createElement("svg:path"); + gchar const *str = sp_svg_write_path(c); + Geom::Point strokewidth = Geom::Point(1,1) * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + SPCSSAttr *css = sp_repr_css_attr_new(); + std::stringstream stroke_width; + stroke_width.imbue(std::locale::classic()); + stroke_width << strokewidth[Geom::X] / desktop->current_zoom(); + sp_repr_css_set_property (css, "stroke-width", stroke_width.str().c_str()); + sp_repr_css_set_property (css, "fill", "none"); + guint32 line_color_secondary = 0xff00007f; + gchar c[64]; + sp_svg_write_color (c, sizeof(c), line_color_secondary); + sp_repr_css_set_property (css, "stroke", c); + sp_repr_css_set_property (css, "stroke-linecap", "butt"); + sp_repr_css_set_property (css, "stroke-linejoin", "miter"); + sp_repr_css_set_property (css, "stroke-miterlimit", "4"); + sp_repr_css_set_property (css, "stroke-dasharray", "none"); + sp_repr_css_set_property (css, "stroke-opacity", "0.5"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + repr->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + g_assert( str != NULL ); + repr->setAttribute("d", str); + measure_repr->addChild(repr, NULL); + Inkscape::GC::release(repr); + } + } } } - } // namespace Geom::Point const MAGIC_POINT = Geom::Point(-0.0003432532004303,-0.006745034004304); @@ -249,7 +292,7 @@ MeasureTool::MeasureTool() , grabbed(NULL) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - // create the knot + // create the knots this->knot_start = new SPKnot(desktop, N_("Measure start")); this->knot_start->setMode(SP_KNOT_MODE_XOR); this->knot_start->setFill(MT_KNOT_COLOR_NORMAL, MT_KNOT_COLOR_MOUSEOVER, MT_KNOT_COLOR_MOUSEOVER); @@ -262,12 +305,13 @@ MeasureTool::MeasureTool() this->knot_end->setStroke(0x0000007f, 0x0000007f, 0x0000007f); this->knot_end->setShape(SP_KNOT_SHAPE_CIRCLE); this->knot_end->updateCtrl(); - if(end_p != MAGIC_POINT){ + Geom::Rect display_area = desktop->get_display_area () ; + if(display_area.interiorContains(start_p) && display_area.interiorContains(end_p) && end_p != MAGIC_POINT) { this->knot_start->moveto(start_p); this->knot_start->show(); this->knot_end->moveto(end_p); this->knot_end->show(); - this->showCanvasItems(); + showCanvasItems(); } this->_knot_start_moved_connection = this->knot_start->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotStartMovedHandler)); this->_knot_start_ungrabbed_connection = this->knot_start->ungrabbed_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotUngrabbedHandler)); @@ -276,7 +320,8 @@ MeasureTool::MeasureTool() } -MeasureTool::~MeasureTool() { +MeasureTool::~MeasureTool() +{ this->_knot_start_moved_connection.disconnect(); this->_knot_start_ungrabbed_connection.disconnect(); this->_knot_end_moved_connection.disconnect(); @@ -291,7 +336,8 @@ MeasureTool::~MeasureTool() { measure_tmp_items.clear(); } -void MeasureTool::reverseKnots(){ +void MeasureTool::reverseKnots() +{ Geom::Point start = start_p; Geom::Point end = end_p; this->knot_start->moveto(end); @@ -301,45 +347,59 @@ void MeasureTool::reverseKnots(){ this->showCanvasItems(end, start); } -void MeasureTool::knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state){ - if (!(state & GDK_SHIFT_MASK)) { +void MeasureTool::knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state) +{ + Geom::Point point = this->knot_start->position(); + if (state & GDK_CONTROL_MASK) { + spdc_endpoint_snap_rotation(this, point, end_p, state); + } else if (!(state & GDK_SHIFT_MASK)) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - Inkscape::SnapCandidatePoint scp(this->knot_start->position(), Inkscape::SNAPSOURCE_OTHER_HANDLE); + Inkscape::SnapCandidatePoint scp(point, Inkscape::SNAPSOURCE_OTHER_HANDLE); scp.addOrigin(this->knot_end->position()); Inkscape::SnappedPoint sp = m.freeSnap(scp); - if(start_p != sp.getPoint()){ - start_p = sp.getPoint(); - this->knot_start->moveto(start_p); - } + point = sp.getPoint(); m.unSetup(); } - showCanvasItems(start_p, this->knot_end->position()); + if(start_p != point) { + start_p = point; + this->knot_start->moveto(start_p); + } + showCanvasItems(start_p, end_p); } -void MeasureTool::knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state){ - if (!(state & GDK_SHIFT_MASK)) { +void MeasureTool::knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state) +{ + Geom::Point point = this->knot_end->position(); + if (state & GDK_CONTROL_MASK) { + spdc_endpoint_snap_rotation(this, point, start_p, state); + } else if (!(state & GDK_SHIFT_MASK)) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - Inkscape::SnapCandidatePoint scp(this->knot_end->position(), Inkscape::SNAPSOURCE_OTHER_HANDLE); + Inkscape::SnapCandidatePoint scp(point, Inkscape::SNAPSOURCE_OTHER_HANDLE); scp.addOrigin(this->knot_start->position()); Inkscape::SnappedPoint sp = m.freeSnap(scp); - if(end_p != sp.getPoint()){ - end_p = sp.getPoint(); - this->knot_end->moveto(end_p); - } + point = sp.getPoint(); m.unSetup(); } - showCanvasItems(this->knot_start->position(), end_p); + if(end_p != point) { + end_p = point; + this->knot_end->moveto(end_p); + } + showCanvasItems(start_p, end_p); } -void MeasureTool::knotUngrabbedHandler(SPKnot */*knot*/, unsigned int state){ - showCanvasItems(this->knot_start->position(), this->knot_end->position()); +void MeasureTool::knotUngrabbedHandler(SPKnot */*knot*/, unsigned int state) +{ + this->knot_start->moveto(start_p); + this->knot_end->moveto(end_p); + showCanvasItems(start_p, end_p); } -void MeasureTool::finish() { +void MeasureTool::finish() +{ this->enableGrDrag(false); if (this->grabbed) { @@ -386,9 +446,9 @@ static void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom: double eps = 0.0001; SPDocument* doc = desktop->getDocument(); if (((*m).ta > eps && - item == doc->getItemAtPoint(desktop->dkey, lineseg[0].pointAt((*m).ta - eps), false, NULL)) || - ((*m).ta + eps < 1 && - item == doc->getItemAtPoint(desktop->dkey, lineseg[0].pointAt((*m).ta + eps), false, NULL)) ) { + item == doc->getItemAtPoint(desktop->dkey, lineseg[0].pointAt((*m).ta - eps), false, NULL)) || + ((*m).ta + eps < 1 && + item == doc->getItemAtPoint(desktop->dkey, lineseg[0].pointAt((*m).ta + eps), false, NULL)) ) { intersections.push_back((*m).ta); } #else @@ -398,106 +458,83 @@ static void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom: } } -bool MeasureTool::root_handler(GdkEvent* event) { +bool MeasureTool::root_handler(GdkEvent* event) +{ gint ret = FALSE; switch (event->type) { - case GDK_BUTTON_PRESS: { - this->knot_start->hide(); - this->knot_end->hide(); - Geom::Point const button_w(event->button.x, event->button.y); - explicitBase = boost::none; - last_end = boost::none; - start_point = desktop->w2d(button_w); - - if (event->button.button == 1 && !this->space_panning) { - // save drag origin - start_point = desktop->w2d(Geom::Point(event->button.x, event->button.y)); - within_tolerance = true; - - ret = TRUE; - } + case GDK_BUTTON_PRESS: { + this->knot_start->hide(); + this->knot_end->hide(); + Geom::Point const button_w(event->button.x, event->button.y); + explicitBase = boost::none; + last_end = boost::none; + start_point = desktop->w2d(button_w); + + if (event->button.button == 1 && !this->space_panning) { + // save drag origin + start_point = desktop->w2d(Geom::Point(event->button.x, event->button.y)); + within_tolerance = true; + + ret = TRUE; + } - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); - m.freeSnapReturnByRef(start_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); - m.unSetup(); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + m.freeSnapReturnByRef(start_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); + m.unSetup(); - sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), - GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, - NULL, event->button.time); - this->grabbed = SP_CANVAS_ITEM(desktop->acetate); - break; - } - case GDK_KEY_PRESS: { - if ((event->key.keyval == GDK_KEY_Shift_L) || (event->key.keyval == GDK_KEY_Shift_R)) { - if (last_end) { - explicitBase = last_end; - } + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), + GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, + NULL, event->button.time); + this->grabbed = SP_CANVAS_ITEM(desktop->acetate); + break; + } + case GDK_KEY_PRESS: { + if ((event->key.keyval == GDK_KEY_Shift_L) || (event->key.keyval == GDK_KEY_Shift_R)) { + if (last_end) { + explicitBase = last_end; } - break; } - case GDK_MOTION_NOTIFY: { - if (!(event->motion.state & GDK_BUTTON1_MASK)){ - if(!(event->motion.state & GDK_SHIFT_MASK)) { - Geom::Point const motion_w(event->motion.x, event->motion.y); - Geom::Point const motion_dt(desktop->w2d(motion_w)); + break; + } + case GDK_MOTION_NOTIFY: { + if (!(event->motion.state & GDK_BUTTON1_MASK)) { + if(!(event->motion.state & GDK_SHIFT_MASK)) { + Geom::Point const motion_w(event->motion.x, event->motion.y); + Geom::Point const motion_dt(desktop->w2d(motion_w)); - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); - Inkscape::SnapCandidatePoint scp(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); + Inkscape::SnapCandidatePoint scp(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_point); - m.preSnap(scp); - m.unSetup(); - } - } else { - ret = TRUE; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); - Geom::Point const motion_w(event->motion.x, event->motion.y); - if ( within_tolerance){ - if ( Geom::LInfty( motion_w - start_point ) < tolerance) { - return FALSE; // Do not drag if we're within tolerance from origin. - } - } - // Once the user has moved farther than tolerance from the original location - // (indicating they intend to move the object, not click), then always process the - // motion notify coordinates as given (no snapping back to origin) - within_tolerance = false; - if(event->motion.time == 0 || !last_end || Geom::LInfty( motion_w - *last_end ) > (tolerance/2)){ - Geom::Point const motion_w(event->motion.x, event->motion.y); - Geom::Point const motion_dt(desktop->w2d(motion_w)); - Geom::Point end_point = motion_dt; - - if (event->motion.state & GDK_CONTROL_MASK) { - spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); - } else if (!(event->motion.state & GDK_SHIFT_MASK)) { - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); - Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); - Inkscape::SnappedPoint sp = m.freeSnap(scp); - end_point = sp.getPoint(); - m.unSetup(); - } - showCanvasItems(start_point, end_point); - last_end = motion_w ; + m.preSnap(scp); + m.unSetup(); + } + } else { + ret = TRUE; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + Geom::Point const motion_w(event->motion.x, event->motion.y); + if ( within_tolerance) { + if ( Geom::LInfty( motion_w - start_point ) < tolerance) { + return FALSE; // Do not drag if we're within tolerance from origin. } - gobble_motion_events(GDK_BUTTON1_MASK); } - break; - } - case GDK_BUTTON_RELEASE: { - this->knot_start->moveto(start_point); - this->knot_start->show(); - Geom::Point end_point = end_p; - if(last_end){ - end_point = desktop->w2d(*last_end); - if (event->button.state & GDK_CONTROL_MASK) { + // Once the user has moved farther than tolerance from the original location + // (indicating they intend to move the object, not click), then always process the + // motion notify coordinates as given (no snapping back to origin) + within_tolerance = false; + if(event->motion.time == 0 || !last_end || Geom::LInfty( motion_w - *last_end ) > (tolerance/4.0)) { + Geom::Point const motion_w(event->motion.x, event->motion.y); + Geom::Point const motion_dt(desktop->w2d(motion_w)); + Geom::Point end_point = motion_dt; + + if (event->motion.state & GDK_CONTROL_MASK) { spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); - } else if (!(event->button.state & GDK_SHIFT_MASK)) { + } else if (!(event->motion.state & GDK_SHIFT_MASK)) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); @@ -506,153 +543,317 @@ bool MeasureTool::root_handler(GdkEvent* event) { end_point = sp.getPoint(); m.unSetup(); } + showCanvasItems(start_point, end_point); + last_end = motion_w ; } - this->knot_end->moveto(end_point); - this->knot_end->show(); - showCanvasItems(start_point, end_point); - if (this->grabbed) { - sp_canvas_item_ungrab(this->grabbed, event->button.time); - this->grabbed = NULL; + gobble_motion_events(GDK_BUTTON1_MASK); + } + break; + } + case GDK_BUTTON_RELEASE: { + this->knot_start->moveto(start_point); + this->knot_start->show(); + Geom::Point end_point = end_p; + if(last_end) { + end_point = desktop->w2d(*last_end); + if (event->button.state & GDK_CONTROL_MASK) { + spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); + } else if (!(event->button.state & GDK_SHIFT_MASK)) { + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_point); + Inkscape::SnappedPoint sp = m.freeSnap(scp); + end_point = sp.getPoint(); + m.unSetup(); } - break; } - default: - break; + this->knot_end->moveto(end_point); + this->knot_end->show(); + showCanvasItems(start_point, end_point); + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; + } + break; + } + default: + break; } if (!ret) { ret = ToolBase::root_handler(event); } - + return ret; } -void MeasureTool::setMarkers(){ - SPDesktop *desktop = this->desktop; +void MeasureTool::setMarkers() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; SPDocument *doc = desktop->getDocument(); SPObject *arrowStart = doc->getObjectById("Arrow2Sstart"); SPObject *arrowEnd = doc->getObjectById("Arrow2Send"); if (!arrowStart) { setMarker(true); } - if(!arrowEnd){ + if(!arrowEnd) { setMarker(false); } } -void MeasureTool::setMarker(bool isStart){ - SPDesktop *desktop = this->desktop; +void MeasureTool::setMarker(bool isStart) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; SPDocument *doc = desktop->getDocument(); SPDefs *defs = doc->getDefs(); - Inkscape::XML::Node *repr; + Inkscape::XML::Node *rmarker; Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - repr = xml_doc->createElement("svg:marker"); - if(isStart){ - repr->setAttribute("id", "Arrow2Sstart"); + rmarker = xml_doc->createElement("svg:marker"); + if(isStart) { + rmarker->setAttribute("id", "Arrow2Sstart"); } else { - repr->setAttribute("id", "Arrow2Send"); + rmarker->setAttribute("id", "Arrow2Send"); } - repr->setAttribute("inkscape:isstock", "true"); - if(isStart){ - repr->setAttribute("inkscape:stockid", "Arrow2Sstart"); + rmarker->setAttribute("inkscape:isstock", "true"); + if(isStart) { + rmarker->setAttribute("inkscape:stockid", "Arrow2Sstart"); } else { - repr->setAttribute("inkscape:stockid", "Arrow2Send"); + rmarker->setAttribute("inkscape:stockid", "Arrow2Send"); } - repr->setAttribute("orient", "auto"); - repr->setAttribute("refX", "0.0"); - repr->setAttribute("refY", "0.0"); - repr->setAttribute("style", "overflow:visible;"); - SPItem *item = SP_ITEM(defs->appendChildRepr(repr)); - Inkscape::GC::release(repr); - item->updateRepr(); - Inkscape::XML::Node *repr2; - repr2 = xml_doc->createElement("svg:path"); - repr2->setAttribute("d", "M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.9730900,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z"); - if(isStart){ - repr2->setAttribute("id", "Arrow2SstartPath"); + rmarker->setAttribute("orient", "auto"); + rmarker->setAttribute("refX", "0.0"); + rmarker->setAttribute("refY", "0.0"); + rmarker->setAttribute("style", "overflow:visible;"); + SPItem *marker = SP_ITEM(defs->appendChildRepr(rmarker)); + Inkscape::GC::release(rmarker); + marker->updateRepr(); + Inkscape::XML::Node *rpath; + rpath = xml_doc->createElement("svg:path"); + rpath->setAttribute("d", "M 8.72,4.03 L -2.21,0.02 L 8.72,-4.00 C 6.97,-1.63 6.98,1.62 8.72,4.03 z"); + if(isStart) { + rpath->setAttribute("id", "Arrow2SstartPath"); } else { - repr2->setAttribute("id", "Arrow2SendPath"); + rpath->setAttribute("id", "Arrow2SendPath"); } - repr2->setAttribute("style", "stroke:#000000;stroke-opacity:1;fill:#000000;fill-opacity:1"); - if(isStart){ - repr2->setAttribute("transform", "scale(0.3) translate(-2.3,0)"); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property (css, "stroke", "none"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + rpath->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if(isStart) { + rpath->setAttribute("transform", "scale(0.3) translate(-2.3,0)"); } else { - repr2->setAttribute("transform", "scale(0.3) rotate(180) translate(-2.3,0)"); + rpath->setAttribute("transform", "scale(0.3) rotate(180) translate(-2.3,0)"); } - SPItem *item2 = SP_ITEM(item->appendChildRepr(repr2)); - Inkscape::GC::release(repr2); - item2->updateRepr(); + SPItem *path = SP_ITEM(marker->appendChildRepr(rpath)); + Inkscape::GC::release(rpath); + path->updateRepr(); +} + +void MeasureTool::toItem() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPDocument *doc = desktop->getDocument(); + Geom::Ray ray(start_p,end_p); + guint32 line_color_primary = 0x0000ff7f; + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Node *rgroup = xml_doc->createElement("svg:g"); + showCanvasItems(start_p, end_p, true, rgroup); + setLine(start_p,end_p, false, &line_color_primary, rgroup); + SPItem *measure_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(rgroup)); + Inkscape::GC::release(rgroup); + measure_item->updateRepr(); + doc->ensureUpToDate(); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Convert measure to items")); + reset(); } -void MeasureTool::toMarkDimension(){ +void MeasureTool::toMarkDimension() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPDocument *doc = desktop->getDocument(); setMarkers(); - Geom::PathVector c; - Geom::Path p; Geom::Ray ray(start_p,end_p); Geom::Point start = start_p + Geom::Point::polar(ray.angle(), 5); - start = desktop->doc2dt(start + Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -(dimension_offset / 4.0))); + start = start + Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -(dimension_offset / 4.0)); Geom::Point end = end_p + Geom::Point::polar(ray.angle(), -5); - end = desktop->doc2dt(end+ Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -(dimension_offset / 4.0))); - p.start(start); - p.appendNew(end); + end = end+ Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -(dimension_offset / 4.0)); + guint32 color = 0x000000ff; + setLine(start, end, true, &color); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); + if (!unit_name.compare("")) { + unit_name = "px"; + } + double fontsize = prefs->getInt("/tools/measure/fontsize") * (96/72); + Geom::Point middle = Geom::middle_point(start, end); + double totallengthval = (end_p - start_p).length(); + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); + gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); + setLabelText(totallength_str, middle, fontsize, Geom::deg_to_rad(180) - ray.angle()); + doc->ensureUpToDate(); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add global meassure line")); +} + +void MeasureTool::setLine(Geom::Point start_point,Geom::Point end_point, bool markers, guint32 *color, Inkscape::XML::Node *measure_repr) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !start_point.isFinite() || !end_point.isFinite()) { + return; + } + Geom::PathVector c; + Geom::Path p; + p.start(desktop->doc2dt(start_point)); + p.appendNew(desktop->doc2dt(end_point)); c.push_back(p); c *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); - SPDesktop *desktop = this->desktop; SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); if (c.size() == 1) { Inkscape::XML::Node *repr; repr = xml_doc->createElement("svg:path"); gchar const *str = sp_svg_write_path(c); - Geom::Point stroke_width = Geom::Point(1,1) * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); - std::stringstream style_str; - style_str.imbue(std::locale::classic()); - style_str << "fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:" << stroke_width[Geom::X] << ";stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-start:url(#Arrow2Sstart);marker-end:url(#Arrow2Send)"; + Geom::Point strokewidth = Geom::Point(1,1) * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + SPCSSAttr *css = sp_repr_css_attr_new(); + std::stringstream stroke_width; + stroke_width.imbue(std::locale::classic()); + if(measure_repr) { + stroke_width << strokewidth[Geom::X] / desktop->current_zoom(); + } else { + stroke_width << strokewidth[Geom::X]; + } + sp_repr_css_set_property (css, "stroke-width", stroke_width.str().c_str()); + sp_repr_css_set_property (css, "fill", "none"); + if(color) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), *color); + sp_repr_css_set_property (css, "stroke", c); + } else { + sp_repr_css_set_property (css, "stroke", "#000000"); + } + sp_repr_css_set_property (css, "stroke-linecap", "butt"); + sp_repr_css_set_property (css, "stroke-linejoin", "miter"); + sp_repr_css_set_property (css, "stroke-miterlimit", "4"); + sp_repr_css_set_property (css, "stroke-dasharray", "none"); + if(measure_repr) { + sp_repr_css_set_property (css, "stroke-opacity", "0.5"); + } else { + sp_repr_css_set_property (css, "stroke-opacity", "1"); + } + if(markers) { + sp_repr_css_set_property (css, "marker-start", "url(#Arrow2Sstart)"); + sp_repr_css_set_property (css, "marker-end", "url(#Arrow2Send)"); + } + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + repr->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); g_assert( str != NULL ); repr->setAttribute("d", str); - repr->setAttribute("style", style_str.str().c_str()); - SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); - Inkscape::GC::release(repr); - item->updateRepr(); + if(measure_repr) { + measure_repr->addChild(repr, NULL); + Inkscape::GC::release(repr); + } else { + SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); + Inkscape::GC::release(repr); + item->updateRepr(); + } } +} - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); - if (!unit_name.compare("")) { - unit_name = "px"; +void MeasureTool::setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !origin.isFinite()) { + return; + } + char const * svgd; + svgd = "m -3.55,-3.55 7.11,7.11 m 0,-7.11 -7.11,7.11"; + Geom::PathVector c = sp_svg_read_pathv(svgd); + Geom::Scale scale = Geom::Scale(desktop->current_zoom()).inverse(); + c *= scale; + Geom::Point strokewidth = (Geom::Point(1,1) * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse())/ desktop->current_zoom(); + c *= Geom::Translate(Geom::Point(strokewidth/2.0) - (scale.vector() * 0.5)); + c *= Geom::Translate(desktop->doc2dt(origin)); + c *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + SPDocument *doc = desktop->getDocument(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + if (c.size() == 2) { + Inkscape::XML::Node *repr; + repr = xml_doc->createElement("svg:path"); + gchar const *str = sp_svg_write_path(c); + SPCSSAttr *css = sp_repr_css_attr_new(); + std::stringstream stroke_width; + stroke_width.imbue(std::locale::classic()); + stroke_width << strokewidth[Geom::X]; + sp_repr_css_set_property (css, "stroke-width", stroke_width.str().c_str()); + sp_repr_css_set_property (css, "fill", "none"); + guint32 line_color_secondary = 0xff0000ff; + gchar c[64]; + sp_svg_write_color (c, sizeof(c), line_color_secondary); + sp_repr_css_set_property (css, "stroke", c); + sp_repr_css_set_property (css, "stroke-linecap", "butt"); + sp_repr_css_set_property (css, "stroke-linejoin", "miter"); + sp_repr_css_set_property (css, "stroke-miterlimit", "4"); + sp_repr_css_set_property (css, "stroke-dasharray", "none"); + sp_repr_css_set_property (css, "stroke-opacity", "0.5"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + repr->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + g_assert( str != NULL ); + repr->setAttribute("d", str); + measure_repr->addChild(repr, NULL); + Inkscape::GC::release(repr); } - double fontsize = prefs->getInt("/tools/measure/fontsize") * (96/72); - Geom::Point middle = Geom::middle_point(start, end); - double totallengthval = (end_p - start_p).length(); - totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); - gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); - setLabelText(totallength_str, middle, fontsize, Geom::deg_to_rad(180) - ray.angle()); - // Flush pending updates - doc->ensureUpToDate(); - DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE, - _("Add global meassure line")); - //reset(); } -void MeasureTool::setLabelText(const char *value, Geom::Point pos, double fontsize, Geom::Coord angle) +void MeasureTool::setLabelText(const char *value, Geom::Point pos, double fontsize, Geom::Coord angle, guint32 *background, Inkscape::XML::Node *measure_repr, CanvasTextAnchorPositionEnum text_anchor) { - /* Create */ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + /* Create */ + pos = desktop->doc2dt(pos); Inkscape::XML::Node *rtext = xml_doc->createElement("svg:text"); rtext->setAttribute("xml:space", "preserve"); /* Set style */ sp_desktop_apply_style_tool(desktop, rtext, "/tools/text", true); - - sp_repr_set_svg_double(rtext, "x", 0); - sp_repr_set_svg_double(rtext, "y", 0); + if(measure_repr) { + sp_repr_set_svg_double(rtext, "x", 2); + sp_repr_set_svg_double(rtext, "y", 2); + } else { + sp_repr_set_svg_double(rtext, "x", 0); + sp_repr_set_svg_double(rtext, "y", 0); + } /* Create */ Inkscape::XML::Node *rtspan = xml_doc->createElement("svg:tspan"); rtspan->setAttribute("sodipodi:role", "line"); // otherwise, why bother creating the tspan? - std::stringstream text_style; - text_style.imbue(std::locale::classic()); - text_style << "font-style:normal;font-weight:normal;font-size:" << fontsize << "px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"; - rtspan->setAttribute("style", text_style.str().c_str()); + SPCSSAttr *css = sp_repr_css_attr_new(); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize ; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0px"); + sp_repr_css_set_property (css, "word-spacing", "0px"); + if(measure_repr) { + sp_repr_css_set_property (css, "fill", "#FFFFFF"); + } else { + sp_repr_css_set_property (css, "fill", "#000000"); + } + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); rtext->addChild(rtspan, NULL); Inkscape::GC::release(rtspan); /* Create TEXT */ @@ -663,19 +864,63 @@ void MeasureTool::setLabelText(const char *value, Geom::Point pos, double fontsi Inkscape::GC::release(rtext); text_item->updateRepr(); Geom::OptRect bbox = text_item->geometricBounds(); - if (bbox) { - Geom::Coord posX = Geom::middle_point(Geom::Point(bbox->left(), bbox->top()), Geom::Point(bbox->right(), bbox->top()))[Geom::X]; - Geom::Coord posY = Geom::middle_point(Geom::Point(bbox->left(), bbox->top()), Geom::Point(bbox->left(), bbox->bottom()))[Geom::Y]; - text_item->transform *= Geom::Translate(Geom::Point(posX, posY)).inverse(); - pos = pos + Geom::Point::polar(angle + Geom::deg_to_rad(90), -Geom::distance(Geom::Point(bbox->left(), bbox->top()), Geom::Point(bbox->left(), bbox->bottom()))); + if (!measure_repr && bbox) { + Geom::Point center = bbox->midpoint(); + text_item->transform *= Geom::Translate(center).inverse(); + pos = pos + Geom::Point::polar(angle+ Geom::deg_to_rad(90), -bbox->height()); + } + if(measure_repr) { + /* Create */ + Inkscape::XML::Node *rgroup = xml_doc->createElement("svg:g"); + /* Create */ + Inkscape::XML::Node *rrect = xml_doc->createElement("svg:rect"); + SPCSSAttr *css = sp_repr_css_attr_new (); + gchar c[64]; + sp_svg_write_color (c, sizeof(c), *background); + sp_repr_css_set_property (css, "fill", c); + sp_repr_css_set_property (css, "fill-opacity", "0.5"); + sp_repr_css_set_property (css, "stroke-width", "0"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + rrect->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + sp_repr_set_svg_double(rgroup, "x", 0); + sp_repr_set_svg_double(rgroup, "y", 0); + sp_repr_set_svg_double(rrect, "x", 0); + sp_repr_set_svg_double(rrect, "y", -bbox->height()); + sp_repr_set_svg_double(rrect, "width", (bbox->width()) + 6); + sp_repr_set_svg_double(rrect, "height", (bbox->height()) + 6); + Inkscape::XML::Node *rtextitem = text_item->getRepr(); + text_item->deleteObject(); + rgroup->addChild(rtextitem, NULL); + Inkscape::GC::release(rtextitem); + rgroup->addChild(rrect, NULL); + Inkscape::GC::release(rrect); + SPItem *text_item_box = SP_ITEM(desktop->currentLayer()->appendChildRepr(rgroup)); + Geom::Scale scale = Geom::Scale(desktop->current_zoom()).inverse(); + if(bbox && text_anchor == TEXT_ANCHOR_CENTER) { + text_item_box->transform *= Geom::Translate(bbox->midpoint() - Geom::Point(1.0,1.0)).inverse(); + } + text_item_box->transform *= scale; + text_item_box->transform *= Geom::Translate(Geom::Point() - (scale.vector() * 0.5)); + text_item_box->transform *= Geom::Translate(pos); + text_item_box->transform *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + text_item_box->updateRepr(); + text_item_box->doWriteTransform(text_item_box->getRepr(), text_item_box->transform, NULL, true); + Inkscape::XML::Node *rlabel = text_item_box->getRepr(); + text_item_box->deleteObject(); + measure_repr->addChild(rlabel, NULL); + Inkscape::GC::release(rlabel); + } else { + text_item->transform *= Geom::Rotate(angle); + text_item->transform *= Geom::Translate(pos); + text_item->transform *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + text_item->doWriteTransform(text_item->getRepr(), text_item->transform, NULL, true); } - text_item->transform *= Geom::Rotate(angle); - text_item->transform *= Geom::Translate(pos); - text_item->transform *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); - text_item->doWriteTransform(text_item->getRepr(), text_item->transform, NULL, true); } -void MeasureTool::reset(){ +void MeasureTool::reset() +{ this->knot_start->hide(); this->knot_end->hide(); for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { @@ -684,15 +929,19 @@ void MeasureTool::reset(){ measure_tmp_items.clear(); } -void MeasureTool::showCanvasItems(){ +void MeasureTool::showCanvasItems() +{ showCanvasItems(start_p, end_p); } -void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point){ +void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point, bool to_item, Inkscape::XML::Node *measure_repr) +{ SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if(!desktop || !start_point.isFinite() || !end_point.isFinite() || end_point == MAGIC_POINT){ + if(!desktop || !start_point.isFinite() || !end_point.isFinite() || end_point == MAGIC_POINT) { return; } + guint32 line_color_primary = 0x0000ff7f; + guint32 line_color_secondary = 0xff00007f; start_p = start_point; end_p = end_point; //clear previous temporary canvas items, we'll draw new ones @@ -731,7 +980,7 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point std::vector items; Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); r->setMode(RUBBERBAND_MODE_TOUCHPATH); - if(!show_in_between){ + if(!show_in_between) { r->start(desktop,start_p); r->move(end_p); items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers, 2); @@ -741,10 +990,10 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point r->move(start_p); std::vector items_reverse = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers, 2); r->stop(); - if(items_reverse.size() == 2 && items_reverse[1] != items[0] && items_reverse[1] != items[1]){ + if(items_reverse.size() == 2 && items_reverse[1] != items[0] && items_reverse[1] != items[1]) { items.push_back(items_reverse[1]); } - if(items_reverse.size() >= 1 && items_reverse[0] != items[1]){ + if(items_reverse.size() >= 1 && items_reverse[0] != items[1]) { items.push_back(items_reverse[0]); } } else { @@ -754,10 +1003,10 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point r->stop(); } std::vector intersection_times; - for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i=items.begin(); i!=items.end(); i++) { SPItem *item = *i; if (SP_IS_SHAPE(item)) { - calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times); + calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times); } else { if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); @@ -802,11 +1051,11 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point std::vector intersections; std::sort(intersection_times.begin(), intersection_times.end()); for (std::vector::iterator iter_t = intersection_times.begin(); iter_t != intersection_times.end(); iter_t++) { - if(show_in_between){ + if(show_in_between) { intersections.push_back(lineseg[0].pointAt(*iter_t)); } } - if(!show_in_between && intersection_times.size() > 1){ + if(!show_in_between && intersection_times.size() > 1) { intersections.push_back(lineseg[0].pointAt(intersection_times[0])); intersections.push_back(lineseg[0].pointAt(intersection_times[intersection_times.size()-1])); } @@ -828,47 +1077,52 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point // Adjust positions repositionOverlappingLabels(placements, desktop, windowNormal, fontsize); - for (std::vector::iterator it = placements.begin(); it != placements.end(); ++it) - { + for (std::vector::iterator it = placements.begin(); it != placements.end(); ++it) { LabelPlacement &place = *it; // TODO cleanup memory, Glib::ustring, etc.: gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - place.end, - measure_str); + desktop, + place.end, + measure_str); sp_canvastext_set_fontsize(canvas_tooltip, fontsize); canvas_tooltip->rgba = 0xffffffff; canvas_tooltip->rgba_background = 0x0000007f; canvas_tooltip->outline = false; canvas_tooltip->background = true; canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); + if(to_item) { + guint32 background = canvas_tooltip->rgba_background; + setLabelText(measure_str, place.end, fontsize, 0, &background, measure_repr); + } g_free(measure_str); } Geom::Point angleDisplayPt = calcAngleDisplayAnchor(desktop, angle, baseAngle, - start_point, end_point, - fontsize); + start_point, end_point, + fontsize); { // TODO cleanup memory, Glib::ustring, etc.: gchar *angle_str = g_strdup_printf("%.2f °", angle * 180/M_PI); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - angleDisplayPt, - angle_str); + desktop, + angleDisplayPt, + angle_str); sp_canvastext_set_fontsize(canvas_tooltip, fontsize); canvas_tooltip->rgba = 0xffffffff; canvas_tooltip->rgba_background = 0x337f337f; canvas_tooltip->outline = false; canvas_tooltip->background = true; canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); + if(to_item) { + guint32 background = canvas_tooltip->rgba_background; + setLabelText(angle_str, angleDisplayPt, fontsize, 0, &background, measure_repr); + } g_free(angle_str); } @@ -879,17 +1133,20 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point // TODO cleanup memory, Glib::ustring, etc.: gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), - totallength_str); + desktop, + end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), + totallength_str); sp_canvastext_set_fontsize(canvas_tooltip, fontsize); canvas_tooltip->rgba = 0xffffffff; canvas_tooltip->rgba_background = 0x3333337f; canvas_tooltip->outline = false; canvas_tooltip->background = true; canvas_tooltip->anchor_position = TEXT_ANCHOR_LEFT; - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); + if(to_item) { + guint32 background = canvas_tooltip->rgba_background; + setLabelText(totallength_str, end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), fontsize, 0, &background, measure_repr, TEXT_ANCHOR_LEFT); + } g_free(totallength_str); } @@ -900,44 +1157,68 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point // TODO cleanup memory, Glib::ustring, etc.: gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * (dimension_offset * 2), - total_str); + desktop, + desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * (dimension_offset * 2), + total_str); sp_canvastext_set_fontsize(canvas_tooltip, fontsize); canvas_tooltip->rgba = 0xffffffff; canvas_tooltip->rgba_background = 0x33337f7f; canvas_tooltip->outline = false; canvas_tooltip->background = true; canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); + if(to_item) { + guint32 background = canvas_tooltip->rgba_background; + setLabelText(total_str, desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * (dimension_offset * 2), fontsize, 0, &background, measure_repr); + } g_free(total_str); } + // Initial point + { + SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), + SP_TYPE_CTRL, + "anchor", SP_ANCHOR_CENTER, + "size", 8.0, + "stroked", TRUE, + "stroke_color", 0xff0000ff, + "mode", SP_KNOT_MODE_XOR, + "shape", SP_KNOT_SHAPE_CROSS, + NULL ); + + SP_CTRL(canvasitem)->moveto(start_point); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvasitem, 0)); + if(to_item) { + setPoint(start_point, measure_repr); + } + } + // Now that text has been added, we can add lines and controls so that they go underneath for (size_t idx = 0; idx < intersections.size(); ++idx) { // Display the intersection indicator (i.e. the cross) SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), - SP_TYPE_CTRL, - "anchor", SP_ANCHOR_CENTER, - "size", 8.0, - "stroked", TRUE, - "stroke_color", 0xff0000ff, - "mode", SP_KNOT_MODE_XOR, - "shape", SP_KNOT_SHAPE_CROSS, - NULL ); + SP_TYPE_CTRL, + "anchor", SP_ANCHOR_CENTER, + "size", 8.0, + "stroked", TRUE, + "stroke_color", 0xff0000ff, + "mode", SP_KNOT_MODE_XOR, + "shape", SP_KNOT_SHAPE_CROSS, + NULL ); SP_CTRL(canvasitem)->moveto(desktop->doc2dt(intersections[idx])); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvasitem, 0)); + if(to_item) { + setPoint(desktop->doc2dt(intersections[idx]), measure_repr); + } } - // Since adding goes to the bottom, do all lines last. // draw main control line { SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), - start_point, - end_point); + start_point, + end_point); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); if ((end_point[Geom::X] != start_point[Geom::X]) && (end_point[Geom::Y] != start_point[Geom::Y])) { @@ -951,12 +1232,18 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point } SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), - start_point, - anchorEnd, - CTLINE_SECONDARY); + start_point, + anchorEnd, + CTLINE_SECONDARY); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - - createAngleDisplayCurve(desktop, start_point, end_point, angleDisplayPt, angle); + if(to_item) { + setLine(start_point, + anchorEnd, + false, + &line_color_secondary, + measure_repr); + } + createAngleDisplayCurve(desktop, start_point, end_point, angleDisplayPt, angle, measure_repr); } } @@ -967,29 +1254,50 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point desktop->doc2dt(intersections[0]) + normal * (dimension_offset * 2), desktop->doc2dt(intersections[intersections.size() - 1]) + normal * (dimension_offset * 2)); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - + if(to_item) { + setLine(desktop->doc2dt(intersections[0]) + normal * (dimension_offset * 2), + desktop->doc2dt(intersections[intersections.size() - 1]) + normal * (dimension_offset * 2), + false, + &line_color_primary, + measure_repr); + } control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(intersections[0]), desktop->doc2dt(intersections[0]) + normal * (dimension_offset * 2)); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - + if(to_item) { + setLine(desktop->doc2dt(intersections[0]), + desktop->doc2dt(intersections[0]) + normal * (dimension_offset * 2), + false, + &line_color_primary, + measure_repr); + } control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(intersections[intersections.size() - 1]), desktop->doc2dt(intersections[intersections.size() - 1]) + normal * (dimension_offset * 2)); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); + if(to_item) { + setLine(desktop->doc2dt(intersections[intersections.size() - 1]), + desktop->doc2dt(intersections[intersections.size() - 1]) + normal * (dimension_offset * 2), + false, + &line_color_primary, + measure_repr); + } } // call-out lines - for (std::vector::iterator it = placements.begin(); it != placements.end(); ++it) - { + for (std::vector::iterator it = placements.begin(); it != placements.end(); ++it) { LabelPlacement &place = *it; ControlManager &mgr = ControlManager::getManager(); SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), - place.start, - place.end, - CTLINE_SECONDARY); + place.start, + place.end, + CTLINE_SECONDARY); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); + if(to_item) { + setLine(place.start,place.end, false, &line_color_secondary, measure_repr); + } } { @@ -998,28 +1306,19 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point ControlManager &mgr = ControlManager::getManager(); SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), - desktop->doc2dt(measure_text_pos), - desktop->doc2dt(measure_text_pos) - (normal * dimension_offset), - CTLINE_SECONDARY); + desktop->doc2dt(measure_text_pos), + desktop->doc2dt(measure_text_pos) - (normal * dimension_offset), + CTLINE_SECONDARY); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); + if(to_item) { + setLine(desktop->doc2dt(measure_text_pos), + desktop->doc2dt(measure_text_pos) - (normal * dimension_offset), + false, + &line_color_secondary, + measure_repr); + } } } - - // Initial point - { - SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), - SP_TYPE_CTRL, - "anchor", SP_ANCHOR_CENTER, - "size", 8.0, - "stroked", TRUE, - "stroke_color", 0xff0000ff, - "mode", SP_KNOT_MODE_XOR, - "shape", SP_KNOT_SHAPE_CROSS, - NULL ); - - SP_CTRL(canvasitem)->moveto(start_point); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvasitem, 0)); - } } } } diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index 0670fb9f7..ee45c18e5 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -6,7 +6,7 @@ * * Authors: * Felipe Correa da Silva Sanches - * + * Jabiertxo Arraiza * Copyright (C) 2011 Authors * * Released under GNU GPL, read the file 'COPYING' for more information @@ -15,6 +15,7 @@ #include #include "ui/tools/tool-base.h" #include <2geom/point.h> +#include "display/canvas-text.h" #include #define SP_MEASURE_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) @@ -36,14 +37,17 @@ public: virtual void finish(); virtual bool root_handler(GdkEvent* event); virtual void showCanvasItems(); - virtual void showCanvasItems(Geom::Point start_point, Geom::Point end_point); + virtual void showCanvasItems(Geom::Point start_point, Geom::Point end_point, bool to_item = false, Inkscape::XML::Node *measure_repr = NULL); virtual void reverseKnots(); virtual void toMarkDimension(); + virtual void toItem(); virtual void reset(); virtual void setMarkers(); virtual void setMarker(bool isStart); virtual const std::string& getPrefsPath(); - void setLabelText(const char *value, Geom::Point pos, double fontsize, Geom::Coord angle); + void setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr); + void setLine(Geom::Point start_point,Geom::Point end_point, bool markers = false, guint32 *color = NULL, Inkscape::XML::Node *measure_repr = NULL); + void setLabelText(const char *value, Geom::Point pos, double fontsize, Geom::Coord angle, guint32 *background = NULL, Inkscape::XML::Node *measure_repr = NULL, CanvasTextAnchorPositionEnum text_anchor = TEXT_ANCHOR_CENTER ); void knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state); void knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state); void knotUngrabbedHandler(SPKnot */*knot*/, unsigned int /*state*/); @@ -66,3 +70,14 @@ private: } #endif // SEEN_SP_MEASURING_CONTEXT_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 9c782b4b6..48c781fb3 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -178,6 +178,13 @@ static void sp_to_mark_dimension(void){ } } +static void sp_to_item(void){ + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->toItem(); + } +} + void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder) { UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); @@ -283,6 +290,16 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_mark_dimension), 0 ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } + //to item + { + InkAction* act = ink_action_new( "MeasureToItem", + _("Convert to item"), + _("Convert to item"), + INKSCAPE_ICON("path-reverse"), + secondarySize ); + g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_item), 0 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } } // end of sp_measure_toolbox_prep() diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 3daa3c467..665502745 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -348,6 +348,7 @@ static gchar const * ui_descr = " " " " " " + " " " " " " -- cgit v1.2.3 From 328132ad756f7b094341c52175d184449155fe0f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 12 Oct 2015 18:08:22 +0200 Subject: Fix positions of genetated intersection items (bzr r14393.1.19) --- src/ui/tools/measure-tool.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 76b8e931e..00d66b4c9 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -733,7 +733,7 @@ void MeasureTool::setLine(Geom::Point start_point,Geom::Point end_point, bool ma } else { sp_repr_css_set_property (css, "stroke", "#000000"); } - sp_repr_css_set_property (css, "stroke-linecap", "butt"); + sp_repr_css_set_property (css, "stroke-linecap", "square"); sp_repr_css_set_property (css, "stroke-linejoin", "miter"); sp_repr_css_set_property (css, "stroke-miterlimit", "4"); sp_repr_css_set_property (css, "stroke-dasharray", "none"); @@ -770,12 +770,12 @@ void MeasureTool::setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr return; } char const * svgd; - svgd = "m -3.55,-3.55 7.11,7.11 m 0,-7.11 -7.11,7.11"; + svgd = "m 0.707,0.707 6.586,6.586 m 0,-6.586 -6.586,6.586"; Geom::PathVector c = sp_svg_read_pathv(svgd); Geom::Scale scale = Geom::Scale(desktop->current_zoom()).inverse(); + c *= Geom::Translate(Geom::Point(-3.5,-3.5)); c *= scale; - Geom::Point strokewidth = (Geom::Point(1,1) * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse())/ desktop->current_zoom(); - c *= Geom::Translate(Geom::Point(strokewidth/2.0) - (scale.vector() * 0.5)); + c *= Geom::Translate(Geom::Point() - (scale.vector() * 0.5)); c *= Geom::Translate(desktop->doc2dt(origin)); c *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); SPDocument *doc = desktop->getDocument(); @@ -785,6 +785,7 @@ void MeasureTool::setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr repr = xml_doc->createElement("svg:path"); gchar const *str = sp_svg_write_path(c); SPCSSAttr *css = sp_repr_css_attr_new(); + Geom::Point strokewidth = (Geom::Point(1,1) * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse())/ desktop->current_zoom(); std::stringstream stroke_width; stroke_width.imbue(std::locale::classic()); stroke_width << strokewidth[Geom::X]; @@ -794,7 +795,7 @@ void MeasureTool::setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr gchar c[64]; sp_svg_write_color (c, sizeof(c), line_color_secondary); sp_repr_css_set_property (css, "stroke", c); - sp_repr_css_set_property (css, "stroke-linecap", "butt"); + sp_repr_css_set_property (css, "stroke-linecap", "square"); sp_repr_css_set_property (css, "stroke-linejoin", "miter"); sp_repr_css_set_property (css, "stroke-miterlimit", "4"); sp_repr_css_set_property (css, "stroke-dasharray", "none"); -- cgit v1.2.3 From 074d5514042f280f94ea897269a4421ff50d8c30 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 16 Oct 2015 13:12:59 +0200 Subject: Fixed explicit base with SHIFT to allow calculate angles A bit refactor (bzr r14393.2.2) --- src/ui/tools/measure-tool.cpp | 118 ++++++++++++++++++++---------------------- src/ui/tools/measure-tool.h | 4 +- 2 files changed, 56 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 00d66b4c9..110b706fd 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -344,7 +344,7 @@ void MeasureTool::reverseKnots() this->knot_start->show(); this->knot_end->moveto(start); this->knot_end->show(); - this->showCanvasItems(end, start); + this->showCanvasItems(); } void MeasureTool::knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state) @@ -365,7 +365,7 @@ void MeasureTool::knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppo start_p = point; this->knot_start->moveto(start_p); } - showCanvasItems(start_p, end_p); + showCanvasItems(); } void MeasureTool::knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state) @@ -386,14 +386,15 @@ void MeasureTool::knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppoin end_p = point; this->knot_end->moveto(end_p); } - showCanvasItems(start_p, end_p); + last_end = desktop->d2w(end_p); + showCanvasItems(); } void MeasureTool::knotUngrabbedHandler(SPKnot */*knot*/, unsigned int state) { this->knot_start->moveto(start_p); this->knot_end->moveto(end_p); - showCanvasItems(start_p, end_p); + showCanvasItems(); } @@ -469,11 +470,11 @@ bool MeasureTool::root_handler(GdkEvent* event) Geom::Point const button_w(event->button.x, event->button.y); explicitBase = boost::none; last_end = boost::none; - start_point = desktop->w2d(button_w); + start_p = desktop->w2d(button_w); if (event->button.button == 1 && !this->space_panning) { // save drag origin - start_point = desktop->w2d(Geom::Point(event->button.x, event->button.y)); + start_p = desktop->w2d(Geom::Point(event->button.x, event->button.y)); within_tolerance = true; ret = TRUE; @@ -481,7 +482,7 @@ bool MeasureTool::root_handler(GdkEvent* event) SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - m.freeSnapReturnByRef(start_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); + m.freeSnapReturnByRef(start_p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), @@ -492,9 +493,7 @@ bool MeasureTool::root_handler(GdkEvent* event) } case GDK_KEY_PRESS: { if ((event->key.keyval == GDK_KEY_Shift_L) || (event->key.keyval == GDK_KEY_Shift_R)) { - if (last_end) { - explicitBase = last_end; - } + explicitBase = end_p; } break; } @@ -508,7 +507,7 @@ bool MeasureTool::root_handler(GdkEvent* event) m.setup(desktop); Inkscape::SnapCandidatePoint scp(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); + scp.addOrigin(start_p); m.preSnap(scp); m.unSetup(); @@ -519,7 +518,7 @@ bool MeasureTool::root_handler(GdkEvent* event) tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); Geom::Point const motion_w(event->motion.x, event->motion.y); if ( within_tolerance) { - if ( Geom::LInfty( motion_w - start_point ) < tolerance) { + if ( Geom::LInfty( motion_w - start_p ) < tolerance) { return FALSE; // Do not drag if we're within tolerance from origin. } } @@ -530,20 +529,20 @@ bool MeasureTool::root_handler(GdkEvent* event) if(event->motion.time == 0 || !last_end || Geom::LInfty( motion_w - *last_end ) > (tolerance/4.0)) { Geom::Point const motion_w(event->motion.x, event->motion.y); Geom::Point const motion_dt(desktop->w2d(motion_w)); - Geom::Point end_point = motion_dt; + end_p = motion_dt; if (event->motion.state & GDK_CONTROL_MASK) { - spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); + spdc_endpoint_snap_rotation(this, end_p, start_p, event->motion.state); } else if (!(event->motion.state & GDK_SHIFT_MASK)) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); + Inkscape::SnapCandidatePoint scp(end_p, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_p); Inkscape::SnappedPoint sp = m.freeSnap(scp); - end_point = sp.getPoint(); + end_p = sp.getPoint(); m.unSetup(); } - showCanvasItems(start_point, end_point); + showCanvasItems(); last_end = motion_w ; } gobble_motion_events(GDK_BUTTON1_MASK); @@ -551,26 +550,26 @@ bool MeasureTool::root_handler(GdkEvent* event) break; } case GDK_BUTTON_RELEASE: { - this->knot_start->moveto(start_point); + this->knot_start->moveto(start_p); this->knot_start->show(); - Geom::Point end_point = end_p; + end_p = end_p; if(last_end) { - end_point = desktop->w2d(*last_end); + end_p = desktop->w2d(*last_end); if (event->button.state & GDK_CONTROL_MASK) { - spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); + spdc_endpoint_snap_rotation(this, end_p, start_p, event->motion.state); } else if (!(event->button.state & GDK_SHIFT_MASK)) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); + Inkscape::SnapCandidatePoint scp(end_p, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_p); Inkscape::SnappedPoint sp = m.freeSnap(scp); - end_point = sp.getPoint(); + end_p = sp.getPoint(); m.unSetup(); } } - this->knot_end->moveto(end_point); + this->knot_end->moveto(end_p); this->knot_end->show(); - showCanvasItems(start_point, end_point); + showCanvasItems(); if (this->grabbed) { sp_canvas_item_ungrab(this->grabbed, event->button.time); this->grabbed = NULL; @@ -660,7 +659,7 @@ void MeasureTool::toItem() guint32 line_color_primary = 0x0000ff7f; Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *rgroup = xml_doc->createElement("svg:g"); - showCanvasItems(start_p, end_p, true, rgroup); + showCanvasItems(true, rgroup); setLine(start_p,end_p, false, &line_color_primary, rgroup); SPItem *measure_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(rgroup)); Inkscape::GC::release(rgroup); @@ -700,7 +699,7 @@ void MeasureTool::toMarkDimension() void MeasureTool::setLine(Geom::Point start_point,Geom::Point end_point, bool markers, guint32 *color, Inkscape::XML::Node *measure_repr) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if(!desktop || !start_point.isFinite() || !end_point.isFinite()) { + if(!desktop || !start_p.isFinite() || !end_p.isFinite()) { return; } Geom::PathVector c; @@ -930,21 +929,14 @@ void MeasureTool::reset() measure_tmp_items.clear(); } -void MeasureTool::showCanvasItems() -{ - showCanvasItems(start_p, end_p); -} - -void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point, bool to_item, Inkscape::XML::Node *measure_repr) +void MeasureTool::showCanvasItems(bool to_item, Inkscape::XML::Node *measure_repr) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if(!desktop || !start_point.isFinite() || !end_point.isFinite() || end_point == MAGIC_POINT) { + if(!desktop || !start_p.isFinite() || !end_p.isFinite() || end_p == MAGIC_POINT) { return; } guint32 line_color_primary = 0x0000ff7f; guint32 line_color_secondary = 0xff00007f; - start_p = start_point; - end_p = end_point; //clear previous temporary canvas items, we'll draw new ones for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); @@ -956,18 +948,18 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point dimension_offset = prefs->getDouble("/tools/measure/offset"); Geom::PathVector lineseg; Geom::Path p; - p.start(desktop->dt2doc(start_point)); - p.appendNew(desktop->dt2doc(end_point)); + p.start(desktop->dt2doc(start_p)); + p.appendNew(desktop->dt2doc(end_p)); lineseg.push_back(p); - double deltax = end_point[Geom::X] - start_point[Geom::X]; - double deltay = end_point[Geom::Y] - start_point[Geom::Y]; + double deltax = end_p[Geom::X] - start_p[Geom::X]; + double deltay = end_p[Geom::Y] - start_p[Geom::Y]; double angle = atan2(deltay, deltax); double baseAngle = 0; if (explicitBase) { - double deltax2 = explicitBase.get()[Geom::X] - start_point[Geom::X]; - double deltay2 = explicitBase.get()[Geom::Y] - start_point[Geom::Y]; + double deltax2 = explicitBase.get()[Geom::X] - start_p[Geom::X]; + double deltay2 = explicitBase.get()[Geom::Y] - start_p[Geom::Y]; baseAngle = atan2(deltay2, deltax2); angle -= baseAngle; @@ -998,8 +990,8 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point items.push_back(items_reverse[0]); } } else { - r->start(desktop,start_point); - r->move(end_point); + r->start(desktop,start_p); + r->move(end_p); items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers); r->stop(); } @@ -1046,7 +1038,7 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point double fontsize = prefs->getInt("/tools/measure/fontsize") * (96/72); // Normal will be used for lines and text - Geom::Point windowNormal = Geom::unit_vector(Geom::rot90(desktop->d2w(end_point - start_point))); + Geom::Point windowNormal = Geom::unit_vector(Geom::rot90(desktop->d2w(end_p - start_p))); Geom::Point normal = desktop->w2d(windowNormal); std::vector intersections; @@ -1102,7 +1094,7 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point } Geom::Point angleDisplayPt = calcAngleDisplayAnchor(desktop, angle, baseAngle, - start_point, end_point, + start_p, end_p, fontsize); { @@ -1128,14 +1120,14 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point } { - double totallengthval = (end_point - start_point).length(); + double totallengthval = (end_p - start_p).length(); totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); // TODO cleanup memory, Glib::ustring, etc.: gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, - end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), + end_p + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), totallength_str); sp_canvastext_set_fontsize(canvas_tooltip, fontsize); canvas_tooltip->rgba = 0xffffffff; @@ -1146,7 +1138,7 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); if(to_item) { guint32 background = canvas_tooltip->rgba_background; - setLabelText(totallength_str, end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), fontsize, 0, &background, measure_repr, TEXT_ANCHOR_LEFT); + setLabelText(totallength_str, end_p + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), fontsize, 0, &background, measure_repr, TEXT_ANCHOR_LEFT); } g_free(totallength_str); } @@ -1187,10 +1179,10 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point "shape", SP_KNOT_SHAPE_CROSS, NULL ); - SP_CTRL(canvasitem)->moveto(start_point); + SP_CTRL(canvasitem)->moveto(start_p); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvasitem, 0)); if(to_item) { - setPoint(start_point, measure_repr); + setPoint(start_p, measure_repr); } } @@ -1218,33 +1210,33 @@ void MeasureTool::showCanvasItems(Geom::Point start_point, Geom::Point end_point // draw main control line { SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), - start_point, - end_point); + start_p, + end_p); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - if ((end_point[Geom::X] != start_point[Geom::X]) && (end_point[Geom::Y] != start_point[Geom::Y])) { - double length = std::abs((end_point - start_point).length()); - Geom::Point anchorEnd = start_point; + if ((end_p[Geom::X] != start_p[Geom::X]) && (end_p[Geom::Y] != start_p[Geom::Y])) { + double length = std::abs((end_p - start_p).length()); + Geom::Point anchorEnd = start_p; anchorEnd[Geom::X] += length; if (explicitBase) { - anchorEnd *= (Geom::Affine(Geom::Translate(-start_point)) + anchorEnd *= (Geom::Affine(Geom::Translate(-start_p)) * Geom::Affine(Geom::Rotate(baseAngle)) - * Geom::Affine(Geom::Translate(start_point))); + * Geom::Affine(Geom::Translate(start_p))); } SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), - start_point, + start_p, anchorEnd, CTLINE_SECONDARY); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); if(to_item) { - setLine(start_point, + setLine(start_p, anchorEnd, false, &line_color_secondary, measure_repr); } - createAngleDisplayCurve(desktop, start_point, end_point, angleDisplayPt, angle, measure_repr); + createAngleDisplayCurve(desktop, start_p, end_p, angleDisplayPt, angle, measure_repr); } } diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index ee45c18e5..919152aad 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -36,8 +36,7 @@ public: virtual void finish(); virtual bool root_handler(GdkEvent* event); - virtual void showCanvasItems(); - virtual void showCanvasItems(Geom::Point start_point, Geom::Point end_point, bool to_item = false, Inkscape::XML::Node *measure_repr = NULL); + virtual void showCanvasItems(bool to_item = false, Inkscape::XML::Node *measure_repr = NULL); virtual void reverseKnots(); virtual void toMarkDimension(); virtual void toItem(); @@ -54,7 +53,6 @@ public: private: SPCanvasItem* grabbed; - Geom::Point start_point; boost::optional explicitBase; boost::optional last_end; SPKnot *knot_start; -- cgit v1.2.3 From 7480acb475c646171babc133edcde56356867ede Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 16 Oct 2015 15:57:52 +0200 Subject: removed unnecesary line (bzr r14393.2.3) --- src/ui/tools/measure-tool.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 110b706fd..7fedf6631 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -386,7 +386,6 @@ void MeasureTool::knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppoin end_p = point; this->knot_end->moveto(end_p); } - last_end = desktop->d2w(end_p); showCanvasItems(); } -- cgit v1.2.3 From 69aa4c6436321b22525fb11c552ca7d60ac1b096 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 16 Oct 2015 19:17:47 +0200 Subject: Add convert to guides option (bzr r14393.2.4) --- src/ui/tools/measure-tool.cpp | 91 +++++++++++++++++++++++++++++++++++++++++ src/ui/tools/measure-tool.h | 1 + src/widgets/measure-toolbar.cpp | 17 ++++++++ src/widgets/toolbox.cpp | 1 + 4 files changed, 110 insertions(+) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 7fedf6631..bf82fb745 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -650,6 +650,97 @@ void MeasureTool::setMarker(bool isStart) path->updateRepr(); } +void MeasureTool::toGuides() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPDocument *doc = desktop->getDocument(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + Geom::Point start = start_p * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + Geom::Point end = end_p * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + Geom::Ray ray(start,end); + SPNamedView *namedview = desktop->namedview; + if(!namedview){ + return; + } + //meassure angle + Inkscape::XML::Node *measure_line; + measure_line = xml_doc->createElement("sodipodi:guide"); + std::stringstream position; + position.imbue(std::locale::classic()); + position << start[Geom::X] << "," << start[Geom::Y]; + measure_line->setAttribute("position", position.str().c_str() ); + Geom::Point unit_vector = Geom::rot90(start.polar(ray.angle())); + std::stringstream angle; + angle.imbue(std::locale::classic()); + angle << unit_vector[Geom::X] << "," << unit_vector[Geom::Y]; + measure_line->setAttribute("orientation", angle.str().c_str()); + namedview->appendChild(measure_line); + Inkscape::GC::release(measure_line); + //base angle + if(explicitBase){ + explicitBase = *explicitBase * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + ray.setPoints(start, *explicitBase); + if(ray.angle() != 0){ + Inkscape::XML::Node *base_line; + base_line = xml_doc->createElement("sodipodi:guide"); + position.str(""); + position.imbue(std::locale::classic()); + position << start[Geom::X] << "," << start[Geom::Y]; + base_line->setAttribute("position", position.str().c_str() ); + Geom::Point unit_vector = Geom::rot90(start.polar(ray.angle())); + std::stringstream angle; + angle.imbue(std::locale::classic()); + angle << unit_vector[Geom::X] << "," << unit_vector[Geom::Y]; + base_line->setAttribute("orientation", angle.str().c_str()); + namedview->appendChild(base_line); + Inkscape::GC::release(base_line); + } + } + //start horizontal + Inkscape::XML::Node *start_horizontal; + start_horizontal = xml_doc->createElement("sodipodi:guide"); + position.str(""); + position.imbue(std::locale::classic()); + position << start[Geom::X] << "," << start[Geom::Y]; + start_horizontal->setAttribute("position", position.str().c_str() ); + start_horizontal->setAttribute("orientation", "0,1"); + namedview->appendChild(start_horizontal); + Inkscape::GC::release(start_horizontal); + //start vertical + Inkscape::XML::Node *start_vertical; + start_vertical = xml_doc->createElement("sodipodi:guide"); + position.str(""); + position.imbue(std::locale::classic()); + position << start[Geom::X] << "," << start[Geom::Y]; + start_vertical->setAttribute("position", position.str().c_str() ); + start_vertical->setAttribute("orientation", "1,0"); + namedview->appendChild(start_vertical); + Inkscape::GC::release(start_vertical); + //end horizontal + Inkscape::XML::Node *end_horizontal; + end_horizontal = xml_doc->createElement("sodipodi:guide"); + position.str(""); + position.imbue(std::locale::classic()); + position << end[Geom::X] << "," << end[Geom::Y]; + end_horizontal->setAttribute("position", position.str().c_str() ); + end_horizontal->setAttribute("orientation", "0,1"); + namedview->appendChild(end_horizontal); + Inkscape::GC::release(end_horizontal); + //start vertical + Inkscape::XML::Node *end_vertical; + end_vertical = xml_doc->createElement("sodipodi:guide"); + position.str(""); + position.imbue(std::locale::classic()); + position << end[Geom::X] << "," << end[Geom::Y]; + end_vertical->setAttribute("position", position.str().c_str() ); + end_vertical->setAttribute("orientation", "1,0"); + namedview->appendChild(end_vertical); + Inkscape::GC::release(end_vertical); + + doc->ensureUpToDate(); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add guides from measure tool")); +} + void MeasureTool::toItem() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index 919152aad..b53131ef9 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -38,6 +38,7 @@ public: virtual bool root_handler(GdkEvent* event); virtual void showCanvasItems(bool to_item = false, Inkscape::XML::Node *measure_repr = NULL); virtual void reverseKnots(); + virtual void toGuides(); virtual void toMarkDimension(); virtual void toItem(); virtual void reset(); diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 48c781fb3..741d600b4 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -178,6 +178,13 @@ static void sp_to_mark_dimension(void){ } } +static void sp_to_guides(void){ + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->toGuides(); + } +} + static void sp_to_item(void){ MeasureTool *mt = get_measure_tool(); if (mt) { @@ -280,6 +287,16 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_reverse_knots), 0 ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } + //to guides + { + InkAction* act = ink_action_new( "MeasureToGuides", + _("To guides"), + _("Mark Dimension"), + INKSCAPE_ICON("guides"), + secondarySize ); + g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_guides), 0 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } //to mark dimensions { InkAction* act = ink_action_new( "MeasureMarkDimension", diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 665502745..a2bd16978 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -347,6 +347,7 @@ static gchar const * ui_descr = " " " " " " + " " " " " " " " -- cgit v1.2.3 From 08729b1dc767a8b3fd3de4ce0098d325f56fae60 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 16 Oct 2015 20:02:37 +0200 Subject: Fix a regression on mirror measure (bzr r14393.2.5) --- src/ui/tools/measure-tool.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index bf82fb745..1bdccf13b 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -344,6 +344,8 @@ void MeasureTool::reverseKnots() this->knot_start->show(); this->knot_end->moveto(start); this->knot_end->show(); + start_p = end; + end_p = start; this->showCanvasItems(); } -- cgit v1.2.3 From f0cd7f4d9ca2e7f6f59c8030ee57917254816a59 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 16 Oct 2015 20:06:31 +0200 Subject: Fix a wrong string (bzr r14393.2.6) --- src/widgets/measure-toolbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 741d600b4..28f82ba44 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -291,7 +291,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G { InkAction* act = ink_action_new( "MeasureToGuides", _("To guides"), - _("Mark Dimension"), + _("To guides"), INKSCAPE_ICON("guides"), secondarySize ); g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_guides), 0 ); -- cgit v1.2.3 From 3b66eaf39332144a8545a85bbf8516e0e5024dd8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 16 Oct 2015 20:44:32 +0200 Subject: fixing guide positions... (bzr r14393.2.7) --- src/ui/tools/measure-tool.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 1bdccf13b..3795a980c 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -657,8 +657,10 @@ void MeasureTool::toGuides() SPDesktop *desktop = SP_ACTIVE_DESKTOP; SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Geom::Point start = start_p * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); - Geom::Point end = end_p * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + Geom::Point start = desktop->doc2dt(start_p); + Geom::Point end = desktop->doc2dt(end_p); + start *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + end *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); Geom::Ray ray(start,end); SPNamedView *namedview = desktop->namedview; if(!namedview){ -- cgit v1.2.3 From 257bf92c7eada92b55fa9b68a75feedc0e80eefe Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 17 Oct 2015 18:36:14 +0200 Subject: Fixed guides if current layer has any transform Improved guides code Change color and label to the result guides (bzr r14393.1.23) --- src/ui/tools/measure-tool.cpp | 129 +++++++++++++++++------------------------- src/ui/tools/measure-tool.h | 3 +- 2 files changed, 54 insertions(+), 78 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 3795a980c..b26e528c4 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -39,6 +39,7 @@ #include "sp-flowtext.h" #include "sp-defs.h" #include "sp-item.h" +#include "sp-root.h" #include "macros.h" #include "rubberband.h" #include "path-chemistry.h" @@ -656,91 +657,26 @@ void MeasureTool::toGuides() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; SPDocument *doc = desktop->getDocument(); - Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Geom::Point start = desktop->doc2dt(start_p); - Geom::Point end = desktop->doc2dt(end_p); - start *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); - end *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + Geom::Point start = desktop->doc2dt(start_p) * desktop->doc2dt(); + Geom::Point end = desktop->doc2dt(end_p) * desktop->doc2dt(); Geom::Ray ray(start,end); SPNamedView *namedview = desktop->namedview; if(!namedview){ return; } - //meassure angle - Inkscape::XML::Node *measure_line; - measure_line = xml_doc->createElement("sodipodi:guide"); - std::stringstream position; - position.imbue(std::locale::classic()); - position << start[Geom::X] << "," << start[Geom::Y]; - measure_line->setAttribute("position", position.str().c_str() ); - Geom::Point unit_vector = Geom::rot90(start.polar(ray.angle())); - std::stringstream angle; - angle.imbue(std::locale::classic()); - angle << unit_vector[Geom::X] << "," << unit_vector[Geom::Y]; - measure_line->setAttribute("orientation", angle.str().c_str()); - namedview->appendChild(measure_line); - Inkscape::GC::release(measure_line); - //base angle + setGuide(start,ray.angle(), _("Meassure")); if(explicitBase){ explicitBase = *explicitBase * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); ray.setPoints(start, *explicitBase); if(ray.angle() != 0){ - Inkscape::XML::Node *base_line; - base_line = xml_doc->createElement("sodipodi:guide"); - position.str(""); - position.imbue(std::locale::classic()); - position << start[Geom::X] << "," << start[Geom::Y]; - base_line->setAttribute("position", position.str().c_str() ); - Geom::Point unit_vector = Geom::rot90(start.polar(ray.angle())); - std::stringstream angle; - angle.imbue(std::locale::classic()); - angle << unit_vector[Geom::X] << "," << unit_vector[Geom::Y]; - base_line->setAttribute("orientation", angle.str().c_str()); - namedview->appendChild(base_line); - Inkscape::GC::release(base_line); + setGuide(start,ray.angle(), _("Base")); } } - //start horizontal - Inkscape::XML::Node *start_horizontal; - start_horizontal = xml_doc->createElement("sodipodi:guide"); - position.str(""); - position.imbue(std::locale::classic()); - position << start[Geom::X] << "," << start[Geom::Y]; - start_horizontal->setAttribute("position", position.str().c_str() ); - start_horizontal->setAttribute("orientation", "0,1"); - namedview->appendChild(start_horizontal); - Inkscape::GC::release(start_horizontal); - //start vertical - Inkscape::XML::Node *start_vertical; - start_vertical = xml_doc->createElement("sodipodi:guide"); - position.str(""); - position.imbue(std::locale::classic()); - position << start[Geom::X] << "," << start[Geom::Y]; - start_vertical->setAttribute("position", position.str().c_str() ); - start_vertical->setAttribute("orientation", "1,0"); - namedview->appendChild(start_vertical); - Inkscape::GC::release(start_vertical); - //end horizontal - Inkscape::XML::Node *end_horizontal; - end_horizontal = xml_doc->createElement("sodipodi:guide"); - position.str(""); - position.imbue(std::locale::classic()); - position << end[Geom::X] << "," << end[Geom::Y]; - end_horizontal->setAttribute("position", position.str().c_str() ); - end_horizontal->setAttribute("orientation", "0,1"); - namedview->appendChild(end_horizontal); - Inkscape::GC::release(end_horizontal); - //start vertical - Inkscape::XML::Node *end_vertical; - end_vertical = xml_doc->createElement("sodipodi:guide"); - position.str(""); - position.imbue(std::locale::classic()); - position << end[Geom::X] << "," << end[Geom::Y]; - end_vertical->setAttribute("position", position.str().c_str() ); - end_vertical->setAttribute("orientation", "1,0"); - namedview->appendChild(end_vertical); - Inkscape::GC::release(end_vertical); - + setGuide(start,0,_("Start")); + setGuide(start,Geom::deg_to_rad(90),_("Start")); + setGuide(end,0,_("End")); + setGuide(end,Geom::deg_to_rad(90),_("End")); + showCanvasItems(true); doc->ensureUpToDate(); DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add guides from measure tool")); } @@ -753,7 +689,7 @@ void MeasureTool::toItem() guint32 line_color_primary = 0x0000ff7f; Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *rgroup = xml_doc->createElement("svg:g"); - showCanvasItems(true, rgroup); + showCanvasItems(false, true,rgroup); setLine(start_p,end_p, false, &line_color_primary, rgroup); SPItem *measure_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(rgroup)); Inkscape::GC::release(rgroup); @@ -790,6 +726,39 @@ void MeasureTool::toMarkDimension() DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add global meassure line")); } +void MeasureTool::setGuide(Geom::Point origin,double angle, const char *label) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPDocument *doc = desktop->getDocument(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + SPRoot const *root = doc->getRoot(); + Geom::Affine affine(Geom::identity()); + if(root) { + affine *= root->c2p.inverse(); + } + SPNamedView *namedview = desktop->namedview; + if(!namedview){ + return; + } + origin *= affine; + //meassure angle + Inkscape::XML::Node *guide; + guide = xml_doc->createElement("sodipodi:guide"); + std::stringstream position; + position.imbue(std::locale::classic()); + position << origin[Geom::X] << "," << origin[Geom::Y]; + guide->setAttribute("position", position.str().c_str() ); + guide->setAttribute("inkscape:color", "rgb(167,0,255)"); + guide->setAttribute("inkscape:label", label); + Geom::Point unit_vector = Geom::rot90(origin.polar(angle)); + std::stringstream angle_str; + angle_str.imbue(std::locale::classic()); + angle_str << unit_vector[Geom::X] << "," << unit_vector[Geom::Y]; + guide->setAttribute("orientation", angle_str.str().c_str()); + namedview->appendChild(guide); + Inkscape::GC::release(guide); +} + void MeasureTool::setLine(Geom::Point start_point,Geom::Point end_point, bool markers, guint32 *color, Inkscape::XML::Node *measure_repr) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; @@ -1023,7 +992,7 @@ void MeasureTool::reset() measure_tmp_items.clear(); } -void MeasureTool::showCanvasItems(bool to_item, Inkscape::XML::Node *measure_repr) +void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::Node *measure_repr) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; if(!desktop || !start_p.isFinite() || !end_p.isFinite() || end_p == MAGIC_POINT) { @@ -1193,7 +1162,7 @@ void MeasureTool::showCanvasItems(bool to_item, Inkscape::XML::Node *measure_rep { // TODO cleanup memory, Glib::ustring, etc.: - gchar *angle_str = g_strdup_printf("%.2f °", angle * 180/M_PI); + gchar *angle_str = g_strdup_printf("%.2f °", Geom::rad_to_deg(angle)); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, @@ -1298,6 +1267,12 @@ void MeasureTool::showCanvasItems(bool to_item, Inkscape::XML::Node *measure_rep if(to_item) { setPoint(desktop->doc2dt(intersections[idx]), measure_repr); } + if(to_guides) { + std::stringstream cross_number; + cross_number.imbue(std::locale::classic()); + cross_number << _("Crossing ") << idx; + setGuide(desktop->doc2dt(intersections[idx]), angle + Geom::deg_to_rad(90), cross_number.str().c_str()); + } } // Since adding goes to the bottom, do all lines last. diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index b53131ef9..05c8296c1 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -36,7 +36,7 @@ public: virtual void finish(); virtual bool root_handler(GdkEvent* event); - virtual void showCanvasItems(bool to_item = false, Inkscape::XML::Node *measure_repr = NULL); + virtual void showCanvasItems(bool to_guides = false, bool to_item = false, Inkscape::XML::Node *measure_repr = NULL); virtual void reverseKnots(); virtual void toGuides(); virtual void toMarkDimension(); @@ -45,6 +45,7 @@ public: virtual void setMarkers(); virtual void setMarker(bool isStart); virtual const std::string& getPrefsPath(); + void setGuide(Geom::Point origin, double angle, const char *label); void setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr); void setLine(Geom::Point start_point,Geom::Point end_point, bool markers = false, guint32 *color = NULL, Inkscape::XML::Node *measure_repr = NULL); void setLabelText(const char *value, Geom::Point pos, double fontsize, Geom::Coord angle, guint32 *background = NULL, Inkscape::XML::Node *measure_repr = NULL, CanvasTextAnchorPositionEnum text_anchor = TEXT_ANCHOR_CENTER ); -- cgit v1.2.3 From 19a39e655f7abf8fb9844bb4474fdd908a548870 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 17 Oct 2015 18:42:23 +0200 Subject: String fixes (bzr r14393.1.24) --- src/ui/tools/measure-tool.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index b26e528c4..a461a6b3c 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -664,7 +664,7 @@ void MeasureTool::toGuides() if(!namedview){ return; } - setGuide(start,ray.angle(), _("Meassure")); + setGuide(start,ray.angle(), _("Measure")); if(explicitBase){ explicitBase = *explicitBase * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); ray.setPoints(start, *explicitBase); @@ -723,7 +723,7 @@ void MeasureTool::toMarkDimension() gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); setLabelText(totallength_str, middle, fontsize, Geom::deg_to_rad(180) - ray.angle()); doc->ensureUpToDate(); - DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add global meassure line")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add global measure line")); } void MeasureTool::setGuide(Geom::Point origin,double angle, const char *label) @@ -741,7 +741,7 @@ void MeasureTool::setGuide(Geom::Point origin,double angle, const char *label) return; } origin *= affine; - //meassure angle + //measure angle Inkscape::XML::Node *guide; guide = xml_doc->createElement("sodipodi:guide"); std::stringstream position; -- cgit v1.2.3 From c7bf1a0ffbc1e5fc397df2fb8ce7fac90caba9eb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 17 Oct 2015 18:55:33 +0200 Subject: Fix for numbering crosing labels (bzr r14393.1.25) --- src/ui/tools/measure-tool.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index a461a6b3c..4bb8edcc3 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -672,10 +672,10 @@ void MeasureTool::toGuides() setGuide(start,ray.angle(), _("Base")); } } - setGuide(start,0,_("Start")); + setGuide(start,0,""); setGuide(start,Geom::deg_to_rad(90),_("Start")); setGuide(end,0,_("End")); - setGuide(end,Geom::deg_to_rad(90),_("End")); + setGuide(end,Geom::deg_to_rad(90),""); showCanvasItems(true); doc->ensureUpToDate(); DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add guides from measure tool")); @@ -1270,8 +1270,16 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N if(to_guides) { std::stringstream cross_number; cross_number.imbue(std::locale::classic()); - cross_number << _("Crossing ") << idx; - setGuide(desktop->doc2dt(intersections[idx]), angle + Geom::deg_to_rad(90), cross_number.str().c_str()); + if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true)){ + cross_number << _("Crossing ") << idx; + } else { + cross_number << _("Crossing ") << idx + 1; + } + if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true) && idx == 0) { + setGuide(desktop->doc2dt(intersections[idx]), angle + Geom::deg_to_rad(90), ""); + } else { + setGuide(desktop->doc2dt(intersections[idx]), angle + Geom::deg_to_rad(90), cross_number.str().c_str()); + } } } // Since adding goes to the bottom, do all lines last. -- cgit v1.2.3 From d03a0a3405b10ac4686faac1d4827c01f47114b0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 17 Oct 2015 19:51:26 +0200 Subject: Add precision to measure. Also change other scalar widgets to a .2 precision instead 3 (bzr r14393.1.26) --- src/ui/tools/measure-tool.cpp | 32 ++++++++++++++++++++++++++------ src/widgets/measure-toolbar.cpp | 37 ++++++++++++++++++++++++++++++++++--- src/widgets/toolbox.cpp | 2 ++ 3 files changed, 62 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 4bb8edcc3..57e519a0e 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -716,11 +716,15 @@ void MeasureTool::toMarkDimension() if (!unit_name.compare("")) { unit_name = "px"; } - double fontsize = prefs->getInt("/tools/measure/fontsize") * (96/72); + double fontsize = prefs->getInt("/tools/measure/fontsize") * (96.0/72.0); + int precision = prefs->getInt("/tools/measure/precision"); + std::stringstream precision_str; + precision_str.imbue(std::locale::classic()); + precision_str << "%." << precision << "f %s"; Geom::Point middle = Geom::middle_point(start, end); double totallengthval = (end_p - start_p).length(); totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); - gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); + gchar *totallength_str = g_strdup_printf(precision_str.str().c_str(), totallengthval, unit_name.c_str()); setLabelText(totallength_str, middle, fontsize, Geom::deg_to_rad(180) - ray.angle()); doc->ensureUpToDate(); DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add global measure line")); @@ -1137,7 +1141,11 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N LabelPlacement &place = *it; // TODO cleanup memory, Glib::ustring, etc.: - gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit_name.c_str()); + int precision = prefs->getInt("/tools/measure/precision"); + std::stringstream precision_str; + precision_str.imbue(std::locale::classic()); + precision_str << "%." << precision << "f %s"; + gchar *measure_str = g_strdup_printf(precision_str.str().c_str(), place.lengthVal, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, place.end, @@ -1162,7 +1170,11 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N { // TODO cleanup memory, Glib::ustring, etc.: - gchar *angle_str = g_strdup_printf("%.2f °", Geom::rad_to_deg(angle)); + int precision = prefs->getInt("/tools/measure/precision"); + std::stringstream precision_str; + precision_str.imbue(std::locale::classic()); + precision_str << "%." << precision << "f °"; + gchar *angle_str = g_strdup_printf(precision_str.str().c_str(), Geom::rad_to_deg(angle)); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, @@ -1187,7 +1199,11 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); // TODO cleanup memory, Glib::ustring, etc.: - gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); + int precision = prefs->getInt("/tools/measure/precision"); + std::stringstream precision_str; + precision_str.imbue(std::locale::classic()); + precision_str << "%." << precision << "f %s"; + gchar *totallength_str = g_strdup_printf(precision_str.str().c_str(), totallengthval, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, end_p + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), @@ -1211,7 +1227,11 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); // TODO cleanup memory, Glib::ustring, etc.: - gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); + int precision = prefs->getInt("/tools/measure/precision"); + std::stringstream precision_str; + precision_str.imbue(std::locale::classic()); + precision_str << "%." << precision << "f %s"; + gchar *total_str = g_strdup_printf(precision_str.str().c_str(), totallengthval, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * (dimension_offset * 2), diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 28f82ba44..8256abc76 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -102,6 +102,23 @@ sp_measure_offset_value_changed(GtkAdjustment *adj, GObject *tbl) } } + +static void +sp_measure_precision_value_changed(GtkAdjustment *adj, GObject *tbl) +{ + SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); + + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt(Glib::ustring("/tools/measure/precision"), + gtk_adjustment_get_value(adj)); + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } + } +} + static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl) { UnitTracker* tracker = reinterpret_cast(g_object_get_data(tbl, "tracker")); @@ -212,8 +229,8 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 1, 36, 1.0, 4.0, 0, 0, 0, - sp_measure_fontsize_value_changed); - gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + sp_measure_fontsize_value_changed, NULL, 0 , 2); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact)); } // units label @@ -231,6 +248,20 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G gtk_action_group_add_action( mainActions, act ); } + /* Precission */ + { + eact = create_adjustment_action( "MeasurePrecisionAction", + _("Precision"), _("Precision:"), + _("Decimal precision of measure"), + "/tools/measure/precision", 2, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + 0, 10, 1, 0, + 0, 0, 0, + sp_measure_precision_value_changed, NULL, 0 ,0); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact)); + } + + /* Offset */ { eact = create_adjustment_action( "MeasureOffsetAction", @@ -240,7 +271,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 90000.0, 1.0, 4.0, 0, 0, 0, - sp_measure_offset_value_changed); + sp_measure_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 a2bd16978..e7dd69a28 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -339,6 +339,8 @@ static gchar const * ui_descr = " " " " " " + " " + " " " " " " " " -- cgit v1.2.3 From aed527316ca2cff495c32f57f68e37cd5b346f12 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 18 Oct 2015 13:51:14 +0200 Subject: Added Scale option (bzr r14393.1.27) --- src/ui/tools/measure-tool.cpp | 70 ++++++++++++++++++++++------------------- src/widgets/measure-toolbar.cpp | 46 +++++++++++++++++++++------ src/widgets/toolbox.cpp | 2 ++ 3 files changed, 76 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 57e519a0e..e56d0e916 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -106,14 +106,14 @@ bool SortLabelPlacement(LabelPlacement const &first, LabelPlacement const &secon } } -void repositionOverlappingLabels(std::vector &placements, SPDesktop *desktop, Geom::Point const &normal, double fontsize) +void repositionOverlappingLabels(std::vector &placements, SPDesktop *desktop, Geom::Point const &normal, double fontsize, int precision) { std::sort(placements.begin(), placements.end(), SortLabelPlacement); double border = 3; Geom::Rect box; { - Geom::Point tmp(fontsize * 8 + (border * 2), fontsize + (border * 2)); + Geom::Point tmp(fontsize * (6 + precision) + (border * 2), fontsize + (border * 2)); tmp = desktop->w2d(tmp); box = Geom::Rect(-tmp[Geom::X] / 2, -tmp[Geom::Y] / 2, tmp[Geom::X] / 2, tmp[Geom::Y] / 2); } @@ -706,12 +706,13 @@ void MeasureTool::toMarkDimension() setMarkers(); Geom::Ray ray(start_p,end_p); Geom::Point start = start_p + Geom::Point::polar(ray.angle(), 5); - start = start + Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -(dimension_offset / 4.0)); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + dimension_offset = prefs->getDouble("/tools/measure/offset"); + start = start + Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -dimension_offset); Geom::Point end = end_p + Geom::Point::polar(ray.angle(), -5); - end = end+ Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -(dimension_offset / 4.0)); + end = end+ Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -dimension_offset); guint32 color = 0x000000ff; setLine(start, end, true, &color); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); if (!unit_name.compare("")) { unit_name = "px"; @@ -724,7 +725,8 @@ void MeasureTool::toMarkDimension() Geom::Point middle = Geom::middle_point(start, end); double totallengthval = (end_p - start_p).length(); totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); - gchar *totallength_str = g_strdup_printf(precision_str.str().c_str(), totallengthval, unit_name.c_str()); + double scale = prefs->getDouble("/tools/measure/scale") / 100.0; + gchar *totallength_str = g_strdup_printf(precision_str.str().c_str(), totallengthval * scale, unit_name.c_str()); setLabelText(totallength_str, middle, fontsize, Geom::deg_to_rad(180) - ray.angle()); doc->ensureUpToDate(); DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add global measure line")); @@ -825,6 +827,8 @@ void MeasureTool::setLine(Geom::Point start_point,Geom::Point end_point, bool ma SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); Inkscape::GC::release(repr); item->updateRepr(); + desktop->getSelection()->clear(); + desktop->getSelection()->add(item); } } } @@ -903,13 +907,15 @@ void MeasureTool::setLabelText(const char *value, Geom::Point pos, double fontsi SPCSSAttr *css = sp_repr_css_attr_new(); std::stringstream font_size; font_size.imbue(std::locale::classic()); - font_size << fontsize ; + font_size << fontsize << "px"; sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); sp_repr_css_set_property (css, "font-style", "normal"); sp_repr_css_set_property (css, "font-weight", "normal"); sp_repr_css_set_property (css, "line-height", "125%"); sp_repr_css_set_property (css, "letter-spacing", "0px"); sp_repr_css_set_property (css, "word-spacing", "0px"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); if(measure_repr) { sp_repr_css_set_property (css, "fill", "#FFFFFF"); } else { @@ -953,10 +959,10 @@ void MeasureTool::setLabelText(const char *value, Geom::Point pos, double fontsi sp_repr_css_attr_unref (css); sp_repr_set_svg_double(rgroup, "x", 0); sp_repr_set_svg_double(rgroup, "y", 0); - sp_repr_set_svg_double(rrect, "x", 0); + sp_repr_set_svg_double(rrect, "x", -bbox->width()/2.0); sp_repr_set_svg_double(rrect, "y", -bbox->height()); - sp_repr_set_svg_double(rrect, "width", (bbox->width()) + 6); - sp_repr_set_svg_double(rrect, "height", (bbox->height()) + 6); + sp_repr_set_svg_double(rrect, "width", bbox->width() + 6); + sp_repr_set_svg_double(rrect, "height", bbox->height() + 6); Inkscape::XML::Node *rtextitem = text_item->getRepr(); text_item->deleteObject(); rgroup->addChild(rtextitem, NULL); @@ -1012,7 +1018,7 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool show_in_between = prefs->getBool("/tools/measure/show_in_between"); bool all_layers = prefs->getBool("/tools/measure/all_layers"); - dimension_offset = prefs->getDouble("/tools/measure/offset"); + dimension_offset = 70; Geom::PathVector lineseg; Geom::Path p; p.start(desktop->dt2doc(start_p)); @@ -1102,8 +1108,8 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N if (!unit_name.compare("")) { unit_name = "px"; } - - double fontsize = prefs->getInt("/tools/measure/fontsize") * (96/72); + double scale = prefs->getDouble("/tools/measure/scale") / 100.0; + double fontsize = prefs->getDouble("/tools/measure/fontsize") * (96/72); // Normal will be used for lines and text Geom::Point windowNormal = Geom::unit_vector(Geom::rot90(desktop->d2w(end_p - start_p))); Geom::Point normal = desktop->w2d(windowNormal); @@ -1128,24 +1134,24 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N LabelPlacement placement; placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length(); placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, "px", unit_name); - placement.offset = dimension_offset; + placement.offset = dimension_offset / 2; placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 ); placement.end = placement.start - (normal * placement.offset); placements.push_back(placement); } - + int precision = prefs->getInt("/tools/measure/precision"); // Adjust positions - repositionOverlappingLabels(placements, desktop, windowNormal, fontsize); + repositionOverlappingLabels(placements, desktop, windowNormal, fontsize, precision); for (std::vector::iterator it = placements.begin(); it != placements.end(); ++it) { LabelPlacement &place = *it; // TODO cleanup memory, Glib::ustring, etc.: - int precision = prefs->getInt("/tools/measure/precision"); + std::stringstream precision_str; precision_str.imbue(std::locale::classic()); precision_str << "%." << precision << "f %s"; - gchar *measure_str = g_strdup_printf(precision_str.str().c_str(), place.lengthVal, unit_name.c_str()); + gchar *measure_str = g_strdup_printf(precision_str.str().c_str(), place.lengthVal * scale, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, place.end, @@ -1203,7 +1209,7 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N std::stringstream precision_str; precision_str.imbue(std::locale::classic()); precision_str << "%." << precision << "f %s"; - gchar *totallength_str = g_strdup_printf(precision_str.str().c_str(), totallengthval, unit_name.c_str()); + gchar *totallength_str = g_strdup_printf(precision_str.str().c_str(), totallengthval * scale, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, end_p + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), @@ -1231,10 +1237,10 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N std::stringstream precision_str; precision_str.imbue(std::locale::classic()); precision_str << "%." << precision << "f %s"; - gchar *total_str = g_strdup_printf(precision_str.str().c_str(), totallengthval, unit_name.c_str()); + gchar *total_str = g_strdup_printf(precision_str.str().c_str(), totallengthval * scale, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, - desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * (dimension_offset * 2), + desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * dimension_offset, total_str); sp_canvastext_set_fontsize(canvas_tooltip, fontsize); canvas_tooltip->rgba = 0xffffffff; @@ -1245,7 +1251,7 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); if(to_item) { guint32 background = canvas_tooltip->rgba_background; - setLabelText(total_str, desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * (dimension_offset * 2), fontsize, 0, &background, measure_repr); + setLabelText(total_str, desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * dimension_offset, fontsize, 0, &background, measure_repr); } g_free(total_str); } @@ -1341,34 +1347,34 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N ControlManager &mgr = ControlManager::getManager(); SPCtrlLine *control_line = 0; control_line = mgr.createControlLine(desktop->getTempGroup(), - desktop->doc2dt(intersections[0]) + normal * (dimension_offset * 2), - desktop->doc2dt(intersections[intersections.size() - 1]) + normal * (dimension_offset * 2)); + desktop->doc2dt(intersections[0]) + normal * dimension_offset, + desktop->doc2dt(intersections[intersections.size() - 1]) + normal * dimension_offset); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); if(to_item) { - setLine(desktop->doc2dt(intersections[0]) + normal * (dimension_offset * 2), - desktop->doc2dt(intersections[intersections.size() - 1]) + normal * (dimension_offset * 2), + setLine(desktop->doc2dt(intersections[0]) + normal * dimension_offset, + desktop->doc2dt(intersections[intersections.size() - 1]) + normal * dimension_offset, false, &line_color_primary, measure_repr); } control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(intersections[0]), - desktop->doc2dt(intersections[0]) + normal * (dimension_offset * 2)); + desktop->doc2dt(intersections[0]) + normal * dimension_offset); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); if(to_item) { setLine(desktop->doc2dt(intersections[0]), - desktop->doc2dt(intersections[0]) + normal * (dimension_offset * 2), + desktop->doc2dt(intersections[0]) + normal * dimension_offset, false, &line_color_primary, measure_repr); } control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(intersections[intersections.size() - 1]), - desktop->doc2dt(intersections[intersections.size() - 1]) + normal * (dimension_offset * 2)); + desktop->doc2dt(intersections[intersections.size() - 1]) + normal * dimension_offset); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); if(to_item) { setLine(desktop->doc2dt(intersections[intersections.size() - 1]), - desktop->doc2dt(intersections[intersections.size() - 1]) + normal * (dimension_offset * 2), + desktop->doc2dt(intersections[intersections.size() - 1]) + normal * dimension_offset, false, &line_color_primary, measure_repr); @@ -1397,12 +1403,12 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N ControlManager &mgr = ControlManager::getManager(); SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(measure_text_pos), - desktop->doc2dt(measure_text_pos) - (normal * dimension_offset), + desktop->doc2dt(measure_text_pos) - (normal * dimension_offset / 2), CTLINE_SECONDARY); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); if(to_item) { setLine(desktop->doc2dt(measure_text_pos), - desktop->doc2dt(measure_text_pos) - (normal * dimension_offset), + desktop->doc2dt(measure_text_pos) - (normal * dimension_offset / 2), false, &line_color_secondary, measure_repr); diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 8256abc76..8d7146a46 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -102,6 +102,20 @@ sp_measure_offset_value_changed(GtkAdjustment *adj, GObject *tbl) } } +static void sp_measure_scale_value_changed(GtkAdjustment *adj, GObject *tbl) +{ + SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); + + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt(Glib::ustring("/tools/measure/scale"), + gtk_adjustment_get_value(adj)); + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } + } +} static void sp_measure_precision_value_changed(GtkAdjustment *adj, GObject *tbl) @@ -233,7 +247,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G gtk_action_group_add_action( mainActions, GTK_ACTION(eact)); } - // units label + /* units label */ { EgeOutputAction* act = ege_output_action_new( "measure_units_label", _("Units:"), _("The units to be used for the measurements"), 0 ); ege_output_action_set_use_markup( act, TRUE ); @@ -241,7 +255,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); } - // units menu + /* units menu */ { GtkAction* act = tracker->createAction( "MeasureUnitsAction", _("Units:"), _("The units to be used for the measurements") ); g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(measure_unit_changed), holder ); @@ -261,13 +275,25 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G gtk_action_group_add_action( mainActions, GTK_ACTION(eact)); } + /* Scale */ + { + eact = create_adjustment_action( "MeasureScaleAction", + _("Scale %"), _("Scale %:"), + _("Scale the results"), + "/tools/measure/scale", 100.0, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + 0.0, 90000.0, 1.0, 4.0, + 0, 0, 0, + sp_measure_scale_value_changed, NULL, 0 , 3); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + } /* Offset */ { eact = create_adjustment_action( "MeasureOffsetAction", _("Offset"), _("Offset:"), _("The offset size"), - "/tools/measure/offset", 30.0, + "/tools/measure/offset", 5.0, GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 90000.0, 1.0, 4.0, 0, 0, 0, @@ -275,7 +301,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); } - // ignore_1st_and_last + /* ignore_1st_and_last */ { InkToggleAction* act = ink_toggle_action_new( "MeasureIgnore1stAndLast", _("Ignore first and last"), @@ -286,7 +312,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_ignore_1st_and_last), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - // measure imbetweens + /* measure imbetweens */ { InkToggleAction* act = ink_toggle_action_new( "MeasureInBettween", _("Show measures between items"), @@ -297,7 +323,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_in_between), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - // measure only current layer + /* measure only current layer */ { InkToggleAction* act = ink_toggle_action_new( "MeasureAllLayers", _("Measure all layers"), @@ -308,7 +334,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_all_layers), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - //toogle start end + /* toogle start end */ { InkAction* act = ink_action_new( "MeasureReverse", _("Reverse measure"), @@ -318,7 +344,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_reverse_knots), 0 ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - //to guides + /* to guides */ { InkAction* act = ink_action_new( "MeasureToGuides", _("To guides"), @@ -328,7 +354,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_guides), 0 ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - //to mark dimensions + /* to mark dimensions */ { InkAction* act = ink_action_new( "MeasureMarkDimension", _("Mark Dimension"), @@ -338,7 +364,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_mark_dimension), 0 ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - //to item + /* to item */ { InkAction* act = ink_action_new( "MeasureToItem", _("Convert to item"), diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index e7dd69a28..5d41d3b10 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -341,6 +341,8 @@ static gchar const * ui_descr = " " " " " " + " " + " " " " " " " " -- cgit v1.2.3 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 1c4eee9dacf11acbe1dc9ec1009f46e453aa8725 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Wed, 21 Oct 2015 07:40:23 +0200 Subject: Fix for bug #1498444 (Guides flicker under the mouse after changing the label of any guide) and bug #1469514 (Crash when renaming a guideline label in a new session). Fixed bugs: - https://launchpad.net/bugs/1498444 - https://launchpad.net/bugs/1469514 (bzr r14426) --- src/sp-guide.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index b9c124138..bbdf5f260 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -103,8 +103,8 @@ void SPGuide::set(unsigned int key, const gchar *value) { } break; case SP_ATTR_INKSCAPE_LABEL: - if (this->label) g_free(this->label); - + // this->label already freed in sp_guideline_set_label (src/display/guideline.cpp) + // see bug #1498444, bug #1469514 if (value) { this->label = g_strdup(value); } else { -- 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 aba9f9838aca1f4d062dd0c0f336587accf74b44 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 23 Oct 2015 19:47:28 +0200 Subject: Removing some stringsstreams and free gchars (bzr r14393.3.3) --- src/ui/tools/measure-tool.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 81e1bea7d..87e8d5804 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -210,7 +210,7 @@ void setMeasureItem(Geom::PathVector pathv, bool is_curve, bool markers, guint32 Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *repr; repr = xml_doc->createElement("svg:path"); - gchar const *str = sp_svg_write_path(pathv); + gchar *str = sp_svg_write_path(pathv); SPCSSAttr *css = sp_repr_css_attr_new(); Geom::Coord strokewidth = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse().expansionX(); std::stringstream stroke_width; @@ -249,6 +249,7 @@ void setMeasureItem(Geom::PathVector pathv, bool is_curve, bool markers, guint32 sp_repr_css_attr_unref (css); g_assert( str != NULL ); repr->setAttribute("d", str); + g_free(str); if(measure_repr) { measure_repr->addChild(repr, NULL); Inkscape::GC::release(repr); @@ -408,11 +409,10 @@ void MeasureTool::writeMeasurePoint(Geom::Point point, bool is_start) { if(!namedview) { return; } - Inkscape::SVGOStringStream os; - os << point; - gchar * str = g_strdup(os.str().c_str()); - char const * measure_point = is_start ? "inkscape:measure-start" : "inkscape:measure-end"; + gchar *str = g_strdup_printf("%f,%f", point[Geom::X], point[Geom::Y]); + gchar const *measure_point = is_start ? "inkscape:measure-start" : "inkscape:measure-end"; namedview->setAttribute (measure_point, str); + g_free(str); } //This function is used to reverse the Measure, I do it in two steps because when move the knot the @@ -759,7 +759,7 @@ void MeasureTool::toMarkDimension() if (!unit_name.compare("")) { unit_name = "px"; } - double fontsize = prefs->getInt("/tools/measure/fontsize", 10.0); + double fontsize = prefs->getDouble("/tools/measure/fontsize", 10.0); int precision = prefs->getInt("/tools/measure/precision", 2); std::stringstream precision_str; precision_str.imbue(std::locale::classic()); @@ -770,6 +770,7 @@ void MeasureTool::toMarkDimension() double scale = prefs->getDouble("/tools/measure/scale", 100.0) / 100.0; gchar *totallength_str = g_strdup_printf(precision_str.str().c_str(), totallengthval * scale, unit_name.c_str()); setLabelText(totallength_str, middle, fontsize, Geom::deg_to_rad(180) - ray.angle(), color); + g_free(totallength_str); doc->ensureUpToDate(); DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add global measure line")); } @@ -867,7 +868,7 @@ void MeasureTool::setLabelText(const char *value, Geom::Point pos, double fontsi /* Create */ Inkscape::XML::Node *rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); // otherwise, why bother creating the tspan? + rtspan->setAttribute("sodipodi:role", "line"); SPCSSAttr *css = sp_repr_css_attr_new(); std::stringstream font_size; font_size.imbue(std::locale::classic()); @@ -1199,18 +1200,18 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N for (size_t idx = 0; idx < intersections.size(); ++idx) { setMeasureCanvasItem(desktop->doc2dt(intersections[idx]), to_item, measure_repr); if(to_guides) { - std::stringstream cross_number; - cross_number.imbue(std::locale::classic()); + gchar *cross_number; if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true)) { - cross_number << _("Crossing ") << idx; + cross_number= g_strdup_printf(_("Crossing %d"), idx); } else { - cross_number << _("Crossing ") << idx + 1; + cross_number= g_strdup_printf(_("Crossing %d"), idx + 1); } if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true) && idx == 0) { setGuide(desktop->doc2dt(intersections[idx]), angle + Geom::deg_to_rad(90), ""); } else { - setGuide(desktop->doc2dt(intersections[idx]), angle + Geom::deg_to_rad(90), cross_number.str().c_str()); + setGuide(desktop->doc2dt(intersections[idx]), angle + Geom::deg_to_rad(90), cross_number); } + g_free(cross_number); } } // Since adding goes to the bottom, do all lines last. -- 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 7f606e3eb5e38a645c4dc5e0c22bbe1136a1f674 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 25 Oct 2015 02:55:48 +0100 Subject: Fixed some toolbox definition and minor tweaks (bzr r14393.1.30) --- src/ui/tools/measure-tool.cpp | 23 +++++++++++++++---- src/widgets/measure-toolbar.cpp | 51 ++++++++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 87e8d5804..e6f56674a 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -347,14 +347,20 @@ MeasureTool::MeasureTool() this->knot_end->setStroke(0x0000007f, 0x0000007f, 0x0000007f); this->knot_end->setShape(SP_KNOT_SHAPE_CIRCLE); this->knot_end->updateCtrl(); - Geom::Rect display_area = desktop->get_display_area () ; + Geom::Rect display_area = desktop->get_display_area(); if(display_area.interiorContains(start_p) && display_area.interiorContains(end_p) && end_p != Geom::Point()) { this->knot_start->moveto(start_p); this->knot_start->show(); this->knot_end->moveto(end_p); this->knot_end->show(); showCanvasItems(); + } else { + start_p = Geom::Point(0,0); + end_p = Geom::Point(0,0); + writeMeasurePoint(start_p, true); + writeMeasurePoint(end_p, false); } + this->_knot_start_moved_connection = this->knot_start->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotStartMovedHandler)); this->_knot_start_ungrabbed_connection = this->knot_start->ungrabbed_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotUngrabbedHandler)); this->_knot_end_moved_connection = this->knot_end->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotEndMovedHandler)); @@ -612,7 +618,6 @@ bool MeasureTool::root_handler(GdkEvent* event) case GDK_BUTTON_RELEASE: { this->knot_start->moveto(start_p); this->knot_start->show(); - end_p = end_p; if(last_end) { end_p = desktop->w2d(*last_end); if (event->button.state & GDK_CONTROL_MASK) { @@ -630,6 +635,7 @@ bool MeasureTool::root_handler(GdkEvent* event) this->knot_end->moveto(end_p); this->knot_end->show(); showCanvasItems(); + if (this->grabbed) { sp_canvas_item_ungrab(this->grabbed, event->button.time); this->grabbed = NULL; @@ -698,6 +704,9 @@ void MeasureTool::setMarker(bool isStart) void MeasureTool::toGuides() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !start_p.isFinite() || !end_p.isFinite() || start_p == end_p) { + return; + } SPDocument *doc = desktop->getDocument(); Geom::Point start = desktop->doc2dt(start_p) * desktop->doc2dt(); Geom::Point end = desktop->doc2dt(end_p) * desktop->doc2dt(); @@ -726,12 +735,15 @@ void MeasureTool::toGuides() void MeasureTool::toItem() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !start_p.isFinite() || !end_p.isFinite() || start_p == end_p) { + return; + } SPDocument *doc = desktop->getDocument(); Geom::Ray ray(start_p,end_p); guint32 line_color_primary = 0x0000ff7f; Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *rgroup = xml_doc->createElement("svg:g"); - showCanvasItems(false, true,rgroup); + showCanvasItems(false, true, rgroup); setLine(start_p,end_p, false, line_color_primary, rgroup); SPItem *measure_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(rgroup)); Inkscape::GC::release(rgroup); @@ -744,6 +756,9 @@ void MeasureTool::toItem() void MeasureTool::toMarkDimension() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !start_p.isFinite() || !end_p.isFinite() || start_p == end_p) { + return; + } SPDocument *doc = desktop->getDocument(); setMarkers(); Geom::Ray ray(start_p,end_p); @@ -1218,7 +1233,7 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::N // draw main control line { - setMeasureCanvasControlLine(start_p, end_p, false, CTLINE_SECONDARY, measure_repr); + setMeasureCanvasControlLine(start_p, end_p, false, CTLINE_PRIMARY, measure_repr); double length = std::abs((end_p - start_p).length()); Geom::Point anchorEnd = start_p; anchorEnd[Geom::X] += length; diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 0e083924e..67c128dd2 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -77,7 +77,7 @@ sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl) if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(Glib::ustring("/tools/measure/fontsize"), + prefs->setDouble(Glib::ustring("/tools/measure/fontsize"), gtk_adjustment_get_value(adj)); MeasureTool *mt = get_measure_tool(); if (mt) { @@ -93,7 +93,7 @@ sp_measure_offset_value_changed(GtkAdjustment *adj, GObject *tbl) if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(Glib::ustring("/tools/measure/offset"), + prefs->setDouble(Glib::ustring("/tools/measure/offset"), gtk_adjustment_get_value(adj)); MeasureTool *mt = get_measure_tool(); if (mt) { @@ -108,7 +108,7 @@ static void sp_measure_scale_value_changed(GtkAdjustment *adj, GObject *tbl) if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(Glib::ustring("/tools/measure/scale"), + prefs->setDouble(Glib::ustring("/tools/measure/scale"), gtk_adjustment_get_value(adj)); MeasureTool *mt = get_measure_tool(); if (mt) { @@ -133,7 +133,8 @@ sp_measure_precision_value_changed(GtkAdjustment *adj, GObject *tbl) } } -static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl) +static void +sp_measure_unit_changed(GtkAction* /*act*/, GObject* tbl) { UnitTracker* tracker = reinterpret_cast(g_object_get_data(tbl, "tracker")); Glib::ustring const unit = tracker->getActiveUnit()->abbr; @@ -145,11 +146,12 @@ static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl) } } -static void toggle_ignore_1st_and_last( GtkToggleAction* act, gpointer data ) +static void +sp_toggle_ignore_1st_and_last( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setInt("/tools/measure/ignore_1st_and_last", active); + prefs->setBool("/tools/measure/ignore_1st_and_last", active); SPDesktop *desktop = static_cast(data); if ( active ) { desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Start and end measures inactive.")); @@ -162,11 +164,12 @@ static void toggle_ignore_1st_and_last( GtkToggleAction* act, gpointer data ) } } -static void toggle_only_visible( GtkToggleAction* act, gpointer data ) +static void +sp_toggle_only_visible( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setInt("/tools/measure/only_visible", active); + prefs->setBool("/tools/measure/only_visible", active); SPDesktop *desktop = static_cast(data); if ( active ) { desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Show only visible crossings.")); @@ -179,11 +182,12 @@ static void toggle_only_visible( GtkToggleAction* act, gpointer data ) } } -static void toggle_all_layers( GtkToggleAction* act, gpointer data ) +static void +sp_toggle_all_layers( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setInt("/tools/measure/all_layers", active); + prefs->setBool("/tools/measure/all_layers", active); SPDesktop *desktop = static_cast(data); if ( active ) { desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Use all layers in the measure.")); @@ -196,11 +200,12 @@ static void toggle_all_layers( GtkToggleAction* act, gpointer data ) } } -static void toggle_show_in_between( GtkToggleAction* act, gpointer data ) +static void +sp_toggle_show_in_between( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setInt("/tools/measure/show_in_between", active); + prefs->setBool("/tools/measure/show_in_between", active); SPDesktop *desktop = static_cast(data); if ( active ) { desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Compute all elements.")); @@ -212,28 +217,32 @@ static void toggle_show_in_between( GtkToggleAction* act, gpointer data ) mt->showCanvasItems(); } } -static void sp_reverse_knots(void){ +static void +sp_reverse_knots(void){ MeasureTool *mt = get_measure_tool(); if (mt) { mt->reverseKnots(); } } -static void sp_to_mark_dimension(void){ +static void +sp_to_mark_dimension(void){ MeasureTool *mt = get_measure_tool(); if (mt) { mt->toMarkDimension(); } } -static void sp_to_guides(void){ +static void +sp_to_guides(void){ MeasureTool *mt = get_measure_tool(); if (mt) { mt->toGuides(); } } -static void sp_to_item(void){ +static void +sp_to_item(void){ MeasureTool *mt = get_measure_tool(); if (mt) { mt->toItem(); @@ -275,7 +284,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G /* units menu */ { GtkAction* act = tracker->createAction( "MeasureUnitsAction", _("Units:"), _("The units to be used for the measurements") ); - g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(measure_unit_changed), holder ); + g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_measure_unit_changed), holder ); gtk_action_group_add_action( mainActions, act ); } @@ -326,7 +335,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G INKSCAPE_ICON("draw-geometry-line-segment"), secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/ignore_1st_and_last", true) ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_ignore_1st_and_last), desktop) ; + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_ignore_1st_and_last), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } /* only visible */ @@ -337,7 +346,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G INKSCAPE_ICON("zoom"), secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/only_visible", true) ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_only_visible), desktop) ; + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_only_visible), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } /* measure imbetweens */ @@ -348,7 +357,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G INKSCAPE_ICON("distribute-randomize"), secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/show_in_between", true) ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_in_between), desktop) ; + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_show_in_between), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } /* measure only current layer */ @@ -359,7 +368,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G INKSCAPE_ICON("dialog-layers"), secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/all_layers", true) ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_all_layers), desktop) ; + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_all_layers), desktop) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } /* toogle start end */ -- 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 d3e163d627550bf1016b35d4afb75c024a508922 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 25 Oct 2015 17:54:27 +0100 Subject: Cleanup Spray tool improvements (bzr r14422.3.1) --- src/live_effects/lpe-roughen.cpp | 91 ++++++++++--------- src/live_effects/lpe-roughen.h | 3 +- src/ui/tools/spray-tool.cpp | 187 ++++----------------------------------- src/ui/tools/spray-tool.h | 4 +- src/widgets/spray-toolbar.cpp | 41 +-------- src/widgets/spray-toolbar.h | 2 +- src/widgets/toolbox.cpp | 7 +- 7 files changed, 72 insertions(+), 263 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index cea91509e..55ca77e9c 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,53 +359,55 @@ 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 = 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()); + 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[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) { + 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); } - ray.setPoints(A->pointAt(t) + point_a3, A->pointAt(t + (t / 3)) + point_a3); - point_b1 = randomize(max_lenght, ray.angle()); if(last){ - ray.setPoints(A->finalPoint() + point_b3, A->pointAt(t +((t / 3) * 2)) + point_b3); - point_b2 = randomize(max_lenght, ray.angle()); + 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/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); diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 69a6f0435..e2be5ca4b 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -12,7 +12,6 @@ * Steren GIANNINI (steren.giannini@gmail.com) * Jon A. Cruz * Abhishek Sharma - * Jabiertxo Arraiza * * Copyright (C) 2009 authors * @@ -50,7 +49,6 @@ #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" @@ -59,9 +57,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" @@ -156,8 +151,6 @@ SprayTool::SprayTool() , is_dilating(false) , has_dilated(false) , dilate_area(NULL) - , overlap(false) - , offset(0) { } @@ -230,8 +223,6 @@ 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")) { @@ -269,10 +260,6 @@ 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(); } } @@ -345,64 +332,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 *= 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, - 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); - 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; - } - } - return true; -} - static bool sp_spray_recursive(SPDesktop *desktop, Inkscape::Selection *selection, SPItem *item, @@ -419,10 +348,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, double ratio, double tilt, double rotation_variation, - gint _distrib, - bool overlap, - double offset, - size_t &limit) + gint _distrib) { bool did = false; @@ -445,66 +371,27 @@ 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) { - 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; - //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 + 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); + 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)); - sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale)); + 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 = true; } } @@ -538,13 +425,6 @@ 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); @@ -576,45 +456,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::OptRect a = item->documentVisualBounds(); 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()); - } 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; + 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(); @@ -624,9 +467,6 @@ 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 - if(!clone->attribute("inkscape:spray-origin")){ - clone->setAttribute("inkscape:spray-origin", spray_origin); - } gchar *href_str = g_strdup_printf("#%s", old_repr->attribute("id")); clone->setAttribute("xlink:href", href_str, false); g_free(href_str); @@ -634,12 +474,15 @@ 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); + did = true; } } @@ -686,8 +529,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); - 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)) { did = true; } } diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index a46f2cc90..8df730201 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -12,7 +12,6 @@ * Benoît LAVORATA * Vincent MONTAGNE * Pierre BARBRY-BLOT - * Jabiertxo Arraiza JABIERTXOF * * Copyright (C) 2009 authors * @@ -87,8 +86,7 @@ public: bool has_dilated; Geom::Point last_push; SPCanvasItem *dilate_area; - bool overlap; - double offset; + 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 6a062bc46..183814b7e 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -15,11 +15,10 @@ * Tavmjong Bah * Abhishek Sharma * Kris De Gussem - * Jabiertxo Arraiza * * Copyright (C) 2004 David Turner * Copyright (C) 2003 MenTaLguY - * Copyright (C) 1999-2015 authors + * Copyright (C) 1999-2011 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -103,19 +102,6 @@ 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_toggle_not_overlap( GtkToggleAction* act, gpointer data ) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - 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) { @@ -281,31 +267,6 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj g_object_set_data( holder, "spray_scale", eact ); } - { - 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", - _("Offset"), _("Offset:"), - _("Base offset size"), - "/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) ); - } - - } diff --git a/src/widgets/spray-toolbar.h b/src/widgets/spray-toolbar.h index 30d8233ca..d1d5c7b4c 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-2015 authors + * Copyright (C) 1999-2011 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 f512819e9..a1c32352c 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -16,11 +16,10 @@ * Tavmjong Bah * Abhishek Sharma * Kris De Gussem - * Jabiertxo Arraiza * * Copyright (C) 2004 David Turner * Copyright (C) 2003 MenTaLguY - * Copyright (C) 1999-2015 authors + * Copyright (C) 1999-2011 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -318,10 +317,6 @@ static gchar const * ui_descr = " " " " " " - " " - " " - " " - " " " " -- cgit v1.2.3 From 443350ec9520e6cf501c8d1137d276df18f58b4f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 25 Oct 2015 23:57:41 +0100 Subject: working on roughen (bzr r14422.3.2) --- src/live_effects/lpe-roughen.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 55ca77e9c..37a244603 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -201,15 +201,15 @@ Geom::Point LPERoughen::randomize(double max_lenght, bool is_node) Geom::Point LPERoughen::randomize(double lenght, Geom::Point start, Geom::Point end) { - int angle = (int)max_smooth_angle; - if (angle == 0){ - angle = 1; + int angle = 0; + if((int)max_smooth_angle != 0){ + angle = sign(Geom::deg_to_rad(rand() % (int)max_smooth_angle)); } 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; + return Geom::Point::polar(ray.angle() + angle , lenght) + start; } void LPERoughen::doEffect(SPCurve *curve) @@ -360,7 +360,7 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point 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_b2 = seg2[2]; point_b3 = seg2[3] + point_b3; point_a3 = seg1[3] + point_a3; Geom::Ray ray(prev,A->initialPoint()); @@ -371,7 +371,10 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point if(last){ Geom::Path b2(point_b3); b2.appendNew(point_a3); - point_b2 = randomize(max_lenght, point_b3, b2.pointAt(1.0/3.0)); + double dist = Geom::distance(b2.pointAt(1.0/3.0), point_b3); + ray.setPoints(point_b3, b2.pointAt(1.0/3.0)); + point_b2 = point_b3 + Geom::Point::polar(ray.angle(), dist); + point_b2 = randomize(max_lenght, point_b3, point_b2); } ray.setPoints(point_b1, point_a3); point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); @@ -396,7 +399,10 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point if(last){ Geom::Path b2(point_b3); b2.appendNew(point_a3); - point_b2 = randomize(max_lenght, point_b3, b2.pointAt(1.0/3.0)); + double dist = Geom::distance(b2.pointAt(1.0/3.0), point_b3); + ray.setPoints(point_b3, b2.pointAt(1.0/3.0)); + point_b2 = point_b3 + Geom::Point::polar(ray.angle(), dist); + point_b2 = randomize(max_lenght, point_b3, point_b2); } ray.setPoints(point_b1, point_a3); point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); -- 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 0d4e511c524d9102d90adbf2defea4f644eb3edd Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Mon, 26 Oct 2015 23:50:52 +0100 Subject: add gtk3 experimental support in CMake Fixed bugs: - https://launchpad.net/bugs/1509969 (bzr r14430) --- src/CMakeLists.txt | 5 ++- src/libgdl/CMakeLists.txt | 87 +++++++++++++++++++++++---------------------- src/ui/dialog/text-edit.cpp | 14 ++++++++ 3 files changed, 63 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ec7713464..30af55925 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -531,6 +531,10 @@ endif() add_dependencies(inkscape inkscape_version) +if (NOT "${WITH_EXT_GDL}") + list (APPEND INKSCAPE_LIBS "gdl_LIB") +endif() + set(INKSCAPE_TARGET_LIBS # order from automake #sp_LIB @@ -542,7 +546,6 @@ set(INKSCAPE_TARGET_LIBS croco_LIB avoid_LIB - gdl_LIB cola_LIB vpsc_LIB livarot_LIB diff --git a/src/libgdl/CMakeLists.txt b/src/libgdl/CMakeLists.txt index d59d017f0..a452320f7 100644 --- a/src/libgdl/CMakeLists.txt +++ b/src/libgdl/CMakeLists.txt @@ -1,47 +1,50 @@ +if (NOT "${WITH_EXT_GDL}") -set(libgdl_SRC - gdl-dock-bar.c - gdl-dock-item-button-image.c - gdl-dock-item-grip.c - gdl-dock-item.c - gdl-dock-master.c - gdl-dock-notebook.c - gdl-dock-object.c - gdl-dock-paned.c - gdl-dock-placeholder.c - gdl-dock-tablabel.c - gdl-dock.c - gdl-i18n.c - gdl-switcher.c - libgdlmarshal.c - libgdltypebuiltins.c + set(libgdl_SRC + gdl-dock-bar.c + gdl-dock-item-button-image.c + gdl-dock-item-grip.c + gdl-dock-item.c + gdl-dock-master.c + gdl-dock-notebook.c + gdl-dock-object.c + gdl-dock-paned.c + gdl-dock-placeholder.c + gdl-dock-tablabel.c + gdl-dock.c + gdl-i18n.c + gdl-switcher.c + libgdlmarshal.c + libgdltypebuiltins.c - # ------- - # Headers - gdl-dock-bar.h - gdl-dock-item-button-image.h - gdl-dock-item-grip.h - gdl-dock-item.h - gdl-dock-master.h - gdl-dock-notebook.h - gdl-dock-object.h - gdl-dock-paned.h - gdl-dock-placeholder.h - gdl-dock-tablabel.h - gdl-dock.h - gdl-i18n.h - gdl-switcher.h - gdl.h - libgdlmarshal.h - libgdltypebuiltins.h -) + # ------- + # Headers + gdl-dock-bar.h + gdl-dock-item-button-image.h + gdl-dock-item-grip.h + gdl-dock-item.h + gdl-dock-master.h + gdl-dock-notebook.h + gdl-dock-object.h + gdl-dock-paned.h + gdl-dock-placeholder.h + gdl-dock-tablabel.h + gdl-dock.h + gdl-i18n.h + gdl-switcher.h + gdl.h + libgdlmarshal.h + libgdltypebuiltins.h + ) -if(WIN32) - list(APPEND libgdl_SRC - gdl-win32.c - gdl-win32.h - ) -endif() + if(WIN32) + list(APPEND libgdl_SRC + gdl-win32.c + gdl-win32.h + ) + endif() + + add_inkscape_lib(gdl_LIB "${libgdl_SRC}") -add_inkscape_lib(gdl_LIB "${libgdl_SRC}") +endif() diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index 7575cc854..cf53e1441 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -175,6 +175,19 @@ TextEdit::TextEdit() gtk_text_view_set_wrap_mode ((GtkTextView *) text_view, GTK_WRAP_WORD); #ifdef WITH_GTKSPELL +#ifdef WITH_GTKMM_3_0 +/* + TODO: Use computed xml:lang attribute of relevant element, if present, to specify the + language (either as 2nd arg of gtkspell_new_attach, or with explicit + gtkspell_set_language call in; see advanced.c example in gtkspell docs). + onReadSelection looks like a suitable place. +*/ + GtkSpellChecker * speller = gtk_spell_checker_new(); + + if (! gtk_spell_checker_attach(speller, GTK_TEXT_VIEW(text_view))) { + g_print("gtkspell error:\n"); + } +#else GError *error = NULL; /* @@ -187,6 +200,7 @@ TextEdit::TextEdit() g_print("gtkspell error: %s\n", error->message); g_error_free(error); } +#endif #endif gtk_widget_set_size_request (text_view, -1, 64); -- 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 a853619b54d05d6cc785a12fa747a3e702122b69 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 28 Oct 2015 21:28:43 +0100 Subject: typo (bzr r14431) --- src/live_effects/lpe-simplify.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index f6842a030..2d79d5b34 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -29,7 +29,7 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject) : Effect(lpeobject), steps(_("Steps:"),_("Change number of simplify steps "), "steps", &wr, this,1), threshold(_("Roughly threshold:"), _("Roughly threshold:"), "threshold", &wr, this, 0.003), - smooth_angles(_("Smooth angles:"), _("Max degree difference on handles to preform a smooth"), "smooth_angles", &wr, this, 20.), + smooth_angles(_("Smooth angles:"), _("Max degree difference on handles to perform a smooth"), "smooth_angles", &wr, this, 20.), helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 5), simplify_individual_paths(_("Paths separately"), _("Simplifying paths (separately)"), "simplify_individual_paths", &wr, this, false, "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), -- cgit v1.2.3 From 2e1f86061452fc6cad648a3370236bf2cb1f1a7d Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 28 Oct 2015 21:43:30 +0100 Subject: static code analysis (bzr r14432) --- src/conn-avoid-ref.cpp | 2 +- src/desktop-style.cpp | 36 ++++++++++++++++++------------------ src/display/canvas-text.cpp | 6 +++++- src/display/curve.cpp | 2 +- src/live_effects/lpe-taperstroke.cpp | 3 +-- src/sp-filter.cpp | 2 +- src/uri.cpp | 2 +- src/uri.h | 2 +- src/widgets/sp-xmlview-attr-list.cpp | 2 ++ 9 files changed, 31 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp index ec9aba793..4c9665fa0 100644 --- a/src/conn-avoid-ref.cpp +++ b/src/conn-avoid-ref.cpp @@ -253,7 +253,7 @@ static std::vector approxItemWithPoints(SPItem const *item, const G SPGroup* group = SP_GROUP(item); // consider all first-order children std::vector itemlist = sp_item_group_item_list(group); - for (std::vector::const_iterator i = itemlist.begin(); i != itemlist.end(); i++) { + for (std::vector::const_iterator i = itemlist.begin(); i != itemlist.end(); ++i) { SPItem* child_item = *i; std::vector child_points = approxItemWithPoints(child_item, item_transform * child_item->transform); poly_points.insert(poly_points.end(), child_points.begin(), child_points.end()); diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 02c18339b..e66da90fb 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -195,7 +195,7 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write sp_css_attr_unset_uris(css_write); prefs->mergeStyle("/desktop/style", css_write); std::vector const itemlist = desktop->selection->itemList(); - for (std::vector::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) { + for (std::vector::const_iterator i = itemlist.begin(); i!= itemlist.end(); ++i) { /* last used styles for 3D box faces are stored separately */ SPObject *obj = *i; Box3DSide *side = dynamic_cast(obj); @@ -235,7 +235,7 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write css_no_text = sp_css_attr_unset_text(css_no_text); std::vector const itemlist = desktop->selection->itemList(); - for (std::vector::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) { + for (std::vector::const_iterator i = itemlist.begin(); i!= itemlist.end(); ++i) { SPItem *item = *i; // If not text, don't apply text attributes (can a group have text attributes? Yes! FIXME) @@ -447,7 +447,7 @@ stroke_average_width (const std::vector &objects) gdouble avgwidth = 0.0; bool notstroked = true; int n_notstroked = 0; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPItem *item = *i; if (!item) { continue; @@ -513,7 +513,7 @@ objects_query_fillstroke (const std::vector &objects, SPStyle *style_re prev[0] = prev[1] = prev[2] = 0.0; bool same_color = true; - for (std::vector::const_iterator i = objects.begin(); i!= objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i!= objects.end(); ++i) { SPObject *obj = *i; if (!obj) { continue; @@ -697,7 +697,7 @@ objects_query_opacity (const std::vector &objects, SPStyle *style_res) guint opacity_items = 0; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!obj) { continue; @@ -753,7 +753,7 @@ objects_query_strokewidth (const std::vector &objects, SPStyle *style_r int n_stroked = 0; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!obj) { continue; @@ -827,7 +827,7 @@ objects_query_miterlimit (const std::vector &objects, SPStyle *style_re gdouble prev_ml = -1; bool same_ml = true; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!dynamic_cast(obj)) { continue; @@ -886,7 +886,7 @@ objects_query_strokecap (const std::vector &objects, SPStyle *style_res bool same_cap = true; int n_stroked = 0; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!dynamic_cast(obj)) { continue; @@ -940,7 +940,7 @@ objects_query_strokejoin (const std::vector &objects, SPStyle *style_re bool same_join = true; int n_stroked = 0; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!dynamic_cast(obj)) { continue; @@ -1003,7 +1003,7 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r int texts = 0; int no_size = 0; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!isTextualItem(obj)) { @@ -1122,7 +1122,7 @@ objects_query_fontstyle (const std::vector &objects, SPStyle *style_res int texts = 0; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!isTextualItem(obj)) { @@ -1192,7 +1192,7 @@ objects_query_fontvariants (const std::vector &objects, SPStyle *style_ caps_res->value = 0; numeric_res->value = 0; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!isTextualItem(obj)) { @@ -1268,7 +1268,7 @@ objects_query_fontfeaturesettings (const std::vector &objects, SPStyle } style_res->font_feature_settings.set = FALSE; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; // std::cout << " " << reinterpret_cast(i->data)->getId() << std::endl; @@ -1336,7 +1336,7 @@ objects_query_baselines (const std::vector &objects, SPStyle *style_res int texts = 0; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!isTextualItem(obj)) { @@ -1424,7 +1424,7 @@ objects_query_fontfamily (const std::vector &objects, SPStyle *style_re } style_res->font_family.set = FALSE; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; // std::cout << " " << reinterpret_cast(i->data)->getId() << std::endl; @@ -1480,7 +1480,7 @@ objects_query_fontspecification (const std::vector &objects, SPStyle *s } style_res->font_specification.set = FALSE; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; // std::cout << " " << reinterpret_cast(i->data)->getId() << std::endl; @@ -1538,7 +1538,7 @@ objects_query_blend (const std::vector &objects, SPStyle *style_res) bool same_blend = true; guint items = 0; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!obj) { continue; @@ -1628,7 +1628,7 @@ objects_query_blur (const std::vector &objects, SPStyle *style_res) guint blur_items = 0; guint items = 0; - for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!obj) { continue; diff --git a/src/display/canvas-text.cpp b/src/display/canvas-text.cpp index 5ad87b4ef..2c29fc207 100644 --- a/src/display/canvas-text.cpp +++ b/src/display/canvas-text.cpp @@ -266,10 +266,14 @@ sp_canvastext_set_coords (SPCanvasText *ct, gdouble x0, gdouble y0) void sp_canvastext_set_coords (SPCanvasText *ct, const Geom::Point start) { - Geom::Point pos = ct->desktop->doc2dt(start); + Geom::Point pos; g_return_if_fail (ct != NULL); g_return_if_fail (SP_IS_CANVASTEXT (ct)); + + if (ct && ct->desktop) { + pos = ct->desktop->doc2dt(start); + } if (DIFFER (pos[0], ct->s[Geom::X]) || DIFFER (pos[1], ct->s[Geom::Y])) { ct->s[Geom::X] = pos[0]; diff --git a/src/display/curve.cpp b/src/display/curve.cpp index 3024d1276..b6c387034 100644 --- a/src/display/curve.cpp +++ b/src/display/curve.cpp @@ -496,7 +496,7 @@ SPCurve::append(SPCurve const *curve2, _pathv.push_back( (*it) ); } - for (it++; it != curve2->_pathv.end(); ++it) { + for (++it; it != curve2->_pathv.end(); ++it) { _pathv.push_back( (*it) ); } } else { diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index ef616f802..f2ddd4929 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -408,9 +408,8 @@ Piecewise > stretch_along(Piecewise > pwd2_in, Geom::Path n = force_continuity(remove_short_cuts(n,.1)); int nbCopies = 0; - double scaling = 1; + double scaling = (uskeleton.domain().extent() - toffset)/pattBndsX->extent(); nbCopies = 1; - scaling = (uskeleton.domain().extent() - toffset)/pattBndsX->extent(); double pattWidth = pattBndsX->extent() * scaling; diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index 1bde69dd1..c17c67fc5 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -246,7 +246,7 @@ void SPFilter::update(SPCtx *ctx, guint flags) { } childflags &= SP_OBJECT_MODIFIED_CASCADE; std::vector l(this->childList(true, SPObject::ActionUpdate)); - for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ + for(std::vector::const_iterator i=l.begin();i!=l.end();++i){ SPObject *child = *i; if( SP_IS_FILTER_PRIMITIVE( child ) ) { child->updateDisplay(ctx, childflags); diff --git a/src/uri.cpp b/src/uri.cpp index 2eaf4ecc1..49bdab63c 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -148,7 +148,7 @@ gchar *URI::to_native_filename(gchar const* uri) throw(BadURIException) * Does not check if the returned path is the local document's path (local) * and thus redundent. Caller is expected to check against the document's path. */ -const std::string URI::getFullPath(std::string const base) const { +const std::string URI::getFullPath(std::string const &base) const { if (!_impl->getPath()) { return ""; } diff --git a/src/uri.h b/src/uri.h index cee1baa09..bdf5f1baa 100644 --- a/src/uri.h +++ b/src/uri.h @@ -104,7 +104,7 @@ public: static char *to_native_filename(char const* uri) throw(BadURIException); - const std::string getFullPath(std::string const base) const; + const std::string getFullPath(std::string const &base) const; char *toNativeFilename() const throw(BadURIException); diff --git a/src/widgets/sp-xmlview-attr-list.cpp b/src/widgets/sp-xmlview-attr-list.cpp index dd763aea5..a4c00db7c 100644 --- a/src/widgets/sp-xmlview-attr-list.cpp +++ b/src/widgets/sp-xmlview-attr-list.cpp @@ -145,6 +145,7 @@ void sp_xmlview_attr_list_select_row_by_key(SPXMLViewAttrList * list, const gcha break; } valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(list->store), &iter); + // cppcheck-suppress nullPointer // a string was copied in n by gtk_tree_model_get if (n) { g_free(n); } @@ -181,6 +182,7 @@ event_attr_changed (Inkscape::XML::Node * /*repr*/, } row++; valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(list->store), &iter); + // cppcheck-suppress nullPointer // a string was copied in n by gtk_tree_model_get if (n) { g_free(n); } -- 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 cb75f9913807063d2c15d68b4b1fcbb7ac9df408 Mon Sep 17 00:00:00 2001 From: mathog <> Date: Thu, 29 Oct 2015 12:47:45 -0700 Subject: patch for bug 1511508 (bzr r14435) --- src/extension/internal/emf-inout.cpp | 5 +---- src/extension/internal/emf-print.cpp | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index e88cf3d42..68b38f5ee 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -1174,10 +1174,7 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index) if (!d->dc[d->level].style.stroke_dasharray.values.empty() && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dasharray.values!=d->dc[d->level-1].style.stroke_dasharray.values))) d->dc[d->level].style.stroke_dasharray.values.clear(); for (unsigned int i=0; ielp.elpNumEntries; i++) { -// Doing it this way typically results in a pattern that is tiny, better to assume the array -// is the same scale as for dot/dash below, that is, no scaling should be applied -// double dash_length = pix_to_abs_size( d, pEmr->elp.elpStyleEntry[i] ); - double dash_length = pEmr->elp.elpStyleEntry[i]; + double dash_length = pix_to_abs_size( d, pEmr->elp.elpStyleEntry[i] ); d->dc[d->level].style.stroke_dasharray.values.push_back(dash_length); } d->dc[d->level].style.stroke_dasharray.set = 1; diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index 5b8aae655..cc798cc5f 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -708,7 +708,7 @@ int PrintEmf::create_pen(SPStyle const *style, const Geom::Affine &transform) n_dash = style->stroke_dasharray.values.size(); dash = new uint32_t[n_dash]; for (i = 0; i < n_dash; i++) { - dash[i] = style->stroke_dasharray.values[i]; + dash[i] = MAX(1, (uint32_t) round(scale * style->stroke_dasharray.values[i] * PX2WORLD)); } } } -- cgit v1.2.3 From fd5fce801e86b3e9ab0d56a702e89b11dbf7484e Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Thu, 29 Oct 2015 23:24:26 +0100 Subject: static code analysis (bzr r14436) --- src/display/canvas-text.cpp | 8 +--- src/extension/execution-env.cpp | 2 +- src/extension/internal/cairo-renderer.cpp | 2 +- src/extension/internal/latex-text-renderer.cpp | 2 +- src/live_effects/lpe-fill-between-many.cpp | 2 +- .../parameter/filletchamferpointarray.cpp | 10 ++-- src/pure-transform.h | 56 +++++++++++----------- src/selection-describer.cpp | 6 +-- src/snap.cpp | 2 +- src/sp-hatch.cpp | 2 +- src/unclump.cpp | 10 ++-- 11 files changed, 47 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/display/canvas-text.cpp b/src/display/canvas-text.cpp index 2c29fc207..7c019caf5 100644 --- a/src/display/canvas-text.cpp +++ b/src/display/canvas-text.cpp @@ -266,14 +266,10 @@ sp_canvastext_set_coords (SPCanvasText *ct, gdouble x0, gdouble y0) void sp_canvastext_set_coords (SPCanvasText *ct, const Geom::Point start) { - Geom::Point pos; - - g_return_if_fail (ct != NULL); + g_return_if_fail (ct && ct->desktop); g_return_if_fail (SP_IS_CANVASTEXT (ct)); - if (ct && ct->desktop) { - pos = ct->desktop->doc2dt(start); - } + Geom::Point pos = ct->desktop->doc2dt(start); if (DIFFER (pos[0], ct->s[Geom::X]) || DIFFER (pos[1], ct->s[Geom::Y])) { ct->s[Geom::X] = pos[0]; diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index 29c2b5537..27d19fdff 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -61,7 +61,7 @@ ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Imp if (desktop != NULL) { std::vector selected = desktop->getSelection()->itemList(); - for(std::vector::const_iterator x = selected.begin(); x != selected.end(); x++){ + for(std::vector::const_iterator x = selected.begin(); x != selected.end(); ++x){ Glib::ustring selected_id; selected_id = (*x)->getId(); _selected.insert(_selected.end(), selected_id); diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 5a5553e97..a4561fd11 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -295,7 +295,7 @@ static void sp_group_render(SPGroup *group, CairoRenderContext *ctx) TRACE(("sp_group_render opacity: %f\n", SP_SCALE24_TO_FLOAT(item->style->opacity.value))); std::vector l(group->childList(false)); - for(std::vector::const_iterator x = l.begin(); x!= l.end(); x++){ + for(std::vector::const_iterator x = l.begin(); x!= l.end(); ++x){ SPItem *item = dynamic_cast(*x); if (item) { renderer->renderItem(ctx, item); diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index 5933dd526..dec75aeb6 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -229,7 +229,7 @@ LaTeXTextRenderer::writePostamble() void LaTeXTextRenderer::sp_group_render(SPGroup *group) { std::vector l = (group->childList(false)); - for(std::vector::const_iterator x = l.begin(); x != l.end(); x++){ + for(std::vector::const_iterator x = l.begin(); x != l.end(); ++x){ SPItem *item = dynamic_cast(*x); if (item) { renderItem(item); diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index 3e0810cfc..574ec3580 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -37,7 +37,7 @@ void LPEFillBetweenMany::doEffect (SPCurve * curve) { Geom::PathVector res_pathv; SPItem * firstObj = NULL; - for (std::vector::iterator iter = linked_paths._vector.begin(); iter != linked_paths._vector.end(); iter++) { + for (std::vector::iterator iter = linked_paths._vector.begin(); iter != linked_paths._vector.end(); ++iter) { SPObject *obj; if ((*iter)->ref.isAttached() && (obj = (*iter)->ref.getObject()) && SP_IS_ITEM(obj) && !(*iter)->_pathvector.empty()) { Geom::Path linked_path; diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index b089213fd..399307502 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -159,9 +159,8 @@ void FilletChamferPointArrayParam::recalculate_controlpoints_for_new_pwd2( //todo: if the path remove some nodes whith the result of a straight //line but with handles, the node inserted into dont fire the knot // because is not handle as cusp node by get_nodetype function - bool this_is_line = true; bool next_is_line = is_straight_curve(*curve_it1); - this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); + bool this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); nodetype = get_nodetype((*path_it)[counterCurves - 1], *curve_it1); if (this_is_line || next_is_line) { nodetype = NODE_CUSP; @@ -307,9 +306,8 @@ void FilletChamferPointArrayParam::recalculate_knots( nodetype = NODE_NONE; } } else { - bool this_is_line = true; bool next_is_line = is_straight_curve(*curve_it1); - this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); + bool this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); nodetype = get_nodetype((*path_it)[counterCurves - 1], *curve_it1); if (this_is_line || next_is_line) { nodetype = NODE_CUSP; @@ -467,12 +465,12 @@ double FilletChamferPointArrayParam::len_to_rad(int index, double len) Geom::Point endArcPoint = B->toSBasis().valueAt(times[2]); Curve *knotCurve1 = A->portion(times[0], times[1]); Curve *knotCurve2 = B->portion(times[2], 1); - Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); + Geom::CubicBezier const *cubic1 = dynamic_cast(knotCurve1); Ray ray1(startArcPoint, A->finalPoint()); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } - Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); + Geom::CubicBezier const *cubic2 = dynamic_cast(knotCurve2); Ray ray2(B->initialPoint(), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); diff --git a/src/pure-transform.h b/src/pure-transform.h index 8ea74ce76..f973a95b1 100644 --- a/src/pure-transform.h +++ b/src/pure-transform.h @@ -54,10 +54,7 @@ public: // PureTranslate(); // Default constructor // PureTranslate(PureTranslate const &); // Copy constructor virtual ~PureTranslate() {}; - PureTranslate(Geom::Point vector = Geom::Point()) { - _vector = vector; - _vector_snapped = vector; - } + PureTranslate(Geom::Point vector = Geom::Point()) : _vector(vector), _vector_snapped(vector) {} Geom::Point getTranslationSnapped() {return _vector_snapped;} // PureTranslate * clone () const {return new PureTranslate(*this);} @@ -100,12 +97,12 @@ public: // PureScale(PureScale const &); // Copy constructor virtual ~PureScale() {}; - PureScale(Geom::Scale scale, Geom::Point origin, bool uniform) { - _scale = scale; - _scale_snapped = scale; - _origin = origin; - _uniform = uniform; - } + PureScale(Geom::Scale scale, Geom::Point origin, bool uniform) : + _scale (scale), + _scale_snapped (scale), + _origin (origin), + _uniform (uniform) + {} Geom::Scale getScaleSnapped() {return _scale_snapped;} // PureScale * clone () const {return new PureScale (*this);} @@ -142,12 +139,13 @@ protected: public: virtual ~PureStretchConstrained() {}; - PureStretchConstrained(Geom::Coord magnitude, Geom::Point origin, Geom::Dim2 direction, bool uniform) { - _magnitude = magnitude; - _origin = origin; - _direction = direction; - _uniform = uniform; - _stretch_snapped = Geom::Scale(magnitude, magnitude); + PureStretchConstrained(Geom::Coord magnitude, Geom::Point origin, Geom::Dim2 direction, bool uniform) : + _magnitude (magnitude), + _stretch_snapped (Geom::Scale(magnitude, magnitude)), + _origin (origin), + _direction (direction), + _uniform (uniform) + { if (not uniform) { _stretch_snapped[1-direction] = 1.0; } @@ -178,13 +176,13 @@ protected: public: virtual ~PureSkewConstrained() {}; - PureSkewConstrained(Geom::Coord skew, Geom::Coord scale, Geom::Point origin, Geom::Dim2 direction) { - _skew = skew; - _skew_snapped = skew; - _scale = scale; - _origin = origin; - _direction = direction; - }; + PureSkewConstrained(Geom::Coord skew, Geom::Coord scale, Geom::Point origin, Geom::Dim2 direction) : + _skew (skew), + _skew_snapped (skew), + _scale (scale), + _origin (origin), + _direction (direction) + {}; Geom::Coord getSkewSnapped() {return _skew_snapped;} @@ -212,12 +210,12 @@ public: // PureRotate(PureRotate const &); // Copy constructor virtual ~PureRotateConstrained() {}; - PureRotateConstrained(double angle, Geom::Point origin) { - _origin = origin; - _angle = angle; // in radians! - _angle_snapped = angle; - _uniform = true; // We do not yet allow for simultaneous rotation and scaling - } + PureRotateConstrained(double angle, Geom::Point origin) : + _angle (angle), // in radians! + _angle_snapped (angle), + _origin (origin), + _uniform (true) // We do not yet allow for simultaneous rotation and scaling + {} double getAngleSnapped() {return _angle_snapped;} diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index 8304db684..ddc7a0d10 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -46,7 +46,7 @@ char* collect_terms (const std::vector &items) std::stringstream ss; bool first = true; - for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();++iter ) { SPItem *item = *iter; if (item) { const char *term = item->displayName(); @@ -65,7 +65,7 @@ static int count_terms (const std::vector &items) { GSList *check = NULL; int count=0; - for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();++iter ) { SPItem *item = *iter; if (item) { const char *term = item->displayName(); @@ -82,7 +82,7 @@ static int count_terms (const std::vector &items) static int count_filtered (const std::vector &items) { int count=0; - for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();++iter ) { SPItem *item = *iter; if (item) { count += item->isFiltered(); diff --git a/src/snap.cpp b/src/snap.cpp index 5a4a047b2..4721283c3 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -710,7 +710,7 @@ void SnapManager::setupIgnoreSelection(SPDesktop const *desktop, Inkscape::Selection *sel = _desktop->selection; std::vector const items = sel->itemList(); - for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i=items.begin();i!=items.end();++i) { _items_to_ignore.push_back(*i); } } diff --git a/src/sp-hatch.cpp b/src/sp-hatch.cpp index ea4c5865a..2d938618c 100644 --- a/src/sp-hatch.cpp +++ b/src/sp-hatch.cpp @@ -113,7 +113,7 @@ void SPHatch::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) SPHatchPath *path_child = dynamic_cast(document->getObjectByRepr(child)); if (path_child) { - for (ViewIterator iter = _display.begin(); iter != _display.end(); iter++) { + for (ViewIterator iter = _display.begin(); iter != _display.end(); ++iter) { Geom::OptInterval extents = _calculateStripExtents(iter->bbox); Inkscape::DrawingItem *ac = path_child->show(iter->arenaitem->drawing(), iter->key, extents); diff --git a/src/unclump.cpp b/src/unclump.cpp index 81c958937..2c6840425 100644 --- a/src/unclump.cpp +++ b/src/unclump.cpp @@ -172,7 +172,7 @@ static double unclump_average (SPItem *item, std::list &others) { int n = 0; double sum = 0; - for (std::list::const_iterator i = others.begin(); i != others.end();i++) { + for (std::list::const_iterator i = others.begin(); i != others.end();++i) { SPItem *other = *i; if (other == item) @@ -196,7 +196,7 @@ static SPItem *unclump_closest (SPItem *item, std::list &others) double min = HUGE_VAL; SPItem *closest = NULL; - for (std::list::const_iterator i = others.begin(); i != others.end();i++) { + for (std::list::const_iterator i = others.begin(); i != others.end();++i) { SPItem *other = *i; if (other == item) @@ -219,7 +219,7 @@ static SPItem *unclump_farest (SPItem *item, std::list &others) { double max = -HUGE_VAL; SPItem *farest = NULL; - for (std::list::const_iterator i = others.begin(); i != others.end();i++) { + for (std::list::const_iterator i = others.begin(); i != others.end();++i) { SPItem *other = *i; if (other == item) @@ -259,7 +259,7 @@ unclump_remove_behind (SPItem *item, SPItem *closest, std::list &rest) double val_item = A * it[Geom::X] + B * it[Geom::Y] + C; std::vector out; - for (std::list::const_reverse_iterator i = rest.rbegin(); i != rest.rend();i++) { + for (std::list::const_reverse_iterator i = rest.rbegin(); i != rest.rend();++i) { SPItem *other = *i; if (other == item) @@ -336,7 +336,7 @@ unclump (std::vector &items) c_cache.clear(); wh_cache.clear(); - for (std::vector::const_iterator i = items.begin(); i != items.end();i++) { // for each original/clone x: + for (std::vector::const_iterator i = items.begin(); i != items.end();++i) { // for each original/clone x: SPItem *item = *i; std::list nei; -- 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 e40c7e81cc683c8c937486c4a53f9758752bbbe6 Mon Sep 17 00:00:00 2001 From: Yuri Chornoivan <> Date: Sun, 1 Nov 2015 13:49:27 +0100 Subject: Typo fix (bzr r14439) --- src/live_effects/lpe-roughen.cpp | 2 +- src/live_effects/lpe-transform_2pts.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index cea91509e..29cfc9839 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -63,7 +63,7 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) "max_smooth_angle", &wr, this, 20), shift_nodes(_("Shift nodes"), _("Shift nodes"), "shift_nodes", &wr, this, true), - fixed_displacement(_("Fixed displacement"), _("Fixed displacement, 1/3 of segment lenght"), + fixed_displacement(_("Fixed displacement"), _("Fixed displacement, 1/3 of segment length"), "fixed_displacement", &wr, this, false), spray_tool_friendly(_("Spray Tool friendly"), _("For use with spray tool"), "spray_tool_friendly", &wr, this, false) diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 8326bd6f1..f2b756567 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -30,13 +30,13 @@ LPETransform2Pts::LPETransform2Pts(LivePathEffectObject *lpeobject) : Effect(lpeobject), elastic(_("Elastic"), _("Elastic transform mode"), "elastic", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), from_original_width(_("From original width"), _("From original width"), "from_original_width", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), - lock_lenght(_("Lock lenght"), _("Lock lenght to current distance"), "lock_lenght", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), + lock_lenght(_("Lock length"), _("Lock length to current distance"), "lock_lenght", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), lock_angle(_("Lock angle"), _("Lock angle"), "lock_angle", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), flip_horizontal(_("Flip horizontal"), _("Flip horizontal"), "flip_horizontal", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), flip_vertical(_("Flip vertical"), _("Flip vertical"), "flip_vertical", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), start(_("Start"), _("Start point"), "start", &wr, this, "Start point"), end(_("End"), _("End point"), "end", &wr, this, "End point"), - strech(_("Strech"), _("Strech the result"), "strech", &wr, this, 1), + strech(_("Stretch"), _("Stretch the result"), "strech", &wr, this, 1), offset(_("Offset"), _("Offset from knots"), "offset", &wr, this, 0), first_knot(_("First Knot"), _("First Knot"), "first_knot", &wr, this, 1), last_knot(_("Last Knot"), _("Last Knot"), "last_knot", &wr, this, 1), -- cgit v1.2.3 From 326bf4284ba296b71c9584962e2ec232a7a89fb3 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sun, 1 Nov 2015 13:50:42 +0100 Subject: i18n. Strings disambiguation (thanks, Maren!). Translation. Translation template update. Translation. French translation update. (bzr r14440) --- src/ui/dialog/inkscape-preferences.cpp | 4 +- src/ui/dialog/objects.cpp | 10 ++--- src/ui/widget/font-variants.cpp | 70 +++++++++++++++++----------------- src/widgets/tweak-toolbar.cpp | 8 ++-- 4 files changed, 46 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 14eaa65aa..fec49d484 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -601,7 +601,7 @@ void InkscapePreferences::initPageUI() _("Set the language for menus and number formats"), false); { - Glib::ustring sizeLabels[] = {_("Large"), _("Small"), _("Smaller")}; + Glib::ustring sizeLabels[] = {C_("Icon size", "Large"), C_("Icon size", "Small"), C_("Icon size", "Smaller")}; int sizeValues[] = {0, 1, 2}; _misc_small_tools.init( "/toolbox/tools/small", sizeLabels, sizeValues, G_N_ELEMENTS(sizeLabels), 0 ); @@ -686,7 +686,7 @@ void InkscapePreferences::initPageUI() _win_ontop_agressive.init ( _("Aggressive"), "/options/transientpolicy/value", 2, false, &_win_ontop_none); { - Glib::ustring defaultSizeLabels[] = {_("Small"), _("Large"), _("Maximized")}; + Glib::ustring defaultSizeLabels[] = {C_("Window size", "Small"), C_("Window size", "Large"), C_("Window size", "Maximized")}; int defaultSizeValues[] = {0, 1, 2}; _win_default_size.init( "/options/defaultwindowsize/value", defaultSizeLabels, defaultSizeValues, G_N_ELEMENTS(defaultSizeLabels), 1 ); diff --git a/src/ui/dialog/objects.cpp b/src/ui/dialog/objects.cpp index 835ecf35b..d72dda028 100644 --- a/src/ui/dialog/objects.cpp +++ b/src/ui/dialog/objects.cpp @@ -1614,11 +1614,11 @@ ObjectsPanel::ObjectsPanel() : _pending(0), _toggleEvent(0), _defer_target(), - _visibleHeader(_("V")), - _lockHeader(_("L")), - _typeHeader(_("T")), - _clipmaskHeader(_("CM")), - _highlightHeader(_("HL")), + _visibleHeader(C_("Visibility", "V")), + _lockHeader(C_("Lock", "L")), + _typeHeader(C_("Type", "T")), + _clipmaskHeader(C_("Clip and mask", "CM")), + _highlightHeader(C_("Highlight", "HL")), _nameHeader(_("Label")), _composite_vbox(false, 0), _opacity_vbox(false, 0), diff --git a/src/ui/widget/font-variants.cpp b/src/ui/widget/font-variants.cpp index 5d1e40971..62598dead 100644 --- a/src/ui/widget/font-variants.cpp +++ b/src/ui/widget/font-variants.cpp @@ -35,41 +35,41 @@ namespace Widget { FontVariants::FontVariants () : Gtk::VBox (), - _ligatures_frame ( Glib::ustring(_("Ligatures" )) ), - _ligatures_common ( Glib::ustring(_("Common" )) ), - _ligatures_discretionary ( Glib::ustring(_("Discretionary")) ), - _ligatures_historical ( Glib::ustring(_("Historical" )) ), - _ligatures_contextual ( Glib::ustring(_("Contextual" )) ), - - _position_frame ( Glib::ustring(_("Position" )) ), - _position_normal ( Glib::ustring(_("Normal" )) ), - _position_sub ( Glib::ustring(_("Subscript" )) ), - _position_super ( Glib::ustring(_("Superscript" )) ), - - _caps_frame ( Glib::ustring(_("Capitals" )) ), - _caps_normal ( Glib::ustring(_("Normal" )) ), - _caps_small ( Glib::ustring(_("Small" )) ), - _caps_all_small ( Glib::ustring(_("All small" )) ), - _caps_petite ( Glib::ustring(_("Petite" )) ), - _caps_all_petite ( Glib::ustring(_("All petite" )) ), - _caps_unicase ( Glib::ustring(_("Unicase" )) ), - _caps_titling ( Glib::ustring(_("Titling" )) ), - - _numeric_frame ( Glib::ustring(_("Numeric" )) ), - _numeric_lining ( Glib::ustring(_("Lining" )) ), - _numeric_old_style ( Glib::ustring(_("Old Style" )) ), - _numeric_default_style ( Glib::ustring(_("Default Style")) ), - _numeric_proportional ( Glib::ustring(_("Proportional" )) ), - _numeric_tabular ( Glib::ustring(_("Tabular" )) ), - _numeric_default_width ( Glib::ustring(_("Default Width")) ), - _numeric_diagonal ( Glib::ustring(_("Diagonal" )) ), - _numeric_stacked ( Glib::ustring(_("Stacked" )) ), - _numeric_default_fractions( Glib::ustring(_("Default Fractions")) ), - _numeric_ordinal ( Glib::ustring(_("Ordinal" )) ), - _numeric_slashed_zero ( Glib::ustring(_("Slashed Zero" )) ), - - _feature_frame ( Glib::ustring(_("Feature Settings")) ), - _feature_label ( Glib::ustring(_("Selection has different Feature Settings!")) ), + _ligatures_frame ( Glib::ustring(C_("Font variant", "Ligatures" )) ), + _ligatures_common ( Glib::ustring(C_("Font variant", "Common" )) ), + _ligatures_discretionary ( Glib::ustring(C_("Font variant", "Discretionary")) ), + _ligatures_historical ( Glib::ustring(C_("Font variant", "Historical" )) ), + _ligatures_contextual ( Glib::ustring(C_("Font variant", "Contextual" )) ), + + _position_frame ( Glib::ustring(C_("Font variant", "Position" )) ), + _position_normal ( Glib::ustring(C_("Font variant", "Normal" )) ), + _position_sub ( Glib::ustring(C_("Font variant", "Subscript" )) ), + _position_super ( Glib::ustring(C_("Font variant", "Superscript" )) ), + + _caps_frame ( Glib::ustring(C_("Font variant", "Capitals" )) ), + _caps_normal ( Glib::ustring(C_("Font variant", "Normal" )) ), + _caps_small ( Glib::ustring(C_("Font variant", "Small" )) ), + _caps_all_small ( Glib::ustring(C_("Font variant", "All small" )) ), + _caps_petite ( Glib::ustring(C_("Font variant", "Petite" )) ), + _caps_all_petite ( Glib::ustring(C_("Font variant", "All petite" )) ), + _caps_unicase ( Glib::ustring(C_("Font variant", "Unicase" )) ), + _caps_titling ( Glib::ustring(C_("Font variant", "Titling" )) ), + + _numeric_frame ( Glib::ustring(C_("Font variant", "Numeric" )) ), + _numeric_lining ( Glib::ustring(C_("Font variant", "Lining" )) ), + _numeric_old_style ( Glib::ustring(C_("Font variant", "Old Style" )) ), + _numeric_default_style ( Glib::ustring(C_("Font variant", "Default Style")) ), + _numeric_proportional ( Glib::ustring(C_("Font variant", "Proportional" )) ), + _numeric_tabular ( Glib::ustring(C_("Font variant", "Tabular" )) ), + _numeric_default_width ( Glib::ustring(C_("Font variant", "Default Width")) ), + _numeric_diagonal ( Glib::ustring(C_("Font variant", "Diagonal" )) ), + _numeric_stacked ( Glib::ustring(C_("Font variant", "Stacked" )) ), + _numeric_default_fractions( Glib::ustring(C_("Font variant", "Default Fractions")) ), + _numeric_ordinal ( Glib::ustring(C_("Font variant", "Ordinal" )) ), + _numeric_slashed_zero ( Glib::ustring(C_("Font variant", "Slashed Zero" )) ), + + _feature_frame ( Glib::ustring(C_("Font variant", "Feature Settings")) ), + _feature_label ( Glib::ustring(C_("Font variant", "Selection has different Feature Settings!")) ), _ligatures_changed( false ), _position_changed( false ), diff --git a/src/widgets/tweak-toolbar.cpp b/src/widgets/tweak-toolbar.cpp index a5d90fc3d..e2c0daf6e 100644 --- a/src/widgets/tweak-toolbar.cpp +++ b/src/widgets/tweak-toolbar.cpp @@ -288,7 +288,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj NULL, Inkscape::ICON_SIZE_DECORATION ); //TRANSLATORS: "H" here stands for hue - g_object_set( act, "short_label", _("H"), NULL ); + g_object_set( act, "short_label", C_("Hue", "H"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_doh), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/doh", true) ); @@ -304,7 +304,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj NULL, Inkscape::ICON_SIZE_DECORATION ); //TRANSLATORS: "S" here stands for Saturation - g_object_set( act, "short_label", _("S"), NULL ); + g_object_set( act, "short_label", C_("Saturation", "S"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_dos), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/dos", true) ); @@ -320,7 +320,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj NULL, Inkscape::ICON_SIZE_DECORATION ); //TRANSLATORS: "L" here stands for Lightness - g_object_set( act, "short_label", _("L"), NULL ); + g_object_set( act, "short_label", C_("Lightness", "L"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_dol), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/dol", true) ); @@ -336,7 +336,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj NULL, Inkscape::ICON_SIZE_DECORATION ); //TRANSLATORS: "O" here stands for Opacity - g_object_set( act, "short_label", _("O"), NULL ); + g_object_set( act, "short_label", C_("Opacity", "O"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_doo), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/doo", true) ); -- 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 e90bd3cd9a9bcc57551c4f37c035cf28cd01e30a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 3 Nov 2015 22:46:41 +0100 Subject: Fix a localization problem storing attribute (bzr r14393.1.32) --- src/ui/tools/measure-tool.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index e6f56674a..31977b8b1 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -415,9 +415,11 @@ void MeasureTool::writeMeasurePoint(Geom::Point point, bool is_start) { if(!namedview) { return; } - gchar *str = g_strdup_printf("%f,%f", point[Geom::X], point[Geom::Y]); + std::stringstream meassure_point_str; + meassure_point_str.imbue(std::locale::classic()); + meassure_point_str << point[Geom::X] << "," << point[Geom::Y]; gchar const *measure_point = is_start ? "inkscape:measure-start" : "inkscape:measure-end"; - namedview->setAttribute (measure_point, str); + namedview->setAttribute (measure_point, meassure_point_str.str().c_str()); g_free(str); } -- cgit v1.2.3 From 01f40289c4b069d0b3d8ad80b4c59c69950dd937 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 3 Nov 2015 23:57:43 +0100 Subject: Fix a bug compiling (bzr r14393.1.34) --- src/ui/tools/measure-tool.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 31977b8b1..06f32ba5c 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -420,7 +420,6 @@ void MeasureTool::writeMeasurePoint(Geom::Point point, bool is_start) { meassure_point_str << point[Geom::X] << "," << point[Geom::Y]; gchar const *measure_point = is_start ? "inkscape:measure-start" : "inkscape:measure-end"; namedview->setAttribute (measure_point, meassure_point_str.str().c_str()); - g_free(str); } //This function is used to reverse the Measure, I do it in two steps because when move the knot the -- cgit v1.2.3 From 23935ad410a79d6f82e0ce90e5efba32a55cda4c Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Thu, 5 Nov 2015 22:27:44 +0100 Subject: static code analysis (bzr r14446) --- src/live_effects/parameter/originalpatharray.cpp | 10 +++++----- src/ui/clipboard.cpp | 10 +++++----- src/ui/dialog/export.cpp | 6 +++--- src/ui/dialog/font-substitution.cpp | 2 +- src/ui/dialog/glyphs.cpp | 4 ++-- src/ui/dialog/icon-preview.cpp | 2 +- src/ui/dialog/pixelartdialog.cpp | 2 +- src/ui/dialog/polar-arrange-tab.cpp | 2 +- src/ui/dialog/tags.cpp | 4 ++-- src/ui/dialog/text-edit.cpp | 6 +++--- src/ui/dialog/transformation.cpp | 8 ++++---- src/ui/tools/eraser-tool.cpp | 8 ++++---- src/ui/tools/lpe-tool.cpp | 2 +- src/widgets/arc-toolbar.cpp | 8 ++++---- src/widgets/connector-toolbar.cpp | 4 ++-- src/widgets/gradient-toolbar.cpp | 6 +++--- src/widgets/mesh-toolbar.cpp | 4 ++-- src/widgets/rect-toolbar.cpp | 4 ++-- src/widgets/star-toolbar.cpp | 12 ++++++------ src/widgets/stroke-style.cpp | 6 +++--- 20 files changed, 55 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/live_effects/parameter/originalpatharray.cpp b/src/live_effects/parameter/originalpatharray.cpp index 78e061e66..9e03e2c02 100644 --- a/src/live_effects/parameter/originalpatharray.cpp +++ b/src/live_effects/parameter/originalpatharray.cpp @@ -215,7 +215,7 @@ void OriginalPathArrayParam::on_up_button_click() int i = -1; std::vector::iterator piter = _vector.begin(); - for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); piter = iter, i++, iter++) { + for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); piter = iter, i++, ++iter) { if (*iter == row[_model->_colObject]) { _vector.erase(iter); _vector.insert(piter, row[_model->_colObject]); @@ -241,7 +241,7 @@ void OriginalPathArrayParam::on_down_button_click() Gtk::TreeModel::Row row = *iter; int i = 0; - for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); i++, iter++) { + for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); i++, ++iter) { if (*iter == row[_model->_colObject]) { std::vector::iterator niter = _vector.erase(iter); if (niter != _vector.end()) { @@ -295,7 +295,7 @@ OriginalPathArrayParam::on_link_button_click() Inkscape::SVGOStringStream os; bool foundOne = false; - for (std::vector::const_iterator iter = _vector.begin(); iter != _vector.end(); iter++) { + for (std::vector::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { if (foundOne) { os << "|"; } else { @@ -330,7 +330,7 @@ void OriginalPathArrayParam::unlink(PathAndDirection* to) void OriginalPathArrayParam::remove_link(PathAndDirection* to) { unlink(to); - for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); iter++) { + for (std::vector::iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { if (*iter == to) { PathAndDirection *w = *iter; _vector.erase(iter); @@ -455,7 +455,7 @@ gchar * OriginalPathArrayParam::param_getSVGValue() const { Inkscape::SVGOStringStream os; bool foundOne = false; - for (std::vector::const_iterator iter = _vector.begin(); iter != _vector.end(); iter++) { + for (std::vector::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { if (foundOne) { os << "|"; } else { diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 0792fb9c5..354fa45dc 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -525,7 +525,7 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a // resize each object in the selection if (separately) { std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (item) { Geom::OptRect obj_size = item->desktopVisualBounds(); @@ -581,7 +581,7 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) // make sure all selected items are converted to paths first (i.e. rectangles) sp_selected_to_lpeitems(desktop); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; _applyPathEffect(item, effectstack); } @@ -665,7 +665,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) // copy the defs used by all items std::vector itemlist=selection->itemList(); cloned_elements.clear(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (item) { _copyUsedDefs(item); @@ -676,7 +676,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) // copy the representation of the items std::vector sorted_items; - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i) sorted_items.push_back(*i); sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position_bool); @@ -692,7 +692,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) sorted_items.insert(sorted_items.end(),cloned_elements.begin(),cloned_elements.end()); - for(std::vector::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){ + for(std::vector::const_iterator i=sorted_items.begin();i!=sorted_items.end();++i){ SPItem *item = dynamic_cast(*i); if (item) { Inkscape::XML::Node *obj = item->getRepr(); diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 59fab7771..2fb5f9e3b 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -821,7 +821,7 @@ void Export::onAreaToggled () if (filename.empty()) { const gchar * id = "object"; const std::vector reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); - for(std::vector::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + for(std::vector::const_iterator i=reprlst.begin(); reprlst.end() != i; ++i) { Inkscape::XML::Node * repr = *i; if (repr->attribute("id")) { id = repr->attribute("id"); @@ -1030,7 +1030,7 @@ void Export::onExport () gint export_count = 0; std::vector itemlist=desktop->getSelection()->itemList(); - for(std::vector::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;i++){ + for(std::vector::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;++i){ SPItem *item = *i; prog_dlg->set_data("current", GINT_TO_POINTER(n)); @@ -1239,7 +1239,7 @@ void Export::onExport () DocumentUndo::setUndoSensitive(doc, false); reprlst = desktop->getSelection()->reprList(); - for(std::vector::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + for(std::vector::const_iterator i=reprlst.begin(); reprlst.end() != i; ++i) { Inkscape::XML::Node * repr = *i; const gchar * temp_string; Glib::ustring dir = Glib::path_get_dirname(filename.c_str()); diff --git a/src/ui/dialog/font-substitution.cpp b/src/ui/dialog/font-substitution.cpp index 19506c6a3..f219f3db6 100644 --- a/src/ui/dialog/font-substitution.cpp +++ b/src/ui/dialog/font-substitution.cpp @@ -154,7 +154,7 @@ std::vector FontSubstitution::getFontReplacedItems(SPDocument* doc, Gli std::map mapFontStyles; allList = get_all_items(x, doc->getRoot(), desktop, false, false, true, y); - for(std::vector::const_iterator i = allList.begin();i!=allList.end();i++){ + for(std::vector::const_iterator i = allList.begin();i!=allList.end();++i){ SPItem *item = *i; SPStyle *style = item->style; Glib::ustring family = ""; diff --git a/src/ui/dialog/glyphs.cpp b/src/ui/dialog/glyphs.cpp index 7ca277ea2..56b001291 100644 --- a/src/ui/dialog/glyphs.cpp +++ b/src/ui/dialog/glyphs.cpp @@ -579,7 +579,7 @@ void GlyphsPanel::insertText() { SPItem *textItem = 0; std::vector itemlist=targetDesktop->selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { textItem = *i; break; @@ -689,7 +689,7 @@ void GlyphsPanel::calcCanInsert() { int items = 0; std::vector itemlist=targetDesktop->selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { ++items; } diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index 77f120e1a..83656a1f2 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -363,7 +363,7 @@ void IconPreviewPanel::refreshPreview() //g_message("found a selection to play with"); std::vector const items = sel->itemList(); - for(std::vector::const_iterator i=items.begin();!target && i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();!target && i!=items.end();++i){ SPItem* item = *i; gchar const *id = item->getId(); if ( id ) { diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp index 760391df6..f557ff0fc 100644 --- a/src/ui/dialog/pixelartdialog.cpp +++ b/src/ui/dialog/pixelartdialog.cpp @@ -373,7 +373,7 @@ void PixelArtDialogImpl::vectorize() } std::vector const items = desktop->selection->itemList(); - for(std::vector::const_iterator i=items.begin(); i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin(); i!=items.end();++i){ if ( !SP_IS_IMAGE(*i) ) continue; diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index af1386e27..a93cebee8 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -304,7 +304,7 @@ void PolarArrangeTab::arrange() bool arrangeOnFirstEllipse = arrangeOnEllipse && arrangeOnFirstCircleRadio.get_active(); int count = 0; - for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++) + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i) { if(arrangeOnEllipse) { diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp index f36e3f18d..9b6f3219f 100644 --- a/src/ui/dialog/tags.cpp +++ b/src/ui/dialog/tags.cpp @@ -353,7 +353,7 @@ void TagsPanel::_objectsSelected( Selection *sel ) { _selectedConnection.block(); _tree.get_selection()->unselect_all(); std::vector tmp=sel->list(); - for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++) + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i) { SPObject *obj = *i; _store->foreach(sigc::bind( sigc::mem_fun(*this, &TagsPanel::_checkForSelected), obj)); @@ -651,7 +651,7 @@ bool TagsPanel::_handleButtonEvent(GdkEventButton* event) if (SP_IS_TAG(obj)) { bool wasadded = false; std::vector items=_desktop->selection->itemList(); - for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPObject *newobj = *i; bool addchild = true; for ( SPObject *child = obj->children; child != NULL; child = child->next) { diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index cf53e1441..05cf3a388 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -444,7 +444,7 @@ SPItem *TextEdit::getSelectedTextItem (void) return NULL; std::vector tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); - for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++) + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) return *i; @@ -462,7 +462,7 @@ unsigned TextEdit::getSelectedTextCount (void) unsigned int items = 0; std::vector tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); - for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++) + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) ++items; @@ -572,7 +572,7 @@ void TextEdit::onApply() SPCSSAttr *css = fillTextStyle (); sp_desktop_set_style(desktop, css, true); - for(std::vector::const_iterator i=item_list.begin();i!=item_list.end();i++){ + for(std::vector::const_iterator i=item_list.begin();i!=item_list.end();++i){ // apply style to the reprs of all text objects in the selection if (SP_IS_TEXT (*i)) { diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 6049368f5..ae972bbbd 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -812,7 +812,7 @@ void Transformation::applyPageScale(Inkscape::Selection *selection) bool preserve = prefs->getBool("/options/preservetransform/value", false); if (prefs->getBool("/dialogs/transformation/applyseparately")) { std::vector tmp=selection->itemList(); - for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++){ + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i){ SPItem *item = *i; Geom::OptRect bbox_pref = item->desktopPreferredBounds(); Geom::OptRect bbox_geom = item->desktopGeometricBounds(); @@ -876,7 +876,7 @@ void Transformation::applyPageRotate(Inkscape::Selection *selection) if (prefs->getBool("/dialogs/transformation/applyseparately")) { std::vector tmp=selection->itemList(); - for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++){ + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i){ SPItem *item = *i; sp_item_rotate_rel(item, Geom::Rotate (angle*M_PI/180.0)); } @@ -896,7 +896,7 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/dialogs/transformation/applyseparately")) { std::vector items=selection->itemList(); - for(std::vector::const_iterator i = items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i = items.begin();i!=items.end();++i){ SPItem *item = *i; if (!_units_skew.isAbsolute()) { // percentage @@ -998,7 +998,7 @@ void Transformation::applyPageTransform(Inkscape::Selection *selection) if (_check_replace_matrix.get_active()) { std::vector tmp=selection->itemList(); - for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++){ + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i){ SPItem *item = *i; item->set_item_transform(displayed); item->updateRepr(); diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index e416fd7ef..83ecf7a0a 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -682,7 +682,7 @@ void EraserTool::set_to_accumulated() { if ( !toWorkOn.empty() ) { if ( eraserMode ) { - for (std::vector::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); i++){ + for (std::vector::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){ SPItem *item = *i; if ( eraserMode ) { @@ -701,7 +701,7 @@ void EraserTool::set_to_accumulated() { if ( !selection->isEmpty() ) { // If the item was not completely erased, track the new remainder. std::vector nowSel(selection->itemList()); - for (std::vector::const_iterator i2 = nowSel.begin();i2!=nowSel.end();i2++) { + for (std::vector::const_iterator i2 = nowSel.begin();i2!=nowSel.end();++i2) { remainingItems.push_back(*i2); } } @@ -711,11 +711,11 @@ void EraserTool::set_to_accumulated() { } } } else { - for (std::vector ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + for (std::vector ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();++i) { sp_object_ref( *i, 0 ); } - for (std::vector::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + for (std::vector::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();++i) { SPItem *item = *i; item->deleteObject(true); sp_object_unref(item); diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index 13e47f3a6..9bbc1ac20 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -397,7 +397,7 @@ lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection) gchar *arc_length; double lengthval; std::vector items=selection->itemList(); - for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ if (SP_IS_PATH(*i)) { path = SP_PATH(*i); curve = path->getCurve(); diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index 71418e238..7b872e8b1 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -98,7 +98,7 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v bool modmade = false; std::vector itemlist=desktop->getSelection()->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { @@ -164,7 +164,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) if ( ege_select_one_action_get_active(act) != 0 ) { std::vector itemlist=desktop->getSelection()->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -175,7 +175,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) } } else { std::vector itemlist=desktop->getSelection()->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -265,7 +265,7 @@ static void sp_arc_toolbox_selection_changed(Inkscape::Selection *selection, GOb purge_repr_listener( tbl, tbl ); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { n_selected++; diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index 1c99f283d..8cc254bd2 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -98,7 +98,7 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl bool modmade = false; std::vector itemlist=desktop->getSelection()->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (Inkscape::UI::Tools::cc_item_is_connector(item)) { @@ -145,7 +145,7 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) bool modmade = false; std::vector itemlist=desktop->getSelection()->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (Inkscape::UI::Tools::cc_item_is_connector(item)) { diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index 6743dd23a..b24615126 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -117,7 +117,7 @@ void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient // If no drag or no dragger selected, act on selection std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ gr_apply_gradient_to_item(*i, gr, initialType, initialMode, initialMode); } } @@ -219,7 +219,7 @@ void gr_get_dt_selected_gradient(Inkscape::Selection *selection, SPGradient *&gr SPGradient *gradient = 0; std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; @@ -287,7 +287,7 @@ void gr_read_selection( Inkscape::Selection *selection, // If no selected dragger, read desktop selection std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; SPStyle *style = item->style; diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index bef9129b9..4e0b6d68b 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -90,7 +90,7 @@ void ms_read_selection( Inkscape::Selection *selection, ms_type = SP_MESH_TYPE_COONS; std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; SPStyle *style = item->style; @@ -217,7 +217,7 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMesh *&ms_sel SPMesh *gradient = 0; std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 96ba699dc..bc27d003c 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -107,7 +107,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ if (SP_IS_RECT(*i)) { if (gtk_adjustment_get_value(adj) != 0) { (SP_RECT(*i)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); @@ -244,7 +244,7 @@ static void sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GO purge_repr_listener( tbl, tbl ); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ if (SP_IS_RECT(*i)) { n_selected++; item = *i; diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 96005d7df..741fd38ad 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -84,7 +84,7 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu Inkscape::Selection *selection = desktop->getSelection(); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -129,7 +129,7 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -186,7 +186,7 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d } std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -225,7 +225,7 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg Inkscape::Selection *selection = desktop->getSelection(); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -265,7 +265,7 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl Inkscape::Selection *selection = desktop->getSelection(); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -368,7 +368,7 @@ sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) purge_repr_listener( tbl, tbl ); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { n_selected++; diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index d05b3b994..43dffec56 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -480,7 +480,7 @@ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, Inkscape::Selection *selection = spw->desktop->getSelection(); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) { // can't set marker to rect, until it's converted to using continue; @@ -981,7 +981,7 @@ StrokeStyle::scaleLine() int ndash; dashSelector->get_dash(&ndash, &dash, &offset); - for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ /* Set stroke width */ double width; if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { @@ -1156,7 +1156,7 @@ StrokeStyle::updateAllMarkers(std::vector const &objects) }; bool all_texts = true; - for(std::vector::const_iterator i=objects.begin();i!=objects.end();i++){ + for(std::vector::const_iterator i=objects.begin();i!=objects.end();++i){ if (!SP_IS_TEXT (*i)) { all_texts = false; break; -- cgit v1.2.3 From 53badc4158169b711d54d68ce112a9b0480776de Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sat, 7 Nov 2015 00:03:00 +0100 Subject: static code analysis (bzr r14447) --- src/selection-chemistry.cpp | 139 ++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 70 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 85b62957c..cdbc6a937 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -284,7 +284,7 @@ void SelectionHelper::fixSelection(SPDesktop *dt) std::vector const selList = selection->itemList(); - for( std::vector::const_reverse_iterator i = selList.rbegin(); i != selList.rend(); i++ ) { + for( std::vector::const_reverse_iterator i = selList.rbegin(); i != selList.rend(); ++i ) { SPItem *item = *i; if( item && !dt->isLayer(item) && @@ -330,7 +330,7 @@ static void sp_selection_copy_impl(std::vector const &items, std::vecto sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position_bool); // Copy item reprs: - for (std::vector::const_iterator i = sorted_items.begin(); i != sorted_items.end(); i++) { + for (std::vector::const_iterator i = sorted_items.begin(); i != sorted_items.end(); ++i) { SPItem *item = *i; if (item) { sp_selection_copy_one(item->getRepr(), item->i2doc_affine(), clip, xml_doc); @@ -351,7 +351,7 @@ static std::vector sp_selection_paste_impl(SPDocument *doc std::vector copied; // add objects to document - for (std::vector::const_iterator l = clip.begin(); l != clip.end(); l++) { + for (std::vector::const_iterator l = clip.begin(); l != clip.end(); ++l) { Inkscape::XML::Node *repr = *l; Inkscape::XML::Node *copy = repr->duplicate(xml_doc); @@ -378,10 +378,10 @@ static std::vector sp_selection_paste_impl(SPDocument *doc static void sp_selection_delete_impl(std::vector const &items, bool propagate = true, bool propagate_descendants = true) { - for (std::vector::const_iterator i = items.begin(); i != items.end(); i++) { + for (std::vector::const_iterator i = items.begin(); i != items.end(); ++i) { sp_object_ref(*i, NULL); } - for (std::vector::const_iterator i = items.begin(); i != items.end(); i++) { + for (std::vector::const_iterator i = items.begin(); i != items.end(); ++i) { SPItem *item = *i; item->deleteObject(propagate, propagate_descendants); sp_object_unref(item, NULL); @@ -475,7 +475,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone, bool duplicat bool relink_clones = prefs->getBool("/options/relinkclonesonduplicate/value"); const bool fork_livepatheffects = prefs->getBool("/options/forklpeonduplicate/value", true); - for(std::vector::const_iterator i=reprs.begin();i!=reprs.end();i++){ + for(std::vector::const_iterator i=reprs.begin();i!=reprs.end();++i){ Inkscape::XML::Node *old_repr = *i; Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); @@ -483,7 +483,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone, bool duplicat if(! duplicateLayer) parent->appendChild(copy); else - parent->addChild(copy, old_repr); + parent->addChild(copy, old_repr); if (relink_clones) { SPObject *old_obj = doc->getObjectByRepr(old_repr); @@ -547,7 +547,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone, bool duplicat if(!duplicateLayer) selection->setReprList(newsel); else{ - SPObject* new_layer = doc->getObjectByRepr(newsel[0]); + SPObject* new_layer = doc->getObjectByRepr(newsel[0]); gchar* name = g_strdup_printf(_("%s copy"), new_layer->label()); desktop->layer_manager->renameLayer( new_layer, name, TRUE ); g_free(name); @@ -638,7 +638,7 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i std::vector all_items = sp_item_group_item_list(dynamic_cast(dt->currentLayer())); - for (std::vector::const_reverse_iterator i=all_items.rbegin();i!=all_items.rend();i++) { + for (std::vector::const_reverse_iterator i=all_items.rbegin();i!=all_items.rend();++i) { SPItem *item = *i; if (item && (!onlysensitive || !item->isLocked())) { @@ -655,7 +655,7 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i break; } case PREFS_SELECTION_LAYER_RECURSIVE: { - std::vector x; + std::vector x; items = get_all_items(x, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude); break; } @@ -698,7 +698,7 @@ static void sp_selection_group_impl(std::vector p, Inkscap gint topmost = p.back()->position(); Inkscape::XML::Node *topmost_parent = p.back()->parent(); - for(std::vector::const_iterator i = p.begin(); i != p.end(); i++){ + for(std::vector::const_iterator i = p.begin(); i != p.end(); ++i){ Inkscape::XML::Node *current = *i; if (current->parent() == topmost_parent) { @@ -802,7 +802,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) std::vector old_select = selection->itemList(); std::vector new_select; GSList *groups = NULL; - for (std::vector::const_iterator item = old_select.begin(); item!=old_select.end(); item++) { + for (std::vector::const_iterator item = old_select.begin(); item!=old_select.end(); ++item) { SPItem *obj = *item; if (dynamic_cast(obj)) { groups = g_slist_prepend(groups, obj); @@ -821,7 +821,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) // If any of the clones refer to the groups, unlink them and replace them with successors // in the items list. GSList *clones_to_unlink = NULL; - for (std::vector::const_iterator item = items.begin(); item != items.end(); item++) { + for (std::vector::const_iterator item = items.begin(); item != items.end(); ++item) { SPUse *use = dynamic_cast(*item); SPItem *original = use; @@ -847,12 +847,12 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) g_slist_free(clones_to_unlink); // do the actual work - for (std::vector::iterator item = items.begin(); item != items.end(); item++) { + for (std::vector::iterator item = items.begin(); item != items.end(); ++item) { SPItem *obj = *item; // ungroup only the groups marked earlier if (g_slist_find(groups, *item) != NULL) { - std::vector children; + std::vector children; sp_item_group_ungroup(dynamic_cast(obj), children, false); // add the items resulting from ungrouping to the selection new_select.insert(new_select.end(),children.begin(),children.end()); @@ -873,16 +873,16 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) std::vector sp_degroup_list(std::vector &items) { - std::vector out; + std::vector out; bool has_groups = false; - for (std::vector::const_iterator item=items.begin();item!=items.end();item++) { + for (std::vector::const_iterator item=items.begin();item!=items.end();++item) { SPGroup *group = dynamic_cast(*item); if (!group) { out.push_back(*item); } else { has_groups = true; std::vector members = sp_item_group_item_list(group); - for (std::vector::const_iterator member=members.begin();member!=members.end();member++) { + for (std::vector::const_iterator member=members.begin();member!=members.end();++member) { out.push_back(*member); } members.clear(); @@ -899,7 +899,7 @@ sp_degroup_list(std::vector &items) /** If items in the list have a common parent, return it, otherwise return NULL */ static SPGroup * -sp_item_list_common_parent_group(std::vector const items) +sp_item_list_common_parent_group(std::vector const &items) { if (items.empty()) { return NULL; @@ -909,8 +909,8 @@ sp_item_list_common_parent_group(std::vector const items) if (!dynamic_cast(parent)) { return NULL; } - for (std::vector::const_iterator item=items.begin();item!=items.end();item++) { - if((*item)==items[0])continue; + for (std::vector::const_iterator item=items.begin();item!=items.end();++item) { + if((*item)==items[0])continue; if ((*item)->parent != parent) { return NULL; } @@ -926,7 +926,7 @@ enclose_items(std::vector const &items) g_assert(!items.empty()); Geom::OptRect r; - for (std::vector::const_iterator i = items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i = items.begin();i!=items.end();++i) { r.unionWith((*i)->desktopVisualBounds()); } return r; @@ -945,7 +945,7 @@ static SPObject *prev_sibling(SPObject *child) bool sp_item_repr_compare_position_bool(SPObject const *first, SPObject const *second) { return sp_repr_compare_position(((SPItem*)first)->getRepr(), - ((SPItem*)second)->getRepr())<0; + ((SPItem*)second)->getRepr())<0; } void @@ -974,7 +974,7 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) // Iterate over all objects in the selection (starting from top). if (selected) { - for (std::vector::const_iterator item=rev.begin();item!=rev.end();item++) { + for (std::vector::const_iterator item=rev.begin();item!=rev.end();++item) { SPObject *child = *item; // for each selected object, find the next sibling for (SPObject *newref = child->next; newref; newref = newref->next) { @@ -1019,7 +1019,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto std::vector rl(selection->reprList()); sort(rl.begin(),rl.end(),sp_repr_compare_position_bool); - for (std::vector::const_iterator l=rl.begin(); l!=rl.end();l++) { + for (std::vector::const_iterator l=rl.begin(); l!=rl.end();++l) { Inkscape::XML::Node *repr =(*l); repr->setPosition(-1); } @@ -1053,7 +1053,7 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) // Iterate over all objects in the selection (starting from top). if (selected) { - for (std::vector::const_reverse_iterator item=rev.rbegin();item!=rev.rend();item++) { + for (std::vector::const_reverse_iterator item=rev.rbegin();item!=rev.rend();++item) { SPObject *child = *item; // for each selected object, find the prev sibling for (SPObject *newref = prev_sibling(child); newref; newref = prev_sibling(newref)) { @@ -1103,7 +1103,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des std::vector rl(selection->reprList()); sort(rl.begin(),rl.end(),sp_repr_compare_position_bool); - for (std::vector::const_reverse_iterator l=rl.rbegin();l!=rl.rend();l++) { + for (std::vector::const_reverse_iterator l=rl.rbegin();l!=rl.rend();++l) { gint minpos; SPObject *pp, *pc; Inkscape::XML::Node *repr = (*l); @@ -1256,7 +1256,7 @@ void sp_selection_remove_livepatheffect(SPDesktop *desktop) return; } std::vector list=selection->itemList(); - for ( std::vector::const_iterator itemlist=list.begin();itemlist!=list.end();itemlist++) { + for ( std::vector::const_iterator itemlist=list.begin();itemlist!=list.end();++itemlist) { SPItem *item = *itemlist; sp_selection_remove_livepatheffect_impl(item); @@ -1313,7 +1313,7 @@ void sp_selection_paste_size_separately(SPDesktop *desktop, bool apply_x, bool a */ void sp_selection_change_layer_maintain_clones(std::vector const &items,SPObject *where) { - for (std::vector::const_iterator i = items.begin(); i != items.end(); i++) { + for (std::vector::const_iterator i = items.begin(); i != items.end(); ++i) { SPItem *item = *i; if (item) { SPItem *oldparent = dynamic_cast(item->parent); @@ -1472,7 +1472,7 @@ selection_contains_both_clone_and_original(Inkscape::Selection *selection) { bool clone_with_original = false; std::vector items = selection->itemList(); - for (std::vector::const_iterator l=items.begin();l!=items.end() ;l++) { + for (std::vector::const_iterator l=items.begin();l!=items.end() ;++l) { SPItem *item = *l; if (item) { clone_with_original |= selection_contains_original(item, selection); @@ -1517,7 +1517,7 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, Geom::Affine cons persp3d_apply_affine_transformation(transf_persp, affine); } std::vector items = selection->itemList(); - for (std::vector::const_iterator l=items.begin();l!=items.end() ;l++) { + for (std::vector::const_iterator l=items.begin();l!=items.end() ;++l) { SPItem *item = *l; if( dynamic_cast(item) ) { @@ -1688,7 +1688,7 @@ void sp_selection_remove_transform(SPDesktop *desktop) Inkscape::Selection *selection = desktop->getSelection(); std::vector items = selection->reprList(); - for (std::vector::const_iterator l=items.begin();l!=items.end() ;l++) { + for (std::vector::const_iterator l=items.begin();l!=items.end() ;++l) { (*l)->setAttribute("transform", NULL, false); } @@ -1789,7 +1789,7 @@ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw) std::vector items = selection->itemList(); Geom::Rotate const rot_90(Geom::Point(0, ccw ? 1 : -1)); // pos. or neg. rotation, depending on the value of ccw - for (std::vector::const_iterator l=items.begin();l!=items.end() ;l++) { + for (std::vector::const_iterator l=items.begin();l!=items.end() ;++l) { SPItem *item = *l; if (item) { sp_item_rotate_rel(item, rot_90); @@ -1854,14 +1854,14 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea std::vector items = selection->itemList(); std::vector tmp; - for (std::vector::const_iterator iter=all_list.begin();iter!=all_list.end();iter++) { + for (std::vector::const_iterator iter=all_list.begin();iter!=all_list.end();++iter) { if(!SP_IS_GROUP(*iter)){ tmp.push_back(*iter); } } all_list=tmp; - for (std::vector::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + for (std::vector::const_iterator sel_iter=items.begin();sel_iter!=items.end();++sel_iter) { SPItem *sel = *sel_iter; std::vector matches = all_list; if (fill && stroke && style) { @@ -1909,7 +1909,7 @@ void sp_select_same_object_type(SPDesktop *desktop) Inkscape::Selection *selection = desktop->getSelection(); std::vector items=selection->itemList(); - for (std::vector::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + for (std::vector::const_iterator sel_iter=items.begin();sel_iter!=items.end();++sel_iter) { SPItem *sel = *sel_iter; if (sel) { matches = sp_get_same_object_type(sel, matches); @@ -1936,7 +1936,7 @@ std::vector sp_get_same_fill_or_stroke_color(SPItem *sel, std::vectorstyle->fill) : &(sel->style->stroke); - for (std::vector::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) { + for (std::vector::const_reverse_iterator i=src.rbegin();i!=src.rend();++i) { SPItem *iter = *i; if (iter) { SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke); @@ -2031,7 +2031,7 @@ std::vector sp_get_same_object_type(SPItem *sel, std::vector & { std::vector matches; - for (std::vector::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) { + for (std::vector::const_reverse_iterator i=src.rbegin();i!=src.rend();++i) { SPItem *item = *i; if (item && item_type_match(sel, item) && !item->cloned) { matches.push_back(item); @@ -2072,7 +2072,7 @@ std::vector sp_get_same_style(SPItem *sel, std::vector &src, S objects_query_strokewidth (objects, sel_style_for_width); } bool match_g; - for (std::vector::const_iterator i=src.begin();i!=src.end();i++) { + for (std::vector::const_iterator i=src.begin();i!=src.end();++i) { SPItem *iter = *i; if (iter) { match_g=true; @@ -2112,7 +2112,7 @@ std::vector sp_get_same_style(SPItem *sel, std::vector &src, S } } } - match_g = match_g && match; + match_g = match_g && match; if (match_g) { while (iter->cloned) iter=dynamic_cast(iter->parent); matches.insert(matches.begin(),iter); @@ -2371,11 +2371,11 @@ SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, template -SPItem *next_item_from_list(SPDesktop *desktop, std::vector const items, +SPItem *next_item_from_list(SPDesktop *desktop, std::vector const &items, SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) { SPObject *current=root; - for(std::vector::const_iterator i = items.begin();i!=items.end();i++) { + for(std::vector::const_iterator i = items.begin();i!=items.end();++i) { SPItem *item = *i; if ( root->isAncestorOf(item) && ( !only_in_viewport || desktop->isWithinViewport(item) ) ) @@ -2577,8 +2577,8 @@ void sp_selection_clone(SPDesktop *desktop) std::vector newsel; - for(std::vector::const_iterator i=reprs.begin();i!=reprs.end();i++){ - Inkscape::XML::Node *sel_repr = *i; + for(std::vector::const_iterator i=reprs.begin();i!=reprs.end();++i){ + Inkscape::XML::Node *sel_repr = *i; Inkscape::XML::Node *parent = sel_repr->parent(); Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); @@ -2628,7 +2628,7 @@ sp_selection_relink(SPDesktop *desktop) // Get a copy of current selection. bool relinked = false; std::vector items=selection->itemList(); - for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPItem *item = *i; if (dynamic_cast(item)) { @@ -2666,7 +2666,7 @@ sp_selection_unlink(SPDesktop *desktop) std::vector new_select; bool unlinked = false; std::vector items=selection->itemList(); - for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){ SPItem *item = *i; if (dynamic_cast(item)) { @@ -2831,7 +2831,7 @@ void sp_selection_clone_original_path_lpe(SPDesktop *desktop) Inkscape::SVGOStringStream os; SPObject * firstItem = NULL; std::vector items=selection->itemList(); - for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();++i){ if (SP_IS_SHAPE(*i) || SP_IS_TEXT(*i)) { if (firstItem) { os << "|"; @@ -2934,7 +2934,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) // Create a list of duplicates, to be pasted inside marker element. std::vector repr_copies; - for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){ Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); repr_copies.push_back(dup); } @@ -2944,7 +2944,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) if (apply) { // Delete objects so that their clones don't get alerted; // the objects will be restored inside the marker element. - for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPObject *item = *i; item->deleteObject(false); } @@ -2973,7 +2973,7 @@ static void sp_selection_to_guides_recursive(SPItem *item, bool wholegroups) { SPGroup *group = dynamic_cast(item); if (group && !dynamic_cast(item) && !wholegroups) { std::vector items=sp_item_group_item_list(group); - for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();++i){ sp_selection_to_guides_recursive(*i, wholegroups); } } else { @@ -3004,7 +3004,7 @@ void sp_selection_to_guides(SPDesktop *desktop) // and its entry in the selection list is invalid (crash). // Therefore: first convert all, then delete all. - for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();++i){ sp_selection_to_guides_recursive(*i, wholegroups); } @@ -3122,7 +3122,7 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) } // Move selected items to new - for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){ Inkscape::XML::Node *repr = (*i)->getRepr(); repr->parent()->removeChild(repr); symbol_repr->addChild(repr,NULL); @@ -3206,7 +3206,7 @@ void sp_selection_unsymbol(SPDesktop *desktop) } } - for (std::vector::const_reverse_iterator i=children.rbegin();i!=children.rend();i++){ + for (std::vector::const_reverse_iterator i=children.rbegin();i!=children.rend();++i){ Inkscape::XML::Node *repr = (*i)->getRepr(); repr->parent()->removeChild(repr); group->addChild(repr,NULL); @@ -3290,7 +3290,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) // create a list of duplicates std::vector repr_copies; - for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();++i){ Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); repr_copies.push_back(dup); } @@ -3299,7 +3299,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) if (apply) { // delete objects so that their clones don't get alerted; this object will be restored shortly - for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPObject *item = *i; item->deleteObject(false); } @@ -3373,7 +3373,7 @@ void sp_selection_untile(SPDesktop *desktop) bool did = false; std::vector items(selection->itemList()); - for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){ SPItem *item = *i; SPStyle *style = item->style; @@ -3442,7 +3442,7 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring bool xdpi_search = TRUE; bool ydpi_search = TRUE; - for (std::vector::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();i++){ + for (std::vector::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();++i){ gchar const *dpi_string; Inkscape::XML::Node *repr = *i; @@ -3493,7 +3493,6 @@ void sp_document_get_export_hints(SPDocument *doc, Glib::ustring &filename, floa *xdpi = atof(dpi_string); } - dpi_string = NULL; dpi_string = repr->attribute("inkscape:export-ydpi"); if (dpi_string != NULL) { *ydpi = atof(dpi_string); @@ -3743,8 +3742,8 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) Inkscape::XML::Node *inner = xml_doc->createElement("svg:g"); inner->setAttribute("inkscape:label", "Clip"); - for(std::vector::const_iterator i=p.begin();i!=p.end();i++){ - Inkscape::XML::Node *current = *i; + for(std::vector::const_iterator i=p.begin();i!=p.end();++i){ + Inkscape::XML::Node *current = *i; if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -3879,12 +3878,12 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ apply_to_items.push_back(SP_ITEM(desktop->currentLayer())); } - for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i=items.begin();i!=items.end();++i) { if((!topmost && !apply_to_layer && *i == items.front()) || (topmost && !apply_to_layer && *i == items.back()) - || apply_to_layer){ + || apply_to_layer){ - Geom::Affine oldtr=(*i)->transform; + Geom::Affine oldtr=(*i)->transform; (*i)->doWriteTransform((*i)->getRepr(), (*i)->i2doc_affine()); Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); (*i)->doWriteTransform((*i)->getRepr(), oldtr); @@ -3896,7 +3895,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ else { items_to_select.push_back(*i); } - continue; + continue; }else{ apply_to_items.push_back(*i); items_to_select.push_back(*i); @@ -3914,7 +3913,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ group->setAttribute("inkscape:groupmode", "maskhelper"); std::vector reprs_to_group; - for (std::vector::const_iterator i = apply_to_items.begin(); i != apply_to_items.end(); i++) { + for (std::vector::const_iterator i = apply_to_items.begin(); i != apply_to_items.end(); ++i) { reprs_to_group.push_back(static_cast(*i)->getRepr()); } items_to_select.clear(); @@ -3935,13 +3934,13 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ gchar const *attributeName = apply_clip_path ? "clip-path" : "mask"; - for (std::vector::const_reverse_iterator i = apply_to_items.rbegin(); i != apply_to_items.rend(); i++) { + for (std::vector::const_reverse_iterator i = apply_to_items.rbegin(); i != apply_to_items.rend(); ++i) { SPItem *item = reinterpret_cast(*i); // inverted object transform should be applied to a mask object, // as mask is calculated in user space (after applying transform) std::vector mask_items_dup; - for(std::vector::const_iterator it=mask_items.begin();it!=mask_items.end();it++) - mask_items_dup.push_back((*it)->duplicate(xml_doc)); + for(std::vector::const_iterator it=mask_items.begin();it!=mask_items.end();++it) + mask_items_dup.push_back((*it)->duplicate(xml_doc)); Inkscape::XML::Node *current = SP_OBJECT(*i)->getRepr(); // Node to apply mask to Inkscape::XML::Node *apply_mask_to = current; @@ -3980,7 +3979,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ } - for (std::vector::const_iterator i = items_to_delete.begin(); i != items_to_delete.end(); i++) { + for (std::vector::const_iterator i = items_to_delete.begin(); i != items_to_delete.end(); ++i) { SPObject *item = reinterpret_cast(*i); item->deleteObject(false); items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), item), items_to_select.end()); @@ -4027,7 +4026,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { // SPObject* refers to a group containing the clipped path or mask itself, // whereas SPItem* refers to the item being clipped or masked - for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();++i){ if (remove_original) { // remember referenced mask/clippath, so orphaned masks can be moved back to document SPItem *item = *i; -- cgit v1.2.3 From ce318a442bc1c9fb4381e1b9ad11effb1314f9b7 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sat, 7 Nov 2015 00:03:53 +0100 Subject: static code analysis (bzr r14448) --- src/box3d.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/box3d.cpp b/src/box3d.cpp index dc04a2eb6..c4c2728e4 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -50,6 +50,11 @@ SPBox3D::SPBox3D() : SPGroup() { this->persp_href = NULL; this->persp_ref = new Persp3DReference(this); + + /* we initialize the z-orders to zero so that they are updated during dragging */ + for (int i = 0; i < 6; ++i) { + z_orders[i] = 0; + } } SPBox3D::~SPBox3D() { @@ -902,7 +907,7 @@ box3d_swap_sides(int z_orders[6], Box3D::Axis axis) { } } - if (pos1 != -1){ + if ((pos1 != -1) && (pos2 != -1)){ int tmp = z_orders[pos1]; z_orders[pos1] = z_orders[pos2]; z_orders[pos2] = tmp; -- cgit v1.2.3 From 23f5e12afb04c9e029a69fcd77e9857d056e3a6a Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sat, 7 Nov 2015 16:09:43 +0000 Subject: Rebase on upstream libcroco 0.6.9 and backport minor fixes (bzr r14449) --- src/libcroco/cr-additional-sel.c | 16 ++--- src/libcroco/cr-attr-sel.c | 8 +-- src/libcroco/cr-cascade.c | 2 +- src/libcroco/cr-declaration.c | 26 ++++---- src/libcroco/cr-enc-handler.c | 2 +- src/libcroco/cr-fonts.c | 12 ++-- src/libcroco/cr-input.c | 2 +- src/libcroco/cr-num.c | 4 +- src/libcroco/cr-om-parser.c | 61 +++++++++++------- src/libcroco/cr-parser.c | 40 ++++++------ src/libcroco/cr-pseudo.c | 12 ++-- src/libcroco/cr-rgb.c | 13 ++-- src/libcroco/cr-sel-eng.c | 40 ++++++------ src/libcroco/cr-sel-eng.h | 6 +- src/libcroco/cr-selector.c | 15 +++-- src/libcroco/cr-simple-sel.c | 22 ++++--- src/libcroco/cr-statement.c | 131 +++++++++++++++++++++------------------ src/libcroco/cr-string.c | 15 +++-- src/libcroco/cr-style.c | 60 +++++++++--------- src/libcroco/cr-stylesheet.c | 4 +- src/libcroco/cr-term.c | 71 ++++++++++----------- src/libcroco/cr-tknzr.c | 20 +++--- src/libcroco/cr-token.c | 4 +- src/libcroco/cr-utils.c | 26 ++------ 24 files changed, 326 insertions(+), 286 deletions(-) (limited to 'src') diff --git a/src/libcroco/cr-additional-sel.c b/src/libcroco/cr-additional-sel.c index 5a37eba6c..c34b8d243 100644 --- a/src/libcroco/cr-additional-sel.c +++ b/src/libcroco/cr-additional-sel.c @@ -247,7 +247,7 @@ cr_additional_sel_to_string (CRAdditionalSel const * a_this) guchar *name = NULL; if (cur->content.class_name) { - name = g_strndup + name = (guchar *) g_strndup (cur->content.class_name->stryng->str, cur->content.class_name->stryng->len); @@ -266,8 +266,8 @@ cr_additional_sel_to_string (CRAdditionalSel const * a_this) { guchar *name = NULL; - if (cur->content.class_name) { - name = g_strndup + if (cur->content.id_name) { + name = (guchar *) g_strndup (cur->content.id_name->stryng->str, cur->content.id_name->stryng->len); @@ -323,7 +323,7 @@ cr_additional_sel_to_string (CRAdditionalSel const * a_this) } if (str_buf) { - result = str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } @@ -347,7 +347,7 @@ cr_additional_sel_one_to_string (CRAdditionalSel const *a_this) guchar *name = NULL; if (a_this->content.class_name) { - name = g_strndup + name = (guchar *) g_strndup (a_this->content.class_name->stryng->str, a_this->content.class_name->stryng->len); @@ -366,8 +366,8 @@ cr_additional_sel_one_to_string (CRAdditionalSel const *a_this) { guchar *name = NULL; - if (a_this->content.class_name) { - name = g_strndup + if (a_this->content.id_name) { + name = (guchar *) g_strndup (a_this->content.id_name->stryng->str, a_this->content.id_name->stryng->len); @@ -422,7 +422,7 @@ cr_additional_sel_one_to_string (CRAdditionalSel const *a_this) } if (str_buf) { - result = str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } diff --git a/src/libcroco/cr-attr-sel.c b/src/libcroco/cr-attr-sel.c index 7976ff1f8..31d9da579 100644 --- a/src/libcroco/cr-attr-sel.c +++ b/src/libcroco/cr-attr-sel.c @@ -123,10 +123,10 @@ cr_attr_sel_to_string (CRAttrSel const * a_this) if (cur->name) { guchar *name = NULL; - name = g_strndup (cur->name->stryng->str, + name = (guchar *) g_strndup (cur->name->stryng->str, cur->name->stryng->len); if (name) { - g_string_append (str_buf, name); + g_string_append (str_buf, (const gchar *) name); g_free (name); name = NULL; } @@ -135,7 +135,7 @@ cr_attr_sel_to_string (CRAttrSel const * a_this) if (cur->value) { guchar *value = NULL; - value = g_strndup (cur->value->stryng->str, + value = (guchar *) g_strndup (cur->value->stryng->str, cur->value->stryng->len); if (value) { switch (cur->match_way) { @@ -168,7 +168,7 @@ cr_attr_sel_to_string (CRAttrSel const * a_this) } if (str_buf) { - result = str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); } diff --git a/src/libcroco/cr-cascade.c b/src/libcroco/cr-cascade.c index 31e938bb7..9f8dbdf8d 100644 --- a/src/libcroco/cr-cascade.c +++ b/src/libcroco/cr-cascade.c @@ -75,8 +75,8 @@ cr_cascade_new (CRStyleSheet * a_author_sheet, PRIVATE (result) = g_try_malloc (sizeof (CRCascadePriv)); if (!PRIVATE (result)) { - g_free(result); cr_utils_trace_info ("Out of memory"); + g_free (result); return NULL; } memset (PRIVATE (result), 0, sizeof (CRCascadePriv)); diff --git a/src/libcroco/cr-declaration.c b/src/libcroco/cr-declaration.c index ab150a9e4..69c24b376 100644 --- a/src/libcroco/cr-declaration.c +++ b/src/libcroco/cr-declaration.c @@ -48,7 +48,7 @@ dump (CRDeclaration const * a_this, FILE * a_fp, glong a_indent) g_return_if_fail (a_this); - str = cr_declaration_to_string (a_this, a_indent); + str = (guchar *) cr_declaration_to_string (a_this, a_indent); if (str) { fprintf (a_fp, "%s", str); g_free (str); @@ -130,7 +130,7 @@ cr_declaration_parse_from_buf (CRStatement * a_statement, g_return_val_if_fail (a_statement->type == RULESET_STMT, NULL); - parser = cr_parser_new_from_buf ((guchar*)a_str, strlen (a_str), a_enc, FALSE); + parser = cr_parser_new_from_buf ((guchar*)a_str, strlen ((const char *) a_str), a_enc, FALSE); g_return_val_if_fail (parser, NULL); status = cr_parser_try_to_skip_spaces_and_comments (parser); @@ -194,7 +194,7 @@ cr_declaration_parse_list_from_buf (const guchar * a_str, g_return_val_if_fail (a_str, NULL); - parser = cr_parser_new_from_buf ((guchar*)a_str, strlen (a_str), a_enc, FALSE); + parser = cr_parser_new_from_buf ((guchar*)a_str, strlen ((const char *) a_str), a_enc, FALSE); g_return_val_if_fail (parser, NULL); status = cr_parser_get_tknzr (parser, &tokenizer); if (status != CR_OK || !tokenizer) { @@ -243,10 +243,10 @@ cr_declaration_parse_list_from_buf (const guchar * a_str, if (status != CR_OK || !property) { if (status == CR_END_OF_INPUT_ERROR) { status = CR_OK; // simply the end of input, do not delete what we got so far, just finish - break; + break; } else { continue; // even if one declaration is broken, it's no reason to discard others (see http://www.w3.org/TR/CSS21/syndata.html#declaration) - } + } } cur_decl = cr_declaration_new (NULL, property, value); if (cur_decl) { @@ -504,7 +504,7 @@ cr_declaration_to_string (CRDeclaration const * a_this, gulong a_indent) { GString *stringue = NULL; - guchar *str = NULL, + gchar *str = NULL, *result = NULL; g_return_val_if_fail (a_this, NULL); @@ -581,7 +581,7 @@ cr_declaration_list_to_string (CRDeclaration const * a_this, gulong a_indent) stringue = g_string_new (NULL); for (cur = a_this; cur; cur = cur->next) { - str = cr_declaration_to_string (cur, a_indent); + str = (guchar *) cr_declaration_to_string (cur, a_indent); if (str) { g_string_append_printf (stringue, "%s;", str); g_free (str); @@ -589,7 +589,7 @@ cr_declaration_list_to_string (CRDeclaration const * a_this, gulong a_indent) break; } if (stringue && stringue->str) { - result = stringue->str; + result = (guchar *) stringue->str; g_string_free (stringue, FALSE); } @@ -620,7 +620,7 @@ cr_declaration_list_to_string2 (CRDeclaration const * a_this, stringue = g_string_new (NULL); for (cur = a_this; cur; cur = cur->next) { - str = cr_declaration_to_string (cur, a_indent); + str = (guchar *) cr_declaration_to_string (cur, a_indent); if (str) { if (a_one_decl_per_line == TRUE) { if (cur->next) @@ -628,21 +628,21 @@ cr_declaration_list_to_string2 (CRDeclaration const * a_this, "%s;\n", str); else g_string_append (stringue, - str); + (const gchar *) str); } else { if (cur->next) g_string_append_printf (stringue, "%s;", str); else g_string_append (stringue, - str); + (const gchar *) str); } g_free (str); } else break; } if (stringue && stringue->str) { - result = stringue->str; + result = (guchar *) stringue->str; g_string_free (stringue, FALSE); } @@ -714,7 +714,7 @@ cr_declaration_get_by_prop_name (CRDeclaration * a_this, && cur->property->stryng && cur->property->stryng->str) { if (!strcmp (cur->property->stryng->str, - a_prop)) { + (const char *) a_prop)) { return cur; } } diff --git a/src/libcroco/cr-enc-handler.c b/src/libcroco/cr-enc-handler.c index b3e5b7eba..646bf1fe2 100644 --- a/src/libcroco/cr-enc-handler.c +++ b/src/libcroco/cr-enc-handler.c @@ -122,7 +122,7 @@ cr_enc_handler_resolve_enc_alias (const guchar * a_alias_name, g_ascii_strup (alias_name_up, -1); for (i = 0; gv_default_aliases[i].name; i++) { - if (!strcmp (gv_default_aliases[i].name, alias_name_up)) { + if (!strcmp (gv_default_aliases[i].name, (const gchar *) alias_name_up)) { *a_enc = gv_default_aliases[i].encoding; status = CR_OK; break; diff --git a/src/libcroco/cr-fonts.c b/src/libcroco/cr-fonts.c index 10f26c99c..78e261149 100644 --- a/src/libcroco/cr-fonts.c +++ b/src/libcroco/cr-fonts.c @@ -78,7 +78,7 @@ cr_font_family_to_string_real (CRFontFamily const * a_this, if (a_this->prev) { g_string_append_printf (*a_string, ", %s", name); } else { - g_string_append (*a_string, name); + g_string_append (*a_string, (const gchar *) name); } } if (a_walk_list == TRUE && a_this->next) { @@ -187,7 +187,7 @@ cr_font_family_to_string (CRFontFamily const * a_this, GString *stringue = NULL; if (!a_this) { - result = g_strdup ("NULL"); + result = (guchar *) g_strdup ("NULL"); g_return_val_if_fail (result, NULL); return result; } @@ -196,7 +196,7 @@ cr_font_family_to_string (CRFontFamily const * a_this, &stringue); if (status == CR_OK && stringue) { - result = stringue->str; + result = (guchar *) stringue->str; g_string_free (stringue, FALSE); stringue = NULL; @@ -420,7 +420,7 @@ cr_font_size_set_predefined_absolute_font_size (CRFontSize *a_this, enum CRPredefinedAbsoluteFontSize a_predefined) { g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - g_return_val_if_fail ((unsigned)a_predefined < NB_FONT_SIZE_TYPE, + g_return_val_if_fail ((unsigned)a_predefined < NB_PREDEFINED_ABSOLUTE_FONT_SIZES, CR_BAD_PARAM_ERROR) ; a_this->type = PREDEFINED_ABSOLUTE_FONT_SIZE ; @@ -526,7 +526,7 @@ cr_font_size_to_string (CRFontSize const * a_this) (a_this->value.predefined)); break; case ABSOLUTE_FONT_SIZE: - str = cr_num_to_string (&a_this->value.absolute); + str = (gchar *) cr_num_to_string (&a_this->value.absolute); break; case RELATIVE_FONT_SIZE: str = g_strdup (cr_relative_font_size_to_string @@ -683,7 +683,7 @@ cr_font_size_adjust_to_string (CRFontSizeAdjust const * a_this) break; case FONT_SIZE_ADJUST_NUMBER: if (a_this->num) - str = cr_num_to_string (a_this->num); + str = (gchar *) cr_num_to_string (a_this->num); else str = g_strdup ("unknow font-size-adjust property value"); /* Should raise an error no?*/ break; diff --git a/src/libcroco/cr-input.c b/src/libcroco/cr-input.c index 3cc283e01..5395ae214 100644 --- a/src/libcroco/cr-input.c +++ b/src/libcroco/cr-input.c @@ -746,7 +746,7 @@ enum CRStatus cr_input_peek_char (CRInput const * a_this, guint32 * a_char) { enum CRStatus status = CR_OK; - glong consumed = 0, + gulong consumed = 0, nb_bytes_left = 0; g_return_val_if_fail (a_this && PRIVATE (a_this) diff --git a/src/libcroco/cr-num.c b/src/libcroco/cr-num.c index a5c320bf2..6cc5150a1 100644 --- a/src/libcroco/cr-num.c +++ b/src/libcroco/cr-num.c @@ -105,7 +105,7 @@ cr_num_to_string (CRNum const * a_this) test_val = a_this->val - (glong) a_this->val; if (!test_val) { - tmp_char1 = g_strdup_printf ("%ld", (glong) a_this->val); + tmp_char1 = (guchar *) g_strdup_printf ("%ld", (glong) a_this->val); } else { /* We can't use g_ascii_dtostr, because that sometimes uses e notation (which wouldn't be a valid number in CSS). */ @@ -195,7 +195,7 @@ cr_num_to_string (CRNum const * a_this) } if (tmp_char2) { - result = g_strconcat (tmp_char1, tmp_char2, NULL); + result = (guchar *) g_strconcat ((gchar *) tmp_char1, tmp_char2, NULL); g_free (tmp_char1); } else { result = tmp_char1; diff --git a/src/libcroco/cr-om-parser.c b/src/libcroco/cr-om-parser.c index c1acb855c..596cd6e6b 100644 --- a/src/libcroco/cr-om-parser.c +++ b/src/libcroco/cr-om-parser.c @@ -39,9 +39,6 @@ struct _CROMParserPriv { #define PRIVATE(a_this) ((a_this)->priv) -// Unfortunately, C does not allow unnamed function arguments, so use this macro instead... -#define UNUSED(x) (void)(x) - /* *Forward declaration of a type defined later *in this file. @@ -210,12 +207,12 @@ static void start_font_face (CRDocHandler * a_this, CRParsingLocation *a_location) { - UNUSED(a_location); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; + (void) a_location; + g_return_if_fail (a_this); g_return_if_fail (a_this); @@ -307,8 +304,6 @@ static void charset (CRDocHandler * a_this, CRString * a_charset, CRParsingLocation *a_location) { - UNUSED(a_location); - enum CRStatus status = CR_OK; CRStatement *stmt = NULL, *stmt2 = NULL; @@ -317,6 +312,8 @@ charset (CRDocHandler * a_this, CRString * a_charset, ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; + (void) a_location; + g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); @@ -347,12 +344,12 @@ start_page (CRDocHandler * a_this, CRString * a_pseudo, CRParsingLocation *a_location) { - UNUSED(a_location); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; + (void) a_location; + g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); @@ -390,18 +387,21 @@ end_page (CRDocHandler * a_this, CRString * a_page, CRString * a_pseudo_page) { - UNUSED(a_page); - UNUSED(a_pseudo_page); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; CRStatement *stmt = NULL; + (void) a_page; + (void) a_pseudo_page; + g_return_if_fail (a_this); + ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->cur_stmt && ctxt->cur_stmt->type == AT_PAGE_RULE_STMT && ctxt->stylesheet); @@ -419,6 +419,8 @@ end_page (CRDocHandler * a_this, cr_statement_destroy (ctxt->cur_stmt); ctxt->cur_stmt = NULL; } + a_page = NULL; /*keep compiler happy */ + a_pseudo_page = NULL; /*keep compiler happy */ } static void @@ -426,13 +428,13 @@ start_media (CRDocHandler * a_this, GList * a_media_list, CRParsingLocation *a_location) { - UNUSED(a_location); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; GList *media_list = NULL; + (void) a_location; + g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); @@ -456,17 +458,20 @@ start_media (CRDocHandler * a_this, static void end_media (CRDocHandler * a_this, GList * a_media_list) { - UNUSED(a_media_list); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; CRStatement *stmts = NULL; + (void) a_media_list; + g_return_if_fail (a_this); + ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt && ctxt->cur_media_stmt && ctxt->cur_media_stmt->type == AT_MEDIA_RULE_STMT @@ -474,6 +479,7 @@ end_media (CRDocHandler * a_this, GList * a_media_list) stmts = cr_statement_append (ctxt->stylesheet->statements, ctxt->cur_media_stmt); + if (!stmts) { cr_statement_destroy (ctxt->cur_media_stmt); ctxt->cur_media_stmt = NULL; @@ -484,6 +490,7 @@ end_media (CRDocHandler * a_this, GList * a_media_list) ctxt->cur_stmt = NULL ; ctxt->cur_media_stmt = NULL ; + a_media_list = NULL; } static void @@ -493,9 +500,6 @@ import_style (CRDocHandler * a_this, CRString * a_uri_default_ns, CRParsingLocation *a_location) { - UNUSED(a_uri_default_ns); - UNUSED(a_location); - enum CRStatus status = CR_OK; CRString *uri = NULL; CRStatement *stmt = NULL, @@ -504,17 +508,26 @@ import_style (CRDocHandler * a_this, ParsingContext **ctxtptr = NULL; GList *media_list = NULL ; + (void) a_uri_default_ns; + (void) a_location; + g_return_if_fail (a_this); + ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->stylesheet); uri = cr_string_dup (a_uri) ; + if (a_media_list) media_list = cr_utils_dup_glist_of_cr_string (a_media_list) ; + stmt = cr_statement_new_at_import_rule (ctxt->stylesheet, uri, media_list, NULL); + if (!stmt) goto error; @@ -546,6 +559,7 @@ import_style (CRDocHandler * a_this, cr_statement_destroy (stmt); stmt = NULL; } + a_uri_default_ns = NULL; /*keep compiler happy */ } static void @@ -572,16 +586,19 @@ start_selector (CRDocHandler * a_this, CRSelector * a_selector_list) static void end_selector (CRDocHandler * a_this, CRSelector * a_selector_list) { - UNUSED(a_selector_list); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; + (void) a_selector_list; + g_return_if_fail (a_this); + ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->cur_stmt && ctxt->stylesheet); if (ctxt->cur_stmt) { @@ -621,6 +638,8 @@ end_selector (CRDocHandler * a_this, CRSelector * a_selector_list) } } + + a_selector_list = NULL; /*keep compiler happy */ } static void diff --git a/src/libcroco/cr-parser.c b/src/libcroco/cr-parser.c index 69b521496..544b35ab0 100644 --- a/src/libcroco/cr-parser.c +++ b/src/libcroco/cr-parser.c @@ -78,7 +78,7 @@ typedef struct _CRParserError CRParserError; *parsing routines. */ struct _CRParserError { - gchar *msg; + guchar *msg; enum CRStatus status; glong line; glong column; @@ -197,9 +197,9 @@ if ((a_status) != CR_OK) \ */ #define PEEK_NEXT_CHAR(a_this, a_to_char) \ {\ -enum CRStatus status ; \ -status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, a_to_char) ; \ -CHECK_PARSING_STATUS (status, TRUE) \ +enum CRStatus pnc_status ; \ +pnc_status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, a_to_char) ; \ +CHECK_PARSING_STATUS (pnc_status, TRUE) \ } /** @@ -374,11 +374,11 @@ static enum CRStatus cr_parser_parse_simple_selector (CRParser * a_this, static enum CRStatus cr_parser_parse_simple_sels (CRParser * a_this, CRSimpleSel ** a_sel); -static CRParserError *cr_parser_error_new (const gchar * a_msg, +static CRParserError *cr_parser_error_new (const guchar * a_msg, enum CRStatus); static void cr_parser_error_set_msg (CRParserError * a_this, - const gchar * a_msg); + const guchar * a_msg); static void cr_parser_error_dump (CRParserError * a_this); @@ -392,7 +392,7 @@ static void cr_parser_error_destroy (CRParserError * a_this); static enum CRStatus cr_parser_push_error (CRParser * a_this, - const gchar * a_msg, + const guchar * a_msg, enum CRStatus a_status); static enum CRStatus cr_parser_dump_err_stack (CRParser * a_this, @@ -411,7 +411,7 @@ static enum CRStatus *@return the newly built instance of #CRParserError. */ static CRParserError * -cr_parser_error_new (const gchar * a_msg, enum CRStatus a_status) +cr_parser_error_new (const guchar * a_msg, enum CRStatus a_status) { CRParserError *result = NULL; @@ -436,7 +436,7 @@ cr_parser_error_new (const gchar * a_msg, enum CRStatus a_status) *@param a_msg the new message. */ static void -cr_parser_error_set_msg (CRParserError * a_this, const gchar * a_msg) +cr_parser_error_set_msg (CRParserError * a_this, const guchar * a_msg) { g_return_if_fail (a_this); @@ -444,7 +444,7 @@ cr_parser_error_set_msg (CRParserError * a_this, const gchar * a_msg) g_free (a_this->msg); } - a_this->msg = g_strdup (a_msg); + a_this->msg = (guchar *) g_strdup ((const gchar *) a_msg); } /** @@ -515,7 +515,7 @@ cr_parser_error_destroy (CRParserError * a_this) */ static enum CRStatus cr_parser_push_error (CRParser * a_this, - const gchar * a_msg, enum CRStatus a_status) + const guchar * a_msg, enum CRStatus a_status) { enum CRStatus status = CR_OK; @@ -733,7 +733,7 @@ cr_parser_parse_stylesheet_core (CRParser * a_this) error: cr_parser_push_error - (a_this, "could not recognize next production", CR_ERROR); + (a_this, (const guchar *) "could not recognize next production", CR_ERROR); cr_parser_dump_err_stack (a_this, TRUE); @@ -1688,14 +1688,12 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel) && token->u.unichar == '*') { int comb = (int)sel->type_mask | (int) UNIVERSAL_SELECTOR; sel->type_mask = (enum SimpleSelectorType)comb; - //sel->type_mask |= UNIVERSAL_SELECTOR; sel->name = cr_string_new_from_string ("*"); found_sel = TRUE; } else if (token && token->type == IDENT_TK) { sel->name = token->u.str; int comb = (int)sel->type_mask | (int) TYPE_SELECTOR; sel->type_mask = (enum SimpleSelectorType)comb; - //sel->type_mask |= TYPE_SELECTOR; token->u.str = NULL; found_sel = TRUE; } else { @@ -2707,7 +2705,7 @@ cr_parser_parse_stylesheet (CRParser * a_this) } cr_parser_push_error - (a_this, "could not recognize next production", CR_ERROR); + (a_this, (const guchar *) "could not recognize next production", CR_ERROR); if (PRIVATE (a_this)->sac_handler && PRIVATE (a_this)->sac_handler->unrecoverable_error) { @@ -3193,7 +3191,7 @@ cr_parser_parse_declaration (CRParser * a_this, CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, - "while parsing declaration: next property is malformed", + (const guchar *) "while parsing declaration: next property is malformed", CR_SYNTAX_ERROR); READ_NEXT_CHAR (a_this, &cur_char); @@ -3202,7 +3200,7 @@ cr_parser_parse_declaration (CRParser * a_this, status = CR_PARSING_ERROR; cr_parser_push_error (a_this, - "while parsing declaration: this char must be ':'", + (const guchar *) "while parsing declaration: this char must be ':'", CR_SYNTAX_ERROR); goto error; } @@ -3213,7 +3211,7 @@ cr_parser_parse_declaration (CRParser * a_this, CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, - "while parsing declaration: next expression is malformed", + (const guchar *) "while parsing declaration: next expression is malformed", CR_SYNTAX_ERROR); cr_parser_try_to_skip_spaces_and_comments (a_this); @@ -3353,7 +3351,7 @@ cr_parser_parse_ruleset (CRParser * a_this) ENSURE_PARSING_COND_ERR (a_this, cur_char == '{', - "while parsing rulset: current char should be '{'", + (const guchar *) "while parsing rulset: current char should be '{'", CR_SYNTAX_ERROR); if (PRIVATE (a_this)->sac_handler @@ -3417,7 +3415,7 @@ cr_parser_parse_ruleset (CRParser * a_this) } CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, - "while parsing ruleset: next construction should be a declaration", + (const guchar *) "while parsing ruleset: next construction should be a declaration", CR_SYNTAX_ERROR); for (;;) { @@ -3459,7 +3457,7 @@ cr_parser_parse_ruleset (CRParser * a_this) READ_NEXT_CHAR (a_this, &cur_char); ENSURE_PARSING_COND_ERR (a_this, cur_char == '}', - "while parsing rulset: current char must be a '}'", + (const guchar *) "while parsing rulset: current char must be a '}'", CR_SYNTAX_ERROR); selector->location = end_parsing_location; diff --git a/src/libcroco/cr-pseudo.c b/src/libcroco/cr-pseudo.c index a46e69ed0..cee3fc869 100644 --- a/src/libcroco/cr-pseudo.c +++ b/src/libcroco/cr-pseudo.c @@ -68,11 +68,11 @@ cr_pseudo_to_string (CRPseudo const * a_this) goto error; } - name = g_strndup (a_this->name->stryng->str, + name = (guchar *) g_strndup (a_this->name->stryng->str, a_this->name->stryng->len); if (name) { - g_string_append (str_buf, name); + g_string_append (str_buf, (const gchar *) name); g_free (name); name = NULL; } @@ -83,11 +83,11 @@ cr_pseudo_to_string (CRPseudo const * a_this) if (a_this->name == NULL) goto error; - name = g_strndup (a_this->name->stryng->str, + name = (guchar *) g_strndup (a_this->name->stryng->str, a_this->name->stryng->len); if (a_this->extra) { - arg = g_strndup (a_this->extra->stryng->str, + arg = (guchar *) g_strndup (a_this->extra->stryng->str, a_this->extra->stryng->len); } @@ -97,7 +97,7 @@ cr_pseudo_to_string (CRPseudo const * a_this) name = NULL; if (arg) { - g_string_append (str_buf, arg); + g_string_append (str_buf, (const gchar *) arg); g_free (arg); arg = NULL; } @@ -107,7 +107,7 @@ cr_pseudo_to_string (CRPseudo const * a_this) } if (str_buf) { - result = str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } diff --git a/src/libcroco/cr-rgb.c b/src/libcroco/cr-rgb.c index 537343579..889f248b6 100644 --- a/src/libcroco/cr-rgb.c +++ b/src/libcroco/cr-rgb.c @@ -275,7 +275,7 @@ cr_rgb_to_string (CRRgb const * a_this) } if (str_buf) { - result = str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); } @@ -507,7 +507,7 @@ cr_rgb_set_from_hex_str (CRRgb * a_this, const guchar * a_hex) g_return_val_if_fail (a_this && a_hex, CR_BAD_PARAM_ERROR); - if (strlen (a_hex) == 3) { + if (strlen ((const char *) a_hex) == 3) { for (i = 0; i < 3; i++) { if (a_hex[i] >= '0' && a_hex[i] <= '9') { colors[i] = a_hex[i] - '0'; @@ -522,7 +522,7 @@ cr_rgb_set_from_hex_str (CRRgb * a_this, const guchar * a_hex) status = CR_UNKNOWN_TYPE_ERROR; } } - } else if (strlen (a_hex) == 6) { + } else if (strlen ((const char *) a_hex) == 6) { for (i = 0; i < 6; i++) { if (a_hex[i] >= '0' && a_hex[i] <= '9') { colors[i / 2] <<= 4; @@ -587,7 +587,7 @@ cr_rgb_set_from_term (CRRgb *a_this, const struct _CRTerm *a_value) } else { status = cr_rgb_set_from_name (a_this, - a_value->content.str->stryng->str) ; + (const guchar *) a_value->content.str->stryng->str) ; } } else { cr_utils_trace_info @@ -600,7 +600,7 @@ cr_rgb_set_from_term (CRRgb *a_this, const struct _CRTerm *a_value) && a_value->content.str->stryng->str) { status = cr_rgb_set_from_hex_str (a_this, - a_value->content.str->stryng->str) ; + (const guchar *) a_value->content.str->stryng->str) ; } else { cr_utils_trace_info ("a_value has NULL string value") ; @@ -656,8 +656,7 @@ cr_rgb_parse_from_buf (const guchar *a_str, g_return_val_if_fail (a_str, NULL); - parser = cr_parser_new_from_buf ((guchar*)a_str, strlen (a_str), - a_enc, FALSE) ; + parser = cr_parser_new_from_buf ((guchar *) a_str, strlen ((const char *) a_str), a_enc, FALSE); g_return_val_if_fail (parser, NULL); diff --git a/src/libcroco/cr-sel-eng.c b/src/libcroco/cr-sel-eng.c index 4f501ee05..ed40de393 100644 --- a/src/libcroco/cr-sel-eng.c +++ b/src/libcroco/cr-sel-eng.c @@ -37,7 +37,7 @@ #define PRIVATE(a_this) (a_this)->priv struct CRPseudoClassSelHandlerEntry { - char *name; + guchar *name; enum CRPseudoType type; CRPseudoClassSelectorHandler handler; }; @@ -149,8 +149,8 @@ lang_pseudo_class_handler (CRSelEng *const a_this, || a_sel->content.pseudo->extra->stryng->len < 2) return FALSE; for (; node; node = get_next_parent_element_node (node_iface, node)) { - char *val = node_iface->getProp (node, "lang"); - if (!val) val = node_iface->getProp (node, "xml:lang"); + char *val = node_iface->getProp (node, (const xmlChar *) "lang"); + if (!val) val = node_iface->getProp (node, (const xmlChar *) "xml:lang"); if (val) { if (!strcasecmp(val, a_sel->content.pseudo->extra->stryng->str)) { result = TRUE; @@ -209,7 +209,7 @@ pseudo_class_add_sel_matches_node (CRSelEng * a_this, && a_node, FALSE); status = cr_sel_eng_get_pseudo_class_selector_handler - (a_this, a_add_sel->content.pseudo->name->stryng->str, + (a_this, (guchar *) a_add_sel->content.pseudo->name->stryng->str, a_add_sel->content.pseudo->type, &handler); if (status != CR_OK || !handler) return FALSE; @@ -237,7 +237,7 @@ class_add_sel_matches_node (CRAdditionalSel * a_add_sel, && a_add_sel->content.class_name->stryng->str && a_node, FALSE); - klass = a_node_iface->getProp (a_node, "class"); + klass = a_node_iface->getProp (a_node, (const xmlChar *) "class"); if (klass) { char const *cur; for (cur = klass; cur && *cur; cur++) { @@ -246,7 +246,7 @@ class_add_sel_matches_node (CRAdditionalSel * a_add_sel, == TRUE) cur++; - if (!strncmp (cur, + if (!strncmp ((const char *) cur, a_add_sel->content.class_name->stryng->str, a_add_sel->content.class_name->stryng->len)) { cur += a_add_sel->content.class_name->stryng->len; @@ -291,9 +291,9 @@ id_add_sel_matches_node (CRAdditionalSel * a_add_sel, && a_add_sel->type == ID_ADD_SELECTOR && a_node, FALSE); - id = a_node_iface->getProp (a_node, "id"); + id = a_node_iface->getProp (a_node, (const xmlChar *) "id"); if (id) { - if (!strqcmp (id, a_add_sel->content.id_name->stryng->str, + if (!strqcmp ((const char *) id, a_add_sel->content.id_name->stryng->str, a_add_sel->content.id_name->stryng->len)) { result = TRUE; } @@ -324,7 +324,7 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, for (cur_sel = a_add_sel->content.attr_sel; cur_sel; cur_sel = cur_sel->next) { - if (!cur_sel->name + if (!cur_sel->name || !cur_sel->name->stryng || !cur_sel->name->stryng->str) return FALSE; @@ -384,7 +384,7 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, ptr2 = cur; if (!strncmp - (ptr1, + ((const char *) ptr1, cur_sel->value->stryng->str, ptr2 - ptr1 + 1)) { found = TRUE; @@ -422,7 +422,7 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, ptr2 = cur; if (g_strstr_len - (ptr1, ptr2 - ptr1 + 1, + ((const gchar *) ptr1, ptr2 - ptr1 + 1, cur_sel->value->stryng->str) == ptr1) { found = TRUE; @@ -635,7 +635,7 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel, && cur_sel->name->stryng && cur_sel->name->stryng->str) && (!strcmp (cur_sel->name->stryng->str, - node_iface->getLocalName(cur_node)))) + (const char *) node_iface->getLocalName(cur_node)))) || (cur_sel->type_mask & UNIVERSAL_SELECTOR)) { /* *this simple selector @@ -1121,11 +1121,11 @@ cr_sel_eng_new (void) } memset (PRIVATE (result), 0, sizeof (CRSelEngPriv)); cr_sel_eng_register_pseudo_class_sel_handler - (result, "first-child", + (result, (guchar *) "first-child", IDENT_PSEUDO, /*(CRPseudoClassSelectorHandler)*/ first_child_pseudo_class_handler); cr_sel_eng_register_pseudo_class_sel_handler - (result, "lang", + (result, (guchar *) "lang", FUNCTION_PSEUDO, /*(CRPseudoClassSelectorHandler)*/ lang_pseudo_class_handler); @@ -1146,7 +1146,7 @@ cr_sel_eng_new (void) */ enum CRStatus cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng * a_this, - char * a_name, + guchar * a_name, enum CRPseudoType a_type, CRPseudoClassSelectorHandler a_handler) @@ -1164,7 +1164,7 @@ cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng * a_this, } memset (handler_entry, 0, sizeof (struct CRPseudoClassSelHandlerEntry)); - handler_entry->name = g_strdup (a_name); + handler_entry->name = (guchar *) g_strdup ((const gchar *) a_name); handler_entry->type = a_type; handler_entry->handler = a_handler; list = g_list_append (PRIVATE (a_this)->pcs_handlers, handler_entry); @@ -1177,7 +1177,7 @@ cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng * a_this, enum CRStatus cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng * a_this, - char * a_name, + guchar * a_name, enum CRPseudoType a_type) { GList *elem = NULL, @@ -1190,7 +1190,7 @@ cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng * a_this, for (elem = PRIVATE (a_this)->pcs_handlers; elem; elem = g_list_next (elem)) { entry = (struct CRPseudoClassSelHandlerEntry *) elem->data; - if (!strcmp (entry->name, a_name) + if (!strcmp ((const char *) entry->name, (const char *) a_name) && entry->type == a_type) { found = TRUE; break; @@ -1250,7 +1250,7 @@ cr_sel_eng_unregister_all_pseudo_class_sel_handlers (CRSelEng * a_this) enum CRStatus cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng * a_this, - char * a_name, + guchar * a_name, enum CRPseudoType a_type, CRPseudoClassSelectorHandler * a_handler) @@ -1265,7 +1265,7 @@ cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng * a_this, for (elem = PRIVATE (a_this)->pcs_handlers; elem; elem = g_list_next (elem)) { entry = (struct CRPseudoClassSelHandlerEntry *) elem->data; - if (!strcmp (a_name, entry->name) + if (!strcmp ((const char *) a_name, (const char *) entry->name) && entry->type == a_type) { found = TRUE; break; diff --git a/src/libcroco/cr-sel-eng.h b/src/libcroco/cr-sel-eng.h index 4d09f9c95..564debc8d 100644 --- a/src/libcroco/cr-sel-eng.h +++ b/src/libcroco/cr-sel-eng.h @@ -65,18 +65,18 @@ typedef gboolean (*CRPseudoClassSelectorHandler) (CRSelEng* a_this, CRSelEng * cr_sel_eng_new (void) ; enum CRStatus cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng *a_this, - char *a_pseudo_class_sel_name, + guchar *a_pseudo_class_sel_name, enum CRPseudoType a_pseudo_class_type, CRPseudoClassSelectorHandler a_handler) ; enum CRStatus cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng *a_this, - char *a_pseudo_class_sel_name, + guchar *a_pseudo_class_sel_name, enum CRPseudoType a_pseudo_class_type) ; enum CRStatus cr_sel_eng_unregister_all_pseudo_class_sel_handlers (CRSelEng *a_this) ; enum CRStatus cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng *a_this, - char *a_pseudo_class_sel_name, + guchar *a_pseudo_class_sel_name, enum CRPseudoType a_pseudo_class_type, CRPseudoClassSelectorHandler *a_handler) ; diff --git a/src/libcroco/cr-selector.c b/src/libcroco/cr-selector.c index 43a3bd914..c56c43fda 100644 --- a/src/libcroco/cr-selector.c +++ b/src/libcroco/cr-selector.c @@ -38,7 +38,10 @@ CRSelector * cr_selector_new (CRSimpleSel * a_simple_sel) { - CRSelector *result = (CRSelector *)g_try_malloc (sizeof (CRSelector)); + CRSelector *result = NULL; + + result = (CRSelector *) g_try_malloc (sizeof (CRSelector)); + if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -55,8 +58,7 @@ cr_selector_parse_from_buf (const guchar * a_char_buf, enum CREncoding a_enc) g_return_val_if_fail (a_char_buf, NULL); - parser = cr_parser_new_from_buf ((guchar*)a_char_buf, - strlen ((char *)a_char_buf), + parser = cr_parser_new_from_buf ((guchar*)a_char_buf, strlen ((const char *) a_char_buf), a_enc, FALSE); g_return_val_if_fail (parser, NULL); @@ -140,8 +142,9 @@ guchar * cr_selector_to_string (CRSelector const * a_this) { guchar *result = NULL; + GString *str_buf = NULL; - GString *str_buf = (GString *)g_string_new (NULL); + str_buf = (GString *) g_string_new (NULL); g_return_val_if_fail (str_buf, NULL); if (a_this) { @@ -159,7 +162,7 @@ cr_selector_to_string (CRSelector const * a_this) g_string_append (str_buf, ", "); - g_string_append (str_buf, (gchar *)tmp_str); + g_string_append (str_buf, (const gchar *) tmp_str); g_free (tmp_str); tmp_str = NULL; @@ -169,7 +172,7 @@ cr_selector_to_string (CRSelector const * a_this) } if (str_buf) { - result = (guchar *)str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } diff --git a/src/libcroco/cr-simple-sel.c b/src/libcroco/cr-simple-sel.c index 4f5ac965a..a4670fe88 100644 --- a/src/libcroco/cr-simple-sel.c +++ b/src/libcroco/cr-simple-sel.c @@ -35,7 +35,9 @@ CRSimpleSel * cr_simple_sel_new (void) { - CRSimpleSel *result = (CRSimpleSel *)g_try_malloc (sizeof (CRSimpleSel)); + CRSimpleSel *result = NULL; + + result = (CRSimpleSel *) g_try_malloc (sizeof (CRSimpleSel)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -110,7 +112,7 @@ cr_simple_sel_to_string (CRSimpleSel const * a_this) str_buf = g_string_new (NULL); for (cur = a_this; cur; cur = cur->next) { if (cur->name) { - gchar *str = g_strndup (cur->name->stryng->str, + guchar *str = (guchar *) g_strndup (cur->name->stryng->str, cur->name->stryng->len); if (str) { @@ -131,17 +133,18 @@ cr_simple_sel_to_string (CRSimpleSel const * a_this) break; } - g_string_append (str_buf, str); + g_string_append (str_buf, (const gchar *) str); g_free (str); str = NULL; } } if (cur->add_sel) { + guchar *tmp_str = NULL; - gchar *tmp_str = (gchar *)cr_additional_sel_to_string (cur->add_sel); + tmp_str = cr_additional_sel_to_string (cur->add_sel); if (tmp_str) { - g_string_append (str_buf, tmp_str); + g_string_append (str_buf, (const gchar *) tmp_str); g_free (tmp_str); tmp_str = NULL; } @@ -149,7 +152,7 @@ cr_simple_sel_to_string (CRSimpleSel const * a_this) } if (str_buf) { - result = (guchar *)str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } @@ -168,7 +171,7 @@ cr_simple_sel_one_to_string (CRSimpleSel const * a_this) str_buf = g_string_new (NULL); if (a_this->name) { - gchar *str = g_strndup (a_this->name->stryng->str, + guchar *str = (guchar *) g_strndup (a_this->name->stryng->str, a_this->name->stryng->len); if (str) { @@ -179,8 +182,9 @@ cr_simple_sel_one_to_string (CRSimpleSel const * a_this) } if (a_this->add_sel) { + guchar *tmp_str = NULL; - gchar *tmp_str = (gchar *)cr_additional_sel_to_string (a_this->add_sel); + tmp_str = cr_additional_sel_to_string (a_this->add_sel); if (tmp_str) { g_string_append_printf (str_buf, "%s", tmp_str); @@ -190,7 +194,7 @@ cr_simple_sel_one_to_string (CRSimpleSel const * a_this) } if (str_buf) { - result = (guchar *)str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } diff --git a/src/libcroco/cr-statement.c b/src/libcroco/cr-statement.c index 4666f26ec..e31123aec 100644 --- a/src/libcroco/cr-statement.c +++ b/src/libcroco/cr-statement.c @@ -25,8 +25,6 @@ #include "cr-statement.h" #include "cr-parser.h" -#define UNUSED(_param) ((void)(_param)) - /** *@file *Definition of the #CRStatement class. @@ -38,12 +36,12 @@ static void cr_statement_clear (CRStatement * a_this); static void parse_font_face_start_font_face_cb (CRDocHandler * a_this, - CRParsingLocation * a_location) + CRParsingLocation *a_location) { CRStatement *stmt = NULL; enum CRStatus status = CR_OK; - UNUSED(a_location); + (void) a_location; stmt = cr_statement_new_at_font_face_rule (NULL, NULL); g_return_if_fail (stmt); @@ -86,7 +84,7 @@ parse_font_face_property_cb (CRDocHandler * a_this, CRStatement *stmt = NULL; CRStatement **stmtptr = NULL; - UNUSED(a_important); + (void) a_important; g_return_if_fail (a_this && a_name); @@ -144,13 +142,13 @@ static void parse_page_start_page_cb (CRDocHandler * a_this, CRString * a_name, CRString * a_pseudo_page, - CRParsingLocation * a_location) + CRParsingLocation *a_location) { CRStatement *stmt = NULL; enum CRStatus status = CR_OK; CRString *page_name = NULL, *pseudo_name = NULL ; - UNUSED(a_location); + (void) a_location; if (a_name) page_name = cr_string_dup (a_name) ; @@ -225,8 +223,8 @@ parse_page_end_page_cb (CRDocHandler * a_this, CRStatement *stmt = NULL; CRStatement **stmtptr = NULL; - UNUSED(a_name); - UNUSED(a_pseudo_page); + (void) a_name; + (void) a_pseudo_page; stmtptr = &stmt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr); @@ -240,13 +238,13 @@ parse_page_end_page_cb (CRDocHandler * a_this, static void parse_at_media_start_media_cb (CRDocHandler * a_this, GList * a_media_list, - CRParsingLocation * a_location) + CRParsingLocation *a_location) { enum CRStatus status = CR_OK; CRStatement *at_media = NULL; GList *media_list = NULL; - UNUSED(a_location); + (void) a_location; g_return_if_fail (a_this && a_this->priv); @@ -380,7 +378,7 @@ parse_at_media_end_media_cb (CRDocHandler * a_this, CRStatement *at_media = NULL; CRStatement **at_media_ptr = NULL; - UNUSED(a_media_list); + (void) a_media_list; g_return_if_fail (a_this && a_this->priv); @@ -603,12 +601,13 @@ cr_statement_clear (CRStatement * a_this) static gchar * cr_statement_ruleset_to_string (CRStatement const * a_this, glong a_indent) { + GString *stringue = NULL; gchar *tmp_str = NULL, *result = NULL; g_return_val_if_fail (a_this && a_this->type == RULESET_STMT, NULL); - GString * stringue = (GString *)g_string_new (NULL); + stringue = (GString *) g_string_new (NULL); if (!stringue) { return result; } @@ -617,8 +616,8 @@ cr_statement_ruleset_to_string (CRStatement const * a_this, glong a_indent) if (a_indent) cr_utils_dump_n_chars2 (' ', stringue, a_indent); - tmp_str = (gchar *) - cr_selector_to_string (a_this->kind.ruleset-> + tmp_str = + (gchar *) cr_selector_to_string (a_this->kind.ruleset-> sel_list); if (tmp_str) { g_string_append (stringue, tmp_str); @@ -628,7 +627,7 @@ cr_statement_ruleset_to_string (CRStatement const * a_this, glong a_indent) } g_string_append (stringue, " {\n"); if (a_this->kind.ruleset->decl_list) { - tmp_str = (gchar *)cr_declaration_list_to_string2 + tmp_str = (gchar *) cr_declaration_list_to_string2 (a_this->kind.ruleset->decl_list, a_indent + DECLARATION_INDENT_NB, TRUE); if (tmp_str) { @@ -677,13 +676,13 @@ cr_statement_font_face_rule_to_string (CRStatement const * a_this, NULL); if (a_this->kind.font_face_rule->decl_list) { - stringue = (GString *)g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; g_return_val_if_fail (stringue, NULL) ; if (a_indent) cr_utils_dump_n_chars2 (' ', stringue, a_indent); g_string_append (stringue, "@font-face {\n"); - tmp_str = (gchar *)cr_declaration_list_to_string2 + tmp_str = (gchar *) cr_declaration_list_to_string2 (a_this->kind.font_face_rule->decl_list, a_indent + DECLARATION_INDENT_NB, TRUE) ; if (tmp_str) { @@ -762,9 +761,10 @@ static gchar * cr_statement_at_page_rule_to_string (CRStatement const *a_this, gulong a_indent) { + GString *stringue = NULL; gchar *result = NULL ; - GString *stringue = (GString *)g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; cr_utils_dump_n_chars2 (' ', stringue, a_indent) ; g_string_append (stringue, "@page"); @@ -785,7 +785,7 @@ cr_statement_at_page_rule_to_string (CRStatement const *a_this, if (a_this->kind.page_rule->decl_list) { gchar *str = NULL ; g_string_append (stringue, " {\n"); - str = (gchar *)cr_declaration_list_to_string2 + str = (gchar *) cr_declaration_list_to_string2 (a_this->kind.page_rule->decl_list, a_indent + DECLARATION_INDENT_NB, TRUE) ; if (str) { @@ -821,17 +821,17 @@ cr_statement_media_rule_to_string (CRStatement const *a_this, NULL); if (a_this->kind.media_rule) { - stringue = (GString *)g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; cr_utils_dump_n_chars2 (' ', stringue, a_indent); g_string_append (stringue, "@media"); for (cur = a_this->kind.media_rule->media_list; cur; cur = cur->next) { if (cur->data) { - gchar *str = cr_string_dup2 + gchar *str2 = cr_string_dup2 ((CRString const *) cur->data); - if (str) { + if (str2) { if (cur->prev) { g_string_append (stringue, @@ -839,9 +839,9 @@ cr_statement_media_rule_to_string (CRStatement const *a_this, } g_string_append_printf (stringue, - " %s", str); - g_free (str); - str = NULL; + " %s", str2); + g_free (str2); + str2 = NULL; } } } @@ -878,7 +878,7 @@ cr_statement_import_rule_to_string (CRStatement const *a_this, if (a_this->kind.import_rule->url && a_this->kind.import_rule->url->stryng) { - stringue = (GString *)g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; g_return_val_if_fail (stringue, NULL) ; str = g_strndup (a_this->kind.import_rule->url->stryng->str, a_this->kind.import_rule->url->stryng->len); @@ -950,8 +950,7 @@ cr_statement_does_buf_parses_against_core (const guchar * a_buf, enum CRStatus status = CR_OK; gboolean result = FALSE; - parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_encoding, FALSE); g_return_val_if_fail (parser, FALSE); @@ -1071,8 +1070,7 @@ cr_statement_ruleset_parse_from_buf (const guchar * a_buf, g_return_val_if_fail (a_buf, NULL); - parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_enc, FALSE); g_return_val_if_fail (parser, NULL); @@ -1138,6 +1136,8 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet, CRDeclaration * a_decl_list, CRStatement * a_parent_media_rule) { + CRStatement *result = NULL; + g_return_val_if_fail (a_sel_list, NULL); if (a_parent_media_rule) { @@ -1148,7 +1148,7 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet, NULL); } - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1157,7 +1157,7 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = RULESET_STMT; - result->kind.ruleset = (CRRuleSet *)g_try_malloc (sizeof (CRRuleSet)); + result->kind.ruleset = (CRRuleSet *) g_try_malloc (sizeof (CRRuleSet)); if (!result->kind.ruleset) { cr_utils_trace_info ("Out of memory"); @@ -1207,8 +1207,7 @@ cr_statement_at_media_rule_parse_from_buf (const guchar * a_buf, CRDocHandler *sac_handler = NULL; enum CRStatus status = CR_OK; - parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_enc, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of the parser failed"); @@ -1278,12 +1277,13 @@ CRStatement * cr_statement_new_at_media_rule (CRStyleSheet * a_sheet, CRStatement * a_rulesets, GList * a_media) { - CRStatement *cur = NULL; + CRStatement *result = NULL, + *cur = NULL; if (a_rulesets) g_return_val_if_fail (a_rulesets->type == RULESET_STMT, NULL); - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1293,7 +1293,7 @@ cr_statement_new_at_media_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_MEDIA_RULE_STMT; - result->kind.media_rule = (CRAtMediaRule *)g_try_malloc (sizeof (CRAtMediaRule)); + result->kind.media_rule = (CRAtMediaRule *) g_try_malloc (sizeof (CRAtMediaRule)); if (!result->kind.media_rule) { cr_utils_trace_info ("Out of memory"); g_free (result); @@ -1340,7 +1340,9 @@ cr_statement_new_at_import_rule (CRStyleSheet * a_container_sheet, GList * a_media_list, CRStyleSheet * a_imported_sheet) { - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + CRStatement *result = NULL; + + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1350,7 +1352,7 @@ cr_statement_new_at_import_rule (CRStyleSheet * a_container_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_IMPORT_RULE_STMT; - result->kind.import_rule = (CRAtImportRule *)g_try_malloc (sizeof (CRAtImportRule)); + result->kind.import_rule = (CRAtImportRule *) g_try_malloc (sizeof (CRAtImportRule)); if (!result->kind.import_rule) { cr_utils_trace_info ("Out of memory"); @@ -1391,8 +1393,7 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf, CRString *import_string = NULL; CRParsingLocation location = {0,0,0} ; - parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_encoding, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of parser failed."); @@ -1425,8 +1426,7 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf, parser = NULL; } if (media_list) { - GList *cur = NULL; - for (cur = media_list; media_list; + for (; media_list; media_list = g_list_next (media_list)) { if (media_list->data) { cr_string_destroy ((CRString*)media_list->data); @@ -1463,7 +1463,9 @@ cr_statement_new_at_page_rule (CRStyleSheet * a_sheet, CRDeclaration * a_decl_list, CRString * a_name, CRString * a_pseudo) { - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + CRStatement *result = NULL; + + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1473,7 +1475,7 @@ cr_statement_new_at_page_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_PAGE_RULE_STMT; - result->kind.page_rule = (CRAtPageRule *)g_try_malloc (sizeof (CRAtPageRule)); + result->kind.page_rule = (CRAtPageRule *) g_try_malloc (sizeof (CRAtPageRule)); if (!result->kind.page_rule) { cr_utils_trace_info ("Out of memory"); @@ -1511,14 +1513,14 @@ cr_statement_at_page_rule_parse_from_buf (const guchar * a_buf, enum CREncoding a_encoding) { enum CRStatus status = CR_OK; + CRParser *parser = NULL; CRDocHandler *sac_handler = NULL; CRStatement *result = NULL; CRStatement **resultptr = NULL; g_return_val_if_fail (a_buf, NULL); - CRParser *parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_encoding, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of the parser failed."); @@ -1584,9 +1586,11 @@ CRStatement * cr_statement_new_at_charset_rule (CRStyleSheet * a_sheet, CRString * a_charset) { + CRStatement *result = NULL; + g_return_val_if_fail (a_charset, NULL); - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1596,7 +1600,7 @@ cr_statement_new_at_charset_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_CHARSET_RULE_STMT; - result->kind.charset_rule = (CRAtCharsetRule *)g_try_malloc (sizeof (CRAtCharsetRule)); + result->kind.charset_rule = (CRAtCharsetRule *) g_try_malloc (sizeof (CRAtCharsetRule)); if (!result->kind.charset_rule) { cr_utils_trace_info ("Out of memory"); @@ -1626,13 +1630,13 @@ cr_statement_at_charset_rule_parse_from_buf (const guchar * a_buf, enum CREncoding a_encoding) { enum CRStatus status = CR_OK; + CRParser *parser = NULL; CRStatement *result = NULL; CRString *charset = NULL; g_return_val_if_fail (a_buf, NULL); - CRParser *parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_encoding, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of the parser failed."); @@ -1678,7 +1682,9 @@ CRStatement * cr_statement_new_at_font_face_rule (CRStyleSheet * a_sheet, CRDeclaration * a_font_decls) { - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + CRStatement *result = NULL; + + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1687,7 +1693,7 @@ cr_statement_new_at_font_face_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_FONT_FACE_RULE_STMT; - result->kind.font_face_rule = (CRAtFontFaceRule *)g_try_malloc + result->kind.font_face_rule = (CRAtFontFaceRule *) g_try_malloc (sizeof (CRAtFontFaceRule)); if (!result->kind.font_face_rule) { @@ -1723,12 +1729,11 @@ cr_statement_font_face_rule_parse_from_buf (const guchar * a_buf, { CRStatement *result = NULL; CRStatement **resultptr = NULL; + CRParser *parser = NULL; CRDocHandler *sac_handler = NULL; enum CRStatus status = CR_OK; - CRParser *parser = (CRParser *)cr_parser_new_from_buf ( - (guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_encoding, FALSE); if (!parser) goto cleanup; @@ -2614,8 +2619,10 @@ cr_statement_dump (CRStatement const * a_this, FILE * a_fp, gulong a_indent) void cr_statement_dump_ruleset (CRStatement const * a_this, FILE * a_fp, glong a_indent) { + gchar *str = NULL; + g_return_if_fail (a_fp && a_this); - gchar *str = cr_statement_ruleset_to_string (a_this, a_indent); + str = cr_statement_ruleset_to_string (a_this, a_indent); if (str) { fprintf (a_fp, "%s", str); g_free (str); @@ -2661,9 +2668,11 @@ cr_statement_dump_font_face_rule (CRStatement const * a_this, FILE * a_fp, void cr_statement_dump_charset (CRStatement const * a_this, FILE * a_fp, gulong a_indent) { + gchar *str = NULL; + g_return_if_fail (a_this && a_this->type == AT_CHARSET_RULE_STMT); - gchar *str = cr_statement_charset_to_string (a_this, + str = cr_statement_charset_to_string (a_this, a_indent) ; if (str) { fprintf (a_fp, "%s", str) ; @@ -2685,11 +2694,13 @@ cr_statement_dump_charset (CRStatement const * a_this, FILE * a_fp, gulong a_ind void cr_statement_dump_page (CRStatement const * a_this, FILE * a_fp, gulong a_indent) { + gchar *str = NULL; + g_return_if_fail (a_this && a_this->type == AT_PAGE_RULE_STMT && a_this->kind.page_rule); - gchar *str = cr_statement_at_page_rule_to_string (a_this, a_indent) ; + str = cr_statement_at_page_rule_to_string (a_this, a_indent) ; if (str) { fprintf (a_fp, "%s", str); g_free (str) ; diff --git a/src/libcroco/cr-string.c b/src/libcroco/cr-string.c index 47d557d5b..86ad3432c 100644 --- a/src/libcroco/cr-string.c +++ b/src/libcroco/cr-string.c @@ -32,7 +32,9 @@ CRString * cr_string_new (void) { - CRString *result = (CRString *)g_try_malloc (sizeof (CRString)) ; + CRString *result = NULL ; + + result = (CRString *) g_try_malloc (sizeof (CRString)) ; if (!result) { cr_utils_trace_info ("Out of memory") ; return NULL ; @@ -51,7 +53,9 @@ cr_string_new (void) CRString * cr_string_new_from_string (const gchar * a_string) { - CRString *result = cr_string_new () ; + CRString *result = NULL ; + + result = cr_string_new () ; if (!result) { cr_utils_trace_info ("Out of memory") ; return NULL ; @@ -70,7 +74,9 @@ cr_string_new_from_string (const gchar * a_string) CRString * cr_string_new_from_gstring (GString const *a_string) { - CRString *result = cr_string_new () ; + CRString *result = NULL ; + + result = cr_string_new () ; if (!result) { cr_utils_trace_info ("Out of memory") ; return NULL ; @@ -87,9 +93,10 @@ cr_string_new_from_gstring (GString const *a_string) CRString * cr_string_dup (CRString const *a_this) { + CRString *result = NULL ; g_return_val_if_fail (a_this, NULL) ; - CRString *result = cr_string_new_from_gstring (a_this->stryng) ; + result = cr_string_new_from_gstring (a_this->stryng) ; if (!result) { cr_utils_trace_info ("Out of memory") ; return NULL ; diff --git a/src/libcroco/cr-style.c b/src/libcroco/cr-style.c index a9c5a5cec..2b865c248 100644 --- a/src/libcroco/cr-style.c +++ b/src/libcroco/cr-style.c @@ -140,9 +140,9 @@ static CRPropertyDesc gv_prop_table[] = { {"font-size", PROP_ID_FONT_SIZE}, {"font-style", PROP_ID_FONT_STYLE}, {"font-weight", PROP_ID_FONT_WEIGHT}, - {"white-space", PROP_ID_WHITE_SPACE}, + {"white-space", PROP_ID_WHITE_SPACE}, /*must be the last one */ - {NULL, (enum CRPropertyID)0} + {NULL, (enum CRPropertyID) 0} }; /** @@ -185,7 +185,7 @@ static struct CRNumPropEnumDumpInfo gv_num_props_dump_infos[] = { {NUM_PROP_MARGIN_BOTTOM, "margin-bottom"}, {NUM_PROP_MARGIN_LEFT, "margin-left"}, {NUM_PROP_WIDTH, "width"}, - {(enum CRNumProp)0, NULL} + {(enum CRNumProp) 0, NULL} }; struct CRRgbPropEnumDumpInfo { @@ -200,7 +200,7 @@ static struct CRRgbPropEnumDumpInfo gv_rgb_props_dump_infos[] = { {RGB_PROP_BORDER_LEFT_COLOR, "left-color"}, {RGB_PROP_COLOR, "color"}, {RGB_PROP_BACKGROUND_COLOR, "background-color"}, - {(enum CRRgbProp)0, NULL} + {(enum CRRgbProp) 0, NULL} }; struct CRBorderStylePropEnumDumpInfo { @@ -215,7 +215,7 @@ static struct CRBorderStylePropEnumDumpInfo gv_border_style_props_dump_infos[] {BORDER_STYLE_PROP_RIGHT, "border-style-right"}, {BORDER_STYLE_PROP_BOTTOM, "boder-style-bottom"}, {BORDER_STYLE_PROP_LEFT, "border-style-left"}, - {(enum CRBorderStyleProp)0, NULL} + {(enum CRBorderStyleProp) 0, NULL} }; static enum CRStatus @@ -319,9 +319,9 @@ set_prop_font_weight_from_value (CRStyle * a_style, CRTerm * a_value); static const gchar * num_prop_code_to_string (enum CRNumProp a_code) { - int len = sizeof (gv_num_props_dump_infos) / + guint len = sizeof (gv_num_props_dump_infos) / sizeof (struct CRNumPropEnumDumpInfo); - if ((int)a_code >= len) { + if (a_code >= len) { cr_utils_trace_info ("A field has been added " "to 'enum CRNumProp' and no matching" " entry has been " @@ -342,10 +342,10 @@ num_prop_code_to_string (enum CRNumProp a_code) static const gchar * rgb_prop_code_to_string (enum CRRgbProp a_code) { - int len = sizeof (gv_rgb_props_dump_infos) / + guint len = sizeof (gv_rgb_props_dump_infos) / sizeof (struct CRRgbPropEnumDumpInfo); - if ((int)a_code >= len) { + if (a_code >= len) { cr_utils_trace_info ("A field has been added " "to 'enum CRRgbProp' and no matching" " entry has been " @@ -366,10 +366,10 @@ rgb_prop_code_to_string (enum CRRgbProp a_code) static const gchar * border_style_prop_code_to_string (enum CRBorderStyleProp a_code) { - int len = sizeof (gv_border_style_props_dump_infos) / + guint len = sizeof (gv_border_style_props_dump_infos) / sizeof (struct CRBorderStylePropEnumDumpInfo); - if ((int)a_code >= len) { + if (a_code >= len) { cr_utils_trace_info ("A field has been added " "to 'enum CRBorderStyleProp' and no matching" " entry has been " @@ -421,7 +421,7 @@ cr_style_get_prop_id (const guchar * a_prop) cr_style_init_properties (); } - raw_id = (gpointer *)g_hash_table_lookup (gv_prop_hash, a_prop); + raw_id = (gpointer *) g_hash_table_lookup (gv_prop_hash, a_prop); if (!raw_id) { return PROP_ID_NOT_KNOWN; } @@ -465,7 +465,7 @@ set_prop_padding_x_from_value (CRStyle * a_style, if (a_value->content.str && a_value->content.str->stryng && a_value->content.str->stryng->str - && !strncmp ("inherit", + && !strncmp ((const char *) "inherit", a_value->content.str->stryng->str, sizeof ("inherit")-1)) { status = cr_num_set (num_val, 0.0, NUM_INHERIT); @@ -569,9 +569,10 @@ static enum CRStatus set_prop_border_width_from_value (CRStyle *a_style, CRTerm *a_value) { + CRTerm *cur_term = NULL ; g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - CRTerm *cur_term = a_value ; + cur_term = a_value ; if (!cur_term) return CR_ERROR ; @@ -579,7 +580,7 @@ set_prop_border_width_from_value (CRStyle *a_style, int dir; for (dir = (int) DIR_TOP ; dir < (int)NB_DIRS ; dir++) { enum CRDirection direction = (enum CRDirection)dir; - set_prop_border_x_width_from_value (a_style, + set_prop_border_x_width_from_value (a_style, cur_term, direction) ; } @@ -696,16 +697,18 @@ static enum CRStatus set_prop_border_style_from_value (CRStyle *a_style, CRTerm *a_value) { + CRTerm *cur_term = NULL ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - CRTerm *cur_term = a_value ; + cur_term = a_value ; if (!cur_term || cur_term->type != TERM_IDENT) { return CR_ERROR ; } int dir; - for (dir = (int)DIR_TOP ; dir < (int)NB_DIRS ; dir++) { + for (dir = (int)DIR_TOP ; dir < (int)NB_DIRS ; dir++) { enum CRDirection direction = (enum CRDirection)dir; set_prop_border_x_style_from_value (a_style, cur_term, @@ -908,7 +911,7 @@ set_prop_position_from_value (CRStyle * a_style, CRTerm * a_value) break; } - return CR_OK; + return status; } static enum CRStatus @@ -1115,11 +1118,11 @@ set_prop_border_x_color_from_value (CRStyle * a_style, CRTerm * a_value, && a_value->content.str->stryng->str) { status = cr_rgb_set_from_name (rgb_color, - (guchar *)a_value->content.str->stryng->str); + (const guchar *) a_value->content.str->stryng->str); } if (status != CR_OK) { - cr_rgb_set_from_name (rgb_color, (guchar *)"black"); + cr_rgb_set_from_name (rgb_color, (const guchar *) "black"); } } else if (a_value->type == TERM_RGB) { if (a_value->content.rgb) { @@ -1354,7 +1357,7 @@ set_prop_font_family_from_value (CRStyle * a_style, CRTerm * a_value) && cur_term->content.str->stryng->str) { cur_ff = cr_font_family_new (FONT_FAMILY_NON_GENERIC, - (guchar *)cur_term->content.str->stryng->str); + (guchar *) cur_term->content.str->stryng->str); } } break; @@ -1707,7 +1710,9 @@ set_prop_white_space_from_value (CRStyle * a_style, CRTerm * a_value) CRStyle * cr_style_new (gboolean a_set_props_to_initial_values) { - CRStyle *result = (CRStyle *)g_try_malloc (sizeof (CRStyle)); + CRStyle *result = NULL; + + result = (CRStyle *) g_try_malloc (sizeof (CRStyle)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -2018,7 +2023,7 @@ cr_style_set_style_from_decl (CRStyle * a_this, CRDeclaration * a_decl) CR_BAD_PARAM_ERROR); prop_id = cr_style_get_prop_id - ((guchar *)a_decl->property->stryng->str); + ((const guchar *) a_decl->property->stryng->str); value = a_decl->value; switch (prop_id) { @@ -2676,7 +2681,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) *before outputing it value */ cr_utils_dump_n_chars2 (' ', str, indent); - tmp_str = (gchar *) num_prop_code_to_string ((enum CRNumProp)i); + tmp_str = (gchar *) num_prop_code_to_string ((enum CRNumProp) i); if (tmp_str) { g_string_append_printf (str, "%s: ", tmp_str); } else { @@ -2690,7 +2695,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) } /*loop over the rgb_props and to_string() them all */ for (i = RGB_PROP_BORDER_TOP_COLOR; i < NB_RGB_PROPS; i++) { - tmp_str = (gchar *) rgb_prop_code_to_string ((enum CRRgbProp)i); + tmp_str = (gchar *) rgb_prop_code_to_string ((enum CRRgbProp) i); cr_utils_dump_n_chars2 (' ', str, indent); if (tmp_str) { g_string_append_printf (str, "%s: ", tmp_str); @@ -2705,8 +2710,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) } /*loop over the border_style_props and to_string() them */ for (i = BORDER_STYLE_PROP_TOP; i < NB_BORDER_STYLE_PROPS; i++) { - tmp_str = (gchar *) - border_style_prop_code_to_string ((enum CRBorderStyleProp)i); + tmp_str = (gchar *) border_style_prop_code_to_string ((enum CRBorderStyleProp) i); cr_utils_dump_n_chars2 (' ', str, indent); if (tmp_str) { g_string_append_printf (str, "%s: ", tmp_str); @@ -2741,7 +2745,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) cr_utils_dump_n_chars2 (' ', str, indent); g_string_append (str, "font-family: "); - tmp_str = (gchar *)cr_font_family_to_string (a_this->font_family, TRUE); + tmp_str = (gchar *) cr_font_family_to_string (a_this->font_family, TRUE); if (tmp_str) { g_string_append (str, tmp_str); g_free (tmp_str); diff --git a/src/libcroco/cr-stylesheet.c b/src/libcroco/cr-stylesheet.c index 1b26c64bf..cb5de6958 100644 --- a/src/libcroco/cr-stylesheet.c +++ b/src/libcroco/cr-stylesheet.c @@ -36,7 +36,9 @@ CRStyleSheet * cr_stylesheet_new (CRStatement * a_stmts) { - CRStyleSheet *result = (CRStyleSheet *)g_try_malloc (sizeof (CRStyleSheet)); + CRStyleSheet *result; + + result = (CRStyleSheet *) g_try_malloc (sizeof (CRStyleSheet)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; diff --git a/src/libcroco/cr-term.c b/src/libcroco/cr-term.c index 09b6354db..1c50aed2a 100644 --- a/src/libcroco/cr-term.c +++ b/src/libcroco/cr-term.c @@ -84,7 +84,9 @@ cr_term_clear (CRTerm * a_this) CRTerm * cr_term_new (void) { - CRTerm *result = (CRTerm *)g_try_malloc (sizeof (CRTerm)); + CRTerm *result = NULL; + + result = (CRTerm *) g_try_malloc (sizeof (CRTerm)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -104,15 +106,14 @@ CRTerm * cr_term_parse_expression_from_buf (const guchar * a_buf, enum CREncoding a_encoding) { + CRParser *parser = NULL; CRTerm *result = NULL; enum CRStatus status = CR_OK; g_return_val_if_fail (a_buf, NULL); - CRParser *parser = cr_parser_new_from_buf ( - (guchar*)a_buf, - strlen ((char *)a_buf), - a_encoding, FALSE); + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), + a_encoding, FALSE); g_return_val_if_fail (parser, NULL); status = cr_parser_try_to_skip_spaces_and_comments (parser); @@ -279,8 +280,8 @@ cr_term_to_string (CRTerm const * a_this) { GString *str_buf = NULL; CRTerm const *cur = NULL; - guchar *result = NULL; - gchar *content = NULL; + guchar *result = NULL, + *content = NULL; g_return_val_if_fail (a_this, NULL); @@ -329,11 +330,11 @@ cr_term_to_string (CRTerm const * a_this) switch (cur->type) { case TERM_NUMBER: if (cur->content.num) { - content = (gchar *)cr_num_to_string (cur->content.num); + content = cr_num_to_string (cur->content.num); } if (content) { - g_string_append (str_buf, content); + g_string_append (str_buf, (const gchar *) content); g_free (content); content = NULL; } @@ -342,7 +343,7 @@ cr_term_to_string (CRTerm const * a_this) case TERM_FUNCTION: if (cur->content.str) { - content = g_strndup + content = (guchar *) g_strndup (cur->content.str->stryng->str, cur->content.str->stryng->len); } @@ -360,22 +361,21 @@ cr_term_to_string (CRTerm const * a_this) if (tmp_str) { g_string_append (str_buf, - (gchar *)tmp_str); + (const gchar *) tmp_str); g_free (tmp_str); tmp_str = NULL; } - } + g_string_append (str_buf, ")"); g_free (content); content = NULL; - g_string_append (str_buf, ")"); } break; case TERM_STRING: if (cur->content.str) { - content = g_strndup + content = (guchar *) g_strndup (cur->content.str->stryng->str, cur->content.str->stryng->len); } @@ -390,13 +390,13 @@ cr_term_to_string (CRTerm const * a_this) case TERM_IDENT: if (cur->content.str) { - content = g_strndup + content = (guchar *) g_strndup (cur->content.str->stryng->str, cur->content.str->stryng->len); } if (content) { - g_string_append (str_buf, content); + g_string_append (str_buf, (const gchar *) content); g_free (content); content = NULL; } @@ -404,9 +404,9 @@ cr_term_to_string (CRTerm const * a_this) case TERM_URI: if (cur->content.str) { - content = g_strndup - (cur->content.str->stryng->str, - cur->content.str->stryng->len); + content = (guchar *) g_strndup + (cur->content.str->stryng->str, + cur->content.str->stryng->len); } if (content) { @@ -425,7 +425,7 @@ cr_term_to_string (CRTerm const * a_this) tmp_str = cr_rgb_to_string (cur->content.rgb); if (tmp_str) { - g_string_append (str_buf, (gchar *)tmp_str); + g_string_append (str_buf, (const gchar *) tmp_str); g_free (tmp_str); tmp_str = NULL; } @@ -442,7 +442,7 @@ cr_term_to_string (CRTerm const * a_this) case TERM_HASH: if (cur->content.str) { - content = g_strndup + content = (guchar *) g_strndup (cur->content.str->stryng->str, cur->content.str->stryng->len); } @@ -463,7 +463,7 @@ cr_term_to_string (CRTerm const * a_this) } if (str_buf) { - result = (guchar *)str_buf->str; + result =(guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } @@ -475,8 +475,8 @@ guchar * cr_term_one_to_string (CRTerm const * a_this) { GString *str_buf = NULL; - guchar *result = NULL; - gchar *content = NULL; + guchar *result = NULL, + *content = NULL; g_return_val_if_fail (a_this, NULL); @@ -524,11 +524,11 @@ cr_term_one_to_string (CRTerm const * a_this) switch (a_this->type) { case TERM_NUMBER: if (a_this->content.num) { - content = (gchar *)cr_num_to_string (a_this->content.num); + content = cr_num_to_string (a_this->content.num); } if (content) { - g_string_append (str_buf, content); + g_string_append (str_buf, (const gchar *) content); g_free (content); content = NULL; } @@ -537,7 +537,7 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_FUNCTION: if (a_this->content.str) { - content = g_strndup + content = (guchar *) g_strndup (a_this->content.str->stryng->str, a_this->content.str->stryng->len); } @@ -571,7 +571,7 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_STRING: if (a_this->content.str) { - content = g_strndup + content = (guchar *) g_strndup (a_this->content.str->stryng->str, a_this->content.str->stryng->len); } @@ -586,13 +586,13 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_IDENT: if (a_this->content.str) { - content = g_strndup + content = (guchar *) g_strndup (a_this->content.str->stryng->str, a_this->content.str->stryng->len); } if (content) { - g_string_append (str_buf, content); + g_string_append (str_buf, (const gchar *) content); g_free (content); content = NULL; } @@ -600,7 +600,7 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_URI: if (a_this->content.str) { - content = g_strndup + content = (guchar *) g_strndup (a_this->content.str->stryng->str, a_this->content.str->stryng->len); } @@ -615,12 +615,13 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_RGB: if (a_this->content.rgb) { + guchar *tmp_str = NULL; g_string_append_printf (str_buf, "rgb("); - gchar *tmp_str = (gchar *)cr_rgb_to_string (a_this->content.rgb); + tmp_str = cr_rgb_to_string (a_this->content.rgb); if (tmp_str) { - g_string_append (str_buf, tmp_str); + g_string_append (str_buf, (const gchar *) tmp_str); g_free (tmp_str); tmp_str = NULL; } @@ -637,7 +638,7 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_HASH: if (a_this->content.str) { - content = g_strndup + content = (guchar *) g_strndup (a_this->content.str->stryng->str, a_this->content.str->stryng->len); } @@ -658,7 +659,7 @@ cr_term_one_to_string (CRTerm const * a_this) } if (str_buf) { - result = (guchar *)str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } diff --git a/src/libcroco/cr-tknzr.c b/src/libcroco/cr-tknzr.c index 1f762b5c5..228471bf9 100644 --- a/src/libcroco/cr-tknzr.c +++ b/src/libcroco/cr-tknzr.c @@ -1586,7 +1586,9 @@ cr_tknzr_parse_num (CRTknzr * a_this, CRTknzr * cr_tknzr_new (CRInput * a_input) { - CRTknzr *result = (CRTknzr *)g_try_malloc (sizeof (CRTknzr)); + CRTknzr *result = NULL; + + result = (CRTknzr *) g_try_malloc (sizeof (CRTknzr)); if (result == NULL) { cr_utils_trace_info ("Out of memory"); @@ -1636,7 +1638,9 @@ cr_tknzr_new_from_uri (const guchar * a_file_uri, enum CREncoding a_enc) { CRTknzr *result = NULL; - CRInput *input = cr_input_new_from_uri ((gchar *)a_file_uri, a_enc); + CRInput *input = NULL; + + input = cr_input_new_from_uri ((const gchar *) a_file_uri, a_enc); g_return_val_if_fail (input != NULL, NULL); result = cr_tknzr_new (input); @@ -1909,7 +1913,7 @@ cr_tknzr_consume_chars (CRTknzr * a_this, guint32 a_char, glong * a_nb_char) } return cr_input_consume_chars (PRIVATE (a_this)->input, - a_char, (gulong *)a_nb_char); + a_char, a_nb_char); } enum CRStatus @@ -2097,15 +2101,15 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk) if (BYTE (input, 2, NULL) == 'r' && BYTE (input, 3, NULL) == 'l' && BYTE (input, 4, NULL) == '(') { - CRString *str = NULL; + CRString *str2 = NULL; - status = cr_tknzr_parse_uri (a_this, &str); + status = cr_tknzr_parse_uri (a_this, &str2); if (status == CR_OK) { - status = cr_token_set_uri (token, str); + status = cr_token_set_uri (token, str2); CHECK_PARSING_STATUS (status, TRUE); - if (str) { + if (str2) { cr_parsing_location_copy (&token->location, - &str->location) ; + &str2->location) ; } goto done; } diff --git a/src/libcroco/cr-token.c b/src/libcroco/cr-token.c index 3dd73ac3e..dfe83e221 100644 --- a/src/libcroco/cr-token.c +++ b/src/libcroco/cr-token.c @@ -133,7 +133,9 @@ cr_token_clear (CRToken * a_this) CRToken * cr_token_new (void) { - CRToken *result = (CRToken *)g_try_malloc (sizeof (CRToken)); + CRToken *result = NULL; + + result = (CRToken *) g_try_malloc (sizeof (CRToken)); if (result == NULL) { cr_utils_trace_info ("Out of memory"); diff --git a/src/libcroco/cr-utils.c b/src/libcroco/cr-utils.c index a51c76920..bfb587017 100644 --- a/src/libcroco/cr-utils.c +++ b/src/libcroco/cr-utils.c @@ -429,9 +429,8 @@ cr_utils_read_char_from_utf8_buf (const guchar * a_in, gulong a_in_len, guint32 * a_out, gulong * a_consumed) { - gulong in_len = 0, - in_index = 0, - nb_bytes_2_decode = 0; + gulong in_index = 0, + nb_bytes_2_decode = 0; enum CRStatus status = CR_OK; /* @@ -448,8 +447,6 @@ cr_utils_read_char_from_utf8_buf (const guchar * a_in, goto end; } - in_len = a_in_len; - if (*a_in <= 0x7F) { /* *7 bits long char @@ -901,15 +898,10 @@ cr_utils_ucs1_to_utf8 (const guchar * a_in, if (*a_in_len == 0) { *a_out_len = 0 ; - return CR_OK ; + return status; } g_return_val_if_fail (a_out, CR_BAD_PARAM_ERROR) ; - if (*a_in_len < 1) { - status = CR_OK; - goto end; - } - in_len = *a_in_len; out_len = *a_out_len; @@ -930,11 +922,10 @@ cr_utils_ucs1_to_utf8 (const guchar * a_in, } } /*end for */ - end: *a_in_len = in_index; *a_out_len = out_index; - return CR_OK; + return status; } /** @@ -951,8 +942,7 @@ cr_utils_ucs1_str_to_utf8 (const guchar * a_in, gulong * a_in_len, guchar ** a_out, gulong * a_out_len) { - gulong in_len = 0, - out_len = 0; + gulong out_len = 0; enum CRStatus status = CR_OK; g_return_val_if_fail (a_in && a_in_len && a_out @@ -969,8 +959,6 @@ cr_utils_ucs1_str_to_utf8 (const guchar * a_in, g_return_val_if_fail (status == CR_OK, status); - in_len = *a_in_len; - *a_out = (guchar *) g_malloc0 (out_len); status = cr_utils_ucs1_to_utf8 (a_in, a_in_len, *a_out, &out_len); @@ -1023,7 +1011,6 @@ cr_utils_utf8_to_ucs1 (const guchar * a_in, && a_out && a_out_len, CR_BAD_PARAM_ERROR); if (*a_in_len < 1) { - status = CR_OK; goto end; } @@ -1102,7 +1089,6 @@ cr_utils_utf8_to_ucs1 (const guchar * a_in, *(if any) to get the current character. */ if (in_index + nb_bytes_2_decode - 1 >= in_len) { - status = CR_OK; goto end; } @@ -1136,7 +1122,7 @@ cr_utils_utf8_to_ucs1 (const guchar * a_in, *a_out_len = out_index; *a_in_len = in_index; - return CR_OK; + return status; } /** -- cgit v1.2.3 From 2eb442ffbe3a13afe002df5aca335cbefaed156b Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sat, 7 Nov 2015 20:06:34 +0100 Subject: static code analysis (bzr r14450) --- src/selection.cpp | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/selection.cpp b/src/selection.cpp index 77a507eec..020912381 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -255,7 +255,7 @@ void Selection::addList(std::vector const &list) { _invalidateCachedLists(); - for ( std::vector::const_iterator iter=list.begin();iter!=list.end();iter++ ) { + for ( std::vector::const_iterator iter=list.begin();iter!=list.end(); ++iter) { SPObject *obj = *iter; if (includes(obj)) continue; _add (obj); @@ -267,7 +267,7 @@ void Selection::addList(std::vector const &list) { void Selection::setReprList(std::vector const &list) { _clear(); - for ( std::vector::const_reverse_iterator iter=list.rbegin();iter!=list.rend();iter++ ) { + for ( std::vector::const_reverse_iterator iter=list.rbegin();iter!=list.rend(); ++iter) { SPObject *obj=_objectForXMLNode(*iter); if (obj) { _add(obj); @@ -286,7 +286,7 @@ std::vector const &Selection::list() { if(!_objs_vector.empty()) return _objs_vector; - for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end(); ++iter) { _objs_vector.push_back(*iter); } return _objs_vector; @@ -298,7 +298,7 @@ std::vector const &Selection::itemList() { return _items; } - for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end(); ++iter) { SPObject *obj=*iter; if (SP_IS_ITEM(obj)) { _items.push_back(SP_ITEM(obj)); @@ -310,7 +310,7 @@ std::vector const &Selection::itemList() { std::vector const &Selection::reprList() { if (!_reprs.empty()) { return _reprs; } std::vector list = itemList(); - for ( std::vector::const_iterator iter=list.begin();iter!=list.end();iter++ ) { + for ( std::vector::const_iterator iter=list.begin();iter!=list.end(); ++iter) { SPObject *obj = *iter; _reprs.push_back(obj->getRepr()); } @@ -372,7 +372,7 @@ SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { gdouble max = sml ? 1e18 : 0; SPItem *ist = NULL; - for ( std::vector::const_iterator i=items.begin();i!=items.end();i++ ) { + for ( std::vector::const_iterator i=items.begin();i!=items.end(); ++i) { Geom::OptRect obox = SP_ITEM(*i)->desktopPreferredBounds(); if (!obox || obox.isEmpty()) continue; Geom::Rect bbox = *obox; @@ -404,7 +404,7 @@ Geom::OptRect Selection::geometricBounds() const std::vector const items = const_cast(this)->itemList(); Geom::OptRect bbox; - for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { bbox.unionWith(SP_ITEM(*iter)->desktopGeometricBounds()); } return bbox; @@ -415,7 +415,7 @@ Geom::OptRect Selection::visualBounds() const std::vector const items = const_cast(this)->itemList(); Geom::OptRect bbox; - for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { bbox.unionWith(SP_ITEM(*iter)->desktopVisualBounds()); } return bbox; @@ -436,7 +436,7 @@ Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const std::vector const items = const_cast(this)->itemList(); if (items.empty()) return bbox; - for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPItem *item = SP_ITEM(*iter); bbox |= item->documentBounds(type); } @@ -463,19 +463,21 @@ boost::optional Selection::center() const { } std::vector Selection::getSnapPoints(SnapPreferences const *snapprefs) const { - std::vector const items = const_cast(this)->itemList(); - - SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs - snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, false); // locally disable snapping to the item center std::vector p; - for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { - SPItem *this_item = *iter; - this_item->getSnappoints(p, &snapprefs_dummy); - - //Include the transformation origin for snapping - //For a selection or group only the overall center is considered, not for each item individually - if (snapprefs != NULL && snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER)) { - p.push_back(Inkscape::SnapCandidatePoint(this_item->getCenter(), SNAPSOURCE_ROTATION_CENTER)); + + if (snapprefs != NULL){ + SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs + snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, false); // locally disable snapping to the item center + std::vector const items = const_cast(this)->itemList(); + for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { + SPItem *this_item = *iter; + this_item->getSnappoints(p, &snapprefs_dummy); + + //Include the transformation origin for snapping + //For a selection or group only the overall center is considered, not for each item individually + if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER)) { + p.push_back(Inkscape::SnapCandidatePoint(this_item->getCenter(), SNAPSOURCE_ROTATION_CENTER)); + } } } @@ -484,7 +486,7 @@ std::vector Selection::getSnapPoints(SnapPreferenc void Selection::_removeObjectDescendants(SPObject *obj) { std::vector toremove; - for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end(); ++iter) { SPObject *sel_obj= dynamic_cast(*iter); SPObject *parent = sel_obj->parent; while (parent) { @@ -495,7 +497,7 @@ void Selection::_removeObjectDescendants(SPObject *obj) { parent = parent->parent; } } - for ( std::vector::const_iterator iter=toremove.begin();iter!=toremove.end();iter++ ) { + for ( std::vector::const_iterator iter=toremove.begin();iter!=toremove.end(); ++iter) { _remove(*iter); } } @@ -522,7 +524,7 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { size_t Selection::numberOfLayers() { std::vector const items = const_cast(this)->itemList(); std::set layers; - for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPObject *layer = _layers->layerForObject(*iter); layers.insert(layer); } @@ -532,7 +534,7 @@ size_t Selection::numberOfLayers() { size_t Selection::numberOfParents() { std::vector const items = const_cast(this)->itemList(); std::set parents; - for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPObject *parent = (*iter)->parent; parents.insert(parent); } -- cgit v1.2.3 From e27c914a9673a447a13e1be8eba799939100acf7 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sat, 7 Nov 2015 20:15:21 +0100 Subject: static code analysis (bzr r14451) --- src/sp-clippath.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/sp-clippath.h b/src/sp-clippath.h index c9a8c68df..8abe97f3f 100644 --- a/src/sp-clippath.h +++ b/src/sp-clippath.h @@ -93,10 +93,10 @@ protected: Inkscape::XML::Node * const owner_repr = owner->getRepr(); //XML Tree being used directly here while it shouldn't be... Inkscape::XML::Node * const obj_repr = obj->getRepr(); - char const * owner_name = NULL; - char const * owner_clippath = NULL; - char const * obj_name = NULL; - char const * obj_id = NULL; + char const * owner_name = ""; + char const * owner_clippath = ""; + char const * obj_name = ""; + char const * obj_id = ""; if (owner_repr != NULL) { owner_name = owner_repr->name(); owner_clippath = owner_repr->attribute("clippath"); -- 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 From 31aa6219ac721c59cb1a98788dbca7b7a58c5000 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 10 Nov 2015 18:23:11 +0100 Subject: Spray Tool: Change hide invisibe by over visible and over invisible, sugested by Ivan Louette (bzr r14453) --- src/ui/tools/spray-tool.cpp | 47 +++++++++++++++++++++++++++---------------- src/ui/tools/spray-tool.h | 3 ++- src/widgets/spray-toolbar.cpp | 41 ++++++++++++++++++++++++++++--------- src/widgets/toolbox.cpp | 3 ++- 4 files changed, 65 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 17b82fe1d..99cb78936 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -178,7 +178,8 @@ SprayTool::SprayTool() , pickinversevalue(false) , pickfill(false) , pickstroke(false) - , visible(false) + , overtransparent(true) + , overnotransparent(true) , offset(0) { } @@ -259,7 +260,8 @@ void SprayTool::setup() { sp_event_context_read(this, "pickinversevalue"); sp_event_context_read(this, "pickfill"); sp_event_context_read(this, "pickstroke"); - sp_event_context_read(this, "visible"); + sp_event_context_read(this, "overnotransparent"); + sp_event_context_read(this, "overtransparent"); sp_event_context_read(this, "nooverlap"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -312,8 +314,10 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->pickfill = val.getBool(); } else if (path == "pickstroke") { this->pickstroke = val.getBool(); - } else if (path == "visible") { - this->visible = val.getBool(); + } else if (path == "overnotransparent") { + this->overnotransparent = val.getBool(); + } else if (path == "overtransparent") { + this->overtransparent = val.getBool(); } else if (path == "nooverlap") { this->nooverlap = val.getBool(); } @@ -440,7 +444,8 @@ static bool fit_item(SPDesktop *desktop, bool pickinversevalue, bool pickfill, bool pickstroke, - bool visible, + bool overnotransparent, + bool overtransparent, bool nooverlap, double offset, SPCSSAttr *css, @@ -485,7 +490,10 @@ static bool fit_item(SPDesktop *desktop, 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)){ + if(nooverlap && !overtransparent && (A==0 || A < 1e-6)){ + return false; + } + if(nooverlap && !overnotransparent && A>0){ return false; } size = std::min(width_transformed,height_transformed); @@ -525,14 +533,14 @@ 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 || !overtransparent || !overnotransparent){ item_down->setHidden(true); item_down->updateRepr(); } } } } - if(picker || visible){ + if(picker || !overtransparent || !overnotransparent){ if(!nooverlap){ doc->ensureUpToDate(); } @@ -555,7 +563,10 @@ static bool fit_item(SPDesktop *desktop, g = 1; b = 1; } - if(visible && (a == 0 || a < 1e-6)){ + if(!overtransparent && (a == 0 || a < 1e-6)){ + return false; + } + if(!overnotransparent && a >0){ return false; } @@ -649,7 +660,8 @@ static bool fit_item(SPDesktop *desktop, pickinversevalue, pickfill, pickstroke, - visible, + overnotransparent, + overtransparent, nooverlap, offset, css, @@ -699,7 +711,7 @@ static bool fit_item(SPDesktop *desktop, sp_repr_css_set_property(css, "stroke", color_string); } } - if(!nooverlap && (picker || visible)){ + if(!nooverlap && (picker || !overtransparent || !overnotransparent)){ for (std::vector::const_iterator k=items_down.begin(); k!=items_down.end(); k++) { SPItem *item_hidden = *k; item_hidden->setHidden(false); @@ -732,7 +744,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, bool pickinversevalue, bool pickfill, bool pickstroke, - bool visible, + bool overnotransparent, + bool overtransparent, double offset, bool usepressurescale, double pressure) @@ -773,8 +786,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(nooverlap || picker || visible){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversevalue, pickfill, pickstroke, visible, nooverlap, offset, css, false)){ + if(nooverlap || picker || !overtransparent || !overnotransparent){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversevalue, pickfill, pickstroke, overnotransparent, overtransparent, nooverlap, offset, css, false)){ return false; } } @@ -880,8 +893,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(nooverlap || picker || visible){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversevalue, pickfill, pickstroke, visible, nooverlap, offset, css, false)){ + if(nooverlap || picker || !overtransparent || !overnotransparent){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversevalue, pickfill, pickstroke, overnotransparent, overtransparent, nooverlap, offset, css, false)){ return false; } } @@ -959,7 +972,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->pickinversevalue, 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->overnotransparent, tc->overtransparent, 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 ca0c20375..ba4e75f70 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -94,7 +94,8 @@ public: bool pickinversevalue; bool pickfill; bool pickstroke; - bool visible; + bool overtransparent; + bool overnotransparent; double offset; sigc::connection style_set_connection; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 5e0d81964..fe69b5050 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -186,13 +186,21 @@ static void sp_toggle_pressure_scale( GtkToggleAction* act, gpointer data) sp_stb_sensitivize( tbl ); } -static void sp_toggle_visible( GtkToggleAction* act, gpointer data) +static void sp_toggle_over_no_transparent( GtkToggleAction* act, gpointer data) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setBool("/tools/spray/visible", active); + prefs->setBool("/tools/spray/overnotransparent", active); } +static void sp_toggle_over_transparent( GtkToggleAction* act, gpointer data) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/overtransparent", active); +} + + static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -472,17 +480,30 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_stroke), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - - /* Visible */ + + /* Over Transparent */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayOverTransparentAction", + _("Apply over transparent areas"), + _("Apply over transparent areas"), + INKSCAPE_ICON("object-hidden"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/overtransparent", true) ); + g_object_set_data( holder, "overtransparent", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_over_transparent), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Over No Transparent */ { - InkToggleAction* act = ink_toggle_action_new( "SprayOverVisibleAction", - _("Apply only over non transparent areas"), - _("Apply only over non transparent areas"), + InkToggleAction* act = ink_toggle_action_new( "SprayOverNoTransparentAction", + _("Apply over no transparent areas"), + _("Apply over no 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_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/overnotransparent", true) ); + g_object_set_data( holder, "overnotransparent", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_over_no_transparent), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index cdb9e0d20..b9051dd50 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -321,7 +321,8 @@ static gchar const * ui_descr = " " " " " " - " " + " " + " " " " " " " " -- cgit v1.2.3 From de44c6059f00e773cef5c22534e12a1adc50b3a4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 11 Nov 2015 01:02:03 +0100 Subject: Improvements to the over visible/invisible to minimize the colisions, sprayed items fit on background whith overlap visible or invisible areas Add option in picker mode to compute the center/or average area of sprayed item Now reverse work without adbanced trace dialog inverting the color. By this all buttons have a utility in advanced and in normal mode (bzr r14454) --- src/ui/tools/spray-tool.cpp | 115 ++++++++++++++++++++++++++++++++++-------- src/ui/tools/spray-tool.h | 1 + src/widgets/spray-toolbar.cpp | 28 ++++++++-- src/widgets/toolbox.cpp | 7 +-- 4 files changed, 125 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 99cb78936..1ec7815c5 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -175,6 +175,7 @@ SprayTool::SprayTool() , dilate_area(NULL) , nooverlap(false) , picker(false) + , pickcenter(true) , pickinversevalue(false) , pickfill(false) , pickstroke(false) @@ -257,6 +258,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, "pickcenter"); sp_event_context_read(this, "pickinversevalue"); sp_event_context_read(this, "pickfill"); sp_event_context_read(this, "pickstroke"); @@ -308,6 +310,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 == "pickcenter") { + this->pickcenter = val.getBool(); } else if (path == "pickinversevalue") { this->pickinversevalue = val.getBool(); } else if (path == "pickfill") { @@ -432,6 +436,33 @@ double randomize01(double val, double rand) return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case... } +guint32 getPickerData(Geom::IntRect area){ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + double R = 0, G = 0, B = 0, A = 0; + cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, area.width(), area.height()); + 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); + return SP_RGBA32_F_COMPOSE(R, G, B, A); +} + +bool isTrans(Geom::Point N){ + gint32 rgba = getPickerData(Geom::IntRect::from_xywh(floor(N[Geom::X]), floor(N[Geom::Y]), 1, 1)); + return SP_RGBA32_A_F(rgba)==0 || SP_RGBA32_A_F(rgba) < 1e-6; +} + +bool overTrans(Geom::Point A, Geom::Point B, Geom::Point C, Geom::Point D){ + return isTrans(A) || isTrans(B) || isTrans(C) || isTrans(D); +} + +static void showHidden(std::vector items_down){ + 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(); + } +} + static bool fit_item(SPDesktop *desktop, SPItem *item, Geom::OptRect bbox, @@ -441,6 +472,7 @@ static bool fit_item(SPDesktop *desktop, double &_scale, double scale, bool picker, + bool pickcenter, bool pickinversevalue, bool pickfill, bool pickstroke, @@ -479,21 +511,32 @@ static bool fit_item(SPDesktop *desktop, path *= desktop->doc2dt(); bbox_procesed = path.boundsFast(); double bbox_left_main = bbox_procesed->left(); + double bbox_right_main = bbox_procesed->right(); double bbox_top_main = bbox_procesed->top(); + double bbox_bottom_main = bbox_procesed->bottom(); double width_transformed = bbox_procesed->width(); double height_transformed = bbox_procesed->height(); Geom::Point mid_point = desktop->d2w(bbox_procesed->midpoint()); + Geom::Rect rect_sprayed(mid_point, mid_point); + rect_sprayed.expandBy(width_transformed/2.0, height_transformed/2.0); 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 && !overtransparent && (A==0 || A < 1e-6)){ + if (!rect_sprayed.hasZeroArea() && (!pickcenter || (overtransparent && !overnotransparent))) { + area = rect_sprayed.roundOutwards(); + } + guint32 rgba = getPickerData(area); + if(!overtransparent && overnotransparent){ + Geom::Point lt = desktop->d2w(Geom::Point(floor(bbox_left_main),floor(bbox_top_main))); + Geom::Point rt = desktop->d2w(Geom::Point(floor(bbox_right_main),floor(bbox_top_main))); + Geom::Point rb = desktop->d2w(Geom::Point(floor(bbox_right_main),floor(bbox_bottom_main))); + Geom::Point lb = desktop->d2w(Geom::Point(floor(bbox_left_main),floor(bbox_bottom_main))); + if(overTrans(lt, rt, rb, lb)){ + return false; + } + } + if(nooverlap && !overtransparent && (SP_RGBA32_A_F(rgba)==0 || SP_RGBA32_A_F(rgba) < 1e-6)){ return false; } - if(nooverlap && !overnotransparent && A>0){ + if(nooverlap && !overnotransparent && SP_RGBA32_A_F(rgba)>0){ return false; } size = std::min(width_transformed,height_transformed); @@ -533,16 +576,29 @@ static bool fit_item(SPDesktop *desktop, std::abs(bbox_top - bbox_top_main) > std::abs(offset_min))){ return false; } - } else if(picker || !overtransparent || !overnotransparent){ + } else if(picker || overtransparent || overnotransparent){ item_down->setHidden(true); item_down->updateRepr(); } } } } - if(picker || !overtransparent || !overnotransparent){ + if(picker || overtransparent || overnotransparent){ if(!nooverlap){ doc->ensureUpToDate(); + rgba = getPickerData(area); + } + if(!overtransparent && overnotransparent){ + Geom::Point lt = desktop->d2w(Geom::Point(floor(bbox_left_main),floor(bbox_top_main))); + Geom::Point rt = desktop->d2w(Geom::Point(floor(bbox_right_main),floor(bbox_top_main))); + Geom::Point rb = desktop->d2w(Geom::Point(floor(bbox_right_main),floor(bbox_bottom_main))); + Geom::Point lb = desktop->d2w(Geom::Point(floor(bbox_left_main),floor(bbox_bottom_main))); + if(overTrans(lt, rt, rb, lb)){ + if(!nooverlap && (picker || overtransparent || overnotransparent)){ + showHidden(items_down); + } + return false; + } } int pick = prefs->getInt("/dialogs/clonetiler/pick"); bool pick_to_presence = prefs->getBool("/dialogs/clonetiler/pick_to_presence", false); @@ -564,9 +620,15 @@ static bool fit_item(SPDesktop *desktop, b = 1; } if(!overtransparent && (a == 0 || a < 1e-6)){ + if(!nooverlap && (picker || overtransparent || overnotransparent)){ + showHidden(items_down); + } return false; } - if(!overnotransparent && a >0){ + if(!overnotransparent && a > 0){ + if(!nooverlap && (picker || overtransparent || overnotransparent)){ + showHidden(items_down); + } return false; } @@ -646,6 +708,9 @@ static bool fit_item(SPDesktop *desktop, _scale = val; } if(_scale == 0.0) { + if(!nooverlap && (picker || overtransparent || overnotransparent)){ + showHidden(items_down); + } return false; } if(!fit_item(desktop, @@ -657,6 +722,7 @@ static bool fit_item(SPDesktop *desktop, _scale, scale, picker, + pickcenter, pickinversevalue, pickfill, pickstroke, @@ -666,6 +732,9 @@ static bool fit_item(SPDesktop *desktop, offset, css, true)){ + if(!nooverlap && (picker || overtransparent || overnotransparent)){ + showHidden(items_down); + } return false; } } @@ -699,10 +768,19 @@ static bool fit_item(SPDesktop *desktop, } } if (opacity < 1e-6) { // invisibly transparent, skip + if(!nooverlap && (picker || overtransparent || overnotransparent)){ + showHidden(items_down); + } return false; } } if(!trace){ + if (pickinversevalue) { + r = 1 - r; + g = 1 - g; + b = 1 - b; + } + rgba = SP_RGBA32_F_COMPOSE(r, g, b, a); sp_svg_write_color(color_string, sizeof(color_string), rgba); if(pickfill){ sp_repr_css_set_property(css, "fill", color_string); @@ -711,12 +789,8 @@ static bool fit_item(SPDesktop *desktop, sp_repr_css_set_property(css, "stroke", color_string); } } - if(!nooverlap && (picker || !overtransparent || !overnotransparent)){ - 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(!nooverlap && (picker || overtransparent || overnotransparent)){ + showHidden(items_down); } } return true; @@ -741,6 +815,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, gint _distrib, bool nooverlap, bool picker, + bool pickcenter, bool pickinversevalue, bool pickfill, bool pickstroke, @@ -787,7 +862,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 || !overtransparent || !overnotransparent){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversevalue, pickfill, pickstroke, overnotransparent, overtransparent, nooverlap, offset, css, false)){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickcenter, pickinversevalue, pickfill, pickstroke, overnotransparent, overtransparent, nooverlap, offset, css, false)){ return false; } } @@ -894,7 +969,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 || !overtransparent || !overnotransparent){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickinversevalue, pickfill, pickstroke, overnotransparent, overtransparent, nooverlap, offset, css, false)){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickcenter, pickinversevalue, pickfill, pickstroke, overnotransparent, overtransparent, nooverlap, offset, css, false)){ return false; } } @@ -972,7 +1047,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->pickinversevalue, tc->pickfill, tc->pickstroke, tc->overnotransparent, tc->overtransparent, 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->pickcenter, tc->pickinversevalue, tc->pickfill, tc->pickstroke, tc->overnotransparent, tc->overtransparent, 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 ba4e75f70..066ced00e 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -91,6 +91,7 @@ public: SPCanvasItem *dilate_area; bool nooverlap; bool picker; + bool pickcenter; bool pickinversevalue; bool pickfill; bool pickstroke; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index fe69b5050..a9a038c0e 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -72,6 +72,7 @@ static void sp_stb_sensitivize( GObject *tbl ) GtkAction *pickfill = GTK_ACTION( g_object_get_data(tbl, "pickfill") ); GtkAction *pickstroke = GTK_ACTION( g_object_get_data(tbl, "pickstroke") ); GtkAction *pickinversevalue = GTK_ACTION( g_object_get_data(tbl, "pickinversevalue") ); + GtkAction *pickcenter = GTK_ACTION( g_object_get_data(tbl, "pickcenter") ); gtk_adjustment_set_value( adj_offset, 100.0 ); if (gtk_toggle_action_get_active(nooverlap)) { gtk_action_set_sensitive( offset, TRUE ); @@ -88,10 +89,12 @@ static void sp_stb_sensitivize( GObject *tbl ) gtk_action_set_sensitive( pickfill, TRUE ); gtk_action_set_sensitive( pickstroke, TRUE ); gtk_action_set_sensitive( pickinversevalue, TRUE ); + gtk_action_set_sensitive( pickcenter, TRUE ); } else { gtk_action_set_sensitive( pickfill, FALSE ); gtk_action_set_sensitive( pickstroke, FALSE ); gtk_action_set_sensitive( pickinversevalue, FALSE ); + gtk_action_set_sensitive( pickcenter, FALSE ); } } @@ -218,6 +221,13 @@ static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) sp_stb_sensitivize(tbl); } +static void sp_toggle_pick_center( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/pickcenter", active); +} + static void sp_toggle_pick_fill( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -428,7 +438,6 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - /* Picker */ { InkToggleAction* act = ink_toggle_action_new( "SprayPickColorAction", @@ -441,12 +450,25 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_picker), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } + + /* Pick from center */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPickCenterAction", + _("Pick from center instead average area."), + _("Pick from center instead average area."), + INKSCAPE_ICON("snap-bounding-box-center"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickcenter", true) ); + g_object_set_data( holder, "pickcenter", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_center), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } /* Inverse Value Size */ { InkToggleAction* act = ink_toggle_action_new( "SprayOverPickInverseValueAction", - _("Inversed pick value retaining color"), - _("Inversed pick value retaining color"), + _("Inversed pick value, retaining color in advanced trace mode"), + _("Inversed pick value, retaining color in advanced trace mode"), INKSCAPE_ICON("object-tweak-shrink"), secondarySize ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickinversevalue", false) ); diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index b9051dd50..0aaba39f9 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -327,10 +327,11 @@ static gchar const * ui_descr = " " " " " " - " " " " " " - + " " + " " + " " " " @@ -369,7 +370,7 @@ static gchar const * ui_descr = " " " " " " - " " + " " " " " " -- cgit v1.2.3 From 75f6b25acdf6f51f5772e55d2150076b539b6e67 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 11 Nov 2015 09:34:01 +0100 Subject: Add option to spray tool to no overlap between colors (bzr r14455) --- src/ui/tools/spray-tool.cpp | 59 +++++++++++++++++++++++++------------------ src/ui/tools/spray-tool.h | 1 + src/widgets/spray-toolbar.cpp | 26 ++++++++++++++++--- src/widgets/toolbox.cpp | 8 +++--- 4 files changed, 62 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 1ec7815c5..1c9656a38 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -179,6 +179,7 @@ SprayTool::SprayTool() , pickinversevalue(false) , pickfill(false) , pickstroke(false) + , picknooverlap(false) , overtransparent(true) , overnotransparent(true) , offset(0) @@ -262,6 +263,7 @@ void SprayTool::setup() { sp_event_context_read(this, "pickinversevalue"); sp_event_context_read(this, "pickfill"); sp_event_context_read(this, "pickstroke"); + sp_event_context_read(this, "picknooverlap"); sp_event_context_read(this, "overnotransparent"); sp_event_context_read(this, "overtransparent"); sp_event_context_read(this, "nooverlap"); @@ -318,6 +320,8 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->pickfill = val.getBool(); } else if (path == "pickstroke") { this->pickstroke = val.getBool(); + } else if (path == "picknooverlap") { + this->picknooverlap = val.getBool(); } else if (path == "overnotransparent") { this->overnotransparent = val.getBool(); } else if (path == "overtransparent") { @@ -451,12 +455,18 @@ bool isTrans(Geom::Point N){ return SP_RGBA32_A_F(rgba)==0 || SP_RGBA32_A_F(rgba) < 1e-6; } -bool overTrans(Geom::Point A, Geom::Point B, Geom::Point C, Geom::Point D){ - return isTrans(A) || isTrans(B) || isTrans(C) || isTrans(D); +bool overTrans(std::vector points){ + for (std::vector::const_iterator k=points.begin(); k!=points.end(); ++k) { + Geom::Point point = *k; + if(isTrans(point)){ + return true; + } + } + return false; } static void showHidden(std::vector items_down){ - for (std::vector::const_iterator k=items_down.begin(); k!=items_down.end(); k++) { + 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(); @@ -476,6 +486,7 @@ static bool fit_item(SPDesktop *desktop, bool pickinversevalue, bool pickfill, bool pickstroke, + bool picknooverlap, bool overnotransparent, bool overtransparent, bool nooverlap, @@ -511,28 +522,24 @@ static bool fit_item(SPDesktop *desktop, path *= desktop->doc2dt(); bbox_procesed = path.boundsFast(); double bbox_left_main = bbox_procesed->left(); - double bbox_right_main = bbox_procesed->right(); double bbox_top_main = bbox_procesed->top(); - double bbox_bottom_main = bbox_procesed->bottom(); double width_transformed = bbox_procesed->width(); double height_transformed = bbox_procesed->height(); Geom::Point mid_point = desktop->d2w(bbox_procesed->midpoint()); Geom::Rect rect_sprayed(mid_point, mid_point); rect_sprayed.expandBy(width_transformed/2.0, height_transformed/2.0); Geom::IntRect area = Geom::IntRect::from_xywh(floor(mid_point[Geom::X]), floor(mid_point[Geom::Y]), 1, 1); - if (!rect_sprayed.hasZeroArea() && (!pickcenter || (overtransparent && !overnotransparent))) { - area = rect_sprayed.roundOutwards(); - } - guint32 rgba = getPickerData(area); - if(!overtransparent && overnotransparent){ - Geom::Point lt = desktop->d2w(Geom::Point(floor(bbox_left_main),floor(bbox_top_main))); - Geom::Point rt = desktop->d2w(Geom::Point(floor(bbox_right_main),floor(bbox_top_main))); - Geom::Point rb = desktop->d2w(Geom::Point(floor(bbox_right_main),floor(bbox_bottom_main))); - Geom::Point lb = desktop->d2w(Geom::Point(floor(bbox_left_main),floor(bbox_bottom_main))); - if(overTrans(lt, rt, rb, lb)){ + guint32 rgba; + if(picknooverlap && !rect_sprayed.hasZeroArea()){ + if(getPickerData(area) != getPickerData(rect_sprayed.roundOutwards())){ return false; } } + if (!rect_sprayed.hasZeroArea() && !pickcenter) { + rgba = getPickerData(rect_sprayed.roundOutwards()); + } else { + rgba = getPickerData(area); + } if(nooverlap && !overtransparent && (SP_RGBA32_A_F(rgba)==0 || SP_RGBA32_A_F(rgba) < 1e-6)){ return false; } @@ -586,14 +593,14 @@ static bool fit_item(SPDesktop *desktop, if(picker || overtransparent || overnotransparent){ if(!nooverlap){ doc->ensureUpToDate(); - rgba = getPickerData(area); + if (!rect_sprayed.hasZeroArea() && !pickcenter) { + rgba = getPickerData(rect_sprayed.roundOutwards()); + } else { + rgba = getPickerData(area); + } } - if(!overtransparent && overnotransparent){ - Geom::Point lt = desktop->d2w(Geom::Point(floor(bbox_left_main),floor(bbox_top_main))); - Geom::Point rt = desktop->d2w(Geom::Point(floor(bbox_right_main),floor(bbox_top_main))); - Geom::Point rb = desktop->d2w(Geom::Point(floor(bbox_right_main),floor(bbox_bottom_main))); - Geom::Point lb = desktop->d2w(Geom::Point(floor(bbox_left_main),floor(bbox_bottom_main))); - if(overTrans(lt, rt, rb, lb)){ + if(picknooverlap && !rect_sprayed.hasZeroArea()){ + if(getPickerData(area) != getPickerData(rect_sprayed.roundOutwards())){ if(!nooverlap && (picker || overtransparent || overnotransparent)){ showHidden(items_down); } @@ -726,6 +733,7 @@ static bool fit_item(SPDesktop *desktop, pickinversevalue, pickfill, pickstroke, + picknooverlap, overnotransparent, overtransparent, nooverlap, @@ -819,6 +827,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, bool pickinversevalue, bool pickfill, bool pickstroke, + bool picknooverlap, bool overnotransparent, bool overtransparent, double offset, @@ -862,7 +871,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 || !overtransparent || !overnotransparent){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickcenter, pickinversevalue, pickfill, pickstroke, overnotransparent, overtransparent, nooverlap, offset, css, false)){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickcenter, pickinversevalue, pickfill, pickstroke, picknooverlap, overnotransparent, overtransparent, nooverlap, offset, css, false)){ return false; } } @@ -969,7 +978,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 || !overtransparent || !overnotransparent){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickcenter, pickinversevalue, pickfill, pickstroke, overnotransparent, overtransparent, nooverlap, offset, css, false)){ + if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickcenter, pickinversevalue, pickfill, pickstroke, picknooverlap, overnotransparent, overtransparent, nooverlap, offset, css, false)){ return false; } } @@ -1047,7 +1056,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->pickcenter, tc->pickinversevalue, tc->pickfill, tc->pickstroke, tc->overnotransparent, tc->overtransparent, 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->pickcenter, tc->pickinversevalue, tc->pickfill, tc->pickstroke, tc->picknooverlap, tc->overnotransparent, tc->overtransparent, 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 066ced00e..377893f0d 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -95,6 +95,7 @@ public: bool pickinversevalue; bool pickfill; bool pickstroke; + bool picknooverlap; bool overtransparent; bool overnotransparent; double offset; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index a9a038c0e..34f728ce8 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -235,6 +235,13 @@ static void sp_toggle_pick_fill( GtkToggleAction* act, gpointer data ) prefs->setBool("/tools/spray/pickfill", active); } +static void sp_toggle_pick_no_overlap( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/picknooverlap", active); +} + static void sp_toggle_pick_inverse_value( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -466,7 +473,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Inverse Value Size */ { - InkToggleAction* act = ink_toggle_action_new( "SprayOverPickInverseValueAction", + InkToggleAction* act = ink_toggle_action_new( "SprayPickInverseValueAction", _("Inversed pick value, retaining color in advanced trace mode"), _("Inversed pick value, retaining color in advanced trace mode"), INKSCAPE_ICON("object-tweak-shrink"), @@ -479,7 +486,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Pick Fill */ { - InkToggleAction* act = ink_toggle_action_new( "SprayOverPickFillAction", + InkToggleAction* act = ink_toggle_action_new( "SprayPickFillAction", _("Apply picked color to fill"), _("Apply picked color to fill"), INKSCAPE_ICON("paint-solid"), @@ -492,7 +499,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Pick Stroke */ { - InkToggleAction* act = ink_toggle_action_new( "SprayOverPickStrokeAction", + InkToggleAction* act = ink_toggle_action_new( "SprayPickStrokeAction", _("Apply picked color to stroke"), _("Apply picked color to stroke"), INKSCAPE_ICON("no-marker"), @@ -503,6 +510,19 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } + /* Pick No Overlap */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPickNoOverlapAction", + _("No overlap between colors"), + _("No overlap between colors"), + INKSCAPE_ICON("symbol-bigger"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/picknooverlap", false) ); + g_object_set_data( holder, "picknooverlap", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_no_overlap), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + /* Over Transparent */ { InkToggleAction* act = ink_toggle_action_new( "SprayOverTransparentAction", diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 0aaba39f9..3e79e038a 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -323,15 +323,15 @@ static gchar const * ui_descr = " " " " " " + " " " " " " " " " " - " " - " " - " " + " " + " " + " " " " - " " " " -- cgit v1.2.3 From e015bb069e1722492e5d677b92ce4a5d089cb2fa Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 11 Nov 2015 09:36:54 +0100 Subject: Remove unused functions (bzr r14456) --- src/ui/tools/spray-tool.cpp | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 1c9656a38..9fde142e5 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -450,21 +450,6 @@ guint32 getPickerData(Geom::IntRect area){ return SP_RGBA32_F_COMPOSE(R, G, B, A); } -bool isTrans(Geom::Point N){ - gint32 rgba = getPickerData(Geom::IntRect::from_xywh(floor(N[Geom::X]), floor(N[Geom::Y]), 1, 1)); - return SP_RGBA32_A_F(rgba)==0 || SP_RGBA32_A_F(rgba) < 1e-6; -} - -bool overTrans(std::vector points){ - for (std::vector::const_iterator k=points.begin(); k!=points.end(); ++k) { - Geom::Point point = *k; - if(isTrans(point)){ - return true; - } - } - return false; -} - static void showHidden(std::vector items_down){ for (std::vector::const_iterator k=items_down.begin(); k!=items_down.end(); ++k) { SPItem *item_hidden = *k; -- cgit v1.2.3 From b5c716ade5ee3e23f9c56c6b7a0227acf2118f36 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 11 Nov 2015 15:35:50 +0100 Subject: Improve offseting calculation Improve no picoverlap feature (bzr r14457) --- src/ui/tools/spray-tool.cpp | 88 +++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 9fde142e5..0f8404b8e 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -447,6 +447,12 @@ guint32 getPickerData(Geom::IntRect area){ 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); + //this can fix the bug #1511998 if confirmed + if( A == 0 || A < 1e-6){ + R = 1; + G = 1; + B = 1; + } return SP_RGBA32_F_COMPOSE(R, G, B, A); } @@ -457,7 +463,7 @@ static void showHidden(std::vector items_down){ item_hidden->updateRepr(); } } - +//todo: maybe move same parameter to preferences static bool fit_item(SPDesktop *desktop, SPItem *item, Geom::OptRect bbox, @@ -482,18 +488,21 @@ static bool fit_item(SPDesktop *desktop, 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; + double offset_width = (offset * width)/100.0 - (width); + if(offset_width < 0 ){ + offset_width = 0; + } + double offset_height = (offset * height)/100.0 - (height); + if(offset_height < 0 ){ + offset_height = 0; } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool pick_to_size = prefs->getBool("/dialogs/clonetiler/pick_to_size"); - bool trace = prefs->getBool("/dialogs/clonetiler/dotrace"); - if(picker && pick_to_size && !trace_scale && trace){ + bool do_trace = prefs->getBool("/dialogs/clonetiler/dotrace"); + if(picker && pick_to_size && !trace_scale && do_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)); + Geom::OptRect bbox_procesed = Geom::Rect(Geom::Point(bbox->left() - offset_width, bbox->top() - offset_height),Geom::Point(bbox->right() + offset_width, bbox->bottom() + offset_height)); Geom::Path path; path.start(Geom::Point(bbox_procesed->left(), bbox_procesed->top())); path.appendNew(Geom::Point(bbox_procesed->right(), bbox_procesed->top())); @@ -507,35 +516,39 @@ static bool fit_item(SPDesktop *desktop, path *= desktop->doc2dt(); bbox_procesed = path.boundsFast(); double bbox_left_main = bbox_procesed->left(); + double bbox_right_main = bbox_procesed->right(); double bbox_top_main = bbox_procesed->top(); + double bbox_bottom_main = bbox_procesed->bottom(); double width_transformed = bbox_procesed->width(); double height_transformed = bbox_procesed->height(); Geom::Point mid_point = desktop->d2w(bbox_procesed->midpoint()); - Geom::Rect rect_sprayed(mid_point, mid_point); - rect_sprayed.expandBy(width_transformed/2.0, height_transformed/2.0); Geom::IntRect area = Geom::IntRect::from_xywh(floor(mid_point[Geom::X]), floor(mid_point[Geom::Y]), 1, 1); - guint32 rgba; - if(picknooverlap && !rect_sprayed.hasZeroArea()){ - if(getPickerData(area) != getPickerData(rect_sprayed.roundOutwards())){ + guint32 rgba = getPickerData(area); + guint32 rgba2 = 0xffffff00; + Geom::Rect rect_sprayed(desktop->d2w(Geom::Point(bbox_left_main,bbox_top_main)), desktop->d2w(Geom::Point(bbox_right_main,bbox_bottom_main))); + if (!rect_sprayed.hasZeroArea()) { + rgba2 = getPickerData(rect_sprayed.roundOutwards()); + } + if(picknooverlap){ + if(rgba != rgba2){ return false; } } - if (!rect_sprayed.hasZeroArea() && !pickcenter) { - rgba = getPickerData(rect_sprayed.roundOutwards()); - } else { - rgba = getPickerData(area); + if(!pickcenter){ + rgba = rgba2; } - if(nooverlap && !overtransparent && (SP_RGBA32_A_F(rgba)==0 || SP_RGBA32_A_F(rgba) < 1e-6)){ + if(!overtransparent && (SP_RGBA32_A_F(rgba) == 0 || SP_RGBA32_A_F(rgba) < 1e-6)){ return false; } - if(nooverlap && !overnotransparent && SP_RGBA32_A_F(rgba)>0){ + if(!overnotransparent && SP_RGBA32_A_F(rgba) > 0){ return false; } - size = std::min(width_transformed,height_transformed); if(offset < 100 ){ - offset_min = ((99.0 - offset) * size)/100.0 - size; + offset_width = ((99.0 - offset) * width_transformed)/100.0 - width_transformed; + offset_height = ((99.0 - offset) * height_transformed)/100.0 - height_transformed; } else { - offset_min = 0; + offset_width = 0; + offset_height = 0; } std::vector items_down = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox_procesed); Inkscape::Selection *selection = desktop->getSelection(); @@ -564,8 +577,11 @@ static bool fit_item(SPDesktop *desktop, strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) { 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))){ + if(!(offset_width < 0 && offset_height < 0 && std::abs(bbox_left - bbox_left_main) > std::abs(offset_width) && + std::abs(bbox_top - bbox_top_main) > std::abs(offset_height))){ + if(!nooverlap && (picker || overtransparent || overnotransparent)){ + showHidden(items_down); + } return false; } } else if(picker || overtransparent || overnotransparent){ @@ -578,20 +594,22 @@ static bool fit_item(SPDesktop *desktop, if(picker || overtransparent || overnotransparent){ if(!nooverlap){ doc->ensureUpToDate(); - if (!rect_sprayed.hasZeroArea() && !pickcenter) { - rgba = getPickerData(rect_sprayed.roundOutwards()); - } else { - rgba = getPickerData(area); + rgba = getPickerData(area); + if (!rect_sprayed.hasZeroArea()) { + rgba2 = getPickerData(rect_sprayed.roundOutwards()); } } - if(picknooverlap && !rect_sprayed.hasZeroArea()){ - if(getPickerData(area) != getPickerData(rect_sprayed.roundOutwards())){ + if(picknooverlap){ + if(rgba != rgba2){ if(!nooverlap && (picker || overtransparent || overnotransparent)){ showHidden(items_down); } return false; } } + if(!pickcenter){ + rgba = rgba2; + } 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"); @@ -605,12 +623,6 @@ static bool fit_item(SPDesktop *desktop, 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 || a < 1e-6){ - r = 1; - g = 1; - b = 1; - } if(!overtransparent && (a == 0 || a < 1e-6)){ if(!nooverlap && (picker || overtransparent || overnotransparent)){ showHidden(items_down); @@ -624,7 +636,7 @@ static bool fit_item(SPDesktop *desktop, return false; } - if(picker && trace){ + if(picker && do_trace){ float hsl[3]; sp_color_rgb_to_hsl_floatv (hsl, r, g, b); @@ -767,7 +779,7 @@ static bool fit_item(SPDesktop *desktop, return false; } } - if(!trace){ + if(!do_trace){ if (pickinversevalue) { r = 1 - r; g = 1 - g; -- cgit v1.2.3 From 5be1dd71bf1bf0bb5559c3a5cac3cafba44bd960 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 11 Nov 2015 19:28:19 +0100 Subject: Refactor of code, minor bugs fixed. (bzr r14458) --- src/ui/tools/spray-tool.cpp | 385 +++++++++++++++++++++++++++++------------- src/ui/tools/spray-tool.h | 26 ++- src/widgets/spray-toolbar.cpp | 86 +++++----- 3 files changed, 324 insertions(+), 173 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 0f8404b8e..10a10f49f 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -173,16 +173,25 @@ SprayTool::SprayTool() , is_dilating(false) , has_dilated(false) , dilate_area(NULL) - , nooverlap(false) + , no_overlap(false) , picker(false) - , pickcenter(true) - , pickinversevalue(false) - , pickfill(false) - , pickstroke(false) - , picknooverlap(false) - , overtransparent(true) - , overnotransparent(true) + , pick_center(true) + , pick_inverse_value(false) + , pick_fill(false) + , pick_stroke(false) + , pick_no_overlap(false) + , over_transparent(true) + , over_no_transparent(true) , offset(0) + , pick(0) + , do_trace(false) + , pick_to_size(false) + , pick_to_presence(false) + , pick_to_color(false) + , pick_to_opacity(false) + , invert_picked(false) + , gamma_picked(0) + , rand_picked(0) { } @@ -259,14 +268,14 @@ 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, "pickcenter"); - sp_event_context_read(this, "pickinversevalue"); - sp_event_context_read(this, "pickfill"); - sp_event_context_read(this, "pickstroke"); - sp_event_context_read(this, "picknooverlap"); - sp_event_context_read(this, "overnotransparent"); - sp_event_context_read(this, "overtransparent"); - sp_event_context_read(this, "nooverlap"); + sp_event_context_read(this, "pick_center"); + sp_event_context_read(this, "pick_inverse_value"); + sp_event_context_read(this, "pick_fill"); + sp_event_context_read(this, "pick_stroke"); + sp_event_context_read(this, "pick_no_overlap"); + sp_event_context_read(this, "over_no_transparent"); + sp_event_context_read(this, "over_transparent"); + sp_event_context_read(this, "no_overlap"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/spray/selcue")) { @@ -277,6 +286,19 @@ void SprayTool::setup() { } } +void SprayTool::setCloneTilerPrefs() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + this->do_trace = prefs->getBool("/dialogs/clonetiler/dotrace", false); + this->pick = prefs->getInt("/dialogs/clonetiler/pick"); + this->pick_to_size = prefs->getBool("/dialogs/clonetiler/pick_to_size", false); + this->pick_to_presence = prefs->getBool("/dialogs/clonetiler/pick_to_presence", false); + this->pick_to_color = prefs->getBool("/dialogs/clonetiler/pick_to_color", false); + this->pick_to_opacity = prefs->getBool("/dialogs/clonetiler/pick_to_opacity", false); + this->rand_picked = 0.01 * prefs->getDoubleLimited("/dialogs/clonetiler/rand_picked", 0, 0, 100); + this->invert_picked = prefs->getBool("/dialogs/clonetiler/invert_picked", false); + this->gamma_picked = prefs->getDoubleLimited("/dialogs/clonetiler/gamma_picked", 0, -10, 10); +} + void SprayTool::set(const Inkscape::Preferences::Entry& val) { Glib::ustring path = val.getEntryName(); @@ -309,25 +331,25 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { } 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); + this->offset = val.getDoubleLimited(100.0, 0, 1000.0); + } else if (path == "pick_center") { + this->pick_center = val.getBool(true); + } else if (path == "pick_inverse_value") { + this->pick_inverse_value = val.getBool(false); + } else if (path == "pick_fill") { + this->pick_fill = val.getBool(false); + } else if (path == "pick_stroke") { + this->pick_stroke = val.getBool(false); + } else if (path == "pick_no_overlap") { + this->pick_no_overlap = val.getBool(false); + } else if (path == "over_no_transparent") { + this->over_no_transparent = val.getBool(true); + } else if (path == "over_transparent") { + this->over_transparent = val.getBool(true); + } else if (path == "no_overlap") { + this->no_overlap = val.getBool(false); } else if (path == "picker") { - this->picker = val.getBool(); - } else if (path == "pickcenter") { - this->pickcenter = val.getBool(); - } else if (path == "pickinversevalue") { - this->pickinversevalue = val.getBool(); - } else if (path == "pickfill") { - this->pickfill = val.getBool(); - } else if (path == "pickstroke") { - this->pickstroke = val.getBool(); - } else if (path == "picknooverlap") { - this->picknooverlap = val.getBool(); - } else if (path == "overnotransparent") { - this->overnotransparent = val.getBool(); - } else if (path == "overtransparent") { - this->overtransparent = val.getBool(); - } else if (path == "nooverlap") { - this->nooverlap = val.getBool(); + this->picker = val.getBool(false); } } @@ -473,17 +495,26 @@ static bool fit_item(SPDesktop *desktop, double &_scale, double scale, bool picker, - bool pickcenter, - bool pickinversevalue, - bool pickfill, - bool pickstroke, - bool picknooverlap, - bool overnotransparent, - bool overtransparent, - bool nooverlap, + bool pick_center, + bool pick_inverse_value, + bool pick_fill, + bool pick_stroke, + bool pick_no_overlap, + bool over_no_transparent, + bool over_transparent, + bool no_overlap, double offset, SPCSSAttr *css, - bool trace_scale) + bool trace_scale, + int pick, + bool do_trace, + bool pick_to_size, + bool pick_to_presence, + bool pick_to_color, + bool pick_to_opacity, + bool invert_picked, + double gamma_picked , + double rand_picked) { SPDocument *doc = item->document; double width = bbox->width(); @@ -496,9 +527,6 @@ static bool fit_item(SPDesktop *desktop, if(offset_height < 0 ){ offset_height = 0; } - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - bool pick_to_size = prefs->getBool("/dialogs/clonetiler/pick_to_size"); - bool do_trace = prefs->getBool("/dialogs/clonetiler/dotrace"); if(picker && pick_to_size && !trace_scale && do_trace){ _scale = 0.1; } @@ -529,18 +557,18 @@ static bool fit_item(SPDesktop *desktop, if (!rect_sprayed.hasZeroArea()) { rgba2 = getPickerData(rect_sprayed.roundOutwards()); } - if(picknooverlap){ + if(pick_no_overlap){ if(rgba != rgba2){ return false; } } - if(!pickcenter){ + if(!pick_center){ rgba = rgba2; } - if(!overtransparent && (SP_RGBA32_A_F(rgba) == 0 || SP_RGBA32_A_F(rgba) < 1e-6)){ + if(!over_transparent && (SP_RGBA32_A_F(rgba) == 0 || SP_RGBA32_A_F(rgba) < 1e-6)){ return false; } - if(!overnotransparent && SP_RGBA32_A_F(rgba) > 0){ + if(!over_no_transparent && SP_RGBA32_A_F(rgba) > 0){ return false; } if(offset < 100 ){ @@ -576,61 +604,54 @@ static bool fit_item(SPDesktop *desktop, (item_down->getAttribute("inkscape:spray-origin") && strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) { - if(nooverlap){ + if(no_overlap){ if(!(offset_width < 0 && offset_height < 0 && std::abs(bbox_left - bbox_left_main) > std::abs(offset_width) && std::abs(bbox_top - bbox_top_main) > std::abs(offset_height))){ - if(!nooverlap && (picker || overtransparent || overnotransparent)){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ showHidden(items_down); } return false; } - } else if(picker || overtransparent || overnotransparent){ + } else if(picker || over_transparent || over_no_transparent){ item_down->setHidden(true); item_down->updateRepr(); } } } } - if(picker || overtransparent || overnotransparent){ - if(!nooverlap){ + if(picker || over_transparent || over_no_transparent){ + if(!no_overlap){ doc->ensureUpToDate(); rgba = getPickerData(area); if (!rect_sprayed.hasZeroArea()) { rgba2 = getPickerData(rect_sprayed.roundOutwards()); } } - if(picknooverlap){ + if(pick_no_overlap){ if(rgba != rgba2){ - if(!nooverlap && (picker || overtransparent || overnotransparent)){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ showHidden(items_down); } return false; } } - if(!pickcenter){ + if(!pick_center){ rgba = rgba2; } - 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"); - 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; 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(!overtransparent && (a == 0 || a < 1e-6)){ - if(!nooverlap && (picker || overtransparent || overnotransparent)){ + if(!over_transparent && (a == 0 || a < 1e-6)){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ showHidden(items_down); } return false; } - if(!overnotransparent && a > 0){ - if(!nooverlap && (picker || overtransparent || overnotransparent)){ + if(!over_no_transparent && a > 0){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ showHidden(items_down); } return false; @@ -706,47 +727,58 @@ static bool fit_item(SPDesktop *desktop, rgba = SP_RGBA32_F_COMPOSE(r, g, b, a); if (pick_to_size) { if(!trace_scale){ - if(pickinversevalue) { + if(pick_inverse_value) { _scale = 1.0 - val; } else { _scale = val; } if(_scale == 0.0) { - if(!nooverlap && (picker || overtransparent || overnotransparent)){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ + showHidden(items_down); + } + return false; + } + if(!fit_item(desktop + , item + , bbox + , move + , center + , angle + , _scale + , scale + , picker + , pick_center + , pick_inverse_value + , pick_fill + , pick_stroke + , pick_no_overlap + , over_no_transparent + , over_transparent + , no_overlap + , offset + , css + , true + , pick + , do_trace + , pick_to_size + , pick_to_presence + , pick_to_color + , pick_to_opacity + , invert_picked + , gamma_picked + , rand_picked) + ) + { + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ showHidden(items_down); } return false; } - if(!fit_item(desktop, - item, - bbox, - move, - center, - angle, - _scale, - scale, - picker, - pickcenter, - pickinversevalue, - pickfill, - pickstroke, - picknooverlap, - overnotransparent, - overtransparent, - nooverlap, - offset, - css, - true)){ - if(!nooverlap && (picker || overtransparent || overnotransparent)){ - showHidden(items_down); - } - return false; - } } } if (pick_to_opacity) { - if(pickinversevalue) { + if(pick_inverse_value) { opacity *= 1.0 - val; } else { opacity *= val; @@ -765,36 +797,43 @@ static bool fit_item(SPDesktop *desktop, } if (pick_to_color) { sp_svg_write_color(color_string, sizeof(color_string), rgba); - if(pickfill){ + if(pick_fill){ sp_repr_css_set_property(css, "fill", color_string); } - if(pickstroke){ + if(pick_stroke){ sp_repr_css_set_property(css, "stroke", color_string); } } if (opacity < 1e-6) { // invisibly transparent, skip - if(!nooverlap && (picker || overtransparent || overnotransparent)){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ showHidden(items_down); } return false; } } if(!do_trace){ - if (pickinversevalue) { - r = 1 - r; - g = 1 - g; - b = 1 - b; + if(!pick_center){ + rgba = rgba2; + } + if (pick_inverse_value) { + r = 1 - SP_RGBA32_R_F(rgba); + g = 1 - SP_RGBA32_G_F(rgba); + b = 1 - SP_RGBA32_G_F(rgba); + } else { + r = SP_RGBA32_R_F(rgba); + g = SP_RGBA32_G_F(rgba); + b = SP_RGBA32_G_F(rgba); } rgba = SP_RGBA32_F_COMPOSE(r, g, b, a); sp_svg_write_color(color_string, sizeof(color_string), rgba); - if(pickfill){ + if(pick_fill){ sp_repr_css_set_property(css, "fill", color_string); } - if(pickstroke){ + if(pick_stroke){ sp_repr_css_set_property(css, "stroke", color_string); } } - if(!nooverlap && (picker || overtransparent || overnotransparent)){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ showHidden(items_down); } } @@ -818,18 +857,27 @@ static bool sp_spray_recursive(SPDesktop *desktop, double tilt, double rotation_variation, gint _distrib, - bool nooverlap, + bool no_overlap, bool picker, - bool pickcenter, - bool pickinversevalue, - bool pickfill, - bool pickstroke, - bool picknooverlap, - bool overnotransparent, - bool overtransparent, + bool pick_center, + bool pick_inverse_value, + bool pick_fill, + bool pick_stroke, + bool pick_no_overlap, + bool over_no_transparent, + bool over_transparent, double offset, bool usepressurescale, - double pressure) + double pressure, + int pick, + bool do_trace, + bool pick_to_size, + bool pick_to_presence, + bool pick_to_color, + bool pick_to_opacity, + bool invert_picked, + double gamma_picked , + double rand_picked) { bool did = false; @@ -867,8 +915,36 @@ 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(nooverlap || picker || !overtransparent || !overnotransparent){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickcenter, pickinversevalue, pickfill, pickstroke, picknooverlap, overnotransparent, overtransparent, nooverlap, offset, css, false)){ + if(no_overlap || picker || !over_transparent || !over_no_transparent){ + if(!fit_item(desktop + , item + , a + , move + , center + , angle + , _scale + , scale + , picker + , pick_center + , pick_inverse_value + , pick_fill + , pick_stroke + , pick_no_overlap + , over_no_transparent + , over_transparent + , no_overlap + , offset + , css + , false + , pick + , do_trace + , pick_to_size + , pick_to_presence + , pick_to_color + , pick_to_opacity + , invert_picked + , gamma_picked + , rand_picked)){ return false; } } @@ -974,8 +1050,37 @@ 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(nooverlap || picker || !overtransparent || !overnotransparent){ - if(!fit_item(desktop, item, a, move, center, angle, _scale, scale, picker, pickcenter, pickinversevalue, pickfill, pickstroke, picknooverlap, overnotransparent, overtransparent, nooverlap, offset, css, false)){ + if(no_overlap || picker || !over_transparent || !over_no_transparent){ + if(!fit_item(desktop + , item + , a + , move + , center + , angle + , _scale + , scale + , picker + , pick_center + , pick_inverse_value + , pick_fill + , pick_stroke + , pick_no_overlap + , over_no_transparent + , over_transparent + , no_overlap + , offset + , css + , true + , pick + , do_trace + , pick_to_size + , pick_to_presence + , pick_to_color + , pick_to_opacity + , invert_picked + , gamma_picked + , rand_picked)) + { return false; } } @@ -1053,7 +1158,43 @@ 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->pickcenter, tc->pickinversevalue, tc->pickfill, tc->pickstroke, tc->picknooverlap, tc->overnotransparent, tc->overtransparent, 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->no_overlap + , tc->picker + , tc->pick_center + , tc->pick_inverse_value + , tc->pick_fill + , tc->pick_stroke + , tc->pick_no_overlap + , tc->over_no_transparent + , tc->over_transparent + , tc->offset + , tc->usepressurescale + , get_pressure(tc) + , tc->pick + , tc->do_trace + , tc->pick_to_size + , tc->pick_to_presence + , tc->pick_to_color + , tc->pick_to_opacity + , tc->invert_picked + , tc->gamma_picked + , tc->rand_picked)) { did = true; } } @@ -1100,7 +1241,7 @@ bool SprayTool::root_handler(GdkEvent* event) { if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { return TRUE; } - + this->setCloneTilerPrefs(); Geom::Point const motion_w(event->button.x, event->button.y); Geom::Point const motion_dt(desktop->w2d(motion_w)); this->last_push = desktop->dt2doc(motion_dt); diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index 377893f0d..438318bf4 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -89,22 +89,32 @@ public: bool has_dilated; Geom::Point last_push; SPCanvasItem *dilate_area; - bool nooverlap; + bool no_overlap; bool picker; - bool pickcenter; - bool pickinversevalue; - bool pickfill; - bool pickstroke; - bool picknooverlap; - bool overtransparent; - bool overnotransparent; + bool pick_center; + bool pick_inverse_value; + bool pick_fill; + bool pick_stroke; + bool pick_no_overlap; + bool over_transparent; + bool over_no_transparent; double offset; + int pick; + bool do_trace; + bool pick_to_size; + bool pick_to_presence; + bool pick_to_color; + bool pick_to_opacity; + bool invert_picked; + double gamma_picked; + double rand_picked; sigc::connection style_set_connection; static const std::string prefsPath; virtual void setup(); virtual void set(const Inkscape::Preferences::Entry& val); + virtual void setCloneTilerPrefs(); virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 34f728ce8..1ef0ca9f1 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -66,15 +66,15 @@ 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 *nooverlap = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "nooverlap") ); + GtkToggleAction *no_overlap = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "no_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 *pickinversevalue = GTK_ACTION( g_object_get_data(tbl, "pickinversevalue") ); - GtkAction *pickcenter = GTK_ACTION( g_object_get_data(tbl, "pickcenter") ); + GtkAction *pick_fill = GTK_ACTION( g_object_get_data(tbl, "pick_fill") ); + GtkAction *pick_stroke = GTK_ACTION( g_object_get_data(tbl, "pick_stroke") ); + GtkAction *pick_inverse_value = GTK_ACTION( g_object_get_data(tbl, "pick_inverse_value") ); + GtkAction *pick_center = GTK_ACTION( g_object_get_data(tbl, "pick_center") ); gtk_adjustment_set_value( adj_offset, 100.0 ); - if (gtk_toggle_action_get_active(nooverlap)) { + if (gtk_toggle_action_get_active(no_overlap)) { gtk_action_set_sensitive( offset, TRUE ); } else { gtk_action_set_sensitive( offset, FALSE ); @@ -86,15 +86,15 @@ static void sp_stb_sensitivize( GObject *tbl ) 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( pickinversevalue, TRUE ); - gtk_action_set_sensitive( pickcenter, TRUE ); + gtk_action_set_sensitive( pick_fill, TRUE ); + gtk_action_set_sensitive( pick_stroke, TRUE ); + gtk_action_set_sensitive( pick_inverse_value, TRUE ); + gtk_action_set_sensitive( pick_center, TRUE ); } else { - gtk_action_set_sensitive( pickfill, FALSE ); - gtk_action_set_sensitive( pickstroke, FALSE ); - gtk_action_set_sensitive( pickinversevalue, FALSE ); - gtk_action_set_sensitive( pickcenter, FALSE ); + gtk_action_set_sensitive( pick_fill, FALSE ); + gtk_action_set_sensitive( pick_stroke, FALSE ); + gtk_action_set_sensitive( pick_inverse_value, FALSE ); + gtk_action_set_sensitive( pick_center, FALSE ); } } @@ -168,11 +168,11 @@ static void sp_spray_offset_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ gtk_adjustment_get_value(adj)); } -static void sp_toggle_nooverlap( GtkToggleAction* act, gpointer data) +static void sp_toggle_no_overlap( GtkToggleAction* act, gpointer data) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setBool("/tools/spray/nooverlap", active); + prefs->setBool("/tools/spray/no_overlap", active); GObject *tbl = G_OBJECT(data); sp_stb_sensitivize(tbl); } @@ -193,14 +193,14 @@ static void sp_toggle_over_no_transparent( GtkToggleAction* act, gpointer data) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setBool("/tools/spray/overnotransparent", active); + prefs->setBool("/tools/spray/over_no_transparent", active); } static void sp_toggle_over_transparent( GtkToggleAction* act, gpointer data) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setBool("/tools/spray/overtransparent", active); + prefs->setBool("/tools/spray/over_transparent", active); } @@ -225,35 +225,35 @@ static void sp_toggle_pick_center( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setBool("/tools/spray/pickcenter", active); + prefs->setBool("/tools/spray/pick_center", active); } 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); + prefs->setBool("/tools/spray/pick_fill", active); } -static void sp_toggle_pick_no_overlap( 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); - prefs->setBool("/tools/spray/picknooverlap", active); + prefs->setBool("/tools/spray/pick_stroke", active); } -static void sp_toggle_pick_inverse_value( GtkToggleAction* act, gpointer data ) +static void sp_toggle_pick_no_overlap( GtkToggleAction* act, gpointer data ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); - prefs->setBool("/tools/spray/pickinversevalue", active); + prefs->setBool("/tools/spray/pick_no_overlap", active); } -static void sp_toggle_pick_stroke( 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/pickstroke", active); + prefs->setBool("/tools/spray/pick_inverse_value", active); } void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) @@ -465,8 +465,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("Pick from center instead average area."), INKSCAPE_ICON("snap-bounding-box-center"), secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickcenter", true) ); - g_object_set_data( holder, "pickcenter", act ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pick_center", true) ); + g_object_set_data( holder, "pick_center", act ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_center), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } @@ -478,8 +478,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("Inversed pick value, retaining color in advanced trace mode"), INKSCAPE_ICON("object-tweak-shrink"), secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pickinversevalue", false) ); - g_object_set_data( holder, "pickinversevalue", act ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pick_inverse_value", false) ); + g_object_set_data( holder, "pick_inverse_value", 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) ); } @@ -491,8 +491,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("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 ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pick_fill", false) ); + g_object_set_data( holder, "pick_fill", act ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_fill), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } @@ -504,8 +504,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("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 ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pick_stroke", false) ); + g_object_set_data( holder, "pick_stroke", act ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_stroke), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } @@ -517,8 +517,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("No overlap between colors"), INKSCAPE_ICON("symbol-bigger"), secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/picknooverlap", false) ); - g_object_set_data( holder, "picknooverlap", act ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pick_no_overlap", false) ); + g_object_set_data( holder, "pick_no_overlap", act ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_no_overlap), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } @@ -530,8 +530,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("Apply over transparent areas"), INKSCAPE_ICON("object-hidden"), secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/overtransparent", true) ); - g_object_set_data( holder, "overtransparent", act ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/over_transparent", true) ); + g_object_set_data( holder, "over_transparent", act ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_over_transparent), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } @@ -543,8 +543,8 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("Apply over no transparent areas"), INKSCAPE_ICON("object-visible"), secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/overnotransparent", true) ); - g_object_set_data( holder, "overnotransparent", act ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/over_no_transparent", true) ); + g_object_set_data( holder, "over_no_transparent", act ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_over_no_transparent), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } @@ -556,9 +556,9 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("Prevent overlapping objects"), INKSCAPE_ICON("distribute-randomize"), secondarySize ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/nooverlap", false) ); - g_object_set_data( holder, "nooverlap", act ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_nooverlap), holder) ; + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/no_overlap", false) ); + g_object_set_data( holder, "no_overlap", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_no_overlap), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } -- cgit v1.2.3 From 1bdb2511c92fd5390527aa51a9aa45de01421d2b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 11 Nov 2015 20:50:35 +0100 Subject: Add erase mode to spray. Bugfixes. (bzr r14459) --- src/ui/tools/spray-tool.cpp | 39 +++++++++++++++++++++++++++------------ src/ui/tools/spray-tool.h | 3 ++- src/widgets/spray-toolbar.cpp | 42 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 65 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 10a10f49f..84b0ad431 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -252,6 +252,15 @@ void SprayTool::setup() { this->is_drawing = false; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool("/dialogs/clonetiler/dotrace", false); + if (prefs->getBool("/tools/spray/selcue")) { + this->enableSelectionCue(); + } + if (prefs->getBool("/tools/spray/gradientdrag")) { + this->enableGrDrag(); + } + sp_event_context_read(this, "distrib"); sp_event_context_read(this, "width"); sp_event_context_read(this, "ratio"); @@ -276,14 +285,6 @@ void SprayTool::setup() { sp_event_context_read(this, "over_no_transparent"); sp_event_context_read(this, "over_transparent"); sp_event_context_read(this, "no_overlap"); - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getBool("/tools/spray/selcue")) { - this->enableSelectionCue(); - } - if (prefs->getBool("/tools/spray/gradientdrag")) { - this->enableGrDrag(); - } } void SprayTool::setCloneTilerPrefs() { @@ -491,6 +492,7 @@ static bool fit_item(SPDesktop *desktop, Geom::OptRect bbox, Geom::Point &move, Geom::Point center, + gint mode, double angle, double &_scale, double scale, @@ -604,7 +606,11 @@ static bool fit_item(SPDesktop *desktop, (item_down->getAttribute("inkscape:spray-origin") && strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) { - if(no_overlap){ + if(mode == SPRAY_MODE_ERASER){ + if(strcmp(item_down_sharp, spray_origin) != 0 ){ + item_down->deleteObject(); + } + }else if(no_overlap){ if(!(offset_width < 0 && offset_height < 0 && std::abs(bbox_left - bbox_left_main) > std::abs(offset_width) && std::abs(bbox_top - bbox_top_main) > std::abs(offset_height))){ if(!no_overlap && (picker || over_transparent || over_no_transparent)){ @@ -619,6 +625,12 @@ static bool fit_item(SPDesktop *desktop, } } } + if(mode == SPRAY_MODE_ERASER){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ + showHidden(items_down); + } + return false; + } if(picker || over_transparent || over_no_transparent){ if(!no_overlap){ doc->ensureUpToDate(); @@ -743,6 +755,7 @@ static bool fit_item(SPDesktop *desktop, , bbox , move , center + , mode , angle , _scale , scale @@ -818,11 +831,11 @@ static bool fit_item(SPDesktop *desktop, if (pick_inverse_value) { r = 1 - SP_RGBA32_R_F(rgba); g = 1 - SP_RGBA32_G_F(rgba); - b = 1 - SP_RGBA32_G_F(rgba); + b = 1 - SP_RGBA32_B_F(rgba); } else { r = SP_RGBA32_R_F(rgba); g = SP_RGBA32_G_F(rgba); - b = SP_RGBA32_G_F(rgba); + b = SP_RGBA32_B_F(rgba); } rgba = SP_RGBA32_F_COMPOSE(r, g, b, a); sp_svg_write_color(color_string, sizeof(color_string), rgba); @@ -900,7 +913,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, random_position( dr, dp, mean, standard_deviation, _distrib ); dr=dr*radius; - if (mode == SPRAY_MODE_COPY) { + if (mode == SPRAY_MODE_COPY || mode == SPRAY_MODE_ERASER) { Geom::OptRect a = item->documentVisualBounds(); if (a) { if(_fid <= population) @@ -921,6 +934,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, , a , move , center + , mode , angle , _scale , scale @@ -1056,6 +1070,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, , a , move , center + , mode , angle , _scale , scale diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index 438318bf4..c81110b37 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -47,7 +47,8 @@ namespace Tools { enum { SPRAY_MODE_COPY, SPRAY_MODE_CLONE, - SPRAY_MODE_SINGLE_PATH, + SPRAY_MODE_SINGLE_PATH, + SPRAY_MODE_ERASER, SPRAY_OPTION, }; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 1ef0ca9f1..8866cf11e 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -68,13 +68,14 @@ static void sp_stb_sensitivize( GObject *tbl ) GtkAdjustment *adj_scale = ege_adjustment_action_get_adjustment( EGE_ADJUSTMENT_ACTION(spray_scale) ); GtkToggleAction *no_overlap = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "no_overlap") ); GtkToggleAction *picker = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "picker") ); + GtkAction* picker_action = GTK_ACTION( g_object_get_data(tbl, "picker") ); GtkToggleAction *usepressurescale = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "usepressurescale") ); GtkAction *pick_fill = GTK_ACTION( g_object_get_data(tbl, "pick_fill") ); GtkAction *pick_stroke = GTK_ACTION( g_object_get_data(tbl, "pick_stroke") ); GtkAction *pick_inverse_value = GTK_ACTION( g_object_get_data(tbl, "pick_inverse_value") ); GtkAction *pick_center = GTK_ACTION( g_object_get_data(tbl, "pick_center") ); gtk_adjustment_set_value( adj_offset, 100.0 ); - if (gtk_toggle_action_get_active(no_overlap)) { + if (gtk_toggle_action_get_active(no_overlap) && gtk_action_get_sensitive(picker_action)) { gtk_action_set_sensitive( offset, TRUE ); } else { gtk_action_set_sensitive( offset, FALSE ); @@ -85,7 +86,7 @@ static void sp_stb_sensitivize( GObject *tbl ) } else { gtk_action_set_sensitive( spray_scale, TRUE ); } - if(gtk_toggle_action_get_active(picker)){ + if(gtk_toggle_action_get_active(picker) && gtk_action_get_sensitive(picker_action)){ gtk_action_set_sensitive( pick_fill, TRUE ); gtk_action_set_sensitive( pick_stroke, TRUE ); gtk_action_set_sensitive( pick_inverse_value, TRUE ); @@ -98,6 +99,21 @@ static void sp_stb_sensitivize( GObject *tbl ) } } +static void sp_spray_erase_sensitivize( GObject *tbl, bool sensitive){ + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "rotate") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "no_overlap") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "over_no_transparent") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "over_transparent") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "pick_no_overlap") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "pick_stroke") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "pick_fill") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "pick_inverse_value") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "pick_center") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "picker") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "offset") ), sensitive ); + sp_stb_sensitivize( tbl ); +} + Inkscape::UI::Dialog::CloneTiler *get_clone_tiler_panel(SPDesktop *desktop) { if (Inkscape::UI::Dialog::PanelDialogBase *panel_dialog = @@ -133,11 +149,16 @@ static void sp_spray_standard_deviation_value_changed( GtkAdjustment *adj, GObje gtk_adjustment_get_value(adj)); } -static void sp_spray_mode_changed( EgeSelectOneAction *act, GObject * /*tbl*/ ) +static void sp_spray_mode_changed( EgeSelectOneAction *act, GObject * tbl ) { int mode = ege_select_one_action_get_active( act ); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setInt("/tools/spray/mode", mode); + if(mode != 3){ + sp_spray_erase_sensitivize(tbl, true); + } else { + sp_spray_erase_sensitivize(tbl, false); + } } static void sp_spray_population_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) @@ -210,7 +231,7 @@ static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) gboolean active = gtk_toggle_action_get_active(act); prefs->setBool("/tools/spray/picker", active); if(active == true){ - prefs->setBool("/dialogs/clonetiler/dotrace", true); + prefs->setBool("/dialogs/clonetiler/dotrace", false); SPDesktop *dt = SP_ACTIVE_DESKTOP; if (Inkscape::UI::Dialog::CloneTiler *ct = get_clone_tiler_panel(dt)){ dt->_dlg_mgr->showDialog("CloneTiler"); @@ -323,7 +344,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Mode */ { - GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); + GtkListStore* model = gtk_list_store_new( 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); GtkTreeIter iter; gtk_list_store_append( model, &iter ); @@ -339,6 +360,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj 1, _("Spray clones of the initial selection"), 2, INKSCAPE_ICON("spray-mode-clone"), -1 ); + #ifdef ENABLE_SPRAY_MODE_SINGLE_PATH gtk_list_store_append( model, &iter ); gtk_list_store_set( model, &iter, @@ -347,6 +369,14 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj 2, INKSCAPE_ICON("spray-mode-union"), -1 ); #endif + + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Delete sprayed items"), + 1, _("Delete sprayed items from selection"), + 2, INKSCAPE_ICON("draw-eraser"), + -1 ); + EgeSelectOneAction* act = ege_select_one_action_new( "SprayModeAction", _("Mode"), (""), NULL, GTK_TREE_MODEL(model) ); g_object_set( act, "short_label", _("Mode:"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); @@ -575,7 +605,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj g_object_set_data( holder, "offset", eact ); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); } - sp_stb_sensitivize(holder); + sp_spray_erase_sensitivize(holder, prefs->getInt("/tools/spray/mode") != 3); } -- cgit v1.2.3 From 5c63ccc3f259311d078f77c8262459bb54677884 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 12 Nov 2015 15:34:33 +0100 Subject: Fix a warn on launch (bzr r14460) --- src/widgets/spray-toolbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 8866cf11e..db1f9526a 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -100,7 +100,6 @@ static void sp_stb_sensitivize( GObject *tbl ) } static void sp_spray_erase_sensitivize( GObject *tbl, bool sensitive){ - gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "rotate") ), sensitive ); gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "no_overlap") ), sensitive ); gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "over_no_transparent") ), sensitive ); gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "over_transparent") ), sensitive ); @@ -111,6 +110,7 @@ static void sp_spray_erase_sensitivize( GObject *tbl, bool sensitive){ gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "pick_center") ), sensitive ); gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "picker") ), sensitive ); gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "offset") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "spray_rotation") ), sensitive ); sp_stb_sensitivize( tbl ); } -- cgit v1.2.3 From 56215c1d1b93e249c0a4cddddc67868dc4f3dd56 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 12 Nov 2015 16:05:46 +0100 Subject: Fix crashes in erase mode of spray (bzr r14461) --- src/ui/tools/spray-tool.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 84b0ad431..0d3405dbd 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -586,6 +586,7 @@ static bool fit_item(SPDesktop *desktop, return false; } std::vector const items_selected(selection->itemList()); + std::vector items_down_erased; 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(); @@ -594,6 +595,7 @@ static bool fit_item(SPDesktop *desktop, double bbox_left = bbox_down->left(); double bbox_top = bbox_down->top(); gchar const * item_down_sharp = g_strdup_printf("#%s", item_down->getId()); + items_down_erased.push_back(item_down); for (std::vector::const_iterator j=items_selected.begin(); j!=items_selected.end(); j++) { SPItem *item_selected = *j; gchar const * spray_origin; @@ -607,8 +609,10 @@ static bool fit_item(SPDesktop *desktop, strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) { if(mode == SPRAY_MODE_ERASER){ - if(strcmp(item_down_sharp, spray_origin) != 0 ){ + if(strcmp(item_down_sharp, spray_origin) != 0 && !selection->includes(item_down) ){ item_down->deleteObject(); + items_down_erased.pop_back(); + break; } }else if(no_overlap){ if(!(offset_width < 0 && offset_height < 0 && std::abs(bbox_left - bbox_left_main) > std::abs(offset_width) && @@ -627,7 +631,7 @@ static bool fit_item(SPDesktop *desktop, } if(mode == SPRAY_MODE_ERASER){ if(!no_overlap && (picker || over_transparent || over_no_transparent)){ - showHidden(items_down); + showHidden(items_down_erased); } return false; } -- cgit v1.2.3 From 7d77133cec471ae1e3e40937ebb637876f1c9a47 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 13 Nov 2015 12:54:14 +0100 Subject: Fixed a bug on Spray Friendly when SPLPEITEM has clones. POinted by Ivan Louette (bzr r14422.3.5) --- src/live_effects/lpe-roughen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 6c2ec0227..00f7b8012 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -98,7 +98,7 @@ LPERoughen::~LPERoughen() {} void LPERoughen::doBeforeEffect(SPLPEItem const *lpeitem) { - if(spray_tool_friendly && seed == 0){ + if(spray_tool_friendly && seed == 0 && SP_OBJECT(lpeitem)->getId()){ std::string id_item(SP_OBJECT(lpeitem)->getId()); long seed = static_cast(boost::hash_value(id_item)); global_randomize.param_set_value(global_randomize.get_value(), seed); -- cgit v1.2.3 From bbb9eba40d9bd611af330c40897378adcfd60001 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 13 Nov 2015 15:55:42 +0100 Subject: Fix a bug on bspline, duplicating end nodes (bzr r14462) --- src/live_effects/lpe-bspline.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index 731b5d645..7e92e767d 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -206,6 +206,18 @@ void sp_bspline_do_effect(SPCurve *curve, double helper_size) Geom::D2 sbasis_helper; Geom::CubicBezier const *cubic = NULL; curve_n->moveto(curve_it1->initialPoint()); + if (path_it->closed()) { + const Geom::Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // Geom::LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } + } while (curve_it1 != curve_endit) { SPCurve *in = new SPCurve(); in->moveto(curve_it1->initialPoint()); @@ -361,6 +373,18 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) Geom::D2 sbasis_out; Geom::CubicBezier const *cubic = NULL; curve_n->moveto(curve_it1->initialPoint()); + if (path_it->closed()) { + const Geom::Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // Geom::LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } + } while (curve_it1 != curve_endit) { SPCurve *in = new SPCurve(); in->moveto(curve_it1->initialPoint()); -- cgit v1.2.3 From e8ec23b80082d4c1c20675c83f5a6fad18c3392d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 13 Nov 2015 16:11:51 +0100 Subject: Fix bug end node, start calculate size based in number of nodes and lenght (bzr r14422.3.6) --- src/live_effects/lpe-roughen.cpp | 67 +++++++++++++++++++++++++++++++++++++++- src/live_effects/lpe-roughen.h | 1 + 2 files changed, 67 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 00f7b8012..6b18cf14e 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -65,7 +65,7 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) true), fixed_displacement(_("Fixed displacement"), _("Fixed displacement, 1/3 of segment length"), "fixed_displacement", &wr, this, false), - spray_tool_friendly(_("Spray Tool friendly"), _("For use with spray tool"), + spray_tool_friendly(_("Spray Tool friendly"), _("For use with spray tool in copy mode"), "spray_tool_friendly", &wr, this, false) { registerParameter(&method); @@ -96,6 +96,59 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) LPERoughen::~LPERoughen() {} +void LPERoughen::doOnApply(SPLPEItem const* lpeitem) +{ + SPLPEItem* item = const_cast(lpeitem); + //calculamos el tamaño mas optimo para el roughen en función del número de nodos y la distancia del trazado +} + +static void +sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) +{ + std::vector const item_list = sp_item_group_item_list(group); + + for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = *iter; + + SPGroup *subGroup = dynamic_cast(subitem); + if (subGroup) { + sp_group_perform_patheffect(subGroup, topgroup, write); + } else { + SPShape *subShape = dynamic_cast(subitem); + if (subShape) { + SPCurve * c = NULL; + + SPPath *subPath = dynamic_cast(subShape); + if (subPath) { + c = subPath->get_original_curve(); + } else { + c = subShape->getCurve(); + } + + // only run LPEs when the shape has a curve defined + if (c) { + c->transform(i2anc_affine(subitem, topgroup)); + topgroup->performPathEffect(c); + c->transform(i2anc_affine(subitem, topgroup).inverse()); + subShape->setCurve(c, TRUE); + + if (write) { + Inkscape::XML::Node *repr = subitem->getRepr(); + gchar *str = sp_svg_write_path(c->get_pathvector()); + repr->setAttribute("d", str); +#ifdef GROUP_VERBOSE + g_message("sp_group_perform_patheffect writes 'd' attribute"); +#endif + g_free(str); + } + + c->unref(); + } + } + } + } +} + void LPERoughen::doBeforeEffect(SPLPEItem const *lpeitem) { if(spray_tool_friendly && seed == 0 && SP_OBJECT(lpeitem)->getId()){ @@ -228,6 +281,18 @@ void LPERoughen::doEffect(SPCurve *curve) Geom::Point prev(0, 0); Geom::Point last_move(0, 0); nCurve->moveto(curve_it1->initialPoint()); + if (path_it->closed()) { + const Geom::Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // Geom::LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } + } while (curve_it1 != curve_endit) { Geom::CubicBezier const *cubic = NULL; cubic = dynamic_cast(&*curve_it1); diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index 6224c09fa..b12bd08af 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -45,6 +45,7 @@ public: virtual void doEffect(SPCurve *curve); virtual double sign(double randNumber); + virtual void doOnApply(SPLPEItem const* lpeitem); 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); -- cgit v1.2.3 From 7c7b311cb7ff307a4e865341c3b78ec669e73fc7 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Fri, 13 Nov 2015 18:53:22 +0100 Subject: static code analysis (bzr r14463) --- src/gradient-chemistry.cpp | 4 ++-- src/gradient-drag.cpp | 6 +++--- src/graphlayout.cpp | 2 +- src/object-snapper.cpp | 2 +- src/path-chemistry.cpp | 12 ++++++------ src/selcue.cpp | 6 +++--- src/sp-clippath.cpp | 2 +- src/sp-mask.cpp | 2 +- src/sp-pattern.cpp | 6 +++--- src/ui/dialog/filter-effects-dialog.cpp | 6 +++--- src/ui/dialog/find.cpp | 16 ++++++++-------- src/ui/dialog/grid-arrange-tab.cpp | 6 +++--- src/ui/dialog/objects.cpp | 2 +- src/ui/dialog/polar-arrange-tab.cpp | 2 +- src/ui/tools/connector-tool.cpp | 2 +- src/ui/tools/gradient-tool.cpp | 4 ++-- src/ui/tools/spray-tool.cpp | 8 ++++---- src/ui/tools/tweak-tool.cpp | 2 +- src/widgets/fill-style.cpp | 6 +++--- src/widgets/spiral-toolbar.cpp | 4 ++-- 20 files changed, 50 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 409e9f0e6..886bf484d 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -1571,7 +1571,7 @@ void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTa Inkscape::Selection *selection = desktop->getSelection(); const std::vector list=selection->itemList(); - for (std::vector::const_iterator i = list.begin(); i != list.end(); i++) { + for (std::vector::const_iterator i = list.begin(); i != list.end(); ++i) { sp_item_gradient_invert_vector_color(*i, fill_or_stroke); } @@ -1596,7 +1596,7 @@ void sp_gradient_reverse_selected_gradients(SPDesktop *desktop) drag->selected_reverse_vector(); } else { // If no drag or no dragger selected, act on selection (both fill and stroke gradients) const std::vector list=selection->itemList(); - for (std::vector::const_iterator i = list.begin(); i != list.end(); i++) { + for (std::vector::const_iterator i = list.begin(); i != list.end(); ++i) { sp_item_gradient_reverse_vector(*i, Inkscape::FOR_FILL); sp_item_gradient_reverse_vector(*i, Inkscape::FOR_STROKE); } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index b5a988729..f94ffb838 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -2083,7 +2083,7 @@ void GrDrag::updateDraggers() g_return_if_fail(this->selection != NULL); std::vector list = this->selection->itemList(); - for (std::vector::const_iterator i = list.begin(); i != list.end(); i++) { + for (std::vector::const_iterator i = list.begin(); i != list.end(); ++i) { SPItem *item = *i; SPStyle *style = item->style; @@ -2152,7 +2152,7 @@ void GrDrag::updateLines() g_return_if_fail(this->selection != NULL); std::vector list = this->selection->itemList(); - for (std::vector::const_iterator i = list.begin(); i != list.end(); i++) { + for (std::vector::const_iterator i = list.begin(); i != list.end(); ++i) { SPItem *item = *i; SPStyle *style = item->style; @@ -2296,7 +2296,7 @@ void GrDrag::updateLevels() g_return_if_fail (this->selection != NULL); std::vector list = this->selection->itemList(); - for (std::vector::const_iterator i = list.begin(); i != list.end(); i++) { + for (std::vector::const_iterator i = list.begin(); i != list.end(); ++i) { SPItem *item = *i; Geom::OptRect rect = item->desktopVisualBounds(); if (rect) { diff --git a/src/graphlayout.cpp b/src/graphlayout.cpp index 40994347c..9b67ba0b5 100644 --- a/src/graphlayout.cpp +++ b/src/graphlayout.cpp @@ -89,7 +89,7 @@ struct CheckProgress : TestConvergence { * not connectors in filtered */ void filterConnectors(std::vector const &items, list &filtered) { - for(std::vector::const_iterator i = items.begin();i !=items.end(); i++){ + for(std::vector::const_iterator i = items.begin();i !=items.end(); ++i){ SPItem *item = *i; if(!isConnector(item)) { filtered.push_back(item); diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 7302f9de6..5b7874c61 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -239,7 +239,7 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, bool old_pref2 = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_ROTATION_CENTER); if (old_pref2) { std::vector rotationSource=_snapmanager->getRotationCenterSource(); - for ( std::vector::const_iterator itemlist = rotationSource.begin(); itemlist != rotationSource.end(); itemlist++) { + for ( std::vector::const_iterator itemlist = rotationSource.begin(); itemlist != rotationSource.end(); ++itemlist) { if ((*i).item == *itemlist) { // don't snap to this item's rotation center _snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_ROTATION_CENTER, false); diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index c71465782..7b52ac2e1 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -71,14 +71,14 @@ sp_selected_path_combine(SPDesktop *desktop) items = sp_degroup_list (items); // descend into any groups in selection std::vector to_paths; - for (std::vector::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++) { + for (std::vector::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i) { if (!dynamic_cast(*i) && !dynamic_cast(*i)) { to_paths.push_back(*i); } } std::vector converted; bool did = sp_item_list_to_curves(to_paths, items, converted); - for (std::vector::const_iterator i = converted.begin(); i != converted.end(); i++) + for (std::vector::const_iterator i = converted.begin(); i != converted.end(); ++i) items.push_back((SPItem*)doc->getObjectByRepr(*i)); items = sp_degroup_list (items); // converting to path may have added more groups, descend again @@ -101,7 +101,7 @@ sp_selected_path_combine(SPDesktop *desktop) selection->clear(); } - for (std::vector::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++){ + for (std::vector::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i){ SPItem *item = *i; SPPath *path = dynamic_cast(item); @@ -204,7 +204,7 @@ sp_selected_path_break_apart(SPDesktop *desktop) bool did = false; std::vector itemlist(selection->itemList()); - for (std::vector::const_iterator i = itemlist.begin(); i != itemlist.end(); i++){ + for (std::vector::const_iterator i = itemlist.begin(); i != itemlist.end(); ++i){ SPItem *item = *i; @@ -354,7 +354,7 @@ bool sp_item_list_to_curves(const std::vector &items, std::vector& selected, std::vector &to_select, bool skip_all_lpeitems) { bool did = false; - for (std::vector::const_iterator i = items.begin(); i != items.end(); i++){ + for (std::vector::const_iterator i = items.begin(); i != items.end(); ++i){ SPItem *item = *i; g_assert(item != NULL); SPDocument *document = item->document; @@ -621,7 +621,7 @@ sp_selected_path_reverse(SPDesktop *desktop) bool did = false; desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths...")); - for (std::vector::const_iterator i = items.begin(); i != items.end(); i++){ + for (std::vector::const_iterator i = items.begin(); i != items.end(); ++i){ SPPath *path = dynamic_cast(*i); if (!path) { diff --git a/src/selcue.cpp b/src/selcue.cpp index c73219b7d..297b9fffc 100644 --- a/src/selcue.cpp +++ b/src/selcue.cpp @@ -104,7 +104,7 @@ void Inkscape::SelCue::_updateItemBboxes(gint mode, int prefs_bbox) int bcount = 0; std::vector ll=_selection->itemList(); - for (std::vector::const_iterator l = ll.begin(); l != ll.end(); l++) { + for (std::vector::const_iterator l = ll.begin(); l != ll.end(); ++l) { SPItem *item = *l; SPCanvasItem* box = _item_bboxes[bcount ++]; @@ -147,7 +147,7 @@ void Inkscape::SelCue::_newItemBboxes() int prefs_bbox = prefs->getBool("/tools/bounding_box"); std::vector ll=_selection->itemList(); - for (std::vector::const_iterator l = ll.begin(); l != ll.end(); l++) { + for (std::vector::const_iterator l = ll.begin(); l != ll.end(); ++l) { SPItem *item = *l; Geom::OptRect const b = (prefs_bbox == 0) ? @@ -202,7 +202,7 @@ void Inkscape::SelCue::_newTextBaselines() _text_baselines.clear(); std::vector ll = _selection->itemList(); - for (std::vector::const_iterator l=ll.begin();l!=ll.end();l++) { + for (std::vector::const_iterator l=ll.begin();l!=ll.end();++l) { SPItem *item = *l; SPCanvasItem* baseline_point = NULL; diff --git a/src/sp-clippath.cpp b/src/sp-clippath.cpp index d66508eae..0c07d1b3d 100644 --- a/src/sp-clippath.cpp +++ b/src/sp-clippath.cpp @@ -308,7 +308,7 @@ const gchar *SPClipPath::create (std::vector &reprs, SPDoc const gchar *id = repr->attribute("id"); SPObject *clip_path_object = document->getObjectById(id); - for (std::vector::const_iterator it = reprs.begin(); it != reprs.end(); it++) { + for (std::vector::const_iterator it = reprs.begin(); it != reprs.end(); ++it) { Inkscape::XML::Node *node = (*it); SPItem *item = SP_ITEM(clip_path_object->appendChildRepr(node)); diff --git a/src/sp-mask.cpp b/src/sp-mask.cpp index f8fb7aff4..5f7a2ec26 100644 --- a/src/sp-mask.cpp +++ b/src/sp-mask.cpp @@ -221,7 +221,7 @@ sp_mask_create (std::vector &reprs, SPDocument *document, const gchar *mask_id = repr->attribute("id"); SPObject *mask_object = document->getObjectById(mask_id); - for (std::vector::const_iterator it = reprs.begin(); it != reprs.end(); it++) { + for (std::vector::const_iterator it = reprs.begin(); it != reprs.end(); ++it) { Inkscape::XML::Node *node = (*it); SPItem *item = SP_ITEM(mask_object->appendChildRepr(node)); diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index 755d3d162..dd351a8d5 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -244,7 +244,7 @@ void SPPattern::update(SPCtx *ctx, unsigned int flags) std::list l; _getChildren(l); - for (SPObjectIterator it = l.begin(); it != l.end(); it++) { + for (SPObjectIterator it = l.begin(); it != l.end(); ++it) { SPObject *child = *it; sp_object_ref(child, NULL); @@ -270,7 +270,7 @@ void SPPattern::modified(unsigned int flags) std::list l; _getChildren(l); - for (SPObjectIterator it = l.begin(); it != l.end(); it++) { + for (SPObjectIterator it = l.begin(); it != l.end(); ++it) { SPObject *child = *it; sp_object_ref(child, NULL); @@ -398,7 +398,7 @@ const gchar *SPPattern::produce(const std::vector &reprs, const gchar *pat_id = repr->attribute("id"); SPObject *pat_object = document->getObjectById(pat_id); - for (NodePtrIterator i = reprs.begin(); i != reprs.end(); i++) { + for (NodePtrIterator i = reprs.begin(); i != reprs.end(); ++i) { Inkscape::XML::Node *node = *i; SPItem *copy = SP_ITEM(pat_object->appendChildRepr(node)); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 22c8c76f2..08a58291d 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1474,7 +1474,7 @@ void FilterEffectsDialog::FilterModifier::update_selection(Selection *sel) std::set used; std::vector itemlist=sel->itemList(); - for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { SPObject *obj = *i; SPStyle *style = obj->style; if (!style || !SP_IS_ITEM(obj)) { @@ -1555,7 +1555,7 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri filter = 0; std::vector itemlist=sel->itemList(); - for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { SPItem * item = *i; SPStyle *style = item->style; g_assert(style != NULL); @@ -1669,7 +1669,7 @@ void FilterEffectsDialog::FilterModifier::remove_filter() // Delete all references to this filter std::vector x,y; std::vector all = get_all_items(x, _desktop->currentRoot(), _desktop, false, false, true, y); - for(std::vector::const_iterator i=all.begin(); all.end() != i; i++) { + for(std::vector::const_iterator i=all.begin(); all.end() != i; ++i) { if (!SP_IS_ITEM(*i)) { continue; } diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index a8ac42a1b..0f368c5ac 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -561,7 +561,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b std::vector out; if (check_searchin_text.get_active()) { - for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); @@ -584,7 +584,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b bool attrvalue = check_attributevalue.get_active(); if (ids) { - for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast(obj); if (item_id_match(item, text, exact, casematch)) { @@ -600,7 +600,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b if (style) { - for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); @@ -617,7 +617,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b if (attrname) { - for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); @@ -634,7 +634,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b if (attrvalue) { - for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); @@ -651,7 +651,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b if (font) { - for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); @@ -718,7 +718,7 @@ bool Find::item_type_match (SPItem *item) std::vector Find::filter_types (std::vector &l) { std::vector n; - for(std::vector::const_reverse_iterator i=l.rbegin(); l.rend() != i; i++) { + for(std::vector::const_reverse_iterator i=l.rbegin(); l.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); @@ -762,7 +762,7 @@ std::vector &Find::all_items (SPObject *r, std::vector &l, boo std::vector &Find::all_selection_items (Inkscape::Selection *s, std::vector &l, SPObject *ancestor, bool hidden, bool locked) { std::vector itemlist=s->itemList(); - for(std::vector::const_reverse_iterator i=itemlist.rbegin(); itemlist.rend() != i; i++) { + for(std::vector::const_reverse_iterator i=itemlist.rbegin(); itemlist.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index 086cbe45f..53c25c3d5 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -164,7 +164,7 @@ void GridArrangeTab::arrange() Inkscape::Selection *selection = desktop->getSelection(); const std::vector items = selection ? selection->itemList() : std::vector(); - for(std::vector::const_iterator i = items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i = items.begin();i!=items.end(); ++i){ SPItem *item = *i; Geom::OptRect b = item->documentVisualBounds(); if (!b) { @@ -202,7 +202,7 @@ void GridArrangeTab::arrange() cnt=0; const std::vector sizes(sorted); - for (std::vector::const_iterator i = sizes.begin();i!=sizes.end();i++) { + for (std::vector::const_iterator i = sizes.begin();i!=sizes.end(); ++i) { SPItem *item = *i; Geom::OptRect b = item->documentVisualBounds(); if (b) { @@ -301,7 +301,7 @@ g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_h cnt=0; std::vector::iterator it = sorted.begin(); - for (row_cnt=0; ((it != sorted.end()) && (row_cntunselect_all(); SPItem *item = NULL; std::vector const items = sel->itemList(); - for(std::vector::const_iterator i=items.begin(); i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin(); i!=items.end(); ++i){ item = *i; if (setOpacity) { diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index a93cebee8..5ec1285c1 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -373,7 +373,7 @@ void PolarArrangeTab::arrange() Geom::Point realCenter = Geom::Point(cx, cy) * transformation; int i = 0; - for(std::vector::const_iterator it=tmp.begin();it!=tmp.end();it++) + for(std::vector::const_iterator it=tmp.begin();it!=tmp.end(); ++it) { SPItem *item = *it; diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 0a36877ff..b84d16686 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -1307,7 +1307,7 @@ void cc_selection_set_avoid(bool const set_avoid) int changes = 0; std::vector l = selection->itemList(); - for(std::vector::const_iterator i=l.begin();i!=l.end();i++) { + for(std::vector::const_iterator i=l.begin();i!=l.end(); ++i) { SPItem *item = *i; char const *value = (set_avoid) ? "true" : NULL; diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 603458983..bcb0b12b7 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -495,7 +495,7 @@ bool GradientTool::root_handler(GdkEvent* event) { sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->itemList().front()), this->mousepoint_doc, event->button.time); } else { std::vector items=selection->itemList(); - for (std::vector::const_iterator i = items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i = items.begin();i!=items.end();++i) { SPItem *item = *i; SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR); Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; @@ -910,7 +910,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta sp_repr_css_set_property(css, "fill-opacity", "1.0"); std::vector itemlist = selection->itemList(); - for (std::vector::const_iterator i = itemlist.begin();i!=itemlist.end();i++) { + for (std::vector::const_iterator i = itemlist.begin();i!=itemlist.end();++i) { //FIXME: see above sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 0d3405dbd..e9b319bbb 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -999,7 +999,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, int i=1; std::vector items=selection->itemList(); - for(std::vector::const_iterator it=items.begin();it!=items.end();it++){ + for(std::vector::const_iterator it=items.begin();it!=items.end(); ++it){ SPItem *item1 = *it; if (i == 1) { parent_item = item1; @@ -1168,13 +1168,13 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point { std::vector const items(selection->itemList()); - for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end(); ++i){ SPItem *item = *i; g_assert(item != NULL); sp_object_ref(item); } - for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end(); ++i){ SPItem *item = *i; g_assert(item != NULL); if (sp_spray_recursive(desktop @@ -1218,7 +1218,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++){ + for(std::vector::const_iterator i=items.begin();i!=items.end(); ++i){ SPItem *item = *i; g_assert(item != NULL); sp_object_unref(item); diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index 94f7aa135..39a7a3f0b 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -1077,7 +1077,7 @@ sp_tweak_dilate (TweakTool *tc, Geom::Point event_p, Geom::Point p, Geom::Point double color_force = MIN(sqrt(path_force)/20.0, 1); std::vector items=selection->itemList(); - for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end(); ++i){ SPItem *item = *i; if (is_color_mode (tc->mode)) { diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index fa5eabab4..a57c891e5 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -570,7 +570,7 @@ void FillNStroke::updateFromPaint() } } - for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end(); ++i){ //FIXME: see above if (kind == FILL) { sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); @@ -596,7 +596,7 @@ void FillNStroke::updateFromPaint() // We have changed from another gradient type, or modified spread/units within // this gradient type. vector = sp_gradient_ensure_vector_normalized(vector); - for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end(); ++i){ //FIXME: see above if (kind == FILL) { sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); @@ -642,7 +642,7 @@ void FillNStroke::updateFromPaint() // cannot just call sp_desktop_set_style, because we don't want to touch those // objects who already have the same root pattern but through a different href // chain. FIXME: move this to a sp_item_set_pattern - for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end(); ++i){ Inkscape::XML::Node *selrepr = (*i)->getRepr(); if ( (kind == STROKE) && !selrepr) { continue; diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 751a60f06..7e7398091 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -80,7 +80,7 @@ static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustr bool modmade = false; std::vector itemlist=desktop->getSelection()->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ SPItem *item = *i; if (SP_IS_SPIRAL(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -196,7 +196,7 @@ static void sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, purge_repr_listener( tbl, tbl ); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ SPItem *item = *i; if (SP_IS_SPIRAL(item)) { n_selected++; -- cgit v1.2.3 From 15a2f231bec816e134b98ca4de248be499225132 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Fri, 13 Nov 2015 18:54:23 +0100 Subject: static code analysis (bzr r14464) --- src/persp3d.cpp | 8 ++++---- src/sp-mask.h | 8 ++++---- src/widgets/text-toolbar.cpp | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/persp3d.cpp b/src/persp3d.cpp index dc0975d12..a48481145 100644 --- a/src/persp3d.cpp +++ b/src/persp3d.cpp @@ -36,10 +36,10 @@ static int global_counter = 0; /* Constructor/destructor for the internal class */ -Persp3DImpl::Persp3DImpl() { - tmat = Proj::TransfMat3x4 (); - document = NULL; - +Persp3DImpl::Persp3DImpl() : + tmat (Proj::TransfMat3x4 ()), + document (NULL) +{ my_counter = global_counter++; } diff --git a/src/sp-mask.h b/src/sp-mask.h index 74bd4d66e..19786b1fd 100644 --- a/src/sp-mask.h +++ b/src/sp-mask.h @@ -86,10 +86,10 @@ protected: Inkscape::XML::Node * const owner_repr = owner->getRepr(); //XML Tree being used directly here while it shouldn't be... Inkscape::XML::Node * const obj_repr = obj->getRepr(); - char const * owner_name = NULL; - char const * owner_mask = NULL; - char const * obj_name = NULL; - char const * obj_id = NULL; + char const * owner_name = ""; + char const * owner_mask = ""; + char const * obj_name = ""; + char const * obj_id = ""; if (owner_repr != NULL) { owner_name = owner_repr->name(); owner_mask = owner_repr->attribute("mask"); diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 7b22e4af7..c49fbccaa 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -155,7 +155,7 @@ static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GOb act->active = 0; // New family is always at top of list. } - std::pair ui = fontlister->set_font_family( act->active ); + fontlister->set_font_family( act->active ); // active text set in sp_text_toolbox_selection_changed() SPCSSAttr *css = sp_repr_css_attr_new (); @@ -373,7 +373,7 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) // move the x of all texts to preserve the same bbox Inkscape::Selection *selection = desktop->getSelection(); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ if (SP_IS_TEXT(*i)) { SPItem *item = *i; @@ -526,7 +526,7 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) Inkscape::Selection *selection = desktop->getSelection(); bool modmade = false; std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ if (SP_IS_TEXT (*i)) { (*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); modmade = true; @@ -871,7 +871,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Find out if we have flowed text now so we can use it several places gboolean isFlow = false; std::vector itemlist=SP_ACTIVE_DESKTOP->getSelection()->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ // const gchar* id = reinterpret_cast(items->data)->getId(); // std::cout << " " << id << std::endl; if( SP_IS_FLOWTEXT(*i)) { @@ -1165,7 +1165,7 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p SPDocument *document = desktop->getDocument(); std::vector x,y; std::vector allList = get_all_items(x, document->getRoot(), desktop, false, false, true, y); - for(std::vector::const_reverse_iterator i=allList.rbegin();i!=allList.rend();i++){ + for(std::vector::const_reverse_iterator i=allList.rbegin();i!=allList.rend(); ++i){ SPItem *item = *i; SPStyle *style = item->style; -- cgit v1.2.3 From b833d034eeaa8bc144f6bdb2edd300056ed67b34 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 13 Nov 2015 19:29:13 +0100 Subject: Fix a compile problem (bzr r14422.3.7) --- src/live_effects/lpe-roughen.cpp | 46 ---------------------------------------- 1 file changed, 46 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 6b18cf14e..2be3bae31 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -98,56 +98,10 @@ LPERoughen::~LPERoughen() {} void LPERoughen::doOnApply(SPLPEItem const* lpeitem) { - SPLPEItem* item = const_cast(lpeitem); //calculamos el tamaño mas optimo para el roughen en función del número de nodos y la distancia del trazado } -static void -sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) -{ - std::vector const item_list = sp_item_group_item_list(group); - - for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { - SPObject *subitem = *iter; - - SPGroup *subGroup = dynamic_cast(subitem); - if (subGroup) { - sp_group_perform_patheffect(subGroup, topgroup, write); - } else { - SPShape *subShape = dynamic_cast(subitem); - if (subShape) { - SPCurve * c = NULL; - - SPPath *subPath = dynamic_cast(subShape); - if (subPath) { - c = subPath->get_original_curve(); - } else { - c = subShape->getCurve(); - } - - // only run LPEs when the shape has a curve defined - if (c) { - c->transform(i2anc_affine(subitem, topgroup)); - topgroup->performPathEffect(c); - c->transform(i2anc_affine(subitem, topgroup).inverse()); - subShape->setCurve(c, TRUE); - if (write) { - Inkscape::XML::Node *repr = subitem->getRepr(); - gchar *str = sp_svg_write_path(c->get_pathvector()); - repr->setAttribute("d", str); -#ifdef GROUP_VERBOSE - g_message("sp_group_perform_patheffect writes 'd' attribute"); -#endif - g_free(str); - } - - c->unref(); - } - } - } - } -} void LPERoughen::doBeforeEffect(SPLPEItem const *lpeitem) { -- cgit v1.2.3 From b07fe706e7b9f583c21af31e841373fadf1d6a82 Mon Sep 17 00:00:00 2001 From: Alexandre Prokoudine Date: Sat, 14 Nov 2015 13:48:27 +0300 Subject: Some sane defaults for spray offset, subject to further tweaking (bzr r14467) --- src/widgets/spray-toolbar.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index db1f9526a..1774ba418 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -594,13 +594,15 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Offset */ { + gchar const* labels[] = {_("(minimum offset)"), 0, 0, 0, _("(default)"), 0, 0, _("(maximum offset)")}; + gdouble values[] = {0, 25, 50, 75, 100, 150, 200, 1000}; EgeAdjustmentAction *eact = create_adjustment_action( "SprayToolOffsetAction", _("Offset %"), _("Offset %:"), _("Increase to segregate objects more (value in percent)"), "/tools/spray/offset", 100, GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, - 0, 10000, 1, 4, - 0, 0, 0, + 0, 1000, 1, 4, + labels, values, G_N_ELEMENTS(labels), sp_spray_offset_value_changed, NULL, 0 , 0); g_object_set_data( holder, "offset", eact ); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); -- cgit v1.2.3 From d8637ea8e848bd9727c14c584c59a9f61d1930c8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 14 Nov 2015 14:17:29 +0100 Subject: Fix erase mode in no overlap mode, pointed by Ivan Louette (bzr r14469) --- src/ui/tools/spray-tool.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index e9b319bbb..7de2a0b04 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -559,21 +559,27 @@ static bool fit_item(SPDesktop *desktop, if (!rect_sprayed.hasZeroArea()) { rgba2 = getPickerData(rect_sprayed.roundOutwards()); } - if(pick_no_overlap){ - if(rgba != rgba2){ - return false; + if(pick_no_overlap) { + if(rgba != rgba2) { + if(mode != SPRAY_MODE_ERASER) { + return false; + } } } - if(!pick_center){ + if(!pick_center) { rgba = rgba2; } - if(!over_transparent && (SP_RGBA32_A_F(rgba) == 0 || SP_RGBA32_A_F(rgba) < 1e-6)){ - return false; + if(!over_transparent && (SP_RGBA32_A_F(rgba) == 0 || SP_RGBA32_A_F(rgba) < 1e-6)) { + if(mode != SPRAY_MODE_ERASER) { + return false; + } } - if(!over_no_transparent && SP_RGBA32_A_F(rgba) > 0){ - return false; + if(!over_no_transparent && SP_RGBA32_A_F(rgba) > 0) { + if(mode != SPRAY_MODE_ERASER) { + return false; + } } - if(offset < 100 ){ + if(offset < 100 ) { offset_width = ((99.0 - offset) * width_transformed)/100.0 - width_transformed; offset_height = ((99.0 - offset) * height_transformed)/100.0 - height_transformed; } else { @@ -608,13 +614,13 @@ static bool fit_item(SPDesktop *desktop, (item_down->getAttribute("inkscape:spray-origin") && strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) { - if(mode == SPRAY_MODE_ERASER){ + if(mode == SPRAY_MODE_ERASER) { if(strcmp(item_down_sharp, spray_origin) != 0 && !selection->includes(item_down) ){ item_down->deleteObject(); items_down_erased.pop_back(); break; } - }else if(no_overlap){ + } else if(no_overlap) { if(!(offset_width < 0 && offset_height < 0 && std::abs(bbox_left - bbox_left_main) > std::abs(offset_width) && std::abs(bbox_top - bbox_top_main) > std::abs(offset_height))){ if(!no_overlap && (picker || over_transparent || over_no_transparent)){ @@ -622,7 +628,7 @@ static bool fit_item(SPDesktop *desktop, } return false; } - } else if(picker || over_transparent || over_no_transparent){ + } else if(picker || over_transparent || over_no_transparent) { item_down->setHidden(true); item_down->updateRepr(); } -- cgit v1.2.3 From 151126ef45cb00bab461181388a433e751a27bc3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 14 Nov 2015 18:32:14 +0100 Subject: adding default width (bzr r14422.3.8) --- src/live_effects/lpe-roughen.cpp | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 2be3bae31..87046ef4a 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -20,6 +20,7 @@ #include "live_effects/parameter/parameter.h" #include #include "helper/geom.h" +#include "sp-item-group.h" #include #include @@ -42,6 +43,35 @@ static const Util::EnumData HandlesMethodData[HM_END] = { static const Util::EnumDataConverter HMConverter(HandlesMethodData, HM_END); +static void +sp_get_better_default_size(SPItem *item, double &value) +{ + if (SP_IS_GROUP(item)) { + std::vector const item_list = sp_item_group_item_list(SP_GROUP(item)); + for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPItem *subitem = *iter; + value += sp_get_better_default_size(subitem, value); + } + if(item_list.size() > 0){ + value /= item_list.size(); + } + } else { + SPShape *shape = dynamic_cast(item); + if (shape) { + SPCurve * c = NULL; + SPPath *path = dynamic_cast(shape); + if (path) { + c = path->get_original_curve(); + } else { + c = shape->getCurve(); + } + if (c) { + value = Geom::length(paths_to_pw(c->get_pathvector()))/(c->get_segment_count () * 3); + } + } + } +} + LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) : Effect(lpeobject), // initialise your parameters here: @@ -98,11 +128,13 @@ LPERoughen::~LPERoughen() {} void LPERoughen::doOnApply(SPLPEItem const* lpeitem) { - //calculamos el tamaño mas optimo para el roughen en función del número de nodos y la distancia del trazado + SPLPEItem * splpeitem = const_cast(lpeitem); + double initial = 0; + sp_get_better_default_size(SP_ITEM(splpeitem), initial); + displace_x.param_set_value(initial, displace_x.defseed); + displace_y.param_set_value(initial, displace_y.defseed); } - - void LPERoughen::doBeforeEffect(SPLPEItem const *lpeitem) { if(spray_tool_friendly && seed == 0 && SP_OBJECT(lpeitem)->getId()){ -- cgit v1.2.3 From 7c89ed9dc03fb5f83eac25823c54edd91c123f7f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 14 Nov 2015 19:21:59 +0100 Subject: Fixing compile problem (bzr r14422.3.10) --- src/live_effects/lpe-roughen.cpp | 58 ++++++++++++++++++------------------- src/live_effects/parameter/random.h | 2 +- 2 files changed, 30 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 87046ef4a..0d0debd24 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -43,35 +43,6 @@ static const Util::EnumData HandlesMethodData[HM_END] = { static const Util::EnumDataConverter HMConverter(HandlesMethodData, HM_END); -static void -sp_get_better_default_size(SPItem *item, double &value) -{ - if (SP_IS_GROUP(item)) { - std::vector const item_list = sp_item_group_item_list(SP_GROUP(item)); - for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { - SPItem *subitem = *iter; - value += sp_get_better_default_size(subitem, value); - } - if(item_list.size() > 0){ - value /= item_list.size(); - } - } else { - SPShape *shape = dynamic_cast(item); - if (shape) { - SPCurve * c = NULL; - SPPath *path = dynamic_cast(shape); - if (path) { - c = path->get_original_curve(); - } else { - c = shape->getCurve(); - } - if (c) { - value = Geom::length(paths_to_pw(c->get_pathvector()))/(c->get_segment_count () * 3); - } - } - } -} - LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) : Effect(lpeobject), // initialise your parameters here: @@ -126,6 +97,35 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) LPERoughen::~LPERoughen() {} +static void +sp_get_better_default_size(SPItem *item, double &value) +{ + if (SP_IS_GROUP(item)) { + std::vector const item_list = sp_item_group_item_list(SP_GROUP(item)); + for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPItem *subitem = *iter; + sp_get_better_default_size(subitem, value); + } + if(item_list.size() > 0){ + value /= item_list.size(); + } + } else { + SPShape *shape = dynamic_cast(item); + if (shape) { + SPCurve * c = NULL; + SPPath *path = dynamic_cast(shape); + if (path) { + c = path->get_original_curve(); + } else { + c = shape->getCurve(); + } + if (c) { + value += Geom::length(paths_to_pw(c->get_pathvector()))/(c->get_segment_count () * 3); + } + } + } +} + void LPERoughen::doOnApply(SPLPEItem const* lpeitem) { SPLPEItem * splpeitem = const_cast(lpeitem); diff --git a/src/live_effects/parameter/random.h b/src/live_effects/parameter/random.h index ca4440336..52e3cc0a6 100644 --- a/src/live_effects/parameter/random.h +++ b/src/live_effects/parameter/random.h @@ -43,11 +43,11 @@ public: operator gdouble(); inline gdouble get_value() { return value; } ; + long defseed; protected: long startseed; long seed; - long defseed; gdouble value; gdouble min; -- cgit v1.2.3 From 43a821aaa9b8749b9c373925c8334efa77d9c34e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 Nov 2015 02:20:30 +0100 Subject: max_smooth_angle working, now deleted after because dont think a good improvement in realtion of UX complication (bzr r14422.3.11) --- src/live_effects/lpe-roughen.cpp | 224 ++++++++++++++++++++------------------- 1 file changed, 117 insertions(+), 107 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 0d0debd24..5253c0b85 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -120,7 +120,7 @@ sp_get_better_default_size(SPItem *item, double &value) c = shape->getCurve(); } if (c) { - value += Geom::length(paths_to_pw(c->get_pathvector()))/(c->get_segment_count () * 3); + value += Geom::length(paths_to_pw(c->get_pathvector()))/(c->get_segment_count () * 6); } } } @@ -240,10 +240,11 @@ Geom::Point LPERoughen::randomize(double max_lenght, bool is_node) Geom::Point LPERoughen::randomize(double lenght, Geom::Point start, Geom::Point end) { - int angle = 0; + double angle = 0; if((int)max_smooth_angle != 0){ angle = sign(Geom::deg_to_rad(rand() % (int)max_smooth_angle)); } + std::cout << angle << "anggggle\n"; Geom::Ray ray(start, end); if(!fixed_displacement ){ lenght = Geom::distance(start, end); @@ -283,10 +284,11 @@ void LPERoughen::doEffect(SPCurve *curve) Geom::CubicBezier const *cubic = NULL; cubic = dynamic_cast(&*curve_it1); if (cubic) { - nCurve->curveto((*cubic)[1], (*cubic)[2], curve_it1->finalPoint()); + nCurve->curveto((*cubic)[1] + last_move, (*cubic)[2], curve_it1->finalPoint()); } else { nCurve->lineto(curve_it1->finalPoint()); } + last_move = Geom::Point(0, 0); double length = curve_it1->length(0.001); std::size_t splits = 0; if (method == DM_SEGMENTS) { @@ -396,7 +398,68 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point point_b2 = point_b3; } } - if(handles == HM_RETRACT){ + if(handles == HM_SMOOTH){ + if(cubic) { + 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 = seg2[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); + if(prev == Geom::Point(0,0)){ + point_a1 = randomize(max_lenght); + } + if(last){ + Geom::Path b2(point_b3); + b2.appendNew(point_a3); + double dist = Geom::distance(b2.pointAt(1.0/3.0), point_b3); + ray.setPoints(point_b3, b2.pointAt(1.0/3.0)); + point_b2 = point_b3 + Geom::Point::polar(ray.angle(), dist); + point_b2 = randomize(max_lenght, point_b3, point_b2); + } + ray.setPoints(point_b1, point_a3); + point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); + if(last){ + prev = point_b2; + } else { + prev = point_a2; + } + out->moveto(seg1[0]); + out->curveto(point_a1,point_a2,point_a3); + out->curveto(point_b1, point_b2, point_b3); + } else { + 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 = randomize(max_lenght); + } + if(last){ + Geom::Path b2(point_b3); + b2.appendNew(point_a3); + double dist = Geom::distance(b2.pointAt(1.0/3.0), point_b3); + ray.setPoints(point_b3, b2.pointAt(1.0/3.0)); + point_b2 = point_b3 + Geom::Point::polar(ray.angle(), dist); + point_b2 = randomize(max_lenght, point_b3, point_b2); + } + ray.setPoints(point_b1, point_a3); + point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); + if(last){ + prev = point_b2; + } else { + prev = point_a2; + } + out->moveto(A->initialPoint()); + out->curveto(point_a1,point_a2,point_a3); + out->curveto(point_b1, point_b2, point_b3); + } + } else if(handles == HM_RETRACT){ out->moveto(A->initialPoint()); out->lineto(A->pointAt(t) + point_a3); if(cubic && !last){ @@ -406,71 +469,12 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point } else { out->lineto(A->finalPoint() + point_b3); } - } else if(handles == HM_SMOOTH && cubic) { - 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 = seg2[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); - if(prev == Geom::Point(0,0)){ - point_a1 = randomize(max_lenght); - } - if(last){ - Geom::Path b2(point_b3); - b2.appendNew(point_a3); - double dist = Geom::distance(b2.pointAt(1.0/3.0), point_b3); - ray.setPoints(point_b3, b2.pointAt(1.0/3.0)); - point_b2 = point_b3 + Geom::Point::polar(ray.angle(), dist); - point_b2 = randomize(max_lenght, point_b3, point_b2); - } - ray.setPoints(point_b1, point_a3); - point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); - if(last){ - prev = point_b2; - } else { - prev = point_a2; - } - out->moveto(seg1[0]); - 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 = A->initialPoint() + Geom::Point::polar(ray.angle(), max_lenght); - if(prev == Geom::Point(0,0)){ - point_a1 = randomize(max_lenght); - } - if(last){ - Geom::Path b2(point_b3); - b2.appendNew(point_a3); - double dist = Geom::distance(b2.pointAt(1.0/3.0), point_b3); - ray.setPoints(point_b3, b2.pointAt(1.0/3.0)); - point_b2 = point_b3 + Geom::Point::polar(ray.angle(), dist); - point_b2 = randomize(max_lenght, point_b3, point_b2); - } - ray.setPoints(point_b1, point_a3); - point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); - if(last){ - prev = point_b2; - } else { - prev = point_a2; - } - out->moveto(A->initialPoint()); - 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(), - seg2 = div.second.controlPoints(); - out->moveto(seg1[0]); - if(handles == HM_ALONG_NODES){ + } else if(handles == HM_ALONG_NODES){ + if (cubic) { + std::pair div = cubic->subdivide(t); + std::vector seg1 = div.first.controlPoints(), + seg2 = div.second.controlPoints(); + out->moveto(seg1[0]); out->curveto(seg1[1] + last_move, seg1[2] + point_a3, seg1[3] + point_a3); last_move = point_a3; if(last){ @@ -478,17 +482,23 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point } out->curveto(seg2[1] + point_a3, seg2[2] + point_b3, seg2[3] + point_b3); } else { + out->moveto(A->initialPoint()); + out->lineto(A->pointAt(t) + point_a3); + out->lineto(A->finalPoint() + point_b3); + } + } else if(handles == HM_RAND) { + if (cubic) { + std::pair div = cubic->subdivide(t); + std::vector seg1 = div.first.controlPoints(), + seg2 = div.second.controlPoints(); + out->moveto(seg1[0]); out->curveto(seg1[1] + point_a1, seg1[2] + point_a2 + point_a3, seg1[3] + point_a3); out->curveto(seg2[1] + point_a3 + point_b1, seg2[2] + point_b2 + point_b3, seg2[3] + point_b3); + } else { + out->moveto(A->initialPoint()); + out->lineto(A->pointAt(t) + point_a3); + out->lineto(A->finalPoint() + point_b3); } - } else if (handles == HM_RAND) { - out->moveto(A->initialPoint()); - out->curveto(A->pointAt(t / 3) + point_a1, A->pointAt((t / 3) * 2) + point_a2 + point_a3, 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 { - out->moveto(A->initialPoint()); - out->lineto(A->pointAt(t) + point_a3); - out->lineto(A->finalPoint() + point_b3); } return out; } @@ -508,46 +518,46 @@ SPCurve *LPERoughen::jitter(Geom::Curve const * A, Geom::Point &prev, Geom::Poin point_a1 = randomize(max_lenght); point_a2 = randomize(max_lenght); } - if(handles == HM_RETRACT){ - out->moveto(A->initialPoint()); - out->lineto(A->finalPoint() + point_a3); - } 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 = A->pointAt(1.0/3.0) + randomize(max_lenght); - } - ray.setPoints((*cubic)[3] + point_a3, (*cubic)[2] + point_a3); - point_a2 = randomize(max_lenght, ray.angle()); - prev = (*cubic)[2] + point_a2; - out->moveto((*cubic)[0]); - out->curveto((*cubic)[0] + point_a1, (*cubic)[2] + point_a2 + point_a3, (*cubic)[3] + point_a3); - } 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 = A->pointAt(1.0/3.0) + randomize(max_lenght); + if(handles == HM_SMOOTH) { + if (cubic) { + Geom::Ray ray(prev,A->initialPoint()); + point_a1 = Geom::Point::polar(ray.angle(), max_lenght); + if(prev == Geom::Point(0,0)){ + point_a1 = A->pointAt(1.0/3.0) + randomize(max_lenght); + } + ray.setPoints((*cubic)[3] + point_a3, (*cubic)[2] + point_a3); + point_a2 = randomize(max_lenght, ray.angle()); + prev = (*cubic)[2] + point_a2; + out->moveto((*cubic)[0]); + out->curveto((*cubic)[0] + point_a1, (*cubic)[2] + point_a2 + point_a3, (*cubic)[3] + point_a3); + } else { + Geom::Ray ray(prev,A->initialPoint()); + point_a1 = Geom::Point::polar(ray.angle(), max_lenght); + if(prev==Geom::Point(0,0)){ + point_a1 = A->pointAt(1.0/3.0) + randomize(max_lenght); + } + ray.setPoints(A->finalPoint() + point_a3, A->pointAt((1.0/3.0) * 2) + point_a3); + point_a2 = randomize(max_lenght, ray.angle()); + prev = A->pointAt((1.0/3.0) * 2) + point_a2 + point_a3; + out->moveto(A->initialPoint()); + out->curveto(A->initialPoint() + point_a1, A->pointAt((1.0/3.0) * 2) + point_a2 + point_a3, A->finalPoint() + point_a3); } - ray.setPoints(A->finalPoint() + point_a3, A->pointAt((1.0/3.0) * 2) + point_a3); - point_a2 = randomize(max_lenght, ray.angle()); - prev = A->pointAt((1.0/3.0) * 2) + point_a2 + point_a3; + } else if(handles == HM_RETRACT){ out->moveto(A->initialPoint()); - out->curveto(A->initialPoint() + point_a1, A->pointAt((1.0/3.0) * 2) + point_a2 + point_a3, A->finalPoint() + point_a3); - } else if (cubic) { - out->moveto((*cubic)[0]); - if(handles == HM_ALONG_NODES){ + out->lineto(A->finalPoint() + point_a3); + } else if (handles == HM_ALONG_NODES) { + if(cubic){ + out->moveto((*cubic)[0]); out->curveto((*cubic)[1] + last_move, (*cubic)[2] + point_a3, (*cubic)[3] + point_a3); last_move = point_a3; } else { - out->curveto((*cubic)[1] + point_a1, (*cubic)[2] + point_a2 + point_a3, (*cubic)[3] + point_a3); + out->moveto(A->initialPoint()); + out->lineto(A->finalPoint() + point_a3); } } else if (handles == HM_RAND) { out->moveto(A->initialPoint()); out->curveto(A->pointAt(0.3333) + point_a1, A->pointAt(0.6666) + point_a2 + point_a3, A->finalPoint() + point_a3); - } else { - out->moveto(A->initialPoint()); - out->lineto(A->finalPoint() + point_a3); } return out; } -- cgit v1.2.3 From 3a2f830fc5c0c0f3901e64277e6871b9615d283b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 Nov 2015 03:47:20 +0100 Subject: End fixing roughen (bzr r14422.3.12) --- src/live_effects/lpe-roughen.cpp | 64 +++++++++++++++++-------------------- src/live_effects/lpe-roughen.h | 2 -- src/live_effects/parameter/random.h | 2 +- 3 files changed, 30 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 5253c0b85..310f791a1 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -60,8 +60,6 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) "global_randomize", &wr, this, 1.), handles(_("Handles"), _("Handles options"), "handles", HMConverter, &wr, this, HM_ALONG_NODES), - max_smooth_angle(_("Max. smooth handle angle"), _("Max. smooth handle angle"), - "max_smooth_angle", &wr, this, 20), shift_nodes(_("Shift nodes"), _("Shift nodes"), "shift_nodes", &wr, this, true), fixed_displacement(_("Fixed displacement"), _("Fixed displacement, 1/3 of segment length"), @@ -76,7 +74,6 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) registerParameter(&displace_y); registerParameter(&global_randomize); registerParameter(&handles); - registerParameter(&max_smooth_angle); registerParameter(&shift_nodes); registerParameter(&fixed_displacement); registerParameter(&spray_tool_friendly); @@ -89,9 +86,6 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) segments.param_set_range(1, Geom::infinity()); segments.param_set_increments(1, 1); segments.param_set_digits(0); - max_smooth_angle.param_set_range(0, 359); - max_smooth_angle.param_set_increments(1, 1); - max_smooth_angle.param_set_digits(0); seed = 0; } @@ -131,8 +125,8 @@ void LPERoughen::doOnApply(SPLPEItem const* lpeitem) SPLPEItem * splpeitem = const_cast(lpeitem); double initial = 0; sp_get_better_default_size(SP_ITEM(splpeitem), initial); - displace_x.param_set_value(initial, displace_x.defseed); - displace_y.param_set_value(initial, displace_y.defseed); + displace_x.param_set_value(initial, 0); + displace_y.param_set_value(initial, 0); } void LPERoughen::doBeforeEffect(SPLPEItem const *lpeitem) @@ -238,20 +232,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) -{ - double angle = 0; - if((int)max_smooth_angle != 0){ - angle = sign(Geom::deg_to_rad(rand() % (int)max_smooth_angle)); - } - std::cout << angle << "anggggle\n"; - Geom::Ray ray(start, end); - if(!fixed_displacement ){ - lenght = Geom::distance(start, end); - } - return Geom::Point::polar(ray.angle() + angle , lenght) + start; -} - void LPERoughen::doEffect(SPCurve *curve) { Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(curve->get_pathvector()); @@ -403,11 +383,16 @@ 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); + Geom::Ray ray(seg1[3] + point_a3, seg2[1] + point_a3); + double lenght = max_lenght; + if(!fixed_displacement ){ + lenght = Geom::distance(seg1[3] + point_a3, seg2[1] + point_a3); + } + point_b1 = seg1[3] + point_a3 + Geom::Point::polar(ray.angle() , lenght); point_b2 = seg2[2]; point_b3 = seg2[3] + point_b3; point_a3 = seg1[3] + point_a3; - Geom::Ray ray(prev,A->initialPoint()); + ray.setPoints(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); @@ -415,10 +400,12 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point if(last){ Geom::Path b2(point_b3); b2.appendNew(point_a3); - double dist = Geom::distance(b2.pointAt(1.0/3.0), point_b3); - ray.setPoints(point_b3, b2.pointAt(1.0/3.0)); - point_b2 = point_b3 + Geom::Point::polar(ray.angle(), dist); - point_b2 = randomize(max_lenght, point_b3, point_b2); + lenght = max_lenght; + ray.setPoints(point_b3, point_b2); + if(!fixed_displacement ){ + lenght = Geom::distance(b2.pointAt(1.0/3.0), point_b3); + } + point_b2 = point_b3 + Geom::Point::polar(ray.angle() , lenght); } ray.setPoints(point_b1, point_a3); point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); @@ -431,11 +418,16 @@ 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 { - point_b1 = randomize(max_lenght, A->pointAt(t) + point_a3, A->pointAt(t + (t / 3))); + Geom::Ray ray(A->pointAt(t) + point_a3, A->pointAt(t + (t / 3))); + double lenght = max_lenght; + if(!fixed_displacement ){ + lenght = Geom::distance(A->pointAt(t) + point_a3, A->pointAt(t + (t / 3))); + } + point_b1 = A->pointAt(t) + point_a3 + Geom::Point::polar(ray.angle() , lenght); 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()); + ray.setPoints(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); @@ -443,10 +435,12 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point if(last){ Geom::Path b2(point_b3); b2.appendNew(point_a3); - double dist = Geom::distance(b2.pointAt(1.0/3.0), point_b3); - ray.setPoints(point_b3, b2.pointAt(1.0/3.0)); - point_b2 = point_b3 + Geom::Point::polar(ray.angle(), dist); - point_b2 = randomize(max_lenght, point_b3, point_b2); + lenght = max_lenght; + ray.setPoints(point_b3, point_b2); + if(!fixed_displacement ){ + lenght = Geom::distance(b2.pointAt(1.0/3.0), point_b3); + } + point_b2 = point_b3 + Geom::Point::polar(ray.angle() , lenght); } ray.setPoints(point_b1, point_a3); point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); @@ -512,7 +506,7 @@ SPCurve *LPERoughen::jitter(Geom::Curve const * A, Geom::Point &prev, Geom::Poin Geom::Point point_a2(0, 0); Geom::Point point_a3(0, 0); if (shift_nodes) { - point_a3 = randomize(max_lenght); + point_a3 = randomize(max_lenght, true); } if (handles == HM_RAND || handles == HM_SMOOTH) { point_a1 = randomize(max_lenght); diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index b12bd08af..7e6a19d5a 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -47,7 +47,6 @@ public: virtual double sign(double randNumber); virtual void doOnApply(SPLPEItem const* lpeitem); 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); @@ -62,7 +61,6 @@ private: RandomParam displace_y; RandomParam global_randomize; EnumParam handles; - ScalarParam max_smooth_angle; BoolParam shift_nodes; BoolParam fixed_displacement; BoolParam spray_tool_friendly; diff --git a/src/live_effects/parameter/random.h b/src/live_effects/parameter/random.h index 52e3cc0a6..ca4440336 100644 --- a/src/live_effects/parameter/random.h +++ b/src/live_effects/parameter/random.h @@ -43,11 +43,11 @@ public: operator gdouble(); inline gdouble get_value() { return value; } ; - long defseed; protected: long startseed; long seed; + long defseed; gdouble value; gdouble min; -- cgit v1.2.3 From 9ccc911c0f27339694b7210d7f6829b528e96fe2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 Nov 2015 03:57:03 +0100 Subject: Fix a typo (bzr r14422.3.14) --- src/widgets/spray-toolbar.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') 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 -- cgit v1.2.3