diff --git a/src/pen-context.cpp b/src/pen-context.cpp
index eb399d191b43dfc1105bf630f9c21820b3946a53..261c7d4cf69276e37348c3f1eea0b20391c0c487 100644 (file)
--- a/src/pen-context.cpp
+++ b/src/pen-context.cpp
static int pen_next_paraxial_direction(const SPPenContext *const pc, Geom::Point const &pt, Geom::Point const &origin, guint state);
static void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt, guint const state);
-static Geom::Point pen_get_intermediate_horiz_vert(const SPPenContext *const pc, Geom::Point const &pt, guint const state);
static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical
pc->c1 = NULL;
pc->cl0 = NULL;
pc->cl1 = NULL;
-
+
pc->events_disabled = 0;
pc->num_clicks = 0;
}
static void
-pen_cancel (SPPenContext *const pc)
+pen_cancel (SPPenContext *const pc)
{
pc->num_clicks = 0;
pc->state = SP_PEN_CONTEXT_STOP;
{
SPPenContext *pc = SP_PEN_CONTEXT(ec);
+ sp_event_context_snap_window_closed(ec, false); //TODO: Detailed implementation of the snap window; now it's simply always open
+
if (pc->npoints != 0) {
pen_cancel (pc);
}
@@ -332,7 +333,7 @@ spdc_endpoint_snap_handle(SPPenContext const *const pc, Geom::Point &p, guint co
}
}
-static gint
+static gint
sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event)
{
SPPenContext *const pc = SP_PEN_CONTEXT(ec);
{
SPPenContext *const pc = SP_PEN_CONTEXT(ec);
+ sp_event_context_snap_window_open(ec, false); //TODO: Detailed implementation of the snap window; now it's simply always open
+
gint ret = FALSE;
switch (event->type) {
@@ -417,7 +420,7 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
SPDrawContext * const dc = SP_DRAW_CONTEXT(pc);
SPDesktop * const desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
Geom::Point const event_w(bevent.x, bevent.y);
- Geom::Point const event_dt(desktop->w2d(event_w));
+ Geom::Point event_dt(desktop->w2d(event_w));
SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
gint ret = FALSE;
@@ -453,7 +456,7 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
case SP_PEN_CONTEXT_CLOSE:
break;
case SP_PEN_CONTEXT_STOP:
- /* This is allowed, if we just cancelled curve */
+ /* This is allowed, if we just canceled curve */
pc->state = SP_PEN_CONTEXT_POINT;
break;
default:
@@ -463,22 +466,28 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
case SP_PEN_CONTEXT_MODE_DRAG:
switch (pc->state) {
case SP_PEN_CONTEXT_STOP:
- /* This is allowed, if we just cancelled curve */
+ /* This is allowed, if we just canceled curve */
case SP_PEN_CONTEXT_POINT:
if (pc->npoints == 0) {
- if (bevent.state & GDK_CONTROL_MASK) {
- spdc_create_single_dot(event_context, event_dt, "/tools/freehand/pen", bevent.state);
- ret = TRUE;
- break;
- }
+ Geom::Point p;
+ if ((bevent.state & GDK_CONTROL_MASK) && (pc->polylines_only || pc->polylines_paraxial)) {
+ p = event_dt;
+ if (!(bevent.state & GDK_SHIFT_MASK)) {
+ SnapManager &m = desktop->namedview->snap_manager;
+ m.setup(desktop);
+ m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
+ }
+ spdc_create_single_dot(event_context, p, "/tools/freehand/pen", bevent.state);
+ ret = TRUE;
+ break;
+ }
// TODO: Perhaps it would be nicer to rearrange the following case
// distinction so that the case of a waiting LPE is treated separately
/* Set start anchor */
pc->sa = anchor;
- Geom::Point p;
if (anchor && !sp_pen_context_has_waiting_LPE(pc)) {
/* Adjust point to anchor if needed; if we have a waiting LPE, we need
a fresh path to be created so don't continue an existing one */
// allow scrolling
return FALSE;
}
-
+
if (pc->events_disabled) {
// skip motion events if pen events are disabled
return FALSE;
if (pen_within_tolerance) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
- if ( NR::LInfty( event_w - pen_drag_origin_w ) < tolerance ) {
+ if ( Geom::LInfty( event_w - pen_drag_origin_w ) < tolerance ) {
return FALSE; // Do not drag if we're within tolerance from origin.
}
}
ret = TRUE;
break;
case SP_PEN_CONTEXT_STOP:
- /* This is allowed, if we just cancelled curve */
+ /* This is allowed, if we just canceled curve */
pc->state = SP_PEN_CONTEXT_POINT;
ret = TRUE;
break;
pen_handle_2button_press(SPPenContext *const pc, GdkEventButton const &bevent)
{
gint ret = FALSE;
- if (pc->npoints != 0 && bevent.button != 2) {
+ // only end on LMB double click. Otherwise horizontal scrolling causes ending of the path
+ if (pc->npoints != 0 && bevent.button == 1) {
spdc_pen_finish(pc, FALSE);
ret = TRUE;
}
static gint
pen_handle_key_press(SPPenContext *const pc, GdkEvent *event)
{
- gint ret = FALSE;
+
+ gint ret = FALSE;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000); // in px
}
break;
+/* TODO: this is not yet enabled?? looks like some traces of the Geometry tool
case GDK_P:
case GDK_p:
if (MOD__SHIFT_ONLY) {
ret = TRUE;
}
break;
+*/
case GDK_U:
case GDK_u:
case GDK_BackSpace:
case GDK_Delete:
case GDK_KP_Delete:
- if (pc->green_curve->is_empty()) {
+ if ( pc->green_curve->is_empty() || (pc->green_curve->last_segment() == NULL) ) {
if (!pc->red_curve->is_empty()) {
pen_cancel (pc);
ret = TRUE;
break;
}
// The code below assumes that pc->green_curve has only ONE path !
- Geom::Path const & path = pc->green_curve->get_pathvector().back();
- Geom::Curve const * crv = &path.back_default();
+ Geom::Curve const * crv = pc->green_curve->last_segment();
pc->p[0] = crv->initialPoint();
if ( Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>(crv)) {
pc->p[1] = (*cubic)[1];
* Show the status message for the current line/curve segment.
* This type of message always shows angle/distance as the last
* two parameters ("angle %3.2f°, distance %s").
- */
+ */
static void
spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, Geom::Point const p, int pc_point_to_compare, gchar const *message)
{
@@ -1212,8 +1224,8 @@ spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, Geom::Point c
SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop;
Geom::Point rel = p - pc->p[pc_point_to_compare];
- GString *dist = SP_PX_TO_METRIC_STRING(NR::L2(rel), desktop->namedview->getDefaultMetric());
- double angle = atan2(rel[NR::Y], rel[NR::X]) * 180 / M_PI;
+ GString *dist = SP_PX_TO_METRIC_STRING(Geom::L2(rel), desktop->namedview->getDefaultMetric());
+ double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (prefs->getBool("/options/compassangledisplay/value", 0) != 0)
angle = angle_to_compass (angle);
pc->num_clicks = 0;
pen_disable_events(pc);
-
+
SPDesktop *const desktop = pc->desktop;
pc->_message_context->clear();
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished"));
static void
pen_enable_events(SPPenContext *const pc) {
g_return_if_fail(pc->events_disabled != 0);
-
+
pc->events_disabled--;
}
*/
if (pc->num_clicks == 0) {
// first mouse click
- double dist_h = fabs(pt[NR::X] - origin[NR::X]);
- double dist_v = fabs(pt[NR::Y] - origin[NR::Y]);
+ double dist_h = fabs(pt[Geom::X] - origin[Geom::X]);
+ double dist_v = fabs(pt[Geom::Y] - origin[Geom::Y]);
int ret = (dist_h < dist_v) ? 1 : 0; // 0 = horizontal, 1 = vertical
pen_last_paraxial_dir = (state & GDK_SHIFT_MASK) ? 1 - ret : ret;
return pen_last_paraxial_dir;
@@ -1433,21 +1445,10 @@ void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt
if (next_dir == 0) {
// line is forced to be horizontal
- pt[NR::Y] = origin[NR::Y];
+ pt[Geom::Y] = origin[Geom::Y];
} else {
// line is forced to be vertical
- pt[NR::X] = origin[NR::X];
- }
-}
-
-Geom::Point pen_get_intermediate_horiz_vert(const SPPenContext *const pc, Geom::Point const &pt)
-{
- Geom::Point const &origin = pc->p[0];
-
- if (pen_last_paraxial_dir == 0) {
- return Geom::Point (origin[NR::X], pt[NR::Y]);
- } else {
- return Geom::Point (pt[NR::X], origin[NR::Y]);
+ pt[Geom::X] = origin[Geom::X];
}
}