~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/live_effects/lpe-rough-hatches.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:
28
28
#include <2geom/bezier-to-sbasis.h>
29
29
#include <2geom/sbasis-to-bezier.h>
30
30
#include <2geom/d2.h>
31
 
#include <2geom/matrix.h>
 
31
#include <2geom/affine.h>
32
32
 
33
33
#include "ui/widget/scalar.h"
34
 
#include "libnr/nr-values.h"
35
34
 
36
35
namespace Inkscape {
37
36
namespace LivePathEffect {
223
222
LPERoughHatches::LPERoughHatches(LivePathEffectObject *lpeobject) :
224
223
    Effect(lpeobject),
225
224
    hatch_dist(0),
226
 
    dist_rdm(_("Frequency randomness"), _("Variation of distance between hatches, in %."), "dist_rdm", &wr, this, 75),
227
 
    growth(_("Growth"), _("Growth of distance between hatches."), "growth", &wr, this, 0.),
 
225
    dist_rdm(_("Frequency randomness:"), _("Variation of distance between hatches, in %."), "dist_rdm", &wr, this, 75),
 
226
    growth(_("Growth:"), _("Growth of distance between hatches."), "growth", &wr, this, 0.),
228
227
//FIXME: top/bottom names are inverted in the UI/svg and in the code!!
229
 
    scale_tf(_("Half-turns smoothness: 1st side, in"), _("Set smoothness/sharpness of path when reaching a 'bottom' half-turn. 0=sharp, 1=default"), "scale_bf", &wr, this, 1.),
230
 
    scale_tb(_("1st side, out"), _("Set smoothness/sharpness of path when leaving a 'bottom' half-turn. 0=sharp, 1=default"), "scale_bb", &wr, this, 1.),
231
 
    scale_bf(_("2nd side, in"), _("Set smoothness/sharpness of path when reaching a 'top' half-turn. 0=sharp, 1=default"), "scale_tf", &wr, this, 1.),
232
 
    scale_bb(_("2nd side, out"), _("Set smoothness/sharpness of path when leaving a 'top' half-turn. 0=sharp, 1=default"), "scale_tb", &wr, this, 1.),
233
 
    top_edge_variation(_("Magnitude jitter: 1st side"), _("Randomly moves 'bottom' half-turns to produce magnitude variations."), "bottom_edge_variation", &wr, this, 0),
234
 
    bot_edge_variation(_("2nd side"), _("Randomly moves 'top' half-turns to produce magnitude variations."), "top_edge_variation", &wr, this, 0),
235
 
    top_tgt_variation(_("Parallelism jitter: 1st side"), _("Add direction randomness by moving 'bottom' half-turns tangentially to the boundary."), "bottom_tgt_variation", &wr, this, 0),
236
 
    bot_tgt_variation(_("2nd side"), _("Add direction randomness by randomly moving 'top' half-turns tangentially to the boundary."), "top_tgt_variation", &wr, this, 0),
237
 
    top_smth_variation(_("Variance: 1st side"), _("Randomness of 'bottom' half-turns smoothness"), "top_smth_variation", &wr, this, 0),
238
 
    bot_smth_variation(_("2nd side"), _("Randomness of 'top' half-turns smoothness"), "bottom_smth_variation", &wr, this, 0),
 
228
    scale_tf(_("Half-turns smoothness: 1st side, in:"), _("Set smoothness/sharpness of path when reaching a 'bottom' half-turn. 0=sharp, 1=default"), "scale_bf", &wr, this, 1.),
 
229
    scale_tb(_("1st side, out:"), _("Set smoothness/sharpness of path when leaving a 'bottom' half-turn. 0=sharp, 1=default"), "scale_bb", &wr, this, 1.),
 
230
    scale_bf(_("2nd side, in:"), _("Set smoothness/sharpness of path when reaching a 'top' half-turn. 0=sharp, 1=default"), "scale_tf", &wr, this, 1.),
 
231
    scale_bb(_("2nd side, out:"), _("Set smoothness/sharpness of path when leaving a 'top' half-turn. 0=sharp, 1=default"), "scale_tb", &wr, this, 1.),
 
232
    top_edge_variation(_("Magnitude jitter: 1st side:"), _("Randomly moves 'bottom' half-turns to produce magnitude variations."), "bottom_edge_variation", &wr, this, 0),
 
233
    bot_edge_variation(_("2nd side:"), _("Randomly moves 'top' half-turns to produce magnitude variations."), "top_edge_variation", &wr, this, 0),
 
234
    top_tgt_variation(_("Parallelism jitter: 1st side:"), _("Add direction randomness by moving 'bottom' half-turns tangentially to the boundary."), "bottom_tgt_variation", &wr, this, 0),
 
235
    bot_tgt_variation(_("2nd side:"), _("Add direction randomness by randomly moving 'top' half-turns tangentially to the boundary."), "top_tgt_variation", &wr, this, 0),
 
236
    top_smth_variation(_("Variance: 1st side:"), _("Randomness of 'bottom' half-turns smoothness"), "top_smth_variation", &wr, this, 0),
 
237
    bot_smth_variation(_("2nd side:"), _("Randomness of 'top' half-turns smoothness"), "bottom_smth_variation", &wr, this, 0),
239
238
//
240
239
    fat_output(_("Generate thick/thin path"), _("Simulate a stroke of varying width"), "fat_output", &wr, this, true),
241
240
    do_bend(_("Bend hatches"), _("Add a global bend to the hatches (slower)"), "do_bend", &wr, this, true),
242
 
    stroke_width_top(_("Thickness: at 1st side"), _("Width at 'bottom' half-turns"), "stroke_width_top", &wr, this, 1.),
243
 
    stroke_width_bot(_("at 2nd side"), _("Width at 'top' half-turns"), "stroke_width_bottom", &wr, this, 1.),
 
241
    stroke_width_top(_("Thickness: at 1st side:"), _("Width at 'bottom' half-turns"), "stroke_width_top", &wr, this, 1.),
 
242
    stroke_width_bot(_("at 2nd side:"), _("Width at 'top' half-turns"), "stroke_width_bottom", &wr, this, 1.),
244
243
//
245
 
    front_thickness(_("from 2nd to 1st side"), _("Width from 'top' to 'bottom'"), "front_thickness", &wr, this, 1.),
246
 
    back_thickness(_("from 1st to 2nd side"), _("Width from 'bottom' to 'top'"), "back_thickness", &wr, this, .25),
 
244
    front_thickness(_("from 2nd to 1st side:"), _("Width from 'top' to 'bottom'"), "front_thickness", &wr, this, 1.),
 
245
    back_thickness(_("from 1st to 2nd side:"), _("Width from 'bottom' to 'top'"), "back_thickness", &wr, this, .25),
247
246
 
248
247
    direction(_("Hatches width and dir"), _("Defines hatches frequency and direction"), "direction", &wr, this, Geom::Point(50,0)),
249
248
//
271
270
    registerParameter( dynamic_cast<Parameter *>(&front_thickness) );
272
271
    registerParameter( dynamic_cast<Parameter *>(&back_thickness) );
273
272
 
274
 
    //hatch_dist.param_set_range(0.1, NR_HUGE);
275
 
    growth.param_set_range(0, NR_HUGE);
 
273
    //hatch_dist.param_set_range(0.1, Geom::infinity());
 
274
    growth.param_set_range(0, Geom::infinity());
276
275
    dist_rdm.param_set_range(0, 99.);
277
 
    stroke_width_top.param_set_range(0,  NR_HUGE);
278
 
    stroke_width_bot.param_set_range(0,  NR_HUGE);
279
 
    front_thickness.param_set_range(0, NR_HUGE);
280
 
    back_thickness.param_set_range(0, NR_HUGE);
 
276
    stroke_width_top.param_set_range(0,  Geom::infinity());
 
277
    stroke_width_bot.param_set_range(0,  Geom::infinity());
 
278
    front_thickness.param_set_range(0, Geom::infinity());
 
279
    back_thickness.param_set_range(0, Geom::infinity());
281
280
 
282
281
    // hide the widgets for direction and bender vectorparams
283
282
    direction.widget_is_visible = false;
309
308
    }
310
309
    Point transformed_org = direction.getOrigin();
311
310
    Piecewise<SBasis> tilter;//used to bend the hatches
312
 
    Matrix bend_mat;//used to bend the hatches
 
311
    Affine bend_mat;//used to bend the hatches
313
312
 
314
313
    if (do_bend.get_value()){
315
314
        Point bend_dir = -rot90(unit_vector(bender.getVector()));
316
315
        double bend_amount = L2(bender.getVector());
317
 
        bend_mat = Matrix(-bend_dir[Y], bend_dir[X], bend_dir[X], bend_dir[Y],0,0);
 
316
        bend_mat = Affine(-bend_dir[Y], bend_dir[X], bend_dir[X], bend_dir[Y],0,0);
318
317
        transformed_pwd2_in = transformed_pwd2_in * bend_mat;
319
318
        tilter = Piecewise<SBasis>(shift(Linear(-bend_amount),1));
320
319
        OptRect bbox = bounds_exact( transformed_pwd2_in );
325
324
    }
326
325
    hatch_dist = Geom::L2(direction.getVector())/5;
327
326
    Point hatches_dir = rot90(unit_vector(direction.getVector()));
328
 
    Matrix mat(-hatches_dir[Y], hatches_dir[X], hatches_dir[X], hatches_dir[Y],0,0);
 
327
    Affine mat(-hatches_dir[Y], hatches_dir[X], hatches_dir[X], hatches_dir[Y],0,0);
329
328
    transformed_pwd2_in = transformed_pwd2_in * mat;
330
329
    transformed_org *= mat;
331
330
 
557
556
{
558
557
    Effect::resetDefaults(item);
559
558
 
560
 
    Geom::OptRect bbox = item->getBounds(Geom::identity(), SPItem::GEOMETRIC_BBOX);
 
559
    Geom::OptRect bbox = item->geometricBounds();
561
560
    Geom::Point origin(0.,0.);
562
561
    Geom::Point vector(50.,0.);
563
562
    if (bbox) {