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"
36 #include "sp-pattern.h"
37 #include "sp-path.h"
39 #include <glibmm/i18n.h>
41 #include "object-edit.h"
43 #include <libnr/nr-scale-ops.h>
45 #include "xml/repr.h"
47 #include "isnan.h"
49 #define sp_round(v,m) (((v) < 0.0) ? ((ceil((v) / (m) - 0.5)) * (m)) : ((floor((v) / (m) + 0.5)) * (m)))
51 static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop);
52 static SPKnotHolder *box3d_knot_holder(SPItem *item, SPDesktop *desktop);
53 static SPKnotHolder *sp_arc_knot_holder(SPItem *item, SPDesktop *desktop);
54 static SPKnotHolder *sp_star_knot_holder(SPItem *item, SPDesktop *desktop);
55 static SPKnotHolder *sp_spiral_knot_holder(SPItem *item, SPDesktop *desktop);
56 static SPKnotHolder *sp_offset_knot_holder(SPItem *item, SPDesktop *desktop);
57 static SPKnotHolder *sp_misc_knot_holder(SPItem *item, SPDesktop *desktop);
58 static SPKnotHolder *sp_flowtext_knot_holder(SPItem *item, SPDesktop *desktop);
59 static void sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder);
61 SPKnotHolder *
62 sp_item_knot_holder(SPItem *item, SPDesktop *desktop)
63 {
64 if (SP_IS_RECT(item)) {
65 return sp_rect_knot_holder(item, desktop);
66 } else if (SP_IS_BOX3D(item)) {
67 return box3d_knot_holder(item, desktop);
68 } else if (SP_IS_ARC(item)) {
69 return sp_arc_knot_holder(item, desktop);
70 } else if (SP_IS_STAR(item)) {
71 return sp_star_knot_holder(item, desktop);
72 } else if (SP_IS_SPIRAL(item)) {
73 return sp_spiral_knot_holder(item, desktop);
74 } else if (SP_IS_OFFSET(item)) {
75 return sp_offset_knot_holder(item, desktop);
76 } else if (SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
77 return sp_flowtext_knot_holder(item, desktop);
78 } else {
79 return sp_misc_knot_holder(item, desktop);
80 }
82 return NULL;
83 }
86 /* Pattern manipulation */
88 static gdouble sp_pattern_extract_theta(SPPattern *pat, gdouble scale)
89 {
90 gdouble theta = asin(pat->patternTransform[1] / scale);
91 if (pat->patternTransform[0] < 0) theta = M_PI - theta ;
92 return theta;
93 }
95 static gdouble sp_pattern_extract_scale(SPPattern *pat)
96 {
97 gdouble s = pat->patternTransform[1];
98 gdouble c = pat->patternTransform[0];
99 gdouble xscale = sqrt(c * c + s * s);
100 return xscale;
101 }
103 static NR::Point sp_pattern_extract_trans(SPPattern const *pat)
104 {
105 return NR::Point(pat->patternTransform[4], pat->patternTransform[5]);
106 }
108 static void
109 sp_pattern_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
110 {
111 SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
113 NR::Point p_snapped = p;
115 if ( state & GDK_CONTROL_MASK ) {
116 if (fabs((p - origin)[NR::X]) > fabs((p - origin)[NR::Y])) {
117 p_snapped[NR::Y] = origin[NR::Y];
118 } else {
119 p_snapped[NR::X] = origin[NR::X];
120 }
121 }
123 if (state) {
124 NR::Point const q = p_snapped - sp_pattern_extract_trans(pat);
125 sp_item_adjust_pattern(item, NR::Matrix(NR::translate(q)));
126 }
128 item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
129 }
132 static NR::Point sp_pattern_xy_get(SPItem *item)
133 {
134 SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
135 return sp_pattern_extract_trans(pat);
136 }
138 static NR::Point sp_pattern_angle_get(SPItem *item)
139 {
140 SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
142 gdouble x = (pattern_width(pat)*0.5);
143 gdouble y = 0;
144 NR::Point delta = NR::Point(x,y);
145 gdouble scale = sp_pattern_extract_scale(pat);
146 gdouble theta = sp_pattern_extract_theta(pat, scale);
147 delta = delta * NR::Matrix(NR::rotate(theta))*NR::Matrix(NR::scale(scale,scale));
148 delta = delta + sp_pattern_extract_trans(pat);
149 return delta;
150 }
152 static void
153 sp_pattern_angle_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
154 {
155 int const snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
157 SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
159 // get the angle from pattern 0,0 to the cursor pos
160 NR::Point delta = p - sp_pattern_extract_trans(pat);
161 gdouble theta = atan2(delta);
163 if ( state & GDK_CONTROL_MASK ) {
164 theta = sp_round(theta, M_PI/snaps);
165 }
167 // get the scale from the current transform so we can keep it.
168 gdouble scl = sp_pattern_extract_scale(pat);
169 NR::Matrix rot = NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl));
170 NR::Point const t = sp_pattern_extract_trans(pat);
171 rot[4] = t[NR::X];
172 rot[5] = t[NR::Y];
173 sp_item_adjust_pattern(item, rot, true);
174 item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
175 }
177 static void
178 sp_pattern_scale_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
179 {
180 SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
182 // Get the scale from the position of the knotholder,
183 NR::Point d = p - sp_pattern_extract_trans(pat);
184 gdouble s = NR::L2(d);
185 gdouble pat_x = pattern_width(pat) * 0.5;
186 gdouble pat_y = pattern_height(pat) * 0.5;
187 gdouble pat_h = hypot(pat_x, pat_y);
188 gdouble scl = s / pat_h;
190 // get angle from current transform, (need get current scale first to calculate angle)
191 gdouble oldscale = sp_pattern_extract_scale(pat);
192 gdouble theta = sp_pattern_extract_theta(pat,oldscale);
194 NR::Matrix rot = NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl));
195 NR::Point const t = sp_pattern_extract_trans(pat);
196 rot[4] = t[NR::X];
197 rot[5] = t[NR::Y];
198 sp_item_adjust_pattern(item, rot, true);
199 item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
200 }
203 static NR::Point sp_pattern_scale_get(SPItem *item)
204 {
205 SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
207 gdouble x = pattern_width(pat)*0.5;
208 gdouble y = pattern_height(pat)*0.5;
209 NR::Point delta = NR::Point(x,y);
210 NR::Matrix a = pat->patternTransform;
211 a[4] = 0;
212 a[5] = 0;
213 delta = delta * a;
214 delta = delta + sp_pattern_extract_trans(pat);
215 return delta;
216 }
218 /* SPRect */
220 static NR::Point snap_knot_position(SPItem *item, NR::Point const &p)
221 {
222 SPDesktop const *desktop = inkscape_active_desktop();
223 NR::Matrix const i2d (sp_item_i2d_affine (item));
224 NR::Point s = p * i2d;
225 SnapManager &m = desktop->namedview->snap_manager;
226 m.setup(desktop, item);
227 s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, s).getPoint();
228 return s * i2d.inverse();
229 }
231 static NR::Point sp_rect_rx_get(SPItem *item)
232 {
233 SPRect *rect = SP_RECT(item);
235 return NR::Point(rect->x.computed + rect->width.computed - rect->rx.computed, rect->y.computed);
236 }
238 static void sp_rect_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
239 {
240 SPRect *rect = SP_RECT(item);
242 //In general we cannot just snap this radius to an arbitrary point, as we have only a single
243 //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
244 //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
246 if (state & GDK_CONTROL_MASK) {
247 gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
248 rect->rx.computed = rect->ry.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, temp);
249 rect->rx._set = rect->ry._set = true;
251 } else {
252 rect->rx.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, rect->width.computed / 2.0);
253 rect->rx._set = true;
254 }
256 ((SPObject*)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
257 }
260 static NR::Point sp_rect_ry_get(SPItem *item)
261 {
262 SPRect *rect = SP_RECT(item);
264 return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->ry.computed);
265 }
267 static void sp_rect_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
268 {
269 SPRect *rect = SP_RECT(item);
271 //In general we cannot just snap this radius to an arbitrary point, as we have only a single
272 //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
273 //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
275 if (state & GDK_CONTROL_MASK) {
276 gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
277 rect->rx.computed = rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed, 0.0, temp);
278 rect->ry._set = rect->rx._set = true;
279 } else {
280 if (!rect->rx._set || rect->rx.computed == 0) {
281 rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
282 0.0,
283 MIN(rect->height.computed / 2.0, rect->width.computed / 2.0));
284 } else {
285 rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
286 0.0,
287 rect->height.computed / 2.0);
288 }
290 rect->ry._set = true;
291 }
293 ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
294 }
296 /**
297 * Remove rounding from a rectangle.
298 */
299 static void rect_remove_rounding(SPRect *rect)
300 {
301 SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
302 SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
303 }
305 /**
306 * Called when the horizontal rounding radius knot is clicked.
307 */
308 static void sp_rect_rx_knot_click(SPItem *item, guint state)
309 {
310 SPRect *rect = SP_RECT(item);
312 if (state & GDK_SHIFT_MASK) {
313 rect_remove_rounding(rect);
314 } else if (state & GDK_CONTROL_MASK) {
315 /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
316 SP_OBJECT_REPR(rect)->setAttribute("ry", SP_OBJECT_REPR(rect)->attribute("rx"));
317 }
318 }
320 /**
321 * Called when the vertical rounding radius knot is clicked.
322 */
323 static void sp_rect_ry_knot_click(SPItem *item, guint state)
324 {
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("rx", SP_OBJECT_REPR(rect)->attribute("ry"));
332 }
333 }
335 #define SGN(x) ((x)>0?1:((x)<0?-1:0))
337 static void sp_rect_clamp_radii(SPRect *rect)
338 {
339 // clamp rounding radii so that they do not exceed width/height
340 if (2 * rect->rx.computed > rect->width.computed) {
341 rect->rx.computed = 0.5 * rect->width.computed;
342 rect->rx._set = true;
343 }
344 if (2 * rect->ry.computed > rect->height.computed) {
345 rect->ry.computed = 0.5 * rect->height.computed;
346 rect->ry._set = true;
347 }
348 }
350 static NR::Point sp_rect_wh_get(SPItem *item)
351 {
352 SPRect *rect = SP_RECT(item);
354 return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
355 }
357 static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point const &origin, guint state)
358 {
359 NR::Point const s = snap_knot_position(rect, p);
361 if (state & GDK_CONTROL_MASK) {
362 // original width/height when drag started
363 gdouble const w_orig = (origin[NR::X] - rect->x.computed);
364 gdouble const h_orig = (origin[NR::Y] - rect->y.computed);
366 //original ratio
367 gdouble const ratio = (w_orig / h_orig);
369 // mouse displacement since drag started
370 gdouble const minx = s[NR::X] - origin[NR::X];
371 gdouble const miny = s[NR::Y] - origin[NR::Y];
373 if (fabs(minx) > fabs(miny)) {
375 // snap to horizontal or diagonal
376 rect->width.computed = MAX(w_orig + minx, 0);
377 if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
378 // closer to the diagonal and in same-sign quarters, change both using ratio
379 rect->height.computed = MAX(h_orig + minx / ratio, 0);
380 } else {
381 // closer to the horizontal, change only width, height is h_orig
382 rect->height.computed = MAX(h_orig, 0);
383 }
385 } else {
386 // snap to vertical or diagonal
387 rect->height.computed = MAX(h_orig + miny, 0);
388 if (miny != 0 && fabs(minx/miny) > 0.5 * ratio && (SGN(minx) == SGN(miny))) {
389 // closer to the diagonal and in same-sign quarters, change both using ratio
390 rect->width.computed = MAX(w_orig + miny * ratio, 0);
391 } else {
392 // closer to the vertical, change only height, width is w_orig
393 rect->width.computed = MAX(w_orig, 0);
394 }
395 }
397 rect->width._set = rect->height._set = true;
399 } else {
400 // move freely
401 rect->width.computed = MAX(s[NR::X] - rect->x.computed, 0);
402 rect->height.computed = MAX(s[NR::Y] - rect->y.computed, 0);
403 rect->width._set = rect->height._set = true;
404 }
406 sp_rect_clamp_radii(rect);
408 ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
409 }
411 static void sp_rect_wh_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
412 {
413 SPRect *rect = SP_RECT(item);
415 sp_rect_wh_set_internal(rect, p, origin, state);
416 }
418 static NR::Point sp_rect_xy_get(SPItem *item)
419 {
420 SPRect *rect = SP_RECT(item);
422 return NR::Point(rect->x.computed, rect->y.computed);
423 }
425 static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
426 {
427 SPRect *rect = SP_RECT(item);
429 // opposite corner (unmoved)
430 gdouble opposite_x = (rect->x.computed + rect->width.computed);
431 gdouble opposite_y = (rect->y.computed + rect->height.computed);
433 // original width/height when drag started
434 gdouble w_orig = opposite_x - origin[NR::X];
435 gdouble h_orig = opposite_y - origin[NR::Y];
437 NR::Point const s = snap_knot_position(rect, p);
439 // mouse displacement since drag started
440 gdouble minx = s[NR::X] - origin[NR::X];
441 gdouble miny = s[NR::Y] - origin[NR::Y];
443 if (state & GDK_CONTROL_MASK) {
444 //original ratio
445 gdouble ratio = (w_orig / h_orig);
447 if (fabs(minx) > fabs(miny)) {
449 // snap to horizontal or diagonal
450 rect->x.computed = MIN(s[NR::X], opposite_x);
451 rect->width.computed = MAX(w_orig - minx, 0);
452 if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
453 // closer to the diagonal and in same-sign quarters, change both using ratio
454 rect->y.computed = MIN(origin[NR::Y] + minx / ratio, opposite_y);
455 rect->height.computed = MAX(h_orig - minx / ratio, 0);
456 } else {
457 // closer to the horizontal, change only width, height is h_orig
458 rect->y.computed = MIN(origin[NR::Y], opposite_y);
459 rect->height.computed = MAX(h_orig, 0);
460 }
462 } else {
464 // snap to vertical or diagonal
465 rect->y.computed = MIN(s[NR::Y], opposite_y);
466 rect->height.computed = MAX(h_orig - miny, 0);
467 if (miny != 0 && fabs(minx/miny) > 0.5 *ratio && (SGN(minx) == SGN(miny))) {
468 // closer to the diagonal and in same-sign quarters, change both using ratio
469 rect->x.computed = MIN(origin[NR::X] + miny * ratio, opposite_x);
470 rect->width.computed = MAX(w_orig - miny * ratio, 0);
471 } else {
472 // closer to the vertical, change only height, width is w_orig
473 rect->x.computed = MIN(origin[NR::X], opposite_x);
474 rect->width.computed = MAX(w_orig, 0);
475 }
477 }
479 rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
481 } else {
482 // move freely
483 rect->x.computed = MIN(s[NR::X], opposite_x);
484 rect->width.computed = MAX(w_orig - minx, 0);
485 rect->y.computed = MIN(s[NR::Y], opposite_y);
486 rect->height.computed = MAX(h_orig - miny, 0);
487 rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
488 }
490 sp_rect_clamp_radii(rect);
492 ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
493 }
495 static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop)
496 {
497 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
499 sp_knot_holder_add_full(
500 knot_holder, sp_rect_rx_set, sp_rect_rx_get, sp_rect_rx_knot_click,
501 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
502 _("Adjust the <b>horizontal rounding</b> radius; with <b>Ctrl</b> to make the vertical "
503 "radius the same"));
505 sp_knot_holder_add_full(
506 knot_holder, sp_rect_ry_set, sp_rect_ry_get, sp_rect_ry_knot_click,
507 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
508 _("Adjust the <b>vertical rounding</b> radius; with <b>Ctrl</b> to make the horizontal "
509 "radius the same")
510 );
512 sp_knot_holder_add_full(
513 knot_holder, sp_rect_wh_set, sp_rect_wh_get, NULL,
514 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
515 _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
516 "or stretch in one dimension only")
517 );
519 sp_knot_holder_add_full(
520 knot_holder, sp_rect_xy_set, sp_rect_xy_get, NULL,
521 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
522 _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
523 "or stretch in one dimension only")
524 );
526 sp_pat_knot_holder(item, knot_holder);
527 return knot_holder;
528 }
530 /* Box3D (= the new 3D box structure) */
532 static NR::Point box3d_knot_get(SPItem *item, guint knot_id)
533 {
534 return box3d_get_corner_screen(SP_BOX3D(item), knot_id);
535 }
537 static void box3d_knot_set(SPItem *item, guint knot_id, NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
538 {
539 NR::Point const s = snap_knot_position(item, new_pos);
541 g_assert(item != NULL);
542 SPBox3D *box = SP_BOX3D(item);
543 NR::Matrix const i2d (sp_item_i2d_affine (item));
545 Box3D::Axis movement;
546 if ((knot_id < 4) != (state & GDK_SHIFT_MASK)) {
547 movement = Box3D::XY;
548 } else {
549 movement = Box3D::Z;
550 }
552 box3d_set_corner (box, knot_id, s * i2d, movement, (state & GDK_CONTROL_MASK));
553 box3d_set_z_orders(box);
554 box3d_position_set(box);
555 }
557 static NR::Point box3d_knot_center_get (SPItem *item)
558 {
559 return box3d_get_center_screen (SP_BOX3D(item));
560 }
562 static void box3d_knot_center_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
563 {
564 NR::Point const s = snap_knot_position(item, new_pos);
566 SPBox3D *box = SP_BOX3D(item);
567 NR::Matrix const i2d (sp_item_i2d_affine (item));
569 box3d_set_center (SP_BOX3D(item), s * i2d, origin * i2d, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z,
570 state & GDK_CONTROL_MASK);
572 box3d_set_z_orders(box);
573 box3d_position_set(box);
574 }
576 static void box3d_knot0_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
577 {
578 box3d_knot_set(item, 0, new_pos, origin, state);
579 }
581 static void box3d_knot1_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
582 {
583 box3d_knot_set(item, 1, new_pos, origin, state);
584 }
586 static void box3d_knot2_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
587 {
588 box3d_knot_set(item, 2, new_pos, origin, state);
589 }
591 static void box3d_knot3_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
592 {
593 box3d_knot_set(item, 3, new_pos, origin, state);
594 }
596 static void box3d_knot4_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
597 {
598 box3d_knot_set(item, 4, new_pos, origin, state);
599 }
601 static void box3d_knot5_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
602 {
603 box3d_knot_set(item, 5, new_pos, origin, state);
604 }
606 static void box3d_knot6_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
607 {
608 box3d_knot_set(item, 6, new_pos, origin, state);
609 }
611 static void box3d_knot7_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
612 {
613 box3d_knot_set(item, 7, new_pos, origin, state);
614 }
616 static NR::Point box3d_knot0_get(SPItem *item)
617 {
618 return box3d_knot_get(item, 0);
619 }
621 static NR::Point box3d_knot1_get(SPItem *item)
622 {
623 return box3d_knot_get(item, 1);
624 }
626 static NR::Point box3d_knot2_get(SPItem *item)
627 {
628 return box3d_knot_get(item, 2);
629 }
631 static NR::Point box3d_knot3_get(SPItem *item)
632 {
633 return box3d_knot_get(item, 3);
634 }
636 static NR::Point box3d_knot4_get(SPItem *item)
637 {
638 return box3d_knot_get(item, 4);
639 }
641 static NR::Point box3d_knot5_get(SPItem *item)
642 {
643 return box3d_knot_get(item, 5);
644 }
646 static NR::Point box3d_knot6_get(SPItem *item)
647 {
648 return box3d_knot_get(item, 6);
649 }
651 static NR::Point box3d_knot7_get(SPItem *item)
652 {
653 return box3d_knot_get(item, 7);
654 }
656 SPKnotHolder *
657 box3d_knot_holder(SPItem *item, SPDesktop *desktop)
658 {
659 g_assert(item != NULL);
660 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
662 sp_knot_holder_add(knot_holder, box3d_knot0_set, box3d_knot0_get, NULL,
663 _("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"));
664 sp_knot_holder_add(knot_holder, box3d_knot1_set, box3d_knot1_get, NULL,
665 _("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"));
666 sp_knot_holder_add(knot_holder, box3d_knot2_set, box3d_knot2_get, NULL,
667 _("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"));
668 sp_knot_holder_add(knot_holder, box3d_knot3_set, box3d_knot3_get, NULL,
669 _("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"));
670 sp_knot_holder_add(knot_holder, box3d_knot4_set, box3d_knot4_get, NULL,
671 _("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"));
672 sp_knot_holder_add(knot_holder, box3d_knot5_set, box3d_knot5_get, NULL,
673 _("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"));
674 sp_knot_holder_add(knot_holder, box3d_knot6_set, box3d_knot6_get, NULL,
675 _("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"));
676 sp_knot_holder_add(knot_holder, box3d_knot7_set, box3d_knot7_get, NULL,
677 _("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"));
679 // center dragging
680 sp_knot_holder_add_full(knot_holder, box3d_knot_center_set, box3d_knot_center_get, NULL,
681 SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,_("Move the box in perspective"));
683 sp_pat_knot_holder(item, knot_holder);
685 return knot_holder;
686 }
690 /* SPArc */
692 /*
693 * return values:
694 * 1 : inside
695 * 0 : on the curves
696 * -1 : outside
697 */
698 static gint
699 sp_genericellipse_side(SPGenericEllipse *ellipse, NR::Point const &p)
700 {
701 gdouble dx = (p[NR::X] - ellipse->cx.computed) / ellipse->rx.computed;
702 gdouble dy = (p[NR::Y] - ellipse->cy.computed) / ellipse->ry.computed;
704 gdouble s = dx * dx + dy * dy;
705 if (s < 1.0) return 1;
706 if (s > 1.0) return -1;
707 return 0;
708 }
710 static void
711 sp_arc_start_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
712 {
713 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
715 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
716 SPArc *arc = SP_ARC(item);
718 ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
720 NR::Point delta = p - NR::Point(ge->cx.computed, ge->cy.computed);
721 NR::scale sc(ge->rx.computed, ge->ry.computed);
722 ge->start = atan2(delta * sc.inverse());
723 if ( ( state & GDK_CONTROL_MASK )
724 && snaps )
725 {
726 ge->start = sp_round(ge->start, M_PI/snaps);
727 }
728 sp_genericellipse_normalize(ge);
729 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
730 }
732 static NR::Point sp_arc_start_get(SPItem *item)
733 {
734 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
735 SPArc *arc = SP_ARC(item);
737 return sp_arc_get_xy(arc, ge->start);
738 }
740 static void
741 sp_arc_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
742 {
743 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
745 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
746 SPArc *arc = SP_ARC(item);
748 ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
750 NR::Point delta = p - NR::Point(ge->cx.computed, ge->cy.computed);
751 NR::scale sc(ge->rx.computed, ge->ry.computed);
752 ge->end = atan2(delta * sc.inverse());
753 if ( ( state & GDK_CONTROL_MASK )
754 && snaps )
755 {
756 ge->end = sp_round(ge->end, M_PI/snaps);
757 }
758 sp_genericellipse_normalize(ge);
759 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
760 }
762 static NR::Point sp_arc_end_get(SPItem *item)
763 {
764 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
765 SPArc *arc = SP_ARC(item);
767 return sp_arc_get_xy(arc, ge->end);
768 }
770 static void
771 sp_arc_startend_click(SPItem *item, guint state)
772 {
773 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
775 if (state & GDK_SHIFT_MASK) {
776 ge->end = ge->start = 0;
777 ((SPObject *)ge)->updateRepr();
778 }
779 }
782 static void
783 sp_arc_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
784 {
785 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
786 SPArc *arc = SP_ARC(item);
788 NR::Point const s = snap_knot_position(arc, p);
790 ge->rx.computed = fabs( ge->cx.computed - s[NR::X] );
792 if ( state & GDK_CONTROL_MASK ) {
793 ge->ry.computed = ge->rx.computed;
794 }
796 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
797 }
799 static NR::Point sp_arc_rx_get(SPItem *item)
800 {
801 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
803 return (NR::Point(ge->cx.computed, ge->cy.computed) - NR::Point(ge->rx.computed, 0));
804 }
806 static void
807 sp_arc_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
808 {
809 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
810 SPArc *arc = SP_ARC(item);
812 NR::Point const s = snap_knot_position(arc, p);
814 ge->ry.computed = fabs( ge->cy.computed - s[NR::Y] );
816 if ( state & GDK_CONTROL_MASK ) {
817 ge->rx.computed = ge->ry.computed;
818 }
820 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
821 }
823 static NR::Point sp_arc_ry_get(SPItem *item)
824 {
825 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
827 return (NR::Point(ge->cx.computed, ge->cy.computed) - NR::Point(0, ge->ry.computed));
828 }
830 static void
831 sp_arc_rx_click(SPItem *item, guint state)
832 {
833 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
835 if (state & GDK_CONTROL_MASK) {
836 ge->ry.computed = ge->rx.computed;
837 ((SPObject *)ge)->updateRepr();
838 }
839 }
841 static void
842 sp_arc_ry_click(SPItem *item, guint state)
843 {
844 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
846 if (state & GDK_CONTROL_MASK) {
847 ge->rx.computed = ge->ry.computed;
848 ((SPObject *)ge)->updateRepr();
849 }
850 }
852 static SPKnotHolder *
853 sp_arc_knot_holder(SPItem *item, SPDesktop *desktop)
854 {
855 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
857 sp_knot_holder_add_full(knot_holder, sp_arc_rx_set, sp_arc_rx_get, sp_arc_rx_click,
858 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
859 _("Adjust ellipse <b>width</b>, with <b>Ctrl</b> to make circle"));
860 sp_knot_holder_add_full(knot_holder, sp_arc_ry_set, sp_arc_ry_get, sp_arc_ry_click,
861 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
862 _("Adjust ellipse <b>height</b>, with <b>Ctrl</b> to make circle"));
863 sp_knot_holder_add_full(knot_holder, sp_arc_start_set, sp_arc_start_get, sp_arc_startend_click,
864 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
865 _("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"));
866 sp_knot_holder_add_full(knot_holder, sp_arc_end_set, sp_arc_end_get, sp_arc_startend_click,
867 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
868 _("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"));
870 sp_pat_knot_holder(item, knot_holder);
872 return knot_holder;
873 }
875 /* SPStar */
877 static void
878 sp_star_knot1_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
879 {
880 SPStar *star = SP_STAR(item);
882 NR::Point const s = snap_knot_position(star, p);
884 NR::Point d = s - star->center;
886 double arg1 = atan2(d);
887 double darg1 = arg1 - star->arg[0];
889 if (state & GDK_MOD1_MASK) {
890 star->randomized = darg1/(star->arg[0] - star->arg[1]);
891 } else if (state & GDK_SHIFT_MASK) {
892 star->rounded = darg1/(star->arg[0] - star->arg[1]);
893 } else if (state & GDK_CONTROL_MASK) {
894 star->r[0] = L2(d);
895 } else {
896 star->r[0] = L2(d);
897 star->arg[0] = arg1;
898 star->arg[1] += darg1;
899 }
900 ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
901 }
903 static void
904 sp_star_knot2_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
905 {
906 SPStar *star = SP_STAR(item);
908 NR::Point const s = snap_knot_position(star, p);
910 if (star->flatsided == false) {
911 NR::Point d = s - star->center;
913 double arg1 = atan2(d);
914 double darg1 = arg1 - star->arg[1];
916 if (state & GDK_MOD1_MASK) {
917 star->randomized = darg1/(star->arg[0] - star->arg[1]);
918 } else if (state & GDK_SHIFT_MASK) {
919 star->rounded = fabs(darg1/(star->arg[0] - star->arg[1]));
920 } else if (state & GDK_CONTROL_MASK) {
921 star->r[1] = L2(d);
922 star->arg[1] = star->arg[0] + M_PI / star->sides;
923 }
924 else {
925 star->r[1] = L2(d);
926 star->arg[1] = atan2(d);
927 }
928 ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
929 }
930 }
932 static NR::Point sp_star_knot1_get(SPItem *item)
933 {
934 g_assert(item != NULL);
936 SPStar *star = SP_STAR(item);
938 return sp_star_get_xy(star, SP_STAR_POINT_KNOT1, 0);
940 }
942 static NR::Point sp_star_knot2_get(SPItem *item)
943 {
944 g_assert(item != NULL);
946 SPStar *star = SP_STAR(item);
948 return sp_star_get_xy(star, SP_STAR_POINT_KNOT2, 0);
949 }
951 static void
952 sp_star_knot_click(SPItem *item, guint state)
953 {
954 SPStar *star = SP_STAR(item);
956 if (state & GDK_MOD1_MASK) {
957 star->randomized = 0;
958 ((SPObject *)star)->updateRepr();
959 } else if (state & GDK_SHIFT_MASK) {
960 star->rounded = 0;
961 ((SPObject *)star)->updateRepr();
962 } else if (state & GDK_CONTROL_MASK) {
963 star->arg[1] = star->arg[0] + M_PI / star->sides;
964 ((SPObject *)star)->updateRepr();
965 }
966 }
968 static SPKnotHolder *
969 sp_star_knot_holder(SPItem *item, SPDesktop *desktop)
970 {
971 /* we don't need to get parent knot_holder */
972 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
973 g_assert(item != NULL);
975 SPStar *star = SP_STAR(item);
977 sp_knot_holder_add(knot_holder, sp_star_knot1_set, sp_star_knot1_get, sp_star_knot_click,
978 _("Adjust the <b>tip radius</b> of the star or polygon; with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
979 if (star->flatsided == false)
980 sp_knot_holder_add(knot_holder, sp_star_knot2_set, sp_star_knot2_get, sp_star_knot_click,
981 _("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"));
983 sp_pat_knot_holder(item, knot_holder);
985 return knot_holder;
986 }
988 /* SPSpiral */
990 /*
991 * set attributes via inner (t=t0) knot point:
992 * [default] increase/decrease inner point
993 * [shift] increase/decrease inner and outer arg synchronizely
994 * [control] constrain inner arg to round per PI/4
995 */
996 static void
997 sp_spiral_inner_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
998 {
999 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1001 SPSpiral *spiral = SP_SPIRAL(item);
1003 gdouble dx = p[NR::X] - spiral->cx;
1004 gdouble dy = p[NR::Y] - spiral->cy;
1006 if (state & GDK_MOD1_MASK) {
1007 // adjust divergence by vertical drag, relative to rad
1008 double new_exp = (spiral->rad + dy)/(spiral->rad);
1009 spiral->exp = new_exp > 0? new_exp : 0;
1010 } else {
1011 // roll/unroll from inside
1012 gdouble arg_t0;
1013 sp_spiral_get_polar(spiral, spiral->t0, NULL, &arg_t0);
1015 gdouble arg_tmp = atan2(dy, dx) - arg_t0;
1016 gdouble arg_t0_new = arg_tmp - floor((arg_tmp+M_PI)/(2.0*M_PI))*2.0*M_PI + arg_t0;
1017 spiral->t0 = (arg_t0_new - spiral->arg) / (2.0*M_PI*spiral->revo);
1019 /* round inner arg per PI/snaps, if CTRL is pressed */
1020 if ( ( state & GDK_CONTROL_MASK )
1021 && ( fabs(spiral->revo) > SP_EPSILON_2 )
1022 && ( snaps != 0 ) ) {
1023 gdouble arg = 2.0*M_PI*spiral->revo*spiral->t0 + spiral->arg;
1024 spiral->t0 = (sp_round(arg, M_PI/snaps) - spiral->arg)/(2.0*M_PI*spiral->revo);
1025 }
1027 spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1028 }
1030 ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1031 }
1033 /*
1034 * set attributes via outer (t=1) knot point:
1035 * [default] increase/decrease revolution factor
1036 * [control] constrain inner arg to round per PI/4
1037 */
1038 static void
1039 sp_spiral_outer_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
1040 {
1041 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1043 SPSpiral *spiral = SP_SPIRAL(item);
1045 gdouble dx = p[NR::X] - spiral->cx;
1046 gdouble dy = p[NR::Y] - spiral->cy;
1048 if (state & GDK_SHIFT_MASK) { // rotate without roll/unroll
1049 spiral->arg = atan2(dy, dx) - 2.0*M_PI*spiral->revo;
1050 if (!(state & GDK_MOD1_MASK)) {
1051 // if alt not pressed, change also rad; otherwise it is locked
1052 spiral->rad = MAX(hypot(dx, dy), 0.001);
1053 }
1054 if ( ( state & GDK_CONTROL_MASK )
1055 && snaps ) {
1056 spiral->arg = sp_round(spiral->arg, M_PI/snaps);
1057 }
1058 } else { // roll/unroll
1059 // arg of the spiral outer end
1060 double arg_1;
1061 sp_spiral_get_polar(spiral, 1, NULL, &arg_1);
1063 // its fractional part after the whole turns are subtracted
1064 double arg_r = arg_1 - sp_round(arg_1, 2.0*M_PI);
1066 // arg of the mouse point relative to spiral center
1067 double mouse_angle = atan2(dy, dx);
1068 if (mouse_angle < 0)
1069 mouse_angle += 2*M_PI;
1071 // snap if ctrl
1072 if ( ( state & GDK_CONTROL_MASK ) && snaps ) {
1073 mouse_angle = sp_round(mouse_angle, M_PI/snaps);
1074 }
1076 // by how much we want to rotate the outer point
1077 double diff = mouse_angle - arg_r;
1078 if (diff > M_PI)
1079 diff -= 2*M_PI;
1080 else if (diff < -M_PI)
1081 diff += 2*M_PI;
1083 // calculate the new rad;
1084 // the value of t corresponding to the angle arg_1 + diff:
1085 double t_temp = ((arg_1 + diff) - spiral->arg)/(2*M_PI*spiral->revo);
1086 // the rad at that t:
1087 double rad_new = 0;
1088 if (t_temp > spiral->t0)
1089 sp_spiral_get_polar(spiral, t_temp, &rad_new, NULL);
1091 // change the revo (converting diff from radians to the number of turns)
1092 spiral->revo += diff/(2*M_PI);
1093 if (spiral->revo < 1e-3)
1094 spiral->revo = 1e-3;
1096 // if alt not pressed and the values are sane, change the rad
1097 if (!(state & GDK_MOD1_MASK) && rad_new > 1e-3 && rad_new/spiral->rad < 2) {
1098 // adjust t0 too so that the inner point stays unmoved
1099 double r0;
1100 sp_spiral_get_polar(spiral, spiral->t0, &r0, NULL);
1101 spiral->rad = rad_new;
1102 spiral->t0 = pow(r0 / spiral->rad, 1.0/spiral->exp);
1103 }
1104 if (!isFinite(spiral->t0)) spiral->t0 = 0.0;
1105 spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1106 }
1108 ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1109 }
1111 static NR::Point sp_spiral_inner_get(SPItem *item)
1112 {
1113 SPSpiral *spiral = SP_SPIRAL(item);
1115 return sp_spiral_get_xy(spiral, spiral->t0);
1116 }
1118 static NR::Point sp_spiral_outer_get(SPItem *item)
1119 {
1120 SPSpiral *spiral = SP_SPIRAL(item);
1122 return sp_spiral_get_xy(spiral, 1.0);
1123 }
1125 static void
1126 sp_spiral_inner_click(SPItem *item, guint state)
1127 {
1128 SPSpiral *spiral = SP_SPIRAL(item);
1130 if (state & GDK_MOD1_MASK) {
1131 spiral->exp = 1;
1132 ((SPObject *)spiral)->updateRepr();
1133 } else if (state & GDK_SHIFT_MASK) {
1134 spiral->t0 = 0;
1135 ((SPObject *)spiral)->updateRepr();
1136 }
1137 }
1139 static SPKnotHolder *
1140 sp_spiral_knot_holder(SPItem *item, SPDesktop *desktop)
1141 {
1142 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1144 sp_knot_holder_add(knot_holder, sp_spiral_inner_set, sp_spiral_inner_get, sp_spiral_inner_click,
1145 _("Roll/unroll the spiral from <b>inside</b>; with <b>Ctrl</b> to snap angle; with <b>Alt</b> to converge/diverge"));
1146 sp_knot_holder_add(knot_holder, sp_spiral_outer_set, sp_spiral_outer_get, NULL,
1147 _("Roll/unroll the spiral from <b>outside</b>; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to scale/rotate"));
1149 sp_pat_knot_holder(item, knot_holder);
1151 return knot_holder;
1152 }
1154 /* SPOffset */
1156 static void
1157 sp_offset_offset_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
1158 {
1159 SPOffset *offset = SP_OFFSET(item);
1161 offset->rad = sp_offset_distance_to_original(offset, p);
1162 offset->knot = p;
1163 offset->knotSet = true;
1165 ((SPObject *)offset)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1166 }
1169 static NR::Point sp_offset_offset_get(SPItem *item)
1170 {
1171 SPOffset *offset = SP_OFFSET(item);
1173 NR::Point np;
1174 sp_offset_top_point(offset,&np);
1175 return np;
1176 }
1178 static SPKnotHolder *
1179 sp_offset_knot_holder(SPItem *item, SPDesktop *desktop)
1180 {
1181 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1183 sp_knot_holder_add(knot_holder, sp_offset_offset_set, sp_offset_offset_get, NULL,
1184 _("Adjust the <b>offset distance</b>"));
1186 sp_pat_knot_holder(item, knot_holder);
1188 return knot_holder;
1189 }
1191 static SPKnotHolder *
1192 sp_misc_knot_holder(SPItem *item, SPDesktop *desktop) // FIXME: eliminate, instead make a pattern-drag similar to gradient-drag
1193 {
1194 if ((SP_OBJECT(item)->style->fill.isPaintserver())
1195 && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
1196 {
1197 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1199 sp_pat_knot_holder(item, knot_holder);
1201 return knot_holder;
1202 }
1203 return NULL;
1204 }
1206 static void
1207 sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder)
1208 {
1209 if ((SP_OBJECT(item)->style->fill.isPaintserver())
1210 && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
1211 {
1212 sp_knot_holder_add_full(knot_holder, sp_pattern_xy_set, sp_pattern_xy_get, NULL, SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,
1213 // TRANSLATORS: This refers to the pattern that's inside the object
1214 _("<b>Move</b> the pattern fill inside the object"));
1215 sp_knot_holder_add_full(knot_holder, sp_pattern_scale_set, sp_pattern_scale_get, NULL, SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
1216 _("<b>Scale</b> the pattern fill uniformly"));
1217 sp_knot_holder_add_full(knot_holder, sp_pattern_angle_set, sp_pattern_angle_get, NULL, SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
1218 _("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"));
1219 }
1220 }
1222 static NR::Point sp_flowtext_corner_get(SPItem *item)
1223 {
1224 SPRect *rect = SP_RECT(item);
1226 return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
1227 }
1229 static void
1230 sp_flowtext_corner_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
1231 {
1232 SPRect *rect = SP_RECT(item);
1234 sp_rect_wh_set_internal(rect, p, origin, state);
1235 }
1237 static SPKnotHolder *
1238 sp_flowtext_knot_holder(SPItem *item, SPDesktop *desktop)
1239 {
1240 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL);
1242 sp_knot_holder_add(knot_holder, sp_flowtext_corner_set, sp_flowtext_corner_get, NULL,
1243 _("Drag to resize the <b>flowed text frame</b>"));
1245 return knot_holder;
1246 }
1249 /*
1250 Local Variables:
1251 mode:c++
1252 c-file-style:"stroustrup"
1253 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1254 indent-tabs-mode:nil
1255 fill-column:99
1256 End:
1257 */
1258 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :