Code

Use cursor-tweak-move.xpm for all object modes and cursor-color.xpm
[inkscape.git] / src / sp-item.cpp
index 519ed2a45f79bcbfae4169c7515e362cb7e2f3d2..662dc1cac7370d3007ac135aace282407e0905d5 100644 (file)
@@ -33,6 +33,7 @@
 #include "document.h"
 #include "uri.h"
 #include "inkscape.h"
+#include "desktop.h"
 #include "desktop-handles.h"
 
 #include "style.h"
@@ -46,6 +47,7 @@
 #include "sp-item-rm-unsatisfied-cns.h"
 #include "sp-pattern.h"
 #include "sp-switch.h"
+#include "sp-guide-constraint.h"
 #include "gradient-chemistry.h"
 #include "preferences.h"
 #include "conn-avoid-ref.h"
@@ -88,7 +90,7 @@ static void sp_item_update(SPObject *object, SPCtx *ctx, guint flags);
 static Inkscape::XML::Node *sp_item_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
 
 static gchar *sp_item_private_description(SPItem *item);
-static void sp_item_private_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const *snapprefs);
+static void sp_item_private_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs);
 
 static SPItemView *sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, NRArenaItem *arenaitem);
 static SPItemView *sp_item_view_list_remove(SPItemView *list, SPItemView *view);
@@ -175,6 +177,8 @@ void SPItem::init() {
 
     this->avoidRef = new SPAvoidRef(this);
 
+    new (&this->constraints) std::vector<SPGuideConstraint>();
+
     new (&this->_transformed_signal) sigc::signal<void, Geom::Matrix const *, SPItem *>();
 }
 
@@ -289,6 +293,9 @@ SPItem::setExplicitlyHidden(bool const val) {
  */
 void
 SPItem::setCenter(Geom::Point object_centre) {
+    // for getBounds() to work
+    sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(this));
+
     Geom::OptRect bbox = getBounds(sp_item_i2d_affine(this));
     if (bbox) {
         transform_center_x = object_centre[Geom::X] - bbox->midpoint()[Geom::X];
@@ -311,6 +318,9 @@ bool SPItem::isCenterSet() {
 }
 
 Geom::Point SPItem::getCenter() const {
+    // for getBounds() to work
+    sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(this));
+
     Geom::OptRect bbox = getBounds(sp_item_i2d_affine(this));
     if (bbox) {
         return to_2geom(bbox->midpoint()) + Geom::Point (this->transform_center_x, this->transform_center_y);
@@ -935,7 +945,7 @@ Geom::OptRect sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type)
     return rect;
 }
 
-static void sp_item_private_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const */*snapprefs*/)
+static void sp_item_private_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const */*snapprefs*/)
 {
     /* This will only be called if the derived class doesn't override this.
      * see for example sp_genericellipse_snappoints in sp-ellipse.cpp
@@ -948,15 +958,16 @@ static void sp_item_private_snappoints(SPItem const *item, SnapPointsIter p, Ink
         Geom::Point p1, p2;
         p1 = bbox->min();
         p2 = bbox->max();
-        *p = p1;
-        *p = Geom::Point(p1[Geom::X], p2[Geom::Y]);
-        *p = p2;
-        *p = Geom::Point(p1[Geom::Y], p2[Geom::X]);
+        int type = target ? int(Inkscape::SNAPSOURCE_CONVEX_HULL_CORNER) : int(Inkscape::SNAPSOURCE_CONVEX_HULL_CORNER);
+        p.push_back(std::make_pair(p1, type));
+        p.push_back(std::make_pair(Geom::Point(p1[Geom::X], p2[Geom::Y]), type));
+        p.push_back(std::make_pair(p2, type));
+        p.push_back(std::make_pair(Geom::Point(p1[Geom::Y], p2[Geom::X]), type));
     }
 
 }
 
-void sp_item_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const *snapprefs)
+void sp_item_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs)
 {
     g_assert (item != NULL);
     g_assert (SP_IS_ITEM(item));
@@ -964,12 +975,12 @@ void sp_item_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPref
     // Get the snappoints of the item
     SPItemClass const &item_class = *(SPItemClass const *) G_OBJECT_GET_CLASS(item);
     if (item_class.snappoints) {
-        item_class.snappoints(item, p, snapprefs);
+        item_class.snappoints(item, target, p, snapprefs);
     }
 
     // Get the snappoints at the item's center
     if (snapprefs != NULL && snapprefs->getIncludeItemCenter()) {
-        *p = item->getCenter();
+       p.push_back(std::make_pair(item->getCenter(), target ? int(Inkscape::SNAPTARGET_ROTATION_CENTER) : int(Inkscape::SNAPSOURCE_ROTATION_CENTER)));
     }
 
     // Get the snappoints of clipping paths and mask, if any
@@ -978,19 +989,21 @@ void sp_item_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPref
     clips_and_masks.push_back(SP_OBJECT(item->clip_ref->getObject()));
     clips_and_masks.push_back(SP_OBJECT(item->mask_ref->getObject()));
 
+    SPDesktop *desktop = inkscape_active_desktop();
     for (std::list<SPObject const *>::const_iterator o = clips_and_masks.begin(); o != clips_and_masks.end(); o++) {
         if (*o) {
             // obj is a group object, the children are the actual clippers
             for (SPObject *child = (*o)->children ; child ; child = child->next) {
                 if (SP_IS_ITEM(child)) {
-                    std::vector<Geom::Point> p_clip_or_mask;
+                       SnapPointsWithType p_clip_or_mask;
                     // Please note the recursive call here!
-                    sp_item_snappoints(SP_ITEM(child), SnapPointsIter(p_clip_or_mask), snapprefs);
+                    sp_item_snappoints(SP_ITEM(child), target, p_clip_or_mask, snapprefs);
                     // Take into account the transformation of the item being clipped or masked
-                    for (std::vector<Geom::Point>::const_iterator p_orig = p_clip_or_mask.begin(); p_orig != p_clip_or_mask.end(); p_orig++) {
+                    for (SnapPointsWithType::const_iterator p_orig = p_clip_or_mask.begin(); p_orig != p_clip_or_mask.end(); p_orig++) {
                         // All snappoints are in desktop coordinates, but the item's transformation is
                         // in document coordinates. Hence the awkward construction below
-                        *p = (*p_orig) * matrix_to_desktop (matrix_from_desktop (item->transform, item), item);
+                        Geom::Point pt = desktop->dt2doc((*p_orig).first) * sp_item_i2d_affine(item);
+                        p.push_back(std::make_pair(pt, (*p_orig).second));
                     }
                 }
             }
@@ -1045,8 +1058,14 @@ sp_item_description(SPItem *item)
             g_free (s);
             s = snew;
         }
-        if (SP_OBJECT_STYLE(item) && SP_OBJECT_STYLE(item)->filter.href) {
-            gchar *snew = g_strdup_printf (_("%s; <i>filtered</i>"), s);
+        if (SP_OBJECT_STYLE(item) && SP_OBJECT_STYLE(item)->filter.href && SP_OBJECT_STYLE(item)->filter.href->getObject()) {
+            const gchar *label = SP_OBJECT_STYLE(item)->filter.href->getObject()->label();
+            gchar *snew;
+            if (label) {
+                snew = g_strdup_printf (_("%s; <i>filtered (%s)</i>"), s, label);
+            } else {
+                snew = g_strdup_printf (_("%s; <i>filtered</i>"), s);
+            }
             g_free (s);
             s = snew;
         }
@@ -1557,30 +1576,6 @@ Geom::Matrix sp_item_i2d_affine(SPItem const *item)
     return ret;
 }
 
-/**
- * Converts a matrix \a m into the desktop coords of the \a item.
- * Will become a noop when we eliminate the coordinate flipping.
- */
-Geom::Matrix matrix_to_desktop(Geom::Matrix const m, SPItem const *item)
-{
-    Geom::Matrix const ret(m
-                         * Geom::Translate(0, -sp_document_height(SP_OBJECT_DOCUMENT(item)))
-                         * Geom::Scale(1, -1));
-    return ret;
-}
-
-/**
- * Converts a matrix \a m from the desktop coords of the \a item.
- * Will become a noop when we eliminate the coordinate flipping.
- */
-Geom::Matrix matrix_from_desktop(Geom::Matrix const m, SPItem const *item)
-{
-    Geom::Matrix const ret(Geom::Scale(1, -1)
-                         * Geom::Translate(0, sp_document_height(SP_OBJECT_DOCUMENT(item)))
-                         * m);
-    return ret;
-}
-
 void sp_item_set_i2d_affine(SPItem *item, Geom::Matrix const &i2dt)
 {
     g_return_if_fail( item != NULL );