From 1ab271aaa35acc07f07c88945f461d42dc7352fc Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 23:51:50 +0200 Subject: Added "virtual pad" to SPRect. (bzr r11608.1.13) --- src/sp-rect.cpp | 154 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 107 insertions(+), 47 deletions(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 22a403345..47374605b 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -93,9 +93,22 @@ sp_rect_class_init(SPRectClass *klass) shape_class->set_shape = sp_rect_set_shape; } +CRect::CRect(SPRect* rect) : CShape(rect) { + this->sprect = rect; +} + +CRect::~CRect() { +} + static void -sp_rect_init(SPRect */*rect*/) +sp_rect_init(SPRect *rect) { + rect->crect = new CRect(rect); + rect->cshape = rect->crect; + rect->clpeitem = rect->crect; + rect->citem = rect->crect; + rect->cobject = rect->crect; + /* Initializing to zero is automatic */ /* sp_svg_length_unset(&rect->x, SP_SVG_UNIT_NONE, 0.0, 0.0); */ /* sp_svg_length_unset(&rect->y, SP_SVG_UNIT_NONE, 0.0, 0.0); */ @@ -105,11 +118,10 @@ sp_rect_init(SPRect */*rect*/) /* sp_svg_length_unset(&rect->ry, SP_SVG_UNIT_NONE, 0.0, 0.0); */ } -static void -sp_rect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) parent_class)->build) - ((SPObjectClass *) parent_class)->build(object, document, repr); +void CRect::onBuild(SPDocument* doc, Inkscape::XML::Node* repr) { + SPRect* object = this->sprect; + + CShape::onBuild(doc, repr); object->readAttr( "x" ); object->readAttr( "y" ); @@ -119,10 +131,16 @@ sp_rect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) object->readAttr( "ry" ); } +// CPPIFY: remove static void -sp_rect_set(SPObject *object, unsigned key, gchar const *value) +sp_rect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPRect *rect = SP_RECT(object); + ((SPRect*)object)->crect->onBuild(document, repr); +} + +void CRect::onSet(unsigned key, gchar const *value) { + SPRect* rect = this->sprect; + SPRect* object = rect; /* fixme: We need real error processing some time */ @@ -160,15 +178,21 @@ sp_rect_set(SPObject *object, unsigned key, gchar const *value) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set(object, key, value); + CShape::onSet(key, value); break; } } +// CPPIFY: remove static void -sp_rect_update(SPObject *object, SPCtx *ctx, guint flags) +sp_rect_set(SPObject *object, unsigned key, gchar const *value) { + ((SPRect*)object)->crect->onSet(key, value); +} + +void CRect::onUpdate(SPCtx* ctx, unsigned int flags) { + SPRect* object = this->sprect; + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { SPRect *rect = (SPRect *) object; SPStyle *style = object->style; @@ -187,14 +211,18 @@ sp_rect_update(SPObject *object, SPCtx *ctx, guint flags) flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore } - if (((SPObjectClass *) parent_class)->update) - ((SPObjectClass *) parent_class)->update(object, ctx, flags); + CShape::onUpdate(ctx, flags); } -static Inkscape::XML::Node * -sp_rect_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +// CPPIFY: remove +static void +sp_rect_update(SPObject *object, SPCtx *ctx, guint flags) { - SPRect *rect = SP_RECT(object); + ((SPRect*)object)->crect->onUpdate(ctx, flags); +} + +Inkscape::XML::Node * CRect::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPRect* rect = this->sprect; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:rect"); @@ -207,26 +235,34 @@ sp_rect_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML: sp_repr_set_svg_double(repr, "x", rect->x.computed); sp_repr_set_svg_double(repr, "y", rect->y.computed); - if (((SPObjectClass *) parent_class)->write) - ((SPObjectClass *) parent_class)->write(object, xml_doc, repr, flags); + CShape::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +static Inkscape::XML::Node * +sp_rect_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPRect*)object)->crect->onWrite(xml_doc, repr, flags); +} + +gchar* CRect::onDescription() { + g_return_val_if_fail(SP_IS_RECT(this->sprect), NULL); + return g_strdup(_("Rectangle")); +} + +// CPPIFY: remove static gchar * sp_rect_description(SPItem *item) { - g_return_val_if_fail(SP_IS_RECT(item), NULL); - - return g_strdup(_("Rectangle")); + return ((SPRect*)item)->crect->onDescription(); } #define C1 0.554 -static void -sp_rect_set_shape(SPShape *shape) -{ - SPRect *rect = (SPRect *) shape; +void CRect::onSetShape() { + SPRect *rect = this->sprect; if ((rect->height.computed < 1e-18) || (rect->width.computed < 1e-18)) { SP_SHAPE(rect)->setCurveInsync( NULL, TRUE); @@ -288,6 +324,13 @@ sp_rect_set_shape(SPShape *shape) c->unref(); } +// CPPIFY: remove +static void +sp_rect_set_shape(SPShape *shape) +{ + ((SPRect*)shape)->crect->onSetShape(); +} + /* fixme: Think (Lauris) */ void @@ -328,18 +371,9 @@ sp_rect_set_ry(SPRect *rect, gboolean set, gdouble value) SP_OBJECT(rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -/* - * Initially we'll do: - * Transform x, y, set x, y, clear translation - */ - -/* fixme: Use preferred units somehow (Lauris) */ -/* fixme: Alternately preserve whatever units there are (lauris) */ - -static Geom::Affine -sp_rect_set_transform(SPItem *item, Geom::Affine const &xform) -{ - SPRect *rect = SP_RECT(item); +Geom::Affine CRect::onSetTransform(Geom::Affine const& xform) { + SPRect *rect = this->sprect; + SPRect* item = rect; /* Calculate rect start in parent coords. */ Geom::Point pos( Geom::Point(rect->x.computed, rect->y.computed) * xform ); @@ -395,6 +429,21 @@ sp_rect_set_transform(SPItem *item, Geom::Affine const &xform) return ret; } +/* + * Initially we'll do: + * Transform x, y, set x, y, clear translation + */ + +/* fixme: Use preferred units somehow (Lauris) */ +/* fixme: Alternately preserve whatever units there are (lauris) */ + +// CPPIFY: remove +static Geom::Affine +sp_rect_set_transform(SPItem *item, Geom::Affine const &xform) +{ + return ((SPRect*)item)->crect->onSetTransform(xform); +} + /** Returns the ratio in which the vector from p0 to p1 is stretched by transform @@ -551,11 +600,10 @@ sp_rect_get_visible_height(SPRect *rect) rect->transform); } -/** - * Sets the snappoint p to the unrounded corners of the rectangle - */ -static void sp_rect_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) -{ +void CRect::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPRect *rect = this->sprect; + SPRect* item = rect; + /* This method overrides sp_shape_snappoints, which is the default for any shape. The default method returns all eight points along the path of a rounded rectangle, but not the real corners. Snapping the startpoint and endpoint of each rounded corner is not very useful and really confusing. Instead @@ -566,8 +614,6 @@ static void sp_rect_snappoints(SPItem const *item, std::vectori2dt_affine ()); Geom::Point p0 = Geom::Point(rect->x.computed, rect->y.computed) * i2dt; @@ -592,12 +638,20 @@ static void sp_rect_snappoints(SPItem const *item, std::vectorisTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { p.push_back(Inkscape::SnapCandidatePoint((p0 + p2)/2, Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT)); } +} +// CPPIFY: remove +/** + * Sets the snappoint p to the unrounded corners of the rectangle + */ +static void sp_rect_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) +{ + ((SPRect*)item)->crect->onSnappoints(p, snapprefs); } -void -sp_rect_convert_to_guides(SPItem *item) { - SPRect *rect = SP_RECT(item); +void CRect::onConvertToGuides() { + SPRect* rect = this->sprect; + SPRect* item = rect; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (!prefs->getBool("/tools/shapes/rect/convertguides", true)) { @@ -622,6 +676,12 @@ sp_rect_convert_to_guides(SPItem *item) { sp_guide_pt_pairs_to_guides(item->document, pts); } +// CPPIFY: remove +void +sp_rect_convert_to_guides(SPItem *item) { + ((SPRect*)item)->crect->onConvertToGuides(); +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From 260c7156ca920232cca2e829782373a805d59cae Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 29 Sep 2012 17:43:15 +0200 Subject: Removed old calls to set_shape and update_patheffect. (bzr r11608.1.45) --- src/sp-rect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 47374605b..cf814ccb6 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -90,7 +90,7 @@ sp_rect_class_init(SPRectClass *klass) item_class->convert_to_guides = sp_rect_convert_to_guides; item_class->snappoints = sp_rect_snappoints; //override the default sp_shape_snappoints; see sp_rect_snappoints for details - shape_class->set_shape = sp_rect_set_shape; + //shape_class->set_shape = sp_rect_set_shape; } CRect::CRect(SPRect* rect) : CShape(rect) { -- cgit v1.2.3 From 99cb30e28d4ee193f39e23464abbd7630cac8a2d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 6 Oct 2012 23:56:27 +0200 Subject: Added virtual pad to SPFlowtext; removed old calls to virtual SPItem methods. (bzr r11608.1.46) --- src/sp-rect.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index cf814ccb6..f0363d9a8 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -85,10 +85,10 @@ sp_rect_class_init(SPRectClass *klass) sp_object_class->set = sp_rect_set; sp_object_class->update = sp_rect_update; - item_class->description = sp_rect_description; - item_class->set_transform = sp_rect_set_transform; - item_class->convert_to_guides = sp_rect_convert_to_guides; - item_class->snappoints = sp_rect_snappoints; //override the default sp_shape_snappoints; see sp_rect_snappoints for details +// item_class->description = sp_rect_description; +// item_class->set_transform = sp_rect_set_transform; +// item_class->convert_to_guides = sp_rect_convert_to_guides; +// item_class->snappoints = sp_rect_snappoints; //override the default sp_shape_snappoints; see sp_rect_snappoints for details //shape_class->set_shape = sp_rect_set_shape; } -- cgit v1.2.3 From a0a8d020201e0e38a63d9aa3dce228d7d9e6fb35 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Thu, 14 Mar 2013 12:42:39 +0100 Subject: Various changes. (bzr r11608.1.48) --- src/sp-rect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index f0363d9a8..bc85edac4 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -80,7 +80,7 @@ sp_rect_class_init(SPRectClass *klass) parent_class = (SPShapeClass *)g_type_class_ref(SP_TYPE_SHAPE); - sp_object_class->build = sp_rect_build; + //sp_object_class->build = sp_rect_build; sp_object_class->write = sp_rect_write; sp_object_class->set = sp_rect_set; sp_object_class->update = sp_rect_update; -- cgit v1.2.3 From 957c3e4b7909d42c5a13f1b1dd583f877fc32259 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 00:46:57 +0100 Subject: Removed function pointers from SPObject and subclasses. Added some missing virtual pads for classes that were hidden by preprocessor macros. (bzr r11608.1.55) --- src/sp-rect.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index bc85edac4..6ee5fae6c 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -81,9 +81,9 @@ sp_rect_class_init(SPRectClass *klass) parent_class = (SPShapeClass *)g_type_class_ref(SP_TYPE_SHAPE); //sp_object_class->build = sp_rect_build; - sp_object_class->write = sp_rect_write; - sp_object_class->set = sp_rect_set; - sp_object_class->update = sp_rect_update; +// sp_object_class->write = sp_rect_write; +// sp_object_class->set = sp_rect_set; +// sp_object_class->update = sp_rect_update; // item_class->description = sp_rect_description; // item_class->set_transform = sp_rect_set_transform; -- cgit v1.2.3 From 7df6616da5ea2debb86838366ddf746841549cdb Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 00:56:13 +0100 Subject: Renamed virtual function names. (bzr r11608.1.57) --- src/sp-rect.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 733a067cd..c0da69613 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -65,10 +65,10 @@ sp_rect_init(SPRect *rect) /* sp_svg_length_unset(&rect->ry, SP_SVG_UNIT_NONE, 0.0, 0.0); */ } -void CRect::onBuild(SPDocument* doc, Inkscape::XML::Node* repr) { +void CRect::build(SPDocument* doc, Inkscape::XML::Node* repr) { SPRect* object = this->sprect; - CShape::onBuild(doc, repr); + CShape::build(doc, repr); object->readAttr( "x" ); object->readAttr( "y" ); @@ -78,7 +78,7 @@ void CRect::onBuild(SPDocument* doc, Inkscape::XML::Node* repr) { object->readAttr( "ry" ); } -void CRect::onSet(unsigned key, gchar const *value) { +void CRect::set(unsigned key, gchar const *value) { SPRect* rect = this->sprect; SPRect* object = rect; @@ -118,12 +118,12 @@ void CRect::onSet(unsigned key, gchar const *value) { object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - CShape::onSet(key, value); + CShape::set(key, value); break; } } -void CRect::onUpdate(SPCtx* ctx, unsigned int flags) { +void CRect::update(SPCtx* ctx, unsigned int flags) { SPRect* object = this->sprect; if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { @@ -144,10 +144,10 @@ void CRect::onUpdate(SPCtx* ctx, unsigned int flags) { flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore } - CShape::onUpdate(ctx, flags); + CShape::update(ctx, flags); } -Inkscape::XML::Node * CRect::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { +Inkscape::XML::Node * CRect::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPRect* rect = this->sprect; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { @@ -161,20 +161,20 @@ Inkscape::XML::Node * CRect::onWrite(Inkscape::XML::Document *xml_doc, Inkscape: sp_repr_set_svg_double(repr, "x", rect->x.computed); sp_repr_set_svg_double(repr, "y", rect->y.computed); - this->onSetShape(); // evaluate SPCurve - CShape::onWrite(xml_doc, repr, flags); + this->set_shape(); // evaluate SPCurve + CShape::write(xml_doc, repr, flags); return repr; } -gchar* CRect::onDescription() { +gchar* CRect::description() { g_return_val_if_fail(SP_IS_RECT(this->sprect), NULL); return g_strdup(_("Rectangle")); } #define C1 0.554 -void CRect::onSetShape() { +void CRect::set_shape() { SPRect *rect = this->sprect; if ((rect->height.computed < 1e-18) || (rect->width.computed < 1e-18)) { @@ -277,7 +277,7 @@ sp_rect_set_ry(SPRect *rect, gboolean set, gdouble value) SP_OBJECT(rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -Geom::Affine CRect::onSetTransform(Geom::Affine const& xform) { +Geom::Affine CRect::set_transform(Geom::Affine const& xform) { SPRect *rect = this->sprect; SPRect* item = rect; @@ -319,7 +319,7 @@ Geom::Affine CRect::onSetTransform(Geom::Affine const& xform) { rect->x = pos[Geom::X]; rect->y = pos[Geom::Y]; - this->onSetShape(); + this->set_shape(); // Adjust stroke width item->adjust_stroke(sqrt(fabs(sw * sh))); @@ -491,7 +491,7 @@ sp_rect_get_visible_height(SPRect *rect) rect->transform); } -void CRect::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { +void CRect::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { SPRect *rect = this->sprect; SPRect* item = rect; @@ -531,7 +531,7 @@ void CRect::onSnappoints(std::vector &p, Inkscape: } } -void CRect::onConvertToGuides() { +void CRect::convert_to_guides() { SPRect* rect = this->sprect; SPRect* item = rect; -- cgit v1.2.3 From f51227a487f3d80e096c04470a969f5efa911a98 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 21:49:36 +0100 Subject: Turned all functions concerning SPRect into member functions. (bzr r11608.1.60) --- src/sp-rect.cpp | 232 ++++++++++++++++++++++++++------------------------------ 1 file changed, 107 insertions(+), 125 deletions(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 813a29367..17a03ab19 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -239,42 +239,33 @@ void CRect::set_shape() { /* fixme: Think (Lauris) */ -void -sp_rect_position_set(SPRect *rect, gdouble x, gdouble y, gdouble width, gdouble height) -{ - g_return_if_fail(rect != NULL); - g_return_if_fail(SP_IS_RECT(rect)); - - rect->x.computed = x; - rect->y.computed = y; - rect->width.computed = width; - rect->height.computed = height; +void SPRect::setPosition(gdouble x, gdouble y, gdouble width, gdouble height) { + this->x.computed = x; + this->y.computed = y; + this->width.computed = width; + this->height.computed = height; - SP_OBJECT(rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -void -sp_rect_set_rx(SPRect *rect, gboolean set, gdouble value) -{ - g_return_if_fail(rect != NULL); - g_return_if_fail(SP_IS_RECT(rect)); +void SPRect::setRx(bool set, gdouble value) { + this->rx._set = set; - rect->rx._set = set; - if (set) rect->rx.computed = value; + if (set) { + this->rx.computed = value; + } - SP_OBJECT(rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -void -sp_rect_set_ry(SPRect *rect, gboolean set, gdouble value) -{ - g_return_if_fail(rect != NULL); - g_return_if_fail(SP_IS_RECT(rect)); +void SPRect::setRy(bool set, gdouble value) { + this->ry._set = set; - rect->ry._set = set; - if (set) rect->ry.computed = value; + if (set) { + this->ry.computed = value; + } - SP_OBJECT(rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } Geom::Affine CRect::set_transform(Geom::Affine const& xform) { @@ -339,156 +330,147 @@ Geom::Affine CRect::set_transform(Geom::Affine const& xform) { /** Returns the ratio in which the vector from p0 to p1 is stretched by transform */ -static gdouble -vector_stretch(Geom::Point p0, Geom::Point p1, Geom::Affine xform) -{ - if (p0 == p1) +gdouble SPRect::vectorStretch(Geom::Point p0, Geom::Point p1, Geom::Affine xform) { + if (p0 == p1) { return 0; + } + return (Geom::distance(p0 * xform, p1 * xform) / Geom::distance(p0, p1)); } -void -sp_rect_set_visible_rx(SPRect *rect, gdouble rx) -{ +void SPRect::setVisibleRx(gdouble rx) { if (rx == 0) { - rect->rx.computed = 0; - rect->rx._set = false; + this->rx.computed = 0; + this->rx._set = false; } else { - rect->rx.computed = rx / vector_stretch( - Geom::Point(rect->x.computed + 1, rect->y.computed), - Geom::Point(rect->x.computed, rect->y.computed), - rect->transform); - rect->rx._set = true; + this->rx.computed = rx / SPRect::vectorStretch( + Geom::Point(this->x.computed + 1, this->y.computed), + Geom::Point(this->x.computed, this->y.computed), + this->transform); + this->rx._set = true; } - SP_OBJECT(rect)->updateRepr(); + + this->updateRepr(); } -void -sp_rect_set_visible_ry(SPRect *rect, gdouble ry) -{ +void SPRect::setVisibleRy(gdouble ry) { if (ry == 0) { - rect->ry.computed = 0; - rect->ry._set = false; + this->ry.computed = 0; + this->ry._set = false; } else { - rect->ry.computed = ry / vector_stretch( - Geom::Point(rect->x.computed, rect->y.computed + 1), - Geom::Point(rect->x.computed, rect->y.computed), - rect->transform); - rect->ry._set = true; + this->ry.computed = ry / SPRect::vectorStretch( + Geom::Point(this->x.computed, this->y.computed + 1), + Geom::Point(this->x.computed, this->y.computed), + this->transform); + this->ry._set = true; } - SP_OBJECT(rect)->updateRepr(); + this->updateRepr(); } -gdouble -sp_rect_get_visible_rx(SPRect *rect) -{ - if (!rect->rx._set) +gdouble SPRect::getVisibleRx() const { + if (!this->rx._set) { return 0; - return rect->rx.computed * vector_stretch( - Geom::Point(rect->x.computed + 1, rect->y.computed), - Geom::Point(rect->x.computed, rect->y.computed), - rect->transform); + } + + return this->rx.computed * SPRect::vectorStretch( + Geom::Point(this->x.computed + 1, this->y.computed), + Geom::Point(this->x.computed, this->y.computed), + this->transform); } -gdouble -sp_rect_get_visible_ry(SPRect *rect) -{ - if (!rect->ry._set) +gdouble SPRect::getVisibleRy() const { + if (!this->ry._set) { return 0; - return rect->ry.computed * vector_stretch( - Geom::Point(rect->x.computed, rect->y.computed + 1), - Geom::Point(rect->x.computed, rect->y.computed), - rect->transform); + } + + return this->ry.computed * SPRect::vectorStretch( + Geom::Point(this->x.computed, this->y.computed + 1), + Geom::Point(this->x.computed, this->y.computed), + this->transform); } -Geom::Rect -sp_rect_get_rect (SPRect *rect) -{ - Geom::Point p0 = Geom::Point(rect->x.computed, rect->y.computed); - Geom::Point p2 = Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed); +Geom::Rect SPRect::getRect() const { + Geom::Point p0 = Geom::Point(this->x.computed, this->y.computed); + Geom::Point p2 = Geom::Point(this->x.computed + this->width.computed, this->y.computed + this->height.computed); + return Geom::Rect(p0, p2); } -void -sp_rect_compensate_rxry(SPRect *rect, Geom::Affine xform) -{ - if (rect->rx.computed == 0 && rect->ry.computed == 0) +void SPRect::compensateRxRy(Geom::Affine xform) { + if (this->rx.computed == 0 && this->ry.computed == 0) { return; // nothing to compensate + } // test unit vectors to find out compensation: - Geom::Point c(rect->x.computed, rect->y.computed); + Geom::Point c(this->x.computed, this->y.computed); Geom::Point cx = c + Geom::Point(1, 0); Geom::Point cy = c + Geom::Point(0, 1); // apply previous transform if any - c *= rect->transform; - cx *= rect->transform; - cy *= rect->transform; + c *= this->transform; + cx *= this->transform; + cy *= this->transform; // find out stretches that we need to compensate - gdouble eX = vector_stretch(cx, c, xform); - gdouble eY = vector_stretch(cy, c, xform); + gdouble eX = SPRect::vectorStretch(cx, c, xform); + gdouble eY = SPRect::vectorStretch(cy, c, xform); // If only one of the radii is set, set both radii so they have the same visible length // This is needed because if we just set them the same length in SVG, they might end up unequal because of transform - if ((rect->rx._set && !rect->ry._set) || (rect->ry._set && !rect->rx._set)) { - gdouble r = MAX(rect->rx.computed, rect->ry.computed); - rect->rx.computed = r / eX; - rect->ry.computed = r / eY; + if ((this->rx._set && !this->ry._set) || (this->ry._set && !this->rx._set)) { + gdouble r = MAX(this->rx.computed, this->ry.computed); + this->rx.computed = r / eX; + this->ry.computed = r / eY; } else { - rect->rx.computed = rect->rx.computed / eX; - rect->ry.computed = rect->ry.computed / eY; + this->rx.computed = this->rx.computed / eX; + this->ry.computed = this->ry.computed / eY; } // Note that a radius may end up larger than half-side if the rect is scaled down; // that's ok because this preserves the intended radii in case the rect is enlarged again, // and set_shape will take care of trimming too large radii when generating d= - rect->rx._set = rect->ry._set = true; + this->rx._set = this->ry._set = true; } -void -sp_rect_set_visible_width(SPRect *rect, gdouble width) -{ - rect->width.computed = width / vector_stretch( - Geom::Point(rect->x.computed + 1, rect->y.computed), - Geom::Point(rect->x.computed, rect->y.computed), - rect->transform); - rect->width._set = true; - SP_OBJECT(rect)->updateRepr(); +void SPRect::setVisibleWidth(gdouble width) { + this->width.computed = width / SPRect::vectorStretch( + Geom::Point(this->x.computed + 1, this->y.computed), + Geom::Point(this->x.computed, this->y.computed), + this->transform); + this->width._set = true; + this->updateRepr(); } -void -sp_rect_set_visible_height(SPRect *rect, gdouble height) -{ - rect->height.computed = height / vector_stretch( - Geom::Point(rect->x.computed, rect->y.computed + 1), - Geom::Point(rect->x.computed, rect->y.computed), - rect->transform); - rect->height._set = true; - SP_OBJECT(rect)->updateRepr(); +void SPRect::setVisibleHeight(gdouble height) { + this->height.computed = height / SPRect::vectorStretch( + Geom::Point(this->x.computed, this->y.computed + 1), + Geom::Point(this->x.computed, this->y.computed), + this->transform); + this->height._set = true; + this->updateRepr(); } -gdouble -sp_rect_get_visible_width(SPRect *rect) -{ - if (!rect->width._set) +gdouble SPRect::getVisibleWidth() const { + if (!this->width._set) { return 0; - return rect->width.computed * vector_stretch( - Geom::Point(rect->x.computed + 1, rect->y.computed), - Geom::Point(rect->x.computed, rect->y.computed), - rect->transform); + } + + return this->width.computed * SPRect::vectorStretch( + Geom::Point(this->x.computed + 1, this->y.computed), + Geom::Point(this->x.computed, this->y.computed), + this->transform); } -gdouble -sp_rect_get_visible_height(SPRect *rect) -{ - if (!rect->height._set) +gdouble SPRect::getVisibleHeight() const { + if (!this->height._set) { return 0; - return rect->height.computed * vector_stretch( - Geom::Point(rect->x.computed, rect->y.computed + 1), - Geom::Point(rect->x.computed, rect->y.computed), - rect->transform); + } + + return this->height.computed * SPRect::vectorStretch( + Geom::Point(this->x.computed, this->y.computed + 1), + Geom::Point(this->x.computed, this->y.computed), + this->transform); } void CRect::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { -- cgit v1.2.3 From a5d6e692d661f0bf7648e64e8fcb04588bb8f3ab Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 1 Apr 2013 00:07:00 +0200 Subject: Prepared exchange of casting macros. (bzr r11608.1.63) --- src/sp-rect.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 17a03ab19..7ab9854d4 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -49,6 +49,7 @@ static void sp_rect_init(SPRect *rect) { rect->crect = new CRect(rect); + rect->typeHierarchy.insert(typeid(SPRect)); delete rect->cshape; rect->cshape = rect->crect; -- cgit v1.2.3 From 7504b21ce73f7f2d3787ab5f363b5e5acc721a23 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 1 Apr 2013 23:50:52 +0200 Subject: Added experimental constructor to SPRect. Memory leaks because of non-virtual destructor. (bzr r11608.1.66) --- src/sp-rect.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 7ab9854d4..3d06e8304 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -31,7 +31,7 @@ #define noRECT_VERBOSE -G_DEFINE_TYPE(SPRect, sp_rect, SP_TYPE_SHAPE); +G_DEFINE_TYPE(SPRect, sp_rect, G_TYPE_OBJECT); static void sp_rect_class_init(SPRectClass *klass) @@ -45,9 +45,9 @@ CRect::CRect(SPRect* rect) : CShape(rect) { CRect::~CRect() { } -static void -sp_rect_init(SPRect *rect) -{ +SPRect::SPRect() : SPShape() { + SPRect* rect = this; + rect->crect = new CRect(rect); rect->typeHierarchy.insert(typeid(SPRect)); @@ -66,6 +66,12 @@ sp_rect_init(SPRect *rect) /* sp_svg_length_unset(&rect->ry, SP_SVG_UNIT_NONE, 0.0, 0.0); */ } +static void +sp_rect_init(SPRect *rect) +{ + new (rect) SPRect(); +} + void CRect::build(SPDocument* doc, Inkscape::XML::Node* repr) { SPRect* object = this->sprect; -- cgit v1.2.3 From d1af3566872dfff2aeec84859c87f1f8d13f79df Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 19:14:36 +0200 Subject: Registered classes with new factory. Hkern, Vkern and FeFuncX have to be rewritten, as they aren't real classes. (bzr r11608.1.69) --- src/sp-rect.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 3d06e8304..833e87020 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -31,6 +31,17 @@ #define noRECT_VERBOSE +#include "sp-factory.h" + +namespace { + SPObject* createRect() { + return new SPRect(); + } + + bool rectRegistered = SPFactory::instance().registerObject("svg:rect", createRect); +} + + G_DEFINE_TYPE(SPRect, sp_rect, G_TYPE_OBJECT); static void -- cgit v1.2.3 From 8443720ce6429b9beec839e60b8a808595f4ba72 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 23:01:45 +0200 Subject: Cleaned up a bit. Uses some C++11 features. (bzr r11608.1.72) --- src/sp-rect.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 833e87020..9ba444ca6 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -34,21 +34,10 @@ #include "sp-factory.h" namespace { - SPObject* createRect() { - return new SPRect(); - } - - bool rectRegistered = SPFactory::instance().registerObject("svg:rect", createRect); + bool rectRegistered = SPFactory::instance().registerObject("svg:rect", []() { return new SPRect(); }); } -G_DEFINE_TYPE(SPRect, sp_rect, G_TYPE_OBJECT); - -static void -sp_rect_class_init(SPRectClass *klass) -{ -} - CRect::CRect(SPRect* rect) : CShape(rect) { this->sprect = rect; } @@ -77,12 +66,6 @@ SPRect::SPRect() : SPShape() { /* sp_svg_length_unset(&rect->ry, SP_SVG_UNIT_NONE, 0.0, 0.0); */ } -static void -sp_rect_init(SPRect *rect) -{ - new (rect) SPRect(); -} - void CRect::build(SPDocument* doc, Inkscape::XML::Node* repr) { SPRect* object = this->sprect; -- cgit v1.2.3 From 8fa383d9bfd355a7280c87e4c0a2e48833c6928a Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 23:20:29 +0200 Subject: Combined SPRect and CRect. (bzr r11608.1.73) --- src/sp-rect.cpp | 265 +++++++++++++++++++++++++++----------------------------- 1 file changed, 127 insertions(+), 138 deletions(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 9ba444ca6..aefe2dc8c 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -38,129 +38,123 @@ namespace { } -CRect::CRect(SPRect* rect) : CShape(rect) { - this->sprect = rect; +SPRect::SPRect() : SPShape(), CShape(this) { + delete this->cshape; + this->cshape = this; + this->clpeitem = this; + this->citem = this; + this->cobject = this; } -CRect::~CRect() { +SPRect::~SPRect() { } -SPRect::SPRect() : SPShape() { - SPRect* rect = this; - - rect->crect = new CRect(rect); - rect->typeHierarchy.insert(typeid(SPRect)); - - delete rect->cshape; - rect->cshape = rect->crect; - rect->clpeitem = rect->crect; - rect->citem = rect->crect; - rect->cobject = rect->crect; - - /* Initializing to zero is automatic */ - /* sp_svg_length_unset(&rect->x, SP_SVG_UNIT_NONE, 0.0, 0.0); */ - /* sp_svg_length_unset(&rect->y, SP_SVG_UNIT_NONE, 0.0, 0.0); */ - /* sp_svg_length_unset(&rect->width, SP_SVG_UNIT_NONE, 0.0, 0.0); */ - /* sp_svg_length_unset(&rect->height, SP_SVG_UNIT_NONE, 0.0, 0.0); */ - /* sp_svg_length_unset(&rect->rx, SP_SVG_UNIT_NONE, 0.0, 0.0); */ - /* sp_svg_length_unset(&rect->ry, SP_SVG_UNIT_NONE, 0.0, 0.0); */ -} - -void CRect::build(SPDocument* doc, Inkscape::XML::Node* repr) { - SPRect* object = this->sprect; - +void SPRect::build(SPDocument* doc, Inkscape::XML::Node* repr) { CShape::build(doc, repr); - object->readAttr( "x" ); - object->readAttr( "y" ); - object->readAttr( "width" ); - object->readAttr( "height" ); - object->readAttr( "rx" ); - object->readAttr( "ry" ); + this->readAttr("x"); + this->readAttr("y"); + this->readAttr("width"); + this->readAttr("height"); + this->readAttr("rx"); + this->readAttr("ry"); } -void CRect::set(unsigned key, gchar const *value) { - SPRect* rect = this->sprect; - SPRect* object = rect; - +void SPRect::set(unsigned key, gchar const *value) { /* fixme: We need real error processing some time */ switch (key) { case SP_ATTR_X: - rect->x.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->x.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_Y: - rect->y.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->y.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_WIDTH: - if (!rect->width.read(value) || rect->width.value < 0.0) { - rect->width.unset(); + if (!this->width.read(value) || this->width.value < 0.0) { + this->width.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_HEIGHT: - if (!rect->height.read(value) || rect->height.value < 0.0) { - rect->height.unset(); + if (!this->height.read(value) || this->height.value < 0.0) { + this->height.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_RX: - if (!rect->rx.read(value) || rect->rx.value <= 0.0) { - rect->rx.unset(); + if (!this->rx.read(value) || this->rx.value <= 0.0) { + this->rx.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_RY: - if (!rect->ry.read(value) || rect->ry.value <= 0.0) { - rect->ry.unset(); + if (!this->ry.read(value) || this->ry.value <= 0.0) { + this->ry.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + default: CShape::set(key, value); break; } } -void CRect::update(SPCtx* ctx, unsigned int flags) { - SPRect* object = this->sprect; - +void SPRect::update(SPCtx* ctx, unsigned int flags) { if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - SPRect *rect = (SPRect *) object; - SPStyle *style = object->style; + SPStyle *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 = 0.5 * em; // fixme: get x height from pango or libnrtype. - rect->x.update(em, ex, w); - rect->y.update(em, ex, h); - rect->width.update(em, ex, w); - rect->height.update(em, ex, h); - rect->rx.update(em, ex, w); - rect->ry.update(em, ex, h); - ((SPShape *) object)->setShape(); + + this->x.update(em, ex, w); + this->y.update(em, ex, h); + this->width.update(em, ex, w); + this->height.update(em, ex, h); + this->rx.update(em, ex, w); + this->ry.update(em, ex, h); + this->set_shape(); + flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore } CShape::update(ctx, flags); } -Inkscape::XML::Node * CRect::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPRect* rect = this->sprect; - +Inkscape::XML::Node * SPRect::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:rect"); } - sp_repr_set_svg_double(repr, "width", rect->width.computed); - sp_repr_set_svg_double(repr, "height", rect->height.computed); - if (rect->rx._set) sp_repr_set_svg_double(repr, "rx", rect->rx.computed); - if (rect->ry._set) sp_repr_set_svg_double(repr, "ry", rect->ry.computed); - sp_repr_set_svg_double(repr, "x", rect->x.computed); - sp_repr_set_svg_double(repr, "y", rect->y.computed); + sp_repr_set_svg_double(repr, "width", this->width.computed); + sp_repr_set_svg_double(repr, "height", this->height.computed); + + if (this->rx._set) { + sp_repr_set_svg_double(repr, "rx", this->rx.computed); + } + + if (this->ry._set) { + sp_repr_set_svg_double(repr, "ry", this->ry.computed); + } + + sp_repr_set_svg_double(repr, "x", this->x.computed); + sp_repr_set_svg_double(repr, "y", this->y.computed); this->set_shape(); // evaluate SPCurve CShape::write(xml_doc, repr, flags); @@ -168,42 +162,39 @@ Inkscape::XML::Node * CRect::write(Inkscape::XML::Document *xml_doc, Inkscape::X return repr; } -gchar* CRect::description() { - g_return_val_if_fail(SP_IS_RECT(this->sprect), NULL); +gchar* SPRect::description() { return g_strdup(_("Rectangle")); } #define C1 0.554 -void CRect::set_shape() { - SPRect *rect = this->sprect; - - if ((rect->height.computed < 1e-18) || (rect->width.computed < 1e-18)) { - SP_SHAPE(rect)->setCurveInsync( NULL, TRUE); - SP_SHAPE(rect)->setCurveBeforeLPE( NULL ); +void SPRect::set_shape() { + if ((this->height.computed < 1e-18) || (this->width.computed < 1e-18)) { + this->setCurveInsync( NULL, TRUE); + this->setCurveBeforeLPE( NULL ); return; } SPCurve *c = new SPCurve(); - double const x = rect->x.computed; - double const y = rect->y.computed; - double const w = rect->width.computed; - double const h = rect->height.computed; + double const x = this->x.computed; + double const y = this->y.computed; + double const w = this->width.computed; + double const h = this->height.computed; double const w2 = w / 2; double const h2 = h / 2; - double const rx = std::min(( rect->rx._set - ? rect->rx.computed - : ( rect->ry._set - ? rect->ry.computed + double const rx = std::min(( this->rx._set + ? this->rx.computed + : ( this->ry._set + ? this->ry.computed : 0.0 ) ), - .5 * rect->width.computed); - double const ry = std::min(( rect->ry._set - ? rect->ry.computed - : ( rect->rx._set - ? rect->rx.computed + .5 * this->width.computed); + double const ry = std::min(( this->ry._set + ? this->ry.computed + : ( this->rx._set + ? this->rx.computed : 0.0 ) ), - .5 * rect->height.computed); + .5 * this->height.computed); /* TODO: Handle negative rx or ry as per * http://www.w3.org/TR/SVG11/shapes.html#RectElementRXAttribute once Inkscape has proper error * handling (see http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing). @@ -230,8 +221,8 @@ void CRect::set_shape() { } c->closepath(); - SP_SHAPE(rect)->setCurveInsync( c, TRUE); - SP_SHAPE(rect)->setCurveBeforeLPE( c ); + this->setCurveInsync( c, TRUE); + this->setCurveBeforeLPE( c ); // LPE is not applied because result can generally not be represented as SPRect @@ -269,18 +260,16 @@ void SPRect::setRy(bool set, gdouble value) { this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -Geom::Affine CRect::set_transform(Geom::Affine const& xform) { - SPRect *rect = this->sprect; - SPRect* item = rect; - +Geom::Affine SPRect::set_transform(Geom::Affine const& xform) { /* Calculate rect start in parent coords. */ - Geom::Point pos( Geom::Point(rect->x.computed, rect->y.computed) * xform ); + Geom::Point pos(Geom::Point(this->x.computed, this->y.computed) * xform); /* This function takes care of translation and scaling, we return whatever parts we can't handle. */ Geom::Affine ret(Geom::Affine(xform).withoutTranslation()); gdouble const sw = hypot(ret[0], ret[1]); gdouble const sh = hypot(ret[2], ret[3]); + if (sw > 1e-9) { ret[0] /= sw; ret[1] /= sw; @@ -288,6 +277,7 @@ Geom::Affine CRect::set_transform(Geom::Affine const& xform) { ret[0] = 1.0; ret[1] = 0.0; } + if (sh > 1e-9) { ret[2] /= sh; ret[3] /= sh; @@ -297,32 +287,34 @@ Geom::Affine CRect::set_transform(Geom::Affine const& xform) { } /* fixme: Would be nice to preserve units here */ - rect->width = rect->width.computed * sw; - rect->height = rect->height.computed * sh; - if (rect->rx._set) { - rect->rx = rect->rx.computed * sw; + this->width = this->width.computed * sw; + this->height = this->height.computed * sh; + + if (this->rx._set) { + this->rx = this->rx.computed * sw; } - if (rect->ry._set) { - rect->ry = rect->ry.computed * sh; + + if (this->ry._set) { + this->ry = this->ry.computed * sh; } /* Find start in item coords */ pos = pos * ret.inverse(); - rect->x = pos[Geom::X]; - rect->y = pos[Geom::Y]; + this->x = pos[Geom::X]; + this->y = pos[Geom::Y]; this->set_shape(); // Adjust stroke width - item->adjust_stroke(sqrt(fabs(sw * sh))); + this->adjust_stroke(sqrt(fabs(sw * sh))); // Adjust pattern fill - item->adjust_pattern(xform * ret.inverse()); + this->adjust_pattern(xform * ret.inverse()); // Adjust gradient fill - item->adjust_gradient(xform * ret.inverse()); + this->adjust_gradient(xform * ret.inverse()); - item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); return ret; } @@ -348,6 +340,7 @@ void SPRect::setVisibleRx(gdouble rx) { Geom::Point(this->x.computed + 1, this->y.computed), Geom::Point(this->x.computed, this->y.computed), this->transform); + this->rx._set = true; } @@ -363,8 +356,10 @@ void SPRect::setVisibleRy(gdouble ry) { Geom::Point(this->x.computed, this->y.computed + 1), Geom::Point(this->x.computed, this->y.computed), this->transform); + this->ry._set = true; } + this->updateRepr(); } @@ -439,6 +434,7 @@ void SPRect::setVisibleWidth(gdouble width) { Geom::Point(this->x.computed + 1, this->y.computed), Geom::Point(this->x.computed, this->y.computed), this->transform); + this->width._set = true; this->updateRepr(); } @@ -448,6 +444,7 @@ void SPRect::setVisibleHeight(gdouble height) { Geom::Point(this->x.computed, this->y.computed + 1), Geom::Point(this->x.computed, this->y.computed), this->transform); + this->height._set = true; this->updateRepr(); } @@ -474,10 +471,7 @@ gdouble SPRect::getVisibleHeight() const { this->transform); } -void CRect::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { - SPRect *rect = this->sprect; - SPRect* item = rect; - +void SPRect::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { /* This method overrides sp_shape_snappoints, which is the default for any shape. The default method returns all eight points along the path of a rounded rectangle, but not the real corners. Snapping the startpoint and endpoint of each rounded corner is not very useful and really confusing. Instead @@ -485,15 +479,12 @@ void CRect::snappoints(std::vector &p, Inkscape::S but it should be noted that this might be confusing in some cases with relatively large radii. With small radii though the user will easily understand which point is snapping. */ - g_assert(item != NULL); - g_assert(SP_IS_RECT(item)); - - Geom::Affine const i2dt (item->i2dt_affine ()); + Geom::Affine const i2dt (this->i2dt_affine ()); - Geom::Point p0 = Geom::Point(rect->x.computed, rect->y.computed) * i2dt; - Geom::Point p1 = Geom::Point(rect->x.computed, rect->y.computed + rect->height.computed) * i2dt; - Geom::Point p2 = Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed) * i2dt; - Geom::Point p3 = Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed) * i2dt; + Geom::Point p0 = Geom::Point(this->x.computed, this->y.computed) * i2dt; + Geom::Point p1 = Geom::Point(this->x.computed, this->y.computed + this->height.computed) * i2dt; + Geom::Point p2 = Geom::Point(this->x.computed + this->width.computed, this->y.computed + this->height.computed) * i2dt; + Geom::Point p3 = Geom::Point(this->x.computed + this->width.computed, this->y.computed) * i2dt; if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_RECT_CORNER)) { p.push_back(Inkscape::SnapCandidatePoint(p0, Inkscape::SNAPSOURCE_RECT_CORNER, Inkscape::SNAPTARGET_RECT_CORNER)); @@ -514,31 +505,29 @@ void CRect::snappoints(std::vector &p, Inkscape::S } } -void CRect::convert_to_guides() { - SPRect* rect = this->sprect; - SPRect* item = rect; - +void SPRect::convert_to_guides() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (!prefs->getBool("/tools/shapes/rect/convertguides", true)) { - rect->convert_to_guides(); + this->convert_to_guides(); return; } std::list > pts; - Geom::Affine const i2dt(rect->i2dt_affine()); + Geom::Affine const i2dt(this->i2dt_affine()); - Geom::Point A1(Geom::Point(rect->x.computed, rect->y.computed) * i2dt); - Geom::Point A2(Geom::Point(rect->x.computed, rect->y.computed + rect->height.computed) * i2dt); - Geom::Point A3(Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed) * i2dt); - Geom::Point A4(Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed) * i2dt); + Geom::Point A1(Geom::Point(this->x.computed, this->y.computed) * i2dt); + Geom::Point A2(Geom::Point(this->x.computed, this->y.computed + this->height.computed) * i2dt); + Geom::Point A3(Geom::Point(this->x.computed + this->width.computed, this->y.computed + this->height.computed) * i2dt); + Geom::Point A4(Geom::Point(this->x.computed + this->width.computed, this->y.computed) * i2dt); pts.push_back(std::make_pair(A1, A2)); pts.push_back(std::make_pair(A2, A3)); pts.push_back(std::make_pair(A3, A4)); pts.push_back(std::make_pair(A4, A1)); - sp_guide_pt_pairs_to_guides(item->document, pts); + sp_guide_pt_pairs_to_guides(this->document, pts); } /* -- cgit v1.2.3 From cfe48de7f071e2e07a1f2f2ace3456f7b410e93b Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 15:37:33 +0200 Subject: Merged Shape and subclasses. Cleaned up a bit. (bzr r11608.1.76) --- src/sp-rect.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index aefe2dc8c..6bdfb2c6c 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -38,9 +38,7 @@ namespace { } -SPRect::SPRect() : SPShape(), CShape(this) { - delete this->cshape; - this->cshape = this; +SPRect::SPRect() : SPShape() { this->clpeitem = this; this->citem = this; this->cobject = this; @@ -50,7 +48,7 @@ SPRect::~SPRect() { } void SPRect::build(SPDocument* doc, Inkscape::XML::Node* repr) { - CShape::build(doc, repr); + SPShape::build(doc, repr); this->readAttr("x"); this->readAttr("y"); @@ -107,7 +105,7 @@ void SPRect::set(unsigned key, gchar const *value) { break; default: - CShape::set(key, value); + SPShape::set(key, value); break; } } @@ -134,7 +132,7 @@ void SPRect::update(SPCtx* ctx, unsigned int flags) { flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore } - CShape::update(ctx, flags); + SPShape::update(ctx, flags); } Inkscape::XML::Node * SPRect::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { @@ -157,7 +155,7 @@ Inkscape::XML::Node * SPRect::write(Inkscape::XML::Document *xml_doc, Inkscape:: sp_repr_set_svg_double(repr, "y", this->y.computed); this->set_shape(); // evaluate SPCurve - CShape::write(xml_doc, repr, flags); + SPShape::write(xml_doc, repr, flags); return repr; } -- cgit v1.2.3 From 19d00efa85cfc42ccae9bd17ef575602f0d22c50 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 19:42:32 +0200 Subject: Merged more classes. (bzr r11608.1.78) --- src/sp-rect.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 6bdfb2c6c..ff158974c 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -39,7 +39,6 @@ namespace { SPRect::SPRect() : SPShape() { - this->clpeitem = this; this->citem = this; this->cobject = this; } -- cgit v1.2.3 From 8073924aacdda310fb7492750f78d5389b3186af Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 22:45:01 +0200 Subject: Merged Item. (bzr r11608.1.81) --- src/sp-rect.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index ff158974c..94a92079a 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -39,7 +39,6 @@ namespace { SPRect::SPRect() : SPShape() { - this->citem = this; this->cobject = this; } -- cgit v1.2.3 From 27e2102f96a5554bcd5310ec11435d155773b279 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 7 Apr 2013 18:28:22 +0200 Subject: Merge Object and subclasses. Merging of SP- and C-classes complete. (bzr r11608.1.86) --- src/sp-rect.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 94a92079a..820f05dff 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -39,7 +39,6 @@ namespace { SPRect::SPRect() : SPShape() { - this->cobject = this; } SPRect::~SPRect() { -- cgit v1.2.3 From 1f096398da95ef2c74a89e53c64d9cd75911b6eb Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 10 Apr 2013 20:44:21 +0200 Subject: various little changes (bzr r11608.1.93) --- src/sp-rect.cpp | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 820f05dff..c150267fc 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -34,7 +34,11 @@ #include "sp-factory.h" namespace { - bool rectRegistered = SPFactory::instance().registerObject("svg:rect", []() { return new SPRect(); }); + SPRect* createRect() { + return new SPRect(); + } + + bool rectRegistered = SPFactory::instance().registerObject("svg:rect", createRect); } @@ -200,14 +204,30 @@ void SPRect::set_shape() { */ if ((rx > 1e-18) && (ry > 1e-18)) { c->moveto(x + rx, y); - if (rx < w2) c->lineto(x + w - rx, y); - c->curveto(x + w - rx * (1 - C1), y, x + w, y + ry * (1 - C1), x + w, y + ry); - if (ry < h2) c->lineto(x + w, y + h - ry); - c->curveto(x + w, y + h - ry * (1 - C1), x + w - rx * (1 - C1), y + h, x + w - rx, y + h); - if (rx < w2) c->lineto(x + rx, y + h); - c->curveto(x + rx * (1 - C1), y + h, x, y + h - ry * (1 - C1), x, y + h - ry); - if (ry < h2) c->lineto(x, y + ry); - c->curveto(x, y + ry * (1 - C1), x + rx * (1 - C1), y, x + rx, y); + + if (rx < w2) { + c->lineto(x + w - rx, y); + } + + c->curveto(x + w - rx * (1 - C1), y, x + w, y + ry * (1 - C1), x + w, y + ry); + + if (ry < h2) { + c->lineto(x + w, y + h - ry); + } + + c->curveto(x + w, y + h - ry * (1 - C1), x + w - rx * (1 - C1), y + h, x + w - rx, y + h); + + if (rx < w2) { + c->lineto(x + rx, y + h); + } + + c->curveto(x + rx * (1 - C1), y + h, x, y + h - ry * (1 - C1), x, y + h - ry); + + if (ry < h2) { + c->lineto(x, y + ry); + } + + c->curveto(x, y + ry * (1 - C1), x + rx * (1 - C1), y, x + rx, y); } else { c->moveto(x + 0.0, y + 0.0); c->lineto(x + w, y + 0.0); @@ -216,8 +236,8 @@ void SPRect::set_shape() { } c->closepath(); - this->setCurveInsync( c, TRUE); - this->setCurveBeforeLPE( c ); + this->setCurveInsync(c, true); + this->setCurveBeforeLPE(c); // LPE is not applied because result can generally not be represented as SPRect @@ -504,7 +524,8 @@ void SPRect::convert_to_guides() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (!prefs->getBool("/tools/shapes/rect/convertguides", true)) { - this->convert_to_guides(); + // Use bounding box instead of edges + SPShape::convert_to_guides(); return; } -- cgit v1.2.3 From fbb85064cfaaf03cc09bacedb16a8561f61f2b3d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 13 Apr 2013 00:37:18 +0200 Subject: Added prefPaths to contexts; modified SPFactory (bzr r11608.1.94) --- src/sp-rect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index c150267fc..d16f16a9b 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -34,7 +34,7 @@ #include "sp-factory.h" namespace { - SPRect* createRect() { + SPObject* createRect() { return new SPRect(); } -- cgit v1.2.3 From 9b2956fbaefb4e12bad3fc359c47e5923f33bb41 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 28 Apr 2013 00:05:16 +0200 Subject: various changes (bzr r11608.1.105) --- src/sp-rect.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/sp-rect.cpp') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index d16f16a9b..519b7ba6e 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -113,8 +113,6 @@ void SPRect::set(unsigned key, gchar const *value) { void SPRect::update(SPCtx* ctx, unsigned int flags) { if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - SPStyle *style = this->style; - SPItemCtx const *ictx = (SPItemCtx const *) ctx; double const w = ictx->viewport.width(); -- cgit v1.2.3