pen-context.cpp revision 32d45022bee1aac3efef2614be44ea1faf944227
/** \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 "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/n-art-bpath.h"
#include "macros.h"
#include "context-fns.h"
static gint sp_pen_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
static bool pen_within_tolerance = false;
static SPDrawContextClass *pen_parent_class;
/**
* 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;
}
/**
* Callback to destroy the SPPenContext object's members and itself.
*/
static 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
{
}
/**
* 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
{
}
}
/**
* Snaps new node's handle relative to the new node.
*/
static void
{
}
static gint
{
case GDK_BUTTON_PRESS:
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;
}
return TRUE;
}
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:
freehand_create_single_dot(event_context, event_dt, "tools.freehand.pen", bevent.state & GDK_SHIFT_MASK);
break;
}
/* Set start anchor */
if (anchor) {
/* Adjust point to anchor if needed */
} 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)
}
/* Create green anchor */
p = event_dt;
}
} 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);
}
}
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;
}
if (pc->green_closed) {
// finishing at the start anchor, close curve
} else {
// finishing at some other anchor, finish curve but not close
}
}
}
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;
/* Grab mouse, so release will not pass unnoticed */
}
/* 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
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:
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 */
}
}
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 (bpath) {
} else {
}
}
}
void
{
return;
// green
if (bpath) {
}
} else {
// start anchor too
if (pc->green_anchor) {
}
}
// red
}
void
{
}
void
{
return;
// red
} 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_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 {
/* Reset red curve */
/* Destroy topmost green bpath */
if (pc->green_bpaths) {
}
/* Get last segment */
if ( e < 2 ) {
g_warning("Green curve length is %d", e);
break;
}
} else {
}
? p[e - 1].c(3)
: 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;
}
static void
{
/* 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;
if ( (pc->onlycurves)
{
is_curve = true;
} else {
is_curve = false;
}
if (statusbar) {
// status text
pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>%s</b>: angle %3.2f°, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path"), is_curve? "Curve segment" : "Line segment", angle, dist->str);
}
}
static void
{
pc->p[1] = p;
// status text
pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Curve handle</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle"), angle, dist->str);
pc->p[4] = p;
bool is_symm = false;
is_symm = true;
}
// status text
pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>%s</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only"), is_symm? "Curve handle, symmetric" : "Curve handle", angle, dist->str);
} else {
}
}
static void
{
/// \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
{
if (pc->green_anchor) {
}
}
static void
pc->events_disabled++;
}
static void
pc->events_disabled--;
}
/*
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 :