Code

304bf7c0ee3e5c34141b226a37325fc5ed6113bd
[inkscape.git] / src / dialogs / clonetiler.cpp
1 #define __SP_CLONE_TILER_C__
3 /*
4  * Clone tiling dialog
5  *
6  * Authors:
7  *   bulia byak <buliabyak@users.sf.net>
8  *
9  * Copyright (C) 2004-2005 Authors
10  * Released under GNU GPL
11  */
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
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 "../prefs-utils.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-handles.h"
34 #include "../sp-namedview.h"
35 #include "../document.h"
36 #include "../message-stack.h"
37 #include "../sp-use.h"
38 #include "unclump.h"
40 #include "xml/repr.h"
42 #include "svg/svg.h"
44 #include "libnr/nr-matrix-fns.h"
45 #include "libnr/nr-matrix-ops.h"
47 #include "libnr/nr-matrix-translate-ops.h"
48 #include "libnr/nr-translate-ops.h"
49 #include "libnr/nr-translate-rotate-ops.h"
50 #include "libnr/nr-translate-scale-ops.h"
52 #include "display/nr-arena.h"
53 #include "display/nr-arena-item.h"
55 #include "ui/widget/color-picker.h"
57 static GtkWidget *dlg = NULL;
58 static win_data wd;
60 // impossible original values to make sure they are read from prefs
61 static gint x = -1000, y = -1000, w = 0, h = 0;
62 static gchar *prefs_path = "dialogs.clonetiler";
64 #define SB_MARGIN 1
65 #define VB_MARGIN 4
67 enum {
68     PICK_COLOR,
69     PICK_OPACITY,
70     PICK_R,
71     PICK_G,
72     PICK_B,
73     PICK_H,
74     PICK_S,
75     PICK_L
76 };
78 static GtkSizeGroup* table_row_labels = NULL;
80 static sigc::connection _shutdown_connection;
81 static sigc::connection _dialogs_hidden_connection;
82 static sigc::connection _dialogs_unhidden_connection;
83 static sigc::connection _desktop_activated_connection;
84 static sigc::connection _color_changed_connection;
86 static Inkscape::UI::Widget::ColorPicker *color_picker;
88 static void
89 clonetiler_dialog_destroy (GtkObject *object, gpointer data)
90 {
91     if (Inkscape::NSApplication::Application::getNewGui())
92     {
93         _shutdown_connection.disconnect();
94         _dialogs_hidden_connection.disconnect();
95         _dialogs_unhidden_connection.disconnect();
96         _desktop_activated_connection.disconnect();
97     } else {
98         sp_signal_disconnect_by_data (INKSCAPE, dlg);
99     }
100     _color_changed_connection.disconnect();
102     delete color_picker;
103     
104     wd.win = dlg = NULL;
105     wd.stop = 0;
109 static gboolean
110 clonetiler_dialog_delete (GtkObject *object, GdkEvent * /*event*/, gpointer data)
112     gtk_window_get_position ((GtkWindow *) dlg, &x, &y);
113     gtk_window_get_size ((GtkWindow *) dlg, &w, &h);
115     if (x<0) x=0;
116     if (y<0) y=0;
118     prefs_set_int_attribute (prefs_path, "x", x);
119     prefs_set_int_attribute (prefs_path, "y", y);
120     prefs_set_int_attribute (prefs_path, "w", w);
121     prefs_set_int_attribute (prefs_path, "h", h);
123     return FALSE; // which means, go ahead and destroy it
127 static void on_delete()
129     (void)clonetiler_dialog_delete (0, 0, NULL);
132 static void
133 on_picker_color_changed (guint rgba)
135     static bool is_updating = false;
136     if (is_updating || !SP_ACTIVE_DESKTOP)
137         return;
139     is_updating = true;
141     Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, prefs_path);
142     gchar c[32];
143     sp_svg_write_color(c, 32, rgba);
144     repr->setAttribute("initial_color", c);
146     is_updating = false;
149 static guint clonetiler_number_of_clones (SPObject *obj);
151 static void
152 clonetiler_change_selection (Inkscape::Application * /*inkscape*/, Inkscape::Selection *selection, GtkWidget *dlg)
154     GtkWidget *buttons = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "buttons_on_tiles");
155     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
157     if (selection->isEmpty()) {
158         gtk_widget_set_sensitive (buttons, FALSE);
159         gtk_label_set_markup (GTK_LABEL(status), _("<small>Nothing selected.</small>"));
160         return;
161     }
163     if (g_slist_length ((GSList *) selection->itemList()) > 1) {
164         gtk_widget_set_sensitive (buttons, FALSE);
165         gtk_label_set_markup (GTK_LABEL(status), _("<small>More than one object selected.</small>"));
166         return;
167     }
169     guint n = clonetiler_number_of_clones(selection->singleItem());
170     if (n > 0) {
171         gtk_widget_set_sensitive (buttons, TRUE);
172         gchar *sta = g_strdup_printf (_("<small>Object has <b>%d</b> tiled clones.</small>"), n);
173         gtk_label_set_markup (GTK_LABEL(status), sta);
174         g_free (sta);
175     } else {
176         gtk_widget_set_sensitive (buttons, FALSE);
177         gtk_label_set_markup (GTK_LABEL(status), _("<small>Object has no tiled clones.</small>"));
178     }
181 static void
182 clonetiler_external_change (Inkscape::Application * /*inkscape*/, GtkWidget *dlg)
184     clonetiler_change_selection (NULL, SP_DT_SELECTION(SP_ACTIVE_DESKTOP), dlg);
187 static void clonetiler_disconnect_gsignal (GObject *widget, gpointer source) {
188     if (source && G_IS_OBJECT(source))
189         sp_signal_disconnect_by_data (source, widget);
193 enum {
194     TILE_P1,
195     TILE_P2,
196     TILE_PM,
197     TILE_PG,
198     TILE_CM,
199     TILE_PMM,
200     TILE_PMG,
201     TILE_PGG,
202     TILE_CMM,
203     TILE_P4,
204     TILE_P4M,
205     TILE_P4G,
206     TILE_P3,
207     TILE_P31M,
208     TILE_P3M1,
209     TILE_P6,
210     TILE_P6M
211 };
214 static NR::Matrix
215 clonetiler_get_transform ( 
216     // symmetry group
217     int type,
218     // row, column
219     int x, int y,
220     // center, width, height of the tile
221     double cx, double cy,
222     double w, double h,
224     // values from the dialog:
225     double d_x_per_x, double d_y_per_x, double d_x_per_y, double d_y_per_y,
226     int alternate_x, int alternate_y, double rand_x, double rand_y,
227     double d_per_x_exp, double d_per_y_exp,
228     double d_rot_per_x, double d_rot_per_y, int alternate_rotx, int alternate_roty, double rand_rot,
229     double d_scalex_per_x, double d_scaley_per_x, double d_scalex_per_y, double d_scaley_per_y,
230     int alternate_scalex, int alternate_scaley, double rand_scalex, double rand_scaley
231     )
233     // in abs units
234     double eff_x = (alternate_x? (x%2) : pow ((double) x, d_per_x_exp));
235     double eff_y = (alternate_y? (y%2) : pow ((double) y, d_per_y_exp));
236     double dx = d_x_per_x * w * eff_x + d_x_per_y  * w * eff_y + rand_x * w * g_random_double_range (-1, 1);
237     double dy = d_y_per_x * h * eff_x + d_y_per_y  * h * eff_y + rand_y * h * g_random_double_range (-1, 1);
239     NR::Matrix rect_translate (NR::translate (w * pow ((double) x, d_per_x_exp) + dx, h * pow ((double) y, d_per_y_exp) + dy));
241     // in deg
242     double eff_x_rot = (alternate_rotx? (x%2) : (x));
243     double eff_y_rot = (alternate_roty? (y%2) : (y));
244     double drot = d_rot_per_x * eff_x_rot + d_rot_per_y * eff_y_rot + rand_rot * 180 * g_random_double_range (-1, 1);
246     // times the original
247     double eff_x_s = (alternate_scalex? (x%2) : (x));
248     double eff_y_s = (alternate_scaley? (y%2) : (y));
249     double rand_scale_x, rand_scale_y;
250     if (rand_scaley == rand_scalex) {
251         // if rands are equal, scale proportionally
252         rand_scale_x = rand_scale_y = rand_scalex * 1 * g_random_double_range (-1, 1);
253     } else {
254         rand_scale_x = rand_scalex * 1 * g_random_double_range (-1, 1);
255         rand_scale_y = rand_scaley * 1 * g_random_double_range (-1, 1);
256     }
257     double dscalex = 1 + d_scalex_per_x * eff_x_s + d_scalex_per_y * eff_y_s + rand_scale_x;
258     if (dscalex < 0) dscalex = 0;
259     double dscaley = 1 + d_scaley_per_x * eff_x_s + d_scaley_per_y * eff_y_s + rand_scale_y;
260     if (dscaley < 0) dscaley = 0;
262     NR::Matrix drot_c = NR::translate(-cx, -cy) * NR::rotate (M_PI*drot/180) * NR::translate(cx, cy);
264     NR::Matrix dscale_c = NR::translate(-cx, -cy) * NR::scale (dscalex, dscaley) * NR::translate(cx, cy);
266     NR::Matrix d_s_r = dscale_c * drot_c;
268     NR::Matrix rotate_180_c = NR::translate(-cx, -cy) * NR::rotate (M_PI) * NR::translate(cx, cy);
270     NR::Matrix rotate_90_c = NR::translate(-cx, -cy) * NR::rotate (-M_PI/2) * NR::translate(cx, cy);
271     NR::Matrix rotate_m90_c = NR::translate(-cx, -cy) * NR::rotate (M_PI/2) * NR::translate(cx, cy);
273     NR::Matrix rotate_120_c = NR::translate(-cx, -cy) * NR::rotate (-2*M_PI/3) * NR::translate(cx, cy);
274     NR::Matrix rotate_m120_c = NR::translate(-cx, -cy) * NR::rotate (2*M_PI/3) * NR::translate(cx, cy);
276     NR::Matrix rotate_60_c = NR::translate(-cx, -cy) * NR::rotate (-M_PI/3) * NR::translate(cx, cy);
277     NR::Matrix rotate_m60_c = NR::translate(-cx, -cy) * NR::rotate (M_PI/3) * NR::translate(cx, cy);
279     double cos60 = cos(M_PI/3);
280     double sin60 = sin(M_PI/3);
281     double cos30 = cos(M_PI/6);
282     double sin30 = sin(M_PI/6);
284     NR::Matrix flip_x = NR::translate(-cx, -cy) * NR::scale (-1, 1) * NR::translate(cx, cy);
285     NR::Matrix flip_y = NR::translate(-cx, -cy) * NR::scale (1, -1) * NR::translate(cx, cy);
287     x = (int) pow ((double) x, d_per_x_exp);
288     y = (int) pow ((double) y, d_per_y_exp);
290     switch (type) {
292     case TILE_P1:
293         return d_s_r * rect_translate;
294         break;
296     case TILE_P2:
297         if (x % 2 == 0) {
298             return d_s_r * rect_translate;
299         } else {
300             return d_s_r * rotate_180_c * rect_translate;
301         }
302         break;
304     case TILE_PM:
305         if (x % 2 == 0) {
306             return d_s_r * rect_translate;
307         } else {
308             return d_s_r * flip_x * rect_translate;
309         }
310         break;
312     case TILE_PG:
313         if (y % 2 == 0) {
314             return d_s_r * rect_translate;
315         } else {
316             return d_s_r * flip_x * rect_translate;
317         }
318         break;
320     case TILE_CM:
321         if ((x + y) % 2 == 0) {
322             return d_s_r * rect_translate;
323         } else {
324             return d_s_r * flip_x * rect_translate;
325         }
326         break;
328     case TILE_PMM:
329         if (y % 2 == 0) {
330             if (x % 2 == 0) {
331                 return d_s_r * rect_translate;
332             } else {
333                 return d_s_r * flip_x * rect_translate;
334             }
335         } else {
336             if (x % 2 == 0) {
337                 return d_s_r * flip_y * rect_translate;
338             } else {
339                 return d_s_r * flip_x * flip_y * rect_translate;
340             }
341         }
342         break;
344     case TILE_PMG:
345         if (y % 4 == 0) {
346             return d_s_r * rect_translate;
347         } else if (y % 4 == 1) {
348             return d_s_r * flip_y * rect_translate;
349         } else if (y % 4 == 2) {
350             return d_s_r * flip_x * rect_translate;
351         } else if (y % 4 == 3) {
352             return d_s_r * flip_x * flip_y * rect_translate;
353         }
354         break;
356     case TILE_PGG:
357         if (y % 2 == 0) {
358             if (x % 2 == 0) {
359                 return d_s_r * rect_translate;
360             } else {
361                 return d_s_r * flip_y * rect_translate;
362             }
363         } else {
364             if (x % 2 == 0) {
365                 return d_s_r * rotate_180_c * rect_translate;
366             } else {
367                 return d_s_r * rotate_180_c * flip_y * rect_translate;
368             }
369         }
370         break;
372     case TILE_CMM:
373         if (y % 4 == 0) {
374             if (x % 2 == 0) {
375                 return d_s_r * rect_translate;
376             } else {
377                 return d_s_r * flip_x * rect_translate;
378             }
379         } else if (y % 4 == 1) {
380             if (x % 2 == 0) {
381                 return d_s_r * flip_y * rect_translate;
382             } else {
383                 return d_s_r * flip_x * flip_y * rect_translate;
384             }
385         } else if (y % 4 == 2) {
386             if (x % 2 == 1) {
387                 return d_s_r * rect_translate;
388             } else {
389                 return d_s_r * flip_x * rect_translate;
390             }
391         } else {
392             if (x % 2 == 1) {
393                 return d_s_r * flip_y * rect_translate;
394             } else {
395                 return d_s_r * flip_x * flip_y * rect_translate;
396             }
397         }
398         break;
400     case TILE_P4:
401     {
402         NR::Matrix ori (NR::translate ((w + h) * (x/2) + dx,  (h + w) * (y/2) + dy));
403         NR::Matrix dia1 (NR::translate (w/2 + h/2, -h/2 + w/2));
404         NR::Matrix dia2 (NR::translate (-w/2 + h/2, h/2 + w/2));
405         if (y % 2 == 0) {
406             if (x % 2 == 0) {
407                 return d_s_r * ori;
408             } else {
409                 return d_s_r * rotate_m90_c * dia1 * ori;
410             }
411         } else {
412             if (x % 2 == 0) {
413                 return d_s_r * rotate_90_c * dia2 * ori;
414             } else {
415                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
416             }
417         }
418     }
419     break;
421     case TILE_P4M:
422     {
423         double max = MAX(w, h);
424         NR::Matrix ori (NR::translate ((max + max) * (x/4) + dx,  (max + max) * (y/2) + dy));
425         NR::Matrix dia1 (NR::translate (w/2 - h/2, h/2 - w/2));
426         NR::Matrix dia2 (NR::translate (-h/2 + w/2, w/2 - h/2));
427         if (y % 2 == 0) {
428             if (x % 4 == 0) {
429                 return d_s_r * ori;
430             } else if (x % 4 == 1) {
431                 return d_s_r * flip_y * rotate_m90_c * dia1 * ori;
432             } else if (x % 4 == 2) {
433                 return d_s_r * rotate_m90_c * dia1 * NR::translate (h, 0) * ori;
434             } else if (x % 4 == 3) {
435                 return d_s_r * flip_x * NR::translate (w, 0) * ori;
436             }
437         } else {
438             if (x % 4 == 0) {
439                 return d_s_r * flip_y * NR::translate(0, h) * ori;
440             } else if (x % 4 == 1) {
441                 return d_s_r * rotate_90_c * dia2 * NR::translate(0, h) * ori;
442             } else if (x % 4 == 2) {
443                 return d_s_r * flip_y * rotate_90_c * dia2 * NR::translate(h, 0) * NR::translate(0, h) * ori;
444             } else if (x % 4 == 3) {
445                 return d_s_r * flip_y * flip_x * NR::translate(w, 0) * NR::translate(0, h) * ori;
446             }
447         }
448     }
449     break;
451     case TILE_P4G:
452     {
453         double max = MAX(w, h);
454         NR::Matrix ori (NR::translate ((max + max) * (x/4) + dx,  (max + max) * y + dy));
455         NR::Matrix dia1 (NR::translate (w/2 + h/2, h/2 - w/2));
456         NR::Matrix dia2 (NR::translate (-h/2 + w/2, w/2 + h/2));
457         if (((x/4) + y) % 2 == 0) {
458             if (x % 4 == 0) {
459                 return d_s_r * ori;
460             } else if (x % 4 == 1) {
461                 return d_s_r * rotate_m90_c * dia1 * ori;
462             } else if (x % 4 == 2) {
463                 return d_s_r * rotate_90_c * dia2 * ori;
464             } else if (x % 4 == 3) {
465                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
466             }
467         } else {
468             if (x % 4 == 0) {
469                 return d_s_r * flip_y * NR::translate (0, h) * ori;
470             } else if (x % 4 == 1) {
471                 return d_s_r * flip_y * rotate_m90_c * dia1 * NR::translate (-h, 0) * ori;
472             } else if (x % 4 == 2) {
473                 return d_s_r * flip_y * rotate_90_c * dia2 * NR::translate (h, 0) * ori;
474             } else if (x % 4 == 3) {
475                 return d_s_r * flip_x * NR::translate (w, 0) * ori;
476             }
477         }
478     }
479     break;
481     case TILE_P3:
482     {
483         double width;
484         double height;
485         NR::Matrix dia1;
486         NR::Matrix dia2;
487         if (w > h) {
488             width = w + w * cos60;
489             height = 2 * w * sin60;
490             dia1 = NR::Matrix (NR::translate (w/2 + w/2 * cos60, -(w/2 * sin60)));
491             dia2 = dia1 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60)));
492         } else {
493             width = h * cos (M_PI/6);
494             height = h;
495             dia1 = NR::Matrix (NR::translate (h/2 * cos30, -(h/2 * sin30)));
496             dia2 = dia1 * NR::Matrix (NR::translate (0, h/2));
497         }
498         NR::Matrix ori (NR::translate (width * (2*(x/3) + y%2) + dx,  (height/2) * y + dy));
499         if (x % 3 == 0) {
500             return d_s_r * ori;
501         } else if (x % 3 == 1) {
502             return d_s_r * rotate_m120_c * dia1 * ori;
503         } else if (x % 3 == 2) {
504             return d_s_r * rotate_120_c * dia2 * ori;
505         }
506     }
507     break;
509     case TILE_P31M:
510     {
511         NR::Matrix ori;
512         NR::Matrix dia1;
513         NR::Matrix dia2;
514         NR::Matrix dia3;
515         NR::Matrix dia4;
516         if (w > h) {
517             ori = NR::Matrix(NR::translate (w * (x/6) + w/2 * (y%2) + dx,  (w * cos30) * y + dy));
518             dia1 = NR::Matrix (NR::translate (0, h/2) * NR::translate (w/2, 0) * NR::translate (w/2 * cos60, -w/2 * sin60) * NR::translate (-h/2 * cos30, -h/2 * sin30) );
519             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
520             dia3 = dia2 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
521             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
522         } else {
523             ori  = NR::Matrix (NR::translate (2*h * cos30  * (x/6 + 0.5*(y%2)) + dx,  (2*h - h * sin30) * y + dy));
524             dia1 = NR::Matrix (NR::translate (0, -h/2) * NR::translate (h/2 * cos30, h/2 * sin30));
525             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
526             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
527             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
528         }
529         if (x % 6 == 0) {
530             return d_s_r * ori;
531         } else if (x % 6 == 1) {
532             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
533         } else if (x % 6 == 2) {
534             return d_s_r * rotate_m120_c * dia2 * ori;
535         } else if (x % 6 == 3) {
536             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
537         } else if (x % 6 == 4) {
538             return d_s_r * rotate_120_c * dia4 * ori;
539         } else if (x % 6 == 5) {
540             return d_s_r * flip_y * NR::translate(0, h) * ori;
541         }
542     }
543     break;
545     case TILE_P3M1:
546     {
547         double width;
548         double height;
549         NR::Matrix dia1;
550         NR::Matrix dia2;
551         NR::Matrix dia3;
552         NR::Matrix dia4;
553         if (w > h) {
554             width = w + w * cos60;
555             height = 2 * w * sin60;
556             dia1 = NR::Matrix (NR::translate (0, h/2) * NR::translate (w/2, 0) * NR::translate (w/2 * cos60, -w/2 * sin60) * NR::translate (-h/2 * cos30, -h/2 * sin30) );
557             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
558             dia3 = dia2 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
559             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
560         } else {
561             width = 2 * h * cos (M_PI/6);
562             height = 2 * h;
563             dia1 = NR::Matrix (NR::translate (0, -h/2) * NR::translate (h/2 * cos30, h/2 * sin30));
564             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
565             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
566             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
567         }
568         NR::Matrix ori (NR::translate (width * (2*(x/6) + y%2) + dx,  (height/2) * y + dy));
569         if (x % 6 == 0) {
570             return d_s_r * ori;
571         } else if (x % 6 == 1) {
572             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
573         } else if (x % 6 == 2) {
574             return d_s_r * rotate_m120_c * dia2 * ori;
575         } else if (x % 6 == 3) {
576             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
577         } else if (x % 6 == 4) {
578             return d_s_r * rotate_120_c * dia4 * ori;
579         } else if (x % 6 == 5) {
580             return d_s_r * flip_y * NR::translate(0, h) * ori;
581         }
582     }
583     break;
585     case TILE_P6:
586     {
587         NR::Matrix ori;
588         NR::Matrix dia1;
589         NR::Matrix dia2;
590         NR::Matrix dia3;
591         NR::Matrix dia4;
592         NR::Matrix dia5;
593         if (w > h) {
594             ori = NR::Matrix(NR::translate (2*w * (x/6) + w * (y%2) + dx,  (2*w * sin60) * y + dy));
595             dia1 = NR::Matrix (NR::translate (w/2 * cos60, -w/2 * sin60));
596             dia2 = dia1 * NR::Matrix (NR::translate (w/2, 0));
597             dia3 = dia2 * NR::Matrix (NR::translate (w/2 * cos60, w/2 * sin60));
598             dia4 = dia3 * NR::Matrix (NR::translate (-w/2 * cos60, w/2 * sin60));
599             dia5 = dia4 * NR::Matrix (NR::translate (-w/2, 0));
600         } else {
601             ori = NR::Matrix(NR::translate (2*h * cos30 * (x/6 + 0.5*(y%2)) + dx,  (h + h * sin30) * y + dy));
602             dia1 = NR::Matrix (NR::translate (-w/2, -h/2) * NR::translate (h/2 * cos30, -h/2 * sin30) * NR::translate (w/2 * cos60, w/2 * sin60));
603             dia2 = dia1 * NR::Matrix (NR::translate (-w/2 * cos60, -w/2 * sin60) * NR::translate (h/2 * cos30, -h/2 * sin30) * NR::translate (h/2 * cos30, h/2 * sin30) * NR::translate (-w/2 * cos60, w/2 * sin60));
604             dia3 = dia2 * NR::Matrix (NR::translate (w/2 * cos60, -w/2 * sin60) * NR::translate (h/2 * cos30, h/2 * sin30) * NR::translate (-w/2, h/2));
605             dia4 = dia3 * dia1.inverse();
606             dia5 = dia3 * dia2.inverse();
607         }
608         if (x % 6 == 0) {
609             return d_s_r * ori;
610         } else if (x % 6 == 1) {
611             return d_s_r * rotate_m60_c * dia1 * ori;
612         } else if (x % 6 == 2) {
613             return d_s_r * rotate_m120_c * dia2 * ori;
614         } else if (x % 6 == 3) {
615             return d_s_r * rotate_180_c * dia3 * ori;
616         } else if (x % 6 == 4) {
617             return d_s_r * rotate_120_c * dia4 * ori;
618         } else if (x % 6 == 5) {
619             return d_s_r * rotate_60_c * dia5 * ori;
620         }
621     }
622     break;
624     case TILE_P6M:
625     {
627         NR::Matrix ori;
628         NR::Matrix dia1, dia2, dia3, dia4, dia5, dia6, dia7, dia8, dia9, dia10;
629         if (w > h) {
630             ori = NR::Matrix(NR::translate (2*w * (x/12) + w * (y%2) + dx,  (2*w * sin60) * y + dy));
631             dia1 = NR::Matrix (NR::translate (w/2, h/2) * NR::translate (-w/2 * cos60, -w/2 * sin60) * NR::translate (-h/2 * cos30, h/2 * sin30));
632             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, -h * sin30));
633             dia3 = dia2 * NR::Matrix (NR::translate (-h/2 * cos30, h/2 * sin30) * NR::translate (w * cos60, 0) * NR::translate (-h/2 * cos30, -h/2 * sin30));
634             dia4 = dia3 * NR::Matrix (NR::translate (h * cos30, h * sin30));
635             dia5 = dia4 * NR::Matrix (NR::translate (-h/2 * cos30, -h/2 * sin30) * NR::translate (-w/2 * cos60, w/2 * sin60) * NR::translate (w/2, -h/2));
636             dia6 = dia5 * NR::Matrix (NR::translate (0, h));
637             dia7 = dia6 * dia1.inverse();
638             dia8 = dia6 * dia2.inverse();
639             dia9 = dia6 * dia3.inverse();
640             dia10 = dia6 * dia4.inverse();
641         } else {
642             ori = NR::Matrix(NR::translate (4*h * cos30 * (x/12 + 0.5*(y%2)) + dx,  (2*h  + 2*h * sin30) * y + dy));
643             dia1 = NR::Matrix (NR::translate (-w/2, -h/2) * NR::translate (h/2 * cos30, -h/2 * sin30) * NR::translate (w/2 * cos60, w/2 * sin60));
644             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, -h * sin30));
645             dia3 = dia2 * NR::Matrix (NR::translate (-w/2 * cos60, -w/2 * sin60) * NR::translate (h * cos30, 0) * NR::translate (-w/2 * cos60, w/2 * sin60));
646             dia4 = dia3 * NR::Matrix (NR::translate (h * cos30, h * sin30));
647             dia5 = dia4 * NR::Matrix (NR::translate (w/2 * cos60, -w/2 * sin60) * NR::translate (h/2 * cos30, h/2 * sin30) * NR::translate (-w/2, h/2));
648             dia6 = dia5 * NR::Matrix (NR::translate (0, h));
649             dia7 = dia6 * dia1.inverse();
650             dia8 = dia6 * dia2.inverse();
651             dia9 = dia6 * dia3.inverse();
652             dia10 = dia6 * dia4.inverse();
653         }
654         if (x % 12 == 0) {
655             return d_s_r * ori;
656         } else if (x % 12 == 1) {
657             return d_s_r * flip_y * rotate_m60_c * dia1 * ori;
658         } else if (x % 12 == 2) {
659             return d_s_r * rotate_m60_c * dia2 * ori;
660         } else if (x % 12 == 3) {
661             return d_s_r * flip_y * rotate_m120_c * dia3 * ori;
662         } else if (x % 12 == 4) {
663             return d_s_r * rotate_m120_c * dia4 * ori;
664         } else if (x % 12 == 5) {
665             return d_s_r * flip_x * dia5 * ori;
666         } else if (x % 12 == 6) {
667             return d_s_r * flip_x * flip_y * dia6 * ori;
668         } else if (x % 12 == 7) {
669             return d_s_r * flip_y * rotate_120_c * dia7 * ori;
670         } else if (x % 12 == 8) {
671             return d_s_r * rotate_120_c * dia8 * ori;
672         } else if (x % 12 == 9) {
673             return d_s_r * flip_y * rotate_60_c * dia9 * ori;
674         } else if (x % 12 == 10) {
675             return d_s_r * rotate_60_c * dia10 * ori;
676         } else if (x % 12 == 11) {
677             return d_s_r * flip_y * NR::translate (0, h) * ori;
678         }
679     }
680     break;
682     default:
683         break;
684     }
686     return NR::identity();
689 static bool
690 clonetiler_is_a_clone_of (SPObject *tile, SPObject *obj)
692     char *id_href = NULL;
694     if (obj) {
695         Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
696         id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
697     }
699     if (SP_IS_USE(tile) &&
700         SP_OBJECT_REPR(tile)->attribute("xlink:href") &&
701         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("xlink:href"))) &&
702         SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of") &&
703         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of"))))
704     {
705         if (id_href)
706             g_free (id_href);
707         return true;
708     } else {
709         if (id_href)
710             g_free (id_href);
711         return false;
712     }
715 static NRArena const *trace_arena = NULL;
716 static unsigned trace_visionkey;
717 static NRArenaItem *trace_root;
718 static gdouble trace_zoom;
720 static void
721 clonetiler_trace_hide_tiled_clones_recursively (SPObject *from)
723     if (!trace_arena)
724         return;
726     for (SPObject *o = sp_object_first_child(from); o != NULL; o = SP_OBJECT_NEXT(o)) {
727         if (SP_IS_ITEM(o) && clonetiler_is_a_clone_of (o, NULL))
728             sp_item_invoke_hide(SP_ITEM(o), trace_visionkey); // FIXME: hide each tiled clone's original too!
729         clonetiler_trace_hide_tiled_clones_recursively (o);
730     }
733 static void
734 clonetiler_trace_setup (SPDocument *doc, gdouble zoom, SPItem *original)
736     trace_arena = NRArena::create();
737     /* Create ArenaItem and set transform */
738     trace_visionkey = sp_item_display_key_new(1);
739     trace_root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT (doc)), 
740                                       (NRArena *) trace_arena, trace_visionkey, SP_ITEM_SHOW_DISPLAY);
742     // hide the (current) original and any tiled clones, we only want to pick the background
743     sp_item_invoke_hide(original, trace_visionkey); 
744     clonetiler_trace_hide_tiled_clones_recursively (SP_OBJECT(SP_DOCUMENT_ROOT (doc)));
746     sp_document_root (doc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
747     sp_document_ensure_up_to_date(doc);
749     trace_zoom = zoom;
752 static guint32
753 clonetiler_trace_pick (NR::Rect box)
755     if (!trace_arena)
756         return 0;
758     NRMatrix t;
759     nr_matrix_set_scale(&t, trace_zoom, trace_zoom);
760     nr_arena_item_set_transform(trace_root, &t);
761     NRGC gc(NULL);
762     nr_matrix_set_identity(&gc.transform);
763     nr_arena_item_invoke_update( trace_root, NULL, &gc,
764                                  NR_ARENA_ITEM_STATE_ALL,
765                                  NR_ARENA_ITEM_STATE_NONE );
767     /* Item integer bbox in points */
768     NRRectL ibox;
769     ibox.x0 = (int) floor(trace_zoom * box.min()[NR::X] + 0.5);
770     ibox.y0 = (int) floor(trace_zoom * box.min()[NR::Y] + 0.5);
771     ibox.x1 = (int) floor(trace_zoom * box.max()[NR::X] + 0.5);
772     ibox.y1 = (int) floor(trace_zoom * box.max()[NR::Y] + 0.5);
774     /* Find visible area */
775     int width = ibox.x1 - ibox.x0;
776     int height = ibox.y1 - ibox.y0;
778     /* Set up pixblock */
779     guchar *px = nr_new(guchar, 4 * width * height);
780     memset(px, 0x00, 4 * width * height);
782     /* Render */
783     NRPixBlock pb;
784     nr_pixblock_setup_extern( &pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
785                               ibox.x0, ibox.y0, ibox.x1, ibox.y1,
786                               px, 4 * width, FALSE, FALSE );
787     nr_arena_item_invoke_render( trace_root, &ibox, &pb,
788                                  NR_ARENA_ITEM_RENDER_NO_CACHE );
790     double R = 0, G = 0, B = 0, A = 0;
791     double count = 0;
792     double weight = 0;
794     for (int y = ibox.y0; y < ibox.y1; y++) {
795         const unsigned char *s = NR_PIXBLOCK_PX (&pb) + (y - ibox.y0) * pb.rs;
796         for (int x = ibox.x0; x < ibox.x1; x++) {
797             count += 1;
798             weight += s[3] / 255.0;
799             R += s[0] / 255.0;
800             G += s[1] / 255.0;
801             B += s[2] / 255.0;
802             A += s[3] / 255.0;
803             s += 4;
804         }
805     }
807     nr_pixblock_release(&pb);
809     R = R / weight;
810     G = G / weight;
811     B = B / weight;
812     A = A / count;
814     R = CLAMP (R, 0.0, 1.0);
815     G = CLAMP (G, 0.0, 1.0);
816     B = CLAMP (B, 0.0, 1.0);
817     A = CLAMP (A, 0.0, 1.0);
819     return SP_RGBA32_F_COMPOSE (R, G, B, A);
822 static void
823 clonetiler_trace_finish ()
825     if (trace_arena) {
826         ((NRObject *) trace_arena)->unreference();
827         trace_arena = NULL;
828     }
831 static void
832 clonetiler_unclump (GtkWidget *widget, void *)
834     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
835     if (desktop == NULL)
836         return;
838     Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
840     // check if something is selected
841     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
842         SP_DT_MSGSTACK(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump."));
843         return;
844     }
846     SPObject *obj = SP_OBJECT(selection->singleItem());
847     SPObject *parent = SP_OBJECT_PARENT (obj);
849     GSList *to_unclump = NULL; // not including the original
851     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
852         if (clonetiler_is_a_clone_of (child, obj)) {
853             to_unclump = g_slist_prepend (to_unclump, child);
854         }
855     }
857     sp_document_ensure_up_to_date(SP_DT_DOCUMENT(desktop));
859     unclump (to_unclump);
861     g_slist_free (to_unclump);
863     sp_document_done (SP_DT_DOCUMENT (desktop));
866 static guint
867 clonetiler_number_of_clones (SPObject *obj)
869     SPObject *parent = SP_OBJECT_PARENT (obj);
871     guint n = 0;
873     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
874         if (clonetiler_is_a_clone_of (child, obj)) {
875             n ++;
876         }
877     }
879     return n;
882 static void
883 clonetiler_remove (GtkWidget *widget, void *, bool do_undo = true)
885     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
886     if (desktop == NULL)
887         return;
889     Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
891     // check if something is selected
892     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
893         SP_DT_MSGSTACK(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove."));
894         return;
895     }
897     SPObject *obj = SP_OBJECT(selection->singleItem());
898     SPObject *parent = SP_OBJECT_PARENT (obj);
900 // remove old tiling
901     GSList *to_delete = NULL;
902     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
903         if (clonetiler_is_a_clone_of (child, obj)) {
904             to_delete = g_slist_prepend (to_delete, child);
905         }
906     }
907     for (GSList *i = to_delete; i; i = i->next) {
908         SP_OBJECT(i->data)->deleteObject();
909     }
910     g_slist_free (to_delete);
912     clonetiler_change_selection (NULL, selection, dlg);
914     if (do_undo)
915         sp_document_done (SP_DT_DOCUMENT (desktop));
918 static NR::Rect
919 transform_rect(NR::Rect const &r, NR::Matrix const &m)
921     using NR::X;
922     using NR::Y;
923     NR::Point const p1 = r.corner(1) * m;
924     NR::Point const p2 = r.corner(2) * m;
925     NR::Point const p3 = r.corner(3) * m;
926     NR::Point const p4 = r.corner(4) * m;
927     return NR::Rect(
928         NR::Point(
929             std::min(std::min(p1[X], p2[X]), std::min(p3[X], p4[X])), 
930             std::min(std::min(p1[Y], p2[Y]), std::min(p3[Y], p4[Y]))), 
931         NR::Point(
932             std::max(std::max(p1[X], p2[X]), std::max(p3[X], p4[X])), 
933             std::max(std::max(p1[Y], p2[Y]), std::max(p3[Y], p4[Y]))));
936 /**
937 Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same
938 probability of being displaced.
939  */
940 static double
941 randomize01 (double val, double rand)
943     double base = MIN (val - rand, 1 - 2*rand);
944     if (base < 0) base = 0;
945     val = base + g_random_double_range (0, MIN (2 * rand, 1 - base));
946     return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case...
950 static void
951 clonetiler_apply (GtkWidget *widget, void *)
953     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
954     if (desktop == NULL)
955         return;
957     Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
959     // check if something is selected
960     if (selection->isEmpty()) {
961         SP_DT_MSGSTACK(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone."));
962         return;
963     }
965     // Check if more than one object is selected.
966     if (g_slist_length((GSList *) selection->itemList()) > 1) {
967         SP_DT_MSGSTACK(desktop)->flash(Inkscape::ERROR_MESSAGE, _("If you want to clone several objects, <b>group</b> them and <b>clone the group</b>."));
968         return;
969     }
971     SPObject *obj = SP_OBJECT(selection->singleItem());
972     Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
973     const char *id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
974     SPObject *parent = SP_OBJECT_PARENT (obj);
976     clonetiler_remove (NULL, NULL, false);
978     double d_x_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_x_per_x", 0, -100, 1000);
979     double d_y_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_y_per_x", 0, -100, 1000);
980     double d_per_x_exp = prefs_get_double_attribute_limited (prefs_path, "d_per_x_exp", 1, 0, 10);
981     double d_x_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_x_per_y", 0, -100, 1000);
982     double d_y_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_y_per_y", 0, -100, 1000);
983     double d_per_y_exp = prefs_get_double_attribute_limited (prefs_path, "d_per_y_exp", 1, 0, 10);
984     int alternate_x = prefs_get_int_attribute (prefs_path, "alternate_x", 0);
985     int alternate_y = prefs_get_int_attribute (prefs_path, "alternate_y", 0);
986     double rand_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_x", 0, 0, 1000);
987     double rand_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_y", 0, 0, 1000);
989     double d_scalex_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scalex_per_x", 0, -100, 1000);
990     double d_scaley_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scaley_per_x", 0, -100, 1000);
991     double d_scalex_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scalex_per_y", 0, -100, 1000);
992     double d_scaley_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scaley_per_y", 0, -100, 1000);
993     int alternate_scalex = prefs_get_int_attribute (prefs_path, "alternate_scalex", 0);
994     int alternate_scaley = prefs_get_int_attribute (prefs_path, "alternate_scaley", 0);
995     double rand_scalex = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_scalex", 0, 0, 1000);
996     double rand_scaley = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_scaley", 0, 0, 1000);
998     double d_rot_per_x = prefs_get_double_attribute_limited (prefs_path, "d_rot_per_x", 0, -180, 180);
999     double d_rot_per_y = prefs_get_double_attribute_limited (prefs_path, "d_rot_per_y", 0, -180, 180);
1000     int alternate_rotx = prefs_get_int_attribute (prefs_path, "alternate_rotx", 0);
1001     int alternate_roty = prefs_get_int_attribute (prefs_path, "alternate_roty", 0);
1002     double rand_rot = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_rot", 0, 0, 100);
1004     double d_opacity_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_opacity_per_y", 0, 0, 100);
1005     double d_opacity_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_opacity_per_x", 0, 0, 100);
1006     int alternate_opacityy = prefs_get_int_attribute (prefs_path, "alternate_opacityy", 0);
1007     int alternate_opacityx = prefs_get_int_attribute (prefs_path, "alternate_opacityx", 0);
1008     double rand_opacity = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_opacity", 0, 0, 100);
1010     const gchar *initial_color = prefs_get_string_attribute (prefs_path, "initial_color");
1011     double d_hue_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_hue_per_y", 0, -100, 100);
1012     double d_hue_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_hue_per_x", 0, -100, 100);
1013     double rand_hue = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_hue", 0, 0, 100);
1014     double d_saturation_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_saturation_per_y", 0, -100, 100);
1015     double d_saturation_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_saturation_per_x", 0, -100, 100);
1016     double rand_saturation = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_saturation", 0, 0, 100);
1017     double d_lightness_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_lightness_per_y", 0, -100, 100);
1018     double d_lightness_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_lightness_per_x", 0, -100, 100);
1019     double rand_lightness = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_lightness", 0, 0, 100);
1020     int alternate_color_y = prefs_get_int_attribute (prefs_path, "alternate_color_y", 0);
1021     int alternate_color_x = prefs_get_int_attribute (prefs_path, "alternate_color_x", 0);
1023     int type = prefs_get_int_attribute (prefs_path, "symmetrygroup", 0);
1025     int keepbbox = prefs_get_int_attribute (prefs_path, "keepbbox", 1);
1027     int xmax = prefs_get_int_attribute (prefs_path, "xmax", 2);
1028     int ymax = prefs_get_int_attribute (prefs_path, "ymax", 2);
1030     int fillrect = prefs_get_int_attribute (prefs_path, "fillrect", 0);
1031     double fillwidth = prefs_get_double_attribute_limited (prefs_path, "fillwidth", 50, 0, 6000);
1032     double fillheight = prefs_get_double_attribute_limited (prefs_path, "fillheight", 50, 0, 6000);
1034     int dotrace = prefs_get_int_attribute (prefs_path, "dotrace", 0);
1035     int pick = prefs_get_int_attribute (prefs_path, "pick", 0);
1036     int pick_to_presence = prefs_get_int_attribute (prefs_path, "pick_to_presence", 0);
1037     int pick_to_size = prefs_get_int_attribute (prefs_path, "pick_to_size", 0);
1038     int pick_to_color = prefs_get_int_attribute (prefs_path, "pick_to_color", 0);
1039     int pick_to_opacity = prefs_get_int_attribute (prefs_path, "pick_to_opacity", 0);
1040     double rand_picked = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_picked", 0, 0, 100);
1041     int invert_picked = prefs_get_int_attribute (prefs_path, "invert_picked", 0);
1042     double gamma_picked = prefs_get_double_attribute_limited (prefs_path, "gamma_picked", 0, -10, 10);
1044     if (dotrace) {
1045         clonetiler_trace_setup (SP_DT_DOCUMENT(desktop), 1.0, SP_ITEM (obj));
1046     }
1048     NR::Point c;
1049     double w;
1050     double h;
1052     if (keepbbox &&
1053         obj_repr->attribute("inkscape:tile-w") &&
1054         obj_repr->attribute("inkscape:tile-h") &&
1055         obj_repr->attribute("inkscape:tile-cx") &&
1056         obj_repr->attribute("inkscape:tile-cy")) {
1058         double cx = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cx", 0);
1059         double cy = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cy", 0);
1061         c = NR::Point (cx, cy);
1063         w = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-w", 0);
1064         h = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-h", 0);
1065     } else {
1066         NR::Rect const r = SP_ITEM(obj)->invokeBbox(sp_item_i2doc_affine(SP_ITEM(obj)));
1067         c = r.midpoint();
1068         w = r.dimensions()[NR::X];
1069         h = r.dimensions()[NR::Y];
1071         sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
1072         sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
1073         sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", c[NR::X]);
1074         sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", c[NR::Y]);
1075     }
1077     NR::Point cur = NR::Point (0, 0);
1078     NR::Rect bbox_original = NR::Rect (NR::Point (c[NR::X] - w/2, c[NR::Y] - h/2), NR::Point (c[NR::X] + w/2, c[NR::Y] + h/2));
1080     for (int x = 0;
1081          fillrect?
1082              (fabs(cur[NR::X]) < fillwidth && x < 200) // prevent "freezing" with too large fillrect, arbitrarily limit rows
1083              : (x < xmax);
1084          x ++) {
1085         for (int y = 0;
1086              fillrect?
1087                  (fabs(cur[NR::Y]) < fillheight && y < 200) // prevent "freezing" with too large fillrect, arbitrarily limit cols
1088                  : (y < ymax);
1089              y ++) {
1091             // Note: We create a clone at 0,0 too, right over the original, in case our clones are colored
1093             // Get transform from symmetry, shift, scale, rotation
1094             NR::Matrix t = clonetiler_get_transform (type, x, y, c[NR::X], c[NR::Y], w, h,
1095                                                      d_x_per_x, d_y_per_x, d_x_per_y, d_y_per_y, alternate_x, alternate_y, rand_x, rand_y,
1096                                                      d_per_x_exp, d_per_y_exp,
1097                                                      d_rot_per_x, d_rot_per_y, alternate_rotx, alternate_roty, rand_rot,
1098                                                      d_scalex_per_x, d_scaley_per_x, d_scalex_per_y, d_scaley_per_y,
1099                                                      alternate_scalex, alternate_scaley, rand_scalex, rand_scaley);
1101             cur = c * t - c;
1102             if (fillrect) {
1103                 if ((cur[NR::X] > fillwidth) || (cur[NR::Y] > fillheight)) { // off limits
1104                     continue;
1105                 }
1106             }
1108             gchar color_string[32]; *color_string = 0;
1110             // Color tab
1111             if (initial_color) {
1112                 guint32 rgba = sp_svg_read_color (initial_color, 0x000000ff);
1113                 float hsl[3];
1114                 sp_color_rgb_to_hsl_floatv (hsl, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba));
1116                 double eff_x = (alternate_color_x? (x%2) : (x));
1117                 double eff_y = (alternate_color_y? (y%2) : (y));
1119                 hsl[0] += d_hue_per_x * eff_x + d_hue_per_y * eff_y + rand_hue * g_random_double_range (-1, 1);
1120                 if (hsl[0] < 0) hsl[0] += 1;
1121                 if (hsl[0] > 1) hsl[0] -= 1;
1122                 hsl[1] += d_saturation_per_x * eff_x + d_saturation_per_y * eff_y + rand_saturation * g_random_double_range (-1, 1);
1123                 hsl[1] = CLAMP (hsl[1], 0, 1);
1124                 hsl[2] += d_lightness_per_x * eff_x + d_lightness_per_y * eff_y + rand_lightness * g_random_double_range (-1, 1);
1125                 hsl[2] = CLAMP (hsl[2], 0, 1);
1127                 float rgb[3];
1128                 sp_color_hsl_to_rgb_floatv (rgb, hsl[0], hsl[1], hsl[2]);
1129                 sp_svg_write_color(color_string, 32, SP_RGBA32_F_COMPOSE(rgb[0], rgb[1], rgb[2], 1.0));
1130             }
1132             // Opacity tab
1133             double opacity = 1.0;
1134             int eff_x = (alternate_opacityx? (x%2) : (x));
1135             int eff_y = (alternate_opacityy? (y%2) : (y));
1136             opacity = 1 - (d_opacity_per_x * eff_x + d_opacity_per_y * eff_y + rand_opacity * g_random_double_range (-1, 1));
1137             opacity = CLAMP (opacity, 0, 1);
1139             // Trace tab
1140             if (dotrace) {
1141                 NR::Rect bbox_t = transform_rect (bbox_original, t);
1143                 guint32 rgba = clonetiler_trace_pick (bbox_t);
1144                 float r = SP_RGBA32_R_F(rgba);
1145                 float g = SP_RGBA32_G_F(rgba);
1146                 float b = SP_RGBA32_B_F(rgba);
1147                 float a = SP_RGBA32_A_F(rgba);
1149                 float hsl[3];
1150                 sp_color_rgb_to_hsl_floatv (hsl, r, g, b);
1152                 gdouble val = 0;
1153                 switch (pick) {
1154                 case PICK_COLOR:
1155                     val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max
1156                     break;
1157                 case PICK_OPACITY:
1158                     val = a;
1159                     break;
1160                 case PICK_R:
1161                     val = r;
1162                     break;
1163                 case PICK_G:
1164                     val = g;
1165                     break;
1166                 case PICK_B:
1167                     val = b;
1168                     break;
1169                 case PICK_H:
1170                     val = hsl[0];
1171                     break;
1172                 case PICK_S:
1173                     val = hsl[1];
1174                     break;
1175                 case PICK_L:
1176                     val = 1 - hsl[2];
1177                     break;
1178                 default:
1179                     break;
1180                 }
1182                 if (rand_picked > 0) {
1183                     val = randomize01 (val, rand_picked);
1184                     r = randomize01 (r, rand_picked);
1185                     g = randomize01 (g, rand_picked);
1186                     b = randomize01 (b, rand_picked);
1187                 }
1189                 if (gamma_picked != 0) {
1190                     double power;
1191                     if (gamma_picked < 0)
1192                         power = 1/(1 + fabs(gamma_picked));
1193                     else
1194                         power = 1 + gamma_picked;
1196                     val = pow (val, power);
1197                     r = pow (r, power);
1198                     g = pow (g, power);
1199                     b = pow (b, power);
1200                 }
1202                 if (invert_picked) {
1203                     val = 1 - val;
1204                     r = 1 - r;
1205                     g = 1 - g;
1206                     b = 1 - b;
1207                 }
1209                 val = CLAMP (val, 0, 1);
1210                 r = CLAMP (r, 0, 1);
1211                 g = CLAMP (g, 0, 1);
1212                 b = CLAMP (b, 0, 1);
1214                 // recompose tweaked color
1215                 rgba = SP_RGBA32_F_COMPOSE(r, g, b, a);
1217                 if (pick_to_presence) {
1218                     if (g_random_double_range (0, 1) > val) {
1219                         continue; // skip!
1220                     }
1221                 }
1222                 if (pick_to_size) {
1223                     t = NR::translate(-c[NR::X], -c[NR::Y]) * NR::scale (val, val) * NR::translate(c[NR::X], c[NR::Y]) * t;
1224                 }
1225                 if (pick_to_opacity) {
1226                     opacity *= val;
1227                 }
1228                 if (pick_to_color) {
1229                     sp_svg_write_color(color_string, 32, rgba);
1230                 }
1231             }
1233             if (opacity < 1e-6) { // invisibly transparent, skip
1234                     continue;
1235             }
1237             if (fabs(t[0]) + fabs (t[1]) + fabs(t[2]) + fabs(t[3]) < 1e-6) { // too small, skip
1238                     continue;
1239             }
1241             // Create the clone
1242             Inkscape::XML::Node *clone = sp_repr_new("svg:use");
1243             clone->setAttribute("x", "0");
1244             clone->setAttribute("y", "0");
1245             clone->setAttribute("inkscape:tiled-clone-of", id_href);
1246             clone->setAttribute("xlink:href", id_href);
1248             gchar affinestr[80];
1249             if (sp_svg_transform_write(affinestr, 79, t)) {
1250                 clone->setAttribute("transform", affinestr);
1251             } else {
1252                 clone->setAttribute("transform", NULL);
1253             }
1255             if (opacity < 1.0) {
1256                 sp_repr_set_css_double(clone, "opacity", opacity);
1257             }
1259             if (*color_string) {
1260                 clone->setAttribute("fill", color_string);
1261                 clone->setAttribute("stroke", color_string);
1262             }
1264             // add the new clone to the top of the original's parent
1265             SP_OBJECT_REPR(parent)->appendChild(clone);
1266             Inkscape::GC::release(clone);
1267         }
1268         cur[NR::Y] = 0;
1269     }
1271     if (dotrace) {
1272         clonetiler_trace_finish ();
1273     }
1275     clonetiler_change_selection (NULL, selection, dlg);
1277     sp_document_done(SP_DT_DOCUMENT(desktop));
1280 static GtkWidget *
1281 clonetiler_new_tab (GtkWidget *nb, const gchar *label)
1283     GtkWidget *l = gtk_label_new_with_mnemonic (label);
1284     GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN);
1285     gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN);
1286     gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l);
1287     return vb;
1290 static void
1291 clonetiler_checkbox_toggled (GtkToggleButton *tb, gpointer *data)
1293     const gchar *attr = (const gchar *) data;
1294     prefs_set_int_attribute (prefs_path, attr, gtk_toggle_button_get_active (tb));
1297 static GtkWidget *
1298 clonetiler_checkbox (GtkTooltips *tt, const char *tip, const char *attr)
1300     GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
1302     GtkWidget *b = gtk_check_button_new ();
1303     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, tip, NULL);
1305     int value = prefs_get_int_attribute (prefs_path, attr, 0);
1306     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(b), value);
1308     gtk_box_pack_end (GTK_BOX (hb), b, FALSE, TRUE, 0);
1309     gtk_signal_connect ( GTK_OBJECT (b), "clicked",
1310                          GTK_SIGNAL_FUNC (clonetiler_checkbox_toggled), (gpointer) attr);
1312     g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
1314     return hb;
1318 static void
1319 clonetiler_value_changed (GtkAdjustment *adj, gpointer data)
1321     const gchar *pref = (const gchar *) data;
1322     prefs_set_double_attribute (prefs_path, pref, adj->value);
1325 static GtkWidget *
1326 clonetiler_spinbox (GtkTooltips *tt, const char *tip, const char *attr, double lower, double upper, const gchar *suffix, bool exponent = false)
1328     GtkWidget *hb = gtk_hbox_new(FALSE, 0);
1330     {
1331         GtkObject *a;
1332         if (exponent)
1333             a = gtk_adjustment_new(1.0, lower, upper, 0.01, 0.05, 0.1);
1334         else
1335             a = gtk_adjustment_new(0.0, lower, upper, 0.1, 0.5, 2);
1337         GtkWidget *sb;
1338         if (exponent)
1339             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.01, 2);
1340         else
1341             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.1, 1);
1343         gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, tip, NULL);
1344         gtk_entry_set_width_chars (GTK_ENTRY (sb), 4);
1345         gtk_box_pack_start (GTK_BOX (hb), sb, FALSE, FALSE, SB_MARGIN);
1347         double value = prefs_get_double_attribute_limited (prefs_path, attr, exponent? 1 : 0, lower, upper);
1348         gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
1349         gtk_signal_connect(GTK_OBJECT(a), "value_changed",
1350                            GTK_SIGNAL_FUNC(clonetiler_value_changed), (gpointer) attr);
1352         if (exponent)
1353             g_object_set_data (G_OBJECT(sb), "oneable", GINT_TO_POINTER(TRUE));
1354         else
1355             g_object_set_data (G_OBJECT(sb), "zeroable", GINT_TO_POINTER(TRUE));
1356     }
1358     {
1359         GtkWidget *l = gtk_label_new ("");
1360         gtk_label_set_markup (GTK_LABEL(l), suffix);
1361         gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0);
1362         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
1363     }
1365     return hb;
1368 static void
1369 clonetiler_symgroup_changed (GtkMenuItem *item, gpointer data)
1371     gint group_new = GPOINTER_TO_INT (data);
1372     prefs_set_int_attribute ( prefs_path, "symmetrygroup", group_new );
1375 static void
1376 clonetiler_xy_changed (GtkAdjustment *adj, gpointer data)
1378     const gchar *pref = (const gchar *) data;
1379     prefs_set_int_attribute (prefs_path, pref, (int) floor(adj->value + 0.5));
1382 static void
1383 clonetiler_keep_bbox_toggled (GtkToggleButton *tb, gpointer data)
1385     prefs_set_int_attribute (prefs_path, "keepbbox", gtk_toggle_button_get_active (tb));
1388 static void
1389 clonetiler_pick_to (GtkToggleButton *tb, gpointer data)
1391     const gchar *pref = (const gchar *) data;
1392     prefs_set_int_attribute (prefs_path, pref, gtk_toggle_button_get_active (tb));
1396 static void
1397 clonetiler_reset_recursive (GtkWidget *w)
1399     if (w && GTK_IS_OBJECT(w)) {
1400         {
1401             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "zeroable"));
1402             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1403                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1404                 gtk_adjustment_set_value (a, 0);
1405             }
1406         }
1407         {
1408             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "oneable"));
1409             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1410                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1411                 gtk_adjustment_set_value (a, 1);
1412             }
1413         }
1414         {
1415             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "uncheckable"));
1416             if (r && GTK_IS_TOGGLE_BUTTON(w)) { // checkbox
1417                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(w), FALSE);
1418             }
1419         }
1420     }
1422     if (GTK_IS_CONTAINER(w)) {
1423         GList *ch = gtk_container_get_children (GTK_CONTAINER(w));
1424         for (GList *i = ch; i != NULL; i = i->next) {
1425             clonetiler_reset_recursive (GTK_WIDGET(i->data));
1426         }
1427         g_list_free (ch);
1428     }
1431 static void
1432 clonetiler_reset (GtkWidget *widget, void *)
1434     clonetiler_reset_recursive (dlg);
1437 static void
1438 clonetiler_table_attach (GtkWidget *table, GtkWidget *widget, float align, int row, int col)
1440     GtkWidget *a = gtk_alignment_new (align, 0, 0, 0);
1441     gtk_container_add(GTK_CONTAINER(a), widget);
1442     gtk_table_attach ( GTK_TABLE (table), a, col, col + 1, row, row + 1, (GtkAttachOptions)4, (GtkAttachOptions)0, 0, 0 );
1445 static GtkWidget *
1446 clonetiler_table_x_y_rand (int values)
1448     GtkWidget *table = gtk_table_new (values + 2, 5, FALSE);
1449     gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
1450     gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1451     gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1453     {
1454         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1456         GtkWidget *i = sp_icon_new (GTK_ICON_SIZE_MENU, "clonetiler_per_row");
1457         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1459         GtkWidget *l = gtk_label_new ("");
1460         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per row:</small>"));
1461         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1463         clonetiler_table_attach (table, hb, 0, 1, 2);
1464     }
1466     {
1467         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1469         GtkWidget *i = sp_icon_new (GTK_ICON_SIZE_MENU, "clonetiler_per_column");
1470         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1472         GtkWidget *l = gtk_label_new ("");
1473         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per column:</small>"));
1474         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1476         clonetiler_table_attach (table, hb, 0, 1, 3);
1477     }
1479     {
1480         GtkWidget *l = gtk_label_new ("");
1481         gtk_label_set_markup (GTK_LABEL(l), _("<small>Randomize:</small>"));
1482         clonetiler_table_attach (table, l, 0, 1, 4);
1483     }
1485     return table;
1488 static void
1489 clonetiler_pick_switched (GtkToggleButton *tb, gpointer data)
1491     guint v = GPOINTER_TO_INT (data);
1492     prefs_set_int_attribute (prefs_path, "pick", v);
1496 static void
1497 clonetiler_switch_to_create (GtkToggleButton *tb, GtkWidget *dlg)
1499     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1500     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1502     if (rowscols) {
1503         gtk_widget_set_sensitive (rowscols, TRUE);
1504     }
1505     if (widthheight) {
1506         gtk_widget_set_sensitive (widthheight, FALSE);
1507     }
1509     prefs_set_int_attribute (prefs_path, "fillrect", 0);
1513 static void
1514 clonetiler_switch_to_fill (GtkToggleButton *tb, GtkWidget *dlg)
1516     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1517     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1519     if (rowscols) {
1520         gtk_widget_set_sensitive (rowscols, FALSE);
1521     }
1522     if (widthheight) {
1523         gtk_widget_set_sensitive (widthheight, TRUE);
1524     }
1526     prefs_set_int_attribute (prefs_path, "fillrect", 1);
1532 static void
1533 clonetiler_fill_width_changed (GtkAdjustment *adj, GtkWidget *u)
1535     gdouble const raw_dist = adj->value;
1536     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1537     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1539     prefs_set_double_attribute (prefs_path, "fillwidth", pixels);
1542 static void
1543 clonetiler_fill_height_changed (GtkAdjustment *adj, GtkWidget *u)
1545     gdouble const raw_dist = adj->value;
1546     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1547     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1549     prefs_set_double_attribute (prefs_path, "fillheight", pixels);
1553 static void
1554 clonetiler_do_pick_toggled (GtkToggleButton *tb, gpointer data)
1556     GtkWidget *vvb = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "dotrace");
1558     prefs_set_int_attribute (prefs_path, "dotrace", gtk_toggle_button_get_active (tb));
1560     if (vvb)
1561         gtk_widget_set_sensitive (vvb, gtk_toggle_button_get_active (tb));
1567 void
1568 clonetiler_dialog (void)
1570     if (!dlg)
1571     {
1572         gchar title[500];
1573         sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_CLONETILER), title);
1575         dlg = sp_window_new (title, TRUE);
1576         if (x == -1000 || y == -1000) {
1577             x = prefs_get_int_attribute (prefs_path, "x", 0);
1578             y = prefs_get_int_attribute (prefs_path, "y", 0);
1579         }
1580         
1581         if (w ==0 || h == 0) {
1582             w = prefs_get_int_attribute (prefs_path, "w", 0);
1583             h = prefs_get_int_attribute (prefs_path, "h", 0);
1584         }
1585         
1586         if (x<0) x=0;
1587         if (y<0) y=0;
1589         if (x != 0 || y != 0) {
1590             gtk_window_move ((GtkWindow *) dlg, x, y);
1591         
1592         } else {
1593             gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
1594         }
1595         
1596         if (w && h) {
1597             gtk_window_resize ((GtkWindow *) dlg, w, h);
1598         }
1599         
1600         sp_transientize (dlg);
1601         wd.win = dlg;
1602         wd.stop = 0;
1603         
1604                              
1605         gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);
1606         
1607         gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (clonetiler_dialog_destroy), dlg);
1608         gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (clonetiler_dialog_delete), dlg);
1610         if (Inkscape::NSApplication::Application::getNewGui())
1611         {
1612             _shutdown_connection = Inkscape::NSApplication::Editor::connectShutdown (&on_delete);
1613             _dialogs_hidden_connection = Inkscape::NSApplication::Editor::connectDialogsHidden (sigc::bind (&on_dialog_hide, dlg));
1614             _dialogs_unhidden_connection = Inkscape::NSApplication::Editor::connectDialogsUnhidden (sigc::bind (&on_dialog_unhide, dlg));
1615             _desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::bind (&on_transientize, &wd));
1616         } else {            
1617             g_signal_connect   ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (clonetiler_dialog_delete), dlg);
1618             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg);
1619             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg);
1620             g_signal_connect   ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd);
1621         }
1623         GtkTooltips *tt = gtk_tooltips_new();
1625         GtkWidget *mainbox = gtk_vbox_new(FALSE, 4);
1626         gtk_container_set_border_width (GTK_CONTAINER (mainbox), 6);
1627         gtk_container_add (GTK_CONTAINER (dlg), mainbox);
1629         GtkWidget *nb = gtk_notebook_new ();
1630         gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0);
1633 // Symmetry
1634         {
1635             GtkWidget *vb = clonetiler_new_tab (nb, _("_Symmetry"));
1637             GtkWidget *om = gtk_option_menu_new ();
1638             /* TRANSLATORS: For the following 17 symmetry groups, see
1639              * http://www.bib.ulb.ac.be/coursmath/doc/17.htm (visual examples);
1640              * http://www.clarku.edu/~djoyce/wallpaper/seventeen.html (English vocabulary); or
1641              * http://membres.lycos.fr/villemingerard/Geometri/Sym1D.htm (French vocabulary).
1642              */
1643             gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), om, _("Select one of the 17 symmetry groups for the tiling"), NULL);
1644             gtk_box_pack_start (GTK_BOX (vb), om, FALSE, FALSE, SB_MARGIN);
1646             GtkWidget *m = gtk_menu_new ();
1647             int current = prefs_get_int_attribute (prefs_path, "symmetrygroup", 0);
1649             struct SymGroups {
1650                 int group;
1651                 gchar const *label;
1652             } const sym_groups[] = {
1653                 // TRANSLATORS: "translation" means "shift" / "displacement" here.
1654                 {TILE_P1, _("<b>P1</b>: simple translation")},
1655                 {TILE_P2, _("<b>P2</b>: 180&#176; rotation")},
1656                 {TILE_PM, _("<b>PM</b>: reflection")},
1657                 // TRANSLATORS: "glide reflection" is a reflection and a translation combined.
1658                 //  For more info, see http://mathforum.org/sum95/suzanne/symsusan.html
1659                 {TILE_PG, _("<b>PG</b>: glide reflection")},
1660                 {TILE_CM, _("<b>CM</b>: reflection + glide reflection")},
1661                 {TILE_PMM, _("<b>PMM</b>: reflection + reflection")},
1662                 {TILE_PMG, _("<b>PMG</b>: reflection + 180&#176; rotation")},
1663                 {TILE_PGG, _("<b>PGG</b>: glide reflection + 180&#176; rotation")},
1664                 {TILE_CMM, _("<b>CMM</b>: reflection + reflection + 180&#176; rotation")},
1665                 {TILE_P4, _("<b>P4</b>: 90&#176; rotation")},
1666                 {TILE_P4M, _("<b>P4M</b>: 90&#176; rotation + 45&#176; reflection")},
1667                 {TILE_P4G, _("<b>P4G</b>: 90&#176; rotation + 90&#176; reflection")},
1668                 {TILE_P3, _("<b>P3</b>: 120&#176; rotation")},
1669                 {TILE_P31M, _("<b>P31M</b>: reflection + 120&#176; rotation, dense")},
1670                 {TILE_P3M1, _("<b>P3M1</b>: reflection + 120&#176; rotation, sparse")},
1671                 {TILE_P6, _("<b>P6</b>: 60&#176; rotation")},
1672                 {TILE_P6M, _("<b>P6M</b>: reflection + 60&#176; rotation")},
1673             };
1675             for (unsigned j = 0; j < G_N_ELEMENTS(sym_groups); ++j) {
1676                 SymGroups const &sg = sym_groups[j];
1678                 GtkWidget *l = gtk_label_new ("");
1679                 gtk_label_set_markup (GTK_LABEL(l), sg.label);
1680                 gtk_misc_set_alignment (GTK_MISC(l), 0, 0.5);
1682                 GtkWidget *item = gtk_menu_item_new ();
1683                 gtk_container_add (GTK_CONTAINER (item), l);
1685                 gtk_signal_connect ( GTK_OBJECT (item), "activate",
1686                                      GTK_SIGNAL_FUNC (clonetiler_symgroup_changed),
1687                                      GINT_TO_POINTER (sg.group) );
1689                 gtk_menu_append (GTK_MENU (m), item);
1690             }
1692             gtk_option_menu_set_menu (GTK_OPTION_MENU (om), m);
1693             gtk_option_menu_set_history ( GTK_OPTION_MENU (om), current);
1694         }
1696         table_row_labels = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1698 // Shift
1699         {
1700             GtkWidget *vb = clonetiler_new_tab (nb, _("S_hift"));
1702             GtkWidget *table = clonetiler_table_x_y_rand (3);
1703             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1705             // X
1706             {
1707                 GtkWidget *l = gtk_label_new ("");
1708                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) horizontally by this amount
1709                     // xgettext:no-c-format
1710                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift X:</b>"));
1711                 gtk_size_group_add_widget(table_row_labels, l);
1712                 clonetiler_table_attach (table, l, 1, 2, 1);
1713             }
1715             {
1716                 GtkWidget *l = clonetiler_spinbox (tt,
1717                     // xgettext:no-c-format
1718                                                    _("Horizontal shift per row (in % of tile width)"), "d_x_per_y",
1719                                                    -100, 1000, "%");
1720                 clonetiler_table_attach (table, l, 0, 2, 2);
1721             }
1723             {
1724                 GtkWidget *l = clonetiler_spinbox (tt,
1725                     // xgettext:no-c-format
1726                                                    _("Horizontal shift per column (in % of tile width)"), "d_x_per_x",
1727                                                    -100, 1000, "%");
1728                 clonetiler_table_attach (table, l, 0, 2, 3);
1729             }
1731             {
1732                 GtkWidget *l = clonetiler_spinbox (tt,
1733                                                    _("Randomize the horizontal shift by this percentage"), "rand_x",
1734                                                    0, 1000, "%");
1735                 clonetiler_table_attach (table, l, 0, 2, 4);
1736             }
1738             // Y
1739             {
1740                 GtkWidget *l = gtk_label_new ("");
1741                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) vertically by this amount
1742                     // xgettext:no-c-format
1743                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift Y:</b>"));
1744                 gtk_size_group_add_widget(table_row_labels, l);
1745                 clonetiler_table_attach (table, l, 1, 3, 1);
1746             }
1748             {
1749                 GtkWidget *l = clonetiler_spinbox (tt,
1750                     // xgettext:no-c-format
1751                                                    _("Vertical shift per row (in % of tile height)"), "d_y_per_y",
1752                                                    -100, 1000, "%");
1753                 clonetiler_table_attach (table, l, 0, 3, 2);
1754             }
1756             {
1757                 GtkWidget *l = clonetiler_spinbox (tt,
1758                     // xgettext:no-c-format
1759                                                    _("Vertical shift per column (in % of tile height)"), "d_y_per_x",
1760                                                    -100, 1000, "%");
1761                 clonetiler_table_attach (table, l, 0, 3, 3);
1762             }
1764             {
1765                 GtkWidget *l = clonetiler_spinbox (tt,
1766                                                    _("Randomize the vertical shift by this percentage"), "rand_y",
1767                                                    0, 1000, "%");
1768                 clonetiler_table_attach (table, l, 0, 3, 4);
1769             }
1771             // Exponent
1772             {
1773                 GtkWidget *l = gtk_label_new ("");
1774                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
1775                 gtk_size_group_add_widget(table_row_labels, l);
1776                 clonetiler_table_attach (table, l, 1, 4, 1);
1777             }
1779             {
1780                 GtkWidget *l = clonetiler_spinbox (tt,
1781                                                    _("Whether rows are spaced evenly (1), converge (<1) or diverge (>1)"), "d_per_y_exp",
1782                                                    0, 10, "", true);
1783                 clonetiler_table_attach (table, l, 0, 4, 2);
1784             }
1786             {
1787                 GtkWidget *l = clonetiler_spinbox (tt,
1788                                                    _("Whether columns are spaced evenly (1), converge (<1) or diverge (>1)"), "d_per_x_exp",
1789                                                    0, 10, "", true);
1790                 clonetiler_table_attach (table, l, 0, 4, 3);
1791             }
1793             { // alternates
1794                 GtkWidget *l = gtk_label_new ("");
1795                 // TRANSLATORS: "Alternate" is a verb here
1796                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
1797                 gtk_size_group_add_widget(table_row_labels, l);
1798                 clonetiler_table_attach (table, l, 1, 5, 1);
1799             }
1801             {
1802                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each row"), "alternate_y");
1803                 clonetiler_table_attach (table, l, 0, 5, 2);
1804             }
1806             {
1807                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each column"), "alternate_x");
1808                 clonetiler_table_attach (table, l, 0, 5, 3);
1809             }
1811         }
1814 // Scale
1815         {
1816             GtkWidget *vb = clonetiler_new_tab (nb, _("Sc_ale"));
1818             GtkWidget *table = clonetiler_table_x_y_rand (2);
1819             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1821             // X
1822             {
1823                 GtkWidget *l = gtk_label_new ("");
1824                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale X:</b>"));
1825                 gtk_size_group_add_widget(table_row_labels, l);
1826                 clonetiler_table_attach (table, l, 1, 2, 1);
1827             }
1829             {
1830                 GtkWidget *l = clonetiler_spinbox (tt,
1831                     // xgettext:no-c-format
1832                                                    _("Horizontal scale per row (in % of tile width)"), "d_scalex_per_y",
1833                                                    -100, 1000, "%");
1834                 clonetiler_table_attach (table, l, 0, 2, 2);
1835             }
1837             {
1838                 GtkWidget *l = clonetiler_spinbox (tt,
1839                     // xgettext:no-c-format
1840                                                    _("Horizontal scale per column (in % of tile width)"), "d_scalex_per_x",
1841                                                    -100, 1000, "%");
1842                 clonetiler_table_attach (table, l, 0, 2, 3);
1843             }
1845             {
1846                 GtkWidget *l = clonetiler_spinbox (tt,
1847                                                    _("Randomize the horizontal scale by this percentage"), "rand_scalex",
1848                                                    0, 1000, "%");
1849                 clonetiler_table_attach (table, l, 0, 2, 4);
1850             }
1852             // Y
1853             {
1854                 GtkWidget *l = gtk_label_new ("");
1855                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale Y:</b>"));
1856                 gtk_size_group_add_widget(table_row_labels, l);
1857                 clonetiler_table_attach (table, l, 1, 3, 1);
1858             }
1860             {
1861                 GtkWidget *l = clonetiler_spinbox (tt,
1862                     // xgettext:no-c-format
1863                                                    _("Vertical scale per row (in % of tile height)"), "d_scaley_per_y",
1864                                                    -100, 1000, "%");
1865                 clonetiler_table_attach (table, l, 0, 3, 2);
1866             }
1868             {
1869                 GtkWidget *l = clonetiler_spinbox (tt,
1870                     // xgettext:no-c-format
1871                                                    _("Vertical scale per column (in % of tile height)"), "d_scaley_per_x",
1872                                                    -100, 1000, "%");
1873                 clonetiler_table_attach (table, l, 0, 3, 3);
1874             }
1876             {
1877                 GtkWidget *l = clonetiler_spinbox (tt,
1878                                                    _("Randomize the vertical scale by this percentage"), "rand_scaley",
1879                                                    0, 1000, "%");
1880                 clonetiler_table_attach (table, l, 0, 3, 4);
1881             }
1883             { // alternates
1884                 GtkWidget *l = gtk_label_new ("");
1885                 // TRANSLATORS: "Alternate" is a verb here
1886                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
1887                 gtk_size_group_add_widget(table_row_labels, l);
1888                 clonetiler_table_attach (table, l, 1, 4, 1);
1889             }
1891             {
1892                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each row"), "alternate_scaley");
1893                 clonetiler_table_attach (table, l, 0, 4, 2);
1894             }
1896             {
1897                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each column"), "alternate_scalex");
1898                 clonetiler_table_attach (table, l, 0, 4, 3);
1899             }
1901         }
1904 // Rotation
1905         {
1906             GtkWidget *vb = clonetiler_new_tab (nb, _("_Rotation"));
1908             GtkWidget *table = clonetiler_table_x_y_rand (1);
1909             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1911             // Angle
1912             {
1913                 GtkWidget *l = gtk_label_new ("");
1914                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Angle:</b>"));
1915                 gtk_size_group_add_widget(table_row_labels, l);
1916                 clonetiler_table_attach (table, l, 1, 2, 1);
1917             }
1919             {
1920                 GtkWidget *l = clonetiler_spinbox (tt,
1921                     // xgettext:no-c-format
1922                                                    _("Rotate tiles by this angle for each row"), "d_rot_per_y",
1923                                                    -180, 180, "&#176;");
1924                 clonetiler_table_attach (table, l, 0, 2, 2);
1925             }
1927             {
1928                 GtkWidget *l = clonetiler_spinbox (tt,
1929                     // xgettext:no-c-format
1930                                                    _("Rotate tiles by this angle for each column"), "d_rot_per_x",
1931                                                    -180, 180, "&#176;");
1932                 clonetiler_table_attach (table, l, 0, 2, 3);
1933             }
1935             {
1936                 GtkWidget *l = clonetiler_spinbox (tt,
1937                                                    _("Randomize the rotation angle by this percentage"), "rand_rot",
1938                                                    0, 100, "%");
1939                 clonetiler_table_attach (table, l, 0, 2, 4);
1940             }
1942             { // alternates
1943                 GtkWidget *l = gtk_label_new ("");
1944                 // TRANSLATORS: "Alternate" is a verb here
1945                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
1946                 gtk_size_group_add_widget(table_row_labels, l);
1947                 clonetiler_table_attach (table, l, 1, 3, 1);
1948             }
1950             {
1951                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each row"), "alternate_roty");
1952                 clonetiler_table_attach (table, l, 0, 3, 2);
1953             }
1955             {
1956                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each column"), "alternate_rotx");
1957                 clonetiler_table_attach (table, l, 0, 3, 3);
1958             }
1959         }
1962 // Opacity
1963         {
1964             GtkWidget *vb = clonetiler_new_tab (nb, _("_Opacity"));
1966             GtkWidget *table = clonetiler_table_x_y_rand (1);
1967             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1969             // Dissolve
1970             {
1971                 GtkWidget *l = gtk_label_new ("");
1972                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Fade out:</b>"));
1973                 gtk_size_group_add_widget(table_row_labels, l);
1974                 clonetiler_table_attach (table, l, 1, 2, 1);
1975             }
1977             {
1978                 GtkWidget *l = clonetiler_spinbox (tt,
1979                                                    _("Decrease tile opacity by this percentage for each row"), "d_opacity_per_y",
1980                                                    0, 100, "%");
1981                 clonetiler_table_attach (table, l, 0, 2, 2);
1982             }
1984             {
1985                 GtkWidget *l = clonetiler_spinbox (tt,
1986                                                    _("Decrease tile opacity by this percentage for each column"), "d_opacity_per_x",
1987                                                    0, 100, "%");
1988                 clonetiler_table_attach (table, l, 0, 2, 3);
1989             }
1991             {
1992                 GtkWidget *l = clonetiler_spinbox (tt,
1993                                                    _("Randomize the tile opacity by this percentage"), "rand_opacity",
1994                                                    0, 100, "%");
1995                 clonetiler_table_attach (table, l, 0, 2, 4);
1996             }
1998             { // alternates
1999                 GtkWidget *l = gtk_label_new ("");
2000                 // TRANSLATORS: "Alternate" is a verb here
2001                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2002                 gtk_size_group_add_widget(table_row_labels, l);
2003                 clonetiler_table_attach (table, l, 1, 3, 1);
2004             }
2006             {
2007                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each row"), "alternate_opacityy");
2008                 clonetiler_table_attach (table, l, 0, 3, 2);
2009             }
2011             {
2012                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each column"), "alternate_opacityx");
2013                 clonetiler_table_attach (table, l, 0, 3, 3);
2014             }
2015         }
2018 // Color
2019         {
2020             GtkWidget *vb = clonetiler_new_tab (nb, _("Co_lor"));
2022             {
2023             GtkWidget *hb = gtk_hbox_new (FALSE, 0);
2025             GtkWidget *l = gtk_label_new (_("Initial color: "));
2026             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2028             guint32 rgba = 0x000000ff | sp_svg_read_color (prefs_get_string_attribute(prefs_path, "initial_color"), 0x000000ff);
2029             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);
2030             _color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed));
2032             gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast<GtkWidget*>(color_picker->gobj()), FALSE, FALSE, 0);
2034             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2035             }
2038             GtkWidget *table = clonetiler_table_x_y_rand (3);
2039             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2041             // Hue
2042             {
2043                 GtkWidget *l = gtk_label_new ("");
2044                 gtk_label_set_markup (GTK_LABEL(l), _("<b>H:</b>"));
2045                 gtk_size_group_add_widget(table_row_labels, l);
2046                 clonetiler_table_attach (table, l, 1, 2, 1);
2047             }
2049             {
2050                 GtkWidget *l = clonetiler_spinbox (tt,
2051                                                    _("Change the tile hue by this percentage for each row"), "d_hue_per_y",
2052                                                    -100, 100, "%");
2053                 clonetiler_table_attach (table, l, 0, 2, 2);
2054             }
2056             {
2057                 GtkWidget *l = clonetiler_spinbox (tt,
2058                                                    _("Change the tile hue by this percentage for each column"), "d_hue_per_x",
2059                                                    -100, 100, "%");
2060                 clonetiler_table_attach (table, l, 0, 2, 3);
2061             }
2063             {
2064                 GtkWidget *l = clonetiler_spinbox (tt,
2065                                                    _("Randomize the tile hue by this percentage"), "rand_hue",
2066                                                    0, 100, "%");
2067                 clonetiler_table_attach (table, l, 0, 2, 4);
2068             }
2071             // Saturation
2072             {
2073                 GtkWidget *l = gtk_label_new ("");
2074                 gtk_label_set_markup (GTK_LABEL(l), _("<b>S:</b>"));
2075                 gtk_size_group_add_widget(table_row_labels, l);
2076                 clonetiler_table_attach (table, l, 1, 3, 1);
2077             }
2079             {
2080                 GtkWidget *l = clonetiler_spinbox (tt,
2081                                                    _("Change the color saturation by this percentage for each row"), "d_saturation_per_y",
2082                                                    -100, 100, "%");
2083                 clonetiler_table_attach (table, l, 0, 3, 2);
2084             }
2086             {
2087                 GtkWidget *l = clonetiler_spinbox (tt,
2088                                                    _("Change the color saturation by this percentage for each column"), "d_saturation_per_x",
2089                                                    -100, 100, "%");
2090                 clonetiler_table_attach (table, l, 0, 3, 3);
2091             }
2093             {
2094                 GtkWidget *l = clonetiler_spinbox (tt,
2095                                                    _("Randomize the color saturation by this percentage"), "rand_saturation",
2096                                                    0, 100, "%");
2097                 clonetiler_table_attach (table, l, 0, 3, 4);
2098             }
2100             // Lightness
2101             {
2102                 GtkWidget *l = gtk_label_new ("");
2103                 gtk_label_set_markup (GTK_LABEL(l), _("<b>L:</b>"));
2104                 gtk_size_group_add_widget(table_row_labels, l);
2105                 clonetiler_table_attach (table, l, 1, 4, 1);
2106             }
2108             {
2109                 GtkWidget *l = clonetiler_spinbox (tt,
2110                                                    _("Change the color lightness by this percentage for each row"), "d_lightness_per_y",
2111                                                    -100, 100, "%");
2112                 clonetiler_table_attach (table, l, 0, 4, 2);
2113             }
2115             {
2116                 GtkWidget *l = clonetiler_spinbox (tt,
2117                                                    _("Change the color lightness by this percentage for each column"), "d_lightness_per_x",
2118                                                    -100, 100, "%");
2119                 clonetiler_table_attach (table, l, 0, 4, 3);
2120             }
2122             {
2123                 GtkWidget *l = clonetiler_spinbox (tt,
2124                                                    _("Randomize the color lightness by this percentage"), "rand_lightness",
2125                                                    0, 100, "%");
2126                 clonetiler_table_attach (table, l, 0, 4, 4);
2127             }
2130             { // alternates
2131                 GtkWidget *l = gtk_label_new ("");
2132                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2133                 gtk_size_group_add_widget(table_row_labels, l);
2134                 clonetiler_table_attach (table, l, 1, 5, 1);
2135             }
2137             {
2138                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each row"), "alternate_color_y");
2139                 clonetiler_table_attach (table, l, 0, 5, 2);
2140             }
2142             {
2143                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each column"), "alternate_color_x");
2144                 clonetiler_table_attach (table, l, 0, 5, 3);
2145             }
2147         }
2149 // Trace
2150         {
2151             GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace"));
2154         {
2155             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2156             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2158             GtkWidget *b  = gtk_check_button_new_with_label (_("Trace the drawing under the tiles"));
2159             g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
2160             gint old = prefs_get_int_attribute (prefs_path, "dotrace", 0);
2161             gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2162             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);
2163             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2165             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2166                                GTK_SIGNAL_FUNC(clonetiler_do_pick_toggled), dlg);
2167         }
2169         {
2170             GtkWidget *vvb = gtk_vbox_new (FALSE, 0);
2171             gtk_box_pack_start (GTK_BOX (vb), vvb, FALSE, FALSE, 0);
2172             g_object_set_data (G_OBJECT(dlg), "dotrace", (gpointer) vvb);
2175             {
2176                 GtkWidget *frame = gtk_frame_new (_("1. Pick from the drawing:"));
2177                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2179                 GtkWidget *table = gtk_table_new (3, 3, FALSE);
2180                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2181                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2182                 gtk_container_add(GTK_CONTAINER(frame), table);
2185                 GtkWidget* radio;
2186                 {
2187                     radio = gtk_radio_button_new_with_label (NULL, _("Color"));
2188                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the visible color and opacity"), NULL);
2189                     clonetiler_table_attach (table, radio, 0.0, 1, 1);
2190                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2191                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_COLOR));
2192                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_COLOR);
2193                 }
2194                 {
2195                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Opacity"));
2196                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the total accumulated opacity"), NULL);
2197                     clonetiler_table_attach (table, radio, 0.0, 2, 1);
2198                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2199                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_OPACITY));
2200                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_OPACITY);
2201                 }
2202                 {
2203                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("R"));
2204                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Red component of the color"), NULL);
2205                     clonetiler_table_attach (table, radio, 0.0, 1, 2);
2206                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2207                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_R));
2208                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_R);
2209                 }
2210                 {
2211                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("G"));
2212                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Green component of the color"), NULL);
2213                     clonetiler_table_attach (table, radio, 0.0, 2, 2);
2214                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2215                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_G));
2216                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_G);
2217                 }
2218                 {
2219                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("B"));
2220                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Blue component of the color"), NULL);
2221                     clonetiler_table_attach (table, radio, 0.0, 3, 2);
2222                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2223                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_B));
2224                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_B);
2225                 }
2226                 {
2227                     //TRANSLATORS: only translate "string" in "context|string". 
2228                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2229                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|H"));
2230                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the hue of the color"), NULL);
2231                     clonetiler_table_attach (table, radio, 0.0, 1, 3);
2232                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2233                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_H));
2234                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_H);
2235                 }
2236                 {
2237                     //TRANSLATORS: only translate "string" in "context|string". 
2238                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2239                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|S"));
2240                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the saturation of the color"), NULL);
2241                     clonetiler_table_attach (table, radio, 0.0, 2, 3);
2242                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2243                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_S));
2244                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_S);
2245                 }
2246                 {
2247                     //TRANSLATORS: only translate "string" in "context|string". 
2248                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2249                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|L"));
2250                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the lightness of the color"), NULL);
2251                     clonetiler_table_attach (table, radio, 0.0, 3, 3);
2252                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2253                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_L));
2254                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_L);
2255                 }
2257             }
2259             {
2260                 GtkWidget *frame = gtk_frame_new (_("2. Tweak the picked value:"));
2261                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, VB_MARGIN);
2263                 GtkWidget *table = gtk_table_new (4, 2, FALSE);
2264                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2265                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2266                 gtk_container_add(GTK_CONTAINER(frame), table);
2268                 {
2269                     GtkWidget *l = gtk_label_new ("");
2270                     gtk_label_set_markup (GTK_LABEL(l), _("Gamma-correct:"));
2271                     clonetiler_table_attach (table, l, 1.0, 1, 1);
2272                 }
2273                 {
2274                     GtkWidget *l = clonetiler_spinbox (tt,
2275                                                        _("Shift the mid-range of the picked value upwards (>0) or downwards (<0)"), "gamma_picked",
2276                                                        -10, 10, "");
2277                     clonetiler_table_attach (table, l, 0.0, 1, 2);
2278                 }
2280                 {
2281                     GtkWidget *l = gtk_label_new ("");
2282                     gtk_label_set_markup (GTK_LABEL(l), _("Randomize:"));
2283                     clonetiler_table_attach (table, l, 1.0, 1, 3);
2284                 }
2285                 {
2286                     GtkWidget *l = clonetiler_spinbox (tt,
2287                                                        _("Randomize the picked value by this percentage"), "rand_picked",
2288                                                        0, 100, "%");
2289                     clonetiler_table_attach (table, l, 0.0, 1, 4);
2290                 }
2292                 {
2293                     GtkWidget *l = gtk_label_new ("");
2294                     gtk_label_set_markup (GTK_LABEL(l), _("Invert:"));
2295                     clonetiler_table_attach (table, l, 1.0, 2, 1);
2296                 }
2297                 {
2298                     GtkWidget *l = clonetiler_checkbox (tt, _("Invert the picked value"), "invert_picked");
2299                     clonetiler_table_attach (table, l, 0.0, 2, 2);
2300                 }
2301             }
2303             {
2304                 GtkWidget *frame = gtk_frame_new (_("3. Apply the value to the clones':"));
2305                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2308                 GtkWidget *table = gtk_table_new (2, 2, FALSE);
2309                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2310                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2311                 gtk_container_add(GTK_CONTAINER(frame), table);
2313                 {
2314                     GtkWidget *b  = gtk_check_button_new_with_label (_("Presence"));
2315                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_presence", 1);
2316                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2317                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone is created with the probability determined by the picked value in that point"), NULL);
2318                     clonetiler_table_attach (table, b, 0.0, 1, 1);
2319                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2320                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_presence");
2321                 }
2323                 {
2324                     GtkWidget *b  = gtk_check_button_new_with_label (_("Size"));
2325                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_size", 0);
2326                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2327                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's size is determined by the picked value in that point"), NULL);
2328                     clonetiler_table_attach (table, b, 0.0, 2, 1);
2329                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2330                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_size");
2331                 }
2333                 {
2334                     GtkWidget *b  = gtk_check_button_new_with_label (_("Color"));
2335                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_color", 0);
2336                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2337                     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);
2338                     clonetiler_table_attach (table, b, 0.0, 1, 2);
2339                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2340                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_color");
2341                 }
2343                 {
2344                     GtkWidget *b  = gtk_check_button_new_with_label (_("Opacity"));
2345                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_opacity", 0);
2346                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2347                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's opacity is determined by the picked value in that point"), NULL);
2348                     clonetiler_table_attach (table, b, 0.0, 2, 2);
2349                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2350                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_opacity");
2351                 }
2352             }
2353            gtk_widget_set_sensitive (vvb, prefs_get_int_attribute (prefs_path, "dotrace", 0));
2354         }
2355         }
2357 // Rows/columns, width/height
2358         {
2359             GtkWidget *table = gtk_table_new (2, 2, FALSE);
2360             gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
2361             gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2362             gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2363             gtk_box_pack_start (GTK_BOX (mainbox), table, FALSE, FALSE, 0);
2365             {
2366                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2367                 g_object_set_data (G_OBJECT(dlg), "rowscols", (gpointer) hb);
2369                 {
2370                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2371                     int value = prefs_get_int_attribute (prefs_path, "ymax", 2);
2372                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2373                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2374                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many rows in the tiling"), NULL);
2375                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2376                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2378                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2379                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "ymax");
2380                 }
2382                 {
2383                     GtkWidget *l = gtk_label_new ("");
2384                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2385                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2386                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2387                 }
2389                 {
2390                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2391                     int value = prefs_get_int_attribute (prefs_path, "xmax", 2);
2392                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2393                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2394                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many columns in the tiling"), NULL);
2395                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2396                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2398                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2399                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "xmax");
2400                 }
2402                 clonetiler_table_attach (table, hb, 0.0, 1, 2);
2403             }
2405             {
2406                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2407                 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
2409                 // unitmenu
2410                 GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
2411                 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), SP_DT_NAMEDVIEW(SP_ACTIVE_DESKTOP)->doc_units);
2412     
2413                 {
2414                     // Width spinbutton 
2415                     GtkObject *a = gtk_adjustment_new (0.0, -SP_DESKTOP_SCROLL_LIMIT, SP_DESKTOP_SCROLL_LIMIT, 1.0, 10.0, 10.0);
2416                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2418                     double value = prefs_get_double_attribute (prefs_path, "fillwidth", 50);
2419                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2420                     gdouble const units = sp_pixels_get_units (value, unit);
2421                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2423                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2424                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Width of the rectangle to be filled"), NULL);
2425                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2426                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2427                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2428                                        GTK_SIGNAL_FUNC(clonetiler_fill_width_changed), u);
2429                 }
2430                 {
2431                     GtkWidget *l = gtk_label_new ("");
2432                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2433                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2434                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2435                 }
2437                 {
2438                     // Height spinbutton
2439                     GtkObject *a = gtk_adjustment_new (0.0, -SP_DESKTOP_SCROLL_LIMIT, SP_DESKTOP_SCROLL_LIMIT, 1.0, 10.0, 10.0);
2440                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2442                     double value = prefs_get_double_attribute (prefs_path, "fillheight", 50);
2443                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2444                     gdouble const units = sp_pixels_get_units (value, unit);
2445                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2448                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2449                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Height of the rectangle to be filled"), NULL);
2450                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2451                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2452                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2453                                        GTK_SIGNAL_FUNC(clonetiler_fill_height_changed), u);
2454                 }
2456                 gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);
2457                 clonetiler_table_attach (table, hb, 0.0, 2, 2);
2459             }
2461             // Switch
2462             GtkWidget* radio;
2463             {
2464                 radio = gtk_radio_button_new_with_label (NULL, _("Rows, columns: "));
2465                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Create the specified number of rows and columns"), NULL);
2466                 clonetiler_table_attach (table, radio, 0.0, 1, 1);
2467                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_create), (gpointer) dlg);
2468             }
2469             if (prefs_get_int_attribute(prefs_path, "fillrect", 0) == 0) {
2470                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2471                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2472             }
2473             {
2474                 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Width, height: "));
2475                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Fill the specified width and height with the tiling"), NULL);
2476                 clonetiler_table_attach (table, radio, 0.0, 2, 1);
2477                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_fill), (gpointer) dlg);
2478             }
2479             if (prefs_get_int_attribute(prefs_path, "fillrect", 0) == 1) {
2480                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2481                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2482             }
2483         }
2486 // Use saved pos
2487         {
2488             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2489             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2491             GtkWidget *b  = gtk_check_button_new_with_label (_("Use saved size and position of the tile"));
2492             gint keepbbox = prefs_get_int_attribute (prefs_path, "keepbbox", 1);
2493             gtk_toggle_button_set_active ((GtkToggleButton *) b, keepbbox != 0);
2494             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);
2495             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2497             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2498                                GTK_SIGNAL_FUNC(clonetiler_keep_bbox_toggled), NULL);
2499         }
2501 // Statusbar
2502         {
2503             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2504             gtk_box_pack_end (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2505             GtkWidget *l = gtk_label_new("");
2506             g_object_set_data (G_OBJECT(dlg), "status", (gpointer) l);
2507             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2508         }
2510 // Buttons
2511         {
2512             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2513             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2515             {
2516                 GtkWidget *b = gtk_button_new ();
2517                 GtkWidget *l = gtk_label_new ("");
2518                 gtk_label_set_markup_with_mnemonic (GTK_LABEL(l), _(" <b>_Create</b> "));
2519                 gtk_container_add (GTK_CONTAINER(b), l);
2520                 gtk_tooltips_set_tip (tt, b, _("Create and tile the clones of the selection"), NULL);
2521                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_apply), NULL);
2522                 gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0);
2523             }
2525             { // buttons which are enabled only when there are tiled clones
2526                 GtkWidget *sb = gtk_hbox_new(FALSE, 0);
2527                 gtk_box_pack_end (GTK_BOX (hb), sb, FALSE, FALSE, 0);
2528                 g_object_set_data (G_OBJECT(dlg), "buttons_on_tiles", (gpointer) sb);
2529                 {
2530                     // TRANSLATORS: if a group of objects are "clumped" together, then they
2531                     //  are unevenly spread in the given amount of space - as shown in the
2532                     //  diagrams on the left in the following screenshot:
2533                     //  http://www.inkscape.org/screenshots/gallery/inkscape-0.42-CVS-tiles-unclump.png
2534                     //  So unclumping is the process of spreading a number of objects out more evenly.
2535                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" _Unclump "));
2536                     gtk_tooltips_set_tip (tt, b, _("Spread out clones to reduce clumping; can be applied repeatedly"), NULL);
2537                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_unclump), NULL);
2538                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2539                 }
2541                 {
2542                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" Re_move "));
2543                     gtk_tooltips_set_tip (tt, b, _("Remove existing tiled clones of the selected object (siblings only)"), NULL);
2544                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_remove), NULL);
2545                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2546                 }
2548                 // connect to global selection changed signal (so we can change desktops) and
2549                 // external_change (so we're not fooled by undo)
2550                 g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (clonetiler_change_selection), dlg);
2551                 g_signal_connect (G_OBJECT (INKSCAPE), "external_change", G_CALLBACK (clonetiler_external_change), dlg);
2552                 g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), G_OBJECT (INKSCAPE));
2554                 // update now
2555                 clonetiler_change_selection (NULL, SP_DT_SELECTION(SP_ACTIVE_DESKTOP), dlg);
2556             }
2558             {
2559                 GtkWidget *b = gtk_button_new_with_mnemonic (_(" R_eset "));
2560                 // TRANSLATORS: "change" is a noun here
2561                 gtk_tooltips_set_tip (tt, b, _("Reset all shifts, scales, rotates, opacity and color changes in the dialog to zero"), NULL);
2562                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_reset), NULL);
2563                 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2564             }
2565         }
2567         gtk_widget_show_all (mainbox);
2569     } // end of if (!dlg)
2571     gtk_window_present ((GtkWindow *) dlg);
2575 /*
2576   Local Variables:
2577   mode:c++
2578   c-file-style:"stroustrup"
2579   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2580   indent-tabs-mode:nil
2581   fill-column:99
2582   End:
2583 */
2584 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :