pencil-context.cpp revision 1137482ecab2928952d08127515e9d0fc31a29d4
/** \file
* Pencil event context implementation.
*/
/*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Jon A. Cruz <jon@joncruz.org>
*
* 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 "pencil-context.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 "modifier-fns.h"
#include "sp-path.h"
#include "preferences.h"
#include "snap.h"
#include "pixmaps/cursor-pencil.xpm"
#include "display/canvas-bpath.h"
#include "context-fns.h"
#include "sp-namedview.h"
#include "document.h"
#include "desktop-style.h"
#include "macros.h"
#include "display/sp-canvas.h"
static gint pencil_handle_key_press(SPPencilContext *const pc, guint const keyval, guint const state);
static gint pencil_handle_key_release(SPPencilContext *const pc, guint const keyval, guint const state);
static bool pencil_within_tolerance = false;
#include "tool-factory.h"
namespace {
return new SPPencilContext();
}
bool pencilContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pencil", createPencilContext);
}
return SPPencilContext::prefsPath;
}
SPPencilContext* pc = this;
pc->is_drawing = false;
// since SPPencilContext is not properly constructed...
}
void SPPencilContext::setup() {
SPEventContext* ec = this;
ec->enableSelectionCue();
}
// if (((SPEventContextClass *) sp_pencil_context_parent_class)->setup) {
// ((SPEventContextClass *) sp_pencil_context_parent_class)->setup(ec);
// }
SPDrawContext::setup();
pc->is_drawing = false;
pc->anchor_statusbar = false;
}
}
/** Snaps new node relative to the previous node. */
static void
{
}
} else {
//After all, the user explicitely asked for angular snapping by
//pressing CTRL
}
}
}
/**
* Callback for handling all pencil context events.
*/
SPEventContext* ec = this;
case GDK_BUTTON_PRESS:
break;
case GDK_MOTION_NOTIFY:
break;
case GDK_BUTTON_RELEASE:
break;
case GDK_KEY_PRESS:
break;
case GDK_KEY_RELEASE:
break;
default:
break;
}
if (!ret) {
// gint (*const parent_root_handler)(SPEventContext *, GdkEvent *)
// = ((SPEventContextClass *) sp_pencil_context_parent_class)->root_handler;
// if (parent_root_handler) {
// ret = parent_root_handler(ec, event);
// }
}
return ret;
}
static gint
{
return TRUE;
}
/* Grab mouse, so release will not pass unnoticed */
}
/* Find desktop coordinates */
/* Test whether we hit any anchor. */
pencil_within_tolerance = true;
/* Current segment will be finished with release */
break;
default:
/* Set first point of sequence */
}
m.unSetup();
ret = true;
break;
}
if (anchor) {
} 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)
}
m.unSetup();
}
spdc_set_startpoint(pc, p);
break;
}
pc->is_drawing = true;
}
return ret;
}
static gint
{
// mouse was accidentally moved during Ctrl+click;
// ignore the motion and create a single point
pc->is_drawing = false;
return TRUE;
}
if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
// allow scrolling
return FALSE;
}
/* Grab mouse, so release will not pass unnoticed */
}
/* Find desktop coordinates */
/* Test whether we hit any anchor. */
if (pencil_within_tolerance) {
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)
pencil_within_tolerance = false;
/* Set red endpoint */
if (anchor) {
} else {
p = ptnr;
}
spdc_set_endpoint(pc, p);
break;
default:
/* We may be idle or already freehand */
}
/* Create green anchor */
}
if (anchor) {
}
// Only in freehand mode we have to add the first point also to pc->ps (apparently)
// - We cannot add this point in spdc_set_startpoint, because we only need it for freehand
// - We cannot do this in the button press handler because at that point we don't know yet
// wheter we're going into freehand mode or not
}
}
pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Release</b> here to close and finish the path."));
pc->anchor_statusbar = true;
pc->anchor_statusbar = false;
} else if (!anchor) {
}
} else {
pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to continue the path from this point."));
pc->anchor_statusbar = true;
pc->anchor_statusbar = false;
}
}
// a) press the mousebutton to start a freehand drawing, or
// b) release the mousebutton to finish a freehand drawing
if (!sp_event_context_knot_mouseover(pc)) {
m.unSetup();
}
break;
}
return ret;
}
static gint
{
pc->is_drawing = false;
/* Find desktop coordinates */
/* Test whether we hit any anchor. */
revent.y));
case SP_PENCIL_CONTEXT_IDLE:
/* Releasing button in idle mode means single click */
// Ctrl+click creates a single point so only set context in ADDLINE mode when Ctrl isn't pressed
}
break;
/* Finish segment now */
if (anchor) {
} else {
}
spdc_set_endpoint(pc, p);
break;
/* sketch mode: interpolate the sketched path and improve the current output path with the new interpolation. don't finish sketch */
if (pc->green_anchor) {
}
} else {
/* Finish segment now */
/// \todo fixme: Clean up what follows (Lauris)
if (anchor) {
} else {
if (p_end != p) {
// then we must have snapped!
}
}
/* Write curves to object */
if (pc->green_anchor) {
}
// reset sketch mode too
}
break;
case SP_PENCIL_CONTEXT_SKETCH:
default:
break;
}
/* Release grab now */
}
}
return ret;
}
static void
{
/* Release grab now */
}
pc->is_drawing = false;
while (pc->green_bpaths) {
}
if (pc->green_anchor) {
}
}
static gint
{
switch (keyval) {
case GDK_KEY_Up:
case GDK_KEY_Down:
case GDK_KEY_KP_Up:
case GDK_KEY_KP_Down:
// Prevent the zoom field from activation.
if (!mod_ctrl_only(state)) {
}
break;
case GDK_KEY_Escape:
// if drawing, cancel, otherwise pass it up for deselecting
pencil_cancel (pc);
}
}
break;
case GDK_KEY_z:
case GDK_KEY_Z:
// if drawing, cancel, otherwise pass it up for undo
pencil_cancel (pc);
}
}
break;
case GDK_KEY_g:
case GDK_KEY_G:
if (mod_shift_only(state)) {
ret = true;
}
break;
case GDK_KEY_Alt_L:
case GDK_KEY_Alt_R:
case GDK_KEY_Meta_L:
case GDK_KEY_Meta_R:
pc->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("<b>Sketch mode</b>: holding <b>Alt</b> interpolates between sketched paths. Release <b>Alt</b> to finalize."));
}
break;
default:
break;
}
return ret;
}
static gint
{
switch (keyval) {
case GDK_KEY_Alt_L:
case GDK_KEY_Alt_R:
case GDK_KEY_Meta_L:
case GDK_KEY_Meta_R:
if (pc->green_anchor) {
}
}
break;
default:
break;
}
return ret;
}
/**
* Reset points and set new starting point.
*/
static void
{
pc->red_curve_is_valid = false;
if (in_svg_plane(p)) {
}
}
/**
* Change moving endpoint position.
* <ul>
* <li>Ctrl constrains to moving to H/V direction, snapping in given direction.
* <li>Otherwise we snap freely to whatever attractors are available.
* </ul>
*
* Number of points is (re)set to 2 always, 2nd point is modified.
* We change RED curve.
*/
static void
{
return;
/* May occur if first point wasn't in SVG plane (e.g. weird w2d transform, perhaps from bad
* zoom setting).
*/
}
if ( ( p == pc->p[0] )
|| !in_svg_plane(p) )
{
} else {
pc->p[1] = p;
pc->red_curve_is_valid = true;
}
}
/**
* Finalize addline.
*
* \todo
* fixme: I'd like remove red reset from concat colors (lauris).
* Still not sure, how it will make most sense.
*/
static void
{
{
} else {
/* Write curves to object. */
}
}
static void
{
&& in_svg_plane(p) )
{
}
}
static inline double
square(double const x)
{
return x * x;
}
static void
{
return;
}
double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4;
pc->red_curve_is_valid = false;
}
// worst case gives us a segment per point
if ( n_segs > 0)
{
/* Fit and draw and reset state */
for (int c = 0; c < n_segs; c++) {
}
/* Fit and draw and copy last point */
/* Set up direction of next curve. */
{
delete last_seg_reverse;
}
}
g_free(b);
}
/* interpolates the sketched curve and tweaks the current sketch interpolation*/
static void
{
return;
}
double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4;
pc->red_curve_is_valid = false;
}
// worst case gives us a segment per point
if ( n_segs > 0)
{
for (int c = 0; c < n_segs; c++) {
}
double t =0.;
if (average_all_sketches) {
// Average = (sum of all) / n
// = (sum of all + new one) / n+1
// = ((old average)*n + new one) / n+1
} else {
t = 0.5;
}
// simplify path, to eliminate small segments
delete path;
delete pathv;
} else {
}
/* Fit and draw and copy last point */
/* Set up direction of next curve. */
{
delete last_seg_reverse;
}
}
g_free(b);
}
static void
{
double const tolerance_sq = 0;
tolerance_sq, 1);
if ( n_segs > 0
{
/* Fit and draw and reset state */
pc->red_curve_is_valid = true;
} else {
/* Fit and draw and copy last point */
/* Set up direction of next curve. */
{
delete last_seg_reverse;
}
/// \todo fixme:
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
pc->red_curve_is_valid = false;
}
}
/*
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 :