Code

Add checkbox for LPEs to temporarily disable them on canvas (but keep them applied...
[inkscape.git] / src / object-edit.cpp
1 #define __SP_OBJECT_EDIT_C__
3 /*
4  * Node editing extension to objects
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *   Mitsuru Oka
9  *
10  * Licensed under GNU GPL
11  */
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
19 #include "sp-item.h"
20 #include "sp-rect.h"
21 #include "box3d.h"
22 #include "sp-ellipse.h"
23 #include "sp-star.h"
24 #include "sp-spiral.h"
25 #include "sp-offset.h"
26 #include "sp-flowtext.h"
27 #include "prefs-utils.h"
28 #include "inkscape.h"
29 #include "snap.h"
30 #include "desktop-affine.h"
31 #include <style.h>
32 #include "desktop.h"
33 #include "desktop-handles.h"
34 #include "sp-namedview.h"
35 #include "live_effects/effect.h"
37 #include "sp-pattern.h"
38 #include "sp-path.h"
40 #include <glibmm/i18n.h>
42 #include "object-edit.h"
44 #include <libnr/nr-scale-ops.h>
46 #include "xml/repr.h"
48 #include "2geom/isnan.h"
50 #define sp_round(v,m) (((v) < 0.0) ? ((ceil((v) / (m) - 0.5)) * (m)) : ((floor((v) / (m) + 0.5)) * (m)))
52 static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop);
53 static SPKnotHolder *box3d_knot_holder(SPItem *item, SPDesktop *desktop);
54 static SPKnotHolder *sp_arc_knot_holder(SPItem *item, SPDesktop *desktop);
55 static SPKnotHolder *sp_star_knot_holder(SPItem *item, SPDesktop *desktop);
56 static SPKnotHolder *sp_spiral_knot_holder(SPItem *item, SPDesktop *desktop);
57 static SPKnotHolder *sp_offset_knot_holder(SPItem *item, SPDesktop *desktop);
58 static SPKnotHolder *sp_misc_knot_holder(SPItem *item, SPDesktop *desktop);
59 static SPKnotHolder *sp_flowtext_knot_holder(SPItem *item, SPDesktop *desktop);
60 static void sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder);
62 static SPKnotHolder *sp_lpe_knot_holder(SPItem *item, SPDesktop *desktop)
63 {
64     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
66     Inkscape::LivePathEffect::Effect *effect = sp_lpe_item_get_livepatheffect(SP_LPE_ITEM(item));
67     effect->addHandles(knot_holder);
69     return knot_holder;
70 }
72 SPKnotHolder *
73 sp_item_knot_holder(SPItem *item, SPDesktop *desktop)
74 {
75     if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(item)) &&
76         sp_lpe_item_get_livepatheffect(SP_LPE_ITEM(item))->isVisible() &&
77         sp_lpe_item_get_livepatheffect(SP_LPE_ITEM(item))->providesKnotholder()) {
78         return sp_lpe_knot_holder(item, desktop);
79     } else
80     if (SP_IS_RECT(item)) {
81         return sp_rect_knot_holder(item, desktop);
82     } else if (SP_IS_BOX3D(item)) {
83         return box3d_knot_holder(item, desktop);
84     } else if (SP_IS_ARC(item)) {
85         return sp_arc_knot_holder(item, desktop);
86     } else if (SP_IS_STAR(item)) {
87         return sp_star_knot_holder(item, desktop);
88     } else if (SP_IS_SPIRAL(item)) {
89         return sp_spiral_knot_holder(item, desktop);
90     } else if (SP_IS_OFFSET(item)) {
91         return sp_offset_knot_holder(item, desktop);
92     } else if (SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
93         return sp_flowtext_knot_holder(item, desktop);
94     } else {
95         return sp_misc_knot_holder(item, desktop);
96     }
98     return NULL;
99 }
102 /* Pattern manipulation */
104 static gdouble sp_pattern_extract_theta(SPPattern *pat, gdouble scale)
106     gdouble theta = asin(pat->patternTransform[1] / scale);
107     if (pat->patternTransform[0] < 0) theta = M_PI - theta ;
108     return theta;
111 static gdouble sp_pattern_extract_scale(SPPattern *pat)
113     gdouble s = pat->patternTransform[1];
114     gdouble c = pat->patternTransform[0];
115     gdouble xscale = sqrt(c * c + s * s);
116     return xscale;
119 static NR::Point sp_pattern_extract_trans(SPPattern const *pat)
121     return NR::Point(pat->patternTransform[4], pat->patternTransform[5]);
124 static void
125 sp_pattern_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
127     SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
129     NR::Point p_snapped = p;
131     if ( state & GDK_CONTROL_MASK ) {
132         if (fabs((p - origin)[NR::X]) > fabs((p - origin)[NR::Y])) {
133             p_snapped[NR::Y] = origin[NR::Y];
134         } else {
135             p_snapped[NR::X] = origin[NR::X];
136         }
137     }
139     if (state)  {
140         NR::Point const q = p_snapped - sp_pattern_extract_trans(pat);
141         sp_item_adjust_pattern(item, NR::Matrix(NR::translate(q)));
142     }
144     item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
148 static NR::Point sp_pattern_xy_get(SPItem *item)
150     SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
151     return sp_pattern_extract_trans(pat);
154 static NR::Point sp_pattern_angle_get(SPItem *item)
156     SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
158     gdouble x = (pattern_width(pat)*0.5);
159     gdouble y = 0;
160     NR::Point delta = NR::Point(x,y);
161     gdouble scale = sp_pattern_extract_scale(pat);
162     gdouble theta = sp_pattern_extract_theta(pat, scale);
163     delta = delta * NR::Matrix(NR::rotate(theta))*NR::Matrix(NR::scale(scale,scale));
164     delta = delta + sp_pattern_extract_trans(pat);
165     return delta;
168 static void
169 sp_pattern_angle_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
171     int const snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
173     SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
175     // get the angle from pattern 0,0 to the cursor pos
176     NR::Point delta = p - sp_pattern_extract_trans(pat);
177     gdouble theta = atan2(delta);
179     if ( state & GDK_CONTROL_MASK ) {
180         theta = sp_round(theta, M_PI/snaps);
181     }
183     // get the scale from the current transform so we can keep it.
184     gdouble scl = sp_pattern_extract_scale(pat);
185     NR::Matrix rot =  NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl));
186     NR::Point const t = sp_pattern_extract_trans(pat);
187     rot[4] = t[NR::X];
188     rot[5] = t[NR::Y];
189     sp_item_adjust_pattern(item, rot, true);
190     item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
193 static void
194 sp_pattern_scale_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
196     SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
198     // Get the scale from the position of the knotholder,
199     NR::Point d = p - sp_pattern_extract_trans(pat);
200     gdouble s = NR::L2(d);
201     gdouble pat_x = pattern_width(pat) * 0.5;
202     gdouble pat_y = pattern_height(pat) * 0.5;
203     gdouble pat_h = hypot(pat_x, pat_y);
204     gdouble scl = s / pat_h;
206     // get angle from current transform, (need get current scale first to calculate angle)
207     gdouble oldscale = sp_pattern_extract_scale(pat);
208     gdouble theta = sp_pattern_extract_theta(pat,oldscale);
210     NR::Matrix rot =  NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl));
211     NR::Point const t = sp_pattern_extract_trans(pat);
212     rot[4] = t[NR::X];
213     rot[5] = t[NR::Y];
214     sp_item_adjust_pattern(item, rot, true);
215     item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
219 static NR::Point sp_pattern_scale_get(SPItem *item)
221     SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
223     gdouble x = pattern_width(pat)*0.5;
224     gdouble y = pattern_height(pat)*0.5;
225     NR::Point delta = NR::Point(x,y);
226     NR::Matrix a = pat->patternTransform;
227     a[4] = 0;
228     a[5] = 0;
229     delta = delta * a;
230     delta = delta + sp_pattern_extract_trans(pat);
231     return delta;
234 /* SPRect */
236 static NR::Point snap_knot_position(SPItem *item, NR::Point const &p)
238     SPDesktop const *desktop = inkscape_active_desktop();
239     NR::Matrix const i2d (sp_item_i2d_affine (item));
240     NR::Point s = p * i2d;
241     SnapManager &m = desktop->namedview->snap_manager;
242     m.setup(desktop, item);
243     m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, s);
244     return s * i2d.inverse();
247 static NR::Point sp_rect_rx_get(SPItem *item)
249     SPRect *rect = SP_RECT(item);
251     return NR::Point(rect->x.computed + rect->width.computed - rect->rx.computed, rect->y.computed);
254 static void sp_rect_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
256     SPRect *rect = SP_RECT(item);
258     //In general we cannot just snap this radius to an arbitrary point, as we have only a single
259     //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
260     //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
262     if (state & GDK_CONTROL_MASK) {
263         gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
264         rect->rx.computed = rect->ry.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, temp);
265         rect->rx._set = rect->ry._set = true;
267     } else {
268         rect->rx.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, rect->width.computed / 2.0);
269         rect->rx._set = true;
270     }
272     ((SPObject*)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
276 static NR::Point sp_rect_ry_get(SPItem *item)
278     SPRect *rect = SP_RECT(item);
280     return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->ry.computed);
283 static void sp_rect_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
285     SPRect *rect = SP_RECT(item);
287     //In general we cannot just snap this radius to an arbitrary point, as we have only a single
288     //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
289     //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
291     if (state & GDK_CONTROL_MASK) {
292         gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
293         rect->rx.computed = rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed, 0.0, temp);
294         rect->ry._set = rect->rx._set = true;
295     } else {
296         if (!rect->rx._set || rect->rx.computed == 0) {
297             rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
298                                       0.0,
299                                       MIN(rect->height.computed / 2.0, rect->width.computed / 2.0));
300         } else {
301             rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
302                                       0.0,
303                                       rect->height.computed / 2.0);
304         }
306         rect->ry._set = true;
307     }
309     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
312 /**
313  *  Remove rounding from a rectangle.
314  */
315 static void rect_remove_rounding(SPRect *rect)
317     SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
318     SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
321 /**
322  *  Called when the horizontal rounding radius knot is clicked.
323  */
324 static void sp_rect_rx_knot_click(SPItem *item, guint state)
326     SPRect *rect = SP_RECT(item);
328     if (state & GDK_SHIFT_MASK) {
329         rect_remove_rounding(rect);
330     } else if (state & GDK_CONTROL_MASK) {
331         /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
332         SP_OBJECT_REPR(rect)->setAttribute("ry", SP_OBJECT_REPR(rect)->attribute("rx"));
333     }
336 /**
337  *  Called when the vertical rounding radius knot is clicked.
338  */
339 static void sp_rect_ry_knot_click(SPItem *item, guint state)
341     SPRect *rect = SP_RECT(item);
343     if (state & GDK_SHIFT_MASK) {
344         rect_remove_rounding(rect);
345     } else if (state & GDK_CONTROL_MASK) {
346         /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
347         SP_OBJECT_REPR(rect)->setAttribute("rx", SP_OBJECT_REPR(rect)->attribute("ry"));
348     }
351 #define SGN(x) ((x)>0?1:((x)<0?-1:0))
353 static void sp_rect_clamp_radii(SPRect *rect)
355     // clamp rounding radii so that they do not exceed width/height
356     if (2 * rect->rx.computed > rect->width.computed) {
357         rect->rx.computed = 0.5 * rect->width.computed;
358         rect->rx._set = true;
359     }
360     if (2 * rect->ry.computed > rect->height.computed) {
361         rect->ry.computed = 0.5 * rect->height.computed;
362         rect->ry._set = true;
363     }
366 static NR::Point sp_rect_wh_get(SPItem *item)
368     SPRect *rect = SP_RECT(item);
370     return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
373 static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point const &origin, guint state)
375     NR::Point const s = snap_knot_position(rect, p);
377     if (state & GDK_CONTROL_MASK) {
378         // original width/height when drag started
379         gdouble const w_orig = (origin[NR::X] - rect->x.computed);
380         gdouble const h_orig = (origin[NR::Y] - rect->y.computed);
382         //original ratio
383         gdouble const ratio = (w_orig / h_orig);
385         // mouse displacement since drag started
386         gdouble const minx = s[NR::X] - origin[NR::X];
387         gdouble const miny = s[NR::Y] - origin[NR::Y];
389         if (fabs(minx) > fabs(miny)) {
391             // snap to horizontal or diagonal
392             rect->width.computed = MAX(w_orig + minx, 0);
393             if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
394                 // closer to the diagonal and in same-sign quarters, change both using ratio
395                 rect->height.computed = MAX(h_orig + minx / ratio, 0);
396             } else {
397                 // closer to the horizontal, change only width, height is h_orig
398                 rect->height.computed = MAX(h_orig, 0);
399             }
401         } else {
402             // snap to vertical or diagonal
403             rect->height.computed = MAX(h_orig + miny, 0);
404             if (miny != 0 && fabs(minx/miny) > 0.5 * ratio && (SGN(minx) == SGN(miny))) {
405                 // closer to the diagonal and in same-sign quarters, change both using ratio
406                 rect->width.computed = MAX(w_orig + miny * ratio, 0);
407             } else {
408                 // closer to the vertical, change only height, width is w_orig
409                 rect->width.computed = MAX(w_orig, 0);
410             }
411         }
413         rect->width._set = rect->height._set = true;
415     } else {
416         // move freely
417         rect->width.computed = MAX(s[NR::X] - rect->x.computed, 0);
418         rect->height.computed = MAX(s[NR::Y] - rect->y.computed, 0);
419         rect->width._set = rect->height._set = true;
420     }
422     sp_rect_clamp_radii(rect);
424     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
427 static void sp_rect_wh_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
429     SPRect *rect = SP_RECT(item);
431     sp_rect_wh_set_internal(rect, p, origin, state);
434 static NR::Point sp_rect_xy_get(SPItem *item)
436     SPRect *rect = SP_RECT(item);
438     return NR::Point(rect->x.computed, rect->y.computed);
441 static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
443     SPRect *rect = SP_RECT(item);
445     // opposite corner (unmoved)
446     gdouble opposite_x = (rect->x.computed + rect->width.computed);
447     gdouble opposite_y = (rect->y.computed + rect->height.computed);
449     // original width/height when drag started
450     gdouble w_orig = opposite_x - origin[NR::X];
451     gdouble h_orig = opposite_y - origin[NR::Y];
453     NR::Point const s = snap_knot_position(rect, p);
455     // mouse displacement since drag started
456     gdouble minx = s[NR::X] - origin[NR::X];
457     gdouble miny = s[NR::Y] - origin[NR::Y];
459     if (state & GDK_CONTROL_MASK) {
460         //original ratio
461         gdouble ratio = (w_orig / h_orig);
463         if (fabs(minx) > fabs(miny)) {
465             // snap to horizontal or diagonal
466             rect->x.computed = MIN(s[NR::X], opposite_x);
467             rect->width.computed = MAX(w_orig - minx, 0);
468             if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
469                 // closer to the diagonal and in same-sign quarters, change both using ratio
470                 rect->y.computed = MIN(origin[NR::Y] + minx / ratio, opposite_y);
471                 rect->height.computed = MAX(h_orig - minx / ratio, 0);
472             } else {
473                 // closer to the horizontal, change only width, height is h_orig
474                 rect->y.computed = MIN(origin[NR::Y], opposite_y);
475                 rect->height.computed = MAX(h_orig, 0);
476             }
478         } else {
480             // snap to vertical or diagonal
481             rect->y.computed = MIN(s[NR::Y], opposite_y);
482             rect->height.computed = MAX(h_orig - miny, 0);
483             if (miny != 0 && fabs(minx/miny) > 0.5 *ratio && (SGN(minx) == SGN(miny))) {
484                 // closer to the diagonal and in same-sign quarters, change both using ratio
485                 rect->x.computed = MIN(origin[NR::X] + miny * ratio, opposite_x);
486                 rect->width.computed = MAX(w_orig - miny * ratio, 0);
487             } else {
488                 // closer to the vertical, change only height, width is w_orig
489                 rect->x.computed = MIN(origin[NR::X], opposite_x);
490                 rect->width.computed = MAX(w_orig, 0);
491             }
493         }
495         rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
497     } else {
498         // move freely
499         rect->x.computed = MIN(s[NR::X], opposite_x);
500         rect->width.computed = MAX(w_orig - minx, 0);
501         rect->y.computed = MIN(s[NR::Y], opposite_y);
502         rect->height.computed = MAX(h_orig - miny, 0);
503         rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
504     }
506     sp_rect_clamp_radii(rect);
508     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
511 static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop)
513     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
515     sp_knot_holder_add_full(
516       knot_holder, sp_rect_rx_set, sp_rect_rx_get, sp_rect_rx_knot_click,
517       SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
518       _("Adjust the <b>horizontal rounding</b> radius; with <b>Ctrl</b> to make the vertical "
519         "radius the same"));
521     sp_knot_holder_add_full(
522       knot_holder, sp_rect_ry_set, sp_rect_ry_get, sp_rect_ry_knot_click,
523       SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
524       _("Adjust the <b>vertical rounding</b> radius; with <b>Ctrl</b> to make the horizontal "
525         "radius the same")
526       );
528     sp_knot_holder_add_full(
529       knot_holder, sp_rect_wh_set, sp_rect_wh_get, NULL,
530       SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
531       _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
532         "or stretch in one dimension only")
533       );
535     sp_knot_holder_add_full(
536       knot_holder, sp_rect_xy_set, sp_rect_xy_get, NULL,
537       SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
538       _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
539         "or stretch in one dimension only")
540       );
542     sp_pat_knot_holder(item, knot_holder);
543     return knot_holder;
546 /* Box3D (= the new 3D box structure) */
548 static NR::Point box3d_knot_get(SPItem *item, guint knot_id)
550     return box3d_get_corner_screen(SP_BOX3D(item), knot_id);
553 static void box3d_knot_set(SPItem *item, guint knot_id, NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
555     NR::Point const s = snap_knot_position(item, new_pos);
557     g_assert(item != NULL);
558     SPBox3D *box = SP_BOX3D(item);
559     NR::Matrix const i2d (sp_item_i2d_affine (item));
561     Box3D::Axis movement;
562     if ((knot_id < 4) != (state & GDK_SHIFT_MASK)) {
563         movement = Box3D::XY;
564     } else {
565         movement = Box3D::Z;
566     }
568     box3d_set_corner (box, knot_id, s * i2d, movement, (state & GDK_CONTROL_MASK));
569     box3d_set_z_orders(box);
570     box3d_position_set(box);
573 static NR::Point box3d_knot_center_get (SPItem *item)
575     return box3d_get_center_screen (SP_BOX3D(item));
578 static void box3d_knot_center_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
580     NR::Point const s = snap_knot_position(item, new_pos);
582     SPBox3D *box = SP_BOX3D(item);
583     NR::Matrix const i2d (sp_item_i2d_affine (item));
585     box3d_set_center (SP_BOX3D(item), s * i2d, origin * i2d, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z,
586                       state & GDK_CONTROL_MASK);
588     box3d_set_z_orders(box);
589     box3d_position_set(box);
592 static void box3d_knot0_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
594     box3d_knot_set(item, 0, new_pos, origin, state);
597 static void box3d_knot1_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
599     box3d_knot_set(item, 1, new_pos, origin, state);
602 static void box3d_knot2_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
604     box3d_knot_set(item, 2, new_pos, origin, state);
607 static void box3d_knot3_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
609     box3d_knot_set(item, 3, new_pos, origin, state);
612 static void box3d_knot4_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
614     box3d_knot_set(item, 4, new_pos, origin, state);
617 static void box3d_knot5_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
619     box3d_knot_set(item, 5, new_pos, origin, state);
622 static void box3d_knot6_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
624     box3d_knot_set(item, 6, new_pos, origin, state);
627 static void box3d_knot7_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
629     box3d_knot_set(item, 7, new_pos, origin, state);
632 static NR::Point box3d_knot0_get(SPItem *item)
634     return box3d_knot_get(item, 0);
637 static NR::Point box3d_knot1_get(SPItem *item)
639     return box3d_knot_get(item, 1);
642 static NR::Point box3d_knot2_get(SPItem *item)
644     return box3d_knot_get(item, 2);
647 static NR::Point box3d_knot3_get(SPItem *item)
649     return box3d_knot_get(item, 3);
652 static NR::Point box3d_knot4_get(SPItem *item)
654     return box3d_knot_get(item, 4);
657 static NR::Point box3d_knot5_get(SPItem *item)
659     return box3d_knot_get(item, 5);
662 static NR::Point box3d_knot6_get(SPItem *item)
664     return box3d_knot_get(item, 6);
667 static NR::Point box3d_knot7_get(SPItem *item)
669     return box3d_knot_get(item, 7);
672 SPKnotHolder *
673 box3d_knot_holder(SPItem *item, SPDesktop *desktop)
675     g_assert(item != NULL);
676     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
678     sp_knot_holder_add(knot_holder, box3d_knot0_set, box3d_knot0_get, NULL,
679                        _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
680     sp_knot_holder_add(knot_holder, box3d_knot1_set, box3d_knot1_get, NULL,
681                        _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
682     sp_knot_holder_add(knot_holder, box3d_knot2_set, box3d_knot2_get, NULL,
683                        _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
684     sp_knot_holder_add(knot_holder, box3d_knot3_set, box3d_knot3_get, NULL,
685                        _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
686     sp_knot_holder_add(knot_holder, box3d_knot4_set, box3d_knot4_get, NULL,
687                        _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
688     sp_knot_holder_add(knot_holder, box3d_knot5_set, box3d_knot5_get, NULL,
689                        _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
690     sp_knot_holder_add(knot_holder, box3d_knot6_set, box3d_knot6_get, NULL,
691                        _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
692     sp_knot_holder_add(knot_holder, box3d_knot7_set, box3d_knot7_get, NULL,
693                        _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
695     // center dragging
696     sp_knot_holder_add_full(knot_holder, box3d_knot_center_set, box3d_knot_center_get, NULL,
697                             SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,_("Move the box in perspective"));
699     sp_pat_knot_holder(item, knot_holder);
701     return knot_holder;
706 /* SPArc */
708 /*
709  * return values:
710  *   1  : inside
711  *   0  : on the curves
712  *   -1 : outside
713  */
714 static gint
715 sp_genericellipse_side(SPGenericEllipse *ellipse, NR::Point const &p)
717     gdouble dx = (p[NR::X] - ellipse->cx.computed) / ellipse->rx.computed;
718     gdouble dy = (p[NR::Y] - ellipse->cy.computed) / ellipse->ry.computed;
720     gdouble s = dx * dx + dy * dy;
721     if (s < 1.0) return 1;
722     if (s > 1.0) return -1;
723     return 0;
726 static void
727 sp_arc_start_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
729     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
731     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
732     SPArc *arc = SP_ARC(item);
734     ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
736     NR::Point delta = p - NR::Point(ge->cx.computed, ge->cy.computed);
737     NR::scale sc(ge->rx.computed, ge->ry.computed);
738     ge->start = atan2(delta * sc.inverse());
739     if ( ( state & GDK_CONTROL_MASK )
740          && snaps )
741     {
742         ge->start = sp_round(ge->start, M_PI/snaps);
743     }
744     sp_genericellipse_normalize(ge);
745     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
748 static NR::Point sp_arc_start_get(SPItem *item)
750     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
751     SPArc *arc = SP_ARC(item);
753     return sp_arc_get_xy(arc, ge->start);
756 static void
757 sp_arc_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
759     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
761     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
762     SPArc *arc = SP_ARC(item);
764     ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
766     NR::Point delta = p - NR::Point(ge->cx.computed, ge->cy.computed);
767     NR::scale sc(ge->rx.computed, ge->ry.computed);
768     ge->end = atan2(delta * sc.inverse());
769     if ( ( state & GDK_CONTROL_MASK )
770          && snaps )
771     {
772         ge->end = sp_round(ge->end, M_PI/snaps);
773     }
774     sp_genericellipse_normalize(ge);
775     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
778 static NR::Point sp_arc_end_get(SPItem *item)
780     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
781     SPArc *arc = SP_ARC(item);
783     return sp_arc_get_xy(arc, ge->end);
786 static void
787 sp_arc_startend_click(SPItem *item, guint state)
789     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
791     if (state & GDK_SHIFT_MASK) {
792         ge->end = ge->start = 0;
793         ((SPObject *)ge)->updateRepr();
794     }
798 static void
799 sp_arc_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
801     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
802     SPArc *arc = SP_ARC(item);
804     NR::Point const s = snap_knot_position(arc, p);
806     ge->rx.computed = fabs( ge->cx.computed - s[NR::X] );
808     if ( state & GDK_CONTROL_MASK ) {
809         ge->ry.computed = ge->rx.computed;
810     }
812     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
815 static NR::Point sp_arc_rx_get(SPItem *item)
817     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
819     return (NR::Point(ge->cx.computed, ge->cy.computed) -  NR::Point(ge->rx.computed, 0));
822 static void
823 sp_arc_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
825     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
826     SPArc *arc = SP_ARC(item);
828     NR::Point const s = snap_knot_position(arc, p);
830     ge->ry.computed = fabs( ge->cy.computed - s[NR::Y] );
832     if ( state & GDK_CONTROL_MASK ) {
833         ge->rx.computed = ge->ry.computed;
834     }
836     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
839 static NR::Point sp_arc_ry_get(SPItem *item)
841     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
843     return (NR::Point(ge->cx.computed, ge->cy.computed) -  NR::Point(0, ge->ry.computed));
846 static void
847 sp_arc_rx_click(SPItem *item, guint state)
849     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
851     if (state & GDK_CONTROL_MASK) {
852         ge->ry.computed = ge->rx.computed;
853         ((SPObject *)ge)->updateRepr();
854     }
857 static void
858 sp_arc_ry_click(SPItem *item, guint state)
860     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
862     if (state & GDK_CONTROL_MASK) {
863         ge->rx.computed = ge->ry.computed;
864         ((SPObject *)ge)->updateRepr();
865     }
868 static SPKnotHolder *
869 sp_arc_knot_holder(SPItem *item, SPDesktop *desktop)
871     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
873     sp_knot_holder_add_full(knot_holder, sp_arc_rx_set, sp_arc_rx_get, sp_arc_rx_click,
874                             SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
875                             _("Adjust ellipse <b>width</b>, with <b>Ctrl</b> to make circle"));
876     sp_knot_holder_add_full(knot_holder, sp_arc_ry_set, sp_arc_ry_get, sp_arc_ry_click,
877                             SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
878                             _("Adjust ellipse <b>height</b>, with <b>Ctrl</b> to make circle"));
879     sp_knot_holder_add_full(knot_holder, sp_arc_start_set, sp_arc_start_get, sp_arc_startend_click,
880                             SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
881                             _("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"));
882     sp_knot_holder_add_full(knot_holder, sp_arc_end_set, sp_arc_end_get, sp_arc_startend_click,
883                             SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
884                             _("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"));
886     sp_pat_knot_holder(item, knot_holder);
888     return knot_holder;
891 /* SPStar */
893 static void
894 sp_star_knot1_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
896     SPStar *star = SP_STAR(item);
898     NR::Point const s = snap_knot_position(star, p);
900     NR::Point d = s - star->center;
902     double arg1 = atan2(d);
903     double darg1 = arg1 - star->arg[0];
905     if (state & GDK_MOD1_MASK) {
906         star->randomized = darg1/(star->arg[0] - star->arg[1]);
907     } else if (state & GDK_SHIFT_MASK) {
908         star->rounded = darg1/(star->arg[0] - star->arg[1]);
909     } else if (state & GDK_CONTROL_MASK) {
910         star->r[0]    = L2(d);
911     } else {
912         star->r[0]    = L2(d);
913         star->arg[0]  = arg1;
914         star->arg[1] += darg1;
915     }
916     ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
919 static void
920 sp_star_knot2_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
922     SPStar *star = SP_STAR(item);
924     NR::Point const s = snap_knot_position(star, p);
926     if (star->flatsided == false) {
927         NR::Point d = s - star->center;
929         double arg1 = atan2(d);
930         double darg1 = arg1 - star->arg[1];
932         if (state & GDK_MOD1_MASK) {
933             star->randomized = darg1/(star->arg[0] - star->arg[1]);
934         } else if (state & GDK_SHIFT_MASK) {
935             star->rounded = fabs(darg1/(star->arg[0] - star->arg[1]));
936         } else if (state & GDK_CONTROL_MASK) {
937             star->r[1]   = L2(d);
938             star->arg[1] = star->arg[0] + M_PI / star->sides;
939         }
940         else {
941             star->r[1]   = L2(d);
942             star->arg[1] = atan2(d);
943         }
944         ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
945     }
948 static NR::Point sp_star_knot1_get(SPItem *item)
950     g_assert(item != NULL);
952     SPStar *star = SP_STAR(item);
954     return sp_star_get_xy(star, SP_STAR_POINT_KNOT1, 0);
958 static NR::Point sp_star_knot2_get(SPItem *item)
960     g_assert(item != NULL);
962     SPStar *star = SP_STAR(item);
964     return sp_star_get_xy(star, SP_STAR_POINT_KNOT2, 0);
967 static void
968 sp_star_knot_click(SPItem *item, guint state)
970     SPStar *star = SP_STAR(item);
972     if (state & GDK_MOD1_MASK) {
973         star->randomized = 0;
974         ((SPObject *)star)->updateRepr();
975     } else if (state & GDK_SHIFT_MASK) {
976         star->rounded = 0;
977         ((SPObject *)star)->updateRepr();
978     } else if (state & GDK_CONTROL_MASK) {
979         star->arg[1] = star->arg[0] + M_PI / star->sides;
980         ((SPObject *)star)->updateRepr();
981     }
984 static SPKnotHolder *
985 sp_star_knot_holder(SPItem *item, SPDesktop *desktop)
987     /* we don't need to get parent knot_holder */
988     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
989     g_assert(item != NULL);
991     SPStar *star = SP_STAR(item);
993     sp_knot_holder_add(knot_holder, sp_star_knot1_set, sp_star_knot1_get, sp_star_knot_click,
994                        _("Adjust the <b>tip radius</b> of the star or polygon; with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
995     if (star->flatsided == false)
996         sp_knot_holder_add(knot_holder, sp_star_knot2_set, sp_star_knot2_get, sp_star_knot_click,
997                            _("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"));
999     sp_pat_knot_holder(item, knot_holder);
1001     return knot_holder;
1004 /* SPSpiral */
1006 /*
1007  * set attributes via inner (t=t0) knot point:
1008  *   [default] increase/decrease inner point
1009  *   [shift]   increase/decrease inner and outer arg synchronizely
1010  *   [control] constrain inner arg to round per PI/4
1011  */
1012 static void
1013 sp_spiral_inner_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
1015     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1017     SPSpiral *spiral = SP_SPIRAL(item);
1019     gdouble   dx = p[NR::X] - spiral->cx;
1020     gdouble   dy = p[NR::Y] - spiral->cy;
1022     if (state & GDK_MOD1_MASK) {
1023         // adjust divergence by vertical drag, relative to rad
1024         double new_exp = (spiral->rad + dy)/(spiral->rad);
1025         spiral->exp = new_exp > 0? new_exp : 0;
1026     } else {
1027         // roll/unroll from inside
1028         gdouble   arg_t0;
1029         sp_spiral_get_polar(spiral, spiral->t0, NULL, &arg_t0);
1031         gdouble   arg_tmp = atan2(dy, dx) - arg_t0;
1032         gdouble   arg_t0_new = arg_tmp - floor((arg_tmp+M_PI)/(2.0*M_PI))*2.0*M_PI + arg_t0;
1033         spiral->t0 = (arg_t0_new - spiral->arg) / (2.0*M_PI*spiral->revo);
1035         /* round inner arg per PI/snaps, if CTRL is pressed */
1036         if ( ( state & GDK_CONTROL_MASK )
1037              && ( fabs(spiral->revo) > SP_EPSILON_2 )
1038              && ( snaps != 0 ) ) {
1039             gdouble arg = 2.0*M_PI*spiral->revo*spiral->t0 + spiral->arg;
1040             spiral->t0 = (sp_round(arg, M_PI/snaps) - spiral->arg)/(2.0*M_PI*spiral->revo);
1041         }
1043         spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1044     }
1046     ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1049 /*
1050  * set attributes via outer (t=1) knot point:
1051  *   [default] increase/decrease revolution factor
1052  *   [control] constrain inner arg to round per PI/4
1053  */
1054 static void
1055 sp_spiral_outer_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
1057     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1059     SPSpiral *spiral = SP_SPIRAL(item);
1061     gdouble  dx = p[NR::X] - spiral->cx;
1062     gdouble  dy = p[NR::Y] - spiral->cy;
1064     if (state & GDK_SHIFT_MASK) { // rotate without roll/unroll
1065         spiral->arg = atan2(dy, dx) - 2.0*M_PI*spiral->revo;
1066         if (!(state & GDK_MOD1_MASK)) {
1067             // if alt not pressed, change also rad; otherwise it is locked
1068             spiral->rad = MAX(hypot(dx, dy), 0.001);
1069         }
1070         if ( ( state & GDK_CONTROL_MASK )
1071              && snaps ) {
1072             spiral->arg = sp_round(spiral->arg, M_PI/snaps);
1073         }
1074     } else { // roll/unroll
1075         // arg of the spiral outer end
1076         double arg_1;
1077         sp_spiral_get_polar(spiral, 1, NULL, &arg_1);
1079         // its fractional part after the whole turns are subtracted
1080         double arg_r = arg_1 - sp_round(arg_1, 2.0*M_PI);
1082         // arg of the mouse point relative to spiral center
1083         double mouse_angle = atan2(dy, dx);
1084         if (mouse_angle < 0)
1085             mouse_angle += 2*M_PI;
1087         // snap if ctrl
1088         if ( ( state & GDK_CONTROL_MASK ) && snaps ) {
1089             mouse_angle = sp_round(mouse_angle, M_PI/snaps);
1090         }
1092         // by how much we want to rotate the outer point
1093         double diff = mouse_angle - arg_r;
1094         if (diff > M_PI)
1095             diff -= 2*M_PI;
1096         else if (diff < -M_PI)
1097             diff += 2*M_PI;
1099         // calculate the new rad;
1100         // the value of t corresponding to the angle arg_1 + diff:
1101         double t_temp = ((arg_1 + diff) - spiral->arg)/(2*M_PI*spiral->revo);
1102         // the rad at that t:
1103         double rad_new = 0;
1104         if (t_temp > spiral->t0)
1105             sp_spiral_get_polar(spiral, t_temp, &rad_new, NULL);
1107         // change the revo (converting diff from radians to the number of turns)
1108         spiral->revo += diff/(2*M_PI);
1109         if (spiral->revo < 1e-3)
1110             spiral->revo = 1e-3;
1112         // if alt not pressed and the values are sane, change the rad
1113         if (!(state & GDK_MOD1_MASK) && rad_new > 1e-3 && rad_new/spiral->rad < 2) {
1114             // adjust t0 too so that the inner point stays unmoved
1115             double r0;
1116             sp_spiral_get_polar(spiral, spiral->t0, &r0, NULL);
1117             spiral->rad = rad_new;
1118             spiral->t0 = pow(r0 / spiral->rad, 1.0/spiral->exp);
1119         }
1120         if (!IS_FINITE(spiral->t0)) spiral->t0 = 0.0;
1121         spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1122     }
1124     ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1127 static NR::Point sp_spiral_inner_get(SPItem *item)
1129     SPSpiral *spiral = SP_SPIRAL(item);
1131     return sp_spiral_get_xy(spiral, spiral->t0);
1134 static NR::Point sp_spiral_outer_get(SPItem *item)
1136     SPSpiral *spiral = SP_SPIRAL(item);
1138     return sp_spiral_get_xy(spiral, 1.0);
1141 static void
1142 sp_spiral_inner_click(SPItem *item, guint state)
1144     SPSpiral *spiral = SP_SPIRAL(item);
1146     if (state & GDK_MOD1_MASK) {
1147         spiral->exp = 1;
1148         ((SPObject *)spiral)->updateRepr();
1149     } else if (state & GDK_SHIFT_MASK) {
1150         spiral->t0 = 0;
1151         ((SPObject *)spiral)->updateRepr();
1152     }
1155 static SPKnotHolder *
1156 sp_spiral_knot_holder(SPItem *item, SPDesktop *desktop)
1158     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1160     sp_knot_holder_add(knot_holder, sp_spiral_inner_set, sp_spiral_inner_get, sp_spiral_inner_click,
1161                        _("Roll/unroll the spiral from <b>inside</b>; with <b>Ctrl</b> to snap angle; with <b>Alt</b> to converge/diverge"));
1162     sp_knot_holder_add(knot_holder, sp_spiral_outer_set, sp_spiral_outer_get, NULL,
1163                        _("Roll/unroll the spiral from <b>outside</b>; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to scale/rotate"));
1165     sp_pat_knot_holder(item, knot_holder);
1167     return knot_holder;
1170 /* SPOffset */
1172 static void
1173 sp_offset_offset_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
1175     SPOffset *offset = SP_OFFSET(item);
1177     offset->rad = sp_offset_distance_to_original(offset, p);
1178     offset->knot = p;
1179     offset->knotSet = true;
1181     ((SPObject *)offset)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1185 static NR::Point sp_offset_offset_get(SPItem *item)
1187     SPOffset *offset = SP_OFFSET(item);
1189     NR::Point np;
1190     sp_offset_top_point(offset,&np);
1191     return np;
1194 static SPKnotHolder *
1195 sp_offset_knot_holder(SPItem *item, SPDesktop *desktop)
1197     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1199     sp_knot_holder_add(knot_holder, sp_offset_offset_set, sp_offset_offset_get, NULL,
1200                        _("Adjust the <b>offset distance</b>"));
1202     sp_pat_knot_holder(item, knot_holder);
1204     return knot_holder;
1207 static SPKnotHolder *
1208 sp_misc_knot_holder(SPItem *item, SPDesktop *desktop) // FIXME: eliminate, instead make a pattern-drag similar to gradient-drag
1210     if ((SP_OBJECT(item)->style->fill.isPaintserver())
1211         && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
1212     {
1213         SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1215         sp_pat_knot_holder(item, knot_holder);
1217         return knot_holder;
1218     }
1219     return NULL;
1222 static void
1223 sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder)
1225     if ((SP_OBJECT(item)->style->fill.isPaintserver())
1226         && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
1227     {
1228         sp_knot_holder_add_full(knot_holder, sp_pattern_xy_set, sp_pattern_xy_get, NULL, SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,
1229                                 // TRANSLATORS: This refers to the pattern that's inside the object
1230                                 _("<b>Move</b> the pattern fill inside the object"));
1231         sp_knot_holder_add_full(knot_holder, sp_pattern_scale_set, sp_pattern_scale_get, NULL, SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
1232                                 _("<b>Scale</b> the pattern fill uniformly"));
1233         sp_knot_holder_add_full(knot_holder, sp_pattern_angle_set, sp_pattern_angle_get, NULL, SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
1234                                 _("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"));
1235     }
1238 static NR::Point sp_flowtext_corner_get(SPItem *item)
1240     SPRect *rect = SP_RECT(item);
1242     return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
1245 static void
1246 sp_flowtext_corner_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
1248     SPRect *rect = SP_RECT(item);
1250     sp_rect_wh_set_internal(rect, p, origin, state);
1253 static SPKnotHolder *
1254 sp_flowtext_knot_holder(SPItem *item, SPDesktop *desktop)
1256     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL);
1258     sp_knot_holder_add(knot_holder, sp_flowtext_corner_set, sp_flowtext_corner_get, NULL,
1259                        _("Drag to resize the <b>flowed text frame</b>"));
1261     return knot_holder;
1265 /*
1266   Local Variables:
1267   mode:c++
1268   c-file-style:"stroustrup"
1269   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1270   indent-tabs-mode:nil
1271   fill-column:99
1272   End:
1273 */
1274 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :