tweak-context.cpp revision c651830c7a4b9bf01531370a13958adca17cfd6a
#define __SP_TWEAK_CONTEXT_C__
/*
* tweaking paths without node editing
*
* Authors:
* bulia byak
*
* Copyright (C) 2007 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "config.h"
#include <gdk/gdkkeysyms.h>
#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 "pixmaps/cursor-tweak-move.xpm"
#include "pixmaps/cursor-thin.xpm"
#include "pixmaps/cursor-thicken.xpm"
#include "pixmaps/cursor-attract.xpm"
#include "pixmaps/cursor-repel.xpm"
#include "pixmaps/cursor-push.xpm"
#include "pixmaps/cursor-roughen.xpm"
#include "pixmaps/cursor-color.xpm"
#include <boost/optional.hpp>
#include "libnr/nr-matrix-ops.h"
#include "libnr/nr-scale-translate-ops.h"
#include "context-fns.h"
#include "sp-item.h"
#include "inkscape.h"
#include "color.h"
#include "svg/svg-color.h"
#include "splivarot.h"
#include "sp-item-group.h"
#include "sp-shape.h"
#include "sp-path.h"
#include "path-chemistry.h"
#include "sp-gradient.h"
#include "sp-stop.h"
#include "sp-stop-fns.h"
#include "sp-gradient-reference.h"
#include "sp-linear-gradient.h"
#include "sp-radial-gradient.h"
#include "gradient-chemistry.h"
#include "sp-text.h"
#include "sp-flowtext.h"
#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
#include "prefs-utils.h"
#include "style.h"
#include "box3d.h"
#include "sp-item-transform.h"
#include "tweak-context.h"
#define DDC_RED_RGBA 0xff0000ff
#define DYNA_MIN_WIDTH 1.0e-6
static SPEventContextClass *parent_class;
{
if (!type) {
sizeof(SPTweakContextClass),
sizeof(SPTweakContext),
4,
NULL, /* value_table */
};
}
return type;
}
static void
{
}
static void
{
/* attributes */
tc->is_dilating = false;
tc->has_dilated = false;
}
static void
{
if (tc->dilate_area) {
}
if (tc->_message_context) {
delete tc->_message_context;
}
}
{
return (mode == TWEAK_MODE_MOVE ||
mode == TWEAK_MODE_MOVE_IN_OUT ||
mode == TWEAK_MODE_MOVE_JITTER ||
mode == TWEAK_MODE_SCALE ||
mode == TWEAK_MODE_ROTATE ||
mode == TWEAK_MODE_MORELESS);
}
{
}
void
{
} else {
}
case TWEAK_MODE_MOVE:
break;
break;
case TWEAK_MODE_MOVE_IN_OUT:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>move in</b>; with Shift to <b>move out</b>."), sel_message);
break;
case TWEAK_MODE_MOVE_JITTER:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>move randomly</b>."), sel_message);
break;
case TWEAK_MODE_SCALE:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>scale down</b>; with Shift to <b>scale up</b>."), sel_message);
break;
case TWEAK_MODE_ROTATE:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>rotate clockwise</b>; with Shift, <b>counterclockwise</b>."), sel_message);
break;
case TWEAK_MODE_MORELESS:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>duplicate</b>; with Shift, <b>delete</b>."), sel_message);
break;
case TWEAK_MODE_PUSH:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag to <b>push paths</b>."), sel_message);
break;
case TWEAK_MODE_SHRINK_GROW:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>inset paths</b>; with Shift to <b>outset</b>."), sel_message);
if (with_shift) {
} else {
}
break;
case TWEAK_MODE_ATTRACT_REPEL:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>attract paths</b>; with Shift to <b>repel</b>."), sel_message);
if (with_shift) {
} else {
}
break;
case TWEAK_MODE_ROUGHEN:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>roughen paths</b>."), sel_message);
break;
case TWEAK_MODE_COLORPAINT:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>paint objects</b> with color."), sel_message);
break;
case TWEAK_MODE_COLORJITTER:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>randomize colors</b>."), sel_message);
break;
}
}
static bool
{
// we cannot store properties with uris
return true;
}
return false;
}
static void
{
{
/* TODO: have a look at sp_dyna_draw_context_setup where the same is done.. generalize? at least make it an arcto! */
const double C1 = 0.552;
c->moveto(-1,0);
c->closepath();
c->unref();
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(tc->dilate_area), 0xff9900ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
tc->is_drawing = false;
);
ec->enableSelectionCue();
}
ec->enableGrDrag();
}
}
static void
{
sp_tweak_update_cursor(tc, false);
}
}
static void
{
else
}
double
{
// 10 times the pen width:
}
double
{
if (force > 3) {
}
}
double
{
}
bool
sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, NR::Point p, NR::Point vector, gint mode, double radius, double force, double fidelity, bool reverse)
{
bool did = false;
// convert 3D boxes to ordinary groups before tweaking their shapes
}
if (SP_IS_GROUP(item)) {
for (SPObject *child = sp_object_first_child(SP_OBJECT(item)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_ITEM(child)) {
if (sp_tweak_dilate_recursive (selection, SP_ITEM(child), p, vector, mode, radius, force, fidelity, reverse))
did = true;
}
}
} else {
if (mode == TWEAK_MODE_MOVE) {
if (a) {
if (a->contains(p)) x = 0;
if (x < 1) {
did = true;
}
}
} else if (mode == TWEAK_MODE_MOVE_IN_OUT) {
if (a) {
if (a->contains(p)) x = 0;
if (x < 1) {
did = true;
}
}
} else if (mode == TWEAK_MODE_MOVE_JITTER) {
if (a) {
if (a->contains(p)) x = 0;
if (x < 1) {
did = true;
}
}
} else if (mode == TWEAK_MODE_SCALE) {
if (a) {
if (a->contains(p)) x = 0;
if (x < 1) {
did = true;
}
}
} else if (mode == TWEAK_MODE_ROTATE) {
if (a) {
if (a->contains(p)) x = 0;
if (x < 1) {
did = true;
}
}
} else if (mode == TWEAK_MODE_MORELESS) {
if (a) {
if (a->contains(p)) x = 0;
if (x < 1) {
if (reverse) { // delete
} else { // duplicate
}
}
}
}
if (!SP_IS_PATH(item)) {
if (!newrepr)
return false;
// remember the position of the item
// remember parent
// remember id
}
// skip those paths whose bboxes are entirely out of reach with our radius
if (bbox) {
return false;
}
}
return false;
}
res->SetBackData(false);
{
}
{
}
else
{
}
bool did_this = false;
if (mode == TWEAK_MODE_SHRINK_GROW) {
join_straight, 4.0,
did_this = true;
} else if (mode == TWEAK_MODE_ATTRACT_REPEL) {
join_straight, 4.0,
did_this = true;
} else if (mode == TWEAK_MODE_PUSH) {
1.0,
join_straight, 4.0,
did_this = true;
} else if (mode == TWEAK_MODE_ROUGHEN) {
join_straight, 4.0,
did_this = true;
}
// the rest only makes sense if we actually changed the path
if (did_this) {
if (newrepr) { // converting to path, need to replace the repr
if (is_selected)
// It's going to resurrect, so we delete without notifying listeners.
// restore id
// add the new repr to the parent
// move to the saved position
if (is_selected)
}
if (newrepr) {
} else {
} else {
}
}
} else {
// TODO: if there's 0 or 1 node left, delete this path altogether
}
if (newrepr) {
}
}
delete theShape;
delete theRes;
delete orig;
delete res;
if (did_this)
did = true;
}
}
return did;
}
void
{
float rgb_g[3];
float hsl_g[3];
float hsl_c[3];
if (!do_h)
if (!do_s)
if (!do_l)
} else {
}
for (int i = 0; i < 3; i++) {
}
}
void
{
float hsl_c[3];
if (do_h) {
if (hsl_c[0] > 1)
hsl_c[0] -= 1;
if (hsl_c[0] < 0)
hsl_c[0] += 1;
}
if (do_s) {
}
if (do_l) {
}
}
void
{
if (mode == TWEAK_MODE_COLORPAINT) {
} else if (mode == TWEAK_MODE_COLORJITTER) {
}
}
void
{
if (mode == TWEAK_MODE_COLORPAINT) {
double d = opacity_goal - opacity;
} else if (mode == TWEAK_MODE_COLORJITTER) {
}
}
double
{
if (radius == 0)
return 0;
double alpha = 1;
if (x >= 1) {
return 0;
} else if (x <= 0) {
return 1;
} else {
}
}
void
{
return;
// now p is in gradient's original coordinates
double pos = 0;
double r = 0;
if (SP_IS_LINEARGRADIENT(gradient)) {
// This is the matrix which moves and rotates the gradient line
// so it's oriented along the X axis:
NR::Matrix norm = NR::Matrix(NR::translate(-p1)) * NR::Matrix(NR::rotate(-atan2(pdiff[NR::Y], pdiff[NR::X])));
// Transform the mouse point by it to find out its projection onto the gradient line:
// Scale its X coordinate to match the length of the gradient line:
// Calculate radius in lenfth-of-gradient-line units
} else if (SP_IS_RADIALGRADIENT(gradient)) {
}
// Normalize pos to 0..1, taking into accound gradient spread:
if (pos > 1)
pos_e = 1;
if (pos < 0)
pos_e = 0;
if (odd)
}
}
double offset_l = 0;
double offset_h = 0;
if (!SP_IS_STOP(child))
continue;
if (child_prev) {
// the summit falls in this interstop, and the radius is small,
// so it only affects the ends of this interstop;
// distribute the force between the two endstops so that they
// get all the painting even if they are not touched by the brush
child_prev->updateRepr();
break;
} else {
// wide brush, may affect more than 2 stops,
// paint each stop by the force from the profile curve
child_prev->updateRepr();
}
}
}
}
child_prev = child;
}
}
bool
float opacity_goal, bool do_opacity,
{
bool did = false;
if (SP_IS_GROUP(item)) {
for (SPObject *child = sp_object_first_child(SP_OBJECT(item)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_ITEM(child)) {
did = true;
}
}
} else {
if (!style) {
return false;
}
if (!bbox) {
return false;
}
double this_force;
// if item == item_at_point, use max force
if (item == item_at_point) {
this_force = force;
// else if no overlap of bbox and brush box, skip:
return false;
//TODO:
// else if object > 1.5 brush: test 4/8/16 points in the brush on hitting the object, choose max
//} else if (bbox->maxExtent() > 3 * radius) {
//}
// else if object > 0.5 brush: test 4 corners of bbox and center on being in the brush, choose max
// else if still smaller, then check only the object center:
} else {
}
if (this_force > 0.002) {
if (do_fill) {
tweak_colors_in_gradient (item, true, fill_goal, p, radius, this_force, mode, do_h, do_s, do_l, do_o);
did = true;
item->updateRepr();
did = true;
}
}
if (do_stroke) {
tweak_colors_in_gradient (item, false, stroke_goal, p, radius, this_force, mode, do_h, do_s, do_l, do_o);
did = true;
item->updateRepr();
did = true;
}
}
if (do_opacity && do_o) {
}
}
}
return did;
}
bool
sp_tweak_dilate (SPTweakContext *tc, NR::Point event_p, NR::Point p, NR::Point vector, bool reverse)
{
return false;
}
bool did = false;
if (radius == 0 || path_force == 0) {
return false;
}
did = true;
}
if (sp_tweak_dilate_recursive (selection, item, p, vector, tc->mode, radius, move_force, tc->fidelity, reverse))
did = true;
} else {
if (sp_tweak_dilate_recursive (selection, item, p, vector, tc->mode, radius, path_force, tc->fidelity, reverse))
did = true;
}
}
return did;
}
void
{
NR::Matrix const sm (NR::scale(radius, radius) * NR::translate(SP_EVENT_CONTEXT(tc)->desktop->point()));
}
void
{
// need to set explicitly, because the prefs may not have changed by the previous
}
void
{
// Juggling about so that prefs have the old value but tc->mode and the button show new mode:
// button has changed prefs, restore
// changing prefs changed tc->mode, restore back :)
}
{
case GDK_ENTER_NOTIFY:
break;
case GDK_LEAVE_NOTIFY:
break;
case GDK_BUTTON_PRESS:
return TRUE;
}
tc->is_drawing = true;
tc->is_dilating = true;
tc->has_dilated = false;
}
break;
case GDK_MOTION_NOTIFY:
{
// draw the dilating cursor
}
if (num == 0) {
tc->_message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to tweak."));
}
// dilating:
sp_tweak_dilate (tc, motion_w, motion_doc, motion_doc - tc->last_push, event->button.state & GDK_SHIFT_MASK? true : false);
//tc->last_push = motion_doc;
tc->has_dilated = true;
// it's slow, so prevent clogging up with events
return TRUE;
}
}
break;
case GDK_BUTTON_RELEASE:
{
tc->is_drawing = false;
if (!tc->has_dilated) {
// if we did not rub, do a light tap
}
tc->is_dilating = false;
tc->has_dilated = false;
case TWEAK_MODE_MOVE:
SP_VERB_CONTEXT_TWEAK, _("Move tweak"));
break;
case TWEAK_MODE_MOVE_IN_OUT:
SP_VERB_CONTEXT_TWEAK, _("Move in/out tweak"));
break;
case TWEAK_MODE_MOVE_JITTER:
SP_VERB_CONTEXT_TWEAK, _("Move jitter tweak"));
break;
case TWEAK_MODE_SCALE:
SP_VERB_CONTEXT_TWEAK, _("Scale tweak"));
break;
case TWEAK_MODE_ROTATE:
SP_VERB_CONTEXT_TWEAK, _("Rotate tweak"));
break;
case TWEAK_MODE_MORELESS:
SP_VERB_CONTEXT_TWEAK, _("Duplicate/delete tweak"));
break;
case TWEAK_MODE_PUSH:
SP_VERB_CONTEXT_TWEAK, _("Push path tweak"));
break;
case TWEAK_MODE_SHRINK_GROW:
SP_VERB_CONTEXT_TWEAK, _("Shrink/grow path tweak"));
break;
case TWEAK_MODE_ATTRACT_REPEL:
SP_VERB_CONTEXT_TWEAK, _("Attract/repel path tweak"));
break;
case TWEAK_MODE_ROUGHEN:
SP_VERB_CONTEXT_TWEAK, _("Roughen path tweak"));
break;
case TWEAK_MODE_COLORPAINT:
SP_VERB_CONTEXT_TWEAK, _("Color paint tweak"));
break;
case TWEAK_MODE_COLORJITTER:
SP_VERB_CONTEXT_TWEAK, _("Color jitter tweak"));
break;
}
}
break;
}
case GDK_KEY_PRESS:
case GDK_m:
case GDK_M:
case GDK_0:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_i:
case GDK_I:
case GDK_1:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_z:
case GDK_Z:
case GDK_2:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_less:
case GDK_comma:
case GDK_greater:
case GDK_period:
case GDK_3:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_bracketright:
case GDK_bracketleft:
case GDK_4:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_d:
case GDK_D:
case GDK_5:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_p:
case GDK_P:
case GDK_6:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_s:
case GDK_S:
case GDK_7:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_a:
case GDK_A:
case GDK_8:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_r:
case GDK_R:
case GDK_9:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_c:
case GDK_C:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_j:
case GDK_J:
if (MOD__SHIFT_ONLY) {
}
break;
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) {
desktop->setToolboxAdjustmentValue ("altx-tweak", tc->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_Shift_L:
case GDK_Shift_R:
sp_tweak_update_cursor(tc, true);
break;
case GDK_Control_L:
case GDK_Control_R:
break;
default:
break;
}
break;
case GDK_KEY_RELEASE:
case GDK_Shift_L:
case GDK_Shift_R:
sp_tweak_update_cursor(tc, false);
break;
case GDK_Control_L:
case GDK_Control_R:
break;
default:
break;
}
default:
break;
}
if (!ret) {
}
}
return ret;
}
/*
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 :