Code

add abs_width switch for calligraphy pen width; switch it to 1..100 displayed range
authorbuliabyak <buliabyak@users.sourceforge.net>
Thu, 20 Apr 2006 00:56:20 +0000 (00:56 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Thu, 20 Apr 2006 00:56:20 +0000 (00:56 +0000)
src/dyna-draw-context.cpp
src/dyna-draw-context.h
src/ui/dialog/inkscape-preferences.cpp
src/ui/dialog/inkscape-preferences.h
src/widgets/toolbox.cpp

index c0c91adccaaff819bb8c7154398e6dbad992402a..77f32e184dc667e04560283ec81bb88befecefa0 100644 (file)
@@ -155,6 +155,8 @@ sp_dyna_draw_context_init(SPDynaDrawContext *ddc)
 
     ddc->vel_thin = 0.1;
     ddc->flatness = 0.9;
+
+    ddc->abs_width = false;
 }
 
 static void
@@ -216,6 +218,7 @@ sp_dyna_draw_context_setup(SPEventContext *ec)
     sp_event_context_read(ec, "flatness");
     sp_event_context_read(ec, "usepressure");
     sp_event_context_read(ec, "usetilt");
+    sp_event_context_read(ec, "abs_width");
 
     ddc->is_drawing = false;
 
@@ -252,6 +255,8 @@ sp_dyna_draw_context_set(SPEventContext *ec, gchar const *key, gchar const *val)
         ddc->usepressure = (val && strcmp(val, "0"));
     } else if (!strcmp(key, "usetilt")) {
         ddc->usetilt = (val && strcmp(val, "0"));
+    } else if (!strcmp(key, "abs_width")) {
+        ddc->abs_width = (val && strcmp(val, "0"));
     }
 
     //g_print("DDC: %g %g %g %g\n", ddc->mass, ddc->drag, ddc->angle, ddc->width);
@@ -428,11 +433,18 @@ sp_dyna_draw_brush(SPDynaDrawContext *dc)
         width = 0.02 * dc->width;
     }
 
-    NR::Point del_left = 0.05 * (width + tremble_left) * dc->ang;
-    NR::Point del_right = 0.05 * (width + tremble_right) * dc->ang;
+    double dezoomify_factor = 0.05 * 1000;
+    if (!dc->abs_width) {
+        dezoomify_factor /= SP_EVENT_CONTEXT(dc)->desktop->current_zoom();
+    }
+
+    NR::Point del_left = dezoomify_factor * (width + tremble_left) * dc->ang;
+    NR::Point del_right = dezoomify_factor * (width + tremble_right) * dc->ang;
+
+    NR::Point abs_middle = sp_dyna_draw_get_vpoint(dc, dc->cur);
 
-    dc->point1[dc->npoints] = sp_dyna_draw_get_vpoint(dc, dc->cur + del_left);
-    dc->point2[dc->npoints] = sp_dyna_draw_get_vpoint(dc, dc->cur - del_right);
+    dc->point1[dc->npoints] = abs_middle + del_left;
+    dc->point2[dc->npoints] = abs_middle - del_right;
 
     dc->del = 0.5*(del_left + del_right);
 
@@ -606,7 +618,7 @@ sp_dyna_draw_context_root_handler(SPEventContext *event_context,
                 dc->width += 0.01;
                 if (dc->width > 1.0)
                     dc->width = 1.0;
-                sp_ddc_update_toolbox (desktop, "altx-calligraphy", dc->width); // the same spinbutton is for alt+x
+                sp_ddc_update_toolbox (desktop, "altx-calligraphy", dc->width * 100); // the same spinbutton is for alt+x
                 ret = TRUE;
             }
             break;
@@ -616,7 +628,7 @@ sp_dyna_draw_context_root_handler(SPEventContext *event_context,
                 dc->width -= 0.01;
                 if (dc->width < 0.01)
                     dc->width = 0.01;
-                sp_ddc_update_toolbox (desktop, "altx-calligraphy", dc->width);
+                sp_ddc_update_toolbox (desktop, "altx-calligraphy", dc->width * 100);
                 ret = TRUE;
             }
             break;
index feb38c2f8b745d56357325263c47e1e249faffb4..6d4f59ba5ec1249e8cb25d720efd67c3b32b4321 100644 (file)
@@ -102,6 +102,9 @@ struct SPDynaDrawContext
     Inkscape::MessageContext *_message_context;
 
     bool is_drawing;
+
+    /** uses absolute width independent of zoom */
+    bool abs_width;
 };
 
 struct SPDynaDrawContextClass
index 3ebf50eb921dcd51162b9f2202ca197aff1c7828..649dda1003397d1922ddb902472bb4576b998608 100644 (file)
@@ -300,6 +300,8 @@ void InkscapePreferences::initPageTools()
     Gtk::TreeModel::iterator iter_tools = this->AddPage(_page_tools, _("Tools"), PREFS_PAGE_TOOLS);    
     _path_tools = _page_list.get_model()->get_path(iter_tools);
 
+    _calligrapy_use_abs_size.init ( _("Width is in absolute units"), "tools.calligraphic", "abs_width", false);
+
     //Selector
     this->AddPage(_page_selector, _("Selector"), iter_tools, PREFS_PAGE_TOOLS_SELECTOR);
 
@@ -368,6 +370,8 @@ void InkscapePreferences::initPageTools()
     //Calligraphy
     this->AddPage(_page_calligraphy, _("Calligraphy"), iter_tools, PREFS_PAGE_TOOLS_CALLIGRAPHY);
     this->AddNewObjectsStyle(_page_calligraphy, "tools.calligraphic");
+    _page_calligraphy.add_line( false, "", _calligrapy_use_abs_size, "", 
+                            _("If on, pen width is in absolute units (px) independent of zoom; otherwise pen width depends on zoom so that it looks the same at any zoom"));
     //Text
     this->AddPage(_page_text, _("Text"), iter_tools, PREFS_PAGE_TOOLS_TEXT);
     this->AddSelcueCheckbox(_page_text, "tools.text", true);
index 3702c88f35eeb74dc664f7ac62b5ccb8ff60b7e5..d850dd4314d080ad6a002fcacf3070a1cc0ac4f8 100644 (file)
@@ -114,6 +114,8 @@ protected:
     PrefRadioButton _win_ontop_none, _win_ontop_normal, _win_ontop_agressive;
     PrefCheckButton _win_save_geom, _win_hide_task, _win_zoom_resize;
 
+    PrefCheckButton _calligrapy_use_abs_size;
+
     PrefRadioButton _clone_option_parallel, _clone_option_stay, _clone_option_transform,
                     _clone_option_unlink, _clone_option_delete;
 
index 1f9c2e504b5f6352659427e600d53cd61179e589..a45d57add8349535feb7d1f1f37c9b0b00771e4e 100644 (file)
@@ -735,7 +735,7 @@ sp_tb_spinbutton(
     gboolean altx, gchar const *altx_mark,
     gdouble lower, gdouble upper, gdouble step, gdouble page,
     void (*callback)(GtkAdjustment *, GtkWidget *),
-    gdouble climb = 0.1, guint digits = 3)
+    gdouble climb = 0.1, guint digits = 3, double factor = 1.0)
 {
     GtkTooltips *tt = gtk_tooltips_new();
 
@@ -746,7 +746,7 @@ sp_tb_spinbutton(
     gtk_misc_set_alignment(GTK_MISC(l), 1.0, 0.5);
     gtk_container_add(GTK_CONTAINER(hb), l);
 
-    GtkObject *a = gtk_adjustment_new(prefs_get_double_attribute(path, data, def),
+    GtkObject *a = gtk_adjustment_new(prefs_get_double_attribute(path, data, def) * factor,
                                       lower, upper, step, page, page);
     gtk_object_set_data(GTK_OBJECT(tbl), data, a);
     if (us)
@@ -1850,7 +1850,7 @@ sp_ddc_angle_value_changed(GtkAdjustment *adj, GtkWidget *tbl)
 static void
 sp_ddc_width_value_changed(GtkAdjustment *adj, GtkWidget *tbl)
 {
-    prefs_set_double_attribute("tools.calligraphic", "width", adj->value);
+    prefs_set_double_attribute("tools.calligraphic", "width", adj->value * 0.01);
     spinbutton_defocus(GTK_OBJECT(tbl));
 }
 
@@ -1899,7 +1899,7 @@ static void sp_ddc_defaults(GtkWidget *, GtkWidget *tbl)
         {"mass", 0.02},
         {"drag", 1.0},
         {"angle", 30.0},
-        {"width", 0.15},
+        {"width", 15},
         {"thinning", 0.1},
         {"tremor", 0.0},
         {"flatness", 0.9}
@@ -1930,10 +1930,10 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop)
     /* Width */
     {
         GtkWidget *hb = sp_tb_spinbutton(_("Width:"), _("The width of the calligraphic pen (relative to the visible canvas area)"),
-                                         "tools.calligraphic", "width", 0.15,
+                                         "tools.calligraphic", "width", 15,
                                          NULL, tbl, TRUE, "altx-calligraphy",
-                                         0.01, 1.0, 0.01, 0.1,
-                                         sp_ddc_width_value_changed,  0.01, 2);
+                                         1, 100, 1.0, 10.0,
+                                         sp_ddc_width_value_changed,  0.01, 0, 100);
         gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, AUX_SPACING);
     }