Code

400354d4ab55a14f9f9b850de12fe01cb42b7737
[inkscape.git] / src / object-edit.cpp
1 #define __SP_OBJECT_EDIT_C__
3 /*
4  * Node editing extension to objects
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *   Mitsuru Oka
9  *   Maximilian Albert <maximilian.albert@gmail.com>
10  *
11  * Licensed under GNU GPL
12  */
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
20 #include "sp-item.h"
21 #include "sp-rect.h"
22 #include "box3d.h"
23 #include "sp-ellipse.h"
24 #include "sp-star.h"
25 #include "sp-spiral.h"
26 #include "sp-offset.h"
27 #include "sp-flowtext.h"
28 #include "prefs-utils.h"
29 #include "desktop-affine.h"
30 #include "style.h"
31 #include "desktop.h"
32 #include "desktop-handles.h"
33 #include "sp-namedview.h"
34 #include "live_effects/effect.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 "2geom/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 KnotHolder *sp_lpe_knot_holder(SPItem *item, SPDesktop *desktop)
52 {
53     KnotHolder *knot_holder = new KnotHolder(desktop, item, NULL);
55     Inkscape::LivePathEffect::Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
56     effect->addHandles(knot_holder, desktop, item);
58     return knot_holder;
59 }
61 KnotHolder *
62 sp_item_knot_holder(SPItem *item, SPDesktop *desktop)
63 {
64     KnotHolder *knotholder = NULL;
66     if (SP_IS_LPE_ITEM(item) &&
67         sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)) &&
68         sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->isVisible() &&
69         sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->providesKnotholder()) {
70         knotholder = sp_lpe_knot_holder(item, desktop);
71     } else if (SP_IS_RECT(item)) {
72         knotholder = new RectKnotHolder(desktop, item, NULL);
73     } else if (SP_IS_BOX3D(item)) {
74         knotholder = new Box3DKnotHolder(desktop, item, NULL);
75     } else if (SP_IS_ARC(item)) {
76         knotholder = new ArcKnotHolder(desktop, item, NULL);
77     } else if (SP_IS_STAR(item)) {
78         knotholder = new StarKnotHolder(desktop, item, NULL);
79     } else if (SP_IS_SPIRAL(item)) {
80         knotholder = new SpiralKnotHolder(desktop, item, NULL);
81     } else if (SP_IS_OFFSET(item)) {
82         knotholder = new OffsetKnotHolder(desktop, item, NULL);
83     } else if (SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
84         knotholder = new FlowtextKnotHolder(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL);
85     } else if ((SP_OBJECT(item)->style->fill.isPaintserver())
86                && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style))) {
87         knotholder = new KnotHolder(desktop, item, NULL);
88         knotholder->add_pattern_knotholder();
89     }
91     return knotholder;
92 }
94 /* SPRect */
96 /* handle for horizontal rounding radius */
97 class RectKnotHolderEntityRX : public KnotHolderEntity {
98 public:
99     virtual Geom::Point knot_get();
100     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
101     virtual void knot_click(guint state);
102 };
104 /* handle for vertical rounding radius */
105 class RectKnotHolderEntityRY : public KnotHolderEntity {
106 public:
107     virtual Geom::Point knot_get();
108     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
109     virtual void knot_click(guint state);
110 };
112 /* handle for width/height adjustment */
113 class RectKnotHolderEntityWH : public KnotHolderEntity {
114 public:
115     virtual Geom::Point knot_get();
116     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
118 protected:
119     void set_internal(Geom::Point const &p, Geom::Point const &origin, guint state);
120 };
122 /* handle for x/y adjustment */
123 class RectKnotHolderEntityXY : public KnotHolderEntity {
124 public:
125     virtual Geom::Point knot_get();
126     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
127 };
129 Geom::Point
130 RectKnotHolderEntityRX::knot_get()
132     SPRect *rect = SP_RECT(item);
134     return Geom::Point(rect->x.computed + rect->width.computed - rect->rx.computed, rect->y.computed);
137 void
138 RectKnotHolderEntityRX::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
140     SPRect *rect = SP_RECT(item);
142     //In general we cannot just snap this radius to an arbitrary point, as we have only a single
143     //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
144     //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
146     if (state & GDK_CONTROL_MASK) {
147         gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
148         rect->rx.computed = rect->ry.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, temp);
149         rect->rx._set = rect->ry._set = true;
151     } else {
152         rect->rx.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, rect->width.computed / 2.0);
153         rect->rx._set = true;
154     }
156     update_knot();
158     ((SPObject*)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
161 void
162 RectKnotHolderEntityRX::knot_click(guint state)
164     SPRect *rect = SP_RECT(item);
166     if (state & GDK_SHIFT_MASK) {
167         /* remove rounding from rectangle */
168         SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
169         SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
170     } else if (state & GDK_CONTROL_MASK) {
171         /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
172         SP_OBJECT_REPR(rect)->setAttribute("ry", SP_OBJECT_REPR(rect)->attribute("rx"));
173     }
175     update_knot();
178 Geom::Point
179 RectKnotHolderEntityRY::knot_get()
181     SPRect *rect = SP_RECT(item);
183     return Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->ry.computed);
186 void
187 RectKnotHolderEntityRY::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
189     SPRect *rect = SP_RECT(item);
191     //In general we cannot just snap this radius to an arbitrary point, as we have only a single
192     //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
193     //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
195     if (state & GDK_CONTROL_MASK) {
196         gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
197         rect->rx.computed = rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed, 0.0, temp);
198         rect->ry._set = rect->rx._set = true;
199     } else {
200         if (!rect->rx._set || rect->rx.computed == 0) {
201             rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
202                                       0.0,
203                                       MIN(rect->height.computed / 2.0, rect->width.computed / 2.0));
204         } else {
205             rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed,
206                                       0.0,
207                                       rect->height.computed / 2.0);
208         }
210         rect->ry._set = true;
211     }
213     update_knot();
215     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
218 void
219 RectKnotHolderEntityRY::knot_click(guint state)
221     SPRect *rect = SP_RECT(item);
223     if (state & GDK_SHIFT_MASK) {
224         /* remove rounding */
225         SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
226         SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
227     } else if (state & GDK_CONTROL_MASK) {
228         /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
229         SP_OBJECT_REPR(rect)->setAttribute("rx", SP_OBJECT_REPR(rect)->attribute("ry"));
230     }
233 #define SGN(x) ((x)>0?1:((x)<0?-1:0))
235 static void sp_rect_clamp_radii(SPRect *rect)
237     // clamp rounding radii so that they do not exceed width/height
238     if (2 * rect->rx.computed > rect->width.computed) {
239         rect->rx.computed = 0.5 * rect->width.computed;
240         rect->rx._set = true;
241     }
242     if (2 * rect->ry.computed > rect->height.computed) {
243         rect->ry.computed = 0.5 * rect->height.computed;
244         rect->ry._set = true;
245     }
248 Geom::Point
249 RectKnotHolderEntityWH::knot_get()
251     SPRect *rect = SP_RECT(item);
253     return Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
256 void
257 RectKnotHolderEntityWH::set_internal(Geom::Point const &p, Geom::Point const &origin, guint state)
259     SPRect *rect = SP_RECT(item);
260     Geom::Point const s = snap_knot_position(p);
262     if (state & GDK_CONTROL_MASK) {
263         // original width/height when drag started
264         gdouble const w_orig = (origin[NR::X] - rect->x.computed);
265         gdouble const h_orig = (origin[NR::Y] - rect->y.computed);
267         //original ratio
268         gdouble const ratio = (w_orig / h_orig);
270         // mouse displacement since drag started
271         gdouble const minx = s[NR::X] - origin[NR::X];
272         gdouble const miny = s[NR::Y] - origin[NR::Y];
274         if (fabs(minx) > fabs(miny)) {
276             // snap to horizontal or diagonal
277             rect->width.computed = MAX(w_orig + minx, 0);
278             if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
279                 // closer to the diagonal and in same-sign quarters, change both using ratio
280                 rect->height.computed = MAX(h_orig + minx / ratio, 0);
281             } else {
282                 // closer to the horizontal, change only width, height is h_orig
283                 rect->height.computed = MAX(h_orig, 0);
284             }
286         } else {
287             // snap to vertical or diagonal
288             rect->height.computed = MAX(h_orig + miny, 0);
289             if (miny != 0 && fabs(minx/miny) > 0.5 * ratio && (SGN(minx) == SGN(miny))) {
290                 // closer to the diagonal and in same-sign quarters, change both using ratio
291                 rect->width.computed = MAX(w_orig + miny * ratio, 0);
292             } else {
293                 // closer to the vertical, change only height, width is w_orig
294                 rect->width.computed = MAX(w_orig, 0);
295             }
296         }
298         rect->width._set = rect->height._set = true;
300     } else {
301         // move freely
302         rect->width.computed = MAX(s[NR::X] - rect->x.computed, 0);
303         rect->height.computed = MAX(s[NR::Y] - rect->y.computed, 0);
304         rect->width._set = rect->height._set = true;
305     }
307     sp_rect_clamp_radii(rect);
309     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
312 void
313 RectKnotHolderEntityWH::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state)
315     set_internal(p, origin, state);
316     update_knot();
319 Geom::Point
320 RectKnotHolderEntityXY::knot_get()
322     SPRect *rect = SP_RECT(item);
324     return Geom::Point(rect->x.computed, rect->y.computed);
327 void
328 RectKnotHolderEntityXY::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state)
330     SPRect *rect = SP_RECT(item);
332     // opposite corner (unmoved)
333     gdouble opposite_x = (rect->x.computed + rect->width.computed);
334     gdouble opposite_y = (rect->y.computed + rect->height.computed);
336     // original width/height when drag started
337     gdouble w_orig = opposite_x - origin[NR::X];
338     gdouble h_orig = opposite_y - origin[NR::Y];
340     Geom::Point const s = snap_knot_position(p);
342     // mouse displacement since drag started
343     gdouble minx = s[NR::X] - origin[NR::X];
344     gdouble miny = s[NR::Y] - origin[NR::Y];
346     if (state & GDK_CONTROL_MASK) {
347         //original ratio
348         gdouble ratio = (w_orig / h_orig);
350         if (fabs(minx) > fabs(miny)) {
352             // snap to horizontal or diagonal
353             rect->x.computed = MIN(s[NR::X], opposite_x);
354             rect->width.computed = MAX(w_orig - minx, 0);
355             if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
356                 // closer to the diagonal and in same-sign quarters, change both using ratio
357                 rect->y.computed = MIN(origin[NR::Y] + minx / ratio, opposite_y);
358                 rect->height.computed = MAX(h_orig - minx / ratio, 0);
359             } else {
360                 // closer to the horizontal, change only width, height is h_orig
361                 rect->y.computed = MIN(origin[NR::Y], opposite_y);
362                 rect->height.computed = MAX(h_orig, 0);
363             }
365         } else {
367             // snap to vertical or diagonal
368             rect->y.computed = MIN(s[NR::Y], opposite_y);
369             rect->height.computed = MAX(h_orig - miny, 0);
370             if (miny != 0 && fabs(minx/miny) > 0.5 *ratio && (SGN(minx) == SGN(miny))) {
371                 // closer to the diagonal and in same-sign quarters, change both using ratio
372                 rect->x.computed = MIN(origin[NR::X] + miny * ratio, opposite_x);
373                 rect->width.computed = MAX(w_orig - miny * ratio, 0);
374             } else {
375                 // closer to the vertical, change only height, width is w_orig
376                 rect->x.computed = MIN(origin[NR::X], opposite_x);
377                 rect->width.computed = MAX(w_orig, 0);
378             }
380         }
382         rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
384     } else {
385         // move freely
386         rect->x.computed = MIN(s[NR::X], opposite_x);
387         rect->width.computed = MAX(w_orig - minx, 0);
388         rect->y.computed = MIN(s[NR::Y], opposite_y);
389         rect->height.computed = MAX(h_orig - miny, 0);
390         rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
391     }
393     sp_rect_clamp_radii(rect);
395     update_knot();
397     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
400 RectKnotHolder::RectKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
401     KnotHolder(desktop, item, relhandler)
403     RectKnotHolderEntityRX *entity_rx = new RectKnotHolderEntityRX();
404     RectKnotHolderEntityRY *entity_ry = new RectKnotHolderEntityRY();
405     RectKnotHolderEntityWH *entity_wh = new RectKnotHolderEntityWH();
406     RectKnotHolderEntityXY *entity_xy = new RectKnotHolderEntityXY();
407     entity_rx->create(desktop, item, this,
408                       _("Adjust the <b>horizontal rounding</b> radius; with <b>Ctrl</b> "
409                         "to make the vertical radius the same"),
410                        SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
411     entity_ry->create(desktop, item, this,
412                       _("Adjust the <b>vertical rounding</b> radius; with <b>Ctrl</b> "
413                         "to make the horizontal radius the same"),
414                       SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
415     entity_wh->create(desktop, item, this,
416                       _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b>"
417                         "to lock ratio or stretch in one dimension only"),
418                       SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
419     entity_xy->create(desktop, item, this,
420                       _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b>"
421                         "to lock ratio or stretch in one dimension only"),
422                       SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
423     entity.push_back(entity_rx);
424     entity.push_back(entity_ry);
425     entity.push_back(entity_wh);
426     entity.push_back(entity_xy);
428     add_pattern_knotholder();
431 /* Box3D (= the new 3D box structure) */
433 class Box3DKnotHolderEntity : public KnotHolderEntity {
434 public:
435     virtual Geom::Point knot_get() = 0;
436     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) = 0;
438     Geom::Point knot_get_generic(SPItem *item, unsigned int knot_id);
439     void knot_set_generic(SPItem *item, unsigned int knot_id, Geom::Point const &p, guint state);
440 };
442 Geom::Point
443 Box3DKnotHolderEntity::knot_get_generic(SPItem *item, unsigned int knot_id)
445     return box3d_get_corner_screen(SP_BOX3D(item), knot_id);
448 void
449 Box3DKnotHolderEntity::knot_set_generic(SPItem *item, unsigned int knot_id, Geom::Point const &new_pos, guint state)
451     Geom::Point const s = snap_knot_position(new_pos);
453     g_assert(item != NULL);
454     SPBox3D *box = SP_BOX3D(item);
455     Geom::Matrix const i2d (sp_item_i2d_affine (item));
457     Box3D::Axis movement;
458     if ((knot_id < 4) != (state & GDK_SHIFT_MASK)) {
459         movement = Box3D::XY;
460     } else {
461         movement = Box3D::Z;
462     }
464     box3d_set_corner (box, knot_id, s * i2d, movement, (state & GDK_CONTROL_MASK));
465     box3d_set_z_orders(box);
466     box3d_position_set(box);
469 class Box3DKnotHolderEntity0 : public Box3DKnotHolderEntity {
470 public:
471     virtual Geom::Point knot_get();
472     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
473 };
475 class Box3DKnotHolderEntity1 : public Box3DKnotHolderEntity {
476 public:
477     virtual Geom::Point knot_get();
478     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
479 };
481 class Box3DKnotHolderEntity2 : public Box3DKnotHolderEntity {
482 public:
483     virtual Geom::Point knot_get();
484     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
485 };
487 class Box3DKnotHolderEntity3 : public Box3DKnotHolderEntity {
488 public:
489     virtual Geom::Point knot_get();
490     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
491 };
493 class Box3DKnotHolderEntity4 : public Box3DKnotHolderEntity {
494 public:
495     virtual Geom::Point knot_get();
496     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
497 };
499 class Box3DKnotHolderEntity5 : public Box3DKnotHolderEntity {
500 public:
501     virtual Geom::Point knot_get();
502     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
503 };
505 class Box3DKnotHolderEntity6 : public Box3DKnotHolderEntity {
506 public:
507     virtual Geom::Point knot_get();
508     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
509 };
511 class Box3DKnotHolderEntity7 : public Box3DKnotHolderEntity {
512 public:
513     virtual Geom::Point knot_get();
514     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
515 };
517 class Box3DKnotHolderEntityCenter : public KnotHolderEntity {
518 public:
519     virtual Geom::Point knot_get();
520     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
521 };
523 Geom::Point
524 Box3DKnotHolderEntity0::knot_get()
526     return knot_get_generic(item, 0);
529 Geom::Point
530 Box3DKnotHolderEntity1::knot_get()
532     return knot_get_generic(item, 1);
535 Geom::Point
536 Box3DKnotHolderEntity2::knot_get()
538     return knot_get_generic(item, 2);
541 Geom::Point
542 Box3DKnotHolderEntity3::knot_get()
544     return knot_get_generic(item, 3);
547 Geom::Point
548 Box3DKnotHolderEntity4::knot_get()
550     return knot_get_generic(item, 4);
553 Geom::Point
554 Box3DKnotHolderEntity5::knot_get()
556     return knot_get_generic(item, 5);
559 Geom::Point
560 Box3DKnotHolderEntity6::knot_get()
562     return knot_get_generic(item, 6);
565 Geom::Point
566 Box3DKnotHolderEntity7::knot_get()
568     return knot_get_generic(item, 7);
571 Geom::Point
572 Box3DKnotHolderEntityCenter::knot_get()
574     return box3d_get_center_screen(SP_BOX3D(item));
577 void
578 Box3DKnotHolderEntity0::knot_set(Geom::Point const &new_pos, Geom::Point const &/*origin*/, guint state)
580     knot_set_generic(item, 0, new_pos, state);
583 void
584 Box3DKnotHolderEntity1::knot_set(Geom::Point const &new_pos, Geom::Point const &/*origin*/, guint state)
586     knot_set_generic(item, 1, new_pos, state);
589 void
590 Box3DKnotHolderEntity2::knot_set(Geom::Point const &new_pos, Geom::Point const &/*origin*/, guint state)
592     knot_set_generic(item, 2, new_pos, state);
595 void
596 Box3DKnotHolderEntity3::knot_set(Geom::Point const &new_pos, Geom::Point const &/*origin*/, guint state)
598     knot_set_generic(item, 3, new_pos, state);
601 void
602 Box3DKnotHolderEntity4::knot_set(Geom::Point const &new_pos, Geom::Point const &/*origin*/, guint state)
604     knot_set_generic(item, 4, new_pos, state);
607 void
608 Box3DKnotHolderEntity5::knot_set(Geom::Point const &new_pos, Geom::Point const &/*origin*/, guint state)
610     knot_set_generic(item, 5, new_pos, state);
613 void
614 Box3DKnotHolderEntity6::knot_set(Geom::Point const &new_pos, Geom::Point const &/*origin*/, guint state)
616     knot_set_generic(item, 6, new_pos, state);
619 void
620 Box3DKnotHolderEntity7::knot_set(Geom::Point const &new_pos, Geom::Point const &/*origin*/, guint state)
622     knot_set_generic(item, 7, new_pos, state);
625 void
626 Box3DKnotHolderEntityCenter::knot_set(Geom::Point const &new_pos, Geom::Point const &origin, guint state)
628     Geom::Point const s = snap_knot_position(new_pos);
630     SPBox3D *box = SP_BOX3D(item);
631     Geom::Matrix const i2d (sp_item_i2d_affine (item));
633     box3d_set_center (SP_BOX3D(item), s * i2d, origin * i2d, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z,
634                       state & GDK_CONTROL_MASK);
636     box3d_set_z_orders(box);
637     box3d_position_set(box);
640 Box3DKnotHolder::Box3DKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
641     KnotHolder(desktop, item, relhandler)
643     Box3DKnotHolderEntity0 *entity_corner0 = new Box3DKnotHolderEntity0();
644     Box3DKnotHolderEntity1 *entity_corner1 = new Box3DKnotHolderEntity1();
645     Box3DKnotHolderEntity2 *entity_corner2 = new Box3DKnotHolderEntity2();
646     Box3DKnotHolderEntity3 *entity_corner3 = new Box3DKnotHolderEntity3();
647     Box3DKnotHolderEntity4 *entity_corner4 = new Box3DKnotHolderEntity4();
648     Box3DKnotHolderEntity5 *entity_corner5 = new Box3DKnotHolderEntity5();
649     Box3DKnotHolderEntity6 *entity_corner6 = new Box3DKnotHolderEntity6();
650     Box3DKnotHolderEntity7 *entity_corner7 = new Box3DKnotHolderEntity7();
651     Box3DKnotHolderEntityCenter *entity_center = new Box3DKnotHolderEntityCenter();
653     entity_corner0->create(desktop, item, this,
654                            _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; "
655                              "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
656     entity_corner1->create(desktop, item, this,
657                            _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; "
658                              "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
659     entity_corner2->create(desktop, item, this,
660                            _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; "
661                              "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
662     entity_corner3->create(desktop, item, this,
663                            _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; "
664                              "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
665     entity_corner4->create(desktop, item, this,
666                      _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; "
667                        "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
668     entity_corner5->create(desktop, item, this,
669                      _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; "
670                        "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
671     entity_corner6->create(desktop, item, this,
672                      _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; "
673                        "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
674     entity_corner7->create(desktop, item, this,
675                      _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; "
676                        "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
677     entity_center->create(desktop, item, this,
678                           _("Move the box in perspective"),
679                           SP_KNOT_SHAPE_CROSS);
681     entity.push_back(entity_corner0);
682     entity.push_back(entity_corner1);
683     entity.push_back(entity_corner2);
684     entity.push_back(entity_corner3);
685     entity.push_back(entity_corner4);
686     entity.push_back(entity_corner5);
687     entity.push_back(entity_corner6);
688     entity.push_back(entity_corner7);
689     entity.push_back(entity_center);
691     add_pattern_knotholder();
694 /* SPArc */
696 class ArcKnotHolderEntityStart : public KnotHolderEntity {
697 public:
698     virtual Geom::Point knot_get();
699     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
700 };
702 class ArcKnotHolderEntityEnd : public KnotHolderEntity {
703 public:
704     virtual Geom::Point knot_get();
705     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
706     virtual void knot_click(guint state);
707 };
709 class ArcKnotHolderEntityRX : public KnotHolderEntity {
710 public:
711     virtual Geom::Point knot_get();
712     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
713     virtual void knot_click(guint state);
714 };
716 class ArcKnotHolderEntityRY : public KnotHolderEntity {
717 public:
718     virtual Geom::Point knot_get();
719     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
720     virtual void knot_click(guint state);
721 };
723 /*
724  * return values:
725  *   1  : inside
726  *   0  : on the curves
727  *   -1 : outside
728  */
729 static gint
730 sp_genericellipse_side(SPGenericEllipse *ellipse, Geom::Point const &p)
732     gdouble dx = (p[NR::X] - ellipse->cx.computed) / ellipse->rx.computed;
733     gdouble dy = (p[NR::Y] - ellipse->cy.computed) / ellipse->ry.computed;
735     gdouble s = dx * dx + dy * dy;
736     if (s < 1.0) return 1;
737     if (s > 1.0) return -1;
738     return 0;
741 void
742 ArcKnotHolderEntityStart::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
744     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
746     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
747     SPArc *arc = SP_ARC(item);
749     ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
751     Geom::Point delta = p - Geom::Point(ge->cx.computed, ge->cy.computed);
752     NR::scale sc(ge->rx.computed, ge->ry.computed);
753     ge->start = atan2(delta * sc.inverse());
754     if ( ( state & GDK_CONTROL_MASK )
755          && snaps )
756     {
757         ge->start = sp_round(ge->start, M_PI/snaps);
758     }
759     sp_genericellipse_normalize(ge);
760     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
763 Geom::Point
764 ArcKnotHolderEntityStart::knot_get()
766     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
767     SPArc *arc = SP_ARC(item);
769     return sp_arc_get_xy(arc, ge->start);
772 void
773 ArcKnotHolderEntityEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
775     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
777     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
778     SPArc *arc = SP_ARC(item);
780     ge->closed = (sp_genericellipse_side(ge, p) == -1) ? TRUE : FALSE;
782     Geom::Point delta = p - Geom::Point(ge->cx.computed, ge->cy.computed);
783     NR::scale sc(ge->rx.computed, ge->ry.computed);
784     ge->end = atan2(delta * sc.inverse());
785     if ( ( state & GDK_CONTROL_MASK )
786          && snaps )
787     {
788         ge->end = sp_round(ge->end, M_PI/snaps);
789     }
790     sp_genericellipse_normalize(ge);
791     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
794 Geom::Point
795 ArcKnotHolderEntityEnd::knot_get()
797     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
798     SPArc *arc = SP_ARC(item);
800     return sp_arc_get_xy(arc, ge->end);
804 void
805 ArcKnotHolderEntityEnd::knot_click(guint state)
807     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
809     if (state & GDK_SHIFT_MASK) {
810         ge->end = ge->start = 0;
811         ((SPObject *)ge)->updateRepr();
812     }
816 void
817 ArcKnotHolderEntityRX::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
819     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
821     Geom::Point const s = snap_knot_position(p);
823     ge->rx.computed = fabs( ge->cx.computed - s[NR::X] );
825     if ( state & GDK_CONTROL_MASK ) {
826         ge->ry.computed = ge->rx.computed;
827     }
829     ((SPObject *)item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
832 Geom::Point
833 ArcKnotHolderEntityRX::knot_get()
835     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
837     return (Geom::Point(ge->cx.computed, ge->cy.computed) -  Geom::Point(ge->rx.computed, 0));
840 void
841 ArcKnotHolderEntityRX::knot_click(guint state)
843     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
845     if (state & GDK_CONTROL_MASK) {
846         ge->ry.computed = ge->rx.computed;
847         ((SPObject *)ge)->updateRepr();
848     }
851 void
852 ArcKnotHolderEntityRY::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
854     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
856     Geom::Point const s = snap_knot_position(p);
858     ge->ry.computed = fabs( ge->cy.computed - s[NR::Y] );
860     if ( state & GDK_CONTROL_MASK ) {
861         ge->rx.computed = ge->ry.computed;
862     }
864     ((SPObject *)item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
867 Geom::Point
868 ArcKnotHolderEntityRY::knot_get()
870     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
872     return (Geom::Point(ge->cx.computed, ge->cy.computed) -  Geom::Point(0, ge->ry.computed));
875 void
876 ArcKnotHolderEntityRY::knot_click(guint state)
878     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
880     if (state & GDK_CONTROL_MASK) {
881         ge->rx.computed = ge->ry.computed;
882         ((SPObject *)ge)->updateRepr();
883     }
886 ArcKnotHolder::ArcKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
887     KnotHolder(desktop, item, relhandler)
889     ArcKnotHolderEntityRX *entity_rx = new ArcKnotHolderEntityRX();
890     ArcKnotHolderEntityRY *entity_ry = new ArcKnotHolderEntityRY();
891     ArcKnotHolderEntityStart *entity_start = new ArcKnotHolderEntityStart();
892     ArcKnotHolderEntityEnd *entity_end = new ArcKnotHolderEntityEnd();
893     entity_rx->create(desktop, item, this,
894                       _("Adjust ellipse <b>width</b>, with <b>Ctrl</b> to make circle"),
895                       SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
896     entity_ry->create(desktop, item, this,
897                       _("Adjust ellipse <b>height</b>, with <b>Ctrl</b> to make circle"),
898                       SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
899     entity_start->create(desktop, item, this,
900                          _("Position the <b>start point</b> of the arc or segment; with <b>Ctrl</b>"
901                            "to snap angle; drag <b>inside</b> the ellipse for arc, <b>outside</b> for segment"),
902                          SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
903     entity_end->create(desktop, item, this,
904                        _("Position the <b>end point</b> of the arc or segment; with <b>Ctrl</b> to snap angle; "
905                          "drag <b>inside</b> the ellipse for arc, <b>outside</b> for segment"),
906                        SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
907     entity.push_back(entity_rx);
908     entity.push_back(entity_ry);
909     entity.push_back(entity_start);
910     entity.push_back(entity_end);
912     add_pattern_knotholder();
915 /* SPStar */
917 class StarKnotHolderEntity1 : public KnotHolderEntity {
918 public:
919     virtual Geom::Point knot_get();
920     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
921     virtual void knot_click(guint state);
922 };
924 class StarKnotHolderEntity2 : public KnotHolderEntity {
925 public:
926     virtual Geom::Point knot_get();
927     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
928     virtual void knot_click(guint state);
929 };
931 void
932 StarKnotHolderEntity1::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
934     SPStar *star = SP_STAR(item);
936     Geom::Point const s = snap_knot_position(p);
938     Geom::Point d = s - to_2geom(star->center);
940     double arg1 = atan2(d);
941     double darg1 = arg1 - star->arg[0];
943     if (state & GDK_MOD1_MASK) {
944         star->randomized = darg1/(star->arg[0] - star->arg[1]);
945     } else if (state & GDK_SHIFT_MASK) {
946         star->rounded = darg1/(star->arg[0] - star->arg[1]);
947     } else if (state & GDK_CONTROL_MASK) {
948         star->r[0]    = L2(d);
949     } else {
950         star->r[0]    = L2(d);
951         star->arg[0]  = arg1;
952         star->arg[1] += darg1;
953     }
954     ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
957 void
958 StarKnotHolderEntity2::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
960     SPStar *star = SP_STAR(item);
962     Geom::Point const s = snap_knot_position(p);
964     if (star->flatsided == false) {
965         Geom::Point d = s - to_2geom(star->center);
967         double arg1 = atan2(d);
968         double darg1 = arg1 - star->arg[1];
970         if (state & GDK_MOD1_MASK) {
971             star->randomized = darg1/(star->arg[0] - star->arg[1]);
972         } else if (state & GDK_SHIFT_MASK) {
973             star->rounded = fabs(darg1/(star->arg[0] - star->arg[1]));
974         } else if (state & GDK_CONTROL_MASK) {
975             star->r[1]   = L2(d);
976             star->arg[1] = star->arg[0] + M_PI / star->sides;
977         }
978         else {
979             star->r[1]   = L2(d);
980             star->arg[1] = atan2(d);
981         }
982         ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
983     }
986 Geom::Point
987 StarKnotHolderEntity1::knot_get()
989     g_assert(item != NULL);
991     SPStar *star = SP_STAR(item);
993     return sp_star_get_xy(star, SP_STAR_POINT_KNOT1, 0);
997 Geom::Point
998 StarKnotHolderEntity2::knot_get()
1000     g_assert(item != NULL);
1002     SPStar *star = SP_STAR(item);
1004     return sp_star_get_xy(star, SP_STAR_POINT_KNOT2, 0);
1007 static void
1008 sp_star_knot_click(SPItem *item, guint state)
1010     SPStar *star = SP_STAR(item);
1012     if (state & GDK_MOD1_MASK) {
1013         star->randomized = 0;
1014         ((SPObject *)star)->updateRepr();
1015     } else if (state & GDK_SHIFT_MASK) {
1016         star->rounded = 0;
1017         ((SPObject *)star)->updateRepr();
1018     } else if (state & GDK_CONTROL_MASK) {
1019         star->arg[1] = star->arg[0] + M_PI / star->sides;
1020         ((SPObject *)star)->updateRepr();
1021     }
1024 void
1025 StarKnotHolderEntity1::knot_click(guint state)
1027     return sp_star_knot_click(item, state);
1030 void
1031 StarKnotHolderEntity2::knot_click(guint state)
1033     return sp_star_knot_click(item, state);
1036 StarKnotHolder::StarKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
1037     KnotHolder(desktop, item, relhandler)
1039     SPStar *star = SP_STAR(item);
1041     StarKnotHolderEntity1 *entity1 = new StarKnotHolderEntity1();
1042     entity1->create(desktop, item, this,
1043                     _("Adjust the <b>tip radius</b> of the star or polygon; "
1044                       "with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
1045     entity.push_back(entity1);
1047     if (star->flatsided == false) {
1048         StarKnotHolderEntity2 *entity2 = new StarKnotHolderEntity2();
1049         entity2->create(desktop, item, this,
1050                         _("Adjust the <b>base radius</b> of the star; with <b>Ctrl</b> to keep star rays "
1051                           "radial (no skew); with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
1052         entity.push_back(entity2);
1053     }
1055     add_pattern_knotholder();
1058 /* SPSpiral */
1060 class SpiralKnotHolderEntityInner : public KnotHolderEntity {
1061 public:
1062     virtual Geom::Point knot_get();
1063     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
1064     virtual void knot_click(guint state);
1065 };
1067 class SpiralKnotHolderEntityOuter : public KnotHolderEntity {
1068 public:
1069     virtual Geom::Point knot_get();
1070     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
1071 };
1074 /*
1075  * set attributes via inner (t=t0) knot point:
1076  *   [default] increase/decrease inner point
1077  *   [shift]   increase/decrease inner and outer arg synchronizely
1078  *   [control] constrain inner arg to round per PI/4
1079  */
1080 void
1081 SpiralKnotHolderEntityInner::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
1083     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1085     SPSpiral *spiral = SP_SPIRAL(item);
1087     gdouble   dx = p[NR::X] - spiral->cx;
1088     gdouble   dy = p[NR::Y] - spiral->cy;
1090     if (state & GDK_MOD1_MASK) {
1091         // adjust divergence by vertical drag, relative to rad
1092         double new_exp = (spiral->rad + dy)/(spiral->rad);
1093         spiral->exp = new_exp > 0? new_exp : 0;
1094     } else {
1095         // roll/unroll from inside
1096         gdouble   arg_t0;
1097         sp_spiral_get_polar(spiral, spiral->t0, NULL, &arg_t0);
1099         gdouble   arg_tmp = atan2(dy, dx) - arg_t0;
1100         gdouble   arg_t0_new = arg_tmp - floor((arg_tmp+M_PI)/(2.0*M_PI))*2.0*M_PI + arg_t0;
1101         spiral->t0 = (arg_t0_new - spiral->arg) / (2.0*M_PI*spiral->revo);
1103         /* round inner arg per PI/snaps, if CTRL is pressed */
1104         if ( ( state & GDK_CONTROL_MASK )
1105              && ( fabs(spiral->revo) > SP_EPSILON_2 )
1106              && ( snaps != 0 ) ) {
1107             gdouble arg = 2.0*M_PI*spiral->revo*spiral->t0 + spiral->arg;
1108             spiral->t0 = (sp_round(arg, M_PI/snaps) - spiral->arg)/(2.0*M_PI*spiral->revo);
1109         }
1111         spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1112     }
1114     ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1117 /*
1118  * set attributes via outer (t=1) knot point:
1119  *   [default] increase/decrease revolution factor
1120  *   [control] constrain inner arg to round per PI/4
1121  */
1122 void
1123 SpiralKnotHolderEntityOuter::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
1125     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1127     SPSpiral *spiral = SP_SPIRAL(item);
1129     gdouble  dx = p[NR::X] - spiral->cx;
1130     gdouble  dy = p[NR::Y] - spiral->cy;
1132     if (state & GDK_SHIFT_MASK) { // rotate without roll/unroll
1133         spiral->arg = atan2(dy, dx) - 2.0*M_PI*spiral->revo;
1134         if (!(state & GDK_MOD1_MASK)) {
1135             // if alt not pressed, change also rad; otherwise it is locked
1136             spiral->rad = MAX(hypot(dx, dy), 0.001);
1137         }
1138         if ( ( state & GDK_CONTROL_MASK )
1139              && snaps ) {
1140             spiral->arg = sp_round(spiral->arg, M_PI/snaps);
1141         }
1142     } else { // roll/unroll
1143         // arg of the spiral outer end
1144         double arg_1;
1145         sp_spiral_get_polar(spiral, 1, NULL, &arg_1);
1147         // its fractional part after the whole turns are subtracted
1148         double arg_r = arg_1 - sp_round(arg_1, 2.0*M_PI);
1150         // arg of the mouse point relative to spiral center
1151         double mouse_angle = atan2(dy, dx);
1152         if (mouse_angle < 0)
1153             mouse_angle += 2*M_PI;
1155         // snap if ctrl
1156         if ( ( state & GDK_CONTROL_MASK ) && snaps ) {
1157             mouse_angle = sp_round(mouse_angle, M_PI/snaps);
1158         }
1160         // by how much we want to rotate the outer point
1161         double diff = mouse_angle - arg_r;
1162         if (diff > M_PI)
1163             diff -= 2*M_PI;
1164         else if (diff < -M_PI)
1165             diff += 2*M_PI;
1167         // calculate the new rad;
1168         // the value of t corresponding to the angle arg_1 + diff:
1169         double t_temp = ((arg_1 + diff) - spiral->arg)/(2*M_PI*spiral->revo);
1170         // the rad at that t:
1171         double rad_new = 0;
1172         if (t_temp > spiral->t0)
1173             sp_spiral_get_polar(spiral, t_temp, &rad_new, NULL);
1175         // change the revo (converting diff from radians to the number of turns)
1176         spiral->revo += diff/(2*M_PI);
1177         if (spiral->revo < 1e-3)
1178             spiral->revo = 1e-3;
1180         // if alt not pressed and the values are sane, change the rad
1181         if (!(state & GDK_MOD1_MASK) && rad_new > 1e-3 && rad_new/spiral->rad < 2) {
1182             // adjust t0 too so that the inner point stays unmoved
1183             double r0;
1184             sp_spiral_get_polar(spiral, spiral->t0, &r0, NULL);
1185             spiral->rad = rad_new;
1186             spiral->t0 = pow(r0 / spiral->rad, 1.0/spiral->exp);
1187         }
1188         if (!IS_FINITE(spiral->t0)) spiral->t0 = 0.0;
1189         spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
1190     }
1192     ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1195 Geom::Point
1196 SpiralKnotHolderEntityInner::knot_get()
1198     SPSpiral *spiral = SP_SPIRAL(item);
1200     return sp_spiral_get_xy(spiral, spiral->t0);
1203 Geom::Point
1204 SpiralKnotHolderEntityOuter::knot_get()
1206     SPSpiral *spiral = SP_SPIRAL(item);
1208     return sp_spiral_get_xy(spiral, 1.0);
1211 void
1212 SpiralKnotHolderEntityInner::knot_click(guint state)
1214     SPSpiral *spiral = SP_SPIRAL(item);
1216     if (state & GDK_MOD1_MASK) {
1217         spiral->exp = 1;
1218         ((SPObject *)spiral)->updateRepr();
1219     } else if (state & GDK_SHIFT_MASK) {
1220         spiral->t0 = 0;
1221         ((SPObject *)spiral)->updateRepr();
1222     }
1225 SpiralKnotHolder::SpiralKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
1226     KnotHolder(desktop, item, relhandler)
1228     SpiralKnotHolderEntityInner *entity_inner = new SpiralKnotHolderEntityInner();
1229     SpiralKnotHolderEntityOuter *entity_outer = new SpiralKnotHolderEntityOuter();
1230     entity_inner->create(desktop, item, this,
1231                          _("Roll/unroll the spiral from <b>inside</b>; with <b>Ctrl</b> to snap angle; "
1232                            "with <b>Alt</b> to converge/diverge"));
1233     entity_outer->create(desktop, item, this,
1234                          _("Roll/unroll the spiral from <b>outside</b>; with <b>Ctrl</b> to snap angle; "
1235                            "with <b>Shift</b> to scale/rotate"));
1236     entity.push_back(entity_inner);
1237     entity.push_back(entity_outer);
1239     add_pattern_knotholder();
1242 /* SPOffset */
1244 class OffsetKnotHolderEntity : public KnotHolderEntity {
1245 public:
1246     virtual Geom::Point knot_get();
1247     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
1248 };
1250 void
1251 OffsetKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
1253     SPOffset *offset = SP_OFFSET(item);
1255     offset->rad = sp_offset_distance_to_original(offset, p);
1256     offset->knot = p;
1257     offset->knotSet = true;
1259     ((SPObject *)offset)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1263 Geom::Point
1264 OffsetKnotHolderEntity::knot_get()
1266     SPOffset *offset = SP_OFFSET(item);
1268     Geom::Point np;
1269     sp_offset_top_point(offset,&np);
1270     return np;
1273 OffsetKnotHolder::OffsetKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
1274     KnotHolder(desktop, item, relhandler)
1276     OffsetKnotHolderEntity *entity_offset = new OffsetKnotHolderEntity();
1277     entity_offset->create(desktop, item, this,
1278                           _("Adjust the <b>offset distance</b>"));
1279     entity.push_back(entity_offset);
1281     add_pattern_knotholder();
1284 // TODO: this is derived from RectKnotHolderEntityWH because it used the same static function
1285 // set_internal as the latter before KnotHolderEntity was C++ified. Check whether this also makes
1286 // sense logically.
1287 class FlowtextKnotHolderEntity : public RectKnotHolderEntityWH {
1288 public:
1289     virtual Geom::Point knot_get();
1290     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
1291 };
1293 Geom::Point
1294 FlowtextKnotHolderEntity::knot_get()
1296     SPRect *rect = SP_RECT(item);
1298     return Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
1301 void
1302 FlowtextKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state)
1304     set_internal(p, origin, state);
1307 FlowtextKnotHolder::FlowtextKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
1308     KnotHolder(desktop, item, relhandler)
1310     g_assert(item != NULL);
1312     FlowtextKnotHolderEntity *entity_flowtext = new FlowtextKnotHolderEntity();
1313     entity_flowtext->create(desktop, item, this,
1314                             _("Drag to resize the <b>flowed text frame</b>"));
1315     entity.push_back(entity_flowtext);
1318 /*
1319   Local Variables:
1320   mode:c++
1321   c-file-style:"stroustrup"
1322   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1323   indent-tabs-mode:nil
1324   fill-column:99
1325   End:
1326 */
1327 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :