summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-bounding-box.cpp
blob: cfe1f516520cb3b2150602bfe51d14475a18f74b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com>
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#include <glibmm/i18n.h>

#include "live_effects/lpe-bounding-box.h"

#include "display/curve.h"
#include "sp-shape.h"
#include "sp-text.h"

namespace Inkscape {
namespace LivePathEffect {

LPEBoundingBox::LPEBoundingBox(LivePathEffectObject *lpeobject) :
    Effect(lpeobject),
    linked_path(_("Linked path:"), _("Path from which to take the original path data"), "linkedpath", &wr, this),
    visual_bounds(_("Visual Bounds"), _("Uses the visual bounding box"), "visualbounds", &wr, this)
{
    registerParameter( dynamic_cast<Parameter *>(&linked_path) );
    registerParameter( dynamic_cast<Parameter *>(&visual_bounds) );
    //perceived_path = true;
}

LPEBoundingBox::~LPEBoundingBox()
{

}

void LPEBoundingBox::doEffect (SPCurve * curve)
{
    if (curve) {
        if ( linked_path.linksToPath() && linked_path.getObject() ) {
            SPItem * item = linked_path.getObject();
            Geom::OptRect bbox = visual_bounds.get_value() ? item->visualBounds() : item->geometricBounds();
            Geom::Path p(Geom::Point(bbox->left(), bbox->top()));
            p.appendNew<Geom::LineSegment>(Geom::Point(bbox->right(), bbox->top()));
            p.appendNew<Geom::LineSegment>(Geom::Point(bbox->right(), bbox->bottom()));
            p.appendNew<Geom::LineSegment>(Geom::Point(bbox->left(), bbox->bottom()));
            p.appendNew<Geom::LineSegment>(Geom::Point(bbox->left(), bbox->top()));
            Geom::PathVector out;
            out.push_back(p);
            curve->set_pathvector(out);
        }
    }
}

} // namespace LivePathEffect
} /* namespace Inkscape */

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :