index f9f60fd775d0c573be08d4852b1a9a4b38f39cbb..07b388d140127087fdd2283e75babdc92a200168 100644 (file)
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
#include "connector-context.h"
#include "node-context.h"
-#include "draw-context.h"
+#include "pen-context.h"
#include "shape-editor.h"
#include "tweak-context.h"
#include "sp-rect.h"
} else {
gtk_action_set_sensitive(xact, TRUE);
gtk_action_set_sensitive(yact, TRUE);
- NR::Coord oldx = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit);
- NR::Coord oldy = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit);
+ Geom::Coord oldx = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit);
+ Geom::Coord oldy = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit);
if (n_selected == 1) {
- NR::Point sel_node = nodepath->singleSelectedCoords();
- if (oldx != sel_node[NR::X] || oldy != sel_node[NR::Y]) {
- gtk_adjustment_set_value(xadj, sp_pixels_get_units(sel_node[NR::X], *unit));
- gtk_adjustment_set_value(yadj, sp_pixels_get_units(sel_node[NR::Y], *unit));
+ Geom::Point sel_node = nodepath->singleSelectedCoords();
+ if (oldx != sel_node[Geom::X] || oldy != sel_node[Geom::Y]) {
+ gtk_adjustment_set_value(xadj, sp_pixels_get_units(sel_node[Geom::X], *unit));
+ gtk_adjustment_set_value(yadj, sp_pixels_get_units(sel_node[Geom::Y], *unit));
}
} else {
- NR::Maybe<NR::Coord> x = sp_node_selected_common_coord(nodepath, NR::X);
- NR::Maybe<NR::Coord> y = sp_node_selected_common_coord(nodepath, NR::Y);
+ boost::optional<Geom::Coord> x = sp_node_selected_common_coord(nodepath, Geom::X);
+ boost::optional<Geom::Coord> y = sp_node_selected_common_coord(nodepath, Geom::Y);
if ((x && ((*x) != oldx)) || (y && ((*y) != oldy))) {
/* Note: Currently x and y will always have a value, even if the coordinates of the
selected nodes don't coincide (in this case we use the coordinates of the center
@@ -1153,10 +1153,10 @@ sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_
if (shape_editor && shape_editor->has_nodepath()) {
double val = sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit);
if (!strcmp(value_name, "x")) {
- sp_node_selected_move_absolute(shape_editor->get_nodepath(), val, NR::X);
+ sp_node_selected_move_absolute(shape_editor->get_nodepath(), val, Geom::X);
}
if (!strcmp(value_name, "y")) {
- sp_node_selected_move_absolute(shape_editor->get_nodepath(), val, NR::Y);
+ sp_node_selected_move_absolute(shape_editor->get_nodepath(), val, Geom::Y);
}
}
@@ -3265,9 +3265,10 @@ static void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActio
}
//########################
-//## Pen/Pencil ##
+//## Pen/Pencil ##
//########################
+/* This is used in generic functions below to share large portions of code between pen and pencil tool */
static char const *
freehand_tool_name(GObject *dataKludge)
{
: "tools.freehand.pencil" );
}
-static void sp_pc_spiro_spline_mode_changed(EgeSelectOneAction* act, GObject* tbl)
+static void freehand_mode_changed(EgeSelectOneAction* act, GObject* tbl)
{
- prefs_set_int_attribute(freehand_tool_name(tbl), "spiro-spline-mode", ege_select_one_action_get_active(act));
+ gint mode = ege_select_one_action_get_active(act);
+
+ prefs_set_int_attribute(freehand_tool_name(tbl), "freehand-mode", mode);
+
+ SPDesktop *desktop = (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
+ // preparatory work here
+ if (SP_IS_PEN_CONTEXT(desktop->event_context)) {
+ SPPenContext *pc = SP_PEN_CONTEXT(desktop->event_context);
+ pc->polylines_only = (mode == 2);
+ }
}
-static void sp_add_spiro_toggle(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil)
+static void sp_add_freehand_mode_toggle(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil)
{
/* Freehand mode toggle buttons */
{
- // FIXME: spiroMode seems not to be read correctly here during startup, although the
- // correct mode is used in pen/pencil tool later on; same for freehand shapes
- guint spiroMode = prefs_get_int_attribute(freehand_tool_name(holder), "spiro-spline-mode", 0);
+ guint freehandMode = prefs_get_int_attribute(tool_is_pencil ? "tools.freehand.pencil" : "tools.freehand.pen", "freehand-mode", 0);
Inkscape::IconSize secondarySize = prefToSize("toolbox", "secondary", 1);
{
@@ -3309,6 +3319,15 @@ static void sp_add_spiro_toggle(GtkActionGroup* mainActions, GObject* holder, bo
2, "spiro_splines_mode",
-1 );
+ if (!tool_is_pencil) {
+ gtk_list_store_append( model, &iter );
+ gtk_list_store_set( model, &iter,
+ 0, _("Zigzag"),
+ 1, _("Create a sequence of straight line segments"),
+ 2, "polylines_mode",
+ -1 );
+ }
+
EgeSelectOneAction* act = ege_select_one_action_new(tool_is_pencil ?
"FreehandModeActionPencil" :
"FreehandModeActionPen",
@@ -3322,13 +3341,13 @@ static void sp_add_spiro_toggle(GtkActionGroup* mainActions, GObject* holder, bo
ege_select_one_action_set_icon_size( act, secondarySize );
ege_select_one_action_set_tooltip_column( act, 1 );
- ege_select_one_action_set_active( act, spiroMode);
- g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_pc_spiro_spline_mode_changed), holder);
+ ege_select_one_action_set_active( act, freehandMode);
+ g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(freehand_mode_changed), holder);
}
}
}
-static void sp_freehand_change_shape(EgeSelectOneAction* act, GObject *dataKludge) {
+static void freehand_change_shape(EgeSelectOneAction* act, GObject *dataKludge) {
gint shape = ege_select_one_action_get_active( act );
prefs_set_int_attribute(freehand_tool_name(dataKludge), "shape", shape);
}
}
static void
-sp_freehand_add_advanced_shape_options(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil) {
+freehand_add_advanced_shape_options(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil) {
/*advanced shape options */
{
GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
@@ -3370,8 +3389,8 @@ sp_freehand_add_advanced_shape_options(GtkActionGroup* mainActions, GObject* hol
_("Shape:"), ("Shape"), NULL, GTK_TREE_MODEL(model));
g_object_set( act1, "short_label", _("Shape:"), NULL );
ege_select_one_action_set_appearance( act1, "compact" );
- ege_select_one_action_set_active( act1, prefs_get_int_attribute(freehand_tool_name(holder), "shape", 0) );
- g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK(sp_freehand_change_shape), holder );
+ ege_select_one_action_set_active( act1, prefs_get_int_attribute(tool_is_pencil ? "tools.freehand.pencil" : "tools.freehand.pen", "shape", 0) );
+ g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK(freehand_change_shape), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(act1) );
g_object_set_data( holder, "shape_action", act1 );
}
@@ -3379,8 +3398,8 @@ sp_freehand_add_advanced_shape_options(GtkActionGroup* mainActions, GObject* hol
static void sp_pen_toolbox_prep(SPDesktop */*desktop*/, GtkActionGroup* mainActions, GObject* holder)
{
- sp_add_spiro_toggle(mainActions, holder, false);
- sp_freehand_add_advanced_shape_options(mainActions, holder, false);
+ sp_add_freehand_mode_toggle(mainActions, holder, false);
+ freehand_add_advanced_shape_options(mainActions, holder, false);
}
static void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
{
- sp_add_spiro_toggle(mainActions, holder, true);
+ sp_add_freehand_mode_toggle(mainActions, holder, true);
EgeAdjustmentAction* eact = 0;
@@ -3486,7 +3505,7 @@ static void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActio
}
/* advanced shape options */
- sp_freehand_add_advanced_shape_options(mainActions, holder, true);
+ freehand_add_advanced_shape_options(mainActions, holder, true);
/* Reset */
{