summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-08-12 13:53:02 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-08-12 13:53:02 +0000
commit5cd1e00f9821f653dbc354ecb8a7c0e94bfc29c6 (patch)
tree5af16c6e2ae39acc3996354eb470ffbd2684d644 /src
parentshortcuts: comp function should take values of input variables (attempt to fi... (diff)
downloadinkscape-5cd1e00f9821f653dbc354ecb8a7c0e94bfc29c6.tar.gz
inkscape-5cd1e00f9821f653dbc354ecb8a7c0e94bfc29c6.zip
Add flatten button to simplify, bspline and spiro. Need to rerun cmake because file changed
Diffstat (limited to 'src')
-rw-r--r--src/widgets/pencil-toolbar.cpp80
1 files changed, 75 insertions, 5 deletions
diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp
index 918a54991..b15cc5b30 100644
--- a/src/widgets/pencil-toolbar.cpp
+++ b/src/widgets/pencil-toolbar.cpp
@@ -48,6 +48,8 @@
#include "display/curve.h"
#include "live_effects/lpe-simplify.h"
#include "live_effects/lpe-powerstroke.h"
+#include "live_effects/lpe-bspline.h"
+#include "live_effects/lpe-spiro.h"
#include "live_effects/lpeobject.h"
#include "live_effects/lpeobject-reference.h"
@@ -58,7 +60,7 @@ using Inkscape::UI::PrefPusher;
//########################
//## Pen/Pencil ##
//########################
-
+static void sp_flatten_spiro_bspline(GtkWidget * /*widget*/, GObject *obj);
/* This is used in generic functions below to share large portions of code between pen and pencil tool */
static Glib::ustring const freehand_tool_name(GObject *dataKludge)
{
@@ -74,7 +76,6 @@ static void freehand_mode_changed(EgeSelectOneAction* act, GObject* tbl)
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setInt(freehand_tool_name(tbl) + "/freehand-mode", mode);
-
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(tbl, "desktop"));
// in pen tool we have more options than in pencil tool; if one of them was chosen, we do any
@@ -83,6 +84,11 @@ static void freehand_mode_changed(EgeSelectOneAction* act, GObject* tbl)
Inkscape::UI::Tools::PenTool *pc = SP_PEN_CONTEXT(desktop->event_context);
pc->setPolylineMode();
}
+ if (mode == 1 || mode == 2) {
+ gtk_action_set_visible( GTK_ACTION( g_object_get_data(tbl, "flatten_spiro_bspline") ), true );
+ } else {
+ gtk_action_set_visible( GTK_ACTION( g_object_get_data(tbl, "flatten_spiro_bspline") ), false );
+ }
}
static void sp_add_freehand_mode_toggle(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil)
@@ -131,7 +137,7 @@ static void sp_add_freehand_mode_toggle(GtkActionGroup* mainActions, GObject* ho
2, INKSCAPE_ICON("path-mode-polyline-paraxial"),
-1 );
}
-
+
EgeSelectOneAction* act = ege_select_one_action_new(tool_is_pencil ?
"FreehandModeActionPencil" :
"FreehandModeActionPen",
@@ -148,6 +154,21 @@ static void sp_add_freehand_mode_toggle(GtkActionGroup* mainActions, GObject* ho
ege_select_one_action_set_active( act, freehandMode);
g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(freehand_mode_changed), holder);
}
+ /* LPE bspline spiro flatten */
+ InkAction* inky = ink_action_new( tool_is_pencil ? "FlattenSpiroBsplinePencil" :
+ "FlattenSpiroBsplinePen",
+ _("LPE spiro or bspline flatten"),
+ _("LPE spiro or bspline flatten"),
+ INKSCAPE_ICON("flatten"),
+ GTK_ICON_SIZE_SMALL_TOOLBAR );
+ g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_flatten_spiro_bspline), holder );
+ gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
+ g_object_set_data( holder, "flatten_spiro_bspline", inky );
+ if (freehandMode == 1 || freehandMode == 2) {
+ gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "flatten_spiro_bspline") ), true );
+ } else {
+ gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "flatten_spiro_bspline") ), false );
+ }
}
}
@@ -162,6 +183,11 @@ static void freehand_simplify_lpe(InkToggleAction* itact, GObject *dataKludge) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setInt(freehand_tool_name(dataKludge) + "/simplify", simplify);
gtk_action_set_visible( GTK_ACTION( g_object_get_data(dataKludge, "flatten_simplify") ), simplify );
+ if (simplify) {
+ gtk_action_set_visible( GTK_ACTION( g_object_get_data(dataKludge, "flatten_simplify") ), true );
+ } else {
+ gtk_action_set_visible( GTK_ACTION( g_object_get_data(dataKludge, "flatten_simplify") ), false );
+ }
}
/**
@@ -234,6 +260,49 @@ static void sp_pencil_tb_defaults(GtkWidget * /*widget*/, GObject *obj)
spinbutton_defocus(tbl);
}
+static void sp_flatten_spiro_bspline(GtkWidget * /*widget*/, GObject *obj)
+{
+ SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(obj, "desktop"));
+ auto selected = desktop->getSelection()->items();
+ SPLPEItem* lpeitem = NULL;
+ for (auto it(selected.begin()); it != selected.end(); ++it){
+ lpeitem = dynamic_cast<SPLPEItem*>(*it);
+ if (lpeitem && lpeitem->hasPathEffect()){
+ PathEffectList lpelist = lpeitem->getEffectList();
+ PathEffectList::iterator i;
+ for (i = lpelist.begin(); i != lpelist.end(); ++i) {
+ LivePathEffectObject *lpeobj = (*i)->lpeobject;
+ if (lpeobj) {
+ Inkscape::LivePathEffect::Effect *lpe = lpeobj->get_lpe();
+ if (dynamic_cast<Inkscape::LivePathEffect::LPEBSpline *>(lpe) ||
+ dynamic_cast<Inkscape::LivePathEffect::LPESpiro *>(lpe))
+ {
+ SPShape * shape = dynamic_cast<SPShape *>(lpeitem);
+ if(shape){
+ SPCurve * c = shape->getCurveBeforeLPE();
+ lpe->doEffect(c);
+ lpeitem->setCurrentPathEffect(*i);
+ if (lpelist.size() > 1){
+ lpeitem->removeCurrentPathEffect(true);
+ shape->setCurveBeforeLPE(c);
+ } else {
+ lpeitem->removeCurrentPathEffect(false);
+ shape->setCurve(c,0);
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ if (lpeitem) {
+ desktop->getSelection()->remove(lpeitem->getRepr());
+ desktop->getSelection()->add(lpeitem->getRepr());
+ sp_lpe_item_update_patheffect(lpeitem, false, false);
+ }
+}
+
static void sp_simplify_flatten(GtkWidget * /*widget*/, GObject *obj)
{
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(obj, "desktop"));
@@ -271,6 +340,7 @@ static void sp_simplify_flatten(GtkWidget * /*widget*/, GObject *obj)
if (lpeitem) {
desktop->getSelection()->remove(lpeitem->getRepr());
desktop->getSelection()->add(lpeitem->getRepr());
+ sp_lpe_item_update_patheffect(lpeitem, false, false);
}
}
@@ -419,13 +489,13 @@ void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
InkAction* inky = ink_action_new( "PencilLpeSimplifyFlatten",
_("LPE simplify flatten"),
_("LPE simplify flatten"),
- INKSCAPE_ICON("flatten_simplify"),
+ INKSCAPE_ICON("flatten"),
GTK_ICON_SIZE_SMALL_TOOLBAR );
g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_simplify_flatten), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
g_object_set_data( holder, "flatten_simplify", inky );
if (!prefs->getInt("/tools/freehand/pencil/simplify", 0)) {
- gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "flatten_simplify") ), false );
+ gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "flatten_simplify") ), true );
}
}