object-edit.cpp revision 833612d1c1e43055c4428afa90dd2b112a439780
#define __SP_OBJECT_EDIT_C__
/*
* Node editing extension to objects
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Mitsuru Oka
*
* Licensed under GNU GPL
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "sp-item.h"
#include "sp-rect.h"
#include "box3d.h"
#include "sp-ellipse.h"
#include "sp-star.h"
#include "sp-spiral.h"
#include "sp-offset.h"
#include "sp-flowtext.h"
#include "prefs-utils.h"
#include "inkscape.h"
#include "snap.h"
#include "desktop-affine.h"
#include <style.h>
#include "desktop.h"
#include "sp-namedview.h"
#include "sp-pattern.h"
#include "sp-path.h"
#include "object-edit.h"
#include <libnr/nr-scale-ops.h>
#include "isnan.h"
#define sp_round(v,m) (((v) < 0.0) ? ((ceil((v) / (m) - 0.5)) * (m)) : ((floor((v) / (m) + 0.5)) * (m)))
//static
{
if (SP_IS_RECT(item)) {
} else if (SP_IS_3DBOX(item)) {
} else if (SP_IS_STAR(item)) {
} else if (SP_IS_SPIRAL(item)) {
} else if (SP_IS_OFFSET(item)) {
} else {
}
return NULL;
}
/* Pattern manipulation */
{
return theta;
}
{
return xscale;
}
{
}
static void
{
if ( state & GDK_CONTROL_MASK ) {
} else {
}
}
if (state) {
}
}
{
return sp_pattern_extract_trans(pat);
}
{
gdouble y = 0;
return delta;
}
static void
{
// get the angle from pattern 0,0 to the cursor pos
if ( state & GDK_CONTROL_MASK ) {
}
// get the scale from the current transform so we can keep it.
}
static void
{
// Get the scale from the position of the knotholder,
// get angle from current transform, (need get current scale first to calculate angle)
}
{
a[4] = 0;
a[5] = 0;
return delta;
}
/* SPRect */
{
s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, s, item).getPoint();
}
{
}
{
//In general we cannot just snap this radius to an arbitrary point, as we have only a single
//degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
//the radius then we should have a constrained snap. snap_knot_position() is unconstrained
if (state & GDK_CONTROL_MASK) {
rect->rx.computed = rect->ry.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, temp);
} else {
rect->rx.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, rect->width.computed / 2.0);
}
}
{
}
{
//In general we cannot just snap this radius to an arbitrary point, as we have only a single
//degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
//the radius then we should have a constrained snap. snap_knot_position() is unconstrained
if (state & GDK_CONTROL_MASK) {
} else {
0.0,
} else {
0.0,
}
}
}
/**
* Remove rounding from a rectangle.
*/
{
}
/**
* Called when the horizontal rounding radius knot is clicked.
*/
{
if (state & GDK_SHIFT_MASK) {
} else if (state & GDK_CONTROL_MASK) {
/* Ctrl-click sets the vertical rounding to be the same as the horizontal */
}
}
/**
* Called when the vertical rounding radius knot is clicked.
*/
{
if (state & GDK_SHIFT_MASK) {
} else if (state & GDK_CONTROL_MASK) {
/* Ctrl-click sets the vertical rounding to be the same as the horizontal */
}
}
{
}
}
}
{
return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
}
static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point const &origin, guint state)
{
if (state & GDK_CONTROL_MASK) {
//original ratio
// mouse displacement since drag started
// snap to horizontal or diagonal
// closer to the diagonal and in same-sign quarters, change both using ratio
} else {
// closer to the horizontal, change only width, height is h_orig
}
} else {
// snap to vertical or diagonal
// closer to the diagonal and in same-sign quarters, change both using ratio
} else {
// closer to the vertical, change only height, width is w_orig
}
}
} else {
// move freely
}
}
{
}
{
}
{
// opposite corner (unmoved)
// mouse displacement since drag started
if (state & GDK_CONTROL_MASK) {
//original ratio
// snap to horizontal or diagonal
// closer to the diagonal and in same-sign quarters, change both using ratio
} else {
// closer to the horizontal, change only width, height is h_orig
}
} else {
// snap to vertical or diagonal
// closer to the diagonal and in same-sign quarters, change both using ratio
} else {
// closer to the vertical, change only height, width is w_orig
}
}
} else {
// move freely
}
}
{
_("Adjust the <b>horizontal rounding</b> radius; with <b>Ctrl</b> to make the vertical "
"radius the same"));
_("Adjust the <b>vertical rounding</b> radius; with <b>Ctrl</b> to make the horizontal "
"radius the same")
);
_("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
"or stretch in one dimension only")
);
_("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
"or stretch in one dimension only")
);
return knot_holder;
}
/* 3D Box */
{
// FIXME: Why must the coordinates be flipped vertically???
} else {
sp_3dbox_move_corner_in_XY_plane (box, knot_id, new_pos * i2d, (state & GDK_SHIFT_MASK) ? direction : Box3D::XY);
}
}
{
}
static void sp_3dbox_knot1_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
}
/*
static void sp_3dbox_knot1_set_constrained(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
sp_3dbox_knot_set (item, 1, Box3D::Y, new_pos, origin, state ^ GDK_SHIFT_MASK);
}
*/
static void sp_3dbox_knot2_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
}
/*
static void sp_3dbox_knot2_set_constrained(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
sp_3dbox_knot_set (item, 2, Box3D::X, new_pos, origin, state ^ GDK_SHIFT_MASK);
}
static void sp_3dbox_knot3_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
if (!(state & GDK_SHIFT_MASK)) {
sp_3dbox_knot_set (item, 3, Box3D::Y, new_pos, origin, state);
} else {
sp_3dbox_knot_set (item, 3, Box3D::Z, new_pos, origin, state ^ GDK_SHIFT_MASK);
}
}
*/
static void sp_3dbox_knot5_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
}
/*
static void sp_3dbox_knot7_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
sp_3dbox_knot_set (item, 7, Box3D::Z, new_pos, origin, state);
}
*/
// defined a uniform behaviour for all knots
static void sp_3dbox_knot_set_uniformly(SPItem *item, guint knot_id, Box3D::Axis direction, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
} else {
}
}
static void sp_3dbox_knot0_set_uniformly(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
}
static void sp_3dbox_knot1_set_uniformly(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
}
static void sp_3dbox_knot2_set_uniformly(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
}
static void sp_3dbox_knot3_set_uniformly(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
}
static void sp_3dbox_knot4_set_uniformly(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
}
static void sp_3dbox_knot5_set_uniformly(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
}
static void sp_3dbox_knot6_set_uniformly(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
}
static void sp_3dbox_knot7_set_uniformly(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
{
}
{
return sp_3dbox_knot_get(item, 0);
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
//static
{
switch (number_of_handles) {
case 3:
sp_knot_holder_add(knot_holder, sp_3dbox_knot1_set, sp_3dbox_knot1_get, NULL,_("Resize box in X/Y direction"));
sp_knot_holder_add(knot_holder, sp_3dbox_knot2_set, sp_3dbox_knot2_get, NULL,_("Resize box in X/Y direction"));
sp_knot_holder_add(knot_holder, sp_3dbox_knot5_set, sp_3dbox_knot5_get, NULL,_("Resize box in Z direction"));
break;
case 4:
/***
sp_knot_holder_add(knot_holder, sp_3dbox_knot1_set_constrained, sp_3dbox_knot1_get, NULL,_("Resize box in X/Y direction"));
sp_knot_holder_add(knot_holder, sp_3dbox_knot2_set_constrained, sp_3dbox_knot2_get, NULL,_("Resize box in X/Y direction"));
sp_knot_holder_add_full(knot_holder, sp_3dbox_knot3_set, sp_3dbox_knot3_get, NULL,
SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR, _("Resize box in Y direction"));
sp_knot_holder_add(knot_holder, sp_3dbox_knot7_set, sp_3dbox_knot7_get, NULL,_("Resize box in Z direction"));
***/
_("Resize box in X/Y direction; with <b>Shift</b> along the Z axis"));
_("Resize box in X/Y direction; with <b>Shift</b> along the Z axis"));
_("Resize box in X/Y direction; with <b>Shift</b> along the Z axis"));
_("Resize box in X/Y direction; with <b>Shift</b> along the Z axis"));
_("Resize box along the Z axis; with <b>Shift</b> in X/Y direction"));
_("Resize box along the Z axis; with <b>Shift</b> in X/Y direction"));
_("Resize box along the Z axis; with <b>Shift</b> in X/Y direction"));
_("Resize box along the Z axis; with <b>Shift</b> in X/Y direction"));
break;
default:
break;
}
return knot_holder;
}
/* SPArc */
/*
* return values:
* 1 : inside
* 0 : on the curves
* -1 : outside
*/
static gint
{
if (s < 1.0) return 1;
if (s > 1.0) return -1;
return 0;
}
static void
{
if ( ( state & GDK_CONTROL_MASK )
&& snaps )
{
}
}
{
}
static void
{
if ( ( state & GDK_CONTROL_MASK )
&& snaps )
{
}
}
{
}
static void
{
if (state & GDK_SHIFT_MASK) {
}
}
static void
{
if ( state & GDK_CONTROL_MASK ) {
}
}
{
}
static void
{
if ( state & GDK_CONTROL_MASK ) {
}
}
{
}
static void
{
if (state & GDK_CONTROL_MASK) {
}
}
static void
{
if (state & GDK_CONTROL_MASK) {
}
}
static SPKnotHolder *
{
_("Adjust ellipse <b>width</b>, with <b>Ctrl</b> to make circle"));
_("Adjust ellipse <b>height</b>, with <b>Ctrl</b> to make circle"));
_("Position the <b>start point</b> of the arc or segment; with <b>Ctrl</b> to snap angle; drag <b>inside</b> the ellipse for arc, <b>outside</b> for segment"));
_("Position the <b>end point</b> of the arc or segment; with <b>Ctrl</b> to snap angle; drag <b>inside</b> the ellipse for arc, <b>outside</b> for segment"));
return knot_holder;
}
/* SPStar */
static void
{
if (state & GDK_MOD1_MASK) {
} else if (state & GDK_SHIFT_MASK) {
} else if (state & GDK_CONTROL_MASK) {
} else {
}
}
static void
{
if (state & GDK_MOD1_MASK) {
} else if (state & GDK_SHIFT_MASK) {
} else if (state & GDK_CONTROL_MASK) {
}
else {
}
}
}
{
}
{
}
static void
{
if (state & GDK_MOD1_MASK) {
star->randomized = 0;
} else if (state & GDK_SHIFT_MASK) {
} else if (state & GDK_CONTROL_MASK) {
}
}
static SPKnotHolder *
{
/* we don't need to get parent knot_holder */
_("Adjust the <b>tip radius</b> of the star or polygon; with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
_("Adjust the <b>base radius</b> of the star; with <b>Ctrl</b> to keep star rays radial (no skew); with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
return knot_holder;
}
/* SPSpiral */
/*
* set attributes via inner (t=t0) knot point:
* [control] constrain inner arg to round per PI/4
*/
static void
{
if (state & GDK_MOD1_MASK) {
// adjust divergence by vertical drag, relative to rad
} else {
if ( ( state & GDK_CONTROL_MASK )
&& ( snaps != 0 ) ) {
}
}
}
/*
* set attributes via outer (t=1) knot point:
* [control] constrain inner arg to round per PI/4
*/
static void
{
if (!(state & GDK_MOD1_MASK)) {
// if alt not pressed, change also rad; otherwise it is locked
}
if ( ( state & GDK_CONTROL_MASK )
&& snaps ) {
}
// arg of the spiral outer end
double arg_1;
// its fractional part after the whole turns are subtracted
// arg of the mouse point relative to spiral center
if (mouse_angle < 0)
// snap if ctrl
}
// by how much we want to rotate the outer point
// calculate the new rad;
// the value of t corresponding to the angle arg_1 + diff:
// the rad at that t:
double rad_new = 0;
// change the revo (converting diff from radians to the number of turns)
// if alt not pressed and the values are sane, change the rad
// adjust t0 too so that the inner point stays unmoved
double r0;
}
}
}
{
}
{
}
static void
{
if (state & GDK_MOD1_MASK) {
} else if (state & GDK_SHIFT_MASK) {
}
}
static SPKnotHolder *
{
_("Roll/unroll the spiral from <b>inside</b>; with <b>Ctrl</b> to snap angle; with <b>Alt</b> to converge/diverge"));
_("Roll/unroll the spiral from <b>outside</b>; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to scale/rotate"));
return knot_holder;
}
/* SPOffset */
static void
{
}
{
return np;
}
static SPKnotHolder *
{
_("Adjust the <b>offset distance</b>"));
return knot_holder;
}
static SPKnotHolder *
sp_misc_knot_holder(SPItem *item, SPDesktop *desktop) // FIXME: eliminate, instead make a pattern-drag similar to gradient-drag
{
{
return knot_holder;
}
return NULL;
}
static void
{
{
sp_knot_holder_add_full(knot_holder, sp_pattern_xy_set, sp_pattern_xy_get, NULL, SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,
// TRANSLATORS: This refers to the pattern that's inside the object
_("<b>Move</b> the pattern fill inside the object"));
sp_knot_holder_add_full(knot_holder, sp_pattern_scale_set, sp_pattern_scale_get, NULL, SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
_("<b>Scale</b> the pattern fill uniformly"));
sp_knot_holder_add_full(knot_holder, sp_pattern_angle_set, sp_pattern_angle_get, NULL, SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
_("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"));
}
}
{
return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
}
static void
{
}
static SPKnotHolder *
{
_("Drag to resize the <b>flowed text frame</b>"));
return knot_holder;
}
/*
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 :