Code

Provide knotholder for LPEPerpBisector; TODO: this replaces the usual nodepath in...
[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))->providesKnotholder()) {
77         return sp_lpe_knot_holder(item, desktop);
78     } else
79     if (SP_IS_RECT(item)) {
80         return sp_rect_knot_holder(item, desktop);
81     } else if (SP_IS_BOX3D(item)) {
82         return box3d_knot_holder(item, desktop);
83     } else if (SP_IS_ARC(item)) {
84         return sp_arc_knot_holder(item, desktop);
85     } else if (SP_IS_STAR(item)) {
86         return sp_star_knot_holder(item, desktop);
87     } else if (SP_IS_SPIRAL(item)) {
88         return sp_spiral_knot_holder(item, desktop);
89     } else if (SP_IS_OFFSET(item)) {
90         return sp_offset_knot_holder(item, desktop);
91     } else if (SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
92         return sp_flowtext_knot_holder(item, desktop);
93     } else {
94         return sp_misc_knot_holder(item, desktop);
95     }
97     return NULL;
98 }
101 /* Pattern manipulation */
103 static gdouble sp_pattern_extract_theta(SPPattern *pat, gdouble scale)
105     gdouble theta = asin(pat->patternTransform[1] / scale);
106     if (pat->patternTransform[0] < 0) theta = M_PI - theta ;
107     return theta;
110 static gdouble sp_pattern_extract_scale(SPPattern *pat)
112     gdouble s = pat->patternTransform[1];
113     gdouble c = pat->patternTransform[0];
114     gdouble xscale = sqrt(c * c + s * s);
115     return xscale;
118 static NR::Point sp_pattern_extract_trans(SPPattern const *pat)
120     return NR::Point(pat->patternTransform[4], pat->patternTransform[5]);
123 static void
124 sp_pattern_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
126     SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
128     NR::Point p_snapped = p;
130     if ( state & GDK_CONTROL_MASK ) {
131         if (fabs((p - origin)[NR::X]) > fabs((p - origin)[NR::Y])) {
132             p_snapped[NR::Y] = origin[NR::Y];
133         } else {
134             p_snapped[NR::X] = origin[NR::X];
135         }
136     }
138     if (state)  {
139         NR::Point const q = p_snapped - sp_pattern_extract_trans(pat);
140         sp_item_adjust_pattern(item, NR::Matrix(NR::translate(q)));
141     }
143     item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
147 static NR::Point sp_pattern_xy_get(SPItem *item)
149     SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
150     return sp_pattern_extract_trans(pat);
153 static NR::Point sp_pattern_angle_get(SPItem *item)
155     SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
157     gdouble x = (pattern_width(pat)*0.5);
158     gdouble y = 0;
159     NR::Point delta = NR::Point(x,y);
160     gdouble scale = sp_pattern_extract_scale(pat);
161     gdouble theta = sp_pattern_extract_theta(pat, scale);
162     delta = delta * NR::Matrix(NR::rotate(theta))*NR::Matrix(NR::scale(scale,scale));
163     delta = delta + sp_pattern_extract_trans(pat);
164     return delta;
167 static void
168 sp_pattern_angle_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
170     int const snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
172     SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
174     // get the angle from pattern 0,0 to the cursor pos
175     NR::Point delta = p - sp_pattern_extract_trans(pat);
176     gdouble theta = atan2(delta);
178     if ( state & GDK_CONTROL_MASK ) {
179         theta = sp_round(theta, M_PI/snaps);
180     }
182     // get the scale from the current transform so we can keep it.
183     gdouble scl = sp_pattern_extract_scale(pat);
184     NR::Matrix rot =  NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl));
185     NR::Point const t = sp_pattern_extract_trans(pat);
186     rot[4] = t[NR::X];
187     rot[5] = t[NR::Y];
188     sp_item_adjust_pattern(item, rot, true);
189     item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
192 static void
193 sp_pattern_scale_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
195     SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
197     // Get the scale from the position of the knotholder,
198     NR::Point d = p - sp_pattern_extract_trans(pat);
199     gdouble s = NR::L2(d);
200     gdouble pat_x = pattern_width(pat) * 0.5;
201     gdouble pat_y = pattern_height(pat) * 0.5;
202     gdouble pat_h = hypot(pat_x, pat_y);
203     gdouble scl = s / pat_h;
205     // get angle from current transform, (need get current scale first to calculate angle)
206     gdouble oldscale = sp_pattern_extract_scale(pat);
207     gdouble theta = sp_pattern_extract_theta(pat,oldscale);
209     NR::Matrix rot =  NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl));
210     NR::Point const t = sp_pattern_extract_trans(pat);
211     rot[4] = t[NR::X];
212     rot[5] = t[NR::Y];
213     sp_item_adjust_pattern(item, rot, true);
214     item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
218 static NR::Point sp_pattern_scale_get(SPItem *item)
220     SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
222     gdouble x = pattern_width(pat)*0.5;
223     gdouble y = pattern_height(pat)*0.5;
224     NR::Point delta = NR::Point(x,y);
225     NR::Matrix a = pat->patternTransform;
226     a[4] = 0;
227     a[5] = 0;
228     delta = delta * a;
229     delta = delta + sp_pattern_extract_trans(pat);
230     return delta;
233 /* SPRect */
235 static NR::Point snap_knot_position(SPItem *item, NR::Point const &p)
237     SPDesktop const *desktop = inkscape_active_desktop();
238     NR::Matrix const i2d (sp_item_i2d_affine (item));
239     NR::Point s = p * i2d;
240     SnapManager &m = desktop->namedview->snap_manager;
241     m.setup(desktop, item);
242     m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, s);
243     return s * i2d.inverse();
246 static NR::Point sp_rect_rx_get(SPItem *item)
248     SPRect *rect = SP_RECT(item);
250     return NR::Point(rect->x.computed + rect->width.computed - rect->rx.computed, rect->y.computed);
253 static void sp_rect_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
255     SPRect *rect = SP_RECT(item);
257     //In general we cannot just snap this radius to an arbitrary point, as we have only a single
258     //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
259     //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
261     if (state & GDK_CONTROL_MASK) {
262         gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
263         rect->rx.computed = rect->ry.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, temp);
264         rect->rx._set = rect->ry._set = true;
266     } else {
267         rect->rx.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, rect->width.computed / 2.0);
268         rect->rx._set = true;
269     }
271     ((SPObject*)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
275 static NR::Point sp_rect_ry_get(SPItem *item)
277     SPRect *rect = SP_RECT(item);
279     return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->ry.computed);
282 static void sp_rect_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
284     SPRect *rect = SP_RECT(item);
286     //In general we cannot just snap this radius to an arbitrary point, as we have only a single
287     //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
288     //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
290     if (state & GDK_CONTROL_MASK) {
291         gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
292         rect->rx.computed = rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed, 0.0, temp);
293         rect->ry._set = rect->rx._set = true;
294     } else {
295         if (!rect->rx._set || rect->rx.computed == 0) {
296             rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
297                                       0.0,
298                                       MIN(rect->height.computed / 2.0, rect->width.computed / 2.0));
299         } else {
300             rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
301                                       0.0,
302                                       rect->height.computed / 2.0);
303         }
305         rect->ry._set = true;
306     }
308     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
311 /**
312  *  Remove rounding from a rectangle.
313  */
314 static void rect_remove_rounding(SPRect *rect)
316     SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
317     SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
320 /**
321  *  Called when the horizontal rounding radius knot is clicked.
322  */
323 static void sp_rect_rx_knot_click(SPItem *item, guint state)
325     SPRect *rect = SP_RECT(item);
327     if (state & GDK_SHIFT_MASK) {
328         rect_remove_rounding(rect);
329     } else if (state & GDK_CONTROL_MASK) {
330         /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
331         SP_OBJECT_REPR(rect)->setAttribute("ry", SP_OBJECT_REPR(rect)->attribute("rx"));
332     }
335 /**
336  *  Called when the vertical rounding radius knot is clicked.
337  */
338 static void sp_rect_ry_knot_click(SPItem *item, guint state)
340     SPRect *rect = SP_RECT(item);
342     if (state & GDK_SHIFT_MASK) {
343         rect_remove_rounding(rect);
344     } else if (state & GDK_CONTROL_MASK) {
345         /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
346         SP_OBJECT_REPR(rect)->setAttribute("rx", SP_OBJECT_REPR(rect)->attribute("ry"));
347     }
350 #define SGN(x) ((x)>0?1:((x)<0?-1:0))
352 static void sp_rect_clamp_radii(SPRect *rect)
354     // clamp rounding radii so that they do not exceed width/height
355     if (2 * rect->rx.computed > rect->width.computed) {
356         rect->rx.computed = 0.5 * rect->width.computed;
357         rect->rx._set = true;
358     }
359     if (2 * rect->ry.computed > rect->height.computed) {
360         rect->ry.computed = 0.5 * rect->height.computed;
361         rect->ry._set = true;
362     }
365 static NR::Point sp_rect_wh_get(SPItem *item)
367     SPRect *rect = SP_RECT(item);
369     return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
372 static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point const &origin, guint state)
374     NR::Point const s = snap_knot_position(rect, p);
376     if (state & GDK_CONTROL_MASK) {
377         // original width/height when drag started
378         gdouble const w_orig = (origin[NR::X] - rect->x.computed);
379         gdouble const h_orig = (origin[NR::Y] - rect->y.computed);
381         //original ratio
382         gdouble const ratio = (w_orig / h_orig);
384         // mouse displacement since drag started
385         gdouble const minx = s[NR::X] - origin[NR::X];
386         gdouble const miny = s[NR::Y] - origin[NR::Y];
388         if (fabs(minx) > fabs(miny)) {
390             // snap to horizontal or diagonal
391             rect->width.computed = MAX(w_orig + minx, 0);
392             if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
393                 // closer to the diagonal and in same-sign quarters, change both using ratio
394                 rect->height.computed = MAX(h_orig + minx / ratio, 0);
395             } else {
396                 // closer to the horizontal, change only width, height is h_orig
397                 rect->height.computed = MAX(h_orig, 0);
398             }
400         } else {
401             // snap to vertical or diagonal
402             rect->height.computed = MAX(h_orig + miny, 0);
403             if (miny != 0 && fabs(minx/miny) > 0.5 * ratio && (SGN(minx) == SGN(miny))) {
404                 // closer to the diagonal and in same-sign quarters, change both using ratio
405                 rect->width.computed = MAX(w_orig + miny * ratio, 0);
406             } else {
407                 // closer to the vertical, change only height, width is w_orig
408                 rect->width.computed = MAX(w_orig, 0);
409             }
410         }
412         rect->width._set = rect->height._set = true;
414     } else {
415         // move freely
416         rect->width.computed = MAX(s[NR::X] - rect->x.computed, 0);
417         rect->height.computed = MAX(s[NR::Y] - rect->y.computed, 0);
418         rect->width._set = rect->height._set = true;
419     }
421     sp_rect_clamp_radii(rect);
423     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
426 static void sp_rect_wh_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
428     SPRect *rect = SP_RECT(item);
430     sp_rect_wh_set_internal(rect, p, origin, state);
433 static NR::Point sp_rect_xy_get(SPItem *item)
435     SPRect *rect = SP_RECT(item);
437     return NR::Point(rect->x.computed, rect->y.computed);
440 static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
442     SPRect *rect = SP_RECT(item);
444     // opposite corner (unmoved)
445     gdouble opposite_x = (rect->x.computed + rect->width.computed);
446     gdouble opposite_y = (rect->y.computed + rect->height.computed);
448     // original width/height when drag started
449     gdouble w_orig = opposite_x - origin[NR::X];
450     gdouble h_orig = opposite_y - origin[NR::Y];
452     NR::Point const s = snap_knot_position(rect, p);
454     // mouse displacement since drag started
455     gdouble minx = s[NR::X] - origin[NR::X];
456     gdouble miny = s[NR::Y] - origin[NR::Y];
458     if (state & GDK_CONTROL_MASK) {
459         //original ratio
460         gdouble ratio = (w_orig / h_orig);
462         if (fabs(minx) > fabs(miny)) {
464             // snap to horizontal or diagonal
465             rect->x.computed = MIN(s[NR::X], opposite_x);
466             rect->width.computed = MAX(w_orig - minx, 0);
467             if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
468                 // closer to the diagonal and in same-sign quarters, change both using ratio
469                 rect->y.computed = MIN(origin[NR::Y] + minx / ratio, opposite_y);
470                 rect->height.computed = MAX(h_orig - minx / ratio, 0);
471             } else {
472                 // closer to the horizontal, change only width, height is h_orig
473                 rect->y.computed = MIN(origin[NR::Y], opposite_y);
474                 rect->height.computed = MAX(h_orig, 0);
475             }
477         } else {
479             // snap to vertical or diagonal
480             rect->y.computed = MIN(s[NR::Y], opposite_y);
481             rect->height.computed = MAX(h_orig - miny, 0);
482             if (miny != 0 && fabs(minx/miny) > 0.5 *ratio && (SGN(minx) == SGN(miny))) {
483                 // closer to the diagonal and in same-sign quarters, change both using ratio
484                 rect->x.computed = MIN(origin[NR::X] + miny * ratio, opposite_x);
485                 rect->width.computed = MAX(w_orig - miny * ratio, 0);
486             } else {
487                 // closer to the vertical, change only height, width is w_orig
488                 rect->x.computed = MIN(origin[NR::X], opposite_x);
489                 rect->width.computed = MAX(w_orig, 0);
490             }
492         }
494         rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
496     } else {
497         // move freely
498         rect->x.computed = MIN(s[NR::X], opposite_x);
499         rect->width.computed = MAX(w_orig - minx, 0);
500         rect->y.computed = MIN(s[NR::Y], opposite_y);
501         rect->height.computed = MAX(h_orig - miny, 0);
502         rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
503     }
505     sp_rect_clamp_radii(rect);
507     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
510 static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop)
512     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
514     sp_knot_holder_add_full(
515       knot_holder, sp_rect_rx_set, sp_rect_rx_get, sp_rect_rx_knot_click,
516       SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
517       _("Adjust the <b>horizontal rounding</b> radius; with <b>Ctrl</b> to make the vertical "
518         "radius the same"));
520     sp_knot_holder_add_full(
521       knot_holder, sp_rect_ry_set, sp_rect_ry_get, sp_rect_ry_knot_click,
522       SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
523       _("Adjust the <b>vertical rounding</b> radius; with <b>Ctrl</b> to make the horizontal "
524         "radius the same")
525       );
527     sp_knot_holder_add_full(
528       knot_holder, sp_rect_wh_set, sp_rect_wh_get, NULL,
529       SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
530       _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
531         "or stretch in one dimension only")
532       );
534     sp_knot_holder_add_full(
535       knot_holder, sp_rect_xy_set, sp_rect_xy_get, NULL,
536       SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
537       _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
538         "or stretch in one dimension only")
539       );
541     sp_pat_knot_holder(item, knot_holder);
542     return knot_holder;
545 /* Box3D (= the new 3D box structure) */
547 static NR::Point box3d_knot_get(SPItem *item, guint knot_id)
549     return box3d_get_corner_screen(SP_BOX3D(item), knot_id);
552 static void box3d_knot_set(SPItem *item, guint knot_id, NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
554     NR::Point const s = snap_knot_position(item, new_pos);
556     g_assert(item != NULL);
557     SPBox3D *box = SP_BOX3D(item);
558     NR::Matrix const i2d (sp_item_i2d_affine (item));
560     Box3D::Axis movement;
561     if ((knot_id < 4) != (state & GDK_SHIFT_MASK)) {
562         movement = Box3D::XY;
563     } else {
564         movement = Box3D::Z;
565     }
567     box3d_set_corner (box, knot_id, s * i2d, movement, (state & GDK_CONTROL_MASK));
568     box3d_set_z_orders(box);
569     box3d_position_set(box);
572 static NR::Point box3d_knot_center_get (SPItem *item)
574     return box3d_get_center_screen (SP_BOX3D(item));
577 static void box3d_knot_center_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
579     NR::Point const s = snap_knot_position(item, new_pos);
581     SPBox3D *box = SP_BOX3D(item);
582     NR::Matrix const i2d (sp_item_i2d_affine (item));
584     box3d_set_center (SP_BOX3D(item), s * i2d, origin * i2d, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z,
585                       state & GDK_CONTROL_MASK);
587     box3d_set_z_orders(box);
588     box3d_position_set(box);
591 static void box3d_knot0_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
593     box3d_knot_set(item, 0, new_pos, origin, state);
596 static void box3d_knot1_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
598     box3d_knot_set(item, 1, new_pos, origin, state);
601 static void box3d_knot2_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
603     box3d_knot_set(item, 2, new_pos, origin, state);
606 static void box3d_knot3_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
608     box3d_knot_set(item, 3, new_pos, origin, state);
611 static void box3d_knot4_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
613     box3d_knot_set(item, 4, new_pos, origin, state);
616 static void box3d_knot5_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
618     box3d_knot_set(item, 5, new_pos, origin, state);
621 static void box3d_knot6_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
623     box3d_knot_set(item, 6, new_pos, origin, state);
626 static void box3d_knot7_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
628     box3d_knot_set(item, 7, new_pos, origin, state);
631 static NR::Point box3d_knot0_get(SPItem *item)
633     return box3d_knot_get(item, 0);
636 static NR::Point box3d_knot1_get(SPItem *item)
638     return box3d_knot_get(item, 1);
641 static NR::Point box3d_knot2_get(SPItem *item)
643     return box3d_knot_get(item, 2);
646 static NR::Point box3d_knot3_get(SPItem *item)
648     return box3d_knot_get(item, 3);
651 static NR::Point box3d_knot4_get(SPItem *item)
653     return box3d_knot_get(item, 4);
656 static NR::Point box3d_knot5_get(SPItem *item)
658     return box3d_knot_get(item, 5);
661 static NR::Point box3d_knot6_get(SPItem *item)
663     return box3d_knot_get(item, 6);
666 static NR::Point box3d_knot7_get(SPItem *item)
668     return box3d_knot_get(item, 7);
671 SPKnotHolder *
672 box3d_knot_holder(SPItem *item, SPDesktop *desktop)
674     g_assert(item != NULL);
675     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
677     sp_knot_holder_add(knot_holder, box3d_knot0_set, box3d_knot0_get, NULL,
678                        _("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"));
679     sp_knot_holder_add(knot_holder, box3d_knot1_set, box3d_knot1_get, NULL,
680                        _("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"));
681     sp_knot_holder_add(knot_holder, box3d_knot2_set, box3d_knot2_get, NULL,
682                        _("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"));
683     sp_knot_holder_add(knot_holder, box3d_knot3_set, box3d_knot3_get, NULL,
684                        _("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"));
685     sp_knot_holder_add(knot_holder, box3d_knot4_set, box3d_knot4_get, NULL,
686                        _("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"));
687     sp_knot_holder_add(knot_holder, box3d_knot5_set, box3d_knot5_get, NULL,
688                        _("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"));
689     sp_knot_holder_add(knot_holder, box3d_knot6_set, box3d_knot6_get, NULL,
690                        _("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"));
691     sp_knot_holder_add(knot_holder, box3d_knot7_set, box3d_knot7_get, NULL,
692                        _("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"));
694     // center dragging
695     sp_knot_holder_add_full(knot_holder, box3d_knot_center_set, box3d_knot_center_get, NULL,
696                             SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,_("Move the box in perspective"));
698     sp_pat_knot_holder(item, knot_holder);
700     return knot_holder;
705 /* SPArc */
707 /*
708  * return values:
709  *   1  : inside
710  *   0  : on the curves
711  *   -1 : outside
712  */
713 static gint
714 sp_genericellipse_side(SPGenericEllipse *ellipse, NR::Point const &p)
716     gdouble dx = (p[NR::X] - ellipse->cx.computed) / ellipse->rx.computed;
717     gdouble dy = (p[NR::Y] - ellipse->cy.computed) / ellipse->ry.computed;
719     gdouble s = dx * dx + dy * dy;
720     if (s < 1.0) return 1;
721     if (s > 1.0) return -1;
722     return 0;
725 static void
726 sp_arc_start_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
728     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
730     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
731     SPArc *arc = SP_ARC(item);
733     ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
735     NR::Point delta = p - NR::Point(ge->cx.computed, ge->cy.computed);
736     NR::scale sc(ge->rx.computed, ge->ry.computed);
737     ge->start = atan2(delta * sc.inverse());
738     if ( ( state & GDK_CONTROL_MASK )
739          && snaps )
740     {
741         ge->start = sp_round(ge->start, M_PI/snaps);
742     }
743     sp_genericellipse_normalize(ge);
744     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
747 static NR::Point sp_arc_start_get(SPItem *item)
749     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
750     SPArc *arc = SP_ARC(item);
752     return sp_arc_get_xy(arc, ge->start);
755 static void
756 sp_arc_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
758     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
760     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
761     SPArc *arc = SP_ARC(item);
763     ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
765     NR::Point delta = p - NR::Point(ge->cx.computed, ge->cy.computed);
766     NR::scale sc(ge->rx.computed, ge->ry.computed);
767     ge->end = atan2(delta * sc.inverse());
768     if ( ( state & GDK_CONTROL_MASK )
769          && snaps )
770     {
771         ge->end = sp_round(ge->end, M_PI/snaps);
772     }
773     sp_genericellipse_normalize(ge);
774     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
777 static NR::Point sp_arc_end_get(SPItem *item)
779     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
780     SPArc *arc = SP_ARC(item);
782     return sp_arc_get_xy(arc, ge->end);
785 static void
786 sp_arc_startend_click(SPItem *item, guint state)
788     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
790     if (state & GDK_SHIFT_MASK) {
791         ge->end = ge->start = 0;
792         ((SPObject *)ge)->updateRepr();
793     }
797 static void
798 sp_arc_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
800     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
801     SPArc *arc = SP_ARC(item);
803     NR::Point const s = snap_knot_position(arc, p);
805     ge->rx.computed = fabs( ge->cx.computed - s[NR::X] );
807     if ( state & GDK_CONTROL_MASK ) {
808         ge->ry.computed = ge->rx.computed;
809     }
811     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
814 static NR::Point sp_arc_rx_get(SPItem *item)
816     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
818     return (NR::Point(ge->cx.computed, ge->cy.computed) -  NR::Point(ge->rx.computed, 0));
821 static void
822 sp_arc_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
824     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
825     SPArc *arc = SP_ARC(item);
827     NR::Point const s = snap_knot_position(arc, p);
829     ge->ry.computed = fabs( ge->cy.computed - s[NR::Y] );
831     if ( state & GDK_CONTROL_MASK ) {
832         ge->rx.computed = ge->ry.computed;
833     }
835     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
838 static NR::Point sp_arc_ry_get(SPItem *item)
840     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
842     return (NR::Point(ge->cx.computed, ge->cy.computed) -  NR::Point(0, ge->ry.computed));
845 static void
846 sp_arc_rx_click(SPItem *item, guint state)
848     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
850     if (state & GDK_CONTROL_MASK) {
851         ge->ry.computed = ge->rx.computed;
852         ((SPObject *)ge)->updateRepr();
853     }
856 static void
857 sp_arc_ry_click(SPItem *item, guint state)
859     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
861     if (state & GDK_CONTROL_MASK) {
862         ge->rx.computed = ge->ry.computed;
863         ((SPObject *)ge)->updateRepr();
864     }
867 static SPKnotHolder *
868 sp_arc_knot_holder(SPItem *item, SPDesktop *desktop)
870     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
872     sp_knot_holder_add_full(knot_holder, sp_arc_rx_set, sp_arc_rx_get, sp_arc_rx_click,
873                             SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
874                             _("Adjust ellipse <b>width</b>, with <b>Ctrl</b> to make circle"));
875     sp_knot_holder_add_full(knot_holder, sp_arc_ry_set, sp_arc_ry_get, sp_arc_ry_click,
876                             SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
877                             _("Adjust ellipse <b>height</b>, with <b>Ctrl</b> to make circle"));
878     sp_knot_holder_add_full(knot_holder, sp_arc_start_set, sp_arc_start_get, sp_arc_startend_click,
879                             SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
880                             _("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"));
881     sp_knot_holder_add_full(knot_holder, sp_arc_end_set, sp_arc_end_get, sp_arc_startend_click,
882                             SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
883                             _("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"));
885     sp_pat_knot_holder(item, knot_holder);
887     return knot_holder;
890 /* SPStar */
892 static void
893 sp_star_knot1_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
895     SPStar *star = SP_STAR(item);
897     NR::Point const s = snap_knot_position(star, p);
899     NR::Point d = s - star->center;
901     double arg1 = atan2(d);
902     double darg1 = arg1 - star->arg[0];
904     if (state & GDK_MOD1_MASK) {
905         star->randomized = darg1/(star->arg[0] - star->arg[1]);
906     } else if (state & GDK_SHIFT_MASK) {
907         star->rounded = darg1/(star->arg[0] - star->arg[1]);
908     } else if (state & GDK_CONTROL_MASK) {
909         star->r[0]    = L2(d);
910     } else {
911         star->r[0]    = L2(d);
912         star->arg[0]  = arg1;
913         star->arg[1] += darg1;
914     }
915     ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
918 static void
919 sp_star_knot2_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
921     SPStar *star = SP_STAR(item);
923     NR::Point const s = snap_knot_position(star, p);
925     if (star->flatsided == false) {
926         NR::Point d = s - star->center;
928         double arg1 = atan2(d);
929         double darg1 = arg1 - star->arg[1];
931         if (state & GDK_MOD1_MASK) {
932             star->randomized = darg1/(star->arg[0] - star->arg[1]);
933         } else if (state & GDK_SHIFT_MASK) {
934             star->rounded = fabs(darg1/(star->arg[0] - star->arg[1]));
935         } else if (state & GDK_CONTROL_MASK) {
936             star->r[1]   = L2(d);
937             star->arg[1] = star->arg[0] + M_PI / star->sides;
938         }
939         else {
940             star->r[1]   = L2(d);
941             star->arg[1] = atan2(d);
942         }
943         ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
944     }
947 static NR::Point sp_star_knot1_get(SPItem *item)
949     g_assert(item != NULL);
951     SPStar *star = SP_STAR(item);
953     return sp_star_get_xy(star, SP_STAR_POINT_KNOT1, 0);
957 static NR::Point sp_star_knot2_get(SPItem *item)
959     g_assert(item != NULL);
961     SPStar *star = SP_STAR(item);
963     return sp_star_get_xy(star, SP_STAR_POINT_KNOT2, 0);
966 static void
967 sp_star_knot_click(SPItem *item, guint state)
969     SPStar *star = SP_STAR(item);
971     if (state & GDK_MOD1_MASK) {
972         star->randomized = 0;
973         ((SPObject *)star)->updateRepr();
974     } else if (state & GDK_SHIFT_MASK) {
975         star->rounded = 0;
976         ((SPObject *)star)->updateRepr();
977     } else if (state & GDK_CONTROL_MASK) {
978         star->arg[1] = star->arg[0] + M_PI / star->sides;
979         ((SPObject *)star)->updateRepr();
980     }
983 static SPKnotHolder *
984 sp_star_knot_holder(SPItem *item, SPDesktop *desktop)
986     /* we don't need to get parent knot_holder */
987     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
988     g_assert(item != NULL);
990     SPStar *star = SP_STAR(item);
992     sp_knot_holder_add(knot_holder, sp_star_knot1_set, sp_star_knot1_get, sp_star_knot_click,
993                        _("Adjust the <b>tip radius</b> of the star or polygon; with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
994     if (star->flatsided == false)
995         sp_knot_holder_add(knot_holder, sp_star_knot2_set, sp_star_knot2_get, sp_star_knot_click,
996                            _("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"));
998     sp_pat_knot_holder(item, knot_holder);
1000     return knot_holder;
1003 /* SPSpiral */
1005 /*
1006  * set attributes via inner (t=t0) knot point:
1007  *   [default] increase/decrease inner point
1008  *   [shift]   increase/decrease inner and outer arg synchronizely
1009  *   [control] constrain inner arg to round per PI/4
1010  */
1011 static void
1012 sp_spiral_inner_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
1014     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1016     SPSpiral *spiral = SP_SPIRAL(item);
1018     gdouble   dx = p[NR::X] - spiral->cx;
1019     gdouble   dy = p[NR::Y] - spiral->cy;
1021     if (state & GDK_MOD1_MASK) {
1022         // adjust divergence by vertical drag, relative to rad
1023         double new_exp = (spiral->rad + dy)/(spiral->rad);
1024         spiral->exp = new_exp > 0? new_exp : 0;
1025     } else {
1026         // roll/unroll from inside
1027         gdouble   arg_t0;
1028         sp_spiral_get_polar(spiral, spiral->t0, NULL, &arg_t0);
1030         gdouble   arg_tmp = atan2(dy, dx) - arg_t0;
1031         gdouble   arg_t0_new = arg_tmp - floor((arg_tmp+M_PI)/(2.0*M_PI))*2.0*M_PI + arg_t0;
1032         spiral->t0 = (arg_t0_new - spiral->arg) / (2.0*M_PI*spiral->revo);
1034         /* round inner arg per PI/snaps, if CTRL is pressed */
1035         if ( ( state & GDK_CONTROL_MASK )
1036              && ( fabs(spiral->revo) > SP_EPSILON_2 )
1037              && ( snaps != 0 ) ) {
1038             gdouble arg = 2.0*M_PI*spiral->revo*spiral->t0 + spiral->arg;
1039             spiral->t0 = (sp_round(arg, M_PI/snaps) - spiral->arg)/(2.0*M_PI*spiral->revo);
1040         }
1042         spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1043     }
1045     ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1048 /*
1049  * set attributes via outer (t=1) knot point:
1050  *   [default] increase/decrease revolution factor
1051  *   [control] constrain inner arg to round per PI/4
1052  */
1053 static void
1054 sp_spiral_outer_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
1056     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1058     SPSpiral *spiral = SP_SPIRAL(item);
1060     gdouble  dx = p[NR::X] - spiral->cx;
1061     gdouble  dy = p[NR::Y] - spiral->cy;
1063     if (state & GDK_SHIFT_MASK) { // rotate without roll/unroll
1064         spiral->arg = atan2(dy, dx) - 2.0*M_PI*spiral->revo;
1065         if (!(state & GDK_MOD1_MASK)) {
1066             // if alt not pressed, change also rad; otherwise it is locked
1067             spiral->rad = MAX(hypot(dx, dy), 0.001);
1068         }
1069         if ( ( state & GDK_CONTROL_MASK )
1070              && snaps ) {
1071             spiral->arg = sp_round(spiral->arg, M_PI/snaps);
1072         }
1073     } else { // roll/unroll
1074         // arg of the spiral outer end
1075         double arg_1;
1076         sp_spiral_get_polar(spiral, 1, NULL, &arg_1);
1078         // its fractional part after the whole turns are subtracted
1079         double arg_r = arg_1 - sp_round(arg_1, 2.0*M_PI);
1081         // arg of the mouse point relative to spiral center
1082         double mouse_angle = atan2(dy, dx);
1083         if (mouse_angle < 0)
1084             mouse_angle += 2*M_PI;
1086         // snap if ctrl
1087         if ( ( state & GDK_CONTROL_MASK ) && snaps ) {
1088             mouse_angle = sp_round(mouse_angle, M_PI/snaps);
1089         }
1091         // by how much we want to rotate the outer point
1092         double diff = mouse_angle - arg_r;
1093         if (diff > M_PI)
1094             diff -= 2*M_PI;
1095         else if (diff < -M_PI)
1096             diff += 2*M_PI;
1098         // calculate the new rad;
1099         // the value of t corresponding to the angle arg_1 + diff:
1100         double t_temp = ((arg_1 + diff) - spiral->arg)/(2*M_PI*spiral->revo);
1101         // the rad at that t:
1102         double rad_new = 0;
1103         if (t_temp > spiral->t0)
1104             sp_spiral_get_polar(spiral, t_temp, &rad_new, NULL);
1106         // change the revo (converting diff from radians to the number of turns)
1107         spiral->revo += diff/(2*M_PI);
1108         if (spiral->revo < 1e-3)
1109             spiral->revo = 1e-3;
1111         // if alt not pressed and the values are sane, change the rad
1112         if (!(state & GDK_MOD1_MASK) && rad_new > 1e-3 && rad_new/spiral->rad < 2) {
1113             // adjust t0 too so that the inner point stays unmoved
1114             double r0;
1115             sp_spiral_get_polar(spiral, spiral->t0, &r0, NULL);
1116             spiral->rad = rad_new;
1117             spiral->t0 = pow(r0 / spiral->rad, 1.0/spiral->exp);
1118         }
1119         if (!IS_FINITE(spiral->t0)) spiral->t0 = 0.0;
1120         spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1121     }
1123     ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1126 static NR::Point sp_spiral_inner_get(SPItem *item)
1128     SPSpiral *spiral = SP_SPIRAL(item);
1130     return sp_spiral_get_xy(spiral, spiral->t0);
1133 static NR::Point sp_spiral_outer_get(SPItem *item)
1135     SPSpiral *spiral = SP_SPIRAL(item);
1137     return sp_spiral_get_xy(spiral, 1.0);
1140 static void
1141 sp_spiral_inner_click(SPItem *item, guint state)
1143     SPSpiral *spiral = SP_SPIRAL(item);
1145     if (state & GDK_MOD1_MASK) {
1146         spiral->exp = 1;
1147         ((SPObject *)spiral)->updateRepr();
1148     } else if (state & GDK_SHIFT_MASK) {
1149         spiral->t0 = 0;
1150         ((SPObject *)spiral)->updateRepr();
1151     }
1154 static SPKnotHolder *
1155 sp_spiral_knot_holder(SPItem *item, SPDesktop *desktop)
1157     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1159     sp_knot_holder_add(knot_holder, sp_spiral_inner_set, sp_spiral_inner_get, sp_spiral_inner_click,
1160                        _("Roll/unroll the spiral from <b>inside</b>; with <b>Ctrl</b> to snap angle; with <b>Alt</b> to converge/diverge"));
1161     sp_knot_holder_add(knot_holder, sp_spiral_outer_set, sp_spiral_outer_get, NULL,
1162                        _("Roll/unroll the spiral from <b>outside</b>; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to scale/rotate"));
1164     sp_pat_knot_holder(item, knot_holder);
1166     return knot_holder;
1169 /* SPOffset */
1171 static void
1172 sp_offset_offset_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
1174     SPOffset *offset = SP_OFFSET(item);
1176     offset->rad = sp_offset_distance_to_original(offset, p);
1177     offset->knot = p;
1178     offset->knotSet = true;
1180     ((SPObject *)offset)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1184 static NR::Point sp_offset_offset_get(SPItem *item)
1186     SPOffset *offset = SP_OFFSET(item);
1188     NR::Point np;
1189     sp_offset_top_point(offset,&np);
1190     return np;
1193 static SPKnotHolder *
1194 sp_offset_knot_holder(SPItem *item, SPDesktop *desktop)
1196     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1198     sp_knot_holder_add(knot_holder, sp_offset_offset_set, sp_offset_offset_get, NULL,
1199                        _("Adjust the <b>offset distance</b>"));
1201     sp_pat_knot_holder(item, knot_holder);
1203     return knot_holder;
1206 static SPKnotHolder *
1207 sp_misc_knot_holder(SPItem *item, SPDesktop *desktop) // FIXME: eliminate, instead make a pattern-drag similar to gradient-drag
1209     if ((SP_OBJECT(item)->style->fill.isPaintserver())
1210         && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
1211     {
1212         SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1214         sp_pat_knot_holder(item, knot_holder);
1216         return knot_holder;
1217     }
1218     return NULL;
1221 static void
1222 sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder)
1224     if ((SP_OBJECT(item)->style->fill.isPaintserver())
1225         && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
1226     {
1227         sp_knot_holder_add_full(knot_holder, sp_pattern_xy_set, sp_pattern_xy_get, NULL, SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,
1228                                 // TRANSLATORS: This refers to the pattern that's inside the object
1229                                 _("<b>Move</b> the pattern fill inside the object"));
1230         sp_knot_holder_add_full(knot_holder, sp_pattern_scale_set, sp_pattern_scale_get, NULL, SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
1231                                 _("<b>Scale</b> the pattern fill uniformly"));
1232         sp_knot_holder_add_full(knot_holder, sp_pattern_angle_set, sp_pattern_angle_get, NULL, SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
1233                                 _("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"));
1234     }
1237 static NR::Point sp_flowtext_corner_get(SPItem *item)
1239     SPRect *rect = SP_RECT(item);
1241     return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
1244 static void
1245 sp_flowtext_corner_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
1247     SPRect *rect = SP_RECT(item);
1249     sp_rect_wh_set_internal(rect, p, origin, state);
1252 static SPKnotHolder *
1253 sp_flowtext_knot_holder(SPItem *item, SPDesktop *desktop)
1255     SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL);
1257     sp_knot_holder_add(knot_holder, sp_flowtext_corner_set, sp_flowtext_corner_get, NULL,
1258                        _("Drag to resize the <b>flowed text frame</b>"));
1260     return knot_holder;
1264 /*
1265   Local Variables:
1266   mode:c++
1267   c-file-style:"stroustrup"
1268   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1269   indent-tabs-mode:nil
1270   fill-column:99
1271   End:
1272 */
1273 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :