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_current_lpe(SP_LPE_ITEM(item));
67 if (!effect) {
68 g_error("sp_lpe_knot_holder: logical error, this method cannot be called with item having an LPE");
69 } else {
70 effect->addHandles(knot_holder);
71 }
73 return knot_holder;
74 }
76 SPKnotHolder *
77 sp_item_knot_holder(SPItem *item, SPDesktop *desktop)
78 {
79 if ( SP_IS_LPE_ITEM(item) &&
80 sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)) &&
81 sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->isVisible() &&
82 sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->providesKnotholder() )
83 {
84 return sp_lpe_knot_holder(item, desktop);
85 } else if (SP_IS_RECT(item)) {
86 return sp_rect_knot_holder(item, desktop);
87 } else if (SP_IS_BOX3D(item)) {
88 return box3d_knot_holder(item, desktop);
89 } else if (SP_IS_ARC(item)) {
90 return sp_arc_knot_holder(item, desktop);
91 } else if (SP_IS_STAR(item)) {
92 return sp_star_knot_holder(item, desktop);
93 } else if (SP_IS_SPIRAL(item)) {
94 return sp_spiral_knot_holder(item, desktop);
95 } else if (SP_IS_OFFSET(item)) {
96 return sp_offset_knot_holder(item, desktop);
97 } else if (SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
98 return sp_flowtext_knot_holder(item, desktop);
99 } else {
100 return sp_misc_knot_holder(item, desktop);
101 }
103 return NULL;
104 }
107 /* Pattern manipulation */
109 static gdouble sp_pattern_extract_theta(SPPattern *pat, gdouble scale)
110 {
111 gdouble theta = asin(pat->patternTransform[1] / scale);
112 if (pat->patternTransform[0] < 0) theta = M_PI - theta ;
113 return theta;
114 }
116 static gdouble sp_pattern_extract_scale(SPPattern *pat)
117 {
118 gdouble s = pat->patternTransform[1];
119 gdouble c = pat->patternTransform[0];
120 gdouble xscale = sqrt(c * c + s * s);
121 return xscale;
122 }
124 static NR::Point sp_pattern_extract_trans(SPPattern const *pat)
125 {
126 return NR::Point(pat->patternTransform[4], pat->patternTransform[5]);
127 }
129 static void
130 sp_pattern_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
131 {
132 SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
134 NR::Point p_snapped = p;
136 if ( state & GDK_CONTROL_MASK ) {
137 if (fabs((p - origin)[NR::X]) > fabs((p - origin)[NR::Y])) {
138 p_snapped[NR::Y] = origin[NR::Y];
139 } else {
140 p_snapped[NR::X] = origin[NR::X];
141 }
142 }
144 if (state) {
145 NR::Point const q = p_snapped - sp_pattern_extract_trans(pat);
146 sp_item_adjust_pattern(item, NR::Matrix(NR::translate(q)));
147 }
149 item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
150 }
153 static NR::Point sp_pattern_xy_get(SPItem *item)
154 {
155 SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
156 return sp_pattern_extract_trans(pat);
157 }
159 static NR::Point sp_pattern_angle_get(SPItem *item)
160 {
161 SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
163 gdouble x = (pattern_width(pat)*0.5);
164 gdouble y = 0;
165 NR::Point delta = NR::Point(x,y);
166 gdouble scale = sp_pattern_extract_scale(pat);
167 gdouble theta = sp_pattern_extract_theta(pat, scale);
168 delta = delta * NR::Matrix(NR::rotate(theta))*NR::Matrix(NR::scale(scale,scale));
169 delta = delta + sp_pattern_extract_trans(pat);
170 return delta;
171 }
173 static void
174 sp_pattern_angle_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
175 {
176 int const snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
178 SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
180 // get the angle from pattern 0,0 to the cursor pos
181 NR::Point delta = p - sp_pattern_extract_trans(pat);
182 gdouble theta = atan2(delta);
184 if ( state & GDK_CONTROL_MASK ) {
185 theta = sp_round(theta, M_PI/snaps);
186 }
188 // get the scale from the current transform so we can keep it.
189 gdouble scl = sp_pattern_extract_scale(pat);
190 NR::Matrix rot = NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl));
191 NR::Point const t = sp_pattern_extract_trans(pat);
192 rot[4] = t[NR::X];
193 rot[5] = t[NR::Y];
194 sp_item_adjust_pattern(item, rot, true);
195 item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
196 }
198 static void
199 sp_pattern_scale_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
200 {
201 SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
203 // Get the scale from the position of the knotholder,
204 NR::Point d = p - sp_pattern_extract_trans(pat);
205 gdouble s = NR::L2(d);
206 gdouble pat_x = pattern_width(pat) * 0.5;
207 gdouble pat_y = pattern_height(pat) * 0.5;
208 gdouble pat_h = hypot(pat_x, pat_y);
209 gdouble scl = s / pat_h;
211 // get angle from current transform, (need get current scale first to calculate angle)
212 gdouble oldscale = sp_pattern_extract_scale(pat);
213 gdouble theta = sp_pattern_extract_theta(pat,oldscale);
215 NR::Matrix rot = NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl));
216 NR::Point const t = sp_pattern_extract_trans(pat);
217 rot[4] = t[NR::X];
218 rot[5] = t[NR::Y];
219 sp_item_adjust_pattern(item, rot, true);
220 item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
221 }
224 static NR::Point sp_pattern_scale_get(SPItem *item)
225 {
226 SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
228 gdouble x = pattern_width(pat)*0.5;
229 gdouble y = pattern_height(pat)*0.5;
230 NR::Point delta = NR::Point(x,y);
231 NR::Matrix a = pat->patternTransform;
232 a[4] = 0;
233 a[5] = 0;
234 delta = delta * a;
235 delta = delta + sp_pattern_extract_trans(pat);
236 return delta;
237 }
239 /* SPRect */
241 static NR::Point snap_knot_position(SPItem *item, NR::Point const &p)
242 {
243 SPDesktop const *desktop = inkscape_active_desktop();
244 NR::Matrix const i2d (sp_item_i2d_affine (item));
245 NR::Point s = p * i2d;
246 SnapManager &m = desktop->namedview->snap_manager;
247 m.setup(desktop, item);
248 m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, s);
249 return s * i2d.inverse();
250 }
252 static NR::Point sp_rect_rx_get(SPItem *item)
253 {
254 SPRect *rect = SP_RECT(item);
256 return NR::Point(rect->x.computed + rect->width.computed - rect->rx.computed, rect->y.computed);
257 }
259 static void sp_rect_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
260 {
261 SPRect *rect = SP_RECT(item);
263 //In general we cannot just snap this radius to an arbitrary point, as we have only a single
264 //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
265 //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
267 if (state & GDK_CONTROL_MASK) {
268 gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
269 rect->rx.computed = rect->ry.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, temp);
270 rect->rx._set = rect->ry._set = true;
272 } else {
273 rect->rx.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, rect->width.computed / 2.0);
274 rect->rx._set = true;
275 }
277 ((SPObject*)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
278 }
281 static NR::Point sp_rect_ry_get(SPItem *item)
282 {
283 SPRect *rect = SP_RECT(item);
285 return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->ry.computed);
286 }
288 static void sp_rect_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
289 {
290 SPRect *rect = SP_RECT(item);
292 //In general we cannot just snap this radius to an arbitrary point, as we have only a single
293 //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
294 //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
296 if (state & GDK_CONTROL_MASK) {
297 gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
298 rect->rx.computed = rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed, 0.0, temp);
299 rect->ry._set = rect->rx._set = true;
300 } else {
301 if (!rect->rx._set || rect->rx.computed == 0) {
302 rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
303 0.0,
304 MIN(rect->height.computed / 2.0, rect->width.computed / 2.0));
305 } else {
306 rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
307 0.0,
308 rect->height.computed / 2.0);
309 }
311 rect->ry._set = true;
312 }
314 ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
315 }
317 /**
318 * Remove rounding from a rectangle.
319 */
320 static void rect_remove_rounding(SPRect *rect)
321 {
322 SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
323 SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
324 }
326 /**
327 * Called when the horizontal rounding radius knot is clicked.
328 */
329 static void sp_rect_rx_knot_click(SPItem *item, guint state)
330 {
331 SPRect *rect = SP_RECT(item);
333 if (state & GDK_SHIFT_MASK) {
334 rect_remove_rounding(rect);
335 } else if (state & GDK_CONTROL_MASK) {
336 /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
337 SP_OBJECT_REPR(rect)->setAttribute("ry", SP_OBJECT_REPR(rect)->attribute("rx"));
338 }
339 }
341 /**
342 * Called when the vertical rounding radius knot is clicked.
343 */
344 static void sp_rect_ry_knot_click(SPItem *item, guint state)
345 {
346 SPRect *rect = SP_RECT(item);
348 if (state & GDK_SHIFT_MASK) {
349 rect_remove_rounding(rect);
350 } else if (state & GDK_CONTROL_MASK) {
351 /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
352 SP_OBJECT_REPR(rect)->setAttribute("rx", SP_OBJECT_REPR(rect)->attribute("ry"));
353 }
354 }
356 #define SGN(x) ((x)>0?1:((x)<0?-1:0))
358 static void sp_rect_clamp_radii(SPRect *rect)
359 {
360 // clamp rounding radii so that they do not exceed width/height
361 if (2 * rect->rx.computed > rect->width.computed) {
362 rect->rx.computed = 0.5 * rect->width.computed;
363 rect->rx._set = true;
364 }
365 if (2 * rect->ry.computed > rect->height.computed) {
366 rect->ry.computed = 0.5 * rect->height.computed;
367 rect->ry._set = true;
368 }
369 }
371 static NR::Point sp_rect_wh_get(SPItem *item)
372 {
373 SPRect *rect = SP_RECT(item);
375 return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
376 }
378 static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point const &origin, guint state)
379 {
380 NR::Point const s = snap_knot_position(rect, p);
382 if (state & GDK_CONTROL_MASK) {
383 // original width/height when drag started
384 gdouble const w_orig = (origin[NR::X] - rect->x.computed);
385 gdouble const h_orig = (origin[NR::Y] - rect->y.computed);
387 //original ratio
388 gdouble const ratio = (w_orig / h_orig);
390 // mouse displacement since drag started
391 gdouble const minx = s[NR::X] - origin[NR::X];
392 gdouble const miny = s[NR::Y] - origin[NR::Y];
394 if (fabs(minx) > fabs(miny)) {
396 // snap to horizontal or diagonal
397 rect->width.computed = MAX(w_orig + minx, 0);
398 if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
399 // closer to the diagonal and in same-sign quarters, change both using ratio
400 rect->height.computed = MAX(h_orig + minx / ratio, 0);
401 } else {
402 // closer to the horizontal, change only width, height is h_orig
403 rect->height.computed = MAX(h_orig, 0);
404 }
406 } else {
407 // snap to vertical or diagonal
408 rect->height.computed = MAX(h_orig + miny, 0);
409 if (miny != 0 && fabs(minx/miny) > 0.5 * ratio && (SGN(minx) == SGN(miny))) {
410 // closer to the diagonal and in same-sign quarters, change both using ratio
411 rect->width.computed = MAX(w_orig + miny * ratio, 0);
412 } else {
413 // closer to the vertical, change only height, width is w_orig
414 rect->width.computed = MAX(w_orig, 0);
415 }
416 }
418 rect->width._set = rect->height._set = true;
420 } else {
421 // move freely
422 rect->width.computed = MAX(s[NR::X] - rect->x.computed, 0);
423 rect->height.computed = MAX(s[NR::Y] - rect->y.computed, 0);
424 rect->width._set = rect->height._set = true;
425 }
427 sp_rect_clamp_radii(rect);
429 ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
430 }
432 static void sp_rect_wh_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
433 {
434 SPRect *rect = SP_RECT(item);
436 sp_rect_wh_set_internal(rect, p, origin, state);
437 }
439 static NR::Point sp_rect_xy_get(SPItem *item)
440 {
441 SPRect *rect = SP_RECT(item);
443 return NR::Point(rect->x.computed, rect->y.computed);
444 }
446 static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
447 {
448 SPRect *rect = SP_RECT(item);
450 // opposite corner (unmoved)
451 gdouble opposite_x = (rect->x.computed + rect->width.computed);
452 gdouble opposite_y = (rect->y.computed + rect->height.computed);
454 // original width/height when drag started
455 gdouble w_orig = opposite_x - origin[NR::X];
456 gdouble h_orig = opposite_y - origin[NR::Y];
458 NR::Point const s = snap_knot_position(rect, p);
460 // mouse displacement since drag started
461 gdouble minx = s[NR::X] - origin[NR::X];
462 gdouble miny = s[NR::Y] - origin[NR::Y];
464 if (state & GDK_CONTROL_MASK) {
465 //original ratio
466 gdouble ratio = (w_orig / h_orig);
468 if (fabs(minx) > fabs(miny)) {
470 // snap to horizontal or diagonal
471 rect->x.computed = MIN(s[NR::X], opposite_x);
472 rect->width.computed = MAX(w_orig - minx, 0);
473 if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
474 // closer to the diagonal and in same-sign quarters, change both using ratio
475 rect->y.computed = MIN(origin[NR::Y] + minx / ratio, opposite_y);
476 rect->height.computed = MAX(h_orig - minx / ratio, 0);
477 } else {
478 // closer to the horizontal, change only width, height is h_orig
479 rect->y.computed = MIN(origin[NR::Y], opposite_y);
480 rect->height.computed = MAX(h_orig, 0);
481 }
483 } else {
485 // snap to vertical or diagonal
486 rect->y.computed = MIN(s[NR::Y], opposite_y);
487 rect->height.computed = MAX(h_orig - miny, 0);
488 if (miny != 0 && fabs(minx/miny) > 0.5 *ratio && (SGN(minx) == SGN(miny))) {
489 // closer to the diagonal and in same-sign quarters, change both using ratio
490 rect->x.computed = MIN(origin[NR::X] + miny * ratio, opposite_x);
491 rect->width.computed = MAX(w_orig - miny * ratio, 0);
492 } else {
493 // closer to the vertical, change only height, width is w_orig
494 rect->x.computed = MIN(origin[NR::X], opposite_x);
495 rect->width.computed = MAX(w_orig, 0);
496 }
498 }
500 rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
502 } else {
503 // move freely
504 rect->x.computed = MIN(s[NR::X], opposite_x);
505 rect->width.computed = MAX(w_orig - minx, 0);
506 rect->y.computed = MIN(s[NR::Y], opposite_y);
507 rect->height.computed = MAX(h_orig - miny, 0);
508 rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
509 }
511 sp_rect_clamp_radii(rect);
513 ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
514 }
516 static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop)
517 {
518 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
520 sp_knot_holder_add_full(
521 knot_holder, sp_rect_rx_set, sp_rect_rx_get, sp_rect_rx_knot_click,
522 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
523 _("Adjust the <b>horizontal rounding</b> radius; with <b>Ctrl</b> to make the vertical "
524 "radius the same"));
526 sp_knot_holder_add_full(
527 knot_holder, sp_rect_ry_set, sp_rect_ry_get, sp_rect_ry_knot_click,
528 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
529 _("Adjust the <b>vertical rounding</b> radius; with <b>Ctrl</b> to make the horizontal "
530 "radius the same")
531 );
533 sp_knot_holder_add_full(
534 knot_holder, sp_rect_wh_set, sp_rect_wh_get, NULL,
535 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
536 _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
537 "or stretch in one dimension only")
538 );
540 sp_knot_holder_add_full(
541 knot_holder, sp_rect_xy_set, sp_rect_xy_get, NULL,
542 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
543 _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
544 "or stretch in one dimension only")
545 );
547 sp_pat_knot_holder(item, knot_holder);
548 return knot_holder;
549 }
551 /* Box3D (= the new 3D box structure) */
553 static NR::Point box3d_knot_get(SPItem *item, guint knot_id)
554 {
555 return box3d_get_corner_screen(SP_BOX3D(item), knot_id);
556 }
558 static void box3d_knot_set(SPItem *item, guint knot_id, NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
559 {
560 NR::Point const s = snap_knot_position(item, new_pos);
562 g_assert(item != NULL);
563 SPBox3D *box = SP_BOX3D(item);
564 NR::Matrix const i2d (sp_item_i2d_affine (item));
566 Box3D::Axis movement;
567 if ((knot_id < 4) != (state & GDK_SHIFT_MASK)) {
568 movement = Box3D::XY;
569 } else {
570 movement = Box3D::Z;
571 }
573 box3d_set_corner (box, knot_id, s * i2d, movement, (state & GDK_CONTROL_MASK));
574 box3d_set_z_orders(box);
575 box3d_position_set(box);
576 }
578 static NR::Point box3d_knot_center_get (SPItem *item)
579 {
580 return box3d_get_center_screen (SP_BOX3D(item));
581 }
583 static void box3d_knot_center_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
584 {
585 NR::Point const s = snap_knot_position(item, new_pos);
587 SPBox3D *box = SP_BOX3D(item);
588 NR::Matrix const i2d (sp_item_i2d_affine (item));
590 box3d_set_center (SP_BOX3D(item), s * i2d, origin * i2d, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z,
591 state & GDK_CONTROL_MASK);
593 box3d_set_z_orders(box);
594 box3d_position_set(box);
595 }
597 static void box3d_knot0_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
598 {
599 box3d_knot_set(item, 0, new_pos, origin, state);
600 }
602 static void box3d_knot1_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
603 {
604 box3d_knot_set(item, 1, new_pos, origin, state);
605 }
607 static void box3d_knot2_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
608 {
609 box3d_knot_set(item, 2, new_pos, origin, state);
610 }
612 static void box3d_knot3_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
613 {
614 box3d_knot_set(item, 3, new_pos, origin, state);
615 }
617 static void box3d_knot4_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
618 {
619 box3d_knot_set(item, 4, new_pos, origin, state);
620 }
622 static void box3d_knot5_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
623 {
624 box3d_knot_set(item, 5, new_pos, origin, state);
625 }
627 static void box3d_knot6_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
628 {
629 box3d_knot_set(item, 6, new_pos, origin, state);
630 }
632 static void box3d_knot7_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
633 {
634 box3d_knot_set(item, 7, new_pos, origin, state);
635 }
637 static NR::Point box3d_knot0_get(SPItem *item)
638 {
639 return box3d_knot_get(item, 0);
640 }
642 static NR::Point box3d_knot1_get(SPItem *item)
643 {
644 return box3d_knot_get(item, 1);
645 }
647 static NR::Point box3d_knot2_get(SPItem *item)
648 {
649 return box3d_knot_get(item, 2);
650 }
652 static NR::Point box3d_knot3_get(SPItem *item)
653 {
654 return box3d_knot_get(item, 3);
655 }
657 static NR::Point box3d_knot4_get(SPItem *item)
658 {
659 return box3d_knot_get(item, 4);
660 }
662 static NR::Point box3d_knot5_get(SPItem *item)
663 {
664 return box3d_knot_get(item, 5);
665 }
667 static NR::Point box3d_knot6_get(SPItem *item)
668 {
669 return box3d_knot_get(item, 6);
670 }
672 static NR::Point box3d_knot7_get(SPItem *item)
673 {
674 return box3d_knot_get(item, 7);
675 }
677 SPKnotHolder *
678 box3d_knot_holder(SPItem *item, SPDesktop *desktop)
679 {
680 g_assert(item != NULL);
681 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
683 sp_knot_holder_add(knot_holder, box3d_knot0_set, box3d_knot0_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_knot1_set, box3d_knot1_get, NULL,
686 _("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"));
687 sp_knot_holder_add(knot_holder, box3d_knot2_set, box3d_knot2_get, NULL,
688 _("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"));
689 sp_knot_holder_add(knot_holder, box3d_knot3_set, box3d_knot3_get, NULL,
690 _("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"));
691 sp_knot_holder_add(knot_holder, box3d_knot4_set, box3d_knot4_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"));
693 sp_knot_holder_add(knot_holder, box3d_knot5_set, box3d_knot5_get, NULL,
694 _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
695 sp_knot_holder_add(knot_holder, box3d_knot6_set, box3d_knot6_get, NULL,
696 _("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"));
697 sp_knot_holder_add(knot_holder, box3d_knot7_set, box3d_knot7_get, NULL,
698 _("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"));
700 // center dragging
701 sp_knot_holder_add_full(knot_holder, box3d_knot_center_set, box3d_knot_center_get, NULL,
702 SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,_("Move the box in perspective"));
704 sp_pat_knot_holder(item, knot_holder);
706 return knot_holder;
707 }
711 /* SPArc */
713 /*
714 * return values:
715 * 1 : inside
716 * 0 : on the curves
717 * -1 : outside
718 */
719 static gint
720 sp_genericellipse_side(SPGenericEllipse *ellipse, NR::Point const &p)
721 {
722 gdouble dx = (p[NR::X] - ellipse->cx.computed) / ellipse->rx.computed;
723 gdouble dy = (p[NR::Y] - ellipse->cy.computed) / ellipse->ry.computed;
725 gdouble s = dx * dx + dy * dy;
726 if (s < 1.0) return 1;
727 if (s > 1.0) return -1;
728 return 0;
729 }
731 static void
732 sp_arc_start_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
733 {
734 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
736 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
737 SPArc *arc = SP_ARC(item);
739 ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
741 NR::Point delta = p - NR::Point(ge->cx.computed, ge->cy.computed);
742 NR::scale sc(ge->rx.computed, ge->ry.computed);
743 ge->start = atan2(delta * sc.inverse());
744 if ( ( state & GDK_CONTROL_MASK )
745 && snaps )
746 {
747 ge->start = sp_round(ge->start, M_PI/snaps);
748 }
749 sp_genericellipse_normalize(ge);
750 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
751 }
753 static NR::Point sp_arc_start_get(SPItem *item)
754 {
755 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
756 SPArc *arc = SP_ARC(item);
758 return sp_arc_get_xy(arc, ge->start);
759 }
761 static void
762 sp_arc_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
763 {
764 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
766 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
767 SPArc *arc = SP_ARC(item);
769 ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
771 NR::Point delta = p - NR::Point(ge->cx.computed, ge->cy.computed);
772 NR::scale sc(ge->rx.computed, ge->ry.computed);
773 ge->end = atan2(delta * sc.inverse());
774 if ( ( state & GDK_CONTROL_MASK )
775 && snaps )
776 {
777 ge->end = sp_round(ge->end, M_PI/snaps);
778 }
779 sp_genericellipse_normalize(ge);
780 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
781 }
783 static NR::Point sp_arc_end_get(SPItem *item)
784 {
785 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
786 SPArc *arc = SP_ARC(item);
788 return sp_arc_get_xy(arc, ge->end);
789 }
791 static void
792 sp_arc_startend_click(SPItem *item, guint state)
793 {
794 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
796 if (state & GDK_SHIFT_MASK) {
797 ge->end = ge->start = 0;
798 ((SPObject *)ge)->updateRepr();
799 }
800 }
803 static void
804 sp_arc_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
805 {
806 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
807 SPArc *arc = SP_ARC(item);
809 NR::Point const s = snap_knot_position(arc, p);
811 ge->rx.computed = fabs( ge->cx.computed - s[NR::X] );
813 if ( state & GDK_CONTROL_MASK ) {
814 ge->ry.computed = ge->rx.computed;
815 }
817 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
818 }
820 static NR::Point sp_arc_rx_get(SPItem *item)
821 {
822 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
824 return (NR::Point(ge->cx.computed, ge->cy.computed) - NR::Point(ge->rx.computed, 0));
825 }
827 static void
828 sp_arc_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
829 {
830 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
831 SPArc *arc = SP_ARC(item);
833 NR::Point const s = snap_knot_position(arc, p);
835 ge->ry.computed = fabs( ge->cy.computed - s[NR::Y] );
837 if ( state & GDK_CONTROL_MASK ) {
838 ge->rx.computed = ge->ry.computed;
839 }
841 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
842 }
844 static NR::Point sp_arc_ry_get(SPItem *item)
845 {
846 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
848 return (NR::Point(ge->cx.computed, ge->cy.computed) - NR::Point(0, ge->ry.computed));
849 }
851 static void
852 sp_arc_rx_click(SPItem *item, guint state)
853 {
854 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
856 if (state & GDK_CONTROL_MASK) {
857 ge->ry.computed = ge->rx.computed;
858 ((SPObject *)ge)->updateRepr();
859 }
860 }
862 static void
863 sp_arc_ry_click(SPItem *item, guint state)
864 {
865 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
867 if (state & GDK_CONTROL_MASK) {
868 ge->rx.computed = ge->ry.computed;
869 ((SPObject *)ge)->updateRepr();
870 }
871 }
873 static SPKnotHolder *
874 sp_arc_knot_holder(SPItem *item, SPDesktop *desktop)
875 {
876 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
878 sp_knot_holder_add_full(knot_holder, sp_arc_rx_set, sp_arc_rx_get, sp_arc_rx_click,
879 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
880 _("Adjust ellipse <b>width</b>, with <b>Ctrl</b> to make circle"));
881 sp_knot_holder_add_full(knot_holder, sp_arc_ry_set, sp_arc_ry_get, sp_arc_ry_click,
882 SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
883 _("Adjust ellipse <b>height</b>, with <b>Ctrl</b> to make circle"));
884 sp_knot_holder_add_full(knot_holder, sp_arc_start_set, sp_arc_start_get, sp_arc_startend_click,
885 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
886 _("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"));
887 sp_knot_holder_add_full(knot_holder, sp_arc_end_set, sp_arc_end_get, sp_arc_startend_click,
888 SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
889 _("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"));
891 sp_pat_knot_holder(item, knot_holder);
893 return knot_holder;
894 }
896 /* SPStar */
898 static void
899 sp_star_knot1_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
900 {
901 SPStar *star = SP_STAR(item);
903 NR::Point const s = snap_knot_position(star, p);
905 NR::Point d = s - star->center;
907 double arg1 = atan2(d);
908 double darg1 = arg1 - star->arg[0];
910 if (state & GDK_MOD1_MASK) {
911 star->randomized = darg1/(star->arg[0] - star->arg[1]);
912 } else if (state & GDK_SHIFT_MASK) {
913 star->rounded = darg1/(star->arg[0] - star->arg[1]);
914 } else if (state & GDK_CONTROL_MASK) {
915 star->r[0] = L2(d);
916 } else {
917 star->r[0] = L2(d);
918 star->arg[0] = arg1;
919 star->arg[1] += darg1;
920 }
921 ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
922 }
924 static void
925 sp_star_knot2_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
926 {
927 SPStar *star = SP_STAR(item);
929 NR::Point const s = snap_knot_position(star, p);
931 if (star->flatsided == false) {
932 NR::Point d = s - star->center;
934 double arg1 = atan2(d);
935 double darg1 = arg1 - star->arg[1];
937 if (state & GDK_MOD1_MASK) {
938 star->randomized = darg1/(star->arg[0] - star->arg[1]);
939 } else if (state & GDK_SHIFT_MASK) {
940 star->rounded = fabs(darg1/(star->arg[0] - star->arg[1]));
941 } else if (state & GDK_CONTROL_MASK) {
942 star->r[1] = L2(d);
943 star->arg[1] = star->arg[0] + M_PI / star->sides;
944 }
945 else {
946 star->r[1] = L2(d);
947 star->arg[1] = atan2(d);
948 }
949 ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
950 }
951 }
953 static NR::Point sp_star_knot1_get(SPItem *item)
954 {
955 g_assert(item != NULL);
957 SPStar *star = SP_STAR(item);
959 return sp_star_get_xy(star, SP_STAR_POINT_KNOT1, 0);
961 }
963 static NR::Point sp_star_knot2_get(SPItem *item)
964 {
965 g_assert(item != NULL);
967 SPStar *star = SP_STAR(item);
969 return sp_star_get_xy(star, SP_STAR_POINT_KNOT2, 0);
970 }
972 static void
973 sp_star_knot_click(SPItem *item, guint state)
974 {
975 SPStar *star = SP_STAR(item);
977 if (state & GDK_MOD1_MASK) {
978 star->randomized = 0;
979 ((SPObject *)star)->updateRepr();
980 } else if (state & GDK_SHIFT_MASK) {
981 star->rounded = 0;
982 ((SPObject *)star)->updateRepr();
983 } else if (state & GDK_CONTROL_MASK) {
984 star->arg[1] = star->arg[0] + M_PI / star->sides;
985 ((SPObject *)star)->updateRepr();
986 }
987 }
989 static SPKnotHolder *
990 sp_star_knot_holder(SPItem *item, SPDesktop *desktop)
991 {
992 /* we don't need to get parent knot_holder */
993 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
994 g_assert(item != NULL);
996 SPStar *star = SP_STAR(item);
998 sp_knot_holder_add(knot_holder, sp_star_knot1_set, sp_star_knot1_get, sp_star_knot_click,
999 _("Adjust the <b>tip radius</b> of the star or polygon; with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
1000 if (star->flatsided == false)
1001 sp_knot_holder_add(knot_holder, sp_star_knot2_set, sp_star_knot2_get, sp_star_knot_click,
1002 _("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"));
1004 sp_pat_knot_holder(item, knot_holder);
1006 return knot_holder;
1007 }
1009 /* SPSpiral */
1011 /*
1012 * set attributes via inner (t=t0) knot point:
1013 * [default] increase/decrease inner point
1014 * [shift] increase/decrease inner and outer arg synchronizely
1015 * [control] constrain inner arg to round per PI/4
1016 */
1017 static void
1018 sp_spiral_inner_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
1019 {
1020 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1022 SPSpiral *spiral = SP_SPIRAL(item);
1024 gdouble dx = p[NR::X] - spiral->cx;
1025 gdouble dy = p[NR::Y] - spiral->cy;
1027 if (state & GDK_MOD1_MASK) {
1028 // adjust divergence by vertical drag, relative to rad
1029 double new_exp = (spiral->rad + dy)/(spiral->rad);
1030 spiral->exp = new_exp > 0? new_exp : 0;
1031 } else {
1032 // roll/unroll from inside
1033 gdouble arg_t0;
1034 sp_spiral_get_polar(spiral, spiral->t0, NULL, &arg_t0);
1036 gdouble arg_tmp = atan2(dy, dx) - arg_t0;
1037 gdouble arg_t0_new = arg_tmp - floor((arg_tmp+M_PI)/(2.0*M_PI))*2.0*M_PI + arg_t0;
1038 spiral->t0 = (arg_t0_new - spiral->arg) / (2.0*M_PI*spiral->revo);
1040 /* round inner arg per PI/snaps, if CTRL is pressed */
1041 if ( ( state & GDK_CONTROL_MASK )
1042 && ( fabs(spiral->revo) > SP_EPSILON_2 )
1043 && ( snaps != 0 ) ) {
1044 gdouble arg = 2.0*M_PI*spiral->revo*spiral->t0 + spiral->arg;
1045 spiral->t0 = (sp_round(arg, M_PI/snaps) - spiral->arg)/(2.0*M_PI*spiral->revo);
1046 }
1048 spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1049 }
1051 ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1052 }
1054 /*
1055 * set attributes via outer (t=1) knot point:
1056 * [default] increase/decrease revolution factor
1057 * [control] constrain inner arg to round per PI/4
1058 */
1059 static void
1060 sp_spiral_outer_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
1061 {
1062 int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1064 SPSpiral *spiral = SP_SPIRAL(item);
1066 gdouble dx = p[NR::X] - spiral->cx;
1067 gdouble dy = p[NR::Y] - spiral->cy;
1069 if (state & GDK_SHIFT_MASK) { // rotate without roll/unroll
1070 spiral->arg = atan2(dy, dx) - 2.0*M_PI*spiral->revo;
1071 if (!(state & GDK_MOD1_MASK)) {
1072 // if alt not pressed, change also rad; otherwise it is locked
1073 spiral->rad = MAX(hypot(dx, dy), 0.001);
1074 }
1075 if ( ( state & GDK_CONTROL_MASK )
1076 && snaps ) {
1077 spiral->arg = sp_round(spiral->arg, M_PI/snaps);
1078 }
1079 } else { // roll/unroll
1080 // arg of the spiral outer end
1081 double arg_1;
1082 sp_spiral_get_polar(spiral, 1, NULL, &arg_1);
1084 // its fractional part after the whole turns are subtracted
1085 double arg_r = arg_1 - sp_round(arg_1, 2.0*M_PI);
1087 // arg of the mouse point relative to spiral center
1088 double mouse_angle = atan2(dy, dx);
1089 if (mouse_angle < 0)
1090 mouse_angle += 2*M_PI;
1092 // snap if ctrl
1093 if ( ( state & GDK_CONTROL_MASK ) && snaps ) {
1094 mouse_angle = sp_round(mouse_angle, M_PI/snaps);
1095 }
1097 // by how much we want to rotate the outer point
1098 double diff = mouse_angle - arg_r;
1099 if (diff > M_PI)
1100 diff -= 2*M_PI;
1101 else if (diff < -M_PI)
1102 diff += 2*M_PI;
1104 // calculate the new rad;
1105 // the value of t corresponding to the angle arg_1 + diff:
1106 double t_temp = ((arg_1 + diff) - spiral->arg)/(2*M_PI*spiral->revo);
1107 // the rad at that t:
1108 double rad_new = 0;
1109 if (t_temp > spiral->t0)
1110 sp_spiral_get_polar(spiral, t_temp, &rad_new, NULL);
1112 // change the revo (converting diff from radians to the number of turns)
1113 spiral->revo += diff/(2*M_PI);
1114 if (spiral->revo < 1e-3)
1115 spiral->revo = 1e-3;
1117 // if alt not pressed and the values are sane, change the rad
1118 if (!(state & GDK_MOD1_MASK) && rad_new > 1e-3 && rad_new/spiral->rad < 2) {
1119 // adjust t0 too so that the inner point stays unmoved
1120 double r0;
1121 sp_spiral_get_polar(spiral, spiral->t0, &r0, NULL);
1122 spiral->rad = rad_new;
1123 spiral->t0 = pow(r0 / spiral->rad, 1.0/spiral->exp);
1124 }
1125 if (!IS_FINITE(spiral->t0)) spiral->t0 = 0.0;
1126 spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1127 }
1129 ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1130 }
1132 static NR::Point sp_spiral_inner_get(SPItem *item)
1133 {
1134 SPSpiral *spiral = SP_SPIRAL(item);
1136 return sp_spiral_get_xy(spiral, spiral->t0);
1137 }
1139 static NR::Point sp_spiral_outer_get(SPItem *item)
1140 {
1141 SPSpiral *spiral = SP_SPIRAL(item);
1143 return sp_spiral_get_xy(spiral, 1.0);
1144 }
1146 static void
1147 sp_spiral_inner_click(SPItem *item, guint state)
1148 {
1149 SPSpiral *spiral = SP_SPIRAL(item);
1151 if (state & GDK_MOD1_MASK) {
1152 spiral->exp = 1;
1153 ((SPObject *)spiral)->updateRepr();
1154 } else if (state & GDK_SHIFT_MASK) {
1155 spiral->t0 = 0;
1156 ((SPObject *)spiral)->updateRepr();
1157 }
1158 }
1160 static SPKnotHolder *
1161 sp_spiral_knot_holder(SPItem *item, SPDesktop *desktop)
1162 {
1163 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1165 sp_knot_holder_add(knot_holder, sp_spiral_inner_set, sp_spiral_inner_get, sp_spiral_inner_click,
1166 _("Roll/unroll the spiral from <b>inside</b>; with <b>Ctrl</b> to snap angle; with <b>Alt</b> to converge/diverge"));
1167 sp_knot_holder_add(knot_holder, sp_spiral_outer_set, sp_spiral_outer_get, NULL,
1168 _("Roll/unroll the spiral from <b>outside</b>; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to scale/rotate"));
1170 sp_pat_knot_holder(item, knot_holder);
1172 return knot_holder;
1173 }
1175 /* SPOffset */
1177 static void
1178 sp_offset_offset_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
1179 {
1180 SPOffset *offset = SP_OFFSET(item);
1182 offset->rad = sp_offset_distance_to_original(offset, p);
1183 offset->knot = p;
1184 offset->knotSet = true;
1186 ((SPObject *)offset)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1187 }
1190 static NR::Point sp_offset_offset_get(SPItem *item)
1191 {
1192 SPOffset *offset = SP_OFFSET(item);
1194 NR::Point np;
1195 sp_offset_top_point(offset,&np);
1196 return np;
1197 }
1199 static SPKnotHolder *
1200 sp_offset_knot_holder(SPItem *item, SPDesktop *desktop)
1201 {
1202 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1204 sp_knot_holder_add(knot_holder, sp_offset_offset_set, sp_offset_offset_get, NULL,
1205 _("Adjust the <b>offset distance</b>"));
1207 sp_pat_knot_holder(item, knot_holder);
1209 return knot_holder;
1210 }
1212 static SPKnotHolder *
1213 sp_misc_knot_holder(SPItem *item, SPDesktop *desktop) // FIXME: eliminate, instead make a pattern-drag similar to gradient-drag
1214 {
1215 if ((SP_OBJECT(item)->style->fill.isPaintserver())
1216 && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
1217 {
1218 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
1220 sp_pat_knot_holder(item, knot_holder);
1222 return knot_holder;
1223 }
1224 return NULL;
1225 }
1227 static void
1228 sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder)
1229 {
1230 if ((SP_OBJECT(item)->style->fill.isPaintserver())
1231 && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
1232 {
1233 sp_knot_holder_add_full(knot_holder, sp_pattern_xy_set, sp_pattern_xy_get, NULL, SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,
1234 // TRANSLATORS: This refers to the pattern that's inside the object
1235 _("<b>Move</b> the pattern fill inside the object"));
1236 sp_knot_holder_add_full(knot_holder, sp_pattern_scale_set, sp_pattern_scale_get, NULL, SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
1237 _("<b>Scale</b> the pattern fill uniformly"));
1238 sp_knot_holder_add_full(knot_holder, sp_pattern_angle_set, sp_pattern_angle_get, NULL, SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
1239 _("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"));
1240 }
1241 }
1243 static NR::Point sp_flowtext_corner_get(SPItem *item)
1244 {
1245 SPRect *rect = SP_RECT(item);
1247 return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
1248 }
1250 static void
1251 sp_flowtext_corner_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
1252 {
1253 SPRect *rect = SP_RECT(item);
1255 sp_rect_wh_set_internal(rect, p, origin, state);
1256 }
1258 static SPKnotHolder *
1259 sp_flowtext_knot_holder(SPItem *item, SPDesktop *desktop)
1260 {
1261 SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL);
1263 sp_knot_holder_add(knot_holder, sp_flowtext_corner_set, sp_flowtext_corner_get, NULL,
1264 _("Drag to resize the <b>flowed text frame</b>"));
1266 return knot_holder;
1267 }
1270 /*
1271 Local Variables:
1272 mode:c++
1273 c-file-style:"stroustrup"
1274 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1275 indent-tabs-mode:nil
1276 fill-column:99
1277 End:
1278 */
1279 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :