diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-10-19 10:50:48 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2016-10-19 10:50:48 +0000 |
| commit | a3d1d9d574192d268ed4d120ff30b7f8ebbc01fa (patch) | |
| tree | a239da7d25f738496be1919704f51a7cd6dafe32 /src/ui/tools/mesh-tool.cpp | |
| parent | Working with rotate preview (diff) | |
| parent | update author list in about dialog from AUTHORS file (diff) | |
| download | inkscape-a3d1d9d574192d268ed4d120ff30b7f8ebbc01fa.tar.gz inkscape-a3d1d9d574192d268ed4d120ff30b7f8ebbc01fa.zip | |
Update to trunk
(bzr r15142.1.16)
Diffstat (limited to 'src/ui/tools/mesh-tool.cpp')
| -rw-r--r-- | src/ui/tools/mesh-tool.cpp | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index 33cdc3bda..c6983b94a 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -52,6 +52,7 @@ #include "ui/tools/mesh-tool.h" #include "sp-mesh-gradient.h" #include "display/sp-ctrlcurve.h" +#include "display/curve.h" using Inkscape::DocumentUndo; @@ -431,6 +432,71 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation ) /** + * Scale mesh to just fit into bbox of selected items. + */ +void +sp_mesh_context_fit_mesh_in_bbox (MeshTool *rc) +{ + +#ifdef DEBUG_MESH + std::cout << "sp_mesh_context_fit_mesh_in_bbox: entrance: Entrance"<< std::endl; +#endif + + SPDesktop *desktop = SP_EVENT_CONTEXT (rc)->desktop; + + Inkscape::Selection *selection = desktop->getSelection(); + if (selection == NULL) { + return; + } + + bool changed = false; + auto itemlist = selection->items(); + for (auto i=itemlist.begin(); i!=itemlist.end(); ++i) { + + SPItem *item = *i; + SPStyle *style = item->style; + + if (style && (style->fill.isPaintserver())) { + SPPaintServer *server = item->style->getFillPaintServer(); + if ( SP_IS_MESHGRADIENT(server) ) { + + SPMeshGradient *gradient = SP_MESHGRADIENT(server); + SPCurve * outline = gradient->array.outline_path(); + Geom::OptRect mesh_bbox = outline->get_pathvector().boundsExact(); + outline->unref(); + Geom::OptRect item_bbox = item->geometricBounds(); + + if ((*mesh_bbox).width() == 0) { + continue; + } + if ((*mesh_bbox).height() == 0) { + continue; + } + double scale_x = (*item_bbox).width() /(*mesh_bbox).width() ; + double scale_y = (*item_bbox).height()/(*mesh_bbox).height(); + + Geom::Translate t1(-(*mesh_bbox).min()); + Geom::Scale scale(scale_x,scale_y); + Geom::Translate t2((*item_bbox).min()); + Geom::Affine transform = t1 * scale * t2; + if (!transform.isIdentity() ) { + gradient->array.transform(transform); + gradient->array.write( gradient ); + gradient->requestModified(SP_OBJECT_MODIFIED_FLAG); + changed = true; + } + } + } + + } + if (changed) { + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MESH, + _("Fit mesh inside bounding box.")); + } +} + + +/** Handles all keyboard and mouse input for meshs. Note: node/handle events are take care of elsewhere. */ @@ -970,7 +1036,8 @@ static void sp_mesh_new_default(MeshTool &rc) { // Get corresponding object SPMeshGradient *mg = static_cast<SPMeshGradient *>(document->getObjectByRepr(repr)); - mg->array.create(mg, *i, (*i)->visualBounds()); + mg->array.create(mg, *i, (fill_or_stroke == Inkscape::FOR_FILL) ? + (*i)->geometricBounds() : (*i)->visualBounds()); bool isText = SP_IS_TEXT(*i); sp_style_set_property_url (*i, ((fill_or_stroke == Inkscape::FOR_FILL) ? "fill":"stroke"), @@ -979,6 +1046,11 @@ static void sp_mesh_new_default(MeshTool &rc) { (*i)->requestModified(SP_OBJECT_MODIFIED_FLAG|SP_OBJECT_STYLE_MODIFIED_FLAG); } + if (css) { + sp_repr_css_attr_unref(css); + css = 0; + } + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MESH, _("Create mesh")); // status text; we do not track coords because this branch is run once, not all the time |
