Code

Reword transform toggle tooltips based on user feedback regarding the
[inkscape.git] / src / widgets / toolbox.cpp
index d3018b0d9d2140f99ac206d2e88281986398d1e1..9801c9f48876c056fe53b0370b611d9275d45c09 100644 (file)
@@ -64,6 +64,7 @@
 #include "node-context.h"
 #include "shape-editor.h"
 #include "sp-rect.h"
+#include "box3d.h"
 #include "box3d-context.h"
 #include "sp-star.h"
 #include "sp-spiral.h"
@@ -99,6 +100,7 @@ typedef void (*SetupFunction)(GtkWidget *toolbox, SPDesktop *desktop);
 typedef void (*UpdateFunction)(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox);
 
 static void       sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
+static void       sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
 static void       sp_zoom_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
 static void       sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
 static void       sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
@@ -124,6 +126,7 @@ static struct {
 } const tools[] = {
     { "SPSelectContext",   "select_tool",    SP_VERB_CONTEXT_SELECT,  SP_VERB_CONTEXT_SELECT_PREFS},
     { "SPNodeContext",     "node_tool",      SP_VERB_CONTEXT_NODE, SP_VERB_CONTEXT_NODE_PREFS },
+    { "SPTweakContext",    "tweak_tool",     SP_VERB_CONTEXT_TWEAK, SP_VERB_CONTEXT_TWEAK_PREFS },
     { "SPZoomContext",     "zoom_tool",      SP_VERB_CONTEXT_ZOOM, SP_VERB_CONTEXT_ZOOM_PREFS },
     { "SPRectContext",     "rect_tool",      SP_VERB_CONTEXT_RECT, SP_VERB_CONTEXT_RECT_PREFS },
 //    { "SP3DBoxContext",    "3dbox_tool",     SP_VERB_CONTEXT_3DBOX, SP_VERB_CONTEXT_3DBOX_PREFS },
@@ -155,6 +158,8 @@ static struct {
       SP_VERB_INVALID, 0, 0},
     { "SPNodeContext",   "node_toolbox",   0, sp_node_toolbox_prep,              "NodeToolbar",
       SP_VERB_INVALID, 0, 0},
+    { "SPTweakContext",   "tweak_toolbox",   0, sp_tweak_toolbox_prep,              "TweakToolbar",
+      SP_VERB_INVALID, 0, 0},
     { "SPZoomContext",   "zoom_toolbox",   0, sp_zoom_toolbox_prep,              "ZoomToolbar",
       SP_VERB_INVALID, 0, 0},
     { "SPStarContext",   "star_toolbox",   0, sp_star_toolbox_prep,              "StarToolbar",
@@ -235,6 +240,16 @@ static gchar const * ui_descr =
         "    <toolitem action='NodesShowHandlesAction' />"
         "  </toolbar>"
 
+        "  <toolbar name='TweakToolbar'>"
+        "    <toolitem action='TweakWidthAction' />"
+        "    <toolitem action='TweakForceAction' />"
+        "    <separator />"
+        "    <toolitem action='TweakModeAction' />"
+        "    <separator />"
+        "    <toolitem action='TweakFidelityAction' />"
+        "    <toolitem action='TweakPressureAction' />"
+        "  </toolbar>"
+
         "  <toolbar name='ZoomToolbar'>"
         "    <toolitem action='ZoomIn' />"
         "    <toolitem action='ZoomOut' />"
@@ -281,6 +296,7 @@ static gchar const * ui_descr =
         "    <toolitem action='3DBoxVPXAction' />"
         "    <toolitem action='3DBoxVPYAction' />"
         "    <toolitem action='3DBoxVPZAction' />"
+        "    <separator />"
         "  </toolbar>"
 
         "  <toolbar name='SpiralToolbar'>"
@@ -2106,36 +2122,18 @@ static void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
 
 static void sp_3dbox_toggle_vp_changed( GtkToggleAction *act, gpointer data )
 {
-    guint dir = GPOINTER_TO_UINT(data);
-    Box3D::PerspDir axis;// = (Box3D::PerspDir) data;
+    SPDocument *document = sp_desktop_document (inkscape_active_desktop ());
+    Box3D::Axis axis = (Box3D::Axis) GPOINTER_TO_INT(data);
 
-    GString *pstring;
-    switch (dir) {
-        case 0:
-            pstring = g_string_new("togglevpx");
-            axis = Box3D::X;
-            break;
-        case 1:
-            pstring = g_string_new("togglevpy");
-            axis = Box3D::Y;
-            break;
-        case 2:
-            pstring = g_string_new("togglevpz");
-            axis = Box3D::Z;
-            break;
-    }
-    
-    if (SP3DBoxContext::current_perspective) {
-        Box3D::VanishingPoint *vp = SP3DBoxContext::current_perspective->get_vanishing_point(axis);
-        vp->toggle_parallel();
-        vp->draw(axis);
-        prefs_set_int_attribute( "tools.shapes.3dbox", pstring->str, vp->is_finite() ? 0 : 1);
+    if (document->current_perspective) {
+        document->current_perspective->toggle_boxes (axis);
     }
     
 }
 
 static void sp_3dbox_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
 {
+    SPDocument *document = sp_desktop_document (desktop);
     bool toggled = false;
     /* toggle VP in X direction */
     {
@@ -2145,11 +2143,12 @@ static void sp_3dbox_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainAction
                                                   "toggle_vp_x",
                                                   Inkscape::ICON_SIZE_DECORATION );
     gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
-    g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_3dbox_toggle_vp_changed), GUINT_TO_POINTER(0));
-    if (SP3DBoxContext::current_perspective) {
-        toggled = SP3DBoxContext::current_perspective->get_vanishing_point(Box3D::X)->is_finite();
+    if (document->current_perspective) {
+        toggled = !document->current_perspective->get_vanishing_point(Box3D::X)->is_finite();
     }
     gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), toggled );
+    /* we connect the signal after setting the state to avoid switching the state again */
+    g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_3dbox_toggle_vp_changed), GINT_TO_POINTER(Box3D::X));
     }
 
     /* toggle VP in Y direction */
@@ -2160,11 +2159,12 @@ static void sp_3dbox_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainAction
                                                   "toggle_vp_y",
                                                   Inkscape::ICON_SIZE_DECORATION );
     gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
-    g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_3dbox_toggle_vp_changed), GUINT_TO_POINTER(1));
-    if (SP3DBoxContext::current_perspective) {
-        toggled = SP3DBoxContext::current_perspective->get_vanishing_point(Box3D::Y)->is_finite();
+    if (document->current_perspective) {
+        toggled = !document->current_perspective->get_vanishing_point(Box3D::Y)->is_finite();
     }
     gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), toggled );
+    /* we connect the signal after setting the state to avoid switching the state again */
+    g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_3dbox_toggle_vp_changed), GINT_TO_POINTER(Box3D::Y));
     }
 
     /* toggle VP in Z direction */
@@ -2175,11 +2175,12 @@ static void sp_3dbox_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainAction
                                                   "toggle_vp_z",
                                                   Inkscape::ICON_SIZE_DECORATION );
     gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
-    g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_3dbox_toggle_vp_changed), GUINT_TO_POINTER(2));
-    if (SP3DBoxContext::current_perspective) {
-        toggled = SP3DBoxContext::current_perspective->get_vanishing_point(Box3D::Z)->is_finite();
+    if (document->current_perspective) {
+        toggled = !document->current_perspective->get_vanishing_point(Box3D::Z)->is_finite();
     }
+    /* we connect the signal after setting the state to avoid switching the state again */
     gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), toggled );
+    g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_3dbox_toggle_vp_changed), GINT_TO_POINTER(Box3D::Z));
     }
 }
 
@@ -2431,6 +2432,148 @@ static void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActio
     // Put stuff here
 }
 
+//########################
+//##       Tweak        ##
+//########################
+
+static void sp_tweak_width_value_changed( GtkAdjustment *adj, GObject *tbl )
+{
+    prefs_set_double_attribute( "tools.tweak", "width", adj->value * 0.01 );
+}
+
+static void sp_tweak_force_value_changed( GtkAdjustment *adj, GObject *tbl )
+{
+    prefs_set_double_attribute( "tools.tweak", "force", adj->value * 0.01 );
+}
+
+static void sp_tweak_pressure_state_changed( GtkToggleAction *act, gpointer data )
+{
+    prefs_set_int_attribute( "tools.tweak", "usepressure", gtk_toggle_action_get_active( act ) ? 1 : 0);
+}
+
+static void sp_tweak_mode_changed( EgeSelectOneAction *act, GObject *tbl )
+{
+    prefs_set_int_attribute("tools.tweak", "mode", ege_select_one_action_get_active( act ));
+}
+
+static void sp_tweak_fidelity_value_changed( GtkAdjustment *adj, GObject *tbl )
+{
+    prefs_set_double_attribute( "tools.tweak", "fidelity", adj->value * 0.01 );
+}
+
+
+static void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
+{
+    {
+        /* Width */
+        gchar const* labels[] = {_("(pinch tweak)"), 0, 0, 0, _("(default)"), 0, 0, 0, 0, _("(broad tweak)")};
+        gdouble values[] = {1, 3, 5, 10, 15, 20, 30, 50, 75, 100};
+        EgeAdjustmentAction *eact = create_adjustment_action( "TweakWidthAction",
+                                                              _("Width:"), _("The width of the tweak area (relative to the visible canvas area)"),
+                                                              "tools.tweak", "width", 15,
+                                                              GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-tweak",
+                                                              1, 100, 1.0, 10.0,
+                                                              labels, values, G_N_ELEMENTS(labels),
+                                                              sp_tweak_width_value_changed,  0.01, 0, 100 );
+        gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
+        gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
+    }
+
+
+    {
+        /* Force */
+        gchar const* labels[] = {_("(minimum force)"), 0, 0, _("(default)"), 0, 0, 0, _("(maximum force)")};
+        gdouble values[] = {1, 5, 10, 20, 30, 50, 70, 100};
+        EgeAdjustmentAction *eact = create_adjustment_action( "TweakForceAction",
+                                                              _("Force:"), _("The force of the tweak action"),
+                                                              "tools.tweak", "force", 20,
+                                                              GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-force",
+                                                              1, 100, 1.0, 10.0,
+                                                              labels, values, G_N_ELEMENTS(labels),
+                                                              sp_tweak_force_value_changed,  0.01, 0, 100 );
+        gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
+        gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
+    }
+
+    /* Mode */
+    {
+        GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
+
+        GtkTreeIter iter;
+        gtk_list_store_append( model, &iter );
+        gtk_list_store_set( model, &iter,
+                            0, _("Push mode"),
+                            1, _("Switch to Push mode"),
+                            2, "tweak_push_mode",
+                            -1 );
+
+        gtk_list_store_append( model, &iter );
+        gtk_list_store_set( model, &iter,
+                            0, _("Melt mode"),
+                            1, _("Switch to Melt mode"),
+                            2, "tweak_suck_mode",
+                            -1 );
+
+        gtk_list_store_append( model, &iter );
+        gtk_list_store_set( model, &iter,
+                            0, _("Blow mode"),
+                            1, _("Switch to Blow mode"),
+                            2, "tweak_blow_mode",
+                            -1 );
+
+        gtk_list_store_append( model, &iter );
+        gtk_list_store_set( model, &iter,
+                            0, _("Roughen mode"),
+                            1, _("Switch to Roughen mode"),
+                            2, "tweak_roughen_mode",
+                            -1 );
+
+        EgeSelectOneAction* act = ege_select_one_action_new( "TweakModeAction", _(""), _(""), NULL, GTK_TREE_MODEL(model) );
+        gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
+        g_object_set_data( holder, "mode_action", act );
+
+        ege_select_one_action_set_appearance( act, "full" );
+        ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
+        g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
+        ege_select_one_action_set_icon_column( act, 2 );
+        ege_select_one_action_set_tooltip_column( act, 1  );
+
+        gint mode = prefs_get_int_attribute("tools.tweak", "mode", 0);
+        ege_select_one_action_set_active( act, mode );
+        g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_tweak_mode_changed), holder );
+
+        g_object_set_data( G_OBJECT(holder), "tweak_tool_mode", act);
+    }
+
+    {   /* Fidelity */
+        gchar const* labels[] = {_("(rough, simplified)"), 0, 0, _("(default)"), 0, 0, _("(fine, but many nodes)")};
+        gdouble values[] = {10, 25, 35, 50, 60, 80, 100};
+        EgeAdjustmentAction *eact = create_adjustment_action( "TweakFidelityAction",
+                                                              _("Fidelity:"), _("Low fidelity simplifies paths; high fidelity preserves path features but may generate a lot of new nodes"),
+                                                              "tools.tweak", "fidelity", 50,
+                                                              GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-fidelity",
+                                                              1, 100, 1.0, 10.0,
+                                                              labels, values, G_N_ELEMENTS(labels),
+                                                              sp_tweak_fidelity_value_changed,  0.01, 0, 100 );
+        gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
+        gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
+    }
+
+
+    /* Use Pressure button */
+    {
+        InkToggleAction* act = ink_toggle_action_new( "TweakPressureAction",
+                                                      _("Pressure"),
+                                                      _("Use the pressure of the input device to alter the width of the area"),
+                                                      "use_pressure",
+                                                      Inkscape::ICON_SIZE_DECORATION );
+        gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
+        g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_tweak_pressure_state_changed), NULL);
+        gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.tweak", "usepressure", 1 ) );
+    }
+
+}
+
 
 //########################
 //##     Calligraphy    ##
@@ -2690,7 +2833,7 @@ static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main
         {
             GtkAction* act = gtk_action_new( "CalligraphyResetAction",
                                              _("Defaults"),
-                                             _("Reset shape parameters to defaults (use Inkscape Preferences > Tools to change defaults)"),
+                                             _("Reset all parameters to defaults"),
                                              GTK_STOCK_CLEAR );
             g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_ddc_defaults), holder );
             gtk_action_group_add_action( mainActions, act );
@@ -3155,9 +3298,8 @@ bool visible = false;
 void
 sp_text_toolbox_selection_changed (Inkscape::Selection *selection, GObject *tbl)
 {
-
     SPStyle *query =
-        sp_style_new ();
+        sp_style_new (SP_ACTIVE_DOCUMENT);
 
     int result_family =
         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
@@ -3303,6 +3445,8 @@ sp_text_toolbox_selection_changed (Inkscape::Selection *selection, GObject *tbl)
         g_object_set_data (G_OBJECT (button), "block", gpointer(0));
         g_object_set_data (G_OBJECT (button1), "block", gpointer(0));
     }
+
+    sp_style_unref(query);
 }
 
 void
@@ -3349,7 +3493,7 @@ sp_text_toolbox_family_changed (GtkTreeSelection    *selection,
     gtk_entry_set_text (GTK_ENTRY (entry), family);
 
     SPStyle *query =
-        sp_style_new ();
+        sp_style_new (SP_ACTIVE_DOCUMENT);
 
     int result_numbers =
         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
@@ -3368,6 +3512,8 @@ sp_text_toolbox_family_changed (GtkTreeSelection    *selection,
         sp_desktop_set_style (desktop, css, true, true);
     }
 
+    sp_style_unref(query);
+
     sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
                                    _("Text: Change font family"));
     sp_repr_css_attr_unref (css);
@@ -3440,7 +3586,7 @@ sp_text_toolbox_anchoring_toggled (GtkRadioButton   *button,
     }
 
     SPStyle *query =
-        sp_style_new ();
+        sp_style_new (SP_ACTIVE_DOCUMENT);
     int result_numbers =
         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
 
@@ -3450,6 +3596,8 @@ sp_text_toolbox_anchoring_toggled (GtkRadioButton   *button,
         sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style");
     }
 
+    sp_style_unref(query);
+
     sp_desktop_set_style (desktop, css, true, true);
     sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
                                    _("Text: Change alignment"));
@@ -3486,7 +3634,7 @@ sp_text_toolbox_style_toggled (GtkToggleButton  *button,
     }
 
     SPStyle *query =
-        sp_style_new ();
+        sp_style_new (SP_ACTIVE_DOCUMENT);
     int result_numbers =
         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
 
@@ -3496,6 +3644,8 @@ sp_text_toolbox_style_toggled (GtkToggleButton  *button,
         sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style");
     }
 
+    sp_style_unref(query);
+
     sp_desktop_set_style (desktop, css, true, true);
     sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
                                    _("Text: Change font style"));
@@ -3533,7 +3683,7 @@ sp_text_toolbox_orientation_toggled (GtkRadioButton  *button,
     }
 
     SPStyle *query =
-        sp_style_new ();
+        sp_style_new (SP_ACTIVE_DOCUMENT);
     int result_numbers =
         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
 
@@ -3629,7 +3779,7 @@ sp_text_toolbox_size_changed  (GtkComboBox *cbox,
     free (text);
 
     SPStyle *query =
-        sp_style_new ();
+        sp_style_new (SP_ACTIVE_DOCUMENT);
     int result_numbers =
         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
 
@@ -3639,6 +3789,8 @@ sp_text_toolbox_size_changed  (GtkComboBox *cbox,
         sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style");
     }
 
+    sp_style_unref(query);
+
     sp_desktop_set_style (desktop, css, true, true);
     sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "ttb:size", SP_VERB_NONE,
                                    _("Text: Change font size"));