~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/object-edit.cpp

  • Committer: JazzyNico
  • Date: 2011-08-29 20:25:30 UTC
  • Revision ID: nicoduf@yahoo.fr-20110829202530-6deuoz11q90usldv
Code refactoring and merging with trunk (revision 10599).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#define __SP_OBJECT_EDIT_C__
2
 
 
3
1
/*
4
2
 * Node editing extension to objects
5
3
 *
7
5
 *   Lauris Kaplinski <lauris@kaplinski.com>
8
6
 *   Mitsuru Oka
9
7
 *   Maximilian Albert <maximilian.albert@gmail.com>
 
8
 *   Abhishek Sharma
10
9
 *
11
10
 * Licensed under GNU GPL
12
11
 */
31
30
#include "desktop-handles.h"
32
31
#include "sp-namedview.h"
33
32
#include "live_effects/effect.h"
34
 
 
35
33
#include "sp-pattern.h"
36
34
#include "sp-path.h"
37
 
 
38
35
#include <glibmm/i18n.h>
39
 
 
40
36
#include "object-edit.h"
41
 
 
42
 
#include <libnr/nr-scale-ops.h>
43
 
 
44
37
#include "xml/repr.h"
45
 
 
46
 
#include "2geom/isnan.h"
 
38
#include <2geom/math-utils.h>
47
39
 
48
40
#define sp_round(v,m) (((v) < 0.0) ? ((ceil((v) / (m) - 0.5)) * (m)) : ((floor((v) / (m) + 0.5)) * (m)))
49
41
 
81
73
        knotholder = new OffsetKnotHolder(desktop, item, NULL);
82
74
    } else if (SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
83
75
        knotholder = new FlowtextKnotHolder(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL);
84
 
    } else if ((SP_OBJECT(item)->style->fill.isPaintserver())
85
 
               && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style))) {
 
76
    } else if ((item->style->fill.isPaintserver())
 
77
               && SP_IS_PATTERN(item->style->getFillPaintServer())) {
86
78
        knotholder = new KnotHolder(desktop, item, NULL);
87
79
        knotholder->add_pattern_knotholder();
88
80
    }
141
133
    //In general we cannot just snap this radius to an arbitrary point, as we have only a single
142
134
    //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
143
135
    //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
144
 
    Geom::Point const s = snap_knot_position_constrained(p, Inkscape::Snapper::ConstraintLine(Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed), Geom::Point(-1, 0)));
 
136
    Geom::Point const s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed), Geom::Point(-1, 0)));
145
137
 
146
138
    if (state & GDK_CONTROL_MASK) {
147
139
        gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
165
157
 
166
158
    if (state & GDK_SHIFT_MASK) {
167
159
        /* remove rounding from rectangle */
168
 
        SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
169
 
        SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
 
160
        rect->getRepr()->setAttribute("rx", NULL);
 
161
        rect->getRepr()->setAttribute("ry", NULL);
170
162
    } else if (state & GDK_CONTROL_MASK) {
171
163
        /* 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"));
 
164
        rect->getRepr()->setAttribute("ry", rect->getRepr()->attribute("rx"));
173
165
    }
174
166
 
175
 
    update_knot();
176
167
}
177
168
 
178
169
Geom::Point
191
182
    //In general we cannot just snap this radius to an arbitrary point, as we have only a single
192
183
    //degree of freedom. For snapping to an arbitrary point we need two DOF. If we're going to snap
193
184
    //the radius then we should have a constrained snap. snap_knot_position() is unconstrained
194
 
    Geom::Point const s = snap_knot_position_constrained(p, Inkscape::Snapper::ConstraintLine(Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed), Geom::Point(0, 1)));
 
185
    Geom::Point const s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed), Geom::Point(0, 1)));
195
186
 
196
187
    if (state & GDK_CONTROL_MASK) { // When holding control then rx will be kept equal to ry,
197
188
                                    // resulting in a perfect circle (and not an ellipse)
224
215
 
225
216
    if (state & GDK_SHIFT_MASK) {
226
217
        /* remove rounding */
227
 
        SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
228
 
        SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
 
218
        rect->getRepr()->setAttribute("rx", NULL);
 
219
        rect->getRepr()->setAttribute("ry", NULL);
229
220
    } else if (state & GDK_CONTROL_MASK) {
230
221
        /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
231
 
        SP_OBJECT_REPR(rect)->setAttribute("rx", SP_OBJECT_REPR(rect)->attribute("ry"));
 
222
        rect->getRepr()->setAttribute("rx", rect->getRepr()->attribute("ry"));
232
223
    }
233
224
}
234
225
 
280
271
            // snap to horizontal or diagonal
281
272
            if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
282
273
                // closer to the diagonal and in same-sign quarters, change both using ratio
283
 
                s = snap_knot_position_constrained(p, Inkscape::Snapper::ConstraintLine(p_handle, Geom::Point(-ratio, -1)));
 
274
                s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-ratio, -1)));
284
275
                minx = s[Geom::X] - origin[Geom::X];
285
276
                miny = s[Geom::Y] - origin[Geom::Y];
286
277
                rect->height.computed = MAX(h_orig + minx / ratio, 0);
287
278
            } else {
288
279
                // closer to the horizontal, change only width, height is h_orig
289
 
                s = snap_knot_position_constrained(p, Inkscape::Snapper::ConstraintLine(p_handle, Geom::Point(-1, 0)));
 
280
                s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-1, 0)));
290
281
                minx = s[Geom::X] - origin[Geom::X];
291
282
                miny = s[Geom::Y] - origin[Geom::Y];
292
283
                rect->height.computed = MAX(h_orig, 0);
297
288
            // snap to vertical or diagonal
298
289
            if (miny != 0 && fabs(minx/miny) > 0.5 * ratio && (SGN(minx) == SGN(miny))) {
299
290
                // closer to the diagonal and in same-sign quarters, change both using ratio
300
 
                s = snap_knot_position_constrained(p, Inkscape::Snapper::ConstraintLine(p_handle, Geom::Point(-ratio, -1)));
 
291
                s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-ratio, -1)));
301
292
                minx = s[Geom::X] - origin[Geom::X];
302
293
                miny = s[Geom::Y] - origin[Geom::Y];
303
294
                rect->width.computed = MAX(w_orig + miny * ratio, 0);
304
295
            } else {
305
296
                // closer to the vertical, change only height, width is w_orig
306
 
                s = snap_knot_position_constrained(p, Inkscape::Snapper::ConstraintLine(p_handle, Geom::Point(0, -1)));
 
297
                s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(0, -1)));
307
298
                minx = s[Geom::X] - origin[Geom::X];
308
299
                miny = s[Geom::Y] - origin[Geom::Y];
309
300
                rect->width.computed = MAX(w_orig, 0);
370
361
            // snap to horizontal or diagonal
371
362
            if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
372
363
                // closer to the diagonal and in same-sign quarters, change both using ratio
373
 
                s = snap_knot_position_constrained(p, Inkscape::Snapper::ConstraintLine(p_handle, Geom::Point(-ratio, -1)));
 
364
                s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-ratio, -1)));
374
365
                minx = s[Geom::X] - origin[Geom::X];
375
366
                miny = s[Geom::Y] - origin[Geom::Y];
376
367
                rect->y.computed = MIN(origin[Geom::Y] + minx / ratio, opposite_y);
377
368
                rect->height.computed = MAX(h_orig - minx / ratio, 0);
378
369
            } else {
379
370
                // closer to the horizontal, change only width, height is h_orig
380
 
                s = snap_knot_position_constrained(p, Inkscape::Snapper::ConstraintLine(p_handle, Geom::Point(-1, 0)));
 
371
                s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-1, 0)));
381
372
                minx = s[Geom::X] - origin[Geom::X];
382
373
                miny = s[Geom::Y] - origin[Geom::Y];
383
374
                rect->y.computed = MIN(origin[Geom::Y], opposite_y);
389
380
            // snap to vertical or diagonal
390
381
            if (miny != 0 && fabs(minx/miny) > 0.5 *ratio && (SGN(minx) == SGN(miny))) {
391
382
                // closer to the diagonal and in same-sign quarters, change both using ratio
392
 
                s = snap_knot_position_constrained(p, Inkscape::Snapper::ConstraintLine(p_handle, Geom::Point(-ratio, -1)));
 
383
                s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-ratio, -1)));
393
384
                minx = s[Geom::X] - origin[Geom::X];
394
385
                miny = s[Geom::Y] - origin[Geom::Y];
395
386
                rect->x.computed = MIN(origin[Geom::X] + miny * ratio, opposite_x);
396
387
                rect->width.computed = MAX(w_orig - miny * ratio, 0);
397
388
            } else {
398
389
                // closer to the vertical, change only height, width is w_orig
399
 
                s = snap_knot_position_constrained(p, Inkscape::Snapper::ConstraintLine(p_handle, Geom::Point(0, -1)));
 
390
                s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(0, -1)));
400
391
                minx = s[Geom::X] - origin[Geom::X];
401
392
                miny = s[Geom::Y] - origin[Geom::Y];
402
393
                rect->x.computed = MIN(origin[Geom::X], opposite_x);
483
474
 
484
475
    g_assert(item != NULL);
485
476
    SPBox3D *box = SP_BOX3D(item);
486
 
    Geom::Matrix const i2d (sp_item_i2d_affine (item));
 
477
    Geom::Affine const i2dt (item->i2dt_affine ());
487
478
 
488
479
    Box3D::Axis movement;
489
480
    if ((knot_id < 4) != (state & GDK_SHIFT_MASK)) {
492
483
        movement = Box3D::Z;
493
484
    }
494
485
 
495
 
    box3d_set_corner (box, knot_id, s * i2d, movement, (state & GDK_CONTROL_MASK));
 
486
    box3d_set_corner (box, knot_id, s * i2dt, movement, (state & GDK_CONTROL_MASK));
496
487
    box3d_set_z_orders(box);
497
488
    box3d_position_set(box);
498
489
}
659
650
    Geom::Point const s = snap_knot_position(new_pos);
660
651
 
661
652
    SPBox3D *box = SP_BOX3D(item);
662
 
    Geom::Matrix const i2d (sp_item_i2d_affine (item));
 
653
    Geom::Affine const i2dt (item->i2dt_affine ());
663
654
 
664
 
    box3d_set_center (SP_BOX3D(item), s * i2d, origin * i2d, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z,
 
655
    box3d_set_center (SP_BOX3D(item), s * i2dt, origin * i2dt, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z,
665
656
                      state & GDK_CONTROL_MASK);
666
657
 
667
658
    box3d_set_z_orders(box);
968
959
 
969
960
    Geom::Point const s = snap_knot_position(p);
970
961
 
971
 
    Geom::Point d = s - to_2geom(star->center);
 
962
    Geom::Point d = s - star->center;
972
963
 
973
964
    double arg1 = atan2(d);
974
965
    double darg1 = arg1 - star->arg[0];
995
986
    Geom::Point const s = snap_knot_position(p);
996
987
 
997
988
    if (star->flatsided == false) {
998
 
        Geom::Point d = s - to_2geom(star->center);
 
989
        Geom::Point d = s - star->center;
999
990
 
1000
991
        double arg1 = atan2(d);
1001
992
        double darg1 = arg1 - star->arg[1];
1365
1356
  fill-column:99
1366
1357
  End:
1367
1358
*/
1368
 
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
 
1359
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :