Code

Fix RegisteredWidgets. Due to rev 16265, widgets were no longer initialized. This...
[inkscape.git] / src / sp-rect.cpp
index e286648889273a24710c3390dc08c62b3c334a48..0aaa834f251a3b98bc4a1a7eed0de5d785cc6cab 100644 (file)
@@ -22,6 +22,7 @@
 #include <libnr/nr-matrix-div.h>
 #include <libnr/nr-matrix-fns.h>
 
+#include "document.h"
 #include "attributes.h"
 #include "style.h"
 #include "sp-rect.h"
@@ -42,6 +43,7 @@ static gchar *sp_rect_description(SPItem *item);
 static NR::Matrix sp_rect_set_transform(SPItem *item, NR::Matrix const &xform);
 
 static void sp_rect_set_shape(SPShape *shape);
+static void sp_rect_snappoints(SPItem const *item, SnapPointsIter p);
 
 static SPShapeClass *parent_class;
 
@@ -84,6 +86,7 @@ sp_rect_class_init(SPRectClass *klass)
 
     item_class->description = sp_rect_description;
     item_class->set_transform = sp_rect_set_transform;
+    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;
 }
@@ -210,7 +213,8 @@ sp_rect_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
     SPRect *rect = SP_RECT(object);
 
     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
-        repr = sp_repr_new("svg:rect");
+        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
+        repr = xml_doc->createElement("svg:rect");
     }
 
     sp_repr_set_svg_double(repr, "width", rect->width.computed);
@@ -311,7 +315,7 @@ sp_rect_position_set(SPRect *rect, gdouble x, gdouble y, gdouble width, gdouble
 }
 
 void
-sp_rect_set_rx(SPRect *rect, bool set, gdouble value)
+sp_rect_set_rx(SPRect *rect, gboolean set, gdouble value)
 {
     g_return_if_fail(rect != NULL);
     g_return_if_fail(SP_IS_RECT(rect));
@@ -323,7 +327,7 @@ sp_rect_set_rx(SPRect *rect, bool set, gdouble value)
 }
 
 void
-sp_rect_set_ry(SPRect *rect, bool set, gdouble value)
+sp_rect_set_ry(SPRect *rect, gboolean set, gdouble value)
 {
     g_return_if_fail(rect != NULL);
     g_return_if_fail(SP_IS_RECT(rect));
@@ -549,6 +553,31 @@ sp_rect_get_visible_height(SPRect *rect)
         SP_ITEM(rect)->transform);
 }
 
+/**
+ * Sets the snappoint p to the unrounded corners of the rectangle
+ */
+static void sp_rect_snappoints(SPItem const *item, SnapPointsIter p)
+{
+    /* 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 usefull and really confusing. Instead 
+    we could snap either the real corners, or not snap at all. Bulia Byak opted to snap the real corners,
+    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));
+
+    SPRect *rect = SP_RECT(item);
+
+    NR::Matrix const i2d (sp_item_i2d_affine (item));
+
+    *p = NR::Point(rect->x.computed, rect->y.computed) * i2d;
+    *p = NR::Point(rect->x.computed, rect->y.computed + rect->height.computed) * i2d;
+    *p = NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed) * i2d;
+    *p = NR::Point(rect->x.computed + rect->width.computed, rect->y.computed) * i2d;
+}
+
 /*
   Local Variables:
   mode:c++