diff --git a/src/pen-context.cpp b/src/pen-context.cpp
index 95593f25b2e8ca6f3eee4f8780d30818467ecfc7..03a993f827b48bd42ad7ce56c710b1969950ff65 100644 (file)
--- a/src/pen-context.cpp
+++ b/src/pen-context.cpp
-/** \file
- * Pen event context implementation.
+/** \file
+ * Pen event context implementation.
*/
/*
event_context->cursor_shape = cursor_pen_xpm;
event_context->hot_x = 4;
event_context->hot_y = 4;
-
+
pc->npoints = 0;
pc->mode = SP_PEN_CONTEXT_MODE_CLICK;
pc->state = SP_PEN_CONTEXT_POINT;
}
/* Pen indicators */
- pc->c0 = sp_canvas_item_new(SP_DT_CONTROLS(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
+ pc->c0 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
"size", 4.0, "filled", 0, "fill_color", 0xff00007f, "stroked", 1, "stroke_color", 0x0000ff7f, NULL);
- pc->c1 = sp_canvas_item_new(SP_DT_CONTROLS(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
+ pc->c1 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
"size", 4.0, "filled", 0, "fill_color", 0xff00007f, "stroked", 1, "stroke_color", 0x0000ff7f, NULL);
- pc->cl0 = sp_canvas_item_new(SP_DT_CONTROLS(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL);
+ pc->cl0 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL);
sp_ctrlline_set_rgba32(SP_CTRLLINE(pc->cl0), 0x0000007f);
- pc->cl1 = sp_canvas_item_new(SP_DT_CONTROLS(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL);
+ pc->cl1 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL);
sp_ctrlline_set_rgba32(SP_CTRLLINE(pc->cl1), 0x0000007f);
sp_canvas_item_hide(pc->c0);
}
}
+static void
+pen_cancel (SPPenContext *const pc)
+{
+ pc->state = SP_PEN_CONTEXT_STOP;
+ spdc_reset_colors(pc);
+ sp_canvas_item_hide(pc->c0);
+ sp_canvas_item_hide(pc->c1);
+ sp_canvas_item_hide(pc->cl0);
+ sp_canvas_item_hide(pc->cl1);
+ pc->_message_context->clear();
+ pc->_message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled"));
+}
+
/**
* Finalization callback.
*/
static void
sp_pen_context_finish(SPEventContext *ec)
{
- spdc_pen_finish(SP_PEN_CONTEXT(ec), FALSE);
+ SPPenContext *pc = SP_PEN_CONTEXT(ec);
+
+ if (pc->npoints != 0) {
+ pen_cancel (pc);
+ }
if (((SPEventContextClass *) pen_parent_class)->finish) {
((SPEventContextClass *) pen_parent_class)->finish(ec);
}
}
-/**
+/**
* Snaps new node relative to the previous node.
*/
static void
@@ -248,7 +265,7 @@ spdc_endpoint_snap(SPPenContext const *const pc, NR::Point &p, guint const state
spdc_endpoint_snap_free(pc, p, state);
}
-/**
+/**
* Snaps new node's handle relative to the new node.
*/
static void
@@ -321,7 +338,7 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) {
return TRUE;
}
-
+
NR::Point const event_w(bevent.x, bevent.y);
pen_drag_origin_w = event_w;
pen_within_tolerance = true;
@@ -352,12 +369,12 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
/* This is allowed, if we just cancelled curve */
case SP_PEN_CONTEXT_POINT:
if (pc->npoints == 0) {
-
+
/* Set start anchor */
pc->sa = anchor;
NR::Point p;
if (anchor) {
-
+
/* Adjust point to anchor if needed */
p = anchor->dp;
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path"));
@@ -367,9 +384,9 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
// This is the first click of a new curve; deselect item so that
// this curve is not combined with it (unless it is drawn from its
// anchor, which is handled by the sibling branch above)
- Inkscape::Selection * const selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection * const selection = sp_desktop_selection(desktop);
if (!(bevent.state & GDK_SHIFT_MASK)) {
-
+
selection->clear();
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path"));
@@ -385,12 +402,12 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
}
spdc_pen_set_initial_point(pc, p);
} else {
-
+
/* Set end anchor */
pc->ea = anchor;
NR::Point p;
if (anchor) {
-
+
p = anchor->dp;
// we hit an anchor, will finish the curve (either with or without closing)
// in release handler
@@ -399,18 +416,18 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
if (pc->green_anchor && pc->green_anchor->active) {
// we clicked on the current curve start, so close it even if
// we drag a handle away from it
- dc->green_closed = TRUE;
+ dc->green_closed = TRUE;
}
ret = TRUE;
break;
-
+
} else {
-
+
p = event_dt;
spdc_endpoint_snap(pc, p, bevent.state); /* Snap node only if not hitting anchor. */
spdc_pen_set_subsequent_point(pc, p, true);
}
-
+
}
pc->state = SP_PEN_CONTEXT_CONTROL;
ret = TRUE;
@@ -434,7 +451,7 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
ret = TRUE;
}
}
-
+
return ret;
}
return ret;
}
+void
+pen_redraw_all (SPPenContext *const pc)
+{
+ // green
+ if (pc->green_bpaths) {
+ // remove old piecewise green canvasitems
+ while (pc->green_bpaths) {
+ gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
+ pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
+ }
+ // one canvas bpath for all of green_curve
+ SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), pc->green_curve);
+ sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
+ sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cshape), 0, SP_WIND_RULE_NONZERO);
+
+ pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape);
+ }
+
+ if (pc->green_anchor)
+ SP_CTRL(pc->green_anchor->ctrl)->moveto(pc->green_anchor->dp);
+
+ sp_curve_reset(pc->red_curve);
+ sp_curve_moveto(pc->red_curve, pc->p[0]);
+ sp_curve_curveto(pc->red_curve, pc->p[1], pc->p[2], pc->p[3]);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
+
+ // handles
+ if (pc->p[0] != pc->p[1]) {
+ SP_CTRL(pc->c1)->moveto(pc->p[1]);
+ sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl1), pc->p[0], pc->p[1]);
+ sp_canvas_item_show (pc->c1);
+ sp_canvas_item_show (pc->cl1);
+ } else {
+ sp_canvas_item_hide (pc->c1);
+ sp_canvas_item_hide (pc->cl1);
+ }
+
+ NArtBpath *const bpath = sp_curve_last_bpath(pc->green_curve);
+ if (bpath) {
+ if (bpath->code == NR_CURVETO && NR::Point(bpath->x2, bpath->y2) != pc->p[0]) {
+ SP_CTRL(pc->c0)->moveto(NR::Point(bpath->x2, bpath->y2));
+ sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl0), NR::Point(bpath->x2, bpath->y2), pc->p[0]);
+ sp_canvas_item_show (pc->c0);
+ sp_canvas_item_show (pc->cl0);
+ } else {
+ sp_canvas_item_hide (pc->c0);
+ sp_canvas_item_hide (pc->cl0);
+ }
+ }
+}
+
void
pen_lastpoint_move (SPPenContext *const pc, gdouble x, gdouble y)
{
}
bpath->x3 += x;
bpath->y3 += y;
- if (pc->green_bpaths && pc->green_bpaths->data) {
- // remove old piecewise green canvasitems
- while (pc->green_bpaths) {
- gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
- pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
- }
- // one canvas bpath for all of green_curve
- SPCanvasItem *cshape = sp_canvas_bpath_new(SP_DT_SKETCH(pc->desktop), pc->green_curve);
- sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
- sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cshape), 0, SP_WIND_RULE_NONZERO);
-
- pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape);
- }
} else {
// start anchor too
if (pc->green_anchor) {
pc->green_anchor->dp += NR::Point(x, y);
- SP_CTRL(pc->green_anchor->ctrl)->moveto(pc->green_anchor->dp);
}
}
// red
pc->p[0] += NR::Point(x, y);
pc->p[1] += NR::Point(x, y);
- sp_curve_reset(pc->red_curve);
- sp_curve_moveto(pc->red_curve, pc->p[0]);
- sp_curve_curveto(pc->red_curve, pc->p[1], pc->p[2], pc->p[3]);
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
-
- // handles
- if (pc->p[0] != pc->p[1]) {
- SP_CTRL(pc->c1)->moveto(pc->p[1]);
- sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl1), pc->p[0], pc->p[1]);
- }
- if (bpath && bpath->code == NR_CURVETO && NR::Point(bpath->x2, bpath->y2) != pc->p[0]) {
- SP_CTRL(pc->c0)->moveto(NR::Point(bpath->x2, bpath->y2));
- sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl0), NR::Point(bpath->x2, bpath->y2), pc->p[0]);
- }
+ pen_redraw_all(pc);
}
void
pen_lastpoint_move (pc, x / pc->desktop->current_zoom(), y / pc->desktop->current_zoom());
}
+void
+pen_lastpoint_tocurve (SPPenContext *const pc)
+{
+ if (pc->npoints != 5)
+ return;
+
+ // red
+ NArtBpath *const bpath = sp_curve_last_bpath(pc->green_curve);
+ if (bpath && bpath->code == NR_CURVETO) {
+ pc->p[1] = pc->p[0] + (NR::Point(bpath->x3, bpath->y3) - NR::Point(bpath->x2, bpath->y2));
+ } else {
+ pc->p[1] = pc->p[0] + (pc->p[3] - pc->p[0])*(1/3);
+ }
+
+ pen_redraw_all(pc);
+}
+
+void
+pen_lastpoint_toline (SPPenContext *const pc)
+{
+ if (pc->npoints != 5)
+ return;
+
+ pc->p[1] = pc->p[0];
+
+ pen_redraw_all(pc);
+}
+
+
static gint
pen_handle_key_press(SPPenContext *const pc, GdkEvent *event)
{
}
break;
+ case GDK_U:
+ case GDK_u:
+ if (MOD__SHIFT_ONLY) {
+ pen_lastpoint_tocurve(pc);
+ ret = TRUE;
+ }
+ break;
+ case GDK_L:
+ case GDK_l:
+ if (MOD__SHIFT_ONLY) {
+ pen_lastpoint_toline(pc);
+ ret = TRUE;
+ }
+ break;
+
case GDK_Return:
case GDK_KP_Enter:
if (pc->npoints != 0) {
case GDK_Escape:
if (pc->npoints != 0) {
// if drawing, cancel, otherwise pass it up for deselecting
- pc->state = SP_PEN_CONTEXT_STOP;
- spdc_reset_colors(pc);
- sp_canvas_item_hide(pc->c0);
- sp_canvas_item_hide(pc->c1);
- sp_canvas_item_hide(pc->cl0);
- sp_canvas_item_hide(pc->cl1);
+ pen_cancel (pc);
ret = TRUE;
}
break;
case GDK_Z:
if (MOD__CTRL_ONLY && pc->npoints != 0) {
// if drawing, cancel, otherwise pass it up for undo
- pc->state = SP_PEN_CONTEXT_STOP;
- spdc_reset_colors(pc);
- sp_canvas_item_hide(pc->c0);
- sp_canvas_item_hide(pc->c1);
- sp_canvas_item_hide(pc->cl0);
- sp_canvas_item_hide(pc->cl1);
+ pen_cancel (pc);
ret = TRUE;
}
break;
if (pc->green_bpaths->data)
gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
- }
+ }
/* Get last segment */
NArtBpath const *const p = SP_CURVE_BPATH(pc->green_curve);
gint const e = SP_CURVE_LENGTH(pc->green_curve);
@@ -1031,8 +1106,8 @@ spdc_pen_finish_segment(SPPenContext *const pc, NR::Point const p, guint const s
if (!sp_curve_empty(pc->red_curve)) {
sp_curve_append_continuous(pc->green_curve, pc->red_curve, 0.0625);
SPCurve *curve = sp_curve_copy(pc->red_curve);
- /// \todo fixme:
- SPCanvasItem *cshape = sp_canvas_bpath_new(SP_DT_SKETCH(pc->desktop), curve);
+ /// \todo fixme:
+ SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), curve);
sp_curve_unref(curve);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
{
SPDesktop *const desktop = pc->desktop;
pc->_message_context->clear();
- desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing pen"));
+ desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished"));
sp_curve_reset(pc->red_curve);
spdc_concat_colors_and_flush(pc, closed);