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 const &m = desktop->namedview->snap_manager;
226 s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, s, item).getPoint();
227 return s * i2d.inverse();
228 }
230 static NR::Point sp_rect_rx_get(SPItem *item)
231 {
232 SPRect *rect = SP_RECT(item);
234 return NR::Point(rect->x.computed + rect->width.computed - rect->rx.computed, rect->y.computed);
235 }
237 static void sp_rect_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
238 {
239 SPRect *rect = SP_RECT(item);
241 //In general we cannot just snap this radius to an arbitrary point, as we have only a single
242 //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
243 //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
245 if (state & GDK_CONTROL_MASK) {
246 gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
247 rect->rx.computed = rect->ry.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, temp);
248 rect->rx._set = rect->ry._set = true;
250 } else {
251 rect->rx.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, rect->width.computed / 2.0);
252 rect->rx._set = true;
253 }
255 ((SPObject*)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
256 }
259 static NR::Point sp_rect_ry_get(SPItem *item)
260 {
261 SPRect *rect = SP_RECT(item);
263 return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->ry.computed);
264 }
266 static void sp_rect_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
267 {
268 SPRect *rect = SP_RECT(item);
270 //In general we cannot just snap this radius to an arbitrary point, as we have only a single
271 //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
272 //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
274 if (state & GDK_CONTROL_MASK) {
275 gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
276 rect->rx.computed = rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed, 0.0, temp);
277 rect->ry._set = rect->rx._set = true;
278 } else {
279 if (!rect->rx._set || rect->rx.computed == 0) {
280 rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
281 0.0,
282 MIN(rect->height.computed / 2.0, rect->width.computed / 2.0));
283 } else {
284 rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
285 0.0,
286 rect->height.computed / 2.0);
287 }
289 rect->ry._set = true;
290 }
292 ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
293 }
295 /**
296 * Remove rounding from a rectangle.
297 */
298 static void rect_remove_rounding(SPRect *rect)
299 {
300 SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
301 SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
302 }
304 /**
305 * Called when the horizontal rounding radius knot is clicked.
306 */
307 static void sp_rect_rx_knot_click(SPItem *item, guint state)
308 {
309 SPRect *rect = SP_RECT(item);
311 if (state & GDK_SHIFT_MASK) {
312 rect_remove_rounding(rect);
313 } else if (state & GDK_CONTROL_MASK) {
314 /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
315 SP_OBJECT_REPR(rect)->setAttribute("ry", SP_OBJECT_REPR(rect)->attribute("rx"));
316 }
317 }
319 /**
320 * Called when the vertical rounding radius knot is clicked.
321 */
322 static void sp_rect_ry_knot_click(SPItem *item, guint state)
323 {
324 SPRect *rect = SP_RECT(item);
326 if (state & GDK_SHIFT_MASK) {
327 rect_remove_rounding(rect);
328 } else if (state & GDK_CONTROL_MASK) {
329 /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
330 SP_OBJECT_REPR(rect)->setAttribute("rx", SP_OBJECT_REPR(rect)->attribute("ry"));
331 }
332 }
334 #define SGN(x) ((x)>0?1:((x)<0?-1:0))
336 static void sp_rect_clamp_radii(SPRect *rect)
337 {
338 // clamp rounding radii so that they do not exceed width/height
339 if (2 * rect->rx.computed > rect->width.computed) {
340 rect->rx.computed = 0.5 * rect->width.computed;
341 rect->rx._set = true;
342 }
343 if (2 * rect->ry.computed > rect->height.computed) {
344 rect->ry.computed = 0.5 * rect->height.computed;
345 rect->ry._set = true;
346 }
347 }
349 static NR::Point sp_rect_wh_get(SPItem *item)
350 {
351 SPRect *rect = SP_RECT(item);
353 return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
354 }
356 static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point const &origin, guint state)
357 {
358 NR::Point const s = snap_knot_position(rect, p);
360 if (state & GDK_CONTROL_MASK) {
361 // original width/height when drag started
362 gdouble const w_orig = (origin[NR::X] - rect->x.computed);
363 gdouble const h_orig = (origin[NR::Y] - rect->y.computed);
365 //original ratio
366 gdouble const ratio = (w_orig / h_orig);
368 // mouse displacement since drag started
369 gdouble const minx = s[NR::X] - origin[NR::X];
370 gdouble const miny = s[NR::Y] - origin[NR::Y];
372 if (fabs(minx) > fabs(miny)) {
374 // snap to horizontal or diagonal
375 rect->width.computed = MAX(w_orig + minx, 0);
376 if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
377 // closer to the diagonal and in same-sign quarters, change both using ratio
378 rect->height.computed = MAX(h_orig + minx / ratio, 0);
379 } else {
380 // closer to the horizontal, change only width, height is h_orig
381 rect->height.computed = MAX(h_orig, 0);
382 }
384 } else {
385 // snap to vertical or diagonal
386 rect->height.computed = MAX(h_orig + miny, 0);
387 if (miny != 0 && fabs(minx/miny) > 0.5 * ratio && (SGN(minx) == SGN(miny))) {
388 // closer to the diagonal and in same-sign quarters, change both using ratio
389 rect->width.computed = MAX(w_orig + miny * ratio, 0);
390 } else {
391 // closer to the vertical, change only height, width is w_orig
392 rect->width.computed = MAX(w_orig, 0);
393 }
394 }
396 rect->width._set = rect->height._set = true;
398 } else {
399 // move freely
400 rect->width.computed = MAX(s[NR::X] - rect->x.computed, 0);
401 rect->height.computed = MAX(s[NR::Y] - rect->y.computed, 0);
402 rect->width._set = rect->height._set = true;
403 }
405 sp_rect_clamp_radii(rect);
407 ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
408 }
410 static void sp_rect_wh_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
411 {
412 SPRect *rect = SP_RECT(item);
414 sp_rect_wh_set_internal(rect, p, origin, state);
415 }
417 static NR::Point sp_rect_xy_get(SPItem *item)
418 {
419 SPRect *rect = SP_RECT(item);
421 return NR::Point(rect->x.computed, rect->y.computed);
422 }
424 static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
425 {
426 SPRect *rect = SP_RECT(item);
428 // opposite corner (unmoved)
429 gdouble opposite_x = (rect->x.computed + rect->width.computed);
430 gdouble opposite_y = (rect->y.computed + rect->height.computed);
432 // original width/height when drag started
433 gdouble w_orig = opposite_x - origin[NR::X];
434 gdouble h_orig = opposite_y - origin[NR::Y];
436 NR::Point const s = snap_knot_position(rect, p);
438 // mouse displacement since drag started
439 gdouble minx = s[NR::X] - origin[NR::X];
440 gdouble miny = s[NR::Y] - origin[NR::Y];
442 if (state & GDK_CONTROL_MASK) {
443 //original ratio
444 gdouble ratio = (w_orig / h_orig);
446 if (fabs(minx) > fabs(miny)) {
448 // snap to horizontal or diagonal
449 rect->x.computed = MIN(s[NR::X], opposite_x);
450 rect->width.computed = MAX(w_orig - minx, 0);
451 if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
452 // closer to the diagonal and in same-sign quarters, change both using ratio
453 rect->y.computed = MIN(origin[NR::Y] + minx / ratio, opposite_y);
454 rect->height.computed = MAX(h_orig - minx / ratio, 0);
455 } else {
456 // closer to the horizontal, change only width, height is h_orig
457 rect->y.computed = MIN(origin[NR::Y], opposite_y);
458 rect->height.computed = MAX(h_orig, 0);
459 }
461 } else {
463 // snap to vertical or diagonal
464 rect->y.computed = MIN(s[NR::Y], opposite_y);
465 rect->height.computed = MAX(h_orig - miny, 0);
466 if (miny != 0 && fabs(minx/miny) > 0.5 *ratio && (SGN(minx) == SGN(miny))) {
467 // closer to the diagonal and in same-sign quarters, change both using ratio
468 rect->x.computed = MIN(origin[NR::X] + miny * ratio, opposite_x);
469 rect->width.computed = MAX(w_orig - miny * ratio, 0);
470 } else {
471 // closer to the vertical, change only height, width is w_orig
472 rect->x.computed = MIN(origin[NR::X], opposite_x);
473 rect->width.computed = MAX(w_orig, 0);
474 }
476 }
478 rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
480 } else {
481 // move freely
482 rect->x.computed = MIN(s[NR::X], opposite_x);
483 rect->width.computed = MAX(w_orig - minx, 0);
484 rect->y.computed = MIN(s[NR::Y], opposite_y);
485 rect->height.computed = MAX(h_orig - miny, 0);
486 rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
487 }
489 sp_rect_clamp_radii(rect);
491 ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
492 }
494 static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop)
495 {
496 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
498 sp_knot_holder_add_full(
499 knot_holder, sp_rect_rx_set, sp_rect_rx_get, sp_rect_rx_knot_click,
500 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
501 _("Adjust the <b>horizontal rounding</b> radius; with <b>Ctrl</b> to make the vertical "
502 "radius the same"));
504 sp_knot_holder_add_full(
505 knot_holder, sp_rect_ry_set, sp_rect_ry_get, sp_rect_ry_knot_click,
506 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
507 _("Adjust the <b>vertical rounding</b> radius; with <b>Ctrl</b> to make the horizontal "
508 "radius the same")
509 );
511 sp_knot_holder_add_full(
512 knot_holder, sp_rect_wh_set, sp_rect_wh_get, NULL,
513 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
514 _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
515 "or stretch in one dimension only")
516 );
518 sp_knot_holder_add_full(
519 knot_holder, sp_rect_xy_set, sp_rect_xy_get, NULL,
520 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
521 _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
522 "or stretch in one dimension only")
523 );
525 sp_pat_knot_holder(item, knot_holder);
526 return knot_holder;
527 }
529 /* Box3D (= the new 3D box structure) */
531 static NR::Point box3d_knot_get(SPItem *item, guint knot_id)
532 {
533 return box3d_get_corner_screen(SP_BOX3D(item), knot_id);
534 }
536 static void box3d_knot_set(SPItem *item, guint knot_id, NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
537 {
538 NR::Point const s = snap_knot_position(item, new_pos);
540 g_assert(item != NULL);
541 SPBox3D *box = SP_BOX3D(item);
542 NR::Matrix const i2d (sp_item_i2d_affine (item));
544 Box3D::Axis movement;
545 if ((knot_id < 4) != (state & GDK_SHIFT_MASK)) {
546 movement = Box3D::XY;
547 } else {
548 movement = Box3D::Z;
549 }
551 box3d_set_corner (box, knot_id, s * i2d, movement, (state & GDK_CONTROL_MASK));
552 box3d_set_z_orders(box);
553 box3d_position_set(box);
554 }
556 static NR::Point box3d_knot_center_get (SPItem *item)
557 {
558 return box3d_get_center_screen (SP_BOX3D(item));
559 }
561 static void box3d_knot_center_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
562 {
563 NR::Point const s = snap_knot_position(item, new_pos);
565 SPBox3D *box = SP_BOX3D(item);
566 NR::Matrix const i2d (sp_item_i2d_affine (item));
568 box3d_set_center (SP_BOX3D(item), s * i2d, origin * i2d, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z,
569 state & GDK_CONTROL_MASK);
571 box3d_set_z_orders(box);
572 box3d_position_set(box);
573 }
575 static void box3d_knot0_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
576 {
577 box3d_knot_set(item, 0, new_pos, origin, state);
578 }
580 static void box3d_knot1_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
581 {
582 box3d_knot_set(item, 1, new_pos, origin, state);
583 }
585 static void box3d_knot2_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
586 {
587 box3d_knot_set(item, 2, new_pos, origin, state);
588 }
590 static void box3d_knot3_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
591 {
592 box3d_knot_set(item, 3, new_pos, origin, state);
593 }
595 static void box3d_knot4_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
596 {
597 box3d_knot_set(item, 4, new_pos, origin, state);
598 }
600 static void box3d_knot5_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
601 {
602 box3d_knot_set(item, 5, new_pos, origin, state);
603 }
605 static void box3d_knot6_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
606 {
607 box3d_knot_set(item, 6, new_pos, origin, state);
608 }
610 static void box3d_knot7_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
611 {
612 box3d_knot_set(item, 7, new_pos, origin, state);
613 }
615 static NR::Point box3d_knot0_get(SPItem *item)
616 {
617 return box3d_knot_get(item, 0);
618 }
620 static NR::Point box3d_knot1_get(SPItem *item)
621 {
622 return box3d_knot_get(item, 1);
623 }
625 static NR::Point box3d_knot2_get(SPItem *item)
626 {
627 return box3d_knot_get(item, 2);
628 }
630 static NR::Point box3d_knot3_get(SPItem *item)
631 {
632 return box3d_knot_get(item, 3);
633 }
635 static NR::Point box3d_knot4_get(SPItem *item)
636 {
637 return box3d_knot_get(item, 4);
638 }
640 static NR::Point box3d_knot5_get(SPItem *item)
641 {
642 return box3d_knot_get(item, 5);
643 }
645 static NR::Point box3d_knot6_get(SPItem *item)
646 {
647 return box3d_knot_get(item, 6);
648 }
650 static NR::Point box3d_knot7_get(SPItem *item)
651 {
652 return box3d_knot_get(item, 7);
653 }
655 SPKnotHolder *
656 box3d_knot_holder(SPItem *item, SPDesktop *desktop)
657 {
658 g_assert(item != NULL);
659 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
661 sp_knot_holder_add(knot_holder, box3d_knot0_set, box3d_knot0_get, NULL,
662 _("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"));
663 sp_knot_holder_add(knot_holder, box3d_knot1_set, box3d_knot1_get, NULL,
664 _("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"));
665 sp_knot_holder_add(knot_holder, box3d_knot2_set, box3d_knot2_get, NULL,
666 _("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"));
667 sp_knot_holder_add(knot_holder, box3d_knot3_set, box3d_knot3_get, NULL,
668 _("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"));
669 sp_knot_holder_add(knot_holder, box3d_knot4_set, box3d_knot4_get, NULL,
670 _("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"));
671 sp_knot_holder_add(knot_holder, box3d_knot5_set, box3d_knot5_get, NULL,
672 _("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"));
673 sp_knot_holder_add(knot_holder, box3d_knot6_set, box3d_knot6_get, NULL,
674 _("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"));
675 sp_knot_holder_add(knot_holder, box3d_knot7_set, box3d_knot7_get, NULL,
676 _("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"));
678 // center dragging
679 sp_knot_holder_add_full(knot_holder, box3d_knot_center_set, box3d_knot_center_get, NULL,
680 SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,_("Move the box in perspective"));
682 sp_pat_knot_holder(item, knot_holder);
684 return knot_holder;
685 }
689 /* SPArc */
691 /*
692 * return values:
693 * 1 : inside
694 * 0 : on the curves
695 * -1 : outside
696 */
697 static gint
698 sp_genericellipse_side(SPGenericEllipse *ellipse, NR::Point const &p)
699 {
700 gdouble dx = (p[NR::X] - ellipse->cx.computed) / ellipse->rx.computed;
701 gdouble dy = (p[NR::Y] - ellipse->cy.computed) / ellipse->ry.computed;
703 gdouble s = dx * dx + dy * dy;
704 if (s < 1.0) return 1;
705 if (s > 1.0) return -1;
706 return 0;
707 }
709 static void
710 sp_arc_start_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
711 {
712 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
714 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
715 SPArc *arc = SP_ARC(item);
717 ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
719 NR::Point delta = p - NR::Point(ge->cx.computed, ge->cy.computed);
720 NR::scale sc(ge->rx.computed, ge->ry.computed);
721 ge->start = atan2(delta * sc.inverse());
722 if ( ( state & GDK_CONTROL_MASK )
723 && snaps )
724 {
725 ge->start = sp_round(ge->start, M_PI/snaps);
726 }
727 sp_genericellipse_normalize(ge);
728 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
729 }
731 static NR::Point sp_arc_start_get(SPItem *item)
732 {
733 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
734 SPArc *arc = SP_ARC(item);
736 return sp_arc_get_xy(arc, ge->start);
737 }
739 static void
740 sp_arc_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
741 {
742 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
744 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
745 SPArc *arc = SP_ARC(item);
747 ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
749 NR::Point delta = p - NR::Point(ge->cx.computed, ge->cy.computed);
750 NR::scale sc(ge->rx.computed, ge->ry.computed);
751 ge->end = atan2(delta * sc.inverse());
752 if ( ( state & GDK_CONTROL_MASK )
753 && snaps )
754 {
755 ge->end = sp_round(ge->end, M_PI/snaps);
756 }
757 sp_genericellipse_normalize(ge);
758 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
759 }
761 static NR::Point sp_arc_end_get(SPItem *item)
762 {
763 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
764 SPArc *arc = SP_ARC(item);
766 return sp_arc_get_xy(arc, ge->end);
767 }
769 static void
770 sp_arc_startend_click(SPItem *item, guint state)
771 {
772 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
774 if (state & GDK_SHIFT_MASK) {
775 ge->end = ge->start = 0;
776 ((SPObject *)ge)->updateRepr();
777 }
778 }
781 static void
782 sp_arc_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
783 {
784 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
785 SPArc *arc = SP_ARC(item);
787 NR::Point const s = snap_knot_position(arc, p);
789 ge->rx.computed = fabs( ge->cx.computed - s[NR::X] );
791 if ( state & GDK_CONTROL_MASK ) {
792 ge->ry.computed = ge->rx.computed;
793 }
795 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
796 }
798 static NR::Point sp_arc_rx_get(SPItem *item)
799 {
800 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
802 return (NR::Point(ge->cx.computed, ge->cy.computed) - NR::Point(ge->rx.computed, 0));
803 }
805 static void
806 sp_arc_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
807 {
808 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
809 SPArc *arc = SP_ARC(item);
811 NR::Point const s = snap_knot_position(arc, p);
813 ge->ry.computed = fabs( ge->cy.computed - s[NR::Y] );
815 if ( state & GDK_CONTROL_MASK ) {
816 ge->rx.computed = ge->ry.computed;
817 }
819 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
820 }
822 static NR::Point sp_arc_ry_get(SPItem *item)
823 {
824 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
826 return (NR::Point(ge->cx.computed, ge->cy.computed) - NR::Point(0, ge->ry.computed));
827 }
829 static void
830 sp_arc_rx_click(SPItem *item, guint state)
831 {
832 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
834 if (state & GDK_CONTROL_MASK) {
835 ge->ry.computed = ge->rx.computed;
836 ((SPObject *)ge)->updateRepr();
837 }
838 }
840 static void
841 sp_arc_ry_click(SPItem *item, guint state)
842 {
843 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
845 if (state & GDK_CONTROL_MASK) {
846 ge->rx.computed = ge->ry.computed;
847 ((SPObject *)ge)->updateRepr();
848 }
849 }
851 static SPKnotHolder *
852 sp_arc_knot_holder(SPItem *item, SPDesktop *desktop)
853 {
854 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
856 sp_knot_holder_add_full(knot_holder, sp_arc_rx_set, sp_arc_rx_get, sp_arc_rx_click,
857 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
858 _("Adjust ellipse <b>width</b>, with <b>Ctrl</b> to make circle"));
859 sp_knot_holder_add_full(knot_holder, sp_arc_ry_set, sp_arc_ry_get, sp_arc_ry_click,
860 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
861 _("Adjust ellipse <b>height</b>, with <b>Ctrl</b> to make circle"));
862 sp_knot_holder_add_full(knot_holder, sp_arc_start_set, sp_arc_start_get, sp_arc_startend_click,
863 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
864 _("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"));
865 sp_knot_holder_add_full(knot_holder, sp_arc_end_set, sp_arc_end_get, sp_arc_startend_click,
866 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
867 _("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"));
869 sp_pat_knot_holder(item, knot_holder);
871 return knot_holder;
872 }
874 /* SPStar */
876 static void
877 sp_star_knot1_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
878 {
879 SPStar *star = SP_STAR(item);
881 NR::Point const s = snap_knot_position(star, p);
883 NR::Point d = s - star->center;
885 double arg1 = atan2(d);
886 double darg1 = arg1 - star->arg[0];
888 if (state & GDK_MOD1_MASK) {
889 star->randomized = darg1/(star->arg[0] - star->arg[1]);
890 } else if (state & GDK_SHIFT_MASK) {
891 star->rounded = darg1/(star->arg[0] - star->arg[1]);
892 } else if (state & GDK_CONTROL_MASK) {
893 star->r[0] = L2(d);
894 } else {
895 star->r[0] = L2(d);
896 star->arg[0] = arg1;
897 star->arg[1] += darg1;
898 }
899 ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
900 }
902 static void
903 sp_star_knot2_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
904 {
905 SPStar *star = SP_STAR(item);
907 NR::Point const s = snap_knot_position(star, p);
909 if (star->flatsided == false) {
910 NR::Point d = s - star->center;
912 double arg1 = atan2(d);
913 double darg1 = arg1 - star->arg[1];
915 if (state & GDK_MOD1_MASK) {
916 star->randomized = darg1/(star->arg[0] - star->arg[1]);
917 } else if (state & GDK_SHIFT_MASK) {
918 star->rounded = fabs(darg1/(star->arg[0] - star->arg[1]));
919 } else if (state & GDK_CONTROL_MASK) {
920 star->r[1] = L2(d);
921 star->arg[1] = star->arg[0] + M_PI / star->sides;
922 }
923 else {
924 star->r[1] = L2(d);
925 star->arg[1] = atan2(d);
926 }
927 ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
928 }
929 }
931 static NR::Point sp_star_knot1_get(SPItem *item)
932 {
933 g_assert(item != NULL);
935 SPStar *star = SP_STAR(item);
937 return sp_star_get_xy(star, SP_STAR_POINT_KNOT1, 0);
939 }
941 static NR::Point sp_star_knot2_get(SPItem *item)
942 {
943 g_assert(item != NULL);
945 SPStar *star = SP_STAR(item);
947 return sp_star_get_xy(star, SP_STAR_POINT_KNOT2, 0);
948 }
950 static void
951 sp_star_knot_click(SPItem *item, guint state)
952 {
953 SPStar *star = SP_STAR(item);
955 if (state & GDK_MOD1_MASK) {
956 star->randomized = 0;
957 ((SPObject *)star)->updateRepr();
958 } else if (state & GDK_SHIFT_MASK) {
959 star->rounded = 0;
960 ((SPObject *)star)->updateRepr();
961 } else if (state & GDK_CONTROL_MASK) {
962 star->arg[1] = star->arg[0] + M_PI / star->sides;
963 ((SPObject *)star)->updateRepr();
964 }
965 }
967 static SPKnotHolder *
968 sp_star_knot_holder(SPItem *item, SPDesktop *desktop)
969 {
970 /* we don't need to get parent knot_holder */
971 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
972 g_assert(item != NULL);
974 SPStar *star = SP_STAR(item);
976 sp_knot_holder_add(knot_holder, sp_star_knot1_set, sp_star_knot1_get, sp_star_knot_click,
977 _("Adjust the <b>tip radius</b> of the star or polygon; with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
978 if (star->flatsided == false)
979 sp_knot_holder_add(knot_holder, sp_star_knot2_set, sp_star_knot2_get, sp_star_knot_click,
980 _("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"));
982 sp_pat_knot_holder(item, knot_holder);
984 return knot_holder;
985 }
987 /* SPSpiral */
989 /*
990 * set attributes via inner (t=t0) knot point:
991 * [default] increase/decrease inner point
992 * [shift] increase/decrease inner and outer arg synchronizely
993 * [control] constrain inner arg to round per PI/4
994 */
995 static void
996 sp_spiral_inner_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
997 {
998 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1000 SPSpiral *spiral = SP_SPIRAL(item);
1002 gdouble dx = p[NR::X] - spiral->cx;
1003 gdouble dy = p[NR::Y] - spiral->cy;
1005 if (state & GDK_MOD1_MASK) {
1006 // adjust divergence by vertical drag, relative to rad
1007 double new_exp = (spiral->rad + dy)/(spiral->rad);
1008 spiral->exp = new_exp > 0? new_exp : 0;
1009 } else {
1010 // roll/unroll from inside
1011 gdouble arg_t0;
1012 sp_spiral_get_polar(spiral, spiral->t0, NULL, &arg_t0);
1014 gdouble arg_tmp = atan2(dy, dx) - arg_t0;
1015 gdouble arg_t0_new = arg_tmp - floor((arg_tmp+M_PI)/(2.0*M_PI))*2.0*M_PI + arg_t0;
1016 spiral->t0 = (arg_t0_new - spiral->arg) / (2.0*M_PI*spiral->revo);
1018 /* round inner arg per PI/snaps, if CTRL is pressed */
1019 if ( ( state & GDK_CONTROL_MASK )
1020 && ( fabs(spiral->revo) > SP_EPSILON_2 )
1021 && ( snaps != 0 ) ) {
1022 gdouble arg = 2.0*M_PI*spiral->revo*spiral->t0 + spiral->arg;
1023 spiral->t0 = (sp_round(arg, M_PI/snaps) - spiral->arg)/(2.0*M_PI*spiral->revo);
1024 }
1026 spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1027 }
1029 ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1030 }
1032 /*
1033 * set attributes via outer (t=1) knot point:
1034 * [default] increase/decrease revolution factor
1035 * [control] constrain inner arg to round per PI/4
1036 */
1037 static void
1038 sp_spiral_outer_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
1039 {
1040 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1042 SPSpiral *spiral = SP_SPIRAL(item);
1044 gdouble dx = p[NR::X] - spiral->cx;
1045 gdouble dy = p[NR::Y] - spiral->cy;
1047 if (state & GDK_SHIFT_MASK) { // rotate without roll/unroll
1048 spiral->arg = atan2(dy, dx) - 2.0*M_PI*spiral->revo;
1049 if (!(state & GDK_MOD1_MASK)) {
1050 // if alt not pressed, change also rad; otherwise it is locked
1051 spiral->rad = MAX(hypot(dx, dy), 0.001);
1052 }
1053 if ( ( state & GDK_CONTROL_MASK )
1054 && snaps ) {
1055 spiral->arg = sp_round(spiral->arg, M_PI/snaps);
1056 }
1057 } else { // roll/unroll
1058 // arg of the spiral outer end
1059 double arg_1;
1060 sp_spiral_get_polar(spiral, 1, NULL, &arg_1);
1062 // its fractional part after the whole turns are subtracted
1063 double arg_r = arg_1 - sp_round(arg_1, 2.0*M_PI);
1065 // arg of the mouse point relative to spiral center
1066 double mouse_angle = atan2(dy, dx);
1067 if (mouse_angle < 0)
1068 mouse_angle += 2*M_PI;
1070 // snap if ctrl
1071 if ( ( state & GDK_CONTROL_MASK ) && snaps ) {
1072 mouse_angle = sp_round(mouse_angle, M_PI/snaps);
1073 }
1075 // by how much we want to rotate the outer point
1076 double diff = mouse_angle - arg_r;
1077 if (diff > M_PI)
1078 diff -= 2*M_PI;
1079 else if (diff < -M_PI)
1080 diff += 2*M_PI;
1082 // calculate the new rad;
1083 // the value of t corresponding to the angle arg_1 + diff:
1084 double t_temp = ((arg_1 + diff) - spiral->arg)/(2*M_PI*spiral->revo);
1085 // the rad at that t:
1086 double rad_new = 0;
1087 if (t_temp > spiral->t0)
1088 sp_spiral_get_polar(spiral, t_temp, &rad_new, NULL);
1090 // change the revo (converting diff from radians to the number of turns)
1091 spiral->revo += diff/(2*M_PI);
1092 if (spiral->revo < 1e-3)
1093 spiral->revo = 1e-3;
1095 // if alt not pressed and the values are sane, change the rad
1096 if (!(state & GDK_MOD1_MASK) && rad_new > 1e-3 && rad_new/spiral->rad < 2) {
1097 // adjust t0 too so that the inner point stays unmoved
1098 double r0;
1099 sp_spiral_get_polar(spiral, spiral->t0, &r0, NULL);
1100 spiral->rad = rad_new;
1101 spiral->t0 = pow(r0 / spiral->rad, 1.0/spiral->exp);
1102 }
1103 if (!isFinite(spiral->t0)) spiral->t0 = 0.0;
1104 spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1105 }
1107 ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1108 }
1110 static NR::Point sp_spiral_inner_get(SPItem *item)
1111 {
1112 SPSpiral *spiral = SP_SPIRAL(item);
1114 return sp_spiral_get_xy(spiral, spiral->t0);
1115 }
1117 static NR::Point sp_spiral_outer_get(SPItem *item)
1118 {
1119 SPSpiral *spiral = SP_SPIRAL(item);
1121 return sp_spiral_get_xy(spiral, 1.0);
1122 }
1124 static void
1125 sp_spiral_inner_click(SPItem *item, guint state)
1126 {
1127 SPSpiral *spiral = SP_SPIRAL(item);
1129 if (state & GDK_MOD1_MASK) {
1130 spiral->exp = 1;
1131 ((SPObject *)spiral)->updateRepr();
1132 } else if (state & GDK_SHIFT_MASK) {
1133 spiral->t0 = 0;
1134 ((SPObject *)spiral)->updateRepr();
1135 }
1136 }
1138 static SPKnotHolder *
1139 sp_spiral_knot_holder(SPItem *item, SPDesktop *desktop)
1140 {
1141 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1143 sp_knot_holder_add(knot_holder, sp_spiral_inner_set, sp_spiral_inner_get, sp_spiral_inner_click,
1144 _("Roll/unroll the spiral from <b>inside</b>; with <b>Ctrl</b> to snap angle; with <b>Alt</b> to converge/diverge"));
1145 sp_knot_holder_add(knot_holder, sp_spiral_outer_set, sp_spiral_outer_get, NULL,
1146 _("Roll/unroll the spiral from <b>outside</b>; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to scale/rotate"));
1148 sp_pat_knot_holder(item, knot_holder);
1150 return knot_holder;
1151 }
1153 /* SPOffset */
1155 static void
1156 sp_offset_offset_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
1157 {
1158 SPOffset *offset = SP_OFFSET(item);
1160 offset->rad = sp_offset_distance_to_original(offset, p);
1161 offset->knot = p;
1162 offset->knotSet = true;
1164 ((SPObject *)offset)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1165 }
1168 static NR::Point sp_offset_offset_get(SPItem *item)
1169 {
1170 SPOffset *offset = SP_OFFSET(item);
1172 NR::Point np;
1173 sp_offset_top_point(offset,&np);
1174 return np;
1175 }
1177 static SPKnotHolder *
1178 sp_offset_knot_holder(SPItem *item, SPDesktop *desktop)
1179 {
1180 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1182 sp_knot_holder_add(knot_holder, sp_offset_offset_set, sp_offset_offset_get, NULL,
1183 _("Adjust the <b>offset distance</b>"));
1185 sp_pat_knot_holder(item, knot_holder);
1187 return knot_holder;
1188 }
1190 static SPKnotHolder *
1191 sp_misc_knot_holder(SPItem *item, SPDesktop *desktop) // FIXME: eliminate, instead make a pattern-drag similar to gradient-drag
1192 {
1193 if ((SP_OBJECT(item)->style->fill.isPaintserver())
1194 && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
1195 {
1196 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1198 sp_pat_knot_holder(item, knot_holder);
1200 return knot_holder;
1201 }
1202 return NULL;
1203 }
1205 static void
1206 sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder)
1207 {
1208 if ((SP_OBJECT(item)->style->fill.isPaintserver())
1209 && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
1210 {
1211 sp_knot_holder_add_full(knot_holder, sp_pattern_xy_set, sp_pattern_xy_get, NULL, SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,
1212 // TRANSLATORS: This refers to the pattern that's inside the object
1213 _("<b>Move</b> the pattern fill inside the object"));
1214 sp_knot_holder_add_full(knot_holder, sp_pattern_scale_set, sp_pattern_scale_get, NULL, SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
1215 _("<b>Scale</b> the pattern fill uniformly"));
1216 sp_knot_holder_add_full(knot_holder, sp_pattern_angle_set, sp_pattern_angle_get, NULL, SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
1217 _("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"));
1218 }
1219 }
1221 static NR::Point sp_flowtext_corner_get(SPItem *item)
1222 {
1223 SPRect *rect = SP_RECT(item);
1225 return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
1226 }
1228 static void
1229 sp_flowtext_corner_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
1230 {
1231 SPRect *rect = SP_RECT(item);
1233 sp_rect_wh_set_internal(rect, p, origin, state);
1234 }
1236 static SPKnotHolder *
1237 sp_flowtext_knot_holder(SPItem *item, SPDesktop *desktop)
1238 {
1239 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL);
1241 sp_knot_holder_add(knot_holder, sp_flowtext_corner_set, sp_flowtext_corner_get, NULL,
1242 _("Drag to resize the <b>flowed text frame</b>"));
1244 return knot_holder;
1245 }
1248 /*
1249 Local Variables:
1250 mode:c++
1251 c-file-style:"stroustrup"
1252 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1253 indent-tabs-mode:nil
1254 fill-column:99
1255 End:
1256 */
1257 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :