diff options
Diffstat (limited to 'src/sp-line.cpp')
| -rw-r--r-- | src/sp-line.cpp | 311 |
1 files changed, 150 insertions, 161 deletions
diff --git a/src/sp-line.cpp b/src/sp-line.cpp index d0ce32397..b8c5a19b7 100644 --- a/src/sp-line.cpp +++ b/src/sp-line.cpp @@ -1,10 +1,10 @@ -#define __SP_LINE_C__ - /* * SVG <line> implementation * * Authors: * Lauris Kaplinski <lauris@kaplinski.com> + * Abhishek Sharma + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 1999-2002 Lauris Kaplinski * @@ -25,224 +25,213 @@ #include "document.h" #include "inkscape.h" -static void sp_line_class_init (SPLineClass *klass); -static void sp_line_init (SPLine *line); - -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 gchar *sp_line_description (SPItem * item); -static Geom::Matrix sp_line_set_transform(SPItem *item, Geom::Matrix const &xform); - -static void sp_line_update (SPObject *object, SPCtx *ctx, guint flags); -static void sp_line_set_shape (SPShape *shape); -static void sp_line_convert_to_guides(SPItem *item); +SPShapeClass * SPLineClass::static_parent_class = 0; -static SPShapeClass *parent_class; - -GType -sp_line_get_type (void) +GType SPLine::sp_line_get_type(void) { - static GType line_type = 0; - - if (!line_type) { - GTypeInfo line_info = { - sizeof (SPLineClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_line_class_init, - NULL, /* klass_finalize */ - NULL, /* klass_data */ - sizeof (SPLine), - 16, /* n_preallocs */ - (GInstanceInitFunc) sp_line_init, - NULL, /* value_table */ - }; - line_type = g_type_register_static (SP_TYPE_SHAPE, "SPLine", &line_info, (GTypeFlags)0); - } - return line_type; + static GType line_type = 0; + + if (!line_type) { + GTypeInfo line_info = { + sizeof(SPLineClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) SPLineClass::sp_line_class_init, + NULL, /* klass_finalize */ + NULL, /* klass_data */ + sizeof(SPLine), + 16, /* n_preallocs */ + (GInstanceInitFunc) init, + NULL, /* value_table */ + }; + line_type = g_type_register_static(SP_TYPE_SHAPE, "SPLine", &line_info,(GTypeFlags)0); + } + return line_type; } -static void -sp_line_class_init (SPLineClass *klass) +void SPLineClass::sp_line_class_init(SPLineClass *klass) { - parent_class = (SPShapeClass *) g_type_class_ref (SP_TYPE_SHAPE); + SPLineClass::static_parent_class = (SPShapeClass *) g_type_class_ref(SP_TYPE_SHAPE); - SPObjectClass *sp_object_class = (SPObjectClass *) klass; - sp_object_class->build = sp_line_build; - sp_object_class->set = sp_line_set; - sp_object_class->write = sp_line_write; + SPObjectClass *sp_object_class = (SPObjectClass *) klass; + sp_object_class->build = SPLine::build; + sp_object_class->set = SPLine::set; + sp_object_class->write = SPLine::write; - SPItemClass *item_class = (SPItemClass *) klass; - item_class->description = sp_line_description; - item_class->set_transform = sp_line_set_transform; - item_class->convert_to_guides = sp_line_convert_to_guides; + SPItemClass *item_class = (SPItemClass *) klass; + item_class->description = SPLine::getDescription; + item_class->set_transform = SPLine::setTransform; + item_class->convert_to_guides = SPLine::convertToGuides; - sp_object_class->update = sp_line_update; + sp_object_class->update = SPLine::update; - SPShapeClass *shape_class = (SPShapeClass *) klass; - shape_class->set_shape = sp_line_set_shape; + SPShapeClass *shape_class = (SPShapeClass *) klass; + shape_class->set_shape = SPLine::setShape; } -static void -sp_line_init (SPLine * line) +void SPLine::init(SPLine * line) { - line->x1.unset(); - line->y1.unset(); - line->x2.unset(); - line->y2.unset(); + line->x1.unset(); + line->y1.unset(); + line->x2.unset(); + line->y2.unset(); } -static void -sp_line_build (SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) +void SPLine::build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) { - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build (object, document, repr); - } - - sp_object_read_attr (object, "x1"); - sp_object_read_attr (object, "y1"); - sp_object_read_attr (object, "x2"); - sp_object_read_attr (object, "y2"); + if (((SPObjectClass *) SPLineClass::static_parent_class)->build) { + ((SPObjectClass *) SPLineClass::static_parent_class)->build(object, document, repr); + } + + object->readAttr( "x1" ); + object->readAttr( "y1" ); + object->readAttr( "x2" ); + object->readAttr( "y2" ); } -static void -sp_line_set (SPObject *object, unsigned int key, const gchar *value) +void SPLine::set(SPObject *object, unsigned int key, const gchar *value) { - SPLine * line = SP_LINE (object); - - /* fixme: we should really collect updates */ - - switch (key) { - case SP_ATTR_X1: - line->x1.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - case SP_ATTR_Y1: - line->y1.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - case SP_ATTR_X2: - line->x2.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - case SP_ATTR_Y2: - line->y2.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set (object, key, value); - break; - } + SPLine * line = SP_LINE(object); + + /* fixme: we should really collect updates */ + + switch (key) { + case SP_ATTR_X1: + line->x1.readOrUnset(value); + object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_Y1: + line->y1.readOrUnset(value); + object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_X2: + line->x2.readOrUnset(value); + object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_Y2: + line->y2.readOrUnset(value); + object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + default: + if (((SPObjectClass *) SPLineClass::static_parent_class)->set) { + ((SPObjectClass *) SPLineClass::static_parent_class)->set(object, key, value); + } + break; + } } -static void -sp_line_update (SPObject *object, SPCtx *ctx, guint flags) +void SPLine::update(SPObject *object, 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); + 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 = object->style; SPItemCtx const *ictx = (SPItemCtx const *) ctx; double const w = (ictx->vp.x1 - ictx->vp.x0); double const h = (ictx->vp.y1 - ictx->vp.y0); - 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); - - sp_shape_set_shape ((SPShape *) object); - } - - if (((SPObjectClass *) parent_class)->update) - ((SPObjectClass *) parent_class)->update (object, ctx, flags); + 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(); + } + + if (((SPObjectClass *) SPLineClass::static_parent_class)->update) { + ((SPObjectClass *) SPLineClass::static_parent_class)->update(object, ctx, flags); + } } -static Inkscape::XML::Node * -sp_line_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +Inkscape::XML::Node * SPLine::write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPLine *line = SP_LINE (object); + SPLine *line = SP_LINE(object); - if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - repr = xml_doc->createElement("svg:line"); - } + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { + repr = xml_doc->createElement("svg:line"); + } - if (repr != SP_OBJECT_REPR (object)) { - repr->mergeFrom(SP_OBJECT_REPR (object), "id"); - } + if (repr != object->getRepr()) { + repr->mergeFrom(object->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", 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); - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags); + if (((SPObjectClass *) (SPLineClass::static_parent_class))->write) { + ((SPObjectClass *) (SPLineClass::static_parent_class))->write(object, xml_doc, repr, flags); + } - return repr; + return repr; } -static gchar * -sp_line_description(SPItem */*item*/) +gchar * SPLine::getDescription(SPItem */*item*/) { return g_strdup(_("<b>Line</b>")); } -static void -sp_line_convert_to_guides(SPItem *item) +void SPLine::convertToGuides(SPItem *item) { - SPLine *line = SP_LINE(item); - Geom::Point points[2]; + SPLine *line = SP_LINE(item); + Geom::Point points[2]; - Geom::Matrix const i2d (sp_item_i2d_affine(item)); + Geom::Matrix const i2d(item->i2d_affine()); - points[0] = Geom::Point(line->x1.computed, line->y1.computed)*i2d; - points[1] = Geom::Point(line->x2.computed, line->y2.computed)*i2d; + points[0] = Geom::Point(line->x1.computed, line->y1.computed)*i2d; + points[1] = Geom::Point(line->x2.computed, line->y2.computed)*i2d; - sp_guide_create(inkscape_active_desktop(), points[0], points[1]); + SPGuide::createSPGuide(inkscape_active_desktop(), points[0], points[1]); } -static Geom::Matrix -sp_line_set_transform (SPItem *item, Geom::Matrix const &xform) +Geom::Matrix SPLine::setTransform(SPItem *item, Geom::Matrix const &xform) { - SPLine *line = SP_LINE (item); - Geom::Point points[2]; + SPLine *line = SP_LINE(item); + 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(line->x1.computed, line->y1.computed); + points[1] = Geom::Point(line->x2.computed, line->y2.computed); - points[0] *= xform; - points[1] *= xform; + points[0] *= xform; + points[1] *= xform; - 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]; + 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]; - sp_item_adjust_stroke(item, xform.descrim()); + item->adjust_stroke(xform.descrim()); - SP_OBJECT (item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); + SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); - return Geom::identity(); + return Geom::identity(); } -static void -sp_line_set_shape (SPShape *shape) +void SPLine::setShape(SPShape *shape) { - SPLine *line = SP_LINE (shape); + SPLine *line = SP_LINE(shape); - SPCurve *c = new SPCurve (); + SPCurve *c = new SPCurve(); - c->moveto(line->x1.computed, line->y1.computed); - c->lineto(line->x2.computed, line->y2.computed); + c->moveto(line->x1.computed, line->y1.computed); + c->lineto(line->x2.computed, line->y2.computed); - sp_shape_set_curve_insync (shape, c, TRUE); // *_insync does not call update, avoiding infinite recursion when set_shape is called by update + shape->setCurveInsync(c, TRUE); // *_insync does not call update, avoiding infinite recursion when set_shape is called by update - c->unref(); + c->unref(); } + +/* + 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:fileencoding=utf-8:textwidth=99 : |
