Code

more 2geomification
[inkscape.git] / src / dialogs / clonetiler.cpp
1 /** @file
2  * Clone tiling dialog
3  */
4 /* Authors:
5  *   bulia byak <buliabyak@users.sf.net>
6  *   Johan Engelen <goejendaagh@zonnet.nl>
7  *
8  * Copyright (C) 2004-2006 Authors
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #ifdef HAVE_CONFIG_H
13 # include "config.h"
14 #endif
15 #include <glib/gmem.h>
16 #include <gtk/gtk.h>
17 #include <glibmm/i18n.h>
19 #include "application/application.h"
20 #include "application/editor.h"
21 #include "helper/window.h"
22 #include "helper/unit-menu.h"
23 #include "helper/units.h"
24 #include "widgets/icon.h"
25 #include "../inkscape.h"
26 #include "preferences.h"
27 #include "dialog-events.h"
28 #include "../macros.h"
29 #include "../verbs.h"
30 #include "../interface.h"
31 #include "../selection.h"
32 #include "../style.h"
33 #include "../desktop.h"
34 #include "../desktop-handles.h"
35 #include "../sp-namedview.h"
36 #include "../document.h"
37 #include "../message-stack.h"
38 #include "../sp-use.h"
39 #include "unclump.h"
41 #include "xml/repr.h"
43 #include "svg/svg.h"
44 #include "svg/svg-color.h"
46 #include "libnr/nr-matrix-fns.h"
47 #include "libnr/nr-matrix-ops.h"
49 #include "libnr/nr-matrix-translate-ops.h"
50 #include "libnr/nr-translate-ops.h"
51 #include "libnr/nr-translate-rotate-ops.h"
52 #include "libnr/nr-translate-scale-ops.h"
54 #include "display/nr-arena.h"
55 #include "display/nr-arena-item.h"
57 #include "ui/widget/color-picker.h"
59 #include "../sp-filter.h"
60 #include "../filter-chemistry.h"
62 #define MIN_ONSCREEN_DISTANCE 50
64 static GtkWidget *dlg = NULL;
65 static win_data wd;
67 // impossible original values to make sure they are read from prefs
68 static gint x = -1000, y = -1000, w = 0, h = 0;
69 static Glib::ustring const prefs_path = "/dialogs/clonetiler/";
71 #define SB_MARGIN 1
72 #define VB_MARGIN 4
74 enum {
75     PICK_COLOR,
76     PICK_OPACITY,
77     PICK_R,
78     PICK_G,
79     PICK_B,
80     PICK_H,
81     PICK_S,
82     PICK_L
83 };
85 static GtkSizeGroup* table_row_labels = NULL;
87 static sigc::connection _shutdown_connection;
88 static sigc::connection _dialogs_hidden_connection;
89 static sigc::connection _dialogs_unhidden_connection;
90 static sigc::connection _desktop_activated_connection;
91 static sigc::connection _color_changed_connection;
93 static Inkscape::UI::Widget::ColorPicker *color_picker;
95 static void
96 clonetiler_dialog_destroy( GtkObject */*object*/, gpointer /*data*/ )
97 {
98     if (Inkscape::NSApplication::Application::getNewGui())
99     {
100         _shutdown_connection.disconnect();
101         _dialogs_hidden_connection.disconnect();
102         _dialogs_unhidden_connection.disconnect();
103         _desktop_activated_connection.disconnect();
104     } else {
105         sp_signal_disconnect_by_data (INKSCAPE, dlg);
106     }
107     _color_changed_connection.disconnect();
109     delete color_picker;
111     wd.win = dlg = NULL;
112     wd.stop = 0;
116 static gboolean
117 clonetiler_dialog_delete (GtkObject */*object*/, GdkEvent * /*event*/, gpointer /*data*/)
119     gtk_window_get_position ((GtkWindow *) dlg, &x, &y);
120     gtk_window_get_size ((GtkWindow *) dlg, &w, &h);
122     if (x<0) x=0;
123     if (y<0) y=0;
125     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
126     prefs->setInt(prefs_path + "x", x);
127     prefs->setInt(prefs_path + "y", y);
128     prefs->setInt(prefs_path + "w", w);
129     prefs->setInt(prefs_path + "h", h);
131     return FALSE; // which means, go ahead and destroy it
135 static void on_delete()
137     (void)clonetiler_dialog_delete (0, 0, NULL);
140 static void
141 on_picker_color_changed (guint rgba)
143     static bool is_updating = false;
144     if (is_updating || !SP_ACTIVE_DESKTOP)
145         return;
147     is_updating = true;
149     gchar c[32];
150     sp_svg_write_color(c, sizeof(c), rgba);
151     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
152     prefs->setString(prefs_path + "initial_color", c);
154     is_updating = false;
157 static guint clonetiler_number_of_clones (SPObject *obj);
159 static void
160 clonetiler_change_selection (Inkscape::Application * /*inkscape*/, Inkscape::Selection *selection, GtkWidget *dlg)
162     GtkWidget *buttons = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "buttons_on_tiles");
163     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
165     if (selection->isEmpty()) {
166         gtk_widget_set_sensitive (buttons, FALSE);
167         gtk_label_set_markup (GTK_LABEL(status), _("<small>Nothing selected.</small>"));
168         return;
169     }
171     if (g_slist_length ((GSList *) selection->itemList()) > 1) {
172         gtk_widget_set_sensitive (buttons, FALSE);
173         gtk_label_set_markup (GTK_LABEL(status), _("<small>More than one object selected.</small>"));
174         return;
175     }
177     guint n = clonetiler_number_of_clones(selection->singleItem());
178     if (n > 0) {
179         gtk_widget_set_sensitive (buttons, TRUE);
180         gchar *sta = g_strdup_printf (_("<small>Object has <b>%d</b> tiled clones.</small>"), n);
181         gtk_label_set_markup (GTK_LABEL(status), sta);
182         g_free (sta);
183     } else {
184         gtk_widget_set_sensitive (buttons, FALSE);
185         gtk_label_set_markup (GTK_LABEL(status), _("<small>Object has no tiled clones.</small>"));
186     }
189 static void
190 clonetiler_external_change (Inkscape::Application * /*inkscape*/, GtkWidget *dlg)
192     clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
195 static void clonetiler_disconnect_gsignal (GObject *widget, gpointer source) {
196     if (source && G_IS_OBJECT(source))
197         sp_signal_disconnect_by_data (source, widget);
201 enum {
202     TILE_P1,
203     TILE_P2,
204     TILE_PM,
205     TILE_PG,
206     TILE_CM,
207     TILE_PMM,
208     TILE_PMG,
209     TILE_PGG,
210     TILE_CMM,
211     TILE_P4,
212     TILE_P4M,
213     TILE_P4G,
214     TILE_P3,
215     TILE_P31M,
216     TILE_P3M1,
217     TILE_P6,
218     TILE_P6M
219 };
222 static Geom::Matrix
223 clonetiler_get_transform (
225     // symmetry group
226     int type,
228     // row, column
229     int i, int j,
231     // center, width, height of the tile
232     double cx, double cy,
233     double w,  double h,
235     // values from the dialog:
236     // Shift
237     double shiftx_per_i,      double shifty_per_i,
238     double shiftx_per_j,      double shifty_per_j,
239     double shiftx_rand,       double shifty_rand,
240     double shiftx_exp,        double shifty_exp,
241     int    shiftx_alternate,  int    shifty_alternate,
242     int    shiftx_cumulate,   int    shifty_cumulate,
243     int    shiftx_excludew,   int    shifty_excludeh,
245     // Scale
246     double scalex_per_i,      double scaley_per_i,
247     double scalex_per_j,      double scaley_per_j,
248     double scalex_rand,       double scaley_rand,
249     double scalex_exp,        double scaley_exp,
250     double scalex_log,        double scaley_log,
251     int    scalex_alternate,  int    scaley_alternate,
252     int    scalex_cumulate,   int    scaley_cumulate,
254     // Rotation
255     double rotate_per_i,      double rotate_per_j,
256     double rotate_rand,
257     int    rotate_alternatei, int    rotate_alternatej,
258     int    rotate_cumulatei,  int    rotate_cumulatej
259     )
262     // Shift (in units of tile width or height) -------------
263     double delta_shifti = 0.0;
264     double delta_shiftj = 0.0;
266     if( shiftx_alternate ) {
267         delta_shifti = (double)(i%2);
268     } else {
269         if( shiftx_cumulate ) {  // Should the delta shifts be cumulative (i.e. 1, 1+2, 1+2+3, ...)
270             delta_shifti = (double)(i*i);
271         } else {
272             delta_shifti = (double)i;
273         }
274     }
276     if( shifty_alternate ) {
277         delta_shiftj = (double)(j%2);
278     } else {
279         if( shifty_cumulate ) {
280             delta_shiftj = (double)(j*j);
281         } else {
282             delta_shiftj = (double)j;
283         }
284     }
286     // Random shift, only calculate if non-zero.
287     double delta_shiftx_rand = 0.0;
288     double delta_shifty_rand = 0.0;
289     if( shiftx_rand != 0.0 ) delta_shiftx_rand = shiftx_rand * g_random_double_range (-1, 1);
290     if( shifty_rand != 0.0 ) delta_shifty_rand = shifty_rand * g_random_double_range (-1, 1);
293     // Delta shift (units of tile width/height)
294     double di = shiftx_per_i * delta_shifti  + shiftx_per_j * delta_shiftj + delta_shiftx_rand;
295     double dj = shifty_per_i * delta_shifti  + shifty_per_j * delta_shiftj + delta_shifty_rand;
297     // Shift in actual x and y, used below
298     double dx = w * di;
299     double dy = h * dj;
301     double shifti = di;
302     double shiftj = dj;
304     // Include tile width and height in shift if required
305     if( !shiftx_excludew ) shifti += i;
306     if( !shifty_excludeh ) shiftj += j;
308     // Add exponential shift if necessary
309     if ( shiftx_exp != 1.0 ) shifti = pow( shifti, shiftx_exp );
310     if ( shifty_exp != 1.0 ) shiftj = pow( shiftj, shifty_exp );
312     // Final shift
313     Geom::Matrix rect_translate (Geom::Translate (w * shifti, h * shiftj));
315     // Rotation (in degrees) ------------
316     double delta_rotationi = 0.0;
317     double delta_rotationj = 0.0;
319     if( rotate_alternatei ) {
320         delta_rotationi = (double)(i%2);
321     } else {
322         if( rotate_cumulatei ) {
323             delta_rotationi = (double)(i*i + i)/2.0;
324         } else {
325             delta_rotationi = (double)i;
326         }
327     }
329     if( rotate_alternatej ) {
330         delta_rotationj = (double)(j%2);
331     } else {
332         if( rotate_cumulatej ) {
333             delta_rotationj = (double)(j*j + j)/2.0;
334         } else {
335             delta_rotationj = (double)j;
336         }
337     }
339     double delta_rotate_rand = 0.0;
340     if( rotate_rand != 0.0 ) delta_rotate_rand = rotate_rand * 180.0 * g_random_double_range (-1, 1);
342     double dr = rotate_per_i * delta_rotationi + rotate_per_j * delta_rotationj + delta_rotate_rand;
344     // Scale (times the original) -----------
345     double delta_scalei = 0.0;
346     double delta_scalej = 0.0;
348     if( scalex_alternate ) {
349         delta_scalei = (double)(i%2);
350     } else {
351         if( scalex_cumulate ) {  // Should the delta scales be cumulative (i.e. 1, 1+2, 1+2+3, ...)
352             delta_scalei = (double)(i*i + i)/2.0;
353         } else {
354             delta_scalei = (double)i;
355         }
356     }
358     if( scaley_alternate ) {
359         delta_scalej = (double)(j%2);
360     } else {
361         if( scaley_cumulate ) {
362             delta_scalej = (double)(j*j + j)/2.0;
363         } else {
364             delta_scalej = (double)j;
365         }
366     }
368     // Random scale, only calculate if non-zero.
369     double delta_scalex_rand = 0.0;
370     double delta_scaley_rand = 0.0;
371     if( scalex_rand != 0.0 ) delta_scalex_rand = scalex_rand * g_random_double_range (-1, 1);
372     if( scaley_rand != 0.0 ) delta_scaley_rand = scaley_rand * g_random_double_range (-1, 1);
373     // But if random factors are same, scale x and y proportionally
374     if( scalex_rand == scaley_rand ) delta_scalex_rand = delta_scaley_rand;
376     // Total delta scale
377     double scalex = 1.0 + scalex_per_i * delta_scalei  + scalex_per_j * delta_scalej + delta_scalex_rand;
378     double scaley = 1.0 + scaley_per_i * delta_scalei  + scaley_per_j * delta_scalej + delta_scaley_rand;
380     if( scalex < 0.0 ) scalex = 0.0;
381     if( scaley < 0.0 ) scaley = 0.0;
383     // Add exponential scale if necessary
384     if ( scalex_exp != 1.0 ) scalex = pow( scalex, scalex_exp );
385     if ( scaley_exp != 1.0 ) scaley = pow( scaley, scaley_exp );
387     // Add logarithmic factor if necessary
388     if ( scalex_log  > 0.0 ) scalex = pow( scalex_log, scalex - 1.0 );
389     if ( scaley_log  > 0.0 ) scaley = pow( scaley_log, scaley - 1.0 );
390     // Alternative using rotation angle
391     //if ( scalex_log  != 1.0 ) scalex *= pow( scalex_log, M_PI*dr/180 );
392     //if ( scaley_log  != 1.0 ) scaley *= pow( scaley_log, M_PI*dr/180 );
395     // Calculate transformation matrices, translating back to "center of tile" (rotation center) before transforming
396     Geom::Matrix drot_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (M_PI*dr/180)    * Geom::Translate(cx, cy);
398     Geom::Matrix dscale_c = Geom::Translate(-cx, -cy) * Geom::Scale (scalex, scaley)  * Geom::Translate(cx, cy);
400     Geom::Matrix d_s_r = dscale_c * drot_c;
402     Geom::Matrix rotate_180_c  = Geom::Translate(-cx, -cy) * Geom::Rotate (M_PI)      * Geom::Translate(cx, cy);
404     Geom::Matrix rotate_90_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (-M_PI/2)   * Geom::Translate(cx, cy);
405     Geom::Matrix rotate_m90_c  = Geom::Translate(-cx, -cy) * Geom::Rotate ( M_PI/2)   * Geom::Translate(cx, cy);
407     Geom::Matrix rotate_120_c  = Geom::Translate(-cx, -cy) * Geom::Rotate (-2*M_PI/3) * Geom::Translate(cx, cy);
408     Geom::Matrix rotate_m120_c = Geom::Translate(-cx, -cy) * Geom::Rotate ( 2*M_PI/3) * Geom::Translate(cx, cy);
410     Geom::Matrix rotate_60_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (-M_PI/3)   * Geom::Translate(cx, cy);
411     Geom::Matrix rotate_m60_c  = Geom::Translate(-cx, -cy) * Geom::Rotate ( M_PI/3)   * Geom::Translate(cx, cy);
413     Geom::Matrix flip_x        = Geom::Translate(-cx, -cy) * Geom::Scale (-1, 1)      * Geom::Translate(cx, cy);
414     Geom::Matrix flip_y        = Geom::Translate(-cx, -cy) * Geom::Scale (1, -1)      * Geom::Translate(cx, cy);
417     // Create tile with required symmetry
418     const double cos60 = cos(M_PI/3);
419     const double sin60 = sin(M_PI/3);
420     const double cos30 = cos(M_PI/6);
421     const double sin30 = sin(M_PI/6);
423     switch (type) {
425     case TILE_P1:
426         return d_s_r * rect_translate;
427         break;
429     case TILE_P2:
430         if (i % 2 == 0) {
431             return d_s_r * rect_translate;
432         } else {
433             return d_s_r * rotate_180_c * rect_translate;
434         }
435         break;
437     case TILE_PM:
438         if (i % 2 == 0) {
439             return d_s_r * rect_translate;
440         } else {
441             return d_s_r * flip_x * rect_translate;
442         }
443         break;
445     case TILE_PG:
446         if (j % 2 == 0) {
447             return d_s_r * rect_translate;
448         } else {
449             return d_s_r * flip_x * rect_translate;
450         }
451         break;
453     case TILE_CM:
454         if ((i + j) % 2 == 0) {
455             return d_s_r * rect_translate;
456         } else {
457             return d_s_r * flip_x * rect_translate;
458         }
459         break;
461     case TILE_PMM:
462         if (j % 2 == 0) {
463             if (i % 2 == 0) {
464                 return d_s_r * rect_translate;
465             } else {
466                 return d_s_r * flip_x * rect_translate;
467             }
468         } else {
469             if (i % 2 == 0) {
470                 return d_s_r * flip_y * rect_translate;
471             } else {
472                 return d_s_r * flip_x * flip_y * rect_translate;
473             }
474         }
475         break;
477     case TILE_PMG:
478         if (j % 2 == 0) {
479             if (i % 2 == 0) {
480                 return d_s_r * rect_translate;
481             } else {
482                 return d_s_r * rotate_180_c * rect_translate;
483             }
484         } else {
485             if (i % 2 == 0) {
486                 return d_s_r * flip_y * rect_translate;
487             } else {
488                 return d_s_r * rotate_180_c * flip_y * rect_translate;
489             }
490         }
491         break;
493     case TILE_PGG:
494         if (j % 2 == 0) {
495             if (i % 2 == 0) {
496                 return d_s_r * rect_translate;
497             } else {
498                 return d_s_r * flip_y * rect_translate;
499             }
500         } else {
501             if (i % 2 == 0) {
502                 return d_s_r * rotate_180_c * rect_translate;
503             } else {
504                 return d_s_r * rotate_180_c * flip_y * rect_translate;
505             }
506         }
507         break;
509     case TILE_CMM:
510         if (j % 4 == 0) {
511             if (i % 2 == 0) {
512                 return d_s_r * rect_translate;
513             } else {
514                 return d_s_r * flip_x * rect_translate;
515             }
516         } else if (j % 4 == 1) {
517             if (i % 2 == 0) {
518                 return d_s_r * flip_y * rect_translate;
519             } else {
520                 return d_s_r * flip_x * flip_y * rect_translate;
521             }
522         } else if (j % 4 == 2) {
523             if (i % 2 == 1) {
524                 return d_s_r * rect_translate;
525             } else {
526                 return d_s_r * flip_x * rect_translate;
527             }
528         } else {
529             if (i % 2 == 1) {
530                 return d_s_r * flip_y * rect_translate;
531             } else {
532                 return d_s_r * flip_x * flip_y * rect_translate;
533             }
534         }
535         break;
537     case TILE_P4:
538     {
539         Geom::Matrix ori  (Geom::Translate ((w + h) * pow((i/2), shiftx_exp) + dx,  (h + w) * pow((j/2), shifty_exp) + dy));
540         Geom::Matrix dia1 (Geom::Translate (w/2 + h/2, -h/2 + w/2));
541         Geom::Matrix dia2 (Geom::Translate (-w/2 + h/2, h/2 + w/2));
542         if (j % 2 == 0) {
543             if (i % 2 == 0) {
544                 return d_s_r * ori;
545             } else {
546                 return d_s_r * rotate_m90_c * dia1 * ori;
547             }
548         } else {
549             if (i % 2 == 0) {
550                 return d_s_r * rotate_90_c * dia2 * ori;
551             } else {
552                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
553             }
554         }
555     }
556     break;
558     case TILE_P4M:
559     {
560         double max = MAX(w, h);
561         Geom::Matrix ori (Geom::Translate ((max + max) * pow((i/4), shiftx_exp) + dx,  (max + max) * pow((j/2), shifty_exp) + dy));
562         Geom::Matrix dia1 (Geom::Translate ( w/2 - h/2, h/2 - w/2));
563         Geom::Matrix dia2 (Geom::Translate (-h/2 + w/2, w/2 - h/2));
564         if (j % 2 == 0) {
565             if (i % 4 == 0) {
566                 return d_s_r * ori;
567             } else if (i % 4 == 1) {
568                 return d_s_r * flip_y * rotate_m90_c * dia1 * ori;
569             } else if (i % 4 == 2) {
570                 return d_s_r * rotate_m90_c * dia1 * Geom::Translate (h, 0) * ori;
571             } else if (i % 4 == 3) {
572                 return d_s_r * flip_x * Geom::Translate (w, 0) * ori;
573             }
574         } else {
575             if (i % 4 == 0) {
576                 return d_s_r * flip_y * Geom::Translate(0, h) * ori;
577             } else if (i % 4 == 1) {
578                 return d_s_r * rotate_90_c * dia2 * Geom::Translate(0, h) * ori;
579             } else if (i % 4 == 2) {
580                 return d_s_r * flip_y * rotate_90_c * dia2 * Geom::Translate(h, 0) * Geom::Translate(0, h) * ori;
581             } else if (i % 4 == 3) {
582                 return d_s_r * flip_y * flip_x * Geom::Translate(w, 0) * Geom::Translate(0, h) * ori;
583             }
584         }
585     }
586     break;
588     case TILE_P4G:
589     {
590         double max = MAX(w, h);
591         Geom::Matrix ori (Geom::Translate ((max + max) * pow((i/4), shiftx_exp) + dx,  (max + max) * pow(j, shifty_exp) + dy));
592         Geom::Matrix dia1 (Geom::Translate ( w/2 + h/2, h/2 - w/2));
593         Geom::Matrix dia2 (Geom::Translate (-h/2 + w/2, w/2 + h/2));
594         if (((i/4) + j) % 2 == 0) {
595             if (i % 4 == 0) {
596                 return d_s_r * ori;
597             } else if (i % 4 == 1) {
598                 return d_s_r * rotate_m90_c * dia1 * ori;
599             } else if (i % 4 == 2) {
600                 return d_s_r * rotate_90_c * dia2 * ori;
601             } else if (i % 4 == 3) {
602                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
603             }
604         } else {
605             if (i % 4 == 0) {
606                 return d_s_r * flip_y * Geom::Translate (0, h) * ori;
607             } else if (i % 4 == 1) {
608                 return d_s_r * flip_y * rotate_m90_c * dia1 * Geom::Translate (-h, 0) * ori;
609             } else if (i % 4 == 2) {
610                 return d_s_r * flip_y * rotate_90_c * dia2 * Geom::Translate (h, 0) * ori;
611             } else if (i % 4 == 3) {
612                 return d_s_r * flip_x * Geom::Translate (w, 0) * ori;
613             }
614         }
615     }
616     break;
618     case TILE_P3:
619     {
620         double width;
621         double height;
622         Geom::Matrix dia1;
623         Geom::Matrix dia2;
624         if (w > h) {
625             width  = w + w * cos60;
626             height = 2 * w * sin60;
627             dia1 = Geom::Matrix (Geom::Translate (w/2 + w/2 * cos60, -(w/2 * sin60)));
628             dia2 = dia1 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60)));
629         } else {
630             width = h * cos (M_PI/6);
631             height = h;
632             dia1 = Geom::Matrix (Geom::Translate (h/2 * cos30, -(h/2 * sin30)));
633             dia2 = dia1 * Geom::Matrix (Geom::Translate (0, h/2));
634         }
635         Geom::Matrix ori (Geom::Translate (width * pow((2*(i/3) + j%2), shiftx_exp) + dx,  (height/2) * pow(j, shifty_exp) + dy));
636         if (i % 3 == 0) {
637             return d_s_r * ori;
638         } else if (i % 3 == 1) {
639             return d_s_r * rotate_m120_c * dia1 * ori;
640         } else if (i % 3 == 2) {
641             return d_s_r * rotate_120_c * dia2 * ori;
642         }
643     }
644     break;
646     case TILE_P31M:
647     {
648         Geom::Matrix ori;
649         Geom::Matrix dia1;
650         Geom::Matrix dia2;
651         Geom::Matrix dia3;
652         Geom::Matrix dia4;
653         if (w > h) {
654             ori = Geom::Matrix(Geom::Translate (w * pow((i/6) + 0.5*(j%2), shiftx_exp) + dx,  (w * cos30) * pow(j, shifty_exp) + dy));
655             dia1 = Geom::Matrix (Geom::Translate (0, h/2) * Geom::Translate (w/2, 0) * Geom::Translate (w/2 * cos60, -w/2 * sin60) * Geom::Translate (-h/2 * cos30, -h/2 * sin30) );
656             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
657             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
658             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
659         } else {
660             ori  = Geom::Matrix (Geom::Translate (2*h * cos30  * pow((i/6 + 0.5*(j%2)), shiftx_exp) + dx,  (2*h - h * sin30) * pow(j, shifty_exp) + dy));
661             dia1 = Geom::Matrix (Geom::Translate (0, -h/2) * Geom::Translate (h/2 * cos30, h/2 * sin30));
662             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
663             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, h/2));
664             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
665         }
666         if (i % 6 == 0) {
667             return d_s_r * ori;
668         } else if (i % 6 == 1) {
669             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
670         } else if (i % 6 == 2) {
671             return d_s_r * rotate_m120_c * dia2 * ori;
672         } else if (i % 6 == 3) {
673             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
674         } else if (i % 6 == 4) {
675             return d_s_r * rotate_120_c * dia4 * ori;
676         } else if (i % 6 == 5) {
677             return d_s_r * flip_y * Geom::Translate(0, h) * ori;
678         }
679     }
680     break;
682     case TILE_P3M1:
683     {
684         double width;
685         double height;
686         Geom::Matrix dia1;
687         Geom::Matrix dia2;
688         Geom::Matrix dia3;
689         Geom::Matrix dia4;
690         if (w > h) {
691             width = w + w * cos60;
692             height = 2 * w * sin60;
693             dia1 = Geom::Matrix (Geom::Translate (0, h/2) * Geom::Translate (w/2, 0) * Geom::Translate (w/2 * cos60, -w/2 * sin60) * Geom::Translate (-h/2 * cos30, -h/2 * sin30) );
694             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
695             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
696             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
697         } else {
698             width = 2 * h * cos (M_PI/6);
699             height = 2 * h;
700             dia1 = Geom::Matrix (Geom::Translate (0, -h/2) * Geom::Translate (h/2 * cos30, h/2 * sin30));
701             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
702             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, h/2));
703             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
704         }
705         Geom::Matrix ori (Geom::Translate (width * pow((2*(i/6) + j%2), shiftx_exp) + dx,  (height/2) * pow(j, shifty_exp) + dy));
706         if (i % 6 == 0) {
707             return d_s_r * ori;
708         } else if (i % 6 == 1) {
709             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
710         } else if (i % 6 == 2) {
711             return d_s_r * rotate_m120_c * dia2 * ori;
712         } else if (i % 6 == 3) {
713             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
714         } else if (i % 6 == 4) {
715             return d_s_r * rotate_120_c * dia4 * ori;
716         } else if (i % 6 == 5) {
717             return d_s_r * flip_y * Geom::Translate(0, h) * ori;
718         }
719     }
720     break;
722     case TILE_P6:
723     {
724         Geom::Matrix ori;
725         Geom::Matrix dia1;
726         Geom::Matrix dia2;
727         Geom::Matrix dia3;
728         Geom::Matrix dia4;
729         Geom::Matrix dia5;
730         if (w > h) {
731             ori = Geom::Matrix(Geom::Translate (w * pow((2*(i/6) + (j%2)), shiftx_exp) + dx,  (2*w * sin60) * pow(j, shifty_exp) + dy));
732             dia1 = Geom::Matrix (Geom::Translate (w/2 * cos60, -w/2 * sin60));
733             dia2 = dia1 * Geom::Matrix (Geom::Translate (w/2, 0));
734             dia3 = dia2 * Geom::Matrix (Geom::Translate (w/2 * cos60, w/2 * sin60));
735             dia4 = dia3 * Geom::Matrix (Geom::Translate (-w/2 * cos60, w/2 * sin60));
736             dia5 = dia4 * Geom::Matrix (Geom::Translate (-w/2, 0));
737         } else {
738             ori = Geom::Matrix(Geom::Translate (2*h * cos30 * pow((i/6 + 0.5*(j%2)), shiftx_exp) + dx,  (h + h * sin30) * pow(j, shifty_exp) + dy));
739             dia1 = Geom::Matrix (Geom::Translate (-w/2, -h/2) * Geom::Translate (h/2 * cos30, -h/2 * sin30) * Geom::Translate (w/2 * cos60, w/2 * sin60));
740             dia2 = dia1 * Geom::Matrix (Geom::Translate (-w/2 * cos60, -w/2 * sin60) * Geom::Translate (h/2 * cos30, -h/2 * sin30) * Geom::Translate (h/2 * cos30, h/2 * sin30) * Geom::Translate (-w/2 * cos60, w/2 * sin60));
741             dia3 = dia2 * Geom::Matrix (Geom::Translate (w/2 * cos60, -w/2 * sin60) * Geom::Translate (h/2 * cos30, h/2 * sin30) * Geom::Translate (-w/2, h/2));
742             dia4 = dia3 * dia1.inverse();
743             dia5 = dia3 * dia2.inverse();
744         }
745         if (i % 6 == 0) {
746             return d_s_r * ori;
747         } else if (i % 6 == 1) {
748             return d_s_r * rotate_m60_c * dia1 * ori;
749         } else if (i % 6 == 2) {
750             return d_s_r * rotate_m120_c * dia2 * ori;
751         } else if (i % 6 == 3) {
752             return d_s_r * rotate_180_c * dia3 * ori;
753         } else if (i % 6 == 4) {
754             return d_s_r * rotate_120_c * dia4 * ori;
755         } else if (i % 6 == 5) {
756             return d_s_r * rotate_60_c * dia5 * ori;
757         }
758     }
759     break;
761     case TILE_P6M:
762     {
764         Geom::Matrix ori;
765         Geom::Matrix dia1, dia2, dia3, dia4, dia5, dia6, dia7, dia8, dia9, dia10;
766         if (w > h) {
767             ori = Geom::Matrix(Geom::Translate (w * pow((2*(i/12) + (j%2)), shiftx_exp) + dx,  (2*w * sin60) * pow(j, shifty_exp) + dy));
768             dia1 = Geom::Matrix (Geom::Translate (w/2, h/2) * Geom::Translate (-w/2 * cos60, -w/2 * sin60) * Geom::Translate (-h/2 * cos30, h/2 * sin30));
769             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, -h * sin30));
770             dia3 = dia2 * Geom::Matrix (Geom::Translate (-h/2 * cos30, h/2 * sin30) * Geom::Translate (w * cos60, 0) * Geom::Translate (-h/2 * cos30, -h/2 * sin30));
771             dia4 = dia3 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
772             dia5 = dia4 * Geom::Matrix (Geom::Translate (-h/2 * cos30, -h/2 * sin30) * Geom::Translate (-w/2 * cos60, w/2 * sin60) * Geom::Translate (w/2, -h/2));
773             dia6 = dia5 * Geom::Matrix (Geom::Translate (0, h));
774             dia7 = dia6 * dia1.inverse();
775             dia8 = dia6 * dia2.inverse();
776             dia9 = dia6 * dia3.inverse();
777             dia10 = dia6 * dia4.inverse();
778         } else {
779             ori = Geom::Matrix(Geom::Translate (4*h * cos30 * pow((i/12 + 0.5*(j%2)), shiftx_exp) + dx,  (2*h  + 2*h * sin30) * pow(j, shifty_exp) + dy));
780             dia1 = Geom::Matrix (Geom::Translate (-w/2, -h/2) * Geom::Translate (h/2 * cos30, -h/2 * sin30) * Geom::Translate (w/2 * cos60, w/2 * sin60));
781             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, -h * sin30));
782             dia3 = dia2 * Geom::Matrix (Geom::Translate (-w/2 * cos60, -w/2 * sin60) * Geom::Translate (h * cos30, 0) * Geom::Translate (-w/2 * cos60, w/2 * sin60));
783             dia4 = dia3 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
784             dia5 = dia4 * Geom::Matrix (Geom::Translate (w/2 * cos60, -w/2 * sin60) * Geom::Translate (h/2 * cos30, h/2 * sin30) * Geom::Translate (-w/2, h/2));
785             dia6 = dia5 * Geom::Matrix (Geom::Translate (0, h));
786             dia7 = dia6 * dia1.inverse();
787             dia8 = dia6 * dia2.inverse();
788             dia9 = dia6 * dia3.inverse();
789             dia10 = dia6 * dia4.inverse();
790         }
791         if (i % 12 == 0) {
792             return d_s_r * ori;
793         } else if (i % 12 == 1) {
794             return d_s_r * flip_y * rotate_m60_c * dia1 * ori;
795         } else if (i % 12 == 2) {
796             return d_s_r * rotate_m60_c * dia2 * ori;
797         } else if (i % 12 == 3) {
798             return d_s_r * flip_y * rotate_m120_c * dia3 * ori;
799         } else if (i % 12 == 4) {
800             return d_s_r * rotate_m120_c * dia4 * ori;
801         } else if (i % 12 == 5) {
802             return d_s_r * flip_x * dia5 * ori;
803         } else if (i % 12 == 6) {
804             return d_s_r * flip_x * flip_y * dia6 * ori;
805         } else if (i % 12 == 7) {
806             return d_s_r * flip_y * rotate_120_c * dia7 * ori;
807         } else if (i % 12 == 8) {
808             return d_s_r * rotate_120_c * dia8 * ori;
809         } else if (i % 12 == 9) {
810             return d_s_r * flip_y * rotate_60_c * dia9 * ori;
811         } else if (i % 12 == 10) {
812             return d_s_r * rotate_60_c * dia10 * ori;
813         } else if (i % 12 == 11) {
814             return d_s_r * flip_y * Geom::Translate (0, h) * ori;
815         }
816     }
817     break;
819     default:
820         break;
821     }
823     return Geom::identity();
826 static bool
827 clonetiler_is_a_clone_of (SPObject *tile, SPObject *obj)
829     char *id_href = NULL;
831     if (obj) {
832         Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
833         id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
834     }
836     if (SP_IS_USE(tile) &&
837         SP_OBJECT_REPR(tile)->attribute("xlink:href") &&
838         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("xlink:href"))) &&
839         SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of") &&
840         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of"))))
841     {
842         if (id_href)
843             g_free (id_href);
844         return true;
845     } else {
846         if (id_href)
847             g_free (id_href);
848         return false;
849     }
852 static NRArena const *trace_arena = NULL;
853 static unsigned trace_visionkey;
854 static NRArenaItem *trace_root;
855 static gdouble trace_zoom;
856 static SPDocument *trace_doc;
858 static void
859 clonetiler_trace_hide_tiled_clones_recursively (SPObject *from)
861     if (!trace_arena)
862         return;
864     for (SPObject *o = sp_object_first_child(from); o != NULL; o = SP_OBJECT_NEXT(o)) {
865         if (SP_IS_ITEM(o) && clonetiler_is_a_clone_of (o, NULL))
866             sp_item_invoke_hide(SP_ITEM(o), trace_visionkey); // FIXME: hide each tiled clone's original too!
867         clonetiler_trace_hide_tiled_clones_recursively (o);
868     }
871 static void
872 clonetiler_trace_setup (SPDocument *doc, gdouble zoom, SPItem *original)
874     trace_arena = NRArena::create();
875     /* Create ArenaItem and set transform */
876     trace_visionkey = sp_item_display_key_new(1);
877     trace_doc = doc;
878     trace_root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT (trace_doc)),
879                                       (NRArena *) trace_arena, trace_visionkey, SP_ITEM_SHOW_DISPLAY);
881     // hide the (current) original and any tiled clones, we only want to pick the background
882     sp_item_invoke_hide(original, trace_visionkey);
883     clonetiler_trace_hide_tiled_clones_recursively (SP_OBJECT(SP_DOCUMENT_ROOT (trace_doc)));
885     sp_document_root (trace_doc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
886     sp_document_ensure_up_to_date(trace_doc);
888     trace_zoom = zoom;
891 static guint32
892 clonetiler_trace_pick (Geom::Rect box)
894     if (!trace_arena)
895         return 0;
897     Geom::Matrix t(Geom::Scale(trace_zoom, trace_zoom));
898     nr_arena_item_set_transform(trace_root, &t);
899     NRGC gc(NULL);
900     gc.transform.setIdentity();
901     nr_arena_item_invoke_update( trace_root, NULL, &gc,
902                                  NR_ARENA_ITEM_STATE_ALL,
903                                  NR_ARENA_ITEM_STATE_NONE );
905     /* Item integer bbox in points */
906     NRRectL ibox;
907     ibox.x0 = (int) floor(trace_zoom * box[Geom::X].min() + 0.5);
908     ibox.y0 = (int) floor(trace_zoom * box[Geom::Y].min() + 0.5);
909     ibox.x1 = (int) floor(trace_zoom * box[Geom::X].max() + 0.5);
910     ibox.y1 = (int) floor(trace_zoom * box[Geom::Y].max() + 0.5);
912     /* Find visible area */
913     int width = ibox.x1 - ibox.x0;
914     int height = ibox.y1 - ibox.y0;
916     /* Set up pixblock */
917     guchar *px = g_new(guchar, 4 * width * height);
919     if (px == NULL) {
920         return 0; // buffer is too big or too small, cannot pick, so return 0
921     }
923     memset(px, 0x00, 4 * width * height);
925     /* Render */
926     NRPixBlock pb;
927     nr_pixblock_setup_extern( &pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
928                               ibox.x0, ibox.y0, ibox.x1, ibox.y1,
929                               px, 4 * width, FALSE, FALSE );
930     nr_arena_item_invoke_render(NULL, trace_root, &ibox, &pb,
931                                  NR_ARENA_ITEM_RENDER_NO_CACHE );
933     double R = 0, G = 0, B = 0, A = 0;
934     double count = 0;
935     double weight = 0;
937     for (int y = ibox.y0; y < ibox.y1; y++) {
938         const unsigned char *s = NR_PIXBLOCK_PX (&pb) + (y - ibox.y0) * pb.rs;
939         for (int x = ibox.x0; x < ibox.x1; x++) {
940             count += 1;
941             weight += s[3] / 255.0;
942             R += s[0] / 255.0;
943             G += s[1] / 255.0;
944             B += s[2] / 255.0;
945             A += s[3] / 255.0;
946             s += 4;
947         }
948     }
950     nr_pixblock_release(&pb);
952     R = R / weight;
953     G = G / weight;
954     B = B / weight;
955     A = A / count;
957     R = CLAMP (R, 0.0, 1.0);
958     G = CLAMP (G, 0.0, 1.0);
959     B = CLAMP (B, 0.0, 1.0);
960     A = CLAMP (A, 0.0, 1.0);
962     return SP_RGBA32_F_COMPOSE (R, G, B, A);
965 static void
966 clonetiler_trace_finish ()
968     if (trace_doc) {
969         sp_item_invoke_hide(SP_ITEM(sp_document_root(trace_doc)), trace_visionkey);
970     }
971     if (trace_arena) {
972         ((NRObject *) trace_arena)->unreference();
973         trace_arena = NULL;
974     }
977 static void
978 clonetiler_unclump( GtkWidget */*widget*/, void * )
980     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
981     if (desktop == NULL)
982         return;
984     Inkscape::Selection *selection = sp_desktop_selection(desktop);
986     // check if something is selected
987     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
988         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump."));
989         return;
990     }
992     SPObject *obj = SP_OBJECT(selection->singleItem());
993     SPObject *parent = SP_OBJECT_PARENT (obj);
995     GSList *to_unclump = NULL; // not including the original
997     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
998         if (clonetiler_is_a_clone_of (child, obj)) {
999             to_unclump = g_slist_prepend (to_unclump, child);
1000         }
1001     }
1003     sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1005     unclump (to_unclump);
1007     g_slist_free (to_unclump);
1009     sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
1010                       _("Unclump tiled clones"));
1013 static guint
1014 clonetiler_number_of_clones (SPObject *obj)
1016     SPObject *parent = SP_OBJECT_PARENT (obj);
1018     guint n = 0;
1020     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
1021         if (clonetiler_is_a_clone_of (child, obj)) {
1022             n ++;
1023         }
1024     }
1026     return n;
1029 static void
1030 clonetiler_remove( GtkWidget */*widget*/, void *, bool do_undo = true )
1032     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1033     if (desktop == NULL)
1034         return;
1036     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1038     // check if something is selected
1039     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
1040         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove."));
1041         return;
1042     }
1044     SPObject *obj = SP_OBJECT(selection->singleItem());
1045     SPObject *parent = SP_OBJECT_PARENT (obj);
1047 // remove old tiling
1048     GSList *to_delete = NULL;
1049     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
1050         if (clonetiler_is_a_clone_of (child, obj)) {
1051             to_delete = g_slist_prepend (to_delete, child);
1052         }
1053     }
1054     for (GSList *i = to_delete; i; i = i->next) {
1055         SP_OBJECT(i->data)->deleteObject();
1056     }
1057     g_slist_free (to_delete);
1059     clonetiler_change_selection (NULL, selection, dlg);
1061     if (do_undo)
1062         sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
1063                           _("Delete tiled clones"));
1066 static Geom::Rect
1067 transform_rect( Geom::Rect const &r, Geom::Matrix const &m)
1069     using Geom::X;
1070     using Geom::Y;
1071     Geom::Point const p1 = r.corner(1) * m;
1072     Geom::Point const p2 = r.corner(2) * m;
1073     Geom::Point const p3 = r.corner(3) * m;
1074     Geom::Point const p4 = r.corner(4) * m;
1075     return Geom::Rect(
1076         Geom::Point(
1077             std::min(std::min(p1[X], p2[X]), std::min(p3[X], p4[X])),
1078             std::min(std::min(p1[Y], p2[Y]), std::min(p3[Y], p4[Y]))),
1079         Geom::Point(
1080             std::max(std::max(p1[X], p2[X]), std::max(p3[X], p4[X])),
1081             std::max(std::max(p1[Y], p2[Y]), std::max(p3[Y], p4[Y]))));
1084 /**
1085 Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same
1086 probability of being displaced.
1087  */
1088 static double
1089 randomize01 (double val, double rand)
1091     double base = MIN (val - rand, 1 - 2*rand);
1092     if (base < 0) base = 0;
1093     val = base + g_random_double_range (0, MIN (2 * rand, 1 - base));
1094     return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case...
1098 static void
1099 clonetiler_apply( GtkWidget */*widget*/, void * )
1101     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1102     if (desktop == NULL)
1103         return;
1104     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1105     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1107     // check if something is selected
1108     if (selection->isEmpty()) {
1109         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone."));
1110         return;
1111     }
1113     // Check if more than one object is selected.
1114     if (g_slist_length((GSList *) selection->itemList()) > 1) {
1115         sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("If you want to clone several objects, <b>group</b> them and <b>clone the group</b>."));
1116         return;
1117     }
1119     // set "busy" cursor
1120     desktop->setWaitingCursor();
1122     // set statusbar text
1123     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
1124     gtk_label_set_markup (GTK_LABEL(status), _("<small>Creating tiled clones...</small>"));
1125     gtk_widget_queue_draw(GTK_WIDGET(status));
1126     gdk_window_process_all_updates();
1128     SPObject *obj = SP_OBJECT(selection->singleItem());
1129     Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
1130     const char *id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
1131     SPObject *parent = SP_OBJECT_PARENT (obj);
1133     clonetiler_remove (NULL, NULL, false);
1135     double shiftx_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_per_i", 0, -10000, 10000);
1136     double shifty_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_per_i", 0, -10000, 10000);
1137     double shiftx_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_per_j", 0, -10000, 10000);
1138     double shifty_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_per_j", 0, -10000, 10000);
1139     double shiftx_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_rand", 0, 0, 1000);
1140     double shifty_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_rand", 0, 0, 1000);
1141     double shiftx_exp   =        prefs->getDoubleLimited(prefs_path + "shiftx_exp",   1, 0, 10);
1142     double shifty_exp   =        prefs->getDoubleLimited(prefs_path + "shifty_exp", 1, 0, 10);
1143     bool   shiftx_alternate =    prefs->getBool(prefs_path + "shiftx_alternate");
1144     bool   shifty_alternate =    prefs->getBool(prefs_path + "shifty_alternate");
1145     bool   shiftx_cumulate  =    prefs->getBool(prefs_path + "shiftx_cumulate");
1146     bool   shifty_cumulate  =    prefs->getBool(prefs_path + "shifty_cumulate");
1147     bool   shiftx_excludew  =    prefs->getBool(prefs_path + "shiftx_excludew");
1148     bool   shifty_excludeh  =    prefs->getBool(prefs_path + "shifty_excludeh");
1150     double scalex_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_per_i", 0, -100, 1000);
1151     double scaley_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_per_i", 0, -100, 1000);
1152     double scalex_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_per_j", 0, -100, 1000);
1153     double scaley_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_per_j", 0, -100, 1000);
1154     double scalex_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_rand",  0, 0, 1000);
1155     double scaley_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_rand",  0, 0, 1000);
1156     double scalex_exp   =        prefs->getDoubleLimited(prefs_path + "scalex_exp",   1, 0, 10);
1157     double scaley_exp   =        prefs->getDoubleLimited(prefs_path + "scaley_exp",   1, 0, 10);
1158     double scalex_log       =    prefs->getDoubleLimited(prefs_path + "scalex_log",   0, 0, 10);
1159     double scaley_log       =    prefs->getDoubleLimited(prefs_path + "scaley_log",   0, 0, 10);
1160     bool   scalex_alternate =    prefs->getBool(prefs_path + "scalex_alternate");
1161     bool   scaley_alternate =    prefs->getBool(prefs_path + "scaley_alternate");
1162     bool   scalex_cumulate  =    prefs->getBool(prefs_path + "scalex_cumulate");
1163     bool   scaley_cumulate  =    prefs->getBool(prefs_path + "scaley_cumulate");
1165     double rotate_per_i =        prefs->getDoubleLimited(prefs_path + "rotate_per_i", 0, -180, 180);
1166     double rotate_per_j =        prefs->getDoubleLimited(prefs_path + "rotate_per_j", 0, -180, 180);
1167     double rotate_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "rotate_rand", 0, 0, 100);
1168     bool   rotate_alternatei   = prefs->getBool(prefs_path + "rotate_alternatei");
1169     bool   rotate_alternatej   = prefs->getBool(prefs_path + "rotate_alternatej");
1170     bool   rotate_cumulatei    = prefs->getBool(prefs_path + "rotate_cumulatei");
1171     bool   rotate_cumulatej    = prefs->getBool(prefs_path + "rotate_cumulatej");
1173     double blur_per_i =   0.01 * prefs->getDoubleLimited(prefs_path + "blur_per_i", 0, 0, 100);
1174     double blur_per_j =   0.01 * prefs->getDoubleLimited(prefs_path + "blur_per_j", 0, 0, 100);
1175     bool   blur_alternatei =     prefs->getBool(prefs_path + "blur_alternatei");
1176     bool   blur_alternatej =     prefs->getBool(prefs_path + "blur_alternatej");
1177     double blur_rand =    0.01 * prefs->getDoubleLimited(prefs_path + "blur_rand", 0, 0, 100);
1179     double opacity_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "opacity_per_i", 0, 0, 100);
1180     double opacity_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "opacity_per_j", 0, 0, 100);
1181     bool   opacity_alternatei =   prefs->getBool(prefs_path + "opacity_alternatei");
1182     bool   opacity_alternatej =   prefs->getBool(prefs_path + "opacity_alternatej");
1183     double opacity_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "opacity_rand", 0, 0, 100);
1185     Glib::ustring initial_color =    prefs->getString(prefs_path + "initial_color");
1186     double hue_per_j =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_per_j", 0, -100, 100);
1187     double hue_per_i =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_per_i", 0, -100, 100);
1188     double hue_rand  =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_rand", 0, 0, 100);
1189     double saturation_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "saturation_per_j", 0, -100, 100);
1190     double saturation_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "saturation_per_i", 0, -100, 100);
1191     double saturation_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "saturation_rand", 0, 0, 100);
1192     double lightness_per_j =  0.01 * prefs->getDoubleLimited(prefs_path + "lightness_per_j", 0, -100, 100);
1193     double lightness_per_i =  0.01 * prefs->getDoubleLimited(prefs_path + "lightness_per_i", 0, -100, 100);
1194     double lightness_rand =   0.01 * prefs->getDoubleLimited(prefs_path + "lightness_rand", 0, 0, 100);
1195     bool   color_alternatej = prefs->getBool(prefs_path + "color_alternatej");
1196     bool   color_alternatei = prefs->getBool(prefs_path + "color_alternatei");
1198     int    type = prefs->getInt(prefs_path + "symmetrygroup", 0);
1199     bool   keepbbox = prefs->getBool(prefs_path + "keepbbox", true);
1200     int    imax = prefs->getInt(prefs_path + "imax", 2);
1201     int    jmax = prefs->getInt(prefs_path + "jmax", 2);
1203     bool   fillrect = prefs->getBool(prefs_path + "fillrect");
1204     double fillwidth = prefs->getDoubleLimited(prefs_path + "fillwidth", 50, 0, 1e6);
1205     double fillheight = prefs->getDoubleLimited(prefs_path + "fillheight", 50, 0, 1e6);
1207     bool   dotrace = prefs->getBool(prefs_path + "dotrace");
1208     int    pick = prefs->getInt(prefs_path + "pick");
1209     bool   pick_to_presence = prefs->getBool(prefs_path + "pick_to_presence");
1210     bool   pick_to_size = prefs->getBool(prefs_path + "pick_to_size");
1211     bool   pick_to_color = prefs->getBool(prefs_path + "pick_to_color");
1212     bool   pick_to_opacity = prefs->getBool(prefs_path + "pick_to_opacity");
1213     double rand_picked = 0.01 * prefs->getDoubleLimited(prefs_path + "rand_picked", 0, 0, 100);
1214     bool   invert_picked = prefs->getBool(prefs_path + "invert_picked");
1215     double gamma_picked = prefs->getDoubleLimited(prefs_path + "gamma_picked", 0, -10, 10);
1217     if (dotrace) {
1218         clonetiler_trace_setup (sp_desktop_document(desktop), 1.0, SP_ITEM (obj));
1219     }
1221     Geom::Point center;
1222     double w;
1223     double h;
1224     double x0;
1225     double y0;
1227     if (keepbbox &&
1228         obj_repr->attribute("inkscape:tile-w") &&
1229         obj_repr->attribute("inkscape:tile-h") &&
1230         obj_repr->attribute("inkscape:tile-x0") &&
1231         obj_repr->attribute("inkscape:tile-y0") &&
1232         obj_repr->attribute("inkscape:tile-cx") &&
1233         obj_repr->attribute("inkscape:tile-cy")) {
1235         double cx = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cx", 0);
1236         double cy = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cy", 0);
1237         center = Geom::Point (cx, cy);
1239         w = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-w", 0);
1240         h = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-h", 0);
1241         x0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-x0", 0);
1242         y0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-y0", 0);
1243     } else {
1244         bool prefs_bbox = prefs->getBool("/tools/bounding_box", false);
1245         SPItem::BBoxType bbox_type = ( prefs_bbox ? 
1246             SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX );
1247         Geom::OptRect r = SP_ITEM(obj)->getBounds(sp_item_i2doc_affine(SP_ITEM(obj)),
1248                                                         bbox_type);
1249         if (r) {
1250             w = r->dimensions()[Geom::X];
1251             h = r->dimensions()[Geom::Y];
1252             x0 = r->min()[Geom::X];
1253             y0 = r->min()[Geom::Y];
1254             center = desktop->dt2doc(SP_ITEM(obj)->getCenter());
1256             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", center[Geom::X]);
1257             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", center[Geom::Y]);
1258             sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
1259             sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
1260             sp_repr_set_svg_double(obj_repr, "inkscape:tile-x0", x0);
1261             sp_repr_set_svg_double(obj_repr, "inkscape:tile-y0", y0);
1262         } else {
1263             center = Geom::Point(0, 0);
1264             w = h = 0;
1265             x0 = y0 = 0;
1266         }
1267     }
1269     Geom::Point cur(0, 0);
1270     Geom::Rect bbox_original (Geom::Point (x0, y0), Geom::Point (x0 + w, y0 + h));
1271     double perimeter_original = (w + h)/4;
1273     // The integers i and j are reserved for tile column and row.
1274     // The doubles x and y are used for coordinates
1275     for (int i = 0;
1276          fillrect?
1277              (fabs(cur[Geom::X]) < fillwidth && i < 200) // prevent "freezing" with too large fillrect, arbitrarily limit rows
1278              : (i < imax);
1279          i ++) {
1280         for (int j = 0;
1281              fillrect?
1282                  (fabs(cur[Geom::Y]) < fillheight && j < 200) // prevent "freezing" with too large fillrect, arbitrarily limit cols
1283                  : (j < jmax);
1284              j ++) {
1286             // Note: We create a clone at 0,0 too, right over the original, in case our clones are colored
1288             // Get transform from symmetry, shift, scale, rotation
1289             Geom::Matrix t = clonetiler_get_transform (type, i, j, center[Geom::X], center[Geom::Y], w, h,
1290                                                        shiftx_per_i,     shifty_per_i,
1291                                                        shiftx_per_j,     shifty_per_j,
1292                                                        shiftx_rand,      shifty_rand,
1293                                                        shiftx_exp,       shifty_exp,
1294                                                        shiftx_alternate, shifty_alternate,
1295                                                        shiftx_cumulate,  shifty_cumulate,
1296                                                        shiftx_excludew,  shifty_excludeh,
1297                                                        scalex_per_i,     scaley_per_i,
1298                                                        scalex_per_j,     scaley_per_j,
1299                                                        scalex_rand,      scaley_rand,
1300                                                        scalex_exp,       scaley_exp,
1301                                                        scalex_log,       scaley_log,
1302                                                        scalex_alternate, scaley_alternate,
1303                                                        scalex_cumulate,  scaley_cumulate,
1304                                                        rotate_per_i,     rotate_per_j,
1305                                                        rotate_rand,
1306                                                        rotate_alternatei, rotate_alternatej,
1307                                                        rotate_cumulatei,  rotate_cumulatej      );
1309             cur = center * t - center;
1310             if (fillrect) {
1311                 if ((cur[Geom::X] > fillwidth) || (cur[Geom::Y] > fillheight)) { // off limits
1312                     continue;
1313                 }
1314             }
1316             gchar color_string[32]; *color_string = 0;
1318             // Color tab
1319             if (!initial_color.empty()) {
1320                 guint32 rgba = sp_svg_read_color (initial_color.data(), 0x000000ff);
1321                 float hsl[3];
1322                 sp_color_rgb_to_hsl_floatv (hsl, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba));
1324                 double eff_i = (color_alternatei? (i%2) : (i));
1325                 double eff_j = (color_alternatej? (j%2) : (j));
1327                 hsl[0] += hue_per_i * eff_i + hue_per_j * eff_j + hue_rand * g_random_double_range (-1, 1);
1328                 double notused;
1329                 hsl[0] = modf( hsl[0], &notused ); // Restrict to 0-1
1330                 hsl[1] += saturation_per_i * eff_i + saturation_per_j * eff_j + saturation_rand * g_random_double_range (-1, 1);
1331                 hsl[1] = CLAMP (hsl[1], 0, 1);
1332                 hsl[2] += lightness_per_i * eff_i + lightness_per_j * eff_j + lightness_rand * g_random_double_range (-1, 1);
1333                 hsl[2] = CLAMP (hsl[2], 0, 1);
1335                 float rgb[3];
1336                 sp_color_hsl_to_rgb_floatv (rgb, hsl[0], hsl[1], hsl[2]);
1337                 sp_svg_write_color(color_string, sizeof(color_string), SP_RGBA32_F_COMPOSE(rgb[0], rgb[1], rgb[2], 1.0));
1338             }
1340             // Blur
1341             double blur = 0.0;
1342             {
1343             int eff_i = (blur_alternatei? (i%2) : (i));
1344             int eff_j = (blur_alternatej? (j%2) : (j));
1345             blur =  (blur_per_i * eff_i + blur_per_j * eff_j + blur_rand * g_random_double_range (-1, 1));
1346             blur = CLAMP (blur, 0, 1);
1347             }
1349             // Opacity
1350             double opacity = 1.0;
1351             {
1352             int eff_i = (opacity_alternatei? (i%2) : (i));
1353             int eff_j = (opacity_alternatej? (j%2) : (j));
1354             opacity = 1 - (opacity_per_i * eff_i + opacity_per_j * eff_j + opacity_rand * g_random_double_range (-1, 1));
1355             opacity = CLAMP (opacity, 0, 1);
1356             }
1358             // Trace tab
1359             if (dotrace) {
1360                 Geom::Rect bbox_t = transform_rect (bbox_original, t);
1362                 guint32 rgba = clonetiler_trace_pick (bbox_t);
1363                 float r = SP_RGBA32_R_F(rgba);
1364                 float g = SP_RGBA32_G_F(rgba);
1365                 float b = SP_RGBA32_B_F(rgba);
1366                 float a = SP_RGBA32_A_F(rgba);
1368                 float hsl[3];
1369                 sp_color_rgb_to_hsl_floatv (hsl, r, g, b);
1371                 gdouble val = 0;
1372                 switch (pick) {
1373                 case PICK_COLOR:
1374                     val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max
1375                     break;
1376                 case PICK_OPACITY:
1377                     val = a;
1378                     break;
1379                 case PICK_R:
1380                     val = r;
1381                     break;
1382                 case PICK_G:
1383                     val = g;
1384                     break;
1385                 case PICK_B:
1386                     val = b;
1387                     break;
1388                 case PICK_H:
1389                     val = hsl[0];
1390                     break;
1391                 case PICK_S:
1392                     val = hsl[1];
1393                     break;
1394                 case PICK_L:
1395                     val = 1 - hsl[2];
1396                     break;
1397                 default:
1398                     break;
1399                 }
1401                 if (rand_picked > 0) {
1402                     val = randomize01 (val, rand_picked);
1403                     r = randomize01 (r, rand_picked);
1404                     g = randomize01 (g, rand_picked);
1405                     b = randomize01 (b, rand_picked);
1406                 }
1408                 if (gamma_picked != 0) {
1409                     double power;
1410                     if (gamma_picked > 0)
1411                         power = 1/(1 + fabs(gamma_picked));
1412                     else
1413                         power = 1 + fabs(gamma_picked);
1415                     val = pow (val, power);
1416                     r = pow (r, power);
1417                     g = pow (g, power);
1418                     b = pow (b, power);
1419                 }
1421                 if (invert_picked) {
1422                     val = 1 - val;
1423                     r = 1 - r;
1424                     g = 1 - g;
1425                     b = 1 - b;
1426                 }
1428                 val = CLAMP (val, 0, 1);
1429                 r = CLAMP (r, 0, 1);
1430                 g = CLAMP (g, 0, 1);
1431                 b = CLAMP (b, 0, 1);
1433                 // recompose tweaked color
1434                 rgba = SP_RGBA32_F_COMPOSE(r, g, b, a);
1436                 if (pick_to_presence) {
1437                     if (g_random_double_range (0, 1) > val) {
1438                         continue; // skip!
1439                     }
1440                 }
1441                 if (pick_to_size) {
1442                     t = Geom::Translate(-center[Geom::X], -center[Geom::Y]) * Geom::Scale (val, val) * Geom::Translate(center[Geom::X], center[Geom::Y]) * t;
1443                 }
1444                 if (pick_to_opacity) {
1445                     opacity *= val;
1446                 }
1447                 if (pick_to_color) {
1448                     sp_svg_write_color(color_string, sizeof(color_string), rgba);
1449                 }
1450             }
1452             if (opacity < 1e-6) { // invisibly transparent, skip
1453                     continue;
1454             }
1456             if (fabs(t[0]) + fabs (t[1]) + fabs(t[2]) + fabs(t[3]) < 1e-6) { // too small, skip
1457                     continue;
1458             }
1460             // Create the clone
1461             Inkscape::XML::Node *clone = obj_repr->document()->createElement("svg:use");
1462             clone->setAttribute("x", "0");
1463             clone->setAttribute("y", "0");
1464             clone->setAttribute("inkscape:tiled-clone-of", id_href);
1465             clone->setAttribute("xlink:href", id_href);
1467             Geom::Point new_center;
1468             bool center_set = false;
1469             if (obj_repr->attribute("inkscape:transform-center-x") || obj_repr->attribute("inkscape:transform-center-y")) {
1470                 new_center = desktop->dt2doc(SP_ITEM(obj)->getCenter()) * t;
1471                 center_set = true;
1472             }
1474             gchar *affinestr=sp_svg_transform_write(t);
1475             clone->setAttribute("transform", affinestr);
1476             g_free(affinestr);
1478             if (opacity < 1.0) {
1479                 sp_repr_set_css_double(clone, "opacity", opacity);
1480             }
1482             if (*color_string) {
1483                 clone->setAttribute("fill", color_string);
1484                 clone->setAttribute("stroke", color_string);
1485             }
1487             // add the new clone to the top of the original's parent
1488             SP_OBJECT_REPR(parent)->appendChild(clone);
1490             if (blur > 0.0) {
1491                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1492                 double perimeter = perimeter_original * t.descrim();
1493                 double radius = blur * perimeter;
1494                 // this is necessary for all newly added clones to have correct bboxes,
1495                 // otherwise filters won't work:
1496                 sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1497                 // it's hard to figure out exact width/height of the tile without having an object
1498                 // that we can take bbox of; however here we only need a lower bound so that blur
1499                 // margins are not too small, and the perimeter should work
1500                 SPFilter *constructed = new_filter_gaussian_blur(sp_desktop_document(desktop), radius, t.descrim(), t.expansionX(), t.expansionY(), perimeter, perimeter);
1501                 sp_style_set_property_url (clone_object, "filter", SP_OBJECT(constructed), false);
1502             }
1504             if (center_set) {
1505                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1506                 if (clone_object && SP_IS_ITEM(clone_object)) {
1507                     clone_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1508                     SP_ITEM(clone_object)->setCenter(desktop->doc2dt(new_center));
1509                     clone_object->updateRepr();
1510                 }
1511             }
1513             Inkscape::GC::release(clone);
1514         }
1515         cur[Geom::Y] = 0;
1516     }
1518     if (dotrace) {
1519         clonetiler_trace_finish ();
1520     }
1522     clonetiler_change_selection (NULL, selection, dlg);
1524     desktop->clearWaitingCursor();
1526     sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER,
1527                      _("Create tiled clones"));
1530 static GtkWidget *
1531 clonetiler_new_tab (GtkWidget *nb, const gchar *label)
1533     GtkWidget *l = gtk_label_new_with_mnemonic (label);
1534     GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN);
1535     gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN);
1536     gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l);
1537     return vb;
1540 static void
1541 clonetiler_checkbox_toggled (GtkToggleButton *tb, gpointer *data)
1543     const gchar *attr = (const gchar *) data;
1544     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1545     prefs->setBool(prefs_path + attr, gtk_toggle_button_get_active(tb));
1548 static GtkWidget *
1549 clonetiler_checkbox (GtkTooltips *tt, const char *tip, const char *attr)
1551     GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
1553     GtkWidget *b = gtk_check_button_new ();
1554     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, tip, NULL);
1556     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1557     bool value = prefs->getBool(prefs_path + attr);
1558     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(b), value);
1560     gtk_box_pack_end (GTK_BOX (hb), b, FALSE, TRUE, 0);
1561     gtk_signal_connect ( GTK_OBJECT (b), "clicked",
1562                          GTK_SIGNAL_FUNC (clonetiler_checkbox_toggled), (gpointer) attr);
1564     g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
1566     return hb;
1570 static void
1571 clonetiler_value_changed (GtkAdjustment *adj, gpointer data)
1573     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1574     const gchar *pref = (const gchar *) data;
1575     prefs->setDouble(prefs_path + pref, adj->value);
1578 static GtkWidget *
1579 clonetiler_spinbox (GtkTooltips *tt, const char *tip, const char *attr, double lower, double upper, const gchar *suffix, bool exponent = false)
1581     GtkWidget *hb = gtk_hbox_new(FALSE, 0);
1583     {
1584         GtkObject *a;
1585         if (exponent)
1586             a = gtk_adjustment_new(1.0, lower, upper, 0.01, 0.05, 0.1);
1587         else
1588             a = gtk_adjustment_new(0.0, lower, upper, 0.1, 0.5, 2);
1590         GtkWidget *sb;
1591         if (exponent)
1592             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.01, 2);
1593         else
1594             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.1, 1);
1596         gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, tip, NULL);
1597         gtk_entry_set_width_chars (GTK_ENTRY (sb), 4);
1598         gtk_box_pack_start (GTK_BOX (hb), sb, FALSE, FALSE, SB_MARGIN);
1600         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1601         double value = prefs->getDoubleLimited(prefs_path + attr, exponent? 1.0 : 0.0, lower, upper);
1602         gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
1603         gtk_signal_connect(GTK_OBJECT(a), "value_changed",
1604                            GTK_SIGNAL_FUNC(clonetiler_value_changed), (gpointer) attr);
1606         if (exponent)
1607             g_object_set_data (G_OBJECT(sb), "oneable", GINT_TO_POINTER(TRUE));
1608         else
1609             g_object_set_data (G_OBJECT(sb), "zeroable", GINT_TO_POINTER(TRUE));
1610     }
1612     {
1613         GtkWidget *l = gtk_label_new ("");
1614         gtk_label_set_markup (GTK_LABEL(l), suffix);
1615         gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0);
1616         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
1617     }
1619     return hb;
1622 static void
1623 clonetiler_symgroup_changed( GtkMenuItem */*item*/, gpointer data )
1625     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1626     gint group_new = GPOINTER_TO_INT (data);
1627     prefs->setInt(prefs_path + "symmetrygroup", group_new);
1630 static void
1631 clonetiler_xy_changed (GtkAdjustment *adj, gpointer data)
1633     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1634     const gchar *pref = (const gchar *) data;
1635     prefs->setInt(prefs_path + pref, (int) floor(adj->value + 0.5));
1638 static void
1639 clonetiler_keep_bbox_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1641     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1642     prefs->setBool(prefs_path + "keepbbox", gtk_toggle_button_get_active(tb));
1645 static void
1646 clonetiler_pick_to (GtkToggleButton *tb, gpointer data)
1648     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1649     const gchar *pref = (const gchar *) data;
1650     prefs->setBool(prefs_path + pref, gtk_toggle_button_get_active(tb));
1654 static void
1655 clonetiler_reset_recursive (GtkWidget *w)
1657     if (w && GTK_IS_OBJECT(w)) {
1658         {
1659             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "zeroable"));
1660             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1661                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1662                 gtk_adjustment_set_value (a, 0);
1663             }
1664         }
1665         {
1666             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "oneable"));
1667             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1668                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1669                 gtk_adjustment_set_value (a, 1);
1670             }
1671         }
1672         {
1673             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "uncheckable"));
1674             if (r && GTK_IS_TOGGLE_BUTTON(w)) { // checkbox
1675                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(w), FALSE);
1676             }
1677         }
1678     }
1680     if (GTK_IS_CONTAINER(w)) {
1681         GList *ch = gtk_container_get_children (GTK_CONTAINER(w));
1682         for (GList *i = ch; i != NULL; i = i->next) {
1683             clonetiler_reset_recursive (GTK_WIDGET(i->data));
1684         }
1685         g_list_free (ch);
1686     }
1689 static void
1690 clonetiler_reset( GtkWidget */*widget*/, void * )
1692     clonetiler_reset_recursive (dlg);
1695 static void
1696 clonetiler_table_attach (GtkWidget *table, GtkWidget *widget, float align, int row, int col)
1698     GtkWidget *a = gtk_alignment_new (align, 0, 0, 0);
1699     gtk_container_add(GTK_CONTAINER(a), widget);
1700     gtk_table_attach ( GTK_TABLE (table), a, col, col + 1, row, row + 1, (GtkAttachOptions)4, (GtkAttachOptions)0, 0, 0 );
1703 static GtkWidget *
1704 clonetiler_table_x_y_rand (int values)
1706     GtkWidget *table = gtk_table_new (values + 2, 5, FALSE);
1707     gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
1708     gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1709     gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1711     {
1712         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1714         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "clonetiler_per_row");
1715         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1717         GtkWidget *l = gtk_label_new ("");
1718         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per row:</small>"));
1719         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1721         clonetiler_table_attach (table, hb, 0, 1, 2);
1722     }
1724     {
1725         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1727         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "clonetiler_per_column");
1728         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1730         GtkWidget *l = gtk_label_new ("");
1731         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per column:</small>"));
1732         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1734         clonetiler_table_attach (table, hb, 0, 1, 3);
1735     }
1737     {
1738         GtkWidget *l = gtk_label_new ("");
1739         gtk_label_set_markup (GTK_LABEL(l), _("<small>Randomize:</small>"));
1740         clonetiler_table_attach (table, l, 0, 1, 4);
1741     }
1743     return table;
1746 static void
1747 clonetiler_pick_switched( GtkToggleButton */*tb*/, gpointer data )
1749     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1750     guint v = GPOINTER_TO_INT (data);
1751     prefs->setInt(prefs_path + "pick", v);
1755 static void
1756 clonetiler_switch_to_create( GtkToggleButton */*tb*/, GtkWidget *dlg )
1758     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1759     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1761     if (rowscols) {
1762         gtk_widget_set_sensitive (rowscols, TRUE);
1763     }
1764     if (widthheight) {
1765         gtk_widget_set_sensitive (widthheight, FALSE);
1766     }
1768     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1769     prefs->setBool(prefs_path + "fillrect", false);
1773 static void
1774 clonetiler_switch_to_fill( GtkToggleButton */*tb*/, GtkWidget *dlg )
1776     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1777     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1779     if (rowscols) {
1780         gtk_widget_set_sensitive (rowscols, FALSE);
1781     }
1782     if (widthheight) {
1783         gtk_widget_set_sensitive (widthheight, TRUE);
1784     }
1786     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1787     prefs->setBool(prefs_path + "fillrect", true);
1793 static void
1794 clonetiler_fill_width_changed (GtkAdjustment *adj, GtkWidget *u)
1796     gdouble const raw_dist = adj->value;
1797     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1798     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1800     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1801     prefs->setDouble(prefs_path + "fillwidth", pixels);
1804 static void
1805 clonetiler_fill_height_changed (GtkAdjustment *adj, GtkWidget *u)
1807     gdouble const raw_dist = adj->value;
1808     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1809     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1811     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1812     prefs->setDouble(prefs_path + "fillheight", pixels);
1816 static void
1817 clonetiler_do_pick_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1819     GtkWidget *vvb = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "dotrace");
1821     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1822     prefs->setBool(prefs_path + "dotrace", gtk_toggle_button_get_active (tb));
1824     if (vvb)
1825         gtk_widget_set_sensitive (vvb, gtk_toggle_button_get_active (tb));
1831 void
1832 clonetiler_dialog (void)
1834     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1835     if (!dlg)
1836     {
1837         gchar title[500];
1838         sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_CLONETILER), title);
1840         dlg = sp_window_new (title, TRUE);
1841         if (x == -1000 || y == -1000) {
1842             x = prefs->getInt(prefs_path + "x", -1000);
1843             y = prefs->getInt(prefs_path + "y", -1000);
1844         }
1846         if (w ==0 || h == 0) {
1847             w = prefs->getInt(prefs_path + "w", 0);
1848             h = prefs->getInt(prefs_path + "h", 0);
1849         }
1851 //        if (x<0) x=0;
1852 //        if (y<0) y=0;
1854         if (w && h) {
1855             gtk_window_resize ((GtkWindow *) dlg, w, h);
1856         }
1857         if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) {
1858             gtk_window_move ((GtkWindow *) dlg, x, y);
1860         } else {
1861             gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
1862         }
1865         sp_transientize (dlg);
1866         wd.win = dlg;
1867         wd.stop = 0;
1870         gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);
1872         gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (clonetiler_dialog_destroy), dlg);
1873         gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (clonetiler_dialog_delete), dlg);
1875         if (Inkscape::NSApplication::Application::getNewGui())
1876         {
1877             _shutdown_connection = Inkscape::NSApplication::Editor::connectShutdown (&on_delete);
1878             _dialogs_hidden_connection = Inkscape::NSApplication::Editor::connectDialogsHidden (sigc::bind (&on_dialog_hide, dlg));
1879             _dialogs_unhidden_connection = Inkscape::NSApplication::Editor::connectDialogsUnhidden (sigc::bind (&on_dialog_unhide, dlg));
1880             _desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::bind (&on_transientize, &wd));
1881         } else {
1882             g_signal_connect   ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (clonetiler_dialog_delete), dlg);
1883             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg);
1884             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg);
1885             g_signal_connect   ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd);
1886         }
1888         GtkTooltips *tt = gtk_tooltips_new();
1890         GtkWidget *mainbox = gtk_vbox_new(FALSE, 4);
1891         gtk_container_set_border_width (GTK_CONTAINER (mainbox), 6);
1892         gtk_container_add (GTK_CONTAINER (dlg), mainbox);
1894         GtkWidget *nb = gtk_notebook_new ();
1895         gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0);
1898 // Symmetry
1899         {
1900             GtkWidget *vb = clonetiler_new_tab (nb, _("_Symmetry"));
1902             GtkWidget *om = gtk_option_menu_new ();
1903             /* TRANSLATORS: For the following 17 symmetry groups, see
1904              * http://www.bib.ulb.ac.be/coursmath/doc/17.htm (visual examples);
1905              * http://www.clarku.edu/~djoyce/wallpaper/seventeen.html (English vocabulary); or
1906              * http://membres.lycos.fr/villemingerard/Geometri/Sym1D.htm (French vocabulary).
1907              */
1908             gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), om, _("Select one of the 17 symmetry groups for the tiling"), NULL);
1909             gtk_box_pack_start (GTK_BOX (vb), om, FALSE, FALSE, SB_MARGIN);
1911             GtkWidget *m = gtk_menu_new ();
1912             int current = prefs->getInt(prefs_path + "symmetrygroup", 0);
1914             struct SymGroups {
1915                 int group;
1916                 gchar const *label;
1917             } const sym_groups[] = {
1918                 // TRANSLATORS: "translation" means "shift" / "displacement" here.
1919                 {TILE_P1, _("<b>P1</b>: simple translation")},
1920                 {TILE_P2, _("<b>P2</b>: 180&#176; rotation")},
1921                 {TILE_PM, _("<b>PM</b>: reflection")},
1922                 // TRANSLATORS: "glide reflection" is a reflection and a translation combined.
1923                 //  For more info, see http://mathforum.org/sum95/suzanne/symsusan.html
1924                 {TILE_PG, _("<b>PG</b>: glide reflection")},
1925                 {TILE_CM, _("<b>CM</b>: reflection + glide reflection")},
1926                 {TILE_PMM, _("<b>PMM</b>: reflection + reflection")},
1927                 {TILE_PMG, _("<b>PMG</b>: reflection + 180&#176; rotation")},
1928                 {TILE_PGG, _("<b>PGG</b>: glide reflection + 180&#176; rotation")},
1929                 {TILE_CMM, _("<b>CMM</b>: reflection + reflection + 180&#176; rotation")},
1930                 {TILE_P4, _("<b>P4</b>: 90&#176; rotation")},
1931                 {TILE_P4M, _("<b>P4M</b>: 90&#176; rotation + 45&#176; reflection")},
1932                 {TILE_P4G, _("<b>P4G</b>: 90&#176; rotation + 90&#176; reflection")},
1933                 {TILE_P3, _("<b>P3</b>: 120&#176; rotation")},
1934                 {TILE_P31M, _("<b>P31M</b>: reflection + 120&#176; rotation, dense")},
1935                 {TILE_P3M1, _("<b>P3M1</b>: reflection + 120&#176; rotation, sparse")},
1936                 {TILE_P6, _("<b>P6</b>: 60&#176; rotation")},
1937                 {TILE_P6M, _("<b>P6M</b>: reflection + 60&#176; rotation")},
1938             };
1940             for (unsigned j = 0; j < G_N_ELEMENTS(sym_groups); ++j) {
1941                 SymGroups const &sg = sym_groups[j];
1943                 GtkWidget *l = gtk_label_new ("");
1944                 gtk_label_set_markup (GTK_LABEL(l), sg.label);
1945                 gtk_misc_set_alignment (GTK_MISC(l), 0, 0.5);
1947                 GtkWidget *item = gtk_menu_item_new ();
1948                 gtk_container_add (GTK_CONTAINER (item), l);
1950                 gtk_signal_connect ( GTK_OBJECT (item), "activate",
1951                                      GTK_SIGNAL_FUNC (clonetiler_symgroup_changed),
1952                                      GINT_TO_POINTER (sg.group) );
1954                 gtk_menu_append (GTK_MENU (m), item);
1955             }
1957             gtk_option_menu_set_menu (GTK_OPTION_MENU (om), m);
1958             gtk_option_menu_set_history ( GTK_OPTION_MENU (om), current);
1959         }
1961         table_row_labels = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1963 // Shift
1964         {
1965             GtkWidget *vb = clonetiler_new_tab (nb, _("S_hift"));
1967             GtkWidget *table = clonetiler_table_x_y_rand (3);
1968             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1970             // X
1971             {
1972                 GtkWidget *l = gtk_label_new ("");
1973                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) horizontally by this amount
1974                     // xgettext:no-c-format
1975                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift X:</b>"));
1976                 gtk_size_group_add_widget(table_row_labels, l);
1977                 clonetiler_table_attach (table, l, 1, 2, 1);
1978             }
1980             {
1981                 GtkWidget *l = clonetiler_spinbox (tt,
1982                     // xgettext:no-c-format
1983                                                    _("Horizontal shift per row (in % of tile width)"), "shiftx_per_j",
1984                                                    -10000, 10000, "%");
1985                 clonetiler_table_attach (table, l, 0, 2, 2);
1986             }
1988             {
1989                 GtkWidget *l = clonetiler_spinbox (tt,
1990                     // xgettext:no-c-format
1991                                                    _("Horizontal shift per column (in % of tile width)"), "shiftx_per_i",
1992                                                    -10000, 10000, "%");
1993                 clonetiler_table_attach (table, l, 0, 2, 3);
1994             }
1996             {
1997                 GtkWidget *l = clonetiler_spinbox (tt,
1998                                                    _("Randomize the horizontal shift by this percentage"), "shiftx_rand",
1999                                                    0, 1000, "%");
2000                 clonetiler_table_attach (table, l, 0, 2, 4);
2001             }
2003             // Y
2004             {
2005                 GtkWidget *l = gtk_label_new ("");
2006                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) vertically by this amount
2007                     // xgettext:no-c-format
2008                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift Y:</b>"));
2009                 gtk_size_group_add_widget(table_row_labels, l);
2010                 clonetiler_table_attach (table, l, 1, 3, 1);
2011             }
2013             {
2014                 GtkWidget *l = clonetiler_spinbox (tt,
2015                     // xgettext:no-c-format
2016                                                    _("Vertical shift per row (in % of tile height)"), "shifty_per_j",
2017                                                    -10000, 10000, "%");
2018                 clonetiler_table_attach (table, l, 0, 3, 2);
2019             }
2021             {
2022                 GtkWidget *l = clonetiler_spinbox (tt,
2023                     // xgettext:no-c-format
2024                                                    _("Vertical shift per column (in % of tile height)"), "shifty_per_i",
2025                                                    -10000, 10000, "%");
2026                 clonetiler_table_attach (table, l, 0, 3, 3);
2027             }
2029             {
2030                 GtkWidget *l = clonetiler_spinbox (tt,
2031                                                    _("Randomize the vertical shift by this percentage"), "shifty_rand",
2032                                                    0, 1000, "%");
2033                 clonetiler_table_attach (table, l, 0, 3, 4);
2034             }
2036             // Exponent
2037             {
2038                 GtkWidget *l = gtk_label_new ("");
2039                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2040                 gtk_size_group_add_widget(table_row_labels, l);
2041                 clonetiler_table_attach (table, l, 1, 4, 1);
2042             }
2044             {
2045                 GtkWidget *l = clonetiler_spinbox (tt,
2046                                                    _("Whether rows are spaced evenly (1), converge (<1) or diverge (>1)"), "shifty_exp",
2047                                                    0, 10, "", true);
2048                 clonetiler_table_attach (table, l, 0, 4, 2);
2049             }
2051             {
2052                 GtkWidget *l = clonetiler_spinbox (tt,
2053                                                    _("Whether columns are spaced evenly (1), converge (<1) or diverge (>1)"), "shiftx_exp",
2054                                                    0, 10, "", true);
2055                 clonetiler_table_attach (table, l, 0, 4, 3);
2056             }
2058             { // alternates
2059                 GtkWidget *l = gtk_label_new ("");
2060                 // TRANSLATORS: "Alternate" is a verb here
2061                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2062                 gtk_size_group_add_widget(table_row_labels, l);
2063                 clonetiler_table_attach (table, l, 1, 5, 1);
2064             }
2066             {
2067                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each row"), "shifty_alternate");
2068                 clonetiler_table_attach (table, l, 0, 5, 2);
2069             }
2071             {
2072                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each column"), "shiftx_alternate");
2073                 clonetiler_table_attach (table, l, 0, 5, 3);
2074             }
2076             { // Cumulate
2077                 GtkWidget *l = gtk_label_new ("");
2078                 // TRANSLATORS: "Cumulate" is a verb here
2079                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2080                 gtk_size_group_add_widget(table_row_labels, l);
2081                 clonetiler_table_attach (table, l, 1, 6, 1);
2082             }
2084             {
2085                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each row"), "shifty_cumulate");
2086                 clonetiler_table_attach (table, l, 0, 6, 2);
2087             }
2089             {
2090                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each column"), "shiftx_cumulate");
2091                 clonetiler_table_attach (table, l, 0, 6, 3);
2092             }
2094             { // Exclude tile width and height in shift
2095                 GtkWidget *l = gtk_label_new ("");
2096                 // TRANSLATORS: "Cumulate" is a verb here
2097                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Exclude tile:</small>"));
2098                 gtk_size_group_add_widget(table_row_labels, l);
2099                 clonetiler_table_attach (table, l, 1, 7, 1);
2100             }
2102             {
2103                 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile height in shift"), "shifty_excludeh");
2104                 clonetiler_table_attach (table, l, 0, 7, 2);
2105             }
2107             {
2108                 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile width in shift"), "shiftx_excludew");
2109                 clonetiler_table_attach (table, l, 0, 7, 3);
2110             }
2112         }
2115 // Scale
2116         {
2117             GtkWidget *vb = clonetiler_new_tab (nb, _("Sc_ale"));
2119             GtkWidget *table = clonetiler_table_x_y_rand (2);
2120             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2122             // X
2123             {
2124                 GtkWidget *l = gtk_label_new ("");
2125                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale X:</b>"));
2126                 gtk_size_group_add_widget(table_row_labels, l);
2127                 clonetiler_table_attach (table, l, 1, 2, 1);
2128             }
2130             {
2131                 GtkWidget *l = clonetiler_spinbox (tt,
2132                     // xgettext:no-c-format
2133                                                    _("Horizontal scale per row (in % of tile width)"), "scalex_per_j",
2134                                                    -100, 1000, "%");
2135                 clonetiler_table_attach (table, l, 0, 2, 2);
2136             }
2138             {
2139                 GtkWidget *l = clonetiler_spinbox (tt,
2140                     // xgettext:no-c-format
2141                                                    _("Horizontal scale per column (in % of tile width)"), "scalex_per_i",
2142                                                    -100, 1000, "%");
2143                 clonetiler_table_attach (table, l, 0, 2, 3);
2144             }
2146             {
2147                 GtkWidget *l = clonetiler_spinbox (tt,
2148                                                    _("Randomize the horizontal scale by this percentage"), "scalex_rand",
2149                                                    0, 1000, "%");
2150                 clonetiler_table_attach (table, l, 0, 2, 4);
2151             }
2153             // Y
2154             {
2155                 GtkWidget *l = gtk_label_new ("");
2156                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale Y:</b>"));
2157                 gtk_size_group_add_widget(table_row_labels, l);
2158                 clonetiler_table_attach (table, l, 1, 3, 1);
2159             }
2161             {
2162                 GtkWidget *l = clonetiler_spinbox (tt,
2163                     // xgettext:no-c-format
2164                                                    _("Vertical scale per row (in % of tile height)"), "scaley_per_j",
2165                                                    -100, 1000, "%");
2166                 clonetiler_table_attach (table, l, 0, 3, 2);
2167             }
2169             {
2170                 GtkWidget *l = clonetiler_spinbox (tt,
2171                     // xgettext:no-c-format
2172                                                    _("Vertical scale per column (in % of tile height)"), "scaley_per_i",
2173                                                    -100, 1000, "%");
2174                 clonetiler_table_attach (table, l, 0, 3, 3);
2175             }
2177             {
2178                 GtkWidget *l = clonetiler_spinbox (tt,
2179                                                    _("Randomize the vertical scale by this percentage"), "scaley_rand",
2180                                                    0, 1000, "%");
2181                 clonetiler_table_attach (table, l, 0, 3, 4);
2182             }
2184             // Exponent
2185             {
2186                 GtkWidget *l = gtk_label_new ("");
2187                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2188                 gtk_size_group_add_widget(table_row_labels, l);
2189                 clonetiler_table_attach (table, l, 1, 4, 1);
2190             }
2192             {
2193                 GtkWidget *l = clonetiler_spinbox (tt,
2194                                                    _("Whether row scaling is uniform (1), converge (<1) or diverge (>1)"), "scaley_exp",
2195                                                    0, 10, "", true);
2196                 clonetiler_table_attach (table, l, 0, 4, 2);
2197             }
2199             {
2200                 GtkWidget *l = clonetiler_spinbox (tt,
2201                                                    _("Whether column scaling is uniform (1), converge (<1) or diverge (>1)"), "scalex_exp",
2202                                                    0, 10, "", true);
2203                 clonetiler_table_attach (table, l, 0, 4, 3);
2204             }
2206             // Logarithmic (as in logarithmic spiral)
2207             {
2208                 GtkWidget *l = gtk_label_new ("");
2209                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Base:</b>"));
2210                 gtk_size_group_add_widget(table_row_labels, l);
2211                 clonetiler_table_attach (table, l, 1, 5, 1);
2212             }
2214             {
2215                 GtkWidget *l = clonetiler_spinbox (tt,
2216                                                    _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scaley_log",
2217                                                    0, 10, "", false);
2218                 clonetiler_table_attach (table, l, 0, 5, 2);
2219             }
2221             {
2222                 GtkWidget *l = clonetiler_spinbox (tt,
2223                                                    _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scalex_log",
2224                                                    0, 10, "", false);
2225                 clonetiler_table_attach (table, l, 0, 5, 3);
2226             }
2228             { // alternates
2229                 GtkWidget *l = gtk_label_new ("");
2230                 // TRANSLATORS: "Alternate" is a verb here
2231                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2232                 gtk_size_group_add_widget(table_row_labels, l);
2233                 clonetiler_table_attach (table, l, 1, 6, 1);
2234             }
2236             {
2237                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each row"), "scaley_alternate");
2238                 clonetiler_table_attach (table, l, 0, 6, 2);
2239             }
2241             {
2242                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each column"), "scalex_alternate");
2243                 clonetiler_table_attach (table, l, 0, 6, 3);
2244             }
2246             { // Cumulate
2247                 GtkWidget *l = gtk_label_new ("");
2248                 // TRANSLATORS: "Cumulate" is a verb here
2249                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2250                 gtk_size_group_add_widget(table_row_labels, l);
2251                 clonetiler_table_attach (table, l, 1, 7, 1);
2252             }
2254             {
2255                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each row"), "scaley_cumulate");
2256                 clonetiler_table_attach (table, l, 0, 7, 2);
2257             }
2259             {
2260                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each column"), "scalex_cumulate");
2261                 clonetiler_table_attach (table, l, 0, 7, 3);
2262             }
2264         }
2267 // Rotation
2268         {
2269             GtkWidget *vb = clonetiler_new_tab (nb, _("_Rotation"));
2271             GtkWidget *table = clonetiler_table_x_y_rand (1);
2272             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2274             // Angle
2275             {
2276                 GtkWidget *l = gtk_label_new ("");
2277                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Angle:</b>"));
2278                 gtk_size_group_add_widget(table_row_labels, l);
2279                 clonetiler_table_attach (table, l, 1, 2, 1);
2280             }
2282             {
2283                 GtkWidget *l = clonetiler_spinbox (tt,
2284                     // xgettext:no-c-format
2285                                                    _("Rotate tiles by this angle for each row"), "rotate_per_j",
2286                                                    -180, 180, "&#176;");
2287                 clonetiler_table_attach (table, l, 0, 2, 2);
2288             }
2290             {
2291                 GtkWidget *l = clonetiler_spinbox (tt,
2292                     // xgettext:no-c-format
2293                                                    _("Rotate tiles by this angle for each column"), "rotate_per_i",
2294                                                    -180, 180, "&#176;");
2295                 clonetiler_table_attach (table, l, 0, 2, 3);
2296             }
2298             {
2299                 GtkWidget *l = clonetiler_spinbox (tt,
2300                                                    _("Randomize the rotation angle by this percentage"), "rotate_rand",
2301                                                    0, 100, "%");
2302                 clonetiler_table_attach (table, l, 0, 2, 4);
2303             }
2305             { // alternates
2306                 GtkWidget *l = gtk_label_new ("");
2307                 // TRANSLATORS: "Alternate" is a verb here
2308                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2309                 gtk_size_group_add_widget(table_row_labels, l);
2310                 clonetiler_table_attach (table, l, 1, 3, 1);
2311             }
2313             {
2314                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each row"), "rotate_alternatej");
2315                 clonetiler_table_attach (table, l, 0, 3, 2);
2316             }
2318             {
2319                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each column"), "rotate_alternatei");
2320                 clonetiler_table_attach (table, l, 0, 3, 3);
2321             }
2323             { // Cumulate
2324                 GtkWidget *l = gtk_label_new ("");
2325                 // TRANSLATORS: "Cumulate" is a verb here
2326                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2327                 gtk_size_group_add_widget(table_row_labels, l);
2328                 clonetiler_table_attach (table, l, 1, 4, 1);
2329             }
2331             {
2332                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each row"), "rotate_cumulatej");
2333                 clonetiler_table_attach (table, l, 0, 4, 2);
2334             }
2336             {
2337                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each column"), "rotate_cumulatei");
2338                 clonetiler_table_attach (table, l, 0, 4, 3);
2339             }
2341         }
2344 // Blur and opacity
2345         {
2346             GtkWidget *vb = clonetiler_new_tab (nb, _("_Blur & opacity"));
2348             GtkWidget *table = clonetiler_table_x_y_rand (1);
2349             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2352             // Blur
2353             {
2354                 GtkWidget *l = gtk_label_new ("");
2355                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Blur:</b>"));
2356                 gtk_size_group_add_widget(table_row_labels, l);
2357                 clonetiler_table_attach (table, l, 1, 2, 1);
2358             }
2360             {
2361                 GtkWidget *l = clonetiler_spinbox (tt,
2362                                                    _("Blur tiles by this percentage for each row"), "blur_per_j",
2363                                                    0, 100, "%");
2364                 clonetiler_table_attach (table, l, 0, 2, 2);
2365             }
2367             {
2368                 GtkWidget *l = clonetiler_spinbox (tt,
2369                                                    _("Blur tiles by this percentage for each column"), "blur_per_i",
2370                                                    0, 100, "%");
2371                 clonetiler_table_attach (table, l, 0, 2, 3);
2372             }
2374             {
2375                 GtkWidget *l = clonetiler_spinbox (tt,
2376                                                    _("Randomize the tile blur by this percentage"), "blur_rand",
2377                                                    0, 100, "%");
2378                 clonetiler_table_attach (table, l, 0, 2, 4);
2379             }
2381             { // alternates
2382                 GtkWidget *l = gtk_label_new ("");
2383                 // TRANSLATORS: "Alternate" is a verb here
2384                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2385                 gtk_size_group_add_widget(table_row_labels, l);
2386                 clonetiler_table_attach (table, l, 1, 3, 1);
2387             }
2389             {
2390                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each row"), "blur_alternatej");
2391                 clonetiler_table_attach (table, l, 0, 3, 2);
2392             }
2394             {
2395                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each column"), "blur_alternatei");
2396                 clonetiler_table_attach (table, l, 0, 3, 3);
2397             }
2401             // Dissolve
2402             {
2403                 GtkWidget *l = gtk_label_new ("");
2404                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Fade out:</b>"));
2405                 gtk_size_group_add_widget(table_row_labels, l);
2406                 clonetiler_table_attach (table, l, 1, 4, 1);
2407             }
2409             {
2410                 GtkWidget *l = clonetiler_spinbox (tt,
2411                                                    _("Decrease tile opacity by this percentage for each row"), "opacity_per_j",
2412                                                    0, 100, "%");
2413                 clonetiler_table_attach (table, l, 0, 4, 2);
2414             }
2416             {
2417                 GtkWidget *l = clonetiler_spinbox (tt,
2418                                                    _("Decrease tile opacity by this percentage for each column"), "opacity_per_i",
2419                                                    0, 100, "%");
2420                 clonetiler_table_attach (table, l, 0, 4, 3);
2421             }
2423             {
2424                 GtkWidget *l = clonetiler_spinbox (tt,
2425                                                    _("Randomize the tile opacity by this percentage"), "opacity_rand",
2426                                                    0, 100, "%");
2427                 clonetiler_table_attach (table, l, 0, 4, 4);
2428             }
2430             { // alternates
2431                 GtkWidget *l = gtk_label_new ("");
2432                 // TRANSLATORS: "Alternate" is a verb here
2433                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2434                 gtk_size_group_add_widget(table_row_labels, l);
2435                 clonetiler_table_attach (table, l, 1, 5, 1);
2436             }
2438             {
2439                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each row"), "opacity_alternatej");
2440                 clonetiler_table_attach (table, l, 0, 5, 2);
2441             }
2443             {
2444                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each column"), "opacity_alternatei");
2445                 clonetiler_table_attach (table, l, 0, 5, 3);
2446             }
2447         }
2450 // Color
2451         {
2452             GtkWidget *vb = clonetiler_new_tab (nb, _("Co_lor"));
2454             {
2455             GtkWidget *hb = gtk_hbox_new (FALSE, 0);
2457             GtkWidget *l = gtk_label_new (_("Initial color: "));
2458             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2460             guint32 rgba = 0x000000ff | sp_svg_read_color (prefs->getString(prefs_path + "initial_color").data(), 0x000000ff);
2461             color_picker = new Inkscape::UI::Widget::ColorPicker (*new Glib::ustring(_("Initial color of tiled clones")), *new Glib::ustring(_("Initial color for clones (works only if the original has unset fill or stroke)")), rgba, false);
2462             _color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed));
2464             gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast<GtkWidget*>(color_picker->gobj()), FALSE, FALSE, 0);
2466             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2467             }
2470             GtkWidget *table = clonetiler_table_x_y_rand (3);
2471             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2473             // Hue
2474             {
2475                 GtkWidget *l = gtk_label_new ("");
2476                 gtk_label_set_markup (GTK_LABEL(l), _("<b>H:</b>"));
2477                 gtk_size_group_add_widget(table_row_labels, l);
2478                 clonetiler_table_attach (table, l, 1, 2, 1);
2479             }
2481             {
2482                 GtkWidget *l = clonetiler_spinbox (tt,
2483                                                    _("Change the tile hue by this percentage for each row"), "hue_per_j",
2484                                                    -100, 100, "%");
2485                 clonetiler_table_attach (table, l, 0, 2, 2);
2486             }
2488             {
2489                 GtkWidget *l = clonetiler_spinbox (tt,
2490                                                    _("Change the tile hue by this percentage for each column"), "hue_per_i",
2491                                                    -100, 100, "%");
2492                 clonetiler_table_attach (table, l, 0, 2, 3);
2493             }
2495             {
2496                 GtkWidget *l = clonetiler_spinbox (tt,
2497                                                    _("Randomize the tile hue by this percentage"), "hue_rand",
2498                                                    0, 100, "%");
2499                 clonetiler_table_attach (table, l, 0, 2, 4);
2500             }
2503             // Saturation
2504             {
2505                 GtkWidget *l = gtk_label_new ("");
2506                 gtk_label_set_markup (GTK_LABEL(l), _("<b>S:</b>"));
2507                 gtk_size_group_add_widget(table_row_labels, l);
2508                 clonetiler_table_attach (table, l, 1, 3, 1);
2509             }
2511             {
2512                 GtkWidget *l = clonetiler_spinbox (tt,
2513                                                    _("Change the color saturation by this percentage for each row"), "saturation_per_j",
2514                                                    -100, 100, "%");
2515                 clonetiler_table_attach (table, l, 0, 3, 2);
2516             }
2518             {
2519                 GtkWidget *l = clonetiler_spinbox (tt,
2520                                                    _("Change the color saturation by this percentage for each column"), "saturation_per_i",
2521                                                    -100, 100, "%");
2522                 clonetiler_table_attach (table, l, 0, 3, 3);
2523             }
2525             {
2526                 GtkWidget *l = clonetiler_spinbox (tt,
2527                                                    _("Randomize the color saturation by this percentage"), "saturation_rand",
2528                                                    0, 100, "%");
2529                 clonetiler_table_attach (table, l, 0, 3, 4);
2530             }
2532             // Lightness
2533             {
2534                 GtkWidget *l = gtk_label_new ("");
2535                 gtk_label_set_markup (GTK_LABEL(l), _("<b>L:</b>"));
2536                 gtk_size_group_add_widget(table_row_labels, l);
2537                 clonetiler_table_attach (table, l, 1, 4, 1);
2538             }
2540             {
2541                 GtkWidget *l = clonetiler_spinbox (tt,
2542                                                    _("Change the color lightness by this percentage for each row"), "lightness_per_j",
2543                                                    -100, 100, "%");
2544                 clonetiler_table_attach (table, l, 0, 4, 2);
2545             }
2547             {
2548                 GtkWidget *l = clonetiler_spinbox (tt,
2549                                                    _("Change the color lightness by this percentage for each column"), "lightness_per_i",
2550                                                    -100, 100, "%");
2551                 clonetiler_table_attach (table, l, 0, 4, 3);
2552             }
2554             {
2555                 GtkWidget *l = clonetiler_spinbox (tt,
2556                                                    _("Randomize the color lightness by this percentage"), "lightness_rand",
2557                                                    0, 100, "%");
2558                 clonetiler_table_attach (table, l, 0, 4, 4);
2559             }
2562             { // alternates
2563                 GtkWidget *l = gtk_label_new ("");
2564                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2565                 gtk_size_group_add_widget(table_row_labels, l);
2566                 clonetiler_table_attach (table, l, 1, 5, 1);
2567             }
2569             {
2570                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each row"), "color_alternatej");
2571                 clonetiler_table_attach (table, l, 0, 5, 2);
2572             }
2574             {
2575                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each column"), "color_alternatei");
2576                 clonetiler_table_attach (table, l, 0, 5, 3);
2577             }
2579         }
2581 // Trace
2582         {
2583             GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace"));
2586         {
2587             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2588             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2590             GtkWidget *b  = gtk_check_button_new_with_label (_("Trace the drawing under the tiles"));
2591             g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
2592             bool old = prefs->getBool(prefs_path + "dotrace");
2593             gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2594             gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("For each clone, pick a value from the drawing in that clone's location and apply it to the clone"), NULL);
2595             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2597             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2598                                GTK_SIGNAL_FUNC(clonetiler_do_pick_toggled), dlg);
2599         }
2601         {
2602             GtkWidget *vvb = gtk_vbox_new (FALSE, 0);
2603             gtk_box_pack_start (GTK_BOX (vb), vvb, FALSE, FALSE, 0);
2604             g_object_set_data (G_OBJECT(dlg), "dotrace", (gpointer) vvb);
2607             {
2608                 GtkWidget *frame = gtk_frame_new (_("1. Pick from the drawing:"));
2609                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2611                 GtkWidget *table = gtk_table_new (3, 3, FALSE);
2612                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2613                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2614                 gtk_container_add(GTK_CONTAINER(frame), table);
2617                 GtkWidget* radio;
2618                 {
2619                     radio = gtk_radio_button_new_with_label (NULL, _("Color"));
2620                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the visible color and opacity"), NULL);
2621                     clonetiler_table_attach (table, radio, 0.0, 1, 1);
2622                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2623                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_COLOR));
2624                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_COLOR);
2625                 }
2626                 {
2627                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Opacity"));
2628                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the total accumulated opacity"), NULL);
2629                     clonetiler_table_attach (table, radio, 0.0, 2, 1);
2630                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2631                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_OPACITY));
2632                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_OPACITY);
2633                 }
2634                 {
2635                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("R"));
2636                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Red component of the color"), NULL);
2637                     clonetiler_table_attach (table, radio, 0.0, 1, 2);
2638                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2639                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_R));
2640                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_R);
2641                 }
2642                 {
2643                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("G"));
2644                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Green component of the color"), NULL);
2645                     clonetiler_table_attach (table, radio, 0.0, 2, 2);
2646                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2647                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_G));
2648                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_G);
2649                 }
2650                 {
2651                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("B"));
2652                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Blue component of the color"), NULL);
2653                     clonetiler_table_attach (table, radio, 0.0, 3, 2);
2654                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2655                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_B));
2656                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_B);
2657                 }
2658                 {
2659                     //TRANSLATORS: only translate "string" in "context|string".
2660                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2661                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|H"));
2662                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the hue of the color"), NULL);
2663                     clonetiler_table_attach (table, radio, 0.0, 1, 3);
2664                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2665                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_H));
2666                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_H);
2667                 }
2668                 {
2669                     //TRANSLATORS: only translate "string" in "context|string".
2670                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2671                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|S"));
2672                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the saturation of the color"), NULL);
2673                     clonetiler_table_attach (table, radio, 0.0, 2, 3);
2674                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2675                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_S));
2676                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_S);
2677                 }
2678                 {
2679                     //TRANSLATORS: only translate "string" in "context|string".
2680                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2681                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|L"));
2682                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the lightness of the color"), NULL);
2683                     clonetiler_table_attach (table, radio, 0.0, 3, 3);
2684                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2685                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_L));
2686                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_L);
2687                 }
2689             }
2691             {
2692                 GtkWidget *frame = gtk_frame_new (_("2. Tweak the picked value:"));
2693                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, VB_MARGIN);
2695                 GtkWidget *table = gtk_table_new (4, 2, FALSE);
2696                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2697                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2698                 gtk_container_add(GTK_CONTAINER(frame), table);
2700                 {
2701                     GtkWidget *l = gtk_label_new ("");
2702                     gtk_label_set_markup (GTK_LABEL(l), _("Gamma-correct:"));
2703                     clonetiler_table_attach (table, l, 1.0, 1, 1);
2704                 }
2705                 {
2706                     GtkWidget *l = clonetiler_spinbox (tt,
2707                                                        _("Shift the mid-range of the picked value upwards (>0) or downwards (<0)"), "gamma_picked",
2708                                                        -10, 10, "");
2709                     clonetiler_table_attach (table, l, 0.0, 1, 2);
2710                 }
2712                 {
2713                     GtkWidget *l = gtk_label_new ("");
2714                     gtk_label_set_markup (GTK_LABEL(l), _("Randomize:"));
2715                     clonetiler_table_attach (table, l, 1.0, 1, 3);
2716                 }
2717                 {
2718                     GtkWidget *l = clonetiler_spinbox (tt,
2719                                                        _("Randomize the picked value by this percentage"), "rand_picked",
2720                                                        0, 100, "%");
2721                     clonetiler_table_attach (table, l, 0.0, 1, 4);
2722                 }
2724                 {
2725                     GtkWidget *l = gtk_label_new ("");
2726                     gtk_label_set_markup (GTK_LABEL(l), _("Invert:"));
2727                     clonetiler_table_attach (table, l, 1.0, 2, 1);
2728                 }
2729                 {
2730                     GtkWidget *l = clonetiler_checkbox (tt, _("Invert the picked value"), "invert_picked");
2731                     clonetiler_table_attach (table, l, 0.0, 2, 2);
2732                 }
2733             }
2735             {
2736                 GtkWidget *frame = gtk_frame_new (_("3. Apply the value to the clones':"));
2737                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2740                 GtkWidget *table = gtk_table_new (2, 2, FALSE);
2741                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2742                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2743                 gtk_container_add(GTK_CONTAINER(frame), table);
2745                 {
2746                     GtkWidget *b  = gtk_check_button_new_with_label (_("Presence"));
2747                     bool old = prefs->getBool(prefs_path + "pick_to_presence", true);
2748                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2749                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone is created with the probability determined by the picked value in that point"), NULL);
2750                     clonetiler_table_attach (table, b, 0.0, 1, 1);
2751                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2752                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_presence");
2753                 }
2755                 {
2756                     GtkWidget *b  = gtk_check_button_new_with_label (_("Size"));
2757                     bool old = prefs->getBool(prefs_path + "pick_to_size");
2758                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2759                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's size is determined by the picked value in that point"), NULL);
2760                     clonetiler_table_attach (table, b, 0.0, 2, 1);
2761                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2762                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_size");
2763                 }
2765                 {
2766                     GtkWidget *b  = gtk_check_button_new_with_label (_("Color"));
2767                     bool old = prefs->getBool(prefs_path + "pick_to_color", 0);
2768                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2769                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone is painted by the picked color (the original must have unset fill or stroke)"), NULL);
2770                     clonetiler_table_attach (table, b, 0.0, 1, 2);
2771                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2772                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_color");
2773                 }
2775                 {
2776                     GtkWidget *b  = gtk_check_button_new_with_label (_("Opacity"));
2777                     bool old = prefs->getBool(prefs_path + "pick_to_opacity", 0);
2778                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2779                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's opacity is determined by the picked value in that point"), NULL);
2780                     clonetiler_table_attach (table, b, 0.0, 2, 2);
2781                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2782                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_opacity");
2783                 }
2784             }
2785            gtk_widget_set_sensitive (vvb, prefs->getBool(prefs_path + "dotrace"));
2786         }
2787         }
2789 // Rows/columns, width/height
2790         {
2791             GtkWidget *table = gtk_table_new (2, 2, FALSE);
2792             gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
2793             gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2794             gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2795             gtk_box_pack_start (GTK_BOX (mainbox), table, FALSE, FALSE, 0);
2797             {
2798                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2799                 g_object_set_data (G_OBJECT(dlg), "rowscols", (gpointer) hb);
2801                 {
2802                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2803                     int value = prefs->getInt(prefs_path + "jmax", 2);
2804                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2805                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2806                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many rows in the tiling"), NULL);
2807                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2808                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2810                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2811                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "jmax");
2812                 }
2814                 {
2815                     GtkWidget *l = gtk_label_new ("");
2816                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2817                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2818                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2819                 }
2821                 {
2822                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2823                     int value = prefs->getInt(prefs_path + "imax", 2);
2824                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2825                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2826                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many columns in the tiling"), NULL);
2827                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2828                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2830                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2831                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "imax");
2832                 }
2834                 clonetiler_table_attach (table, hb, 0.0, 1, 2);
2835             }
2837             {
2838                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2839                 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
2841                 // unitmenu
2842                 GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
2843                 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
2845                 {
2846                     // Width spinbutton
2847                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2848                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2850                     double value = prefs->getDouble(prefs_path + "fillwidth", 50.0);
2851                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2852                     gdouble const units = sp_pixels_get_units (value, unit);
2853                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2855                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2856                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Width of the rectangle to be filled"), NULL);
2857                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2858                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2859                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2860                                        GTK_SIGNAL_FUNC(clonetiler_fill_width_changed), u);
2861                 }
2862                 {
2863                     GtkWidget *l = gtk_label_new ("");
2864                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2865                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2866                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2867                 }
2869                 {
2870                     // Height spinbutton
2871                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2872                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2874                     double value = prefs->getDouble(prefs_path + "fillheight", 50.0);
2875                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2876                     gdouble const units = sp_pixels_get_units (value, unit);
2877                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2880                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2881                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Height of the rectangle to be filled"), NULL);
2882                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2883                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2884                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2885                                        GTK_SIGNAL_FUNC(clonetiler_fill_height_changed), u);
2886                 }
2888                 gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);
2889                 clonetiler_table_attach (table, hb, 0.0, 2, 2);
2891             }
2893             // Switch
2894             GtkWidget* radio;
2895             {
2896                 radio = gtk_radio_button_new_with_label (NULL, _("Rows, columns: "));
2897                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Create the specified number of rows and columns"), NULL);
2898                 clonetiler_table_attach (table, radio, 0.0, 1, 1);
2899                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_create), (gpointer) dlg);
2900             }
2901             if (!prefs->getBool(prefs_path + "fillrect")) {
2902                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2903                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2904             }
2905             {
2906                 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Width, height: "));
2907                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Fill the specified width and height with the tiling"), NULL);
2908                 clonetiler_table_attach (table, radio, 0.0, 2, 1);
2909                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_fill), (gpointer) dlg);
2910             }
2911             if (prefs->getBool(prefs_path + "fillrect")) {
2912                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2913                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2914             }
2915         }
2918 // Use saved pos
2919         {
2920             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2921             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2923             GtkWidget *b  = gtk_check_button_new_with_label (_("Use saved size and position of the tile"));
2924             bool keepbbox = prefs->getBool(prefs_path + "keepbbox", true);
2925             gtk_toggle_button_set_active ((GtkToggleButton *) b, keepbbox);
2926             gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Pretend that the size and position of the tile are the same as the last time you tiled it (if any), instead of using the current size"), NULL);
2927             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2929             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2930                                GTK_SIGNAL_FUNC(clonetiler_keep_bbox_toggled), NULL);
2931         }
2933 // Statusbar
2934         {
2935             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2936             gtk_box_pack_end (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2937             GtkWidget *l = gtk_label_new("");
2938             g_object_set_data (G_OBJECT(dlg), "status", (gpointer) l);
2939             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2940         }
2942 // Buttons
2943         {
2944             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2945             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2947             {
2948                 GtkWidget *b = gtk_button_new ();
2949                 GtkWidget *l = gtk_label_new ("");
2950                 gtk_label_set_markup_with_mnemonic (GTK_LABEL(l), _(" <b>_Create</b> "));
2951                 gtk_container_add (GTK_CONTAINER(b), l);
2952                 gtk_tooltips_set_tip (tt, b, _("Create and tile the clones of the selection"), NULL);
2953                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_apply), NULL);
2954                 gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0);
2955             }
2957             { // buttons which are enabled only when there are tiled clones
2958                 GtkWidget *sb = gtk_hbox_new(FALSE, 0);
2959                 gtk_box_pack_end (GTK_BOX (hb), sb, FALSE, FALSE, 0);
2960                 g_object_set_data (G_OBJECT(dlg), "buttons_on_tiles", (gpointer) sb);
2961                 {
2962                     // TRANSLATORS: if a group of objects are "clumped" together, then they
2963                     //  are unevenly spread in the given amount of space - as shown in the
2964                     //  diagrams on the left in the following screenshot:
2965                     //  http://www.inkscape.org/screenshots/gallery/inkscape-0.42-CVS-tiles-unclump.png
2966                     //  So unclumping is the process of spreading a number of objects out more evenly.
2967                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" _Unclump "));
2968                     gtk_tooltips_set_tip (tt, b, _("Spread out clones to reduce clumping; can be applied repeatedly"), NULL);
2969                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_unclump), NULL);
2970                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2971                 }
2973                 {
2974                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" Re_move "));
2975                     gtk_tooltips_set_tip (tt, b, _("Remove existing tiled clones of the selected object (siblings only)"), NULL);
2976                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_remove), NULL);
2977                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2978                 }
2980                 // connect to global selection changed signal (so we can change desktops) and
2981                 // external_change (so we're not fooled by undo)
2982                 g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (clonetiler_change_selection), dlg);
2983                 g_signal_connect (G_OBJECT (INKSCAPE), "external_change", G_CALLBACK (clonetiler_external_change), dlg);
2984                 g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), G_OBJECT (INKSCAPE));
2986                 // update now
2987                 clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
2988             }
2990             {
2991                 GtkWidget *b = gtk_button_new_with_mnemonic (_(" R_eset "));
2992                 // TRANSLATORS: "change" is a noun here
2993                 gtk_tooltips_set_tip (tt, b, _("Reset all shifts, scales, rotates, opacity and color changes in the dialog to zero"), NULL);
2994                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_reset), NULL);
2995                 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2996             }
2997         }
2999         gtk_widget_show_all (mainbox);
3001     } // end of if (!dlg)
3003     gtk_window_present ((GtkWindow *) dlg);
3007 /*
3008   Local Variables:
3009   mode:c++
3010   c-file-style:"stroustrup"
3011   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
3012   indent-tabs-mode:nil
3013   fill-column:99
3014   End:
3015 */
3016 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :