pen-context.cpp revision 8952e0a5008b96fe895e2ba0ab76b949f5eb485e
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/** \file
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Pen event context implementation.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/*
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Authors:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Lauris Kaplinski <lauris@kaplinski.com>
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * bulia byak <buliabyak@users.sf.net>
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm *
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Copyright (C) 2000 Lauris Kaplinski
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Copyright (C) 2000-2001 Ximian, Inc.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Copyright (C) 2002 Lauris Kaplinski
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Copyright (C) 2004 Monash University
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm *
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Released under GNU GPL, read the file 'COPYING' for more information
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include <gdk/gdkkeysyms.h>
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include <cstring>
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include <string>
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "pen-context.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "sp-namedview.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "sp-metrics.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "desktop.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "desktop-handles.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "selection.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "selection-chemistry.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "draw-anchor.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "message-stack.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "message-context.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "preferences.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "sp-path.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "display/sp-canvas.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "display/curve.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "pixmaps/cursor-pen.xpm"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "display/canvas-bpath.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "display/sp-ctrlline.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "display/sodipodi-ctrl.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include <glibmm/i18n.h>
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "libnr/nr-point-ops.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "helper/units.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "macros.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "context-fns.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm#include "tools-switch.h"
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void sp_pen_context_class_init(SPPenContextClass *klass);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void sp_pen_context_init(SPPenContext *pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void sp_pen_context_dispose(GObject *object);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void sp_pen_context_setup(SPEventContext *ec);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void sp_pen_context_finish(SPEventContext *ec);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void sp_pen_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint sp_pen_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void spdc_pen_set_initial_point(SPPenContext *pc, Geom::Point const p);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void spdc_pen_set_subsequent_point(SPPenContext *const pc, Geom::Point const p, bool statusbar, guint status = 0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void spdc_pen_set_ctrl(SPPenContext *pc, Geom::Point const p, guint state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void spdc_pen_finish_segment(SPPenContext *pc, Geom::Point p, guint state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void spdc_pen_finish(SPPenContext *pc, gboolean closed);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const &bevent);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint pen_handle_2button_press(SPPenContext *const pc, GdkEventButton const &bevent);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void spdc_reset_colors(SPPenContext *pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void pen_disable_events(SPPenContext *const pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void pen_enable_events(SPPenContext *const pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic Geom::Point pen_drag_origin_w(0, 0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic bool pen_within_tolerance = false;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic SPDrawContextClass *pen_parent_class;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic int pen_next_paraxial_direction(const SPPenContext *const pc, Geom::Point const &pt, Geom::Point const &origin, guint state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt, guint const state, bool snap);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Register SPPenContext with Gdk and return its type.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmGType
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmsp_pen_context_get_type(void)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm static GType type = 0;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!type) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm GTypeInfo info = {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sizeof(SPPenContextClass),
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm NULL, NULL,
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm (GClassInitFunc) sp_pen_context_class_init,
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm NULL, NULL,
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sizeof(SPPenContext),
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm 4,
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm (GInstanceInitFunc) sp_pen_context_init,
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm NULL, /* value_table */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm };
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm type = g_type_register_static(SP_TYPE_DRAW_CONTEXT, "SPPenContext", &info, (GTypeFlags)0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return type;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Initialize the SPPenContext vtable.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmsp_pen_context_class_init(SPPenContextClass *klass)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm GObjectClass *object_class;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPEventContextClass *event_context_class;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm object_class = (GObjectClass *) klass;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm event_context_class = (SPEventContextClass *) klass;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_parent_class = (SPDrawContextClass*)g_type_class_peek_parent(klass);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm object_class->dispose = sp_pen_context_dispose;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm event_context_class->setup = sp_pen_context_setup;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm event_context_class->finish = sp_pen_context_finish;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm event_context_class->set = sp_pen_context_set;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm event_context_class->root_handler = sp_pen_context_root_handler;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm event_context_class->item_handler = sp_pen_context_item_handler;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Callback to initialize SPPenContext object.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmsp_pen_context_init(SPPenContext *pc)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm event_context->cursor_shape = cursor_pen_xpm;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm event_context->hot_x = 4;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm event_context->hot_y = 4;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->npoints = 0;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->mode = SP_PEN_CONTEXT_MODE_CLICK;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->state = SP_PEN_CONTEXT_POINT;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->c0 = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->c1 = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->cl0 = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->cl1 = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->events_disabled = 0;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->num_clicks = 0;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->waiting_LPE = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->waiting_item = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Callback to destroy the SPPenContext object's members and itself.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmsp_pen_context_dispose(GObject *object)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPPenContext *pc;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc = SP_PEN_CONTEXT(object);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->c0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gtk_object_destroy(GTK_OBJECT(pc->c0));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->c0 = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->c1) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gtk_object_destroy(GTK_OBJECT(pc->c1));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->c1 = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->cl0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gtk_object_destroy(GTK_OBJECT(pc->cl0));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->cl0 = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->cl1) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gtk_object_destroy(GTK_OBJECT(pc->cl1));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->cl1 = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm G_OBJECT_CLASS(pen_parent_class)->dispose(object);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->expecting_clicks_for_LPE > 0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // we received too few clicks to sanely set the parameter path so we remove the LPE from the item
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_lpe_item_remove_current_path_effect(pc->waiting_item, false);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmvoid
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmsp_pen_context_set_polyline_mode(SPPenContext *const pc) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Inkscape::Preferences *prefs = Inkscape::Preferences::get();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm guint mode = prefs->getInt("/tools/freehand/pen/freehand-mode", 0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->polylines_only = (mode == 2 || mode == 3);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->polylines_paraxial = (mode == 3);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Callback to initialize SPPenContext object.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmsp_pen_context_setup(SPEventContext *ec)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPPenContext *pc;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc = SP_PEN_CONTEXT(ec);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (((SPEventContextClass *) pen_parent_class)->setup) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ((SPEventContextClass *) pen_parent_class)->setup(ec);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Pen indicators */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->c0 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm "size", 4.0, "filled", 0, "fill_color", 0xff00007f, "stroked", 1, "stroke_color", 0x0000ff7f, NULL);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->c1 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm "size", 4.0, "filled", 0, "fill_color", 0xff00007f, "stroked", 1, "stroke_color", 0x0000ff7f, NULL);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->cl0 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_ctrlline_set_rgba32(SP_CTRLLINE(pc->cl0), 0x0000007f);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->cl1 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_ctrlline_set_rgba32(SP_CTRLLINE(pc->cl1), 0x0000007f);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->c0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->c1);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->cl0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->cl1);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_event_context_read(ec, "mode");
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->anchor_statusbar = false;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_pen_context_set_polyline_mode(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Inkscape::Preferences *prefs = Inkscape::Preferences::get();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (prefs->getBool("/tools/freehand/pen/selcue")) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ec->enableSelectionCue();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmpen_cancel (SPPenContext *const pc)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->num_clicks = 0;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->state = SP_PEN_CONTEXT_STOP;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_reset_colors(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->c0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->c1);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->cl0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->cl1);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->_message_context->clear();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->_message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled"));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_end_forced_full_redraws(pc->desktop->canvas);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Finalization callback.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmsp_pen_context_finish(SPEventContext *ec)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPPenContext *pc = SP_PEN_CONTEXT(ec);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_event_context_discard_delayed_snap_event(ec);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->npoints != 0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_cancel (pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (((SPEventContextClass *) pen_parent_class)->finish) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ((SPEventContextClass *) pen_parent_class)->finish(ec);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Callback that sets key to value in pen context.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmsp_pen_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPPenContext *pc = SP_PEN_CONTEXT(ec);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Glib::ustring name = val->getEntryName();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (name == "mode") {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ( val->getString() == "drag" ) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->mode = SP_PEN_CONTEXT_MODE_DRAG;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->mode = SP_PEN_CONTEXT_MODE_CLICK;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Snaps new node relative to the previous node.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmspdc_endpoint_snap(SPPenContext const *const pc, Geom::Point &p, guint const state)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ((state & GDK_CONTROL_MASK) && !pc->polylines_paraxial) { //CTRL enables angular snapping
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->npoints > 0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap_rotation(pc, p, pc->p[0], state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // We cannot use shift here to disable snapping because the shift-key is already used
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // to toggle the paraxial direction; if the user wants to disable snapping (s)he will
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // have to use the %-key, the menu, or the snap toolbar
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ((pc->npoints > 0) && pc->polylines_paraxial) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // snap constrained
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_set_to_nearest_horiz_vert(pc, p, state, true);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // snap freely
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap_free(pc, p, state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Snaps new node's handle relative to the new node.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmspdc_endpoint_snap_handle(SPPenContext const *const pc, Geom::Point &p, guint const state)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm g_return_if_fail(( pc->npoints == 2 ||
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->npoints == 5 ));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ((state & GDK_CONTROL_MASK)) { //CTRL enables angular snapping
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap_rotation(pc, p, pc->p[pc->npoints - 2], state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!(state & GDK_SHIFT_MASK)) { //SHIFT disables all snapping, except the angular snapping above
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap_free(pc, p, state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmsp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPPenContext *const pc = SP_PEN_CONTEXT(ec);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gint ret = FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (event->type) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_BUTTON_PRESS:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = pen_handle_button_press(pc, event->button);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_BUTTON_RELEASE:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = pen_handle_button_release(pc, event->button);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!ret) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (((SPEventContextClass *) pen_parent_class)->item_handler)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = ((SPEventContextClass *) pen_parent_class)->item_handler(ec, item, event);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return ret;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Callback to handle all pen events.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmsp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPPenContext *const pc = SP_PEN_CONTEXT(ec);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gint ret = FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (event->type) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_BUTTON_PRESS:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = pen_handle_button_press(pc, event->button);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_MOTION_NOTIFY:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = pen_handle_motion_notify(pc, event->motion);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_BUTTON_RELEASE:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = pen_handle_button_release(pc, event->button);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_2BUTTON_PRESS:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = pen_handle_2button_press(pc, event->button);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_KEY_PRESS:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = pen_handle_key_press(pc, event);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!ret) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gint (*const parent_root_handler)(SPEventContext *, GdkEvent *)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm = ((SPEventContextClass *) pen_parent_class)->root_handler;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (parent_root_handler) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = parent_root_handler(ec, event);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return ret;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Handle mouse button press event.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const &bevent)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->events_disabled) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // skip event processing if events are disabled
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPDrawContext * const dc = SP_DRAW_CONTEXT(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPDesktop * const desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point const event_w(bevent.x, bevent.y);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point event_dt(desktop->w2d(event_w));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gint ret = FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (bevent.button == 1 && !event_context->space_panning
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // make sure this is not the last click for a waiting LPE (otherwise we want to finish the path)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm && pc->expecting_clicks_for_LPE != 1) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!pc->grab ) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Grab mouse, so release will not pass unnoticed */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->grab = SP_CANVAS_ITEM(desktop->acetate);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_grab(pc->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK |
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm GDK_BUTTON_RELEASE_MASK |
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm GDK_POINTER_MOTION_MASK ),
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm NULL, bevent.time);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_drag_origin_w = event_w;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_within_tolerance = true;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Test whether we hit any anchor. */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPDrawAnchor * const anchor = spdc_test_inside(pc, event_w);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (pc->mode) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_MODE_CLICK:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* In click mode we add point on release */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (pc->state) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_POINT:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CONTROL:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CLOSE:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_STOP:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* This is allowed, if we just canceled curve */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->state = SP_PEN_CONTEXT_POINT;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_MODE_DRAG:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (pc->state) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_STOP:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* This is allowed, if we just canceled curve */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_POINT:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->npoints == 0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point p;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ((bevent.state & GDK_CONTROL_MASK) && (pc->polylines_only || pc->polylines_paraxial)) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm p = event_dt;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!(bevent.state & GDK_SHIFT_MASK)) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SnapManager &m = desktop->namedview->snap_manager;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.setup(desktop);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.unSetup();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_create_single_dot(event_context, p, "/tools/freehand/pen", bevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // TODO: Perhaps it would be nicer to rearrange the following case
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // distinction so that the case of a waiting LPE is treated separately
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Set start anchor */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->sa = anchor;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (anchor && !sp_pen_context_has_waiting_LPE(pc)) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Adjust point to anchor if needed; if we have a waiting LPE, we need
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm a fresh path to be created so don't continue an existing one */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm p = anchor->dp;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path"));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // This is the first click of a new curve; deselect item so that
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // this curve is not combined with it (unless it is drawn from its
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // anchor, which is handled by the sibling branch above)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Inkscape::Selection * const selection = sp_desktop_selection(desktop);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!(bevent.state & GDK_SHIFT_MASK) || sp_pen_context_has_waiting_LPE(pc)) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* if we have a waiting LPE, we need a fresh path to be created
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm so don't append to an existing one */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm selection->clear();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path"));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else if (selection->singleItem() && SP_IS_PATH(selection->singleItem())) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path"));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Create green anchor */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm p = event_dt;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap(pc, p, bevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->green_anchor = sp_draw_anchor_new(pc, pc->green_curve, TRUE, p);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_set_initial_point(pc, p);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Set end anchor */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->ea = anchor;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point p;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (anchor) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm p = anchor->dp;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // we hit an anchor, will finish the curve (either with or without closing)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // in release handler
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->state = SP_PEN_CONTEXT_CLOSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->green_anchor && pc->green_anchor->active) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // we clicked on the current curve start, so close it even if
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // we drag a handle away from it
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm dc->green_closed = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm p = event_dt;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap(pc, p, bevent.state); /* Snap node only if not hitting anchor. */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_set_subsequent_point(pc, p, true);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->state = pc->polylines_only ? SP_PEN_CONTEXT_POINT : SP_PEN_CONTEXT_CONTROL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CONTROL:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm g_warning("Button down in CONTROL state");
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CLOSE:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm g_warning("Button down in CLOSE state");
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else if (pc->expecting_clicks_for_LPE == 1 && pc->npoints != 0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // when the last click for a waiting LPE occurs we want to finish the path
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish_segment(pc, event_dt, bevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->green_closed) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // finishing at the start anchor, close curve
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish(pc, TRUE);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // finishing at some other anchor, finish curve but not close
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish(pc, FALSE);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else if (bevent.button == 3 && pc->npoints != 0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // right click - finish path
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish(pc, FALSE);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->expecting_clicks_for_LPE > 0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm --pc->expecting_clicks_for_LPE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return ret;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Handle motion_notify event.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmpen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gint ret = FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPDesktop * const dt = SP_EVENT_CONTEXT_DESKTOP(event_context);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // allow scrolling
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->events_disabled) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // skip motion events if pen events are disabled
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point const event_w(mevent.x,
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm mevent.y);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pen_within_tolerance) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Inkscape::Preferences *prefs = Inkscape::Preferences::get();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ( Geom::LInfty( event_w - pen_drag_origin_w ) < tolerance ) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return FALSE; // Do not drag if we're within tolerance from origin.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // Once the user has moved farther than tolerance from the original location
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // (indicating they intend to move the object, not click), then always process the
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // motion notify coordinates as given (no snapping back to origin)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_within_tolerance = false;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Find desktop coordinates */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point p = dt->w2d(event_w);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Test, whether we hit any anchor */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPDrawAnchor *anchor = spdc_test_inside(pc, event_w);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (pc->mode) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_MODE_CLICK:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (pc->state) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_POINT:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ( pc->npoints != 0 ) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Only set point, if we are already appending */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap(pc, p, mevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_set_subsequent_point(pc, p, true);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else if (!sp_event_context_knot_mouseover(pc)) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SnapManager &m = dt->namedview->snap_manager;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.setup(dt);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.unSetup();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CONTROL:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CLOSE:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Placing controls is last operation in CLOSE state */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap(pc, p, mevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_set_ctrl(pc, p, mevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_STOP:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* This is perfectly valid */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_MODE_DRAG:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (pc->state) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_POINT:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ( pc->npoints > 0 ) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Only set point, if we are already appending */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!anchor) { /* Snap node only if not hitting anchor */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap(pc, p, mevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_set_subsequent_point(pc, p, true, mevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_set_subsequent_point(pc, anchor->dp, false, mevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (anchor && !pc->anchor_statusbar) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path."));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->anchor_statusbar = true;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else if (!anchor && pc->anchor_statusbar) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->_message_context->clear();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->anchor_statusbar = false;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (anchor && !pc->anchor_statusbar) {
ea8dd7683dd12883474f6cf9b5f424f8ed831166Kris pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point."));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->anchor_statusbar = true;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else if (!anchor && pc->anchor_statusbar) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->_message_context->clear();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->anchor_statusbar = false;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!sp_event_context_knot_mouseover(pc)) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SnapManager &m = dt->namedview->snap_manager;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.setup(dt);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.unSetup();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CONTROL:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CLOSE:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Placing controls is last operation in CLOSE state */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // snap the handle
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap_handle(pc, p, mevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!pc->polylines_only) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_set_ctrl(pc, p, mevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_set_ctrl(pc, pc->p[1], mevent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gobble_motion_events(GDK_BUTTON1_MASK);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_STOP:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* This is perfectly valid */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!sp_event_context_knot_mouseover(pc)) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SnapManager &m = dt->namedview->snap_manager;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.setup(dt);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm m.unSetup();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return ret;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Handle mouse button release event.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmpen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->events_disabled) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // skip event processing if events are disabled
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gint ret = FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ( revent.button == 1 && !event_context->space_panning) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPDrawContext *dc = SP_DRAW_CONTEXT (pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point const event_w(revent.x,
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm revent.y);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Find desktop coordinates */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point p = pc->desktop->w2d(event_w);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Test whether we hit any anchor. */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPDrawAnchor *anchor = spdc_test_inside(pc, event_w);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (pc->mode) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_MODE_CLICK:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (pc->state) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_POINT:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ( pc->npoints == 0 ) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Start new thread only with button release */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (anchor) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm p = anchor->dp;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->sa = anchor;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_set_initial_point(pc, p);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Set end anchor here */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->ea = anchor;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (anchor) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm p = anchor->dp;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->state = SP_PEN_CONTEXT_CONTROL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CONTROL:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* End current segment */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap(pc, p, revent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish_segment(pc, p, revent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->state = SP_PEN_CONTEXT_POINT;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CLOSE:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* End current segment */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!anchor) { /* Snap node only if not hitting anchor */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap(pc, p, revent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish_segment(pc, p, revent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish(pc, TRUE);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->state = SP_PEN_CONTEXT_POINT;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_STOP:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* This is allowed, if we just canceled curve */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->state = SP_PEN_CONTEXT_POINT;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_MODE_DRAG:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (pc->state) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_POINT:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CONTROL:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap(pc, p, revent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish_segment(pc, p, revent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_CLOSE:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_endpoint_snap(pc, p, revent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish_segment(pc, p, revent.state);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->green_closed) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // finishing at the start anchor, close curve
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish(pc, TRUE);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // finishing at some other anchor, finish curve but not close
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish(pc, FALSE);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case SP_PEN_CONTEXT_STOP:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* This is allowed, if we just cancelled curve */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->state = SP_PEN_CONTEXT_POINT;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->grab) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Release grab now */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_ungrab(pc->grab, revent.time);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->grab = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm dc->green_closed = FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // TODO: can we be sure that the path was created correctly?
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // TODO: should we offer an option to collect the clicks in a list?
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->expecting_clicks_for_LPE == 0 && sp_pen_context_has_waiting_LPE(pc)) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_pen_context_set_polyline_mode(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPEventContext *ec = SP_EVENT_CONTEXT(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->waiting_LPE) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // we have an already created LPE waiting for a path
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem()));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm selection->add(SP_OBJECT(pc->waiting_item));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->waiting_LPE = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // the case that we need to create a new LPE and apply it to the just-drawn path is
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // handled in spdc_check_for_and_apply_waiting_LPE() in draw-context.cpp
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return ret;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmpen_handle_2button_press(SPPenContext *const pc, GdkEventButton const &bevent)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gint ret = FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // only end on LMB double click. Otherwise horizontal scrolling causes ending of the path
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->npoints != 0 && bevent.button == 1) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish(pc, FALSE);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return ret;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmvoid
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmpen_redraw_all (SPPenContext *const pc)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // green
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->green_bpaths) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // remove old piecewise green canvasitems
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm while (pc->green_bpaths) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // one canvas bpath for all of green_curve
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), pc->green_curve);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cshape), 0, SP_WIND_RULE_NONZERO);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->green_anchor)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SP_CTRL(pc->green_anchor->ctrl)->moveto(pc->green_anchor->dp);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve->reset();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve->moveto(pc->p[0]);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve->curveto(pc->p[1], pc->p[2], pc->p[3]);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // handles
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->p[0] != pc->p[1]) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SP_CTRL(pc->c1)->moveto(pc->p[1]);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl1), pc->p[0], pc->p[1]);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_show (pc->c1);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_show (pc->cl1);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide (pc->c1);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide (pc->cl1);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Curve const * last_seg = pc->green_curve->last_segment();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (last_seg) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( last_seg );
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ( cubic &&
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm (*cubic)[2] != to_2geom(pc->p[0]) )
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point p2 = (*cubic)[2];
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SP_CTRL(pc->c0)->moveto(p2);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl0), p2, pc->p[0]);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_show (pc->c0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_show (pc->cl0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide (pc->c0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide (pc->cl0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmvoid
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmpen_lastpoint_move (SPPenContext *const pc, gdouble x, gdouble y)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->npoints != 5)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // green
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!pc->green_curve->is_empty()) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->green_curve->last_point_additive_move( Geom::Point(x,y) );
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // start anchor too
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->green_anchor) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->green_anchor->dp += Geom::Point(x, y);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // red
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[0] += Geom::Point(x, y);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[1] += Geom::Point(x, y);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_redraw_all(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmvoid
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmpen_lastpoint_move_screen (SPPenContext *const pc, gdouble x, gdouble y)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_lastpoint_move (pc, x / pc->desktop->current_zoom(), y / pc->desktop->current_zoom());
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmvoid
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmpen_lastpoint_tocurve (SPPenContext *const pc)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->npoints != 5)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( pc->green_curve->last_segment() );
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ( cubic ) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[1] = pc->p[0] + (Geom::Point)( (*cubic)[3] - (*cubic)[2] );
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[1] = pc->p[0] + (1./3)*(pc->p[3] - pc->p[0]);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_redraw_all(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmvoid
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmpen_lastpoint_toline (SPPenContext *const pc)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->npoints != 5)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[1] = pc->p[0];
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_redraw_all(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic gint
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmpen_handle_key_press(SPPenContext *const pc, GdkEvent *event)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gint ret = FALSE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Inkscape::Preferences *prefs = Inkscape::Preferences::get();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm switch (get_group0_keyval (&event->key)) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_Left: // move last point left
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_KP_Left:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_KP_4:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!MOD__CTRL) { // not ctrl
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__ALT) { // alt
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT) pen_lastpoint_move_screen(pc, -10, 0); // shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else pen_lastpoint_move_screen(pc, -1, 0); // no shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else { // no alt
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT) pen_lastpoint_move(pc, -10*nudge, 0); // shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else pen_lastpoint_move(pc, -nudge, 0); // no shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_Up: // move last point up
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_KP_Up:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_KP_8:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!MOD__CTRL) { // not ctrl
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__ALT) { // alt
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 0, 10); // shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else pen_lastpoint_move_screen(pc, 0, 1); // no shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else { // no alt
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT) pen_lastpoint_move(pc, 0, 10*nudge); // shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else pen_lastpoint_move(pc, 0, nudge); // no shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_Right: // move last point right
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_KP_Right:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_KP_6:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!MOD__CTRL) { // not ctrl
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__ALT) { // alt
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 10, 0); // shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else pen_lastpoint_move_screen(pc, 1, 0); // no shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else { // no alt
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT) pen_lastpoint_move(pc, 10*nudge, 0); // shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else pen_lastpoint_move(pc, nudge, 0); // no shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_Down: // move last point down
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_KP_Down:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_KP_2:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!MOD__CTRL) { // not ctrl
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__ALT) { // alt
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 0, -10); // shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else pen_lastpoint_move_screen(pc, 0, -1); // no shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else { // no alt
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT) pen_lastpoint_move(pc, 0, -10*nudge); // shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm else pen_lastpoint_move(pc, 0, -nudge); // no shift
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/* TODO: this is not yet enabled?? looks like some traces of the Geometry tool
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_P:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_p:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT_ONLY) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PARALLEL, 2);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_C:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_c:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT_ONLY) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::CIRCLE_3PTS, 3);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_B:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_b:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT_ONLY) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PERP_BISECTOR, 2);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_A:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_a:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT_ONLY) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::ANGLE_BISECTOR, 3);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm*/
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_U:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_u:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT_ONLY) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_lastpoint_tocurve(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_L:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_l:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT_ONLY) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_lastpoint_toline(pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_Return:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_KP_Enter:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->npoints != 0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_finish(pc, FALSE);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_Escape:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->npoints != 0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // if drawing, cancel, otherwise pass it up for deselecting
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_cancel (pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_z:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_Z:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__CTRL_ONLY && pc->npoints != 0) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // if drawing, cancel, otherwise pass it up for undo
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_cancel (pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_g:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_G:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (MOD__SHIFT_ONLY) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_selection_to_guides(SP_EVENT_CONTEXT(pc)->desktop);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = true;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_BackSpace:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_Delete:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm case GDK_KP_Delete:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ( pc->green_curve->is_empty() || (pc->green_curve->last_segment() == NULL) ) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (!pc->red_curve->is_empty()) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_cancel (pc);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // do nothing; this event should be handled upstream
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Reset red curve */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve->reset();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Destroy topmost green bpath */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->green_bpaths) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->green_bpaths->data)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Get last segment */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ( pc->green_curve->is_empty() ) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm g_warning("pen_handle_key_press, case GDK_KP_Delete: Green curve is empty");
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // The code below assumes that pc->green_curve has only ONE path !
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Curve const * crv = pc->green_curve->last_segment();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[0] = crv->initialPoint();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ( Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>(crv)) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[1] = (*cubic)[1];
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[1] = pc->p[0];
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point const pt(( pc->npoints < 4
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ? (Geom::Point)(crv->finalPoint())
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm : pc->p[3] ));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->npoints = 2;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->green_curve->backspace();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->c0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->c1);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->cl0);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_item_hide(pc->cl1);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->state = SP_PEN_CONTEXT_POINT;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm spdc_pen_set_subsequent_point(pc, pt, true);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_last_paraxial_dir = !pen_last_paraxial_dir;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm ret = TRUE;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm default:
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm break;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm return ret;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmspdc_reset_colors(SPPenContext *pc)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Red */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve->reset();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Blue */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->blue_curve->reset();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->blue_bpath), NULL);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* Green */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm while (pc->green_bpaths) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->green_curve->reset();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->green_anchor) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->sa = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->ea = NULL;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->npoints = 0;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve_is_valid = false;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmspdc_pen_set_initial_point(SPPenContext *const pc, Geom::Point const p)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm g_assert( pc->npoints == 0 );
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[0] = p;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[1] = p;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->npoints = 2;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_force_full_redraw_after_interruptions(pc->desktop->canvas, 5);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm/**
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * Show the status message for the current line/curve segment.
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * This type of message always shows angle/distance as the last
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm * two parameters ("angle %3.2f&#176;, distance %s").
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmspdc_pen_set_angle_distance_status_message(SPPenContext *const pc, Geom::Point const p, int pc_point_to_compare, gchar const *message)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm g_assert(pc != NULL);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm g_assert((pc_point_to_compare == 0) || (pc_point_to_compare == 3)); // exclude control handles
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm g_assert(message != NULL);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point rel = p - pc->p[pc_point_to_compare];
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm GString *dist = SP_PX_TO_METRIC_STRING(Geom::L2(rel), desktop->namedview->getDefaultMetric());
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Inkscape::Preferences *prefs = Inkscape::Preferences::get();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (prefs->getBool("/options/compassangledisplay/value", 0) != 0)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm angle = angle_to_compass (angle);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm g_string_free(dist, FALSE);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm}
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmstatic void
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrmspdc_pen_set_subsequent_point(SPPenContext *const pc, Geom::Point const p, bool statusbar, guint status)
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm{
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm g_assert( pc->npoints != 0 );
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm /* todo: Check callers to see whether 2 <= npoints is guaranteed. */
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[2] = p;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[3] = p;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->p[4] = p;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->npoints = 5;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve->reset();
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm bool is_curve;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve->moveto(pc->p[0]);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->polylines_paraxial && !statusbar) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // we are drawing horizontal/vertical lines and hit an anchor;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point const origin = pc->p[0];
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // if the previous point and the anchor are not aligned either horizontally or vertically...
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if ((abs(p[Geom::X] - origin[Geom::X]) > 1e-9) && (abs(p[Geom::Y] - origin[Geom::Y]) > 1e-9)) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // ...then we should draw an L-shaped path, consisting of two paraxial segments
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm Geom::Point intermed = p;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pen_set_to_nearest_horiz_vert(pc, intermed, status, false);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve->lineto(intermed);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve->lineto(p);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm is_curve = false;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm // one of the 'regular' modes
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (pc->p[1] != pc->p[0]) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve->curveto(pc->p[1], p, p);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm is_curve = true;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm } else {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm pc->red_curve->lineto(p);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm is_curve = false;
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm }
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm if (statusbar) {
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm gchar *message = is_curve ?
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm _("<b>Curve segment</b>: angle %3.2f&#176;, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path" ):
da58597f9f9ecb17c4f545c4483a844a363bcc27pjrm _("<b>Line segment</b>: angle %3.2f&#176;, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path");
a4030d5ca449e7e384bc699cd249ee704faaeab0Chris Morgan spdc_pen_set_angle_distance_status_message(pc, p, 0, message);
}
}
static void
spdc_pen_set_ctrl(SPPenContext *const pc, Geom::Point const p, guint const state)
{
sp_canvas_item_show(pc->c1);
sp_canvas_item_show(pc->cl1);
if ( pc->npoints == 2 ) {
pc->p[1] = p;
sp_canvas_item_hide(pc->c0);
sp_canvas_item_hide(pc->cl0);
SP_CTRL(pc->c1)->moveto(pc->p[1]);
sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl1), pc->p[0], pc->p[1]);
spdc_pen_set_angle_distance_status_message(pc, p, 0, _("<b>Curve handle</b>: angle %3.2f&#176;, length %s; with <b>Ctrl</b> to snap angle"));
} else if ( pc->npoints == 5 ) {
pc->p[4] = p;
sp_canvas_item_show(pc->c0);
sp_canvas_item_show(pc->cl0);
bool is_symm = false;
if ( ( ( pc->mode == SP_PEN_CONTEXT_MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) ||
( ( pc->mode == SP_PEN_CONTEXT_MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) {
Geom::Point delta = p - pc->p[3];
pc->p[2] = pc->p[3] - delta;
is_symm = true;
pc->red_curve->reset();
pc->red_curve->moveto(pc->p[0]);
pc->red_curve->curveto(pc->p[1], pc->p[2], pc->p[3]);
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
}
SP_CTRL(pc->c0)->moveto(pc->p[2]);
sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl0), pc->p[3], pc->p[2]);
SP_CTRL(pc->c1)->moveto(pc->p[4]);
sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl1), pc->p[3], pc->p[4]);
gchar *message = is_symm ?
_("<b>Curve handle, symmetric</b>: angle %3.2f&#176;, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only") :
_("<b>Curve handle</b>: angle %3.2f&#176;, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only");
spdc_pen_set_angle_distance_status_message(pc, p, 3, message);
} else {
g_warning("Something bad happened - npoints is %d", pc->npoints);
}
}
static void
spdc_pen_finish_segment(SPPenContext *const pc, Geom::Point const p, guint const state)
{
if (pc->polylines_paraxial) {
pen_last_paraxial_dir = pen_next_paraxial_direction(pc, p, pc->p[0], state);
}
++pc->num_clicks;
if (!pc->red_curve->is_empty()) {
pc->green_curve->append_continuous(pc->red_curve, 0.0625);
SPCurve *curve = pc->red_curve->copy();
/// \todo fixme:
SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), curve);
curve->unref();
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape);
pc->p[0] = pc->p[3];
pc->p[1] = pc->p[4];
pc->npoints = 2;
pc->red_curve->reset();
}
}
static void
spdc_pen_finish(SPPenContext *const pc, gboolean const closed)
{
if (pc->expecting_clicks_for_LPE > 1) {
// don't let the path be finished before we have collected the required number of mouse clicks
return;
}
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"));
pc->red_curve->reset();
spdc_concat_colors_and_flush(pc, closed);
pc->sa = NULL;
pc->ea = NULL;
pc->npoints = 0;
pc->state = SP_PEN_CONTEXT_POINT;
sp_canvas_item_hide(pc->c0);
sp_canvas_item_hide(pc->c1);
sp_canvas_item_hide(pc->cl0);
sp_canvas_item_hide(pc->cl1);
if (pc->green_anchor) {
pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor);
}
sp_canvas_end_forced_full_redraws(pc->desktop->canvas);
pen_enable_events(pc);
}
static void
pen_disable_events(SPPenContext *const pc) {
pc->events_disabled++;
}
static void
pen_enable_events(SPPenContext *const pc) {
g_return_if_fail(pc->events_disabled != 0);
pc->events_disabled--;
}
void
sp_pen_context_wait_for_LPE_mouse_clicks(SPPenContext *pc, Inkscape::LivePathEffect::EffectType effect_type,
unsigned int num_clicks, bool use_polylines)
{
if (effect_type == Inkscape::LivePathEffect::INVALID_LPE)
return;
pc->waiting_LPE_type = effect_type;
pc->expecting_clicks_for_LPE = num_clicks;
pc->polylines_only = use_polylines;
pc->polylines_paraxial = false; // TODO: think if this is correct for all cases
}
void
sp_pen_context_cancel_waiting_for_LPE(SPPenContext *pc)
{
pc->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE;
pc->expecting_clicks_for_LPE = 0;
sp_pen_context_set_polyline_mode(pc);
}
static int pen_next_paraxial_direction(const SPPenContext *const pc,
Geom::Point const &pt, Geom::Point const &origin, guint state) {
/*
* after the first mouse click we determine whether the mouse pointer is closest to a
* horizontal or vertical segment; for all subsequent mouse clicks, we use the direction
* orthogonal to the last one; pressing Shift toggles the direction
*/
// num_clicks is not reliable because spdc_pen_finish_segment is sometimes called too early
// (on first mouse release), in which case num_clicks immediately becomes 1.
// if (pc->num_clicks == 0) {
if (pc->green_curve->is_empty()) {
// first mouse click
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;
} else {
// subsequent mouse click
return (state & GDK_SHIFT_MASK) ? pen_last_paraxial_dir : 1 - pen_last_paraxial_dir;
}
}
void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt, guint const state, bool snap)
{
Geom::Point const origin = pc->p[0];
int next_dir = pen_next_paraxial_direction(pc, pt, origin, state);
if (!snap) {
if (next_dir == 0) {
// line is forced to be horizontal
pt[Geom::Y] = origin[Geom::Y];
} else {
// line is forced to be vertical
pt[Geom::X] = origin[Geom::X];
}
} else {
// Create a horizontal or vertical constraint line
Inkscape::Snapper::SnapConstraint cl(origin, next_dir ? Geom::Point(0, 1) : Geom::Point(1, 0));
// Snap along the constraint line; if we didn't snap then still the constraint will be applied
SnapManager &m = pc->desktop->namedview->snap_manager;
Inkscape::Selection *selection = sp_desktop_selection (pc->desktop);
// selection->singleItem() is the item that is currently being drawn. This item will not be snapped to (to avoid self-snapping)
// TODO: Allow snapping to the stationary parts of the item, and only ignore the last segment
m.setup(pc->desktop, true, selection->singleItem());
m.constrainedSnapReturnByRef(pt, Inkscape::SNAPSOURCE_NODE_HANDLE, cl);
m.unSetup();
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :