index 75aef13ef28a25b87211e28385673340f362f49a..7d0c7ee91ff178c849007f6a34c43c83a5b9e2dc 100644 (file)
-#define __SP_DYNA_DRAW_CONTEXT_C__
-
/*
* Handwriting-like drawing mode
*
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* MenTaLguY <mental@rydia.net>
+ * Abhishek Sharma
*
* The original dynadraw code:
* Paul Haeberli <paul@sgi.com>
#include "desktop.h"
#include "desktop-events.h"
#include "desktop-handles.h"
-#include "desktop-affine.h"
#include "desktop-style.h"
#include "message-context.h"
#include "preferences.h"
#include "sp-shape.h"
#include "sp-path.h"
#include "sp-text.h"
+#include "display/sp-canvas.h"
#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
#include "livarot/Shape.h"
#include "dyna-draw-context.h"
+using Inkscape::DocumentUndo;
+
#define DDC_RED_RGBA 0xff0000ff
#define TOLERANCE_CALLIGRAPHIC 0.1
static gint sp_dyna_draw_context_root_handler(SPEventContext *ec, GdkEvent *event);
static void clear_current(SPDynaDrawContext *dc);
-static void set_to_accumulated(SPDynaDrawContext *dc, bool unionize);
+static void set_to_accumulated(SPDynaDrawContext *dc, bool unionize, bool subtract);
static void add_cap(SPCurve *curve, Geom::Point const &from, Geom::Point const &to, double rounding);
static bool accumulate_calligraphic(SPDynaDrawContext *dc);
}
// calculate pointer point in the guide item's coords
- motion_to_curve = sp_item_dt2i_affine(selected) * sp_item_i2doc_affine(selected);
+ motion_to_curve = selected->dt2i_affine() * selected->i2doc_affine();
pointer = motion_dt * motion_to_curve;
// calculate the nearest point on the guide path
if (event->motion.state & GDK_CONTROL_MASK && dc->hatch_item) { // hatching
#define HATCH_VECTOR_ELEMENTS 12
-#define INERTIA_ELEMENTS 36
+#define INERTIA_ELEMENTS 24
#define SPEED_ELEMENTS 12
#define SPEED_MIN 0.3
-#define SPEED_NORMAL 0.3
+#define SPEED_NORMAL 0.35
+#define INERTIA_FORCE 0.5
// speed is the movement of the nearest point along the guide path, divided by
// the movement of the pointer at the same period; it is averaged for the last
if (dot > 0) { // mouse is still moving in approx the same direction
Geom::Point should_have_moved =
(inertia) * (1/Geom::L2(inertia)) * Geom::L2(moved_past_escape);
- motion_dt = dc->inertia_vectors.front() + should_have_moved;
+ motion_dt = dc->inertia_vectors.front() +
+ (INERTIA_FORCE * should_have_moved + (1 - INERTIA_FORCE) * moved_past_escape);
}
}
/* Create object */
fit_and_split(dc, TRUE);
if (accumulate_calligraphic(dc))
- set_to_accumulated(dc, event->button.state & GDK_SHIFT_MASK); // performs document_done
+ set_to_accumulated(dc, event->button.state & GDK_SHIFT_MASK, event->button.state & GDK_MOD1_MASK); // performs document_done
else
g_warning ("Failed to create path: invalid data in dc->cal1 or dc->cal2");
}
static void
-set_to_accumulated(SPDynaDrawContext *dc, bool unionize)
+set_to_accumulated(SPDynaDrawContext *dc, bool unionize, bool subtract)
{
SPDesktop *desktop = SP_EVENT_CONTEXT(dc)->desktop;
if (!dc->accumulated->is_empty()) {
if (!dc->repr) {
/* Create object */
- Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+ Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
/* Set style */
SPItem *item=SP_ITEM(desktop->currentLayer()->appendChildRepr(dc->repr));
Inkscape::GC::release(dc->repr);
- item->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse();
+ item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse();
item->updateRepr();
}
- Geom::PathVector pathv = dc->accumulated->get_pathvector() * sp_desktop_dt2doc_affine(desktop);
+ Geom::PathVector pathv = dc->accumulated->get_pathvector() * desktop->dt2doc();
gchar *str = sp_svg_write_path(pathv);
g_assert( str != NULL );
dc->repr->setAttribute("d", str);
if (unionize) {
sp_desktop_selection(desktop)->add(dc->repr);
sp_selected_path_union_skip_undo(desktop);
+ } else if (subtract) {
+ sp_desktop_selection(desktop)->add(dc->repr);
+ sp_selected_path_diff_skip_undo(desktop);
} else {
if (dc->keep_selected) {
sp_desktop_selection(desktop)->set(dc->repr);
dc->repr = NULL;
}
- sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_CALLIGRAPHIC,
- _("Draw calligraphic stroke"));
+ DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_CALLIGRAPHIC,
+ _("Draw calligraphic stroke"));
}
static void
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :