dyna-draw-context.cpp revision a32a511cd4cd2acc897109af56e52ada5db641bb
#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>
*
* 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.
*
* 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"
#define DDC_RED_RGBA 0xff0000ff
#define SAMPLE_TIMEOUT 10
#define TOLERANCE_LINE 1.0
#define TOLERANCE_CALLIGRAPHIC 3.0
#define DYNA_EPSILON 1.0e-6
#define DYNA_MIN_WIDTH 1.0e-6
#define DRAG_MIN 0.0
#define DRAG_DEFAULT 1.0
#define DRAG_MAX 1.0
static SPEventContextClass *parent_class;
{
if (!type) {
sizeof(SPDynaDrawContextClass),
sizeof(SPDynaDrawContext),
4,
NULL, /* value_table */
};
}
return type;
}
static void
{
}
static void
{
/* DynaDraw values */
/* attributes */
}
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
}
}
}
}
static gint
{
int x, y;
if (! sp_dyna_draw_apply(dc, p)) {
return TRUE;
}
}
return TRUE;
}
void
{
}
{
case GDK_BUTTON_PRESS:
return TRUE;
}
}
/* initialize first point */
( dc->use_timeout
? ( GDK_KEY_PRESS_MASK |
: ( GDK_KEY_PRESS_MASK |
NULL,
}
dc->is_drawing = true;
}
break;
case GDK_MOTION_NOTIFY:
break;
}
}
}
break;
case GDK_BUTTON_RELEASE:
dc->is_drawing = false;
&& dc->use_timeout
{
}
/* 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();
}
} else {
}
}
}
static void
{
}
}
static void
{
}
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) {
}
}
}
/* Current calligraphic */
}
}
} else {
/* fixme: ??? */
#ifdef DYNA_DRAW_VERBOSE
g_print("[fit_and_split_calligraphics] failed to fit-cubic.\n");
#endif
}
}
}
/* Fit and draw and copy last point */
#ifdef DYNA_DRAW_VERBOSE
#endif
if (!release) {
NULL);
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
{
}
}
}
/*
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 :