/*
* tweaking paths without node editing
*
* Authors:
* bulia byak
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* 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 <glib.h>
#include "macros.h"
#include "document.h"
#include "document-undo.h"
#include "selection.h"
#include "desktop.h"
#include "desktop-events.h"
#include "desktop-style.h"
#include "message-context.h"
#include "pixmaps/cursor-tweak-move.xpm"
#include "pixmaps/cursor-tweak-move-in.xpm"
#include "pixmaps/cursor-tweak-move-out.xpm"
#include "pixmaps/cursor-tweak-move-jitter.xpm"
#include "pixmaps/cursor-tweak-scale-up.xpm"
#include "pixmaps/cursor-tweak-scale-down.xpm"
#include "pixmaps/cursor-tweak-rotate-clockwise.xpm"
#include "pixmaps/cursor-tweak-rotate-counterclockwise.xpm"
#include "pixmaps/cursor-tweak-more.xpm"
#include "pixmaps/cursor-tweak-less.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 "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-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/sp-canvas.h"
#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
#include "preferences.h"
#include "style.h"
#include "box3d.h"
#include "sp-item-transform.h"
#include "filter-chemistry.h"
#include "filters/gaussian-blur.h"
#include "verbs.h"
#include "ui/tools/tweak-tool.h"
using Inkscape::DocumentUndo;
namespace Inkscape {
namespace UI {
namespace Tools {
}
, dragging(false)
, usepressure(false)
, usetilt(false)
, width(0.2)
, force(0.2)
, fidelity(0)
, mode(0)
, is_drawing(false)
, is_dilating(false)
, has_dilated(false)
, dilate_area(NULL)
, do_h(true)
, do_s(true)
, do_l(true)
, do_o(false)
{
}
this->enableGrDrag(false);
this->style_set_connection.disconnect();
if (this->dilate_area) {
sp_canvas_item_destroy(this->dilate_area);
this->dilate_area = NULL;
}
}
{
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);
}
{
return (mode == TWEAK_MODE_COLORPAINT || mode == TWEAK_MODE_COLORJITTER || mode == TWEAK_MODE_BLUR);
}
sel_message = g_strdup_printf(ngettext("<b>%i</b> object selected","<b>%i</b> objects selected",num), num);
} else {
}
switch (this->mode) {
case TWEAK_MODE_MOVE:
this->cursor_shape = cursor_tweak_move_xpm;
break;
case TWEAK_MODE_MOVE_IN_OUT:
this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>move in</b>; with Shift to <b>move out</b>."), sel_message);
if (with_shift) {
this->cursor_shape = cursor_tweak_move_out_xpm;
} else {
this->cursor_shape = cursor_tweak_move_in_xpm;
}
break;
case TWEAK_MODE_MOVE_JITTER:
this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>move randomly</b>."), sel_message);
this->cursor_shape = cursor_tweak_move_jitter_xpm;
break;
case TWEAK_MODE_SCALE:
this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>scale down</b>; with Shift to <b>scale up</b>."), sel_message);
if (with_shift) {
this->cursor_shape = cursor_tweak_scale_up_xpm;
} else {
this->cursor_shape = cursor_tweak_scale_down_xpm;
}
break;
case TWEAK_MODE_ROTATE:
this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>rotate clockwise</b>; with Shift, <b>counterclockwise</b>."), sel_message);
if (with_shift) {
} else {
}
break;
case TWEAK_MODE_MORELESS:
this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>duplicate</b>; with Shift, <b>delete</b>."), sel_message);
if (with_shift) {
this->cursor_shape = cursor_tweak_less_xpm;
} else {
this->cursor_shape = cursor_tweak_more_xpm;
}
break;
case TWEAK_MODE_PUSH:
this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag to <b>push paths</b>."), sel_message);
this->cursor_shape = cursor_push_xpm;
break;
case TWEAK_MODE_SHRINK_GROW:
this->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) {
this->cursor_shape = cursor_thicken_xpm;
} else {
this->cursor_shape = cursor_thin_xpm;
}
break;
case TWEAK_MODE_ATTRACT_REPEL:
this->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) {
this->cursor_shape = cursor_repel_xpm;
} else {
this->cursor_shape = cursor_attract_xpm;
}
break;
case TWEAK_MODE_ROUGHEN:
this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>roughen paths</b>."), sel_message);
this->cursor_shape = cursor_roughen_xpm;
break;
case TWEAK_MODE_COLORPAINT:
this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>paint objects</b> with color."), sel_message);
this->cursor_shape = cursor_color_xpm;
break;
case TWEAK_MODE_COLORJITTER:
this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>randomize colors</b>."), sel_message);
this->cursor_shape = cursor_color_xpm;
break;
case TWEAK_MODE_BLUR:
this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag or click to <b>increase blur</b>; with Shift to <b>decrease</b>."), sel_message);
this->cursor_shape = cursor_color_xpm;
break;
}
this->sp_event_context_update_cursor();
}
// we cannot store properties with uris
return true;
}
return false;
}
{
/* TODO: have a look at sp_dyna_draw_context_setup where the same is done.. generalize? at least make it an arcto! */
c->unref();
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->dilate_area), 0xff9900ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_item_hide(this->dilate_area);
}
this->is_drawing = false;
sp_event_context_read(this, "width");
sp_event_context_read(this, "mode");
sp_event_context_read(this, "fidelity");
sp_event_context_read(this, "force");
sp_event_context_read(this, "usepressure");
sp_event_context_read(this, "doh");
sp_event_context_read(this, "dol");
sp_event_context_read(this, "dos");
sp_event_context_read(this, "doo");
this->style_set_connection = this->desktop->connectSetStyle( // catch style-setting signal in this tool
//sigc::bind(sigc::ptr_fun(&sp_tweak_context_style_set), this)
);
this->enableSelectionCue();
}
this->enableGrDrag();
}
}
if (path == "width") {
} else if (path == "mode") {
this->update_cursor(false);
} else if (path == "fidelity") {
} else if (path == "force") {
} else if (path == "usepressure") {
} else if (path == "doh") {
} else if (path == "dos") {
} else if (path == "dol") {
} else if (path == "doo") {
}
}
static void
{
} else {
}
}
static double
{
// 10 times the pen width:
}
static double
{
if (force > 3) {
}
}
static double
{
}
static bool
sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::Point p, Geom::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_tweak_dilate_recursive (selection, 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
item->deleteObject(true, true);
} else { // duplicate
}
}
did = true;
}
}
}
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.
item->deleteObject(false);
// 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;
}
static void
{
if (!do_h) {
}
if (!do_s) {
}
if (!do_l) {
}
} else {
}
for (int i = 0; i < 3; i++) {
}
}
static void
{
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) {
}
}
static void
{
if (mode == TWEAK_MODE_COLORPAINT) {
} else if (mode == TWEAK_MODE_COLORJITTER) {
}
}
static void
{
if (mode == TWEAK_MODE_COLORPAINT) {
double d = opacity_goal - opacity;
} else if (mode == TWEAK_MODE_COLORJITTER) {
}
}
static double
{
if (radius == 0) {
return 0;
}
if (x >= 1) {
return 0;
} else if (x <= 0) {
return 1;
} else {
}
}
{
return;
}
// now p is in gradient's original coordinates
double pos = 0;
double r = 0;
if (lg) {
// This is the matrix which moves and rotates the gradient line
// so it's oriented along the X axis:
Geom::Affine norm = Geom::Affine(Geom::Translate(-p1)) * Geom::Affine(Geom::Rotate(-atan2(pdiff[Geom::Y], pdiff[Geom::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 (rg) {
}
}
// 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 (!stop) {
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
stop->updateRepr();
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();
}
stop->updateRepr();
}
}
}
child_prev = child;
}
}
static bool
float opacity_goal, bool do_opacity,
{
bool did = false;
if (childItem) {
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_blur) {
if (!bbox) {
return did;
}
double blur_now = 0;
//cycle through filter primitives
while (primitive_obj) {
if (primitive) {
//if primitive is gaussianblur
if (spblur) {
}
}
}
}
double blur_new;
if (reverse) {
} else {
}
blur_new = 0;
}
if (blur_new == 0) {
remove_filter(item, false);
} else {
}
return true; // do not do colors, blur is a separate mode
}
if (do_fill) {
tweak_colors_in_gradient(item, Inkscape::FOR_FILL, 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, Inkscape::FOR_STROKE, 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;
}
static bool
sp_tweak_dilate (TweakTool *tc, Geom::Point event_p, Geom::Point p, Geom::Point vector, bool reverse)
{
return false;
}
bool did = false;
if (reverse) {
#if 0
// HSL inversion
float hsv[3];
float rgb[3];
#else
// RGB inversion
#endif
}
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;
}
static void
{
Geom::Affine const sm (Geom::Scale(radius, radius) * Geom::Translate(SP_EVENT_CONTEXT(tc)->desktop->point()));
}
static void
{
// need to set explicitly, because the prefs may not have changed by the previous
}
static 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:
sp_canvas_item_show(this->dilate_area);
break;
case GDK_LEAVE_NOTIFY:
sp_canvas_item_hide(this->dilate_area);
break;
case GDK_BUTTON_PRESS:
return TRUE;
}
sp_tweak_extinput(this, event);
this->is_drawing = true;
this->is_dilating = true;
this->has_dilated = false;
}
break;
case GDK_MOTION_NOTIFY:
{
sp_tweak_extinput(this, event);
// draw the dilating cursor
sp_canvas_item_show(this->dilate_area);
}
if (num == 0) {
this->message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to tweak."));
}
// dilating:
sp_tweak_dilate (this, motion_w, motion_doc, motion_doc - this->last_push, event->button.state & GDK_SHIFT_MASK? true : false);
//this->last_push = motion_doc;
this->has_dilated = true;
// it's slow, so prevent clogging up with events
return TRUE;
}
}
break;
case GDK_BUTTON_RELEASE:
{
this->is_drawing = false;
if (!this->has_dilated) {
// if we did not rub, do a light tap
this->pressure = 0.03;
}
this->is_dilating = false;
this->has_dilated = false;
switch (this->mode) {
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;
case TWEAK_MODE_BLUR:
SP_VERB_CONTEXT_TWEAK, _("Blur tweak"));
break;
}
}
break;
}
case GDK_KEY_PRESS:
{
case GDK_KEY_m:
case GDK_KEY_M:
case GDK_KEY_0:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_i:
case GDK_KEY_I:
case GDK_KEY_1:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_z:
case GDK_KEY_Z:
case GDK_KEY_2:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_less:
case GDK_KEY_comma:
case GDK_KEY_greater:
case GDK_KEY_period:
case GDK_KEY_3:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_bracketright:
case GDK_KEY_bracketleft:
case GDK_KEY_4:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_d:
case GDK_KEY_D:
case GDK_KEY_5:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_p:
case GDK_KEY_P:
case GDK_KEY_6:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_s:
case GDK_KEY_S:
case GDK_KEY_7:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_a:
case GDK_KEY_A:
case GDK_KEY_8:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_r:
case GDK_KEY_R:
case GDK_KEY_9:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_c:
case GDK_KEY_C:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_j:
case GDK_KEY_J:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_b:
case GDK_KEY_B:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_Up:
case GDK_KEY_KP_Up:
if (!MOD__CTRL_ONLY(event)) {
this->force += 0.05;
if (this->force > 1.0) {
this->force = 1.0;
}
}
break;
case GDK_KEY_Down:
case GDK_KEY_KP_Down:
if (!MOD__CTRL_ONLY(event)) {
this->force -= 0.05;
if (this->force < 0.0) {
this->force = 0.0;
}
}
break;
case GDK_KEY_Right:
case GDK_KEY_KP_Right:
if (!MOD__CTRL_ONLY(event)) {
this->width += 0.01;
if (this->width > 1.0) {
this->width = 1.0;
}
desktop->setToolboxAdjustmentValue ("altx-tweak", this->width * 100); // the same spinbutton is for alt+x
sp_tweak_update_area(this);
}
break;
case GDK_KEY_Left:
case GDK_KEY_KP_Left:
if (!MOD__CTRL_ONLY(event)) {
this->width -= 0.01;
if (this->width < 0.01) {
this->width = 0.01;
}
sp_tweak_update_area(this);
}
break;
case GDK_KEY_Home:
case GDK_KEY_KP_Home:
this->width = 0.01;
sp_tweak_update_area(this);
break;
case GDK_KEY_End:
case GDK_KEY_KP_End:
this->width = 1.0;
sp_tweak_update_area(this);
break;
case GDK_KEY_x:
case GDK_KEY_X:
if (MOD__ALT_ONLY(event)) {
}
break;
case GDK_KEY_Shift_L:
case GDK_KEY_Shift_R:
this->update_cursor(true);
break;
case GDK_KEY_Control_L:
case GDK_KEY_Control_R:
break;
case GDK_KEY_Delete:
case GDK_KEY_KP_Delete:
case GDK_KEY_BackSpace:
break;
default:
break;
}
break;
}
case GDK_KEY_RELEASE: {
case GDK_KEY_Shift_L:
case GDK_KEY_Shift_R:
this->update_cursor(false);
break;
case GDK_KEY_Control_L:
case GDK_KEY_Control_R:
this->message_context->clear();
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:fileencoding=utf-8:textwidth=99 :