Code

remove many unnecessary to_2geom and from_2geom calls
[inkscape.git] / src / dialogs / clonetiler.cpp
index 105a24f287d7355adb69c20b4f0533e712574ea1..048635bb97cca014489778b7cc5aa2e08f3ebacc 100644 (file)
@@ -68,7 +68,7 @@ static win_data wd;
 
 // impossible original values to make sure they are read from prefs
 static gint x = -1000, y = -1000, w = 0, h = 0;
-static gchar *prefs_path = "dialogs.clonetiler";
+static gchar const *prefs_path = "dialogs.clonetiler";
 
 #define SB_MARGIN 1
 #define VB_MARGIN 4
@@ -652,7 +652,7 @@ clonetiler_get_transform (
         NR::Matrix dia3;
         NR::Matrix dia4;
         if (w > h) {
-            ori = NR::Matrix(NR::translate (w * pow((i/6) + 1/2 * (j%2), shiftx_exp) + dx,  (w * cos30) * pow(j, shifty_exp) + dy));
+            ori = NR::Matrix(NR::translate (w * pow((i/6) + 0.5*(j%2), shiftx_exp) + dx,  (w * cos30) * pow(j, shifty_exp) + dy));
             dia1 = NR::Matrix (NR::translate (0, h/2) * NR::translate (w/2, 0) * NR::translate (w/2 * cos60, -w/2 * sin60) * NR::translate (-h/2 * cos30, -h/2 * sin30) );
             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
             dia3 = dia2 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
@@ -664,17 +664,17 @@ clonetiler_get_transform (
             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
         }
-        if (x % 6 == 0) {
+        if (i % 6 == 0) {
             return d_s_r * ori;
-        } else if (x % 6 == 1) {
+        } else if (i % 6 == 1) {
             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
-        } else if (x % 6 == 2) {
+        } else if (i % 6 == 2) {
             return d_s_r * rotate_m120_c * dia2 * ori;
-        } else if (x % 6 == 3) {
+        } else if (i % 6 == 3) {
             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
-        } else if (x % 6 == 4) {
+        } else if (i % 6 == 4) {
             return d_s_r * rotate_120_c * dia4 * ori;
-        } else if (x % 6 == 5) {
+        } else if (i % 6 == 5) {
             return d_s_r * flip_y * NR::translate(0, h) * ori;
         }
     }
@@ -703,18 +703,18 @@ clonetiler_get_transform (
             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
         }
-        NR::Matrix ori (NR::translate (width * pow((2*(i/6) + j%2), shiftx_exp) + dx,  (height/2) * pow(i, shifty_exp) + dy));
-        if (x % 6 == 0) {
+        NR::Matrix ori (NR::translate (width * pow((2*(i/6) + j%2), shiftx_exp) + dx,  (height/2) * pow(j, shifty_exp) + dy));
+        if (i % 6 == 0) {
             return d_s_r * ori;
-        } else if (x % 6 == 1) {
+        } else if (i % 6 == 1) {
             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
-        } else if (x % 6 == 2) {
+        } else if (i % 6 == 2) {
             return d_s_r * rotate_m120_c * dia2 * ori;
-        } else if (x % 6 == 3) {
+        } else if (i % 6 == 3) {
             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
-        } else if (x % 6 == 4) {
+        } else if (i % 6 == 4) {
             return d_s_r * rotate_120_c * dia4 * ori;
-        } else if (x % 6 == 5) {
+        } else if (i % 6 == 5) {
             return d_s_r * flip_y * NR::translate(0, h) * ori;
         }
     }
@@ -743,17 +743,17 @@ clonetiler_get_transform (
             dia4 = dia3 * dia1.inverse();
             dia5 = dia3 * dia2.inverse();
         }
-        if (x % 6 == 0) {
+        if (i % 6 == 0) {
             return d_s_r * ori;
-        } else if (x % 6 == 1) {
+        } else if (i % 6 == 1) {
             return d_s_r * rotate_m60_c * dia1 * ori;
-        } else if (x % 6 == 2) {
+        } else if (i % 6 == 2) {
             return d_s_r * rotate_m120_c * dia2 * ori;
-        } else if (x % 6 == 3) {
+        } else if (i % 6 == 3) {
             return d_s_r * rotate_180_c * dia3 * ori;
-        } else if (x % 6 == 4) {
+        } else if (i % 6 == 4) {
             return d_s_r * rotate_120_c * dia4 * ori;
-        } else if (x % 6 == 5) {
+        } else if (i % 6 == 5) {
             return d_s_r * rotate_60_c * dia5 * ori;
         }
     }
@@ -777,7 +777,7 @@ clonetiler_get_transform (
             dia9 = dia6 * dia3.inverse();
             dia10 = dia6 * dia4.inverse();
         } else {
-            ori = NR::Matrix(NR::translate (4*h * cos30 * pow((i/12 + 0.5*(j%2)), shiftx_exp) + dx,  (2*h  + 2*h * sin30) * pow(y, shifty_exp) + dy));
+            ori = NR::Matrix(NR::translate (4*h * cos30 * pow((i/12 + 0.5*(j%2)), shiftx_exp) + dx,  (2*h  + 2*h * sin30) * pow(j, shifty_exp) + dy));
             dia1 = NR::Matrix (NR::translate (-w/2, -h/2) * NR::translate (h/2 * cos30, -h/2 * sin30) * NR::translate (w/2 * cos60, w/2 * sin60));
             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, -h * sin30));
             dia3 = dia2 * NR::Matrix (NR::translate (-w/2 * cos60, -w/2 * sin60) * NR::translate (h * cos30, 0) * NR::translate (-w/2 * cos60, w/2 * sin60));
@@ -789,29 +789,29 @@ clonetiler_get_transform (
             dia9 = dia6 * dia3.inverse();
             dia10 = dia6 * dia4.inverse();
         }
-        if (x % 12 == 0) {
+        if (i % 12 == 0) {
             return d_s_r * ori;
-        } else if (x % 12 == 1) {
+        } else if (i % 12 == 1) {
             return d_s_r * flip_y * rotate_m60_c * dia1 * ori;
-        } else if (x % 12 == 2) {
+        } else if (i % 12 == 2) {
             return d_s_r * rotate_m60_c * dia2 * ori;
-        } else if (x % 12 == 3) {
+        } else if (i % 12 == 3) {
             return d_s_r * flip_y * rotate_m120_c * dia3 * ori;
-        } else if (x % 12 == 4) {
+        } else if (i % 12 == 4) {
             return d_s_r * rotate_m120_c * dia4 * ori;
-        } else if (x % 12 == 5) {
+        } else if (i % 12 == 5) {
             return d_s_r * flip_x * dia5 * ori;
-        } else if (x % 12 == 6) {
+        } else if (i % 12 == 6) {
             return d_s_r * flip_x * flip_y * dia6 * ori;
-        } else if (x % 12 == 7) {
+        } else if (i % 12 == 7) {
             return d_s_r * flip_y * rotate_120_c * dia7 * ori;
-        } else if (x % 12 == 8) {
+        } else if (i % 12 == 8) {
             return d_s_r * rotate_120_c * dia8 * ori;
-        } else if (x % 12 == 9) {
+        } else if (i % 12 == 9) {
             return d_s_r * flip_y * rotate_60_c * dia9 * ori;
-        } else if (x % 12 == 10) {
+        } else if (i % 12 == 10) {
             return d_s_r * rotate_60_c * dia10 * ori;
-        } else if (x % 12 == 11) {
+        } else if (i % 12 == 11) {
             return d_s_r * flip_y * NR::translate (0, h) * ori;
         }
     }
@@ -893,11 +893,10 @@ clonetiler_trace_pick (NR::Rect box)
     if (!trace_arena)
         return 0;
 
-    NRMatrix t;
-    nr_matrix_set_scale(&t, trace_zoom, trace_zoom);
+    NR::Matrix t(NR::scale(trace_zoom, trace_zoom));
     nr_arena_item_set_transform(trace_root, &t);
     NRGC gc(NULL);
-    nr_matrix_set_identity(&gc.transform);
+    gc.transform.set_identity();
     nr_arena_item_invoke_update( trace_root, NULL, &gc,
                                  NR_ARENA_ITEM_STATE_ALL,
                                  NR_ARENA_ITEM_STATE_NONE );
@@ -1113,6 +1112,15 @@ clonetiler_apply( GtkWidget */*widget*/, void * )
         return;
     }
 
+    // set "busy" cursor
+    desktop->setWaitingCursor();
+
+    // set statusbar text
+    GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
+    gtk_label_set_markup (GTK_LABEL(status), _("<small>Creating tiled clones...</small>"));
+    gtk_widget_queue_draw(GTK_WIDGET(status));
+    gdk_window_process_all_updates();
+
     SPObject *obj = SP_OBJECT(selection->singleItem());
     Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
     const char *id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
@@ -1120,10 +1128,10 @@ clonetiler_apply( GtkWidget */*widget*/, void * )
 
     clonetiler_remove (NULL, NULL, false);
 
-    double shiftx_per_i = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shiftx_per_i", 0, -100, 1000);
-    double shifty_per_i = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shifty_per_i", 0, -100, 1000);
-    double shiftx_per_j = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shiftx_per_j", 0, -100, 1000);
-    double shifty_per_j = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shifty_per_j", 0, -100, 1000);
+    double shiftx_per_i = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shiftx_per_i", 0, -10000, 10000);
+    double shifty_per_i = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shifty_per_i", 0, -10000, 10000);
+    double shiftx_per_j = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shiftx_per_j", 0, -10000, 10000);
+    double shifty_per_j = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shifty_per_j", 0, -10000, 10000);
     double shiftx_rand  = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shiftx_rand", 0, 0, 1000);
     double shifty_rand  = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shifty_rand", 0, 0, 1000);
     double shiftx_exp   =        prefs_get_double_attribute_limited (prefs_path, "shiftx_exp",   1, 0, 10);
@@ -1231,13 +1239,11 @@ clonetiler_apply( GtkWidget */*widget*/, void * )
         x0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-x0", 0);
         y0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-y0", 0);
     } else {
-        NR::Maybe<NR::Rect> r = SP_ITEM(obj)->getBounds(sp_item_i2doc_affine(SP_ITEM(obj)),
-                                                        SPItem::GEOMETRIC_BBOX);
-        /* impl: Use of GEOMETRIC_BBOX is so that the stroke of rectangles will be shared
-         * (overlapped) rather than effectively doubled in width.
-         *
-         * (If you wish to change this, then please consider discussing at bug #1722238.) */
-
+        int prefs_bbox = prefs_get_int_attribute("tools", "bounding_box", 0);
+        SPItem::BBoxType bbox_type = (prefs_bbox ==0)? 
+            SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
+        boost::optional<NR::Rect> r = SP_ITEM(obj)->getBounds(sp_item_i2doc_affine(SP_ITEM(obj)),
+                                                        bbox_type);
         if (r) {
             w = r->dimensions()[NR::X];
             h = r->dimensions()[NR::Y];
@@ -1481,12 +1487,15 @@ clonetiler_apply( GtkWidget */*widget*/, void * )
 
             if (blur > 0.0) {
                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
-                double perimeter = perimeter_original * t.expansion();
+                double perimeter = perimeter_original * NR::expansion(t);
                 double radius = blur * perimeter;
+                // this is necessary for all newly added clones to have correct bboxes,
+                // otherwise filters won't work:
+                sp_document_ensure_up_to_date(sp_desktop_document(desktop));
                 // it's hard to figure out exact width/height of the tile without having an object
                 // that we can take bbox of; however here we only need a lower bound so that blur
                 // margins are not too small, and the perimeter should work
-                SPFilter *constructed = new_filter_gaussian_blur(sp_desktop_document(desktop), radius, t.expansion(), t.expansionX(), t.expansionY(), perimeter, perimeter);
+                SPFilter *constructed = new_filter_gaussian_blur(sp_desktop_document(desktop), radius, NR::expansion(t), NR::expansionX(t), NR::expansionY(t), perimeter, perimeter);
                 sp_style_set_property_url (clone_object, "filter", SP_OBJECT(constructed), false);
             }
 
@@ -1510,6 +1519,8 @@ clonetiler_apply( GtkWidget */*widget*/, void * )
 
     clonetiler_change_selection (NULL, selection, dlg);
 
+    desktop->clearWaitingCursor();
+
     sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER,
                      _("Create tiled clones"));
 }
@@ -1953,7 +1964,7 @@ clonetiler_dialog (void)
                 GtkWidget *l = clonetiler_spinbox (tt,
                     // xgettext:no-c-format
                                                    _("Horizontal shift per row (in % of tile width)"), "shiftx_per_j",
-                                                   -100, 1000, "%");
+                                                   -10000, 10000, "%");
                 clonetiler_table_attach (table, l, 0, 2, 2);
             }
 
@@ -1961,7 +1972,7 @@ clonetiler_dialog (void)
                 GtkWidget *l = clonetiler_spinbox (tt,
                     // xgettext:no-c-format
                                                    _("Horizontal shift per column (in % of tile width)"), "shiftx_per_i",
-                                                   -100, 1000, "%");
+                                                   -10000, 10000, "%");
                 clonetiler_table_attach (table, l, 0, 2, 3);
             }
 
@@ -1986,7 +1997,7 @@ clonetiler_dialog (void)
                 GtkWidget *l = clonetiler_spinbox (tt,
                     // xgettext:no-c-format
                                                    _("Vertical shift per row (in % of tile height)"), "shifty_per_j",
-                                                   -100, 1000, "%");
+                                                   -10000, 10000, "%");
                 clonetiler_table_attach (table, l, 0, 3, 2);
             }
 
@@ -1994,7 +2005,7 @@ clonetiler_dialog (void)
                 GtkWidget *l = clonetiler_spinbox (tt,
                     // xgettext:no-c-format
                                                    _("Vertical shift per column (in % of tile height)"), "shifty_per_i",
-                                                   -100, 1000, "%");
+                                                   -10000, 10000, "%");
                 clonetiler_table_attach (table, l, 0, 3, 3);
             }