eraser-context.cpp revision 61f0bc9dfe9dee35ba3522153a7409cceb8434cd
/*
* Eraser drawing mode
*
* Authors:
* Mitsuru Oka <oka326@parkcity.ne.jp>
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* MenTaLguY <mental@rydia.net>
* Jon A. Cruz <jon@joncruz.org>
*
* The original dynadraw code:
* Paul Haeberli <paul@sgi.com>
*
* Copyright (C) 1998 The Free Software Foundation
* Copyright (C) 1999-2005 authors
* Copyright (C) 2001-2002 Ximian, Inc.
* Copyright (C) 2005-2007 bulia byak
* Copyright (C) 2006 MenTaLguY
* Copyright (C) 2008 Jon A. Cruz
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#define noERASER_VERBOSE
#include "config.h"
#include <gdk/gdkkeysyms.h>
#include <string>
#include <cstring>
#include <numeric>
#include "display/canvas-bpath.h"
#include "display/bezier-utils.h"
#include "macros.h"
#include "document.h"
#include "selection.h"
#include "desktop.h"
#include "desktop-events.h"
#include "desktop-handles.h"
#include "desktop-affine.h"
#include "desktop-style.h"
#include "message-context.h"
#include "prefs-utils.h"
#include "pixmaps/cursor-eraser.xpm"
#include "context-fns.h"
#include "sp-item.h"
#include "inkscape.h"
#include "color.h"
#include "rubberband.h"
#include "splivarot.h"
#include "sp-item-group.h"
#include "sp-shape.h"
#include "sp-path.h"
#include "sp-text.h"
#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
#include "eraser-context.h"
#define ERC_RED_RGBA 0xff0000ff
#define TOLERANCE_ERASER 0.1
#define ERASER_EPSILON 0.5e-6
#define ERASER_EPSILON_START 0.5e-2
#define ERASER_VEL_START 1e-5
#define DRAG_MIN 0.0
#define DRAG_DEFAULT 1.0
#define DRAG_MAX 1.0
static void add_cap(SPCurve *curve, NR::Point const &pre, NR::Point const &from, NR::Point const &to, NR::Point const &post, double rounding);
static SPEventContextClass *eraser_parent_class = 0;
{
if (!type) {
sizeof(SPEraserContextClass),
0, // base_init
0, // base_finalize
0, // class_finalize
0, // class_data
sizeof(SPEraserContext),
0, // n_preallocs
0 // value_table
};
type = g_type_register_static(SP_TYPE_COMMON_CONTEXT, "SPEraserContext", &info, static_cast<GTypeFlags>(0));
}
return type;
}
static void
{
}
static void
{
}
static void
{
//SPEraserContext *erc = SP_ERASER_CONTEXT(object);
}
static void
{
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(erc->currentshape), 0x00000000, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
/* fixme: Cannot we cascade it to root more clearly? */
g_signal_connect(G_OBJECT(erc->currentshape), "event", G_CALLBACK(sp_desktop_root_handler), ec->desktop);
/*
static ProfileFloatElement f_profile[PROFILE_FLOAT_SIZE] = {
{"mass",0.02, 0.0, 1.0},
{"wiggle",0.0, 0.0, 1.0},
{"angle",30.0, -90.0, 90.0},
{"thinning",0.1, -1.0, 1.0},
{"tremor",0.0, 0.0, 1.0},
{"flatness",0.9, 0.0, 1.0},
{"cap_rounding",0.0, 0.0, 5.0}
};
*/
erc->is_drawing = false;
ec->enableSelectionCue();
}
// TODO temp force:
ec->enableSelectionCue();
}
static void
{
//pass on up to parent class to handle common attributes.
if ( eraser_parent_class->set ) {
}
}
static double
{
}
/* Get normalized point */
{
}
/* Get view point */
{
}
static void
{
}
static void
{
else
else
else
}
static gboolean
{
/* Calculate mass and drag */
/* Calculate force and acceleration */
// If force is below the absolute threshold ERASER_EPSILON,
// or we haven't yet reached ERASER_VEL_START (i.e. at the beginning of stroke)
// _and_ the force is below the (higher) ERASER_EPSILON_START threshold,
// discard this move.
// This prevents flips, blobs, and jerks caused by microscopic tremor of the tablet pen,
// especially bothersome at the start of the stroke where we don't yet have the inertia to
// smooth them out.
if ( NR::L2(force) < ERASER_EPSILON || (dc->vel_max < ERASER_VEL_START && NR::L2(force) < ERASER_EPSILON_START)) {
return FALSE;
}
/* Calculate new velocity */
/* Calculate angle of drawing tool */
double a1;
// 1a. calculate nib angle from input device tilt:
if (length > 0) {
}
else
a1 = 0.0;
}
else {
// 1b. fixed dc->angle (absolutely flat nib):
}
// 2. perpendicular to dc->vel (absolutely non-flat nib):
if ( mag_vel < ERASER_EPSILON ) {
return FALSE;
}
// 3. Average them using flatness parameter:
// calculate angles
// flip a2 to force it to be in the same half-circle as a1
bool flipped = false;
flipped = true;
}
// normalize a2
// find the flatness-weighted bisector angle, unflip if a2 was flipped
// FIXME: when dc->vel is oscillating around the fixed angle, the new_ang flips back and forth. How to avoid this?
// Try to detect a sudden flip when the new angle differs too much from the previous for the
// current velocity; in that case discard this move
return FALSE;
}
// convert to point
// g_print ("force %g acc %g vel_max %g vel %g a1 %g a2 %g new_ang %g\n", NR::L2(force), NR::L2(dc->acc), dc->vel_max, NR::L2(dc->vel), a1, a2, new_ang);
/* Apply drag */
/* Update position */
return TRUE;
}
static void
{
// How much velocity thins strokestyle
// Influence of pressure on thickness
// drag)
double trace_thick = 1;
double tremble_left = 0, tremble_right = 0;
// obtain two normally distributed random variables, using polar Box-Muller transform
do {
} while ( w >= 1.0 );
// deflect both left and right edges randomly and independently, so that:
// (1) dc->tremor=1 corresponds to sigma=1, decreasing dc->tremor narrows the bell curve;
// (2) deflection depends on width, but is upped for small widths for better visual uniformity across widths;
// (3) deflection somewhat depends on speed, to prevent fast strokes looking
// comparatively smooth and slow ones excessively jittery
}
}
}
}
void
{
}
static void
{
dc->is_drawing = false;
/* Remove all temporary line segments */
}
/* reset accumulated curve */
}
}
{
case GDK_BUTTON_PRESS:
return TRUE;
}
}
/* initialize first point */
NULL,
dc->is_drawing = true;
}
break;
case GDK_MOTION_NOTIFY:
{
break;
}
}
}
}
break;
case GDK_BUTTON_RELEASE:
{
dc->is_drawing = false;
/* Remove all temporary line segments */
}
/* Create object */
/* reset accumulated curve */
}
}
break;
}
case GDK_KEY_PRESS:
case GDK_Up:
case GDK_KP_Up:
if (!MOD__CTRL_ONLY) {
}
break;
case GDK_Down:
case GDK_KP_Down:
if (!MOD__CTRL_ONLY) {
}
break;
case GDK_Right:
case GDK_KP_Right:
if (!MOD__CTRL_ONLY) {
sp_erc_update_toolbox (desktop, "altx-eraser", dc->width * 100); // the same spinbutton is for alt+x
}
break;
case GDK_Left:
case GDK_KP_Left:
if (!MOD__CTRL_ONLY) {
}
break;
case GDK_Home:
case GDK_KP_Home:
break;
case GDK_End:
case GDK_KP_End:
break;
case GDK_x:
case GDK_X:
if (MOD__ALT_ONLY) {
}
break;
case GDK_Escape:
if (dc->is_drawing) {
// if drawing, cancel, otherwise pass it up for deselecting
eraser_cancel (dc);
}
break;
case GDK_z:
case GDK_Z:
// if drawing, cancel, otherwise pass it up for undo
eraser_cancel (dc);
}
break;
default:
break;
}
break;
case GDK_KEY_RELEASE:
case GDK_Control_L:
case GDK_Control_R:
break;
default:
break;
}
default:
break;
}
if (!ret) {
}
}
return ret;
}
static void
{
// reset bpath
// reset curve
// reset points
}
static void
{
bool workDone = false;
/* Create object */
/* Set style */
item->updateRepr();
}
Geom::PathVector pathv = dc->accumulated->get_pathvector() * to_2geom(sp_desktop_dt2root_affine(desktop));
bool wasSelection = false;
if ( eraserMode ) {
} else {
toWorkOn = sp_document_items_at_points(sp_desktop_document(desktop), desktop->dkey, r->getPoints());
}
} else {
wasSelection = true;
}
if ( g_slist_length(toWorkOn) > 0 ) {
if ( eraserMode ) {
if ( eraserMode ) {
workDone = true; // TODO set this only if something was cut.
// If the item was not completely erased, track the new remainder.
}
}
} else {
}
}
}
} else {
}
item->deleteObject(true);
workDone = true;
}
}
if ( !eraserMode ) {
//sp_selection_delete();
}
if ( wasSelection ) {
if ( !remainingItems.empty() ) {
}
}
}
// Remove the eraser stroke itself:
}
} else {
}
}
if ( workDone ) {
_("Draw eraser stroke"));
} else {
}
}
static void
double rounding)
{
if ( mag_in > ERASER_EPSILON ) {
} else {
}
if ( mag_out > ERASER_EPSILON ) {
} else {
}
}
}
static void
{
Geom::CubicBezier const * dc_cal1_firstseg = dynamic_cast<Geom::CubicBezier const *>( dc->cal1->first_segment() );
Geom::CubicBezier const * rev_cal2_firstseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->first_segment() );
Geom::CubicBezier const * dc_cal1_lastseg = dynamic_cast<Geom::CubicBezier const *>( dc->cal1->last_segment() );
Geom::CubicBezier const * rev_cal2_lastseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->last_segment() );
add_cap(dc->accumulated, (*dc_cal1_lastseg)[2], (*dc_cal1_lastseg)[3], (*rev_cal2_firstseg)[3], (*rev_cal2_firstseg)[1], dc->cap_rounding);
add_cap(dc->accumulated, (*rev_cal2_lastseg)[2], (*rev_cal2_lastseg)[3], (*dc_cal1_firstseg)[3], (*dc_cal1_firstseg)[1], dc->cap_rounding);
}
}
static double square(double const x)
{
return x * x;
}
static void
{
double const tolerance_sq = square( NR::expansion(SP_EVENT_CONTEXT(dc)->desktop->w2d()) * TOLERANCE_ERASER );
#ifdef ERASER_VERBOSE
#endif
return; // just clicked
#define BEZIER_SIZE 4
#define BEZIER_MAX_BEZIERS 8
#ifdef ERASER_VERBOSE
g_print("[F&S:#] dc->npoints:%d, release:%s\n",
#endif
/* Current eraser */
/* dc->npoints > 0 */
/* g_print("erasers(1|2) reset\n"); */
}
/* Fit and draw and reset state */
#ifdef ERASER_VERBOSE
#endif
/* CanvasShape */
if (! release) {
}
}
// FIXME: dc->segments is always NULL at this point??
}
}
/* Current eraser */
}
}
} else {
/* fixme: ??? */
#ifdef ERASER_VERBOSE
g_print("[fit_and_split] failed to fit-cubic.\n");
#endif
}
}
}
/* Fit and draw and copy last point */
#ifdef ERASER_VERBOSE
#endif
if (!release) {
NULL);
//guint32 strokeColor = sp_desktop_get_color_tool (SP_ACTIVE_DESKTOP, "tools.eraser", false);
//double strokeOpacity = sp_desktop_get_opacity_tool (SP_ACTIVE_DESKTOP, "tools.eraser", false);
sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cbp), ((fillColor & 0xffffff00) | SP_COLOR_F_TO_U(opacity*fillOpacity)), SP_WIND_RULE_EVENODD);
//on second thougtht don't do stroke yet because we don't have stoke-width yet and because stoke appears between segments while drawing
//sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cbp), ((strokeColor & 0xffffff00) | SP_COLOR_F_TO_U(opacity*strokeOpacity)), 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cbp), 0x00000000, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
/* fixme: Cannot we cascade it to root more clearly? */
g_signal_connect(G_OBJECT(cbp), "event", G_CALLBACK(sp_desktop_root_handler), SP_EVENT_CONTEXT(dc)->desktop);
if ( !eraserMode ) {
}
}
} else {
}
}
static void
{
}
}
add_cap(dc->currentcurve, dc->point2[dc->npoints-2], dc->point2[dc->npoints-1], dc->point1[dc->npoints-1], dc->point1[dc->npoints-2], dc->cap_rounding);
}
}
/*
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 :