summaryrefslogtreecommitdiffstats
path: root/src/selection.cpp
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2007-03-11 19:57:07 +0000
committermental <mental@users.sourceforge.net>2007-03-11 19:57:07 +0000
commit58b0e69b7336a8a06c447cf786f73df903120e53 (patch)
tree7b4e064fee2a8813127b3c1f3ee3a68425d8990c /src/selection.cpp
parentAdd ctrl+click to paint bucket to change clicked object's fill and stroke to ... (diff)
downloadinkscape-58b0e69b7336a8a06c447cf786f73df903120e53.tar.gz
inkscape-58b0e69b7336a8a06c447cf786f73df903120e53.zip
Switch selection bounds and center to use NR::Maybe, addressing most of the
recent bbox regressions. (bzr r2604)
Diffstat (limited to 'src/selection.cpp')
-rw-r--r--src/selection.cpp61
1 files changed, 12 insertions, 49 deletions
diff --git a/src/selection.cpp b/src/selection.cpp
index d39086e8c..c6b307c3b 100644
--- a/src/selection.cpp
+++ b/src/selection.cpp
@@ -306,15 +306,11 @@ Inkscape::XML::Node *Selection::singleRepr() {
NRRect *Selection::bounds(NRRect *bbox) const
{
g_return_val_if_fail (bbox != NULL, NULL);
- NR::Rect const b = bounds();
- bbox->x0 = b.min()[NR::X];
- bbox->y0 = b.min()[NR::Y];
- bbox->x1 = b.max()[NR::X];
- bbox->y1 = b.max()[NR::Y];
+ *bbox = NRRect(bounds());
return bbox;
}
-NR::Rect Selection::bounds() const
+NR::Maybe<NR::Rect> Selection::bounds() const
{
GSList const *items = const_cast<Selection *>(this)->itemList();
@@ -322,13 +318,7 @@ NR::Rect Selection::bounds() const
for ( GSList const *i = items ; i != NULL ; i = i->next ) {
bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data)));
}
-
- // TODO: return NR::Maybe<NR::Rect>
- if (bbox) {
- return *bbox;
- } else {
- return NR::Rect(NR::Point(0, 0), NR::Point(0, 0));
- }
+ return bbox;
}
NRRect *Selection::boundsInDocument(NRRect *bbox) const {
@@ -352,32 +342,27 @@ NRRect *Selection::boundsInDocument(NRRect *bbox) const {
return bbox;
}
-NR::Rect Selection::boundsInDocument() const {
+NR::Maybe<NR::Rect> Selection::boundsInDocument() const {
NRRect r;
- NR::Maybe<NR::Rect> rect(boundsInDocument(&r)->upgrade());
- if (rect) {
- return *rect;
- } else {
- // FIXME
- return NR::Rect(NR::Point(0, 0), NR::Point(0, 0));
- }
+ return boundsInDocument(&r)->upgrade();
}
/** Extract the position of the center from the first selected object */
-NR::Point Selection::center() const {
+NR::Maybe<NR::Point> Selection::center() const {
GSList *items = (GSList *) const_cast<Selection *>(this)->itemList();
NR::Point center;
if (items) {
SPItem *first = reinterpret_cast<SPItem*>(g_slist_last(items)->data); // from the first item in selection
if (first->isCenterSet()) { // only if set explicitly
- center = first->getCenter();
- } else {
- center = bounds().midpoint();
+ return first->getCenter();
}
+ }
+ NR::Maybe<NR::Rect> bbox = bounds();
+ if (bbox) {
+ return bounds()->midpoint();
} else {
- center = bounds().midpoint();
+ return NR::Nothing();
}
- return center;
}
/**
@@ -417,28 +402,6 @@ std::vector<NR::Point> Selection::getSnapPointsConvexHull() const {
return pHull;
}
-std::vector<NR::Point> Selection::getBBoxPoints() const {
- GSList const *items = const_cast<Selection *>(this)->itemList();
- std::vector<NR::Point> p;
- for (GSList const *iter = items; iter != NULL; iter = iter->next) {
- NR::Maybe<NR::Rect> b = sp_item_bbox_desktop(SP_ITEM(iter->data));
- if (b) {
- p.push_back(b->min());
- p.push_back(b->max());
- }
- }
-
- return p;
-}
-
-std::vector<NR::Point> Selection::getBBoxPointsOuter() const {
- std::vector<NR::Point> p;
- NR::Rect bbox = bounds();
- p.push_back(bbox.min());
- p.push_back(bbox.max());
- return p;
-}
-
void Selection::_removeObjectDescendants(SPObject *obj) {
GSList *iter, *next;
for ( iter = _objs ; iter ; iter = next ) {