summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2016-12-01 13:05:02 +0000
committertavmjong-free <tavmjong@free.fr>2016-12-01 13:05:02 +0000
commitd87cfa4971963dfb8118ce31e169854fce85bccd (patch)
tree498675c4078133897637abd22fc3354a985a907f
parentFix bug with mesh handle update when corner moved via keys. (diff)
downloadinkscape-d87cfa4971963dfb8118ce31e169854fce85bccd.tar.gz
inkscape-d87cfa4971963dfb8118ce31e169854fce85bccd.zip
Add toggles for handle visibility, editing fill, and editing stroke.
(bzr r15289)
-rw-r--r--src/gradient-drag.cpp41
-rw-r--r--src/ui/tools/mesh-tool.cpp21
-rw-r--r--src/ui/tools/mesh-tool.h27
-rw-r--r--src/widgets/mesh-toolbar.cpp25
-rw-r--r--src/widgets/toolbox.cpp4
5 files changed, 92 insertions, 26 deletions
diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp
index ad6ace703..752e408f8 100644
--- a/src/gradient-drag.cpp
+++ b/src/gradient-drag.cpp
@@ -1992,15 +1992,10 @@ void GrDrag::addDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::PaintTa
// Show/hide mesh on fill/stroke. This doesn't work at the moment... and prevents node color updating.
- //Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- bool edit_fill = true; //abs(prefs->getBool("/tools/mesh/edit_fill", true));
- bool edit_stroke = true; //abs(prefs->getBool("/tools/mesh/edit_stroke", true));
- bool show_handles = true; //abs(prefs->getBool("/tools/mesh/show_handles", true));
-
- if( (fill_or_stroke == Inkscape::FOR_FILL && !edit_fill) ||
- (fill_or_stroke == Inkscape::FOR_STROKE && !edit_stroke) ) {
- return;
- }
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ bool show_handles = abs(prefs->getBool("/tools/mesh/show_handles", true));
+ bool edit_fill = abs(prefs->getBool("/tools/mesh/edit_fill", true));
+ bool edit_stroke = abs(prefs->getBool("/tools/mesh/edit_stroke", true));
// Make sure we have at least one patch defined.
if( mg->array.patch_rows() == 0 || mg->array.patch_columns() == 0 ) {
@@ -2016,6 +2011,10 @@ void GrDrag::addDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::PaintTa
mg->array.handles.clear();
mg->array.tensors.clear();
+ if( (fill_or_stroke == Inkscape::FOR_FILL && !edit_fill) ||
+ (fill_or_stroke == Inkscape::FOR_STROKE && !edit_stroke) ) {
+ return;
+ }
for( guint i = 0; i < nodes.size(); ++i ) {
for( guint j = 0; j < nodes[i].size(); ++j ) {
@@ -2052,7 +2051,7 @@ void GrDrag::addDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::PaintTa
mg->array.tensors.push_back( nodes[i][j] );
GrDraggable *tensor = new GrDraggable (item, POINT_MG_TENSOR, itensor, fill_or_stroke);
GrDragger* dragger = addDragger ( tensor );
- if( show_handles || !nodes[i][j]->set ) {
+ if( !show_handles || !nodes[i][j]->set ) {
dragger->knot->hide();
}
nodes[i][j]->draggable = itensor;
@@ -2079,7 +2078,8 @@ void GrDrag::refreshDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::Pai
mg->ensureArray();
std::vector< std::vector< SPMeshNode* > > nodes = mg->array.nodes;
- bool show_handles = true; //abs(prefs->getBool("/tools/mesh/show_handles", true));
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ bool show_handles = abs(prefs->getBool("/tools/mesh/show_handles", true));
// Make sure we have at least one patch defined.
if( mg->array.patch_rows() == 0 || mg->array.patch_columns() == 0 ) {
@@ -2114,7 +2114,8 @@ void GrDrag::refreshDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::Pai
dragger->knot->show();
}
} else {
- std::cerr << "GrDrag::refreshDraggersMesh: No dragger!" << std::endl;
+ // This can happen if a draggable is not visible.
+ // std::cerr << "GrDrag::refreshDraggersMesh: No dragger!" << std::endl;
}
++ihandle;
break;
@@ -2132,7 +2133,8 @@ void GrDrag::refreshDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::Pai
dragger->knot->show();
}
} else {
- std::cerr << "GrDrag::refreshDraggersMesh: No dragger!" << std::endl;
+ // This can happen if a draggable is not visible.
+ // std::cerr << "GrDrag::refreshDraggersMesh: No dragger!" << std::endl;
}
++itensor;
break;
@@ -2306,8 +2308,12 @@ void GrDrag::updateLines()
addLine(item, center, getGradientCoords(item, POINT_RG_R2, 0, Inkscape::FOR_FILL), Inkscape::FOR_FILL);
} else if ( SP_IS_MESHGRADIENT(server) ) {
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ bool edit_fill = abs(prefs->getBool("/tools/mesh/edit_fill", true));
+
SPMeshGradient *mg = SP_MESHGRADIENT(server);
+ if (edit_fill) {
guint rows = mg->array.patch_rows();
guint columns = mg->array.patch_columns();
for ( guint i = 0; i < rows; ++i ) {
@@ -2356,6 +2362,7 @@ void GrDrag::updateLines()
addCurve (item, h[0], h[1], h[2], h[3], corner3, corner0, Inkscape::FOR_FILL );
}
}
+ }
}
}
}
@@ -2374,6 +2381,11 @@ void GrDrag::updateLines()
addLine(item, center, getGradientCoords(item, POINT_RG_R2, 0, Inkscape::FOR_STROKE), Inkscape::FOR_STROKE);
} else if ( SP_IS_MESHGRADIENT(server) ) {
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ bool edit_stroke = abs(prefs->getBool("/tools/mesh/edit_stroke", true));
+
+ if (edit_stroke) {
+
// MESH FIXME: TURN ROUTINE INTO FUNCTION AND CALL FOR BOTH FILL AND STROKE.
SPMeshGradient *mg = SP_MESHGRADIENT(server);
@@ -2424,7 +2436,8 @@ void GrDrag::updateLines()
}
addCurve (item, h[0], h[1], h[2], h[3], corner3, corner0, Inkscape::FOR_STROKE );
}
- }
+ }
+ }
}
}
}
diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp
index 61232fb2c..b05caf43a 100644
--- a/src/ui/tools/mesh-tool.cpp
+++ b/src/ui/tools/mesh-tool.cpp
@@ -75,6 +75,9 @@ MeshTool::MeshTool()
: ToolBase(cursor_gradient_xpm, 4, 4)
, cursor_addnode(false)
, node_added(false)
+ , show_handles(true)
+ , edit_fill(true)
+ , edit_stroke(true)
// TODO: Why are these connections stored as pointers?
, selcon(NULL)
, subselcon(NULL)
@@ -253,7 +256,25 @@ void MeshTool::setup() {
)
));
+ sp_event_context_read(this, "show_handles");
+ sp_event_context_read(this, "edit_fill");
+ sp_event_context_read(this, "edit_stroke");
+
this->selection_changed(selection);
+
+}
+
+void MeshTool::set(const Inkscape::Preferences::Entry& value) {
+ Glib::ustring entry_name = value.getEntryName();
+ if (entry_name == "show_handles") {
+ this->show_handles = value.getBool(true);
+ } else if (entry_name == "edit_fill") {
+ this->edit_fill = value.getBool(true);
+ } else if (entry_name == "edit_stroke") {
+ this->edit_stroke = value.getBool(true);
+ } else {
+ ToolBase::set(value);
+ }
}
void
diff --git a/src/ui/tools/mesh-tool.h b/src/ui/tools/mesh-tool.h
index f142bfd9c..1f012dc53 100644
--- a/src/ui/tools/mesh-tool.h
+++ b/src/ui/tools/mesh-tool.h
@@ -31,29 +31,34 @@ namespace Tools {
class MeshTool : public ToolBase {
public:
- MeshTool();
- virtual ~MeshTool();
+ MeshTool();
+ virtual ~MeshTool();
Geom::Point origin;
- bool cursor_addnode;
-
- bool node_added;
-
Geom::Point mousepoint_doc; // stores mousepoint when over_line in doc coords
sigc::connection *selcon;
sigc::connection *subselcon;
- static const std::string prefsPath;
+ static const std::string prefsPath;
- virtual void setup();
- virtual bool root_handler(GdkEvent* event);
+ virtual void setup();
+ virtual void set(const Inkscape::Preferences::Entry& val);
+ virtual bool root_handler(GdkEvent* event);
- virtual const std::string& getPrefsPath();
+ virtual const std::string& getPrefsPath();
private:
- void selection_changed(Inkscape::Selection* sel);
+ void selection_changed(Inkscape::Selection* sel);
+
+ bool cursor_addnode;
+ bool node_added;
+ bool show_handles;
+ bool edit_fill;
+ bool edit_stroke;
+
+
};
void sp_mesh_context_select_next(ToolBase *event_context);
diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp
index a960782cb..f7b7a6ec9 100644
--- a/src/widgets/mesh-toolbar.cpp
+++ b/src/widgets/mesh-toolbar.cpp
@@ -357,6 +357,26 @@ static void ms_fit_mesh(void)
}
}
+static void ms_toggle_handles(void)
+{
+ MeshTool *mt = get_mesh_tool();
+ if (mt) {
+ GrDrag *drag = mt->_grdrag;
+ drag->refreshDraggers();
+ }
+}
+
+static void ms_toggle_fill_stroke(void)
+{
+ MeshTool *mt = get_mesh_tool();
+ if (mt) {
+ GrDrag *drag = mt->_grdrag;
+ drag->updateDraggers();
+ drag->updateLines();
+ drag->updateLevels();
+ }
+}
+
static void ms_warning_popup(void)
{
char *msg = _("Mesh gradients are part of SVG 2:\n"
@@ -487,6 +507,7 @@ void sp_mesh_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObj
gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/mesh/edit_fill");
g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher);
+ g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(ms_toggle_fill_stroke), 0);
}
/* Edit stroke mesh */
@@ -499,18 +520,20 @@ void sp_mesh_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObj
gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/mesh/edit_stroke");
g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher);
+ g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(ms_toggle_fill_stroke), 0);
}
/* Show/hide side and tensor handles */
{
InkToggleAction* act = ink_toggle_action_new( "MeshShowHandlesAction",
_("Show Handles"),
- _("Show side and tensor handles"),
+ _("Show handles"),
INKSCAPE_ICON("show-node-handles"),
secondarySize );
gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/mesh/show_handles");
g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher);
+ g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(ms_toggle_handles), 0);
}
g_object_set_data(holder, "desktop", desktop);
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index ea9af71c8..53de2d342 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -574,6 +574,10 @@ static gchar const * ui_descr =
" <toolitem action='MeshPickColorsAction' />"
" <toolitem action='MeshFitInBoundingBoxAction' />"
" <separator />"
+ " <toolitem action='MeshShowHandlesAction' />"
+ " <toolitem action='MeshEditFillAction' />"
+ " <toolitem action='MeshEditStrokeAction' />"
+ " <separator />"
" <toolitem action='MeshWarningAction' />"
" <separator />"
" <toolitem action='MeshSmoothAction' />"