diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-09-19 22:33:11 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2013-09-19 22:33:11 +0000 |
| commit | 4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7 (patch) | |
| tree | caeb924426bcc861badc6fa81318b67460b26d47 /src/sp-line.cpp | |
| parent | Update to trunk (diff) | |
| parent | updates for cmake (diff) | |
| download | inkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.tar.gz inkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.zip | |
Update to trunk
(bzr r11950.1.141)
Diffstat (limited to 'src/sp-line.cpp')
| -rw-r--r-- | src/sp-line.cpp | 202 |
1 files changed, 76 insertions, 126 deletions
diff --git a/src/sp-line.cpp b/src/sp-line.cpp index 218d0c3b1..3963007de 100644 --- a/src/sp-line.cpp +++ b/src/sp-line.cpp @@ -24,198 +24,148 @@ #include "document.h" #include "inkscape.h" -static void sp_line_build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr); -static void sp_line_set(SPObject *object, unsigned int key, const gchar *value); -static Inkscape::XML::Node* sp_line_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static void sp_line_update(SPObject *object, SPCtx *ctx, guint flags); -static gchar* sp_line_get_description(SPItem * item); -static Geom::Affine sp_line_set_transform(SPItem *item, Geom::Affine const &xform); -static void sp_line_set_shape(SPShape *shape); -static void sp_line_convert_to_guides(SPItem *item); - -G_DEFINE_TYPE(SPLine, sp_line, SP_TYPE_SHAPE); - -static void -sp_line_class_init(SPLineClass *klass) -{ - SPObjectClass *sp_object_class = (SPObjectClass *) klass; - SPItemClass *item_class = (SPItemClass *) klass; - SPShapeClass *shape_class = (SPShapeClass *) klass; - - sp_object_class->build = sp_line_build; - sp_object_class->set = sp_line_set; - sp_object_class->write = sp_line_write; - sp_object_class->update = sp_line_update; - - item_class->description = sp_line_get_description; - item_class->set_transform = sp_line_set_transform; - item_class->convert_to_guides = sp_line_convert_to_guides; - - shape_class->set_shape = sp_line_set_shape; +#include "sp-factory.h" + +namespace { + SPObject* createLine() { + return new SPLine(); + } + + bool lineRegistered = SPFactory::instance().registerObject("svg:line", createLine); } -static void -sp_line_init(SPLine * line) -{ - line->x1.unset(); - line->y1.unset(); - line->x2.unset(); - line->y2.unset(); +SPLine::SPLine() : SPShape() { + this->x1.unset(); + this->y1.unset(); + this->x2.unset(); + this->y2.unset(); } +SPLine::~SPLine() { +} -static void -sp_line_build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) -{ - if (((SPObjectClass *) sp_line_parent_class)->build) { - ((SPObjectClass *) sp_line_parent_class)->build(object, document, repr); - } +void SPLine::build(SPDocument * document, Inkscape::XML::Node * repr) { + SPShape::build(document, repr); - object->readAttr( "x1" ); - object->readAttr( "y1" ); - object->readAttr( "x2" ); - object->readAttr( "y2" ); + this->readAttr( "x1" ); + this->readAttr( "y1" ); + this->readAttr( "x2" ); + this->readAttr( "y2" ); } -static void -sp_line_set(SPObject *object, unsigned int key, const gchar *value) -{ - SPLine * line = SP_LINE(object); - +void SPLine::set(unsigned int key, const gchar* value) { /* fixme: we should really collect updates */ switch (key) { case SP_ATTR_X1: - line->x1.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->x1.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_Y1: - line->y1.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->y1.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_X2: - line->x2.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->x2.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_Y2: - line->y2.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->y2.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + default: - if (((SPObjectClass *) sp_line_parent_class)->set) { - ((SPObjectClass *) sp_line_parent_class)->set(object, key, value); - } + SPShape::set(key, value); break; } } -static void -sp_line_update(SPObject *object, SPCtx *ctx, guint flags) -{ +void SPLine::update(SPCtx *ctx, guint flags) { if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - SPLine *line = SP_LINE(object); - - SPStyle const *style = object->style; + SPStyle const *style = this->style; SPItemCtx const *ictx = (SPItemCtx const *) ctx; double const w = ictx->viewport.width(); double const h = ictx->viewport.height(); double const em = style->font_size.computed; double const ex = em * 0.5; // fixme: get from pango or libnrtype. - line->x1.update(em, ex, w); - line->x2.update(em, ex, w); - line->y1.update(em, ex, h); - line->y2.update(em, ex, h); - ((SPShape *) object)->setShape(); - } + this->x1.update(em, ex, w); + this->x2.update(em, ex, w); + this->y1.update(em, ex, h); + this->y2.update(em, ex, h); - if (((SPObjectClass *) sp_line_parent_class)->update) { - ((SPObjectClass *) sp_line_parent_class)->update(object, ctx, flags); + this->set_shape(); } -} + SPShape::update(ctx, flags); +} -static Inkscape::XML::Node* -sp_line_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) -{ - SPLine *line = SP_LINE(object); - +Inkscape::XML::Node* SPLine::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:line"); } - if (repr != object->getRepr()) { - repr->mergeFrom(object->getRepr(), "id"); + if (repr != this->getRepr()) { + repr->mergeFrom(this->getRepr(), "id"); } - sp_repr_set_svg_double(repr, "x1", line->x1.computed); - sp_repr_set_svg_double(repr, "y1", line->y1.computed); - sp_repr_set_svg_double(repr, "x2", line->x2.computed); - sp_repr_set_svg_double(repr, "y2", line->y2.computed); + sp_repr_set_svg_double(repr, "x1", this->x1.computed); + sp_repr_set_svg_double(repr, "y1", this->y1.computed); + sp_repr_set_svg_double(repr, "x2", this->x2.computed); + sp_repr_set_svg_double(repr, "y2", this->y2.computed); - if (((SPObjectClass *) (sp_line_parent_class))->write) { - ((SPObjectClass *) (sp_line_parent_class))->write(object, xml_doc, repr, flags); - } + SPShape::write(xml_doc, repr, flags); return repr; } -static gchar* -sp_line_get_description(SPItem * /*item*/) -{ - return g_strdup(_("<b>Line</b>")); +gchar* SPLine::description() { + return g_strdup(_("<b>Line</b>")); } -static void -sp_line_convert_to_guides(SPItem *item) -{ - SPLine *line = SP_LINE(item); +void SPLine::convert_to_guides() { Geom::Point points[2]; + Geom::Affine const i2dt(this->i2dt_affine()); - Geom::Affine const i2dt(item->i2dt_affine()); - - points[0] = Geom::Point(line->x1.computed, line->y1.computed)*i2dt; - points[1] = Geom::Point(line->x2.computed, line->y2.computed)*i2dt; + points[0] = Geom::Point(this->x1.computed, this->y1.computed)*i2dt; + points[1] = Geom::Point(this->x2.computed, this->y2.computed)*i2dt; - SPGuide::createSPGuide(item->document, points[0], points[1]); + SPGuide::createSPGuide(this->document, points[0], points[1]); } -static Geom::Affine -sp_line_set_transform(SPItem *item, Geom::Affine const &xform) -{ - SPLine *line = SP_LINE(item); + +Geom::Affine SPLine::set_transform(Geom::Affine const &transform) { Geom::Point points[2]; - points[0] = Geom::Point(line->x1.computed, line->y1.computed); - points[1] = Geom::Point(line->x2.computed, line->y2.computed); + points[0] = Geom::Point(this->x1.computed, this->y1.computed); + points[1] = Geom::Point(this->x2.computed, this->y2.computed); - points[0] *= xform; - points[1] *= xform; + points[0] *= transform; + points[1] *= transform; - line->x1.computed = points[0][Geom::X]; - line->y1.computed = points[0][Geom::Y]; - line->x2.computed = points[1][Geom::X]; - line->y2.computed = points[1][Geom::Y]; + this->x1.computed = points[0][Geom::X]; + this->y1.computed = points[0][Geom::Y]; + this->x2.computed = points[1][Geom::X]; + this->y2.computed = points[1][Geom::Y]; - item->adjust_stroke(xform.descrim()); + this->adjust_stroke(transform.descrim()); - SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); return Geom::identity(); } -static void -sp_line_set_shape(SPShape *shape) -{ - SPLine *line = SP_LINE(shape); - +void SPLine::set_shape() { SPCurve *c = new SPCurve(); - c->moveto(line->x1.computed, line->y1.computed); - c->lineto(line->x2.computed, line->y2.computed); + c->moveto(this->x1.computed, this->y1.computed); + c->lineto(this->x2.computed, this->y2.computed); - shape->setCurveInsync(c, TRUE); // *_insync does not call update, avoiding infinite recursion when set_shape is called by update - shape->setCurveBeforeLPE(c); + this->setCurveInsync(c, TRUE); // *_insync does not call update, avoiding infinite recursion when set_shape is called by update + this->setCurveBeforeLPE(c); // LPE's cannot be applied to lines. (the result can (generally) not be represented as SPLine) |
