dyna-draw-context.cpp revision dbe32b890d08ee7a085dcee01234f24e32db5ee1
#define __SP_DYNA_DRAW_CONTEXT_C__
/*
* Handwriting-like drawing mode
*
* Authors:
* Mitsuru Oka <oka326@parkcity.ne.jp>
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* MenTaLguY <mental@rydia.net>
*
* 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-2006 bulia byak
* Copyright (C) 2006 MenTaLguY
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#define noDYNA_DRAW_VERBOSE
#include "config.h"
#include <gdk/gdkkeysyms.h>
#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 "pixmaps/cursor-calligraphy.xpm"
#include "dyna-draw-context.h"
#include "libnr/n-art-bpath.h"
#include "context-fns.h"
#include "sp-item.h"
#include "inkscape.h"
#include "color.h"
#define DDC_RED_RGBA 0xff0000ff
#define SAMPLE_TIMEOUT 10
#define TOLERANCE_LINE 1.0
#define TOLERANCE_CALLIGRAPHIC 3.0
#define DYNA_EPSILON 0.5e-2
#define DYNA_MIN_WIDTH 1.0e-6
#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 *parent_class;
{
if (!type) {
sizeof(SPDynaDrawContextClass),
sizeof(SPDynaDrawContext),
4,
NULL, /* value_table */
};
}
return type;
}
static void
{
}
static void
{
/* DynaDraw values */
/* attributes */
ddc->keep_selected = true;
}
static void
{
if (ddc->accumulated) {
}
}
if (ddc->currentshape) {
}
if (ddc->_message_context) {
delete ddc->_message_context;
}
}
static void
{
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(ddc->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(ddc->currentshape), "event", G_CALLBACK(sp_desktop_root_handler), ec->desktop);
ddc->is_drawing = false;
}
static void
{
}
//g_print("DDC: %g %g %g %g\n", ddc->mass, ddc->drag, ddc->angle, ddc->width);
}
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 */
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 < DYNA_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?
// convert to point
/* Apply drag */
/* Update position */
return TRUE;
}
static void
{
// How much velocity thins strokestyle
// Influence of pressure on thickness
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
{
}
{
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_ddc_update_toolbox (desktop, "altx-calligraphy", 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_x:
case GDK_X:
if (MOD__ALT_ONLY) {
}
break;
case GDK_Escape:
break;
default:
break;
}
default:
break;
}
if (!ret) {
}
}
return ret;
}
static void
{
/* reset bpath */
/* reset curve */
/* reset points */
}
static void
{
/* Create object */
/* Set style */
item->updateRepr();
if (dc->keep_selected) {
} else {
}
}
} else {
}
}
_("Create calligraphic stroke"));
}
static void
double rounding)
{
if ( mag_in > DYNA_EPSILON ) {
} else {
}
if ( mag_out > DYNA_EPSILON ) {
} else {
}
}
}
static void
{
add_cap(dc->accumulated, SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->c(2), SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->c(3), SP_CURVE_SEGMENT(rev_cal2, 0)->c(3), SP_CURVE_SEGMENT(rev_cal2, 1)->c(1), dc->cap_rounding);
add_cap(dc->accumulated, SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->c(2), SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->c(3), SP_CURVE_SEGMENT(dc->cal1, 0)->c(3), SP_CURVE_SEGMENT(dc->cal1, 1)->c(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_CALLIGRAPHIC );
#ifdef DYNA_DRAW_VERBOSE
#endif
return; // just clicked
#define BEZIER_SIZE 4
#define BEZIER_MAX_BEZIERS 8
#ifdef DYNA_DRAW_VERBOSE
g_print("[F&S:#] dc->npoints:%d, release:%s\n",
#endif
/* Current calligraphic */
/* dc->npoints > 0 */
/* g_print("calligraphics(1|2) reset\n"); */
}
/* Fit and draw and reset state */
#ifdef DYNA_DRAW_VERBOSE
#endif
/* CanvasShape */
if (! release) {
}
}
// FIXME: dc->segments is always NULL at this point??
}
}
/* Current calligraphic */
}
}
} else {
/* fixme: ??? */
#ifdef DYNA_DRAW_VERBOSE
g_print("[fit_and_split] failed to fit-cubic.\n");
#endif
}
}
}
/* Fit and draw and copy last point */
#ifdef DYNA_DRAW_VERBOSE
#endif
if (!release) {
NULL);
//guint32 strokeColor = sp_desktop_get_color_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", false);
//double strokeOpacity = sp_desktop_get_opacity_tool (SP_ACTIVE_DESKTOP, "tools.calligraphic", 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);
}
} else {
}
}
static void
{
}
}
add_cap(dc->currentcurve, dc->point2[1], dc->point2[0], dc->point1[0], dc->point1[1], 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 :