pen-context.cpp revision 8dc2ff4ddcbbce632cd8a6434acf6d9113e39757
/** \file
* Pen event context implementation.
*/
/*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 2000 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
* Copyright (C) 2002 Lauris Kaplinski
* Copyright (C) 2004 Monash University
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <gdk/gdkkeysyms.h>
#include <cstring>
#include <string>
#include "pen-context.h"
#include "sp-namedview.h"
#include "sp-metrics.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "selection.h"
#include "selection-chemistry.h"
#include "draw-anchor.h"
#include "message-stack.h"
#include "message-context.h"
#include "prefs-utils.h"
#include "sp-path.h"
#include "pixmaps/cursor-pen.xpm"
#include "display/canvas-bpath.h"
#include "display/sp-ctrlline.h"
#include "display/sodipodi-ctrl.h"
#include "libnr/nr-point-ops.h"
#include "macros.h"
#include "context-fns.h"
static gint sp_pen_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
static void spdc_pen_set_subsequent_point(SPPenContext *const pc, NR::Point const p, bool statusbar, guint status = 0);
static bool pen_within_tolerance = false;
static SPDrawContextClass *pen_parent_class;
static int pen_next_paraxial_direction(const SPPenContext *const pc, NR::Point const &pt, NR::Point const &origin, guint state);
static void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, NR::Point &pt, guint const state);
static NR::Point pen_get_intermediate_horiz_vert(const SPPenContext *const pc, NR::Point const &pt, guint const state);
static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical
/**
* Register SPPenContext with Gdk and return its type.
*/
sp_pen_context_get_type(void)
{
if (!type) {
sizeof(SPPenContextClass),
sizeof(SPPenContext),
4,
NULL, /* value_table */
};
}
return type;
}
/**
* Initialize the SPPenContext vtable.
*/
static void
{
}
/**
* Callback to initialize SPPenContext object.
*/
static void
{
pc->events_disabled = 0;
pc->num_clicks = 0;
}
/**
* Callback to destroy the SPPenContext object's members and itself.
*/
static void
{
}
}
}
}
if (pc->expecting_clicks_for_LPE > 0) {
// we received too few clicks to sanely set the parameter path so we remove the LPE from the item
}
}
void
}
/**
* Callback to initialize SPPenContext object.
*/
static void
{
}
/* Pen indicators */
pc->c0 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
"size", 4.0, "filled", 0, "fill_color", 0xff00007f, "stroked", 1, "stroke_color", 0x0000ff7f, NULL);
pc->c1 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
"size", 4.0, "filled", 0, "fill_color", 0xff00007f, "stroked", 1, "stroke_color", 0x0000ff7f, NULL);
pc->cl0 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL);
pc->cl1 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL);
pc->anchor_statusbar = false;
ec->enableSelectionCue();
}
}
static void
{
pc->num_clicks = 0;
}
/**
* Finalization callback.
*/
static void
{
pen_cancel (pc);
}
}
}
/**
* Callback that sets key to value in pen context.
*/
static void
{
} else {
}
}
}
/**
* Snaps new node relative to the previous node.
*/
static void
{
/*** old code: ***/
/***
if (pc->polylines_paraxial) {
pen_set_to_nearest_horiz_vert(pc, p, state);
// TODO: another (constrained) snap required?
} else {
if ((state & GDK_CONTROL_MASK)) { //CTRL enables angular snapping
if (pc->npoints > 0) {
spdc_endpoint_snap_rotation(pc, p, pc->p[0], state);
}
} else {
if (!(state & GDK_SHIFT_MASK)) { //SHIFT disables all snapping, except the angular snapping above
//After all, the user explicitely asked for angular snapping by
//pressing CTRL
spdc_endpoint_snap_free(pc, p, state);
}
}
}
**/
}
} else {
//After all, the user explicitely asked for angular snapping by
//pressing CTRL
}
}
if (pc->polylines_paraxial) {
// TODO: must we avoid one of the snaps in the previous case distinction in some situations?
}
}
/**
* Snaps new node's handle relative to the new node.
*/
static void
{
} else {
}
}
}
static gint
{
case GDK_BUTTON_PRESS:
break;
case GDK_BUTTON_RELEASE:
break;
default:
break;
}
if (!ret) {
}
return ret;
}
/**
* Callback to handle all pen events.
*/
static gint
{
case GDK_BUTTON_PRESS:
break;
case GDK_MOTION_NOTIFY:
break;
case GDK_BUTTON_RELEASE:
break;
case GDK_2BUTTON_PRESS:
break;
case GDK_KEY_PRESS:
break;
default:
break;
}
if (!ret) {
if (parent_root_handler) {
}
}
return ret;
}
/**
* Handle mouse button press event.
*/
{
if (pc->events_disabled) {
// skip event processing if events are disabled
return FALSE;
}
// when the last click for a waiting LPE occurs we want to finish the path
return TRUE;
}
/* Grab mouse, so release will not pass unnoticed */
}
pen_within_tolerance = true;
/* Test whether we hit any anchor. */
/* In click mode we add point on release */
case SP_PEN_CONTEXT_POINT:
case SP_PEN_CONTEXT_CONTROL:
case SP_PEN_CONTEXT_CLOSE:
break;
case SP_PEN_CONTEXT_STOP:
/* This is allowed, if we just cancelled curve */
break;
default:
break;
}
break;
case SP_PEN_CONTEXT_MODE_DRAG:
case SP_PEN_CONTEXT_STOP:
/* This is allowed, if we just cancelled curve */
case SP_PEN_CONTEXT_POINT:
break;
}
// TODO: Perhaps it would be nicer to rearrange the following case
// distinction so that the case of a waiting LPE is treated separately
/* Set start anchor */
/* Adjust point to anchor if needed; if we have a waiting LPE, we need
a fresh path to be created so don't continue an existing one */
} else {
// This is the first click of a new curve; deselect item so that
// this curve is not combined with it (unless it is drawn from its
// anchor, which is handled by the sibling branch above)
/* if we have a waiting LPE, we need a fresh path to be created
so don't append to an existing one */
}
/* Create green anchor */
p = event_dt;
if (!pc->polylines_paraxial) {
// only snap the starting point if we're not in horizontal/vertical mode
// because otherwise it gets shifted; TODO: why do we snap here at all??
}
}
} else {
/* Set end anchor */
if (anchor) {
// we hit an anchor, will finish the curve (either with or without closing)
// in release handler
// we clicked on the current curve start, so close it even if
// we drag a handle away from it
}
break;
} else {
p = event_dt;
spdc_pen_set_subsequent_point(pc, p, true);
if (pc->polylines_only) {
}
}
}
break;
case SP_PEN_CONTEXT_CONTROL:
g_warning("Button down in CONTROL state");
break;
case SP_PEN_CONTEXT_CLOSE:
g_warning("Button down in CLOSE state");
break;
default:
break;
}
break;
default:
break;
}
} else if (bevent.button == 3 || pc->expecting_clicks_for_LPE == 1) { // when the last click for a waiting LPE occurs we want to finish the path
if (pc->green_closed) {
// finishing at the start anchor, close curve
} else {
// finishing at some other anchor, finish curve but not close
}
}
}
if (pc->expecting_clicks_for_LPE) {
}
return ret;
}
/**
* Handle motion_notify event.
*/
static gint
{
if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
// allow scrolling
return FALSE;
}
if (pc->events_disabled) {
// skip motion events if pen events are disabled
return FALSE;
}
mevent.y);
if (pen_within_tolerance) {
"value", 0, 0, 100);
return FALSE; // Do not drag if we're within tolerance from origin.
}
}
// Once the user has moved farther than tolerance from the original location
// (indicating they intend to move the object, not click), then always process the
// motion notify coordinates as given (no snapping back to origin)
pen_within_tolerance = false;
/* Find desktop coordinates */
/* Test, whether we hit any anchor */
case SP_PEN_CONTEXT_POINT:
/* Only set point, if we are already appending */
spdc_pen_set_subsequent_point(pc, p, true);
}
break;
case SP_PEN_CONTEXT_CONTROL:
case SP_PEN_CONTEXT_CLOSE:
/* Placing controls is last operation in CLOSE state */
break;
case SP_PEN_CONTEXT_STOP:
/* This is perfectly valid */
break;
default:
break;
}
break;
case SP_PEN_CONTEXT_MODE_DRAG:
case SP_PEN_CONTEXT_POINT:
/* Only set point, if we are already appending */
if (!anchor) { /* Snap node only if not hitting anchor */
}
pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path."));
pc->anchor_statusbar = true;
pc->anchor_statusbar = false;
}
} else {
pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point."));
pc->anchor_statusbar = true;
pc->anchor_statusbar = false;
}
}
break;
case SP_PEN_CONTEXT_CONTROL:
case SP_PEN_CONTEXT_CLOSE:
/* Placing controls is last operation in CLOSE state */
// snap the handle
if (!pc->polylines_only) {
} else {
}
break;
case SP_PEN_CONTEXT_STOP:
/* This is perfectly valid */
break;
default:
break;
}
break;
default:
break;
}
return ret;
}
/**
* Handle mouse button release event.
*/
static gint
{
if (pc->events_disabled) {
// skip event processing if events are disabled
return FALSE;
}
revent.y);
/* Find desktop coordinates */
/* Test whether we hit any anchor. */
case SP_PEN_CONTEXT_POINT:
/* Start new thread only with button release */
if (anchor) {
}
} else {
/* Set end anchor here */
if (anchor) {
}
}
break;
case SP_PEN_CONTEXT_CONTROL:
/* End current segment */
break;
case SP_PEN_CONTEXT_CLOSE:
/* End current segment */
if (!anchor) { /* Snap node only if not hitting anchor */
}
break;
case SP_PEN_CONTEXT_STOP:
/* This is allowed, if we just cancelled curve */
break;
default:
break;
}
break;
case SP_PEN_CONTEXT_MODE_DRAG:
case SP_PEN_CONTEXT_POINT:
case SP_PEN_CONTEXT_CONTROL:
if (!pc->polylines_only) {
}
break;
case SP_PEN_CONTEXT_CLOSE:
if (pc->green_closed) {
// finishing at the start anchor, close curve
} else {
// finishing at some other anchor, finish curve but not close
}
break;
case SP_PEN_CONTEXT_STOP:
/* This is allowed, if we just cancelled curve */
break;
default:
break;
}
break;
default:
break;
}
/* Release grab now */
}
}
// TODO: can we be sure that the path was created correctly?
// TODO: should we offer an option to collect the clicks in a list?
if (pc->waiting_LPE) {
// we have an already created LPE waiting for a path
} else {
// the case that we need to create a new LPE and apply it to the just-drawn path is
// handled in spdc_check_for_and_apply_waiting_LPE() in draw-context.cpp
}
}
return ret;
}
static gint
{
}
return ret;
}
void
{
// green
if (pc->green_bpaths) {
// remove old piecewise green canvasitems
while (pc->green_bpaths) {
}
// one canvas bpath for all of green_curve
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
if (pc->green_anchor)
// handles
} else {
}
if (last_seg) {
if ( cubic &&
{
} else {
}
}
}
void
{
return;
// green
} else {
// start anchor too
if (pc->green_anchor) {
}
}
// red
}
void
{
}
void
{
return;
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( pc->green_curve->last_segment() );
if ( cubic ) {
} else {
}
}
void
{
return;
}
static gint
{
gdouble const nudge = prefs_get_double_attribute_limited("options.nudgedistance", "value", 2, 0, 1000); // in px
case GDK_Left: // move last point left
case GDK_KP_Left:
case GDK_KP_4:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
else { // no alt
}
}
break;
case GDK_Up: // move last point up
case GDK_KP_Up:
case GDK_KP_8:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
else { // no alt
}
}
break;
case GDK_Right: // move last point right
case GDK_KP_Right:
case GDK_KP_6:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
else { // no alt
}
}
break;
case GDK_Down: // move last point down
case GDK_KP_Down:
case GDK_KP_2:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
else { // no alt
}
}
break;
case GDK_P:
case GDK_p:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_C:
case GDK_c:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_B:
case GDK_b:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_A:
case GDK_a:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_U:
case GDK_u:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_L:
case GDK_l:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_Return:
case GDK_KP_Enter:
}
break;
case GDK_Escape:
// if drawing, cancel, otherwise pass it up for deselecting
pen_cancel (pc);
}
break;
case GDK_z:
case GDK_Z:
// if drawing, cancel, otherwise pass it up for undo
pen_cancel (pc);
}
break;
case GDK_g:
case GDK_G:
if (MOD__SHIFT_ONLY) {
ret = true;
}
break;
case GDK_BackSpace:
case GDK_Delete:
case GDK_KP_Delete:
pen_cancel (pc);
} else {
// do nothing; this event should be handled upstream
}
} else {
/* Reset red curve */
/* Destroy topmost green bpath */
if (pc->green_bpaths) {
}
/* Get last segment */
g_warning("pen_handle_key_press, case GDK_KP_Delete: Green curve is empty");
break;
}
// The code below assumes that pc->green_curve has only ONE path !
} else {
}
: pc->p[3] ));
}
break;
default:
break;
}
return ret;
}
static void
{
/* Red */
/* Blue */
/* Green */
while (pc->green_bpaths) {
}
if (pc->green_anchor) {
}
pc->red_curve_is_valid = false;
}
static void
{
pc->p[0] = p;
pc->p[1] = p;
}
/**
* two parameters ("angle %3.2f°, distance %s").
*/
static void
spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, NR::Point const p, int pc_point_to_compare, gchar const *message)
{
}
static void
spdc_pen_set_subsequent_point(SPPenContext *const pc, NR::Point const p, bool statusbar, guint status)
{
/* todo: Check callers to see whether 2 <= npoints is guaranteed. */
pc->p[2] = p;
pc->p[3] = p;
pc->p[4] = p;
bool is_curve;
// we are drawing horizontal/vertical lines and hit an anchor; draw an L-shaped path
is_curve = false;
} else {
// one of the 'regular' modes
{
is_curve = true;
} else {
is_curve = false;
}
}
if (statusbar) {
_("<b>Curve segment</b>: angle %3.2f°, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path" ):
_("<b>Line segment</b>: angle %3.2f°, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path");
}
}
static void
{
pc->p[1] = p;
spdc_pen_set_angle_distance_status_message(pc, p, 0, _("<b>Curve handle</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle"));
pc->p[4] = p;
bool is_symm = false;
is_symm = true;
}
_("<b>Curve handle, symmetric</b>: angle %3.2f°, 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°, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only");
} else {
}
}
static void
{
if (pc->polylines_paraxial) {
}
++pc->num_clicks;
/// \todo fixme:
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
}
static void
{
// don't let the path be finished before we have collected the required number of mouse clicks
return;
}
pc->num_clicks = 0;
if (pc->green_anchor) {
}
}
static void
pc->events_disabled++;
}
static void
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)
{
g_print ("Now waiting for %s to be applied\n",
}
/*
* 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
*/
if (pc->num_clicks == 0) {
// first mouse click
return pen_last_paraxial_dir;
} else {
// subsequent mouse click
}
}
{
if (next_dir == 0) {
// line is forced to be horizontal
} else {
// line is forced to be vertical
}
}
{
if (pen_last_paraxial_dir == 0) {
} else {
}
}
/*
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:encoding=utf-8:textwidth=99 :