summaryrefslogtreecommitdiffstats
path: root/src/sp-item.cpp
diff options
context:
space:
mode:
authorLiam P. White <inkscapebrony@gmail.com>2014-08-17 14:58:39 +0000
committerLiam P. White <inkscapebrony@gmail.com>2014-08-17 14:58:39 +0000
commit2286e96fb2d97298adf9920902babc522dc80b66 (patch)
tree35063233ff3676c4df7def81bf7a7adc4b235eef /src/sp-item.cpp
parentClone Original -> Fill Between Many (diff)
parentUpdate to trunk r13525 (diff)
downloadinkscape-2286e96fb2d97298adf9920902babc522dc80b66.tar.gz
inkscape-2286e96fb2d97298adf9920902babc522dc80b66.zip
Update to experimental r13483
(bzr r13090.1.105)
Diffstat (limited to 'src/sp-item.cpp')
-rw-r--r--src/sp-item.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/sp-item.cpp b/src/sp-item.cpp
index 0c479f086..c7f4e0902 100644
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
@@ -250,18 +250,25 @@ void SPItem::setExplicitlyHidden(bool val) {
}
/**
- * Sets the transform_center_x and transform_center_y properties to retain the rotation centre
- */
+ * Sets the transform_center_x and transform_center_y properties to retain the rotation center
+*/
void SPItem::setCenter(Geom::Point const &object_centre) {
document->ensureUpToDate();
+ // Copied from DocumentProperties::onDocUnitChange()
+ gdouble viewscale_w = this->document->getWidth().value("px") / this->document->getRoot()->viewBox.width();
+ gdouble viewscale_h = this->document->getHeight().value("px")/ this->document->getRoot()->viewBox.height();
+ gdouble viewscale = std::min(viewscale_h, viewscale_w);
+
// FIXME this is seriously wrong
Geom::OptRect bbox = desktopGeometricBounds();
if (bbox) {
- transform_center_x = object_centre[Geom::X] - bbox->midpoint()[Geom::X];
+ // object centre is document coordinates (i.e. in pixels), so we need to consider the viewbox
+ // to translate to user units; transform_center_x/y is in user units
+ transform_center_x = (object_centre[Geom::X] - bbox->midpoint()[Geom::X])/viewscale;
if (Geom::are_near(transform_center_x, 0)) // rounding error
transform_center_x = 0;
- transform_center_y = object_centre[Geom::Y] - bbox->midpoint()[Geom::Y];
+ transform_center_y = (object_centre[Geom::Y] - bbox->midpoint()[Geom::Y])/viewscale;
if (Geom::are_near(transform_center_y, 0)) // rounding error
transform_center_y = 0;
}
@@ -277,16 +284,25 @@ bool SPItem::isCenterSet() const {
return (transform_center_x != 0 || transform_center_y != 0);
}
+// Get the item's transformation center in document coordinates (i.e. in pixels)
Geom::Point SPItem::getCenter() const {
document->ensureUpToDate();
+ // Copied from DocumentProperties::onDocUnitChange()
+ gdouble viewscale_w = this->document->getWidth().value("px") / this->document->getRoot()->viewBox.width();
+ gdouble viewscale_h = this->document->getHeight().value("px")/ this->document->getRoot()->viewBox.height();
+ gdouble viewscale = std::min(viewscale_h, viewscale_w);
+
// FIXME this is seriously wrong
Geom::OptRect bbox = desktopGeometricBounds();
if (bbox) {
- return bbox->midpoint() + Geom::Point (transform_center_x, transform_center_y);
+ // transform_center_x/y are stored in user units, so we have to take the viewbox into account to translate to document coordinates
+ return bbox->midpoint() + Geom::Point (transform_center_x*viewscale, transform_center_y*viewscale);
+
} else {
return Geom::Point(0, 0); // something's wrong!
}
+
}
void