Code

preserve (but not use yet) rotation center when making tiled clones
[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.h"
34 #include "../desktop-handles.h"
35 #include "../sp-namedview.h"
36 #include "../document.h"
37 #include "../message-stack.h"
38 #include "../sp-use.h"
39 #include "unclump.h"
41 #include "xml/repr.h"
43 #include "svg/svg.h"
44 #include "svg/svg-color.h"
46 #include "libnr/nr-matrix-fns.h"
47 #include "libnr/nr-matrix-ops.h"
49 #include "libnr/nr-matrix-translate-ops.h"
50 #include "libnr/nr-translate-ops.h"
51 #include "libnr/nr-translate-rotate-ops.h"
52 #include "libnr/nr-translate-scale-ops.h"
54 #include "display/nr-arena.h"
55 #include "display/nr-arena-item.h"
57 #include "ui/widget/color-picker.h"
59 static GtkWidget *dlg = NULL;
60 static win_data wd;
62 // impossible original values to make sure they are read from prefs
63 static gint x = -1000, y = -1000, w = 0, h = 0;
64 static gchar *prefs_path = "dialogs.clonetiler";
66 #define SB_MARGIN 1
67 #define VB_MARGIN 4
69 enum {
70     PICK_COLOR,
71     PICK_OPACITY,
72     PICK_R,
73     PICK_G,
74     PICK_B,
75     PICK_H,
76     PICK_S,
77     PICK_L
78 };
80 static GtkSizeGroup* table_row_labels = NULL;
82 static sigc::connection _shutdown_connection;
83 static sigc::connection _dialogs_hidden_connection;
84 static sigc::connection _dialogs_unhidden_connection;
85 static sigc::connection _desktop_activated_connection;
86 static sigc::connection _color_changed_connection;
88 static Inkscape::UI::Widget::ColorPicker *color_picker;
90 static void
91 clonetiler_dialog_destroy (GtkObject *object, gpointer data)
92 {
93     if (Inkscape::NSApplication::Application::getNewGui())
94     {
95         _shutdown_connection.disconnect();
96         _dialogs_hidden_connection.disconnect();
97         _dialogs_unhidden_connection.disconnect();
98         _desktop_activated_connection.disconnect();
99     } else {
100         sp_signal_disconnect_by_data (INKSCAPE, dlg);
101     }
102     _color_changed_connection.disconnect();
104     delete color_picker;
105     
106     wd.win = dlg = NULL;
107     wd.stop = 0;
111 static gboolean
112 clonetiler_dialog_delete (GtkObject *object, GdkEvent * /*event*/, gpointer data)
114     gtk_window_get_position ((GtkWindow *) dlg, &x, &y);
115     gtk_window_get_size ((GtkWindow *) dlg, &w, &h);
117     if (x<0) x=0;
118     if (y<0) y=0;
120     prefs_set_int_attribute (prefs_path, "x", x);
121     prefs_set_int_attribute (prefs_path, "y", y);
122     prefs_set_int_attribute (prefs_path, "w", w);
123     prefs_set_int_attribute (prefs_path, "h", h);
125     return FALSE; // which means, go ahead and destroy it
129 static void on_delete()
131     (void)clonetiler_dialog_delete (0, 0, NULL);
134 static void
135 on_picker_color_changed (guint rgba)
137     static bool is_updating = false;
138     if (is_updating || !SP_ACTIVE_DESKTOP)
139         return;
141     is_updating = true;
143     Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, prefs_path);
144     gchar c[32];
145     sp_svg_write_color(c, 32, rgba);
146     repr->setAttribute("initial_color", c);
148     is_updating = false;
151 static guint clonetiler_number_of_clones (SPObject *obj);
153 static void
154 clonetiler_change_selection (Inkscape::Application * /*inkscape*/, Inkscape::Selection *selection, GtkWidget *dlg)
156     GtkWidget *buttons = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "buttons_on_tiles");
157     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
159     if (selection->isEmpty()) {
160         gtk_widget_set_sensitive (buttons, FALSE);
161         gtk_label_set_markup (GTK_LABEL(status), _("<small>Nothing selected.</small>"));
162         return;
163     }
165     if (g_slist_length ((GSList *) selection->itemList()) > 1) {
166         gtk_widget_set_sensitive (buttons, FALSE);
167         gtk_label_set_markup (GTK_LABEL(status), _("<small>More than one object selected.</small>"));
168         return;
169     }
171     guint n = clonetiler_number_of_clones(selection->singleItem());
172     if (n > 0) {
173         gtk_widget_set_sensitive (buttons, TRUE);
174         gchar *sta = g_strdup_printf (_("<small>Object has <b>%d</b> tiled clones.</small>"), n);
175         gtk_label_set_markup (GTK_LABEL(status), sta);
176         g_free (sta);
177     } else {
178         gtk_widget_set_sensitive (buttons, FALSE);
179         gtk_label_set_markup (GTK_LABEL(status), _("<small>Object has no tiled clones.</small>"));
180     }
183 static void
184 clonetiler_external_change (Inkscape::Application * /*inkscape*/, GtkWidget *dlg)
186     clonetiler_change_selection (NULL, SP_DT_SELECTION(SP_ACTIVE_DESKTOP), dlg);
189 static void clonetiler_disconnect_gsignal (GObject *widget, gpointer source) {
190     if (source && G_IS_OBJECT(source))
191         sp_signal_disconnect_by_data (source, widget);
195 enum {
196     TILE_P1,
197     TILE_P2,
198     TILE_PM,
199     TILE_PG,
200     TILE_CM,
201     TILE_PMM,
202     TILE_PMG,
203     TILE_PGG,
204     TILE_CMM,
205     TILE_P4,
206     TILE_P4M,
207     TILE_P4G,
208     TILE_P3,
209     TILE_P31M,
210     TILE_P3M1,
211     TILE_P6,
212     TILE_P6M
213 };
216 static NR::Matrix
217 clonetiler_get_transform ( 
218     // symmetry group
219     int type,
220     // row, column
221     int x, int y,
222     // center, width, height of the tile
223     double cx, double cy,
224     double w, double h,
226     // values from the dialog:
227     double d_x_per_x, double d_y_per_x, double d_x_per_y, double d_y_per_y,
228     int alternate_x, int alternate_y, double rand_x, double rand_y,
229     double d_per_x_exp, double d_per_y_exp,
230     double d_rot_per_x, double d_rot_per_y, int alternate_rotx, int alternate_roty, double rand_rot,
231     double d_scalex_per_x, double d_scaley_per_x, double d_scalex_per_y, double d_scaley_per_y,
232     int alternate_scalex, int alternate_scaley, double rand_scalex, double rand_scaley
233     )
235     // in abs units
236     double eff_x = (alternate_x? (x%2) : pow ((double) x, d_per_x_exp));
237     double eff_y = (alternate_y? (y%2) : pow ((double) y, d_per_y_exp));
238     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);
239     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);
241     NR::Matrix rect_translate (NR::translate (w * pow ((double) x, d_per_x_exp) + dx, h * pow ((double) y, d_per_y_exp) + dy));
243     // in deg
244     double eff_x_rot = (alternate_rotx? (x%2) : (x));
245     double eff_y_rot = (alternate_roty? (y%2) : (y));
246     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);
248     // times the original
249     double eff_x_s = (alternate_scalex? (x%2) : (x));
250     double eff_y_s = (alternate_scaley? (y%2) : (y));
251     double rand_scale_x, rand_scale_y;
252     if (rand_scaley == rand_scalex) {
253         // if rands are equal, scale proportionally
254         rand_scale_x = rand_scale_y = rand_scalex * 1 * g_random_double_range (-1, 1);
255     } else {
256         rand_scale_x = rand_scalex * 1 * g_random_double_range (-1, 1);
257         rand_scale_y = rand_scaley * 1 * g_random_double_range (-1, 1);
258     }
259     double dscalex = 1 + d_scalex_per_x * eff_x_s + d_scalex_per_y * eff_y_s + rand_scale_x;
260     if (dscalex < 0) dscalex = 0;
261     double dscaley = 1 + d_scaley_per_x * eff_x_s + d_scaley_per_y * eff_y_s + rand_scale_y;
262     if (dscaley < 0) dscaley = 0;
264     NR::Matrix drot_c = NR::translate(-cx, -cy) * NR::rotate (M_PI*drot/180) * NR::translate(cx, cy);
266     NR::Matrix dscale_c = NR::translate(-cx, -cy) * NR::scale (dscalex, dscaley) * NR::translate(cx, cy);
268     NR::Matrix d_s_r = dscale_c * drot_c;
270     NR::Matrix rotate_180_c = NR::translate(-cx, -cy) * NR::rotate (M_PI) * NR::translate(cx, cy);
272     NR::Matrix rotate_90_c = NR::translate(-cx, -cy) * NR::rotate (-M_PI/2) * NR::translate(cx, cy);
273     NR::Matrix rotate_m90_c = NR::translate(-cx, -cy) * NR::rotate (M_PI/2) * NR::translate(cx, cy);
275     NR::Matrix rotate_120_c = NR::translate(-cx, -cy) * NR::rotate (-2*M_PI/3) * NR::translate(cx, cy);
276     NR::Matrix rotate_m120_c = NR::translate(-cx, -cy) * NR::rotate (2*M_PI/3) * NR::translate(cx, cy);
278     NR::Matrix rotate_60_c = NR::translate(-cx, -cy) * NR::rotate (-M_PI/3) * NR::translate(cx, cy);
279     NR::Matrix rotate_m60_c = NR::translate(-cx, -cy) * NR::rotate (M_PI/3) * NR::translate(cx, cy);
281     double cos60 = cos(M_PI/3);
282     double sin60 = sin(M_PI/3);
283     double cos30 = cos(M_PI/6);
284     double sin30 = sin(M_PI/6);
286     NR::Matrix flip_x = NR::translate(-cx, -cy) * NR::scale (-1, 1) * NR::translate(cx, cy);
287     NR::Matrix flip_y = NR::translate(-cx, -cy) * NR::scale (1, -1) * NR::translate(cx, cy);
289     x = (int) pow ((double) x, d_per_x_exp);
290     y = (int) pow ((double) y, d_per_y_exp);
292     switch (type) {
294     case TILE_P1:
295         return d_s_r * rect_translate;
296         break;
298     case TILE_P2:
299         if (x % 2 == 0) {
300             return d_s_r * rect_translate;
301         } else {
302             return d_s_r * rotate_180_c * rect_translate;
303         }
304         break;
306     case TILE_PM:
307         if (x % 2 == 0) {
308             return d_s_r * rect_translate;
309         } else {
310             return d_s_r * flip_x * rect_translate;
311         }
312         break;
314     case TILE_PG:
315         if (y % 2 == 0) {
316             return d_s_r * rect_translate;
317         } else {
318             return d_s_r * flip_x * rect_translate;
319         }
320         break;
322     case TILE_CM:
323         if ((x + y) % 2 == 0) {
324             return d_s_r * rect_translate;
325         } else {
326             return d_s_r * flip_x * rect_translate;
327         }
328         break;
330     case TILE_PMM:
331         if (y % 2 == 0) {
332             if (x % 2 == 0) {
333                 return d_s_r * rect_translate;
334             } else {
335                 return d_s_r * flip_x * rect_translate;
336             }
337         } else {
338             if (x % 2 == 0) {
339                 return d_s_r * flip_y * rect_translate;
340             } else {
341                 return d_s_r * flip_x * flip_y * rect_translate;
342             }
343         }
344         break;
346     case TILE_PMG:
347         if (y % 4 == 0) {
348             return d_s_r * rect_translate;
349         } else if (y % 4 == 1) {
350             return d_s_r * flip_y * rect_translate;
351         } else if (y % 4 == 2) {
352             return d_s_r * flip_x * rect_translate;
353         } else if (y % 4 == 3) {
354             return d_s_r * flip_x * flip_y * rect_translate;
355         }
356         break;
358     case TILE_PGG:
359         if (y % 2 == 0) {
360             if (x % 2 == 0) {
361                 return d_s_r * rect_translate;
362             } else {
363                 return d_s_r * flip_y * rect_translate;
364             }
365         } else {
366             if (x % 2 == 0) {
367                 return d_s_r * rotate_180_c * rect_translate;
368             } else {
369                 return d_s_r * rotate_180_c * flip_y * rect_translate;
370             }
371         }
372         break;
374     case TILE_CMM:
375         if (y % 4 == 0) {
376             if (x % 2 == 0) {
377                 return d_s_r * rect_translate;
378             } else {
379                 return d_s_r * flip_x * rect_translate;
380             }
381         } else if (y % 4 == 1) {
382             if (x % 2 == 0) {
383                 return d_s_r * flip_y * rect_translate;
384             } else {
385                 return d_s_r * flip_x * flip_y * rect_translate;
386             }
387         } else if (y % 4 == 2) {
388             if (x % 2 == 1) {
389                 return d_s_r * rect_translate;
390             } else {
391                 return d_s_r * flip_x * rect_translate;
392             }
393         } else {
394             if (x % 2 == 1) {
395                 return d_s_r * flip_y * rect_translate;
396             } else {
397                 return d_s_r * flip_x * flip_y * rect_translate;
398             }
399         }
400         break;
402     case TILE_P4:
403     {
404         NR::Matrix ori (NR::translate ((w + h) * (x/2) + dx,  (h + w) * (y/2) + dy));
405         NR::Matrix dia1 (NR::translate (w/2 + h/2, -h/2 + w/2));
406         NR::Matrix dia2 (NR::translate (-w/2 + h/2, h/2 + w/2));
407         if (y % 2 == 0) {
408             if (x % 2 == 0) {
409                 return d_s_r * ori;
410             } else {
411                 return d_s_r * rotate_m90_c * dia1 * ori;
412             }
413         } else {
414             if (x % 2 == 0) {
415                 return d_s_r * rotate_90_c * dia2 * ori;
416             } else {
417                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
418             }
419         }
420     }
421     break;
423     case TILE_P4M:
424     {
425         double max = MAX(w, h);
426         NR::Matrix ori (NR::translate ((max + max) * (x/4) + dx,  (max + max) * (y/2) + dy));
427         NR::Matrix dia1 (NR::translate (w/2 - h/2, h/2 - w/2));
428         NR::Matrix dia2 (NR::translate (-h/2 + w/2, w/2 - h/2));
429         if (y % 2 == 0) {
430             if (x % 4 == 0) {
431                 return d_s_r * ori;
432             } else if (x % 4 == 1) {
433                 return d_s_r * flip_y * rotate_m90_c * dia1 * ori;
434             } else if (x % 4 == 2) {
435                 return d_s_r * rotate_m90_c * dia1 * NR::translate (h, 0) * ori;
436             } else if (x % 4 == 3) {
437                 return d_s_r * flip_x * NR::translate (w, 0) * ori;
438             }
439         } else {
440             if (x % 4 == 0) {
441                 return d_s_r * flip_y * NR::translate(0, h) * ori;
442             } else if (x % 4 == 1) {
443                 return d_s_r * rotate_90_c * dia2 * NR::translate(0, h) * ori;
444             } else if (x % 4 == 2) {
445                 return d_s_r * flip_y * rotate_90_c * dia2 * NR::translate(h, 0) * NR::translate(0, h) * ori;
446             } else if (x % 4 == 3) {
447                 return d_s_r * flip_y * flip_x * NR::translate(w, 0) * NR::translate(0, h) * ori;
448             }
449         }
450     }
451     break;
453     case TILE_P4G:
454     {
455         double max = MAX(w, h);
456         NR::Matrix ori (NR::translate ((max + max) * (x/4) + dx,  (max + max) * y + dy));
457         NR::Matrix dia1 (NR::translate (w/2 + h/2, h/2 - w/2));
458         NR::Matrix dia2 (NR::translate (-h/2 + w/2, w/2 + h/2));
459         if (((x/4) + y) % 2 == 0) {
460             if (x % 4 == 0) {
461                 return d_s_r * ori;
462             } else if (x % 4 == 1) {
463                 return d_s_r * rotate_m90_c * dia1 * ori;
464             } else if (x % 4 == 2) {
465                 return d_s_r * rotate_90_c * dia2 * ori;
466             } else if (x % 4 == 3) {
467                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
468             }
469         } else {
470             if (x % 4 == 0) {
471                 return d_s_r * flip_y * NR::translate (0, h) * ori;
472             } else if (x % 4 == 1) {
473                 return d_s_r * flip_y * rotate_m90_c * dia1 * NR::translate (-h, 0) * ori;
474             } else if (x % 4 == 2) {
475                 return d_s_r * flip_y * rotate_90_c * dia2 * NR::translate (h, 0) * ori;
476             } else if (x % 4 == 3) {
477                 return d_s_r * flip_x * NR::translate (w, 0) * ori;
478             }
479         }
480     }
481     break;
483     case TILE_P3:
484     {
485         double width;
486         double height;
487         NR::Matrix dia1;
488         NR::Matrix dia2;
489         if (w > h) {
490             width = w + w * cos60;
491             height = 2 * w * sin60;
492             dia1 = NR::Matrix (NR::translate (w/2 + w/2 * cos60, -(w/2 * sin60)));
493             dia2 = dia1 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60)));
494         } else {
495             width = h * cos (M_PI/6);
496             height = h;
497             dia1 = NR::Matrix (NR::translate (h/2 * cos30, -(h/2 * sin30)));
498             dia2 = dia1 * NR::Matrix (NR::translate (0, h/2));
499         }
500         NR::Matrix ori (NR::translate (width * (2*(x/3) + y%2) + dx,  (height/2) * y + dy));
501         if (x % 3 == 0) {
502             return d_s_r * ori;
503         } else if (x % 3 == 1) {
504             return d_s_r * rotate_m120_c * dia1 * ori;
505         } else if (x % 3 == 2) {
506             return d_s_r * rotate_120_c * dia2 * ori;
507         }
508     }
509     break;
511     case TILE_P31M:
512     {
513         NR::Matrix ori;
514         NR::Matrix dia1;
515         NR::Matrix dia2;
516         NR::Matrix dia3;
517         NR::Matrix dia4;
518         if (w > h) {
519             ori = NR::Matrix(NR::translate (w * (x/6) + w/2 * (y%2) + dx,  (w * cos30) * y + dy));
520             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) );
521             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
522             dia3 = dia2 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
523             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
524         } else {
525             ori  = NR::Matrix (NR::translate (2*h * cos30  * (x/6 + 0.5*(y%2)) + dx,  (2*h - h * sin30) * y + dy));
526             dia1 = NR::Matrix (NR::translate (0, -h/2) * NR::translate (h/2 * cos30, h/2 * sin30));
527             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
528             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
529             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
530         }
531         if (x % 6 == 0) {
532             return d_s_r * ori;
533         } else if (x % 6 == 1) {
534             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
535         } else if (x % 6 == 2) {
536             return d_s_r * rotate_m120_c * dia2 * ori;
537         } else if (x % 6 == 3) {
538             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
539         } else if (x % 6 == 4) {
540             return d_s_r * rotate_120_c * dia4 * ori;
541         } else if (x % 6 == 5) {
542             return d_s_r * flip_y * NR::translate(0, h) * ori;
543         }
544     }
545     break;
547     case TILE_P3M1:
548     {
549         double width;
550         double height;
551         NR::Matrix dia1;
552         NR::Matrix dia2;
553         NR::Matrix dia3;
554         NR::Matrix dia4;
555         if (w > h) {
556             width = w + w * cos60;
557             height = 2 * w * sin60;
558             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) );
559             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
560             dia3 = dia2 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
561             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
562         } else {
563             width = 2 * h * cos (M_PI/6);
564             height = 2 * h;
565             dia1 = NR::Matrix (NR::translate (0, -h/2) * NR::translate (h/2 * cos30, h/2 * sin30));
566             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
567             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
568             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
569         }
570         NR::Matrix ori (NR::translate (width * (2*(x/6) + y%2) + dx,  (height/2) * y + dy));
571         if (x % 6 == 0) {
572             return d_s_r * ori;
573         } else if (x % 6 == 1) {
574             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
575         } else if (x % 6 == 2) {
576             return d_s_r * rotate_m120_c * dia2 * ori;
577         } else if (x % 6 == 3) {
578             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
579         } else if (x % 6 == 4) {
580             return d_s_r * rotate_120_c * dia4 * ori;
581         } else if (x % 6 == 5) {
582             return d_s_r * flip_y * NR::translate(0, h) * ori;
583         }
584     }
585     break;
587     case TILE_P6:
588     {
589         NR::Matrix ori;
590         NR::Matrix dia1;
591         NR::Matrix dia2;
592         NR::Matrix dia3;
593         NR::Matrix dia4;
594         NR::Matrix dia5;
595         if (w > h) {
596             ori = NR::Matrix(NR::translate (2*w * (x/6) + w * (y%2) + dx,  (2*w * sin60) * y + dy));
597             dia1 = NR::Matrix (NR::translate (w/2 * cos60, -w/2 * sin60));
598             dia2 = dia1 * NR::Matrix (NR::translate (w/2, 0));
599             dia3 = dia2 * NR::Matrix (NR::translate (w/2 * cos60, w/2 * sin60));
600             dia4 = dia3 * NR::Matrix (NR::translate (-w/2 * cos60, w/2 * sin60));
601             dia5 = dia4 * NR::Matrix (NR::translate (-w/2, 0));
602         } else {
603             ori = NR::Matrix(NR::translate (2*h * cos30 * (x/6 + 0.5*(y%2)) + dx,  (h + h * sin30) * y + dy));
604             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));
605             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));
606             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));
607             dia4 = dia3 * dia1.inverse();
608             dia5 = dia3 * dia2.inverse();
609         }
610         if (x % 6 == 0) {
611             return d_s_r * ori;
612         } else if (x % 6 == 1) {
613             return d_s_r * rotate_m60_c * dia1 * ori;
614         } else if (x % 6 == 2) {
615             return d_s_r * rotate_m120_c * dia2 * ori;
616         } else if (x % 6 == 3) {
617             return d_s_r * rotate_180_c * dia3 * ori;
618         } else if (x % 6 == 4) {
619             return d_s_r * rotate_120_c * dia4 * ori;
620         } else if (x % 6 == 5) {
621             return d_s_r * rotate_60_c * dia5 * ori;
622         }
623     }
624     break;
626     case TILE_P6M:
627     {
629         NR::Matrix ori;
630         NR::Matrix dia1, dia2, dia3, dia4, dia5, dia6, dia7, dia8, dia9, dia10;
631         if (w > h) {
632             ori = NR::Matrix(NR::translate (2*w * (x/12) + w * (y%2) + dx,  (2*w * sin60) * y + dy));
633             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));
634             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, -h * sin30));
635             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));
636             dia4 = dia3 * NR::Matrix (NR::translate (h * cos30, h * sin30));
637             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));
638             dia6 = dia5 * NR::Matrix (NR::translate (0, h));
639             dia7 = dia6 * dia1.inverse();
640             dia8 = dia6 * dia2.inverse();
641             dia9 = dia6 * dia3.inverse();
642             dia10 = dia6 * dia4.inverse();
643         } else {
644             ori = NR::Matrix(NR::translate (4*h * cos30 * (x/12 + 0.5*(y%2)) + dx,  (2*h  + 2*h * sin30) * y + dy));
645             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));
646             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, -h * sin30));
647             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));
648             dia4 = dia3 * NR::Matrix (NR::translate (h * cos30, h * sin30));
649             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));
650             dia6 = dia5 * NR::Matrix (NR::translate (0, h));
651             dia7 = dia6 * dia1.inverse();
652             dia8 = dia6 * dia2.inverse();
653             dia9 = dia6 * dia3.inverse();
654             dia10 = dia6 * dia4.inverse();
655         }
656         if (x % 12 == 0) {
657             return d_s_r * ori;
658         } else if (x % 12 == 1) {
659             return d_s_r * flip_y * rotate_m60_c * dia1 * ori;
660         } else if (x % 12 == 2) {
661             return d_s_r * rotate_m60_c * dia2 * ori;
662         } else if (x % 12 == 3) {
663             return d_s_r * flip_y * rotate_m120_c * dia3 * ori;
664         } else if (x % 12 == 4) {
665             return d_s_r * rotate_m120_c * dia4 * ori;
666         } else if (x % 12 == 5) {
667             return d_s_r * flip_x * dia5 * ori;
668         } else if (x % 12 == 6) {
669             return d_s_r * flip_x * flip_y * dia6 * ori;
670         } else if (x % 12 == 7) {
671             return d_s_r * flip_y * rotate_120_c * dia7 * ori;
672         } else if (x % 12 == 8) {
673             return d_s_r * rotate_120_c * dia8 * ori;
674         } else if (x % 12 == 9) {
675             return d_s_r * flip_y * rotate_60_c * dia9 * ori;
676         } else if (x % 12 == 10) {
677             return d_s_r * rotate_60_c * dia10 * ori;
678         } else if (x % 12 == 11) {
679             return d_s_r * flip_y * NR::translate (0, h) * ori;
680         }
681     }
682     break;
684     default:
685         break;
686     }
688     return NR::identity();
691 static bool
692 clonetiler_is_a_clone_of (SPObject *tile, SPObject *obj)
694     char *id_href = NULL;
696     if (obj) {
697         Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
698         id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
699     }
701     if (SP_IS_USE(tile) &&
702         SP_OBJECT_REPR(tile)->attribute("xlink:href") &&
703         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("xlink:href"))) &&
704         SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of") &&
705         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of"))))
706     {
707         if (id_href)
708             g_free (id_href);
709         return true;
710     } else {
711         if (id_href)
712             g_free (id_href);
713         return false;
714     }
717 static NRArena const *trace_arena = NULL;
718 static unsigned trace_visionkey;
719 static NRArenaItem *trace_root;
720 static gdouble trace_zoom;
722 static void
723 clonetiler_trace_hide_tiled_clones_recursively (SPObject *from)
725     if (!trace_arena)
726         return;
728     for (SPObject *o = sp_object_first_child(from); o != NULL; o = SP_OBJECT_NEXT(o)) {
729         if (SP_IS_ITEM(o) && clonetiler_is_a_clone_of (o, NULL))
730             sp_item_invoke_hide(SP_ITEM(o), trace_visionkey); // FIXME: hide each tiled clone's original too!
731         clonetiler_trace_hide_tiled_clones_recursively (o);
732     }
735 static void
736 clonetiler_trace_setup (SPDocument *doc, gdouble zoom, SPItem *original)
738     trace_arena = NRArena::create();
739     /* Create ArenaItem and set transform */
740     trace_visionkey = sp_item_display_key_new(1);
741     trace_root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT (doc)), 
742                                       (NRArena *) trace_arena, trace_visionkey, SP_ITEM_SHOW_DISPLAY);
744     // hide the (current) original and any tiled clones, we only want to pick the background
745     sp_item_invoke_hide(original, trace_visionkey); 
746     clonetiler_trace_hide_tiled_clones_recursively (SP_OBJECT(SP_DOCUMENT_ROOT (doc)));
748     sp_document_root (doc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
749     sp_document_ensure_up_to_date(doc);
751     trace_zoom = zoom;
754 static guint32
755 clonetiler_trace_pick (NR::Rect box)
757     if (!trace_arena)
758         return 0;
760     NRMatrix t;
761     nr_matrix_set_scale(&t, trace_zoom, trace_zoom);
762     nr_arena_item_set_transform(trace_root, &t);
763     NRGC gc(NULL);
764     nr_matrix_set_identity(&gc.transform);
765     nr_arena_item_invoke_update( trace_root, NULL, &gc,
766                                  NR_ARENA_ITEM_STATE_ALL,
767                                  NR_ARENA_ITEM_STATE_NONE );
769     /* Item integer bbox in points */
770     NRRectL ibox;
771     ibox.x0 = (int) floor(trace_zoom * box.min()[NR::X] + 0.5);
772     ibox.y0 = (int) floor(trace_zoom * box.min()[NR::Y] + 0.5);
773     ibox.x1 = (int) floor(trace_zoom * box.max()[NR::X] + 0.5);
774     ibox.y1 = (int) floor(trace_zoom * box.max()[NR::Y] + 0.5);
776     /* Find visible area */
777     int width = ibox.x1 - ibox.x0;
778     int height = ibox.y1 - ibox.y0;
780     /* Set up pixblock */
781     guchar *px = nr_new(guchar, 4 * width * height);
782     memset(px, 0x00, 4 * width * height);
784     /* Render */
785     NRPixBlock pb;
786     nr_pixblock_setup_extern( &pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
787                               ibox.x0, ibox.y0, ibox.x1, ibox.y1,
788                               px, 4 * width, FALSE, FALSE );
789     nr_arena_item_invoke_render( trace_root, &ibox, &pb,
790                                  NR_ARENA_ITEM_RENDER_NO_CACHE );
792     double R = 0, G = 0, B = 0, A = 0;
793     double count = 0;
794     double weight = 0;
796     for (int y = ibox.y0; y < ibox.y1; y++) {
797         const unsigned char *s = NR_PIXBLOCK_PX (&pb) + (y - ibox.y0) * pb.rs;
798         for (int x = ibox.x0; x < ibox.x1; x++) {
799             count += 1;
800             weight += s[3] / 255.0;
801             R += s[0] / 255.0;
802             G += s[1] / 255.0;
803             B += s[2] / 255.0;
804             A += s[3] / 255.0;
805             s += 4;
806         }
807     }
809     nr_pixblock_release(&pb);
811     R = R / weight;
812     G = G / weight;
813     B = B / weight;
814     A = A / count;
816     R = CLAMP (R, 0.0, 1.0);
817     G = CLAMP (G, 0.0, 1.0);
818     B = CLAMP (B, 0.0, 1.0);
819     A = CLAMP (A, 0.0, 1.0);
821     return SP_RGBA32_F_COMPOSE (R, G, B, A);
824 static void
825 clonetiler_trace_finish ()
827     if (trace_arena) {
828         ((NRObject *) trace_arena)->unreference();
829         trace_arena = NULL;
830     }
833 static void
834 clonetiler_unclump (GtkWidget *widget, void *)
836     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
837     if (desktop == NULL)
838         return;
840     Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
842     // check if something is selected
843     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
844         SP_DT_MSGSTACK(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump."));
845         return;
846     }
848     SPObject *obj = SP_OBJECT(selection->singleItem());
849     SPObject *parent = SP_OBJECT_PARENT (obj);
851     GSList *to_unclump = NULL; // not including the original
853     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
854         if (clonetiler_is_a_clone_of (child, obj)) {
855             to_unclump = g_slist_prepend (to_unclump, child);
856         }
857     }
859     sp_document_ensure_up_to_date(SP_DT_DOCUMENT(desktop));
861     unclump (to_unclump);
863     g_slist_free (to_unclump);
865     sp_document_done (SP_DT_DOCUMENT (desktop));
868 static guint
869 clonetiler_number_of_clones (SPObject *obj)
871     SPObject *parent = SP_OBJECT_PARENT (obj);
873     guint n = 0;
875     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
876         if (clonetiler_is_a_clone_of (child, obj)) {
877             n ++;
878         }
879     }
881     return n;
884 static void
885 clonetiler_remove (GtkWidget *widget, void *, bool do_undo = true)
887     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
888     if (desktop == NULL)
889         return;
891     Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
893     // check if something is selected
894     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
895         SP_DT_MSGSTACK(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove."));
896         return;
897     }
899     SPObject *obj = SP_OBJECT(selection->singleItem());
900     SPObject *parent = SP_OBJECT_PARENT (obj);
902 // remove old tiling
903     GSList *to_delete = NULL;
904     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
905         if (clonetiler_is_a_clone_of (child, obj)) {
906             to_delete = g_slist_prepend (to_delete, child);
907         }
908     }
909     for (GSList *i = to_delete; i; i = i->next) {
910         SP_OBJECT(i->data)->deleteObject();
911     }
912     g_slist_free (to_delete);
914     clonetiler_change_selection (NULL, selection, dlg);
916     if (do_undo)
917         sp_document_done (SP_DT_DOCUMENT (desktop));
920 static NR::Rect
921 transform_rect(NR::Rect const &r, NR::Matrix const &m)
923     using NR::X;
924     using NR::Y;
925     NR::Point const p1 = r.corner(1) * m;
926     NR::Point const p2 = r.corner(2) * m;
927     NR::Point const p3 = r.corner(3) * m;
928     NR::Point const p4 = r.corner(4) * m;
929     return NR::Rect(
930         NR::Point(
931             std::min(std::min(p1[X], p2[X]), std::min(p3[X], p4[X])), 
932             std::min(std::min(p1[Y], p2[Y]), std::min(p3[Y], p4[Y]))), 
933         NR::Point(
934             std::max(std::max(p1[X], p2[X]), std::max(p3[X], p4[X])), 
935             std::max(std::max(p1[Y], p2[Y]), std::max(p3[Y], p4[Y]))));
938 /**
939 Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same
940 probability of being displaced.
941  */
942 static double
943 randomize01 (double val, double rand)
945     double base = MIN (val - rand, 1 - 2*rand);
946     if (base < 0) base = 0;
947     val = base + g_random_double_range (0, MIN (2 * rand, 1 - base));
948     return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case...
952 static void
953 clonetiler_apply (GtkWidget *widget, void *)
955     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
956     if (desktop == NULL)
957         return;
959     Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
961     // check if something is selected
962     if (selection->isEmpty()) {
963         SP_DT_MSGSTACK(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone."));
964         return;
965     }
967     // Check if more than one object is selected.
968     if (g_slist_length((GSList *) selection->itemList()) > 1) {
969         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>."));
970         return;
971     }
973     SPObject *obj = SP_OBJECT(selection->singleItem());
974     Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
975     const char *id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
976     SPObject *parent = SP_OBJECT_PARENT (obj);
978     clonetiler_remove (NULL, NULL, false);
980     double d_x_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_x_per_x", 0, -100, 1000);
981     double d_y_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_y_per_x", 0, -100, 1000);
982     double d_per_x_exp = prefs_get_double_attribute_limited (prefs_path, "d_per_x_exp", 1, 0, 10);
983     double d_x_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_x_per_y", 0, -100, 1000);
984     double d_y_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_y_per_y", 0, -100, 1000);
985     double d_per_y_exp = prefs_get_double_attribute_limited (prefs_path, "d_per_y_exp", 1, 0, 10);
986     int alternate_x = prefs_get_int_attribute (prefs_path, "alternate_x", 0);
987     int alternate_y = prefs_get_int_attribute (prefs_path, "alternate_y", 0);
988     double rand_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_x", 0, 0, 1000);
989     double rand_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_y", 0, 0, 1000);
991     double d_scalex_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scalex_per_x", 0, -100, 1000);
992     double d_scaley_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scaley_per_x", 0, -100, 1000);
993     double d_scalex_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scalex_per_y", 0, -100, 1000);
994     double d_scaley_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scaley_per_y", 0, -100, 1000);
995     int alternate_scalex = prefs_get_int_attribute (prefs_path, "alternate_scalex", 0);
996     int alternate_scaley = prefs_get_int_attribute (prefs_path, "alternate_scaley", 0);
997     double rand_scalex = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_scalex", 0, 0, 1000);
998     double rand_scaley = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_scaley", 0, 0, 1000);
1000     double d_rot_per_x = prefs_get_double_attribute_limited (prefs_path, "d_rot_per_x", 0, -180, 180);
1001     double d_rot_per_y = prefs_get_double_attribute_limited (prefs_path, "d_rot_per_y", 0, -180, 180);
1002     int alternate_rotx = prefs_get_int_attribute (prefs_path, "alternate_rotx", 0);
1003     int alternate_roty = prefs_get_int_attribute (prefs_path, "alternate_roty", 0);
1004     double rand_rot = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_rot", 0, 0, 100);
1006     double d_opacity_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_opacity_per_y", 0, 0, 100);
1007     double d_opacity_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_opacity_per_x", 0, 0, 100);
1008     int alternate_opacityy = prefs_get_int_attribute (prefs_path, "alternate_opacityy", 0);
1009     int alternate_opacityx = prefs_get_int_attribute (prefs_path, "alternate_opacityx", 0);
1010     double rand_opacity = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_opacity", 0, 0, 100);
1012     const gchar *initial_color = prefs_get_string_attribute (prefs_path, "initial_color");
1013     double d_hue_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_hue_per_y", 0, -100, 100);
1014     double d_hue_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_hue_per_x", 0, -100, 100);
1015     double rand_hue = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_hue", 0, 0, 100);
1016     double d_saturation_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_saturation_per_y", 0, -100, 100);
1017     double d_saturation_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_saturation_per_x", 0, -100, 100);
1018     double rand_saturation = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_saturation", 0, 0, 100);
1019     double d_lightness_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_lightness_per_y", 0, -100, 100);
1020     double d_lightness_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_lightness_per_x", 0, -100, 100);
1021     double rand_lightness = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_lightness", 0, 0, 100);
1022     int alternate_color_y = prefs_get_int_attribute (prefs_path, "alternate_color_y", 0);
1023     int alternate_color_x = prefs_get_int_attribute (prefs_path, "alternate_color_x", 0);
1025     int type = prefs_get_int_attribute (prefs_path, "symmetrygroup", 0);
1027     int keepbbox = prefs_get_int_attribute (prefs_path, "keepbbox", 1);
1029     int xmax = prefs_get_int_attribute (prefs_path, "xmax", 2);
1030     int ymax = prefs_get_int_attribute (prefs_path, "ymax", 2);
1032     int fillrect = prefs_get_int_attribute (prefs_path, "fillrect", 0);
1033     double fillwidth = prefs_get_double_attribute_limited (prefs_path, "fillwidth", 50, 0, 6000);
1034     double fillheight = prefs_get_double_attribute_limited (prefs_path, "fillheight", 50, 0, 6000);
1036     int dotrace = prefs_get_int_attribute (prefs_path, "dotrace", 0);
1037     int pick = prefs_get_int_attribute (prefs_path, "pick", 0);
1038     int pick_to_presence = prefs_get_int_attribute (prefs_path, "pick_to_presence", 0);
1039     int pick_to_size = prefs_get_int_attribute (prefs_path, "pick_to_size", 0);
1040     int pick_to_color = prefs_get_int_attribute (prefs_path, "pick_to_color", 0);
1041     int pick_to_opacity = prefs_get_int_attribute (prefs_path, "pick_to_opacity", 0);
1042     double rand_picked = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_picked", 0, 0, 100);
1043     int invert_picked = prefs_get_int_attribute (prefs_path, "invert_picked", 0);
1044     double gamma_picked = prefs_get_double_attribute_limited (prefs_path, "gamma_picked", 0, -10, 10);
1046     if (dotrace) {
1047         clonetiler_trace_setup (SP_DT_DOCUMENT(desktop), 1.0, SP_ITEM (obj));
1048     }
1050     NR::Point c;
1051     double w;
1052     double h;
1054     if (keepbbox &&
1055         obj_repr->attribute("inkscape:tile-w") &&
1056         obj_repr->attribute("inkscape:tile-h") &&
1057         obj_repr->attribute("inkscape:tile-cx") &&
1058         obj_repr->attribute("inkscape:tile-cy")) {
1060         double cx = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cx", 0);
1061         double cy = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cy", 0);
1063         c = NR::Point (cx, cy);
1065         w = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-w", 0);
1066         h = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-h", 0);
1067     } else {
1068         NR::Rect const r = SP_ITEM(obj)->invokeBbox(sp_item_i2doc_affine(SP_ITEM(obj)));
1069         c = r.midpoint();
1070         w = r.dimensions()[NR::X];
1071         h = r.dimensions()[NR::Y];
1073         sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
1074         sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
1075         sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", c[NR::X]);
1076         sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", c[NR::Y]);
1077     }
1079     NR::Point cur = NR::Point (0, 0);
1080     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));
1082     for (int x = 0;
1083          fillrect?
1084              (fabs(cur[NR::X]) < fillwidth && x < 200) // prevent "freezing" with too large fillrect, arbitrarily limit rows
1085              : (x < xmax);
1086          x ++) {
1087         for (int y = 0;
1088              fillrect?
1089                  (fabs(cur[NR::Y]) < fillheight && y < 200) // prevent "freezing" with too large fillrect, arbitrarily limit cols
1090                  : (y < ymax);
1091              y ++) {
1093             // Note: We create a clone at 0,0 too, right over the original, in case our clones are colored
1095             // Get transform from symmetry, shift, scale, rotation
1096             NR::Matrix t = clonetiler_get_transform (type, x, y, c[NR::X], c[NR::Y], w, h,
1097                                                      d_x_per_x, d_y_per_x, d_x_per_y, d_y_per_y, alternate_x, alternate_y, rand_x, rand_y,
1098                                                      d_per_x_exp, d_per_y_exp,
1099                                                      d_rot_per_x, d_rot_per_y, alternate_rotx, alternate_roty, rand_rot,
1100                                                      d_scalex_per_x, d_scaley_per_x, d_scalex_per_y, d_scaley_per_y,
1101                                                      alternate_scalex, alternate_scaley, rand_scalex, rand_scaley);
1103             cur = c * t - c;
1104             if (fillrect) {
1105                 if ((cur[NR::X] > fillwidth) || (cur[NR::Y] > fillheight)) { // off limits
1106                     continue;
1107                 }
1108             }
1110             gchar color_string[32]; *color_string = 0;
1112             // Color tab
1113             if (initial_color) {
1114                 guint32 rgba = sp_svg_read_color (initial_color, 0x000000ff);
1115                 float hsl[3];
1116                 sp_color_rgb_to_hsl_floatv (hsl, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba));
1118                 double eff_x = (alternate_color_x? (x%2) : (x));
1119                 double eff_y = (alternate_color_y? (y%2) : (y));
1121                 hsl[0] += d_hue_per_x * eff_x + d_hue_per_y * eff_y + rand_hue * g_random_double_range (-1, 1);
1122                 if (hsl[0] < 0) hsl[0] += 1;
1123                 if (hsl[0] > 1) hsl[0] -= 1;
1124                 hsl[1] += d_saturation_per_x * eff_x + d_saturation_per_y * eff_y + rand_saturation * g_random_double_range (-1, 1);
1125                 hsl[1] = CLAMP (hsl[1], 0, 1);
1126                 hsl[2] += d_lightness_per_x * eff_x + d_lightness_per_y * eff_y + rand_lightness * g_random_double_range (-1, 1);
1127                 hsl[2] = CLAMP (hsl[2], 0, 1);
1129                 float rgb[3];
1130                 sp_color_hsl_to_rgb_floatv (rgb, hsl[0], hsl[1], hsl[2]);
1131                 sp_svg_write_color(color_string, 32, SP_RGBA32_F_COMPOSE(rgb[0], rgb[1], rgb[2], 1.0));
1132             }
1134             // Opacity tab
1135             double opacity = 1.0;
1136             int eff_x = (alternate_opacityx? (x%2) : (x));
1137             int eff_y = (alternate_opacityy? (y%2) : (y));
1138             opacity = 1 - (d_opacity_per_x * eff_x + d_opacity_per_y * eff_y + rand_opacity * g_random_double_range (-1, 1));
1139             opacity = CLAMP (opacity, 0, 1);
1141             // Trace tab
1142             if (dotrace) {
1143                 NR::Rect bbox_t = transform_rect (bbox_original, t);
1145                 guint32 rgba = clonetiler_trace_pick (bbox_t);
1146                 float r = SP_RGBA32_R_F(rgba);
1147                 float g = SP_RGBA32_G_F(rgba);
1148                 float b = SP_RGBA32_B_F(rgba);
1149                 float a = SP_RGBA32_A_F(rgba);
1151                 float hsl[3];
1152                 sp_color_rgb_to_hsl_floatv (hsl, r, g, b);
1154                 gdouble val = 0;
1155                 switch (pick) {
1156                 case PICK_COLOR:
1157                     val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max
1158                     break;
1159                 case PICK_OPACITY:
1160                     val = a;
1161                     break;
1162                 case PICK_R:
1163                     val = r;
1164                     break;
1165                 case PICK_G:
1166                     val = g;
1167                     break;
1168                 case PICK_B:
1169                     val = b;
1170                     break;
1171                 case PICK_H:
1172                     val = hsl[0];
1173                     break;
1174                 case PICK_S:
1175                     val = hsl[1];
1176                     break;
1177                 case PICK_L:
1178                     val = 1 - hsl[2];
1179                     break;
1180                 default:
1181                     break;
1182                 }
1184                 if (rand_picked > 0) {
1185                     val = randomize01 (val, rand_picked);
1186                     r = randomize01 (r, rand_picked);
1187                     g = randomize01 (g, rand_picked);
1188                     b = randomize01 (b, rand_picked);
1189                 }
1191                 if (gamma_picked != 0) {
1192                     double power;
1193                     if (gamma_picked < 0)
1194                         power = 1/(1 + fabs(gamma_picked));
1195                     else
1196                         power = 1 + gamma_picked;
1198                     val = pow (val, power);
1199                     r = pow (r, power);
1200                     g = pow (g, power);
1201                     b = pow (b, power);
1202                 }
1204                 if (invert_picked) {
1205                     val = 1 - val;
1206                     r = 1 - r;
1207                     g = 1 - g;
1208                     b = 1 - b;
1209                 }
1211                 val = CLAMP (val, 0, 1);
1212                 r = CLAMP (r, 0, 1);
1213                 g = CLAMP (g, 0, 1);
1214                 b = CLAMP (b, 0, 1);
1216                 // recompose tweaked color
1217                 rgba = SP_RGBA32_F_COMPOSE(r, g, b, a);
1219                 if (pick_to_presence) {
1220                     if (g_random_double_range (0, 1) > val) {
1221                         continue; // skip!
1222                     }
1223                 }
1224                 if (pick_to_size) {
1225                     t = NR::translate(-c[NR::X], -c[NR::Y]) * NR::scale (val, val) * NR::translate(c[NR::X], c[NR::Y]) * t;
1226                 }
1227                 if (pick_to_opacity) {
1228                     opacity *= val;
1229                 }
1230                 if (pick_to_color) {
1231                     sp_svg_write_color(color_string, 32, rgba);
1232                 }
1233             }
1235             if (opacity < 1e-6) { // invisibly transparent, skip
1236                     continue;
1237             }
1239             if (fabs(t[0]) + fabs (t[1]) + fabs(t[2]) + fabs(t[3]) < 1e-6) { // too small, skip
1240                     continue;
1241             }
1243             // Create the clone
1244             Inkscape::XML::Node *clone = sp_repr_new("svg:use");
1245             clone->setAttribute("x", "0");
1246             clone->setAttribute("y", "0");
1247             clone->setAttribute("inkscape:tiled-clone-of", id_href);
1248             clone->setAttribute("xlink:href", id_href);
1250             NR::Point new_center;
1251             bool center_set = false;
1252             if (obj_repr->attribute("inkscape:transform-center-x") || obj_repr->attribute("inkscape:transform-center-y")) {
1253                 new_center = desktop->dt2doc(SP_ITEM(obj)->getCenter()) * t;
1254                 center_set = true;
1255             }
1257             gchar affinestr[80];
1258             if (sp_svg_transform_write(affinestr, 79, t)) {
1259                 clone->setAttribute("transform", affinestr);
1260             } else {
1261                 clone->setAttribute("transform", NULL);
1262             }
1264             if (opacity < 1.0) {
1265                 sp_repr_set_css_double(clone, "opacity", opacity);
1266             }
1268             if (*color_string) {
1269                 clone->setAttribute("fill", color_string);
1270                 clone->setAttribute("stroke", color_string);
1271             }
1273             // add the new clone to the top of the original's parent
1274             SP_OBJECT_REPR(parent)->appendChild(clone);
1276             if (center_set) {
1277                 SPObject *clone_object = SP_DT_DOCUMENT(desktop)->getObjectByRepr(clone);
1278                 if (clone_object && SP_IS_ITEM(clone_object)) {
1279                     clone_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1280                     SP_ITEM(clone_object)->setCenter(desktop->doc2dt(new_center));
1281                     clone_object->updateRepr();
1282                 }
1283             }
1285             Inkscape::GC::release(clone);
1286         }
1287         cur[NR::Y] = 0;
1288     }
1290     if (dotrace) {
1291         clonetiler_trace_finish ();
1292     }
1294     clonetiler_change_selection (NULL, selection, dlg);
1296     sp_document_done(SP_DT_DOCUMENT(desktop));
1299 static GtkWidget *
1300 clonetiler_new_tab (GtkWidget *nb, const gchar *label)
1302     GtkWidget *l = gtk_label_new_with_mnemonic (label);
1303     GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN);
1304     gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN);
1305     gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l);
1306     return vb;
1309 static void
1310 clonetiler_checkbox_toggled (GtkToggleButton *tb, gpointer *data)
1312     const gchar *attr = (const gchar *) data;
1313     prefs_set_int_attribute (prefs_path, attr, gtk_toggle_button_get_active (tb));
1316 static GtkWidget *
1317 clonetiler_checkbox (GtkTooltips *tt, const char *tip, const char *attr)
1319     GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
1321     GtkWidget *b = gtk_check_button_new ();
1322     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, tip, NULL);
1324     int value = prefs_get_int_attribute (prefs_path, attr, 0);
1325     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(b), value);
1327     gtk_box_pack_end (GTK_BOX (hb), b, FALSE, TRUE, 0);
1328     gtk_signal_connect ( GTK_OBJECT (b), "clicked",
1329                          GTK_SIGNAL_FUNC (clonetiler_checkbox_toggled), (gpointer) attr);
1331     g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
1333     return hb;
1337 static void
1338 clonetiler_value_changed (GtkAdjustment *adj, gpointer data)
1340     const gchar *pref = (const gchar *) data;
1341     prefs_set_double_attribute (prefs_path, pref, adj->value);
1344 static GtkWidget *
1345 clonetiler_spinbox (GtkTooltips *tt, const char *tip, const char *attr, double lower, double upper, const gchar *suffix, bool exponent = false)
1347     GtkWidget *hb = gtk_hbox_new(FALSE, 0);
1349     {
1350         GtkObject *a;
1351         if (exponent)
1352             a = gtk_adjustment_new(1.0, lower, upper, 0.01, 0.05, 0.1);
1353         else
1354             a = gtk_adjustment_new(0.0, lower, upper, 0.1, 0.5, 2);
1356         GtkWidget *sb;
1357         if (exponent)
1358             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.01, 2);
1359         else
1360             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.1, 1);
1362         gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, tip, NULL);
1363         gtk_entry_set_width_chars (GTK_ENTRY (sb), 4);
1364         gtk_box_pack_start (GTK_BOX (hb), sb, FALSE, FALSE, SB_MARGIN);
1366         double value = prefs_get_double_attribute_limited (prefs_path, attr, exponent? 1 : 0, lower, upper);
1367         gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
1368         gtk_signal_connect(GTK_OBJECT(a), "value_changed",
1369                            GTK_SIGNAL_FUNC(clonetiler_value_changed), (gpointer) attr);
1371         if (exponent)
1372             g_object_set_data (G_OBJECT(sb), "oneable", GINT_TO_POINTER(TRUE));
1373         else
1374             g_object_set_data (G_OBJECT(sb), "zeroable", GINT_TO_POINTER(TRUE));
1375     }
1377     {
1378         GtkWidget *l = gtk_label_new ("");
1379         gtk_label_set_markup (GTK_LABEL(l), suffix);
1380         gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0);
1381         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
1382     }
1384     return hb;
1387 static void
1388 clonetiler_symgroup_changed (GtkMenuItem *item, gpointer data)
1390     gint group_new = GPOINTER_TO_INT (data);
1391     prefs_set_int_attribute ( prefs_path, "symmetrygroup", group_new );
1394 static void
1395 clonetiler_xy_changed (GtkAdjustment *adj, gpointer data)
1397     const gchar *pref = (const gchar *) data;
1398     prefs_set_int_attribute (prefs_path, pref, (int) floor(adj->value + 0.5));
1401 static void
1402 clonetiler_keep_bbox_toggled (GtkToggleButton *tb, gpointer data)
1404     prefs_set_int_attribute (prefs_path, "keepbbox", gtk_toggle_button_get_active (tb));
1407 static void
1408 clonetiler_pick_to (GtkToggleButton *tb, gpointer data)
1410     const gchar *pref = (const gchar *) data;
1411     prefs_set_int_attribute (prefs_path, pref, gtk_toggle_button_get_active (tb));
1415 static void
1416 clonetiler_reset_recursive (GtkWidget *w)
1418     if (w && GTK_IS_OBJECT(w)) {
1419         {
1420             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "zeroable"));
1421             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1422                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1423                 gtk_adjustment_set_value (a, 0);
1424             }
1425         }
1426         {
1427             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "oneable"));
1428             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1429                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1430                 gtk_adjustment_set_value (a, 1);
1431             }
1432         }
1433         {
1434             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "uncheckable"));
1435             if (r && GTK_IS_TOGGLE_BUTTON(w)) { // checkbox
1436                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(w), FALSE);
1437             }
1438         }
1439     }
1441     if (GTK_IS_CONTAINER(w)) {
1442         GList *ch = gtk_container_get_children (GTK_CONTAINER(w));
1443         for (GList *i = ch; i != NULL; i = i->next) {
1444             clonetiler_reset_recursive (GTK_WIDGET(i->data));
1445         }
1446         g_list_free (ch);
1447     }
1450 static void
1451 clonetiler_reset (GtkWidget *widget, void *)
1453     clonetiler_reset_recursive (dlg);
1456 static void
1457 clonetiler_table_attach (GtkWidget *table, GtkWidget *widget, float align, int row, int col)
1459     GtkWidget *a = gtk_alignment_new (align, 0, 0, 0);
1460     gtk_container_add(GTK_CONTAINER(a), widget);
1461     gtk_table_attach ( GTK_TABLE (table), a, col, col + 1, row, row + 1, (GtkAttachOptions)4, (GtkAttachOptions)0, 0, 0 );
1464 static GtkWidget *
1465 clonetiler_table_x_y_rand (int values)
1467     GtkWidget *table = gtk_table_new (values + 2, 5, FALSE);
1468     gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
1469     gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1470     gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1472     {
1473         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1475         GtkWidget *i = sp_icon_new (GTK_ICON_SIZE_MENU, "clonetiler_per_row");
1476         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1478         GtkWidget *l = gtk_label_new ("");
1479         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per row:</small>"));
1480         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1482         clonetiler_table_attach (table, hb, 0, 1, 2);
1483     }
1485     {
1486         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1488         GtkWidget *i = sp_icon_new (GTK_ICON_SIZE_MENU, "clonetiler_per_column");
1489         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1491         GtkWidget *l = gtk_label_new ("");
1492         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per column:</small>"));
1493         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1495         clonetiler_table_attach (table, hb, 0, 1, 3);
1496     }
1498     {
1499         GtkWidget *l = gtk_label_new ("");
1500         gtk_label_set_markup (GTK_LABEL(l), _("<small>Randomize:</small>"));
1501         clonetiler_table_attach (table, l, 0, 1, 4);
1502     }
1504     return table;
1507 static void
1508 clonetiler_pick_switched (GtkToggleButton *tb, gpointer data)
1510     guint v = GPOINTER_TO_INT (data);
1511     prefs_set_int_attribute (prefs_path, "pick", v);
1515 static void
1516 clonetiler_switch_to_create (GtkToggleButton *tb, GtkWidget *dlg)
1518     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1519     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1521     if (rowscols) {
1522         gtk_widget_set_sensitive (rowscols, TRUE);
1523     }
1524     if (widthheight) {
1525         gtk_widget_set_sensitive (widthheight, FALSE);
1526     }
1528     prefs_set_int_attribute (prefs_path, "fillrect", 0);
1532 static void
1533 clonetiler_switch_to_fill (GtkToggleButton *tb, GtkWidget *dlg)
1535     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1536     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1538     if (rowscols) {
1539         gtk_widget_set_sensitive (rowscols, FALSE);
1540     }
1541     if (widthheight) {
1542         gtk_widget_set_sensitive (widthheight, TRUE);
1543     }
1545     prefs_set_int_attribute (prefs_path, "fillrect", 1);
1551 static void
1552 clonetiler_fill_width_changed (GtkAdjustment *adj, GtkWidget *u)
1554     gdouble const raw_dist = adj->value;
1555     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1556     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1558     prefs_set_double_attribute (prefs_path, "fillwidth", pixels);
1561 static void
1562 clonetiler_fill_height_changed (GtkAdjustment *adj, GtkWidget *u)
1564     gdouble const raw_dist = adj->value;
1565     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1566     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1568     prefs_set_double_attribute (prefs_path, "fillheight", pixels);
1572 static void
1573 clonetiler_do_pick_toggled (GtkToggleButton *tb, gpointer data)
1575     GtkWidget *vvb = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "dotrace");
1577     prefs_set_int_attribute (prefs_path, "dotrace", gtk_toggle_button_get_active (tb));
1579     if (vvb)
1580         gtk_widget_set_sensitive (vvb, gtk_toggle_button_get_active (tb));
1586 void
1587 clonetiler_dialog (void)
1589     if (!dlg)
1590     {
1591         gchar title[500];
1592         sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_CLONETILER), title);
1594         dlg = sp_window_new (title, TRUE);
1595         if (x == -1000 || y == -1000) {
1596             x = prefs_get_int_attribute (prefs_path, "x", 0);
1597             y = prefs_get_int_attribute (prefs_path, "y", 0);
1598         }
1599         
1600         if (w ==0 || h == 0) {
1601             w = prefs_get_int_attribute (prefs_path, "w", 0);
1602             h = prefs_get_int_attribute (prefs_path, "h", 0);
1603         }
1604         
1605         if (x<0) x=0;
1606         if (y<0) y=0;
1608         if (x != 0 || y != 0) {
1609             gtk_window_move ((GtkWindow *) dlg, x, y);
1610         
1611         } else {
1612             gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
1613         }
1614         
1615         if (w && h) {
1616             gtk_window_resize ((GtkWindow *) dlg, w, h);
1617         }
1618         
1619         sp_transientize (dlg);
1620         wd.win = dlg;
1621         wd.stop = 0;
1622         
1623                              
1624         gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);
1625         
1626         gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (clonetiler_dialog_destroy), dlg);
1627         gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (clonetiler_dialog_delete), dlg);
1629         if (Inkscape::NSApplication::Application::getNewGui())
1630         {
1631             _shutdown_connection = Inkscape::NSApplication::Editor::connectShutdown (&on_delete);
1632             _dialogs_hidden_connection = Inkscape::NSApplication::Editor::connectDialogsHidden (sigc::bind (&on_dialog_hide, dlg));
1633             _dialogs_unhidden_connection = Inkscape::NSApplication::Editor::connectDialogsUnhidden (sigc::bind (&on_dialog_unhide, dlg));
1634             _desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::bind (&on_transientize, &wd));
1635         } else {            
1636             g_signal_connect   ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (clonetiler_dialog_delete), dlg);
1637             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg);
1638             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg);
1639             g_signal_connect   ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd);
1640         }
1642         GtkTooltips *tt = gtk_tooltips_new();
1644         GtkWidget *mainbox = gtk_vbox_new(FALSE, 4);
1645         gtk_container_set_border_width (GTK_CONTAINER (mainbox), 6);
1646         gtk_container_add (GTK_CONTAINER (dlg), mainbox);
1648         GtkWidget *nb = gtk_notebook_new ();
1649         gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0);
1652 // Symmetry
1653         {
1654             GtkWidget *vb = clonetiler_new_tab (nb, _("_Symmetry"));
1656             GtkWidget *om = gtk_option_menu_new ();
1657             /* TRANSLATORS: For the following 17 symmetry groups, see
1658              * http://www.bib.ulb.ac.be/coursmath/doc/17.htm (visual examples);
1659              * http://www.clarku.edu/~djoyce/wallpaper/seventeen.html (English vocabulary); or
1660              * http://membres.lycos.fr/villemingerard/Geometri/Sym1D.htm (French vocabulary).
1661              */
1662             gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), om, _("Select one of the 17 symmetry groups for the tiling"), NULL);
1663             gtk_box_pack_start (GTK_BOX (vb), om, FALSE, FALSE, SB_MARGIN);
1665             GtkWidget *m = gtk_menu_new ();
1666             int current = prefs_get_int_attribute (prefs_path, "symmetrygroup", 0);
1668             struct SymGroups {
1669                 int group;
1670                 gchar const *label;
1671             } const sym_groups[] = {
1672                 // TRANSLATORS: "translation" means "shift" / "displacement" here.
1673                 {TILE_P1, _("<b>P1</b>: simple translation")},
1674                 {TILE_P2, _("<b>P2</b>: 180&#176; rotation")},
1675                 {TILE_PM, _("<b>PM</b>: reflection")},
1676                 // TRANSLATORS: "glide reflection" is a reflection and a translation combined.
1677                 //  For more info, see http://mathforum.org/sum95/suzanne/symsusan.html
1678                 {TILE_PG, _("<b>PG</b>: glide reflection")},
1679                 {TILE_CM, _("<b>CM</b>: reflection + glide reflection")},
1680                 {TILE_PMM, _("<b>PMM</b>: reflection + reflection")},
1681                 {TILE_PMG, _("<b>PMG</b>: reflection + 180&#176; rotation")},
1682                 {TILE_PGG, _("<b>PGG</b>: glide reflection + 180&#176; rotation")},
1683                 {TILE_CMM, _("<b>CMM</b>: reflection + reflection + 180&#176; rotation")},
1684                 {TILE_P4, _("<b>P4</b>: 90&#176; rotation")},
1685                 {TILE_P4M, _("<b>P4M</b>: 90&#176; rotation + 45&#176; reflection")},
1686                 {TILE_P4G, _("<b>P4G</b>: 90&#176; rotation + 90&#176; reflection")},
1687                 {TILE_P3, _("<b>P3</b>: 120&#176; rotation")},
1688                 {TILE_P31M, _("<b>P31M</b>: reflection + 120&#176; rotation, dense")},
1689                 {TILE_P3M1, _("<b>P3M1</b>: reflection + 120&#176; rotation, sparse")},
1690                 {TILE_P6, _("<b>P6</b>: 60&#176; rotation")},
1691                 {TILE_P6M, _("<b>P6M</b>: reflection + 60&#176; rotation")},
1692             };
1694             for (unsigned j = 0; j < G_N_ELEMENTS(sym_groups); ++j) {
1695                 SymGroups const &sg = sym_groups[j];
1697                 GtkWidget *l = gtk_label_new ("");
1698                 gtk_label_set_markup (GTK_LABEL(l), sg.label);
1699                 gtk_misc_set_alignment (GTK_MISC(l), 0, 0.5);
1701                 GtkWidget *item = gtk_menu_item_new ();
1702                 gtk_container_add (GTK_CONTAINER (item), l);
1704                 gtk_signal_connect ( GTK_OBJECT (item), "activate",
1705                                      GTK_SIGNAL_FUNC (clonetiler_symgroup_changed),
1706                                      GINT_TO_POINTER (sg.group) );
1708                 gtk_menu_append (GTK_MENU (m), item);
1709             }
1711             gtk_option_menu_set_menu (GTK_OPTION_MENU (om), m);
1712             gtk_option_menu_set_history ( GTK_OPTION_MENU (om), current);
1713         }
1715         table_row_labels = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1717 // Shift
1718         {
1719             GtkWidget *vb = clonetiler_new_tab (nb, _("S_hift"));
1721             GtkWidget *table = clonetiler_table_x_y_rand (3);
1722             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1724             // X
1725             {
1726                 GtkWidget *l = gtk_label_new ("");
1727                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) horizontally by this amount
1728                     // xgettext:no-c-format
1729                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift X:</b>"));
1730                 gtk_size_group_add_widget(table_row_labels, l);
1731                 clonetiler_table_attach (table, l, 1, 2, 1);
1732             }
1734             {
1735                 GtkWidget *l = clonetiler_spinbox (tt,
1736                     // xgettext:no-c-format
1737                                                    _("Horizontal shift per row (in % of tile width)"), "d_x_per_y",
1738                                                    -100, 1000, "%");
1739                 clonetiler_table_attach (table, l, 0, 2, 2);
1740             }
1742             {
1743                 GtkWidget *l = clonetiler_spinbox (tt,
1744                     // xgettext:no-c-format
1745                                                    _("Horizontal shift per column (in % of tile width)"), "d_x_per_x",
1746                                                    -100, 1000, "%");
1747                 clonetiler_table_attach (table, l, 0, 2, 3);
1748             }
1750             {
1751                 GtkWidget *l = clonetiler_spinbox (tt,
1752                                                    _("Randomize the horizontal shift by this percentage"), "rand_x",
1753                                                    0, 1000, "%");
1754                 clonetiler_table_attach (table, l, 0, 2, 4);
1755             }
1757             // Y
1758             {
1759                 GtkWidget *l = gtk_label_new ("");
1760                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) vertically by this amount
1761                     // xgettext:no-c-format
1762                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift Y:</b>"));
1763                 gtk_size_group_add_widget(table_row_labels, l);
1764                 clonetiler_table_attach (table, l, 1, 3, 1);
1765             }
1767             {
1768                 GtkWidget *l = clonetiler_spinbox (tt,
1769                     // xgettext:no-c-format
1770                                                    _("Vertical shift per row (in % of tile height)"), "d_y_per_y",
1771                                                    -100, 1000, "%");
1772                 clonetiler_table_attach (table, l, 0, 3, 2);
1773             }
1775             {
1776                 GtkWidget *l = clonetiler_spinbox (tt,
1777                     // xgettext:no-c-format
1778                                                    _("Vertical shift per column (in % of tile height)"), "d_y_per_x",
1779                                                    -100, 1000, "%");
1780                 clonetiler_table_attach (table, l, 0, 3, 3);
1781             }
1783             {
1784                 GtkWidget *l = clonetiler_spinbox (tt,
1785                                                    _("Randomize the vertical shift by this percentage"), "rand_y",
1786                                                    0, 1000, "%");
1787                 clonetiler_table_attach (table, l, 0, 3, 4);
1788             }
1790             // Exponent
1791             {
1792                 GtkWidget *l = gtk_label_new ("");
1793                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
1794                 gtk_size_group_add_widget(table_row_labels, l);
1795                 clonetiler_table_attach (table, l, 1, 4, 1);
1796             }
1798             {
1799                 GtkWidget *l = clonetiler_spinbox (tt,
1800                                                    _("Whether rows are spaced evenly (1), converge (<1) or diverge (>1)"), "d_per_y_exp",
1801                                                    0, 10, "", true);
1802                 clonetiler_table_attach (table, l, 0, 4, 2);
1803             }
1805             {
1806                 GtkWidget *l = clonetiler_spinbox (tt,
1807                                                    _("Whether columns are spaced evenly (1), converge (<1) or diverge (>1)"), "d_per_x_exp",
1808                                                    0, 10, "", true);
1809                 clonetiler_table_attach (table, l, 0, 4, 3);
1810             }
1812             { // alternates
1813                 GtkWidget *l = gtk_label_new ("");
1814                 // TRANSLATORS: "Alternate" is a verb here
1815                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
1816                 gtk_size_group_add_widget(table_row_labels, l);
1817                 clonetiler_table_attach (table, l, 1, 5, 1);
1818             }
1820             {
1821                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each row"), "alternate_y");
1822                 clonetiler_table_attach (table, l, 0, 5, 2);
1823             }
1825             {
1826                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each column"), "alternate_x");
1827                 clonetiler_table_attach (table, l, 0, 5, 3);
1828             }
1830         }
1833 // Scale
1834         {
1835             GtkWidget *vb = clonetiler_new_tab (nb, _("Sc_ale"));
1837             GtkWidget *table = clonetiler_table_x_y_rand (2);
1838             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1840             // X
1841             {
1842                 GtkWidget *l = gtk_label_new ("");
1843                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale X:</b>"));
1844                 gtk_size_group_add_widget(table_row_labels, l);
1845                 clonetiler_table_attach (table, l, 1, 2, 1);
1846             }
1848             {
1849                 GtkWidget *l = clonetiler_spinbox (tt,
1850                     // xgettext:no-c-format
1851                                                    _("Horizontal scale per row (in % of tile width)"), "d_scalex_per_y",
1852                                                    -100, 1000, "%");
1853                 clonetiler_table_attach (table, l, 0, 2, 2);
1854             }
1856             {
1857                 GtkWidget *l = clonetiler_spinbox (tt,
1858                     // xgettext:no-c-format
1859                                                    _("Horizontal scale per column (in % of tile width)"), "d_scalex_per_x",
1860                                                    -100, 1000, "%");
1861                 clonetiler_table_attach (table, l, 0, 2, 3);
1862             }
1864             {
1865                 GtkWidget *l = clonetiler_spinbox (tt,
1866                                                    _("Randomize the horizontal scale by this percentage"), "rand_scalex",
1867                                                    0, 1000, "%");
1868                 clonetiler_table_attach (table, l, 0, 2, 4);
1869             }
1871             // Y
1872             {
1873                 GtkWidget *l = gtk_label_new ("");
1874                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale Y:</b>"));
1875                 gtk_size_group_add_widget(table_row_labels, l);
1876                 clonetiler_table_attach (table, l, 1, 3, 1);
1877             }
1879             {
1880                 GtkWidget *l = clonetiler_spinbox (tt,
1881                     // xgettext:no-c-format
1882                                                    _("Vertical scale per row (in % of tile height)"), "d_scaley_per_y",
1883                                                    -100, 1000, "%");
1884                 clonetiler_table_attach (table, l, 0, 3, 2);
1885             }
1887             {
1888                 GtkWidget *l = clonetiler_spinbox (tt,
1889                     // xgettext:no-c-format
1890                                                    _("Vertical scale per column (in % of tile height)"), "d_scaley_per_x",
1891                                                    -100, 1000, "%");
1892                 clonetiler_table_attach (table, l, 0, 3, 3);
1893             }
1895             {
1896                 GtkWidget *l = clonetiler_spinbox (tt,
1897                                                    _("Randomize the vertical scale by this percentage"), "rand_scaley",
1898                                                    0, 1000, "%");
1899                 clonetiler_table_attach (table, l, 0, 3, 4);
1900             }
1902             { // alternates
1903                 GtkWidget *l = gtk_label_new ("");
1904                 // TRANSLATORS: "Alternate" is a verb here
1905                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
1906                 gtk_size_group_add_widget(table_row_labels, l);
1907                 clonetiler_table_attach (table, l, 1, 4, 1);
1908             }
1910             {
1911                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each row"), "alternate_scaley");
1912                 clonetiler_table_attach (table, l, 0, 4, 2);
1913             }
1915             {
1916                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each column"), "alternate_scalex");
1917                 clonetiler_table_attach (table, l, 0, 4, 3);
1918             }
1920         }
1923 // Rotation
1924         {
1925             GtkWidget *vb = clonetiler_new_tab (nb, _("_Rotation"));
1927             GtkWidget *table = clonetiler_table_x_y_rand (1);
1928             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1930             // Angle
1931             {
1932                 GtkWidget *l = gtk_label_new ("");
1933                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Angle:</b>"));
1934                 gtk_size_group_add_widget(table_row_labels, l);
1935                 clonetiler_table_attach (table, l, 1, 2, 1);
1936             }
1938             {
1939                 GtkWidget *l = clonetiler_spinbox (tt,
1940                     // xgettext:no-c-format
1941                                                    _("Rotate tiles by this angle for each row"), "d_rot_per_y",
1942                                                    -180, 180, "&#176;");
1943                 clonetiler_table_attach (table, l, 0, 2, 2);
1944             }
1946             {
1947                 GtkWidget *l = clonetiler_spinbox (tt,
1948                     // xgettext:no-c-format
1949                                                    _("Rotate tiles by this angle for each column"), "d_rot_per_x",
1950                                                    -180, 180, "&#176;");
1951                 clonetiler_table_attach (table, l, 0, 2, 3);
1952             }
1954             {
1955                 GtkWidget *l = clonetiler_spinbox (tt,
1956                                                    _("Randomize the rotation angle by this percentage"), "rand_rot",
1957                                                    0, 100, "%");
1958                 clonetiler_table_attach (table, l, 0, 2, 4);
1959             }
1961             { // alternates
1962                 GtkWidget *l = gtk_label_new ("");
1963                 // TRANSLATORS: "Alternate" is a verb here
1964                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
1965                 gtk_size_group_add_widget(table_row_labels, l);
1966                 clonetiler_table_attach (table, l, 1, 3, 1);
1967             }
1969             {
1970                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each row"), "alternate_roty");
1971                 clonetiler_table_attach (table, l, 0, 3, 2);
1972             }
1974             {
1975                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each column"), "alternate_rotx");
1976                 clonetiler_table_attach (table, l, 0, 3, 3);
1977             }
1978         }
1981 // Opacity
1982         {
1983             GtkWidget *vb = clonetiler_new_tab (nb, _("_Opacity"));
1985             GtkWidget *table = clonetiler_table_x_y_rand (1);
1986             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1988             // Dissolve
1989             {
1990                 GtkWidget *l = gtk_label_new ("");
1991                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Fade out:</b>"));
1992                 gtk_size_group_add_widget(table_row_labels, l);
1993                 clonetiler_table_attach (table, l, 1, 2, 1);
1994             }
1996             {
1997                 GtkWidget *l = clonetiler_spinbox (tt,
1998                                                    _("Decrease tile opacity by this percentage for each row"), "d_opacity_per_y",
1999                                                    0, 100, "%");
2000                 clonetiler_table_attach (table, l, 0, 2, 2);
2001             }
2003             {
2004                 GtkWidget *l = clonetiler_spinbox (tt,
2005                                                    _("Decrease tile opacity by this percentage for each column"), "d_opacity_per_x",
2006                                                    0, 100, "%");
2007                 clonetiler_table_attach (table, l, 0, 2, 3);
2008             }
2010             {
2011                 GtkWidget *l = clonetiler_spinbox (tt,
2012                                                    _("Randomize the tile opacity by this percentage"), "rand_opacity",
2013                                                    0, 100, "%");
2014                 clonetiler_table_attach (table, l, 0, 2, 4);
2015             }
2017             { // alternates
2018                 GtkWidget *l = gtk_label_new ("");
2019                 // TRANSLATORS: "Alternate" is a verb here
2020                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2021                 gtk_size_group_add_widget(table_row_labels, l);
2022                 clonetiler_table_attach (table, l, 1, 3, 1);
2023             }
2025             {
2026                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each row"), "alternate_opacityy");
2027                 clonetiler_table_attach (table, l, 0, 3, 2);
2028             }
2030             {
2031                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each column"), "alternate_opacityx");
2032                 clonetiler_table_attach (table, l, 0, 3, 3);
2033             }
2034         }
2037 // Color
2038         {
2039             GtkWidget *vb = clonetiler_new_tab (nb, _("Co_lor"));
2041             {
2042             GtkWidget *hb = gtk_hbox_new (FALSE, 0);
2044             GtkWidget *l = gtk_label_new (_("Initial color: "));
2045             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2047             guint32 rgba = 0x000000ff | sp_svg_read_color (prefs_get_string_attribute(prefs_path, "initial_color"), 0x000000ff);
2048             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);
2049             _color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed));
2051             gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast<GtkWidget*>(color_picker->gobj()), FALSE, FALSE, 0);
2053             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2054             }
2057             GtkWidget *table = clonetiler_table_x_y_rand (3);
2058             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2060             // Hue
2061             {
2062                 GtkWidget *l = gtk_label_new ("");
2063                 gtk_label_set_markup (GTK_LABEL(l), _("<b>H:</b>"));
2064                 gtk_size_group_add_widget(table_row_labels, l);
2065                 clonetiler_table_attach (table, l, 1, 2, 1);
2066             }
2068             {
2069                 GtkWidget *l = clonetiler_spinbox (tt,
2070                                                    _("Change the tile hue by this percentage for each row"), "d_hue_per_y",
2071                                                    -100, 100, "%");
2072                 clonetiler_table_attach (table, l, 0, 2, 2);
2073             }
2075             {
2076                 GtkWidget *l = clonetiler_spinbox (tt,
2077                                                    _("Change the tile hue by this percentage for each column"), "d_hue_per_x",
2078                                                    -100, 100, "%");
2079                 clonetiler_table_attach (table, l, 0, 2, 3);
2080             }
2082             {
2083                 GtkWidget *l = clonetiler_spinbox (tt,
2084                                                    _("Randomize the tile hue by this percentage"), "rand_hue",
2085                                                    0, 100, "%");
2086                 clonetiler_table_attach (table, l, 0, 2, 4);
2087             }
2090             // Saturation
2091             {
2092                 GtkWidget *l = gtk_label_new ("");
2093                 gtk_label_set_markup (GTK_LABEL(l), _("<b>S:</b>"));
2094                 gtk_size_group_add_widget(table_row_labels, l);
2095                 clonetiler_table_attach (table, l, 1, 3, 1);
2096             }
2098             {
2099                 GtkWidget *l = clonetiler_spinbox (tt,
2100                                                    _("Change the color saturation by this percentage for each row"), "d_saturation_per_y",
2101                                                    -100, 100, "%");
2102                 clonetiler_table_attach (table, l, 0, 3, 2);
2103             }
2105             {
2106                 GtkWidget *l = clonetiler_spinbox (tt,
2107                                                    _("Change the color saturation by this percentage for each column"), "d_saturation_per_x",
2108                                                    -100, 100, "%");
2109                 clonetiler_table_attach (table, l, 0, 3, 3);
2110             }
2112             {
2113                 GtkWidget *l = clonetiler_spinbox (tt,
2114                                                    _("Randomize the color saturation by this percentage"), "rand_saturation",
2115                                                    0, 100, "%");
2116                 clonetiler_table_attach (table, l, 0, 3, 4);
2117             }
2119             // Lightness
2120             {
2121                 GtkWidget *l = gtk_label_new ("");
2122                 gtk_label_set_markup (GTK_LABEL(l), _("<b>L:</b>"));
2123                 gtk_size_group_add_widget(table_row_labels, l);
2124                 clonetiler_table_attach (table, l, 1, 4, 1);
2125             }
2127             {
2128                 GtkWidget *l = clonetiler_spinbox (tt,
2129                                                    _("Change the color lightness by this percentage for each row"), "d_lightness_per_y",
2130                                                    -100, 100, "%");
2131                 clonetiler_table_attach (table, l, 0, 4, 2);
2132             }
2134             {
2135                 GtkWidget *l = clonetiler_spinbox (tt,
2136                                                    _("Change the color lightness by this percentage for each column"), "d_lightness_per_x",
2137                                                    -100, 100, "%");
2138                 clonetiler_table_attach (table, l, 0, 4, 3);
2139             }
2141             {
2142                 GtkWidget *l = clonetiler_spinbox (tt,
2143                                                    _("Randomize the color lightness by this percentage"), "rand_lightness",
2144                                                    0, 100, "%");
2145                 clonetiler_table_attach (table, l, 0, 4, 4);
2146             }
2149             { // alternates
2150                 GtkWidget *l = gtk_label_new ("");
2151                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2152                 gtk_size_group_add_widget(table_row_labels, l);
2153                 clonetiler_table_attach (table, l, 1, 5, 1);
2154             }
2156             {
2157                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each row"), "alternate_color_y");
2158                 clonetiler_table_attach (table, l, 0, 5, 2);
2159             }
2161             {
2162                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each column"), "alternate_color_x");
2163                 clonetiler_table_attach (table, l, 0, 5, 3);
2164             }
2166         }
2168 // Trace
2169         {
2170             GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace"));
2173         {
2174             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2175             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2177             GtkWidget *b  = gtk_check_button_new_with_label (_("Trace the drawing under the tiles"));
2178             g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
2179             gint old = prefs_get_int_attribute (prefs_path, "dotrace", 0);
2180             gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2181             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);
2182             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2184             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2185                                GTK_SIGNAL_FUNC(clonetiler_do_pick_toggled), dlg);
2186         }
2188         {
2189             GtkWidget *vvb = gtk_vbox_new (FALSE, 0);
2190             gtk_box_pack_start (GTK_BOX (vb), vvb, FALSE, FALSE, 0);
2191             g_object_set_data (G_OBJECT(dlg), "dotrace", (gpointer) vvb);
2194             {
2195                 GtkWidget *frame = gtk_frame_new (_("1. Pick from the drawing:"));
2196                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2198                 GtkWidget *table = gtk_table_new (3, 3, FALSE);
2199                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2200                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2201                 gtk_container_add(GTK_CONTAINER(frame), table);
2204                 GtkWidget* radio;
2205                 {
2206                     radio = gtk_radio_button_new_with_label (NULL, _("Color"));
2207                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the visible color and opacity"), NULL);
2208                     clonetiler_table_attach (table, radio, 0.0, 1, 1);
2209                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2210                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_COLOR));
2211                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_COLOR);
2212                 }
2213                 {
2214                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Opacity"));
2215                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the total accumulated opacity"), NULL);
2216                     clonetiler_table_attach (table, radio, 0.0, 2, 1);
2217                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2218                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_OPACITY));
2219                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_OPACITY);
2220                 }
2221                 {
2222                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("R"));
2223                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Red component of the color"), NULL);
2224                     clonetiler_table_attach (table, radio, 0.0, 1, 2);
2225                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2226                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_R));
2227                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_R);
2228                 }
2229                 {
2230                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("G"));
2231                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Green component of the color"), NULL);
2232                     clonetiler_table_attach (table, radio, 0.0, 2, 2);
2233                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2234                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_G));
2235                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_G);
2236                 }
2237                 {
2238                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("B"));
2239                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Blue component of the color"), NULL);
2240                     clonetiler_table_attach (table, radio, 0.0, 3, 2);
2241                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2242                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_B));
2243                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_B);
2244                 }
2245                 {
2246                     //TRANSLATORS: only translate "string" in "context|string". 
2247                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2248                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|H"));
2249                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the hue of the color"), NULL);
2250                     clonetiler_table_attach (table, radio, 0.0, 1, 3);
2251                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2252                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_H));
2253                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_H);
2254                 }
2255                 {
2256                     //TRANSLATORS: only translate "string" in "context|string". 
2257                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2258                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|S"));
2259                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the saturation of the color"), NULL);
2260                     clonetiler_table_attach (table, radio, 0.0, 2, 3);
2261                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2262                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_S));
2263                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_S);
2264                 }
2265                 {
2266                     //TRANSLATORS: only translate "string" in "context|string". 
2267                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2268                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|L"));
2269                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the lightness of the color"), NULL);
2270                     clonetiler_table_attach (table, radio, 0.0, 3, 3);
2271                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2272                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_L));
2273                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_L);
2274                 }
2276             }
2278             {
2279                 GtkWidget *frame = gtk_frame_new (_("2. Tweak the picked value:"));
2280                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, VB_MARGIN);
2282                 GtkWidget *table = gtk_table_new (4, 2, FALSE);
2283                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2284                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2285                 gtk_container_add(GTK_CONTAINER(frame), table);
2287                 {
2288                     GtkWidget *l = gtk_label_new ("");
2289                     gtk_label_set_markup (GTK_LABEL(l), _("Gamma-correct:"));
2290                     clonetiler_table_attach (table, l, 1.0, 1, 1);
2291                 }
2292                 {
2293                     GtkWidget *l = clonetiler_spinbox (tt,
2294                                                        _("Shift the mid-range of the picked value upwards (>0) or downwards (<0)"), "gamma_picked",
2295                                                        -10, 10, "");
2296                     clonetiler_table_attach (table, l, 0.0, 1, 2);
2297                 }
2299                 {
2300                     GtkWidget *l = gtk_label_new ("");
2301                     gtk_label_set_markup (GTK_LABEL(l), _("Randomize:"));
2302                     clonetiler_table_attach (table, l, 1.0, 1, 3);
2303                 }
2304                 {
2305                     GtkWidget *l = clonetiler_spinbox (tt,
2306                                                        _("Randomize the picked value by this percentage"), "rand_picked",
2307                                                        0, 100, "%");
2308                     clonetiler_table_attach (table, l, 0.0, 1, 4);
2309                 }
2311                 {
2312                     GtkWidget *l = gtk_label_new ("");
2313                     gtk_label_set_markup (GTK_LABEL(l), _("Invert:"));
2314                     clonetiler_table_attach (table, l, 1.0, 2, 1);
2315                 }
2316                 {
2317                     GtkWidget *l = clonetiler_checkbox (tt, _("Invert the picked value"), "invert_picked");
2318                     clonetiler_table_attach (table, l, 0.0, 2, 2);
2319                 }
2320             }
2322             {
2323                 GtkWidget *frame = gtk_frame_new (_("3. Apply the value to the clones':"));
2324                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2327                 GtkWidget *table = gtk_table_new (2, 2, FALSE);
2328                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2329                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2330                 gtk_container_add(GTK_CONTAINER(frame), table);
2332                 {
2333                     GtkWidget *b  = gtk_check_button_new_with_label (_("Presence"));
2334                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_presence", 1);
2335                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2336                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone is created with the probability determined by the picked value in that point"), NULL);
2337                     clonetiler_table_attach (table, b, 0.0, 1, 1);
2338                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2339                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_presence");
2340                 }
2342                 {
2343                     GtkWidget *b  = gtk_check_button_new_with_label (_("Size"));
2344                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_size", 0);
2345                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2346                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's size is determined by the picked value in that point"), NULL);
2347                     clonetiler_table_attach (table, b, 0.0, 2, 1);
2348                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2349                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_size");
2350                 }
2352                 {
2353                     GtkWidget *b  = gtk_check_button_new_with_label (_("Color"));
2354                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_color", 0);
2355                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2356                     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);
2357                     clonetiler_table_attach (table, b, 0.0, 1, 2);
2358                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2359                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_color");
2360                 }
2362                 {
2363                     GtkWidget *b  = gtk_check_button_new_with_label (_("Opacity"));
2364                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_opacity", 0);
2365                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2366                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's opacity is determined by the picked value in that point"), NULL);
2367                     clonetiler_table_attach (table, b, 0.0, 2, 2);
2368                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2369                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_opacity");
2370                 }
2371             }
2372            gtk_widget_set_sensitive (vvb, prefs_get_int_attribute (prefs_path, "dotrace", 0));
2373         }
2374         }
2376 // Rows/columns, width/height
2377         {
2378             GtkWidget *table = gtk_table_new (2, 2, FALSE);
2379             gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
2380             gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2381             gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2382             gtk_box_pack_start (GTK_BOX (mainbox), table, FALSE, FALSE, 0);
2384             {
2385                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2386                 g_object_set_data (G_OBJECT(dlg), "rowscols", (gpointer) hb);
2388                 {
2389                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2390                     int value = prefs_get_int_attribute (prefs_path, "ymax", 2);
2391                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2392                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2393                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many rows in the tiling"), NULL);
2394                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2395                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2397                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2398                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "ymax");
2399                 }
2401                 {
2402                     GtkWidget *l = gtk_label_new ("");
2403                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2404                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2405                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2406                 }
2408                 {
2409                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2410                     int value = prefs_get_int_attribute (prefs_path, "xmax", 2);
2411                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2412                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2413                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many columns in the tiling"), NULL);
2414                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2415                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2417                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2418                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "xmax");
2419                 }
2421                 clonetiler_table_attach (table, hb, 0.0, 1, 2);
2422             }
2424             {
2425                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2426                 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
2428                 // unitmenu
2429                 GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
2430                 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), SP_DT_NAMEDVIEW(SP_ACTIVE_DESKTOP)->doc_units);
2431     
2432                 {
2433                     // Width spinbutton 
2434                     GtkObject *a = gtk_adjustment_new (0.0, -SP_DESKTOP_SCROLL_LIMIT, SP_DESKTOP_SCROLL_LIMIT, 1.0, 10.0, 10.0);
2435                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2437                     double value = prefs_get_double_attribute (prefs_path, "fillwidth", 50);
2438                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2439                     gdouble const units = sp_pixels_get_units (value, unit);
2440                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2442                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2443                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Width of the rectangle to be filled"), NULL);
2444                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2445                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2446                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2447                                        GTK_SIGNAL_FUNC(clonetiler_fill_width_changed), u);
2448                 }
2449                 {
2450                     GtkWidget *l = gtk_label_new ("");
2451                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2452                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2453                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2454                 }
2456                 {
2457                     // Height spinbutton
2458                     GtkObject *a = gtk_adjustment_new (0.0, -SP_DESKTOP_SCROLL_LIMIT, SP_DESKTOP_SCROLL_LIMIT, 1.0, 10.0, 10.0);
2459                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2461                     double value = prefs_get_double_attribute (prefs_path, "fillheight", 50);
2462                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2463                     gdouble const units = sp_pixels_get_units (value, unit);
2464                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2467                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2468                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Height of the rectangle to be filled"), NULL);
2469                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2470                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2471                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2472                                        GTK_SIGNAL_FUNC(clonetiler_fill_height_changed), u);
2473                 }
2475                 gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);
2476                 clonetiler_table_attach (table, hb, 0.0, 2, 2);
2478             }
2480             // Switch
2481             GtkWidget* radio;
2482             {
2483                 radio = gtk_radio_button_new_with_label (NULL, _("Rows, columns: "));
2484                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Create the specified number of rows and columns"), NULL);
2485                 clonetiler_table_attach (table, radio, 0.0, 1, 1);
2486                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_create), (gpointer) dlg);
2487             }
2488             if (prefs_get_int_attribute(prefs_path, "fillrect", 0) == 0) {
2489                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2490                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2491             }
2492             {
2493                 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Width, height: "));
2494                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Fill the specified width and height with the tiling"), NULL);
2495                 clonetiler_table_attach (table, radio, 0.0, 2, 1);
2496                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_fill), (gpointer) dlg);
2497             }
2498             if (prefs_get_int_attribute(prefs_path, "fillrect", 0) == 1) {
2499                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2500                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2501             }
2502         }
2505 // Use saved pos
2506         {
2507             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2508             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2510             GtkWidget *b  = gtk_check_button_new_with_label (_("Use saved size and position of the tile"));
2511             gint keepbbox = prefs_get_int_attribute (prefs_path, "keepbbox", 1);
2512             gtk_toggle_button_set_active ((GtkToggleButton *) b, keepbbox != 0);
2513             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);
2514             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2516             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2517                                GTK_SIGNAL_FUNC(clonetiler_keep_bbox_toggled), NULL);
2518         }
2520 // Statusbar
2521         {
2522             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2523             gtk_box_pack_end (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2524             GtkWidget *l = gtk_label_new("");
2525             g_object_set_data (G_OBJECT(dlg), "status", (gpointer) l);
2526             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2527         }
2529 // Buttons
2530         {
2531             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2532             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2534             {
2535                 GtkWidget *b = gtk_button_new ();
2536                 GtkWidget *l = gtk_label_new ("");
2537                 gtk_label_set_markup_with_mnemonic (GTK_LABEL(l), _(" <b>_Create</b> "));
2538                 gtk_container_add (GTK_CONTAINER(b), l);
2539                 gtk_tooltips_set_tip (tt, b, _("Create and tile the clones of the selection"), NULL);
2540                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_apply), NULL);
2541                 gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0);
2542             }
2544             { // buttons which are enabled only when there are tiled clones
2545                 GtkWidget *sb = gtk_hbox_new(FALSE, 0);
2546                 gtk_box_pack_end (GTK_BOX (hb), sb, FALSE, FALSE, 0);
2547                 g_object_set_data (G_OBJECT(dlg), "buttons_on_tiles", (gpointer) sb);
2548                 {
2549                     // TRANSLATORS: if a group of objects are "clumped" together, then they
2550                     //  are unevenly spread in the given amount of space - as shown in the
2551                     //  diagrams on the left in the following screenshot:
2552                     //  http://www.inkscape.org/screenshots/gallery/inkscape-0.42-CVS-tiles-unclump.png
2553                     //  So unclumping is the process of spreading a number of objects out more evenly.
2554                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" _Unclump "));
2555                     gtk_tooltips_set_tip (tt, b, _("Spread out clones to reduce clumping; can be applied repeatedly"), NULL);
2556                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_unclump), NULL);
2557                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2558                 }
2560                 {
2561                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" Re_move "));
2562                     gtk_tooltips_set_tip (tt, b, _("Remove existing tiled clones of the selected object (siblings only)"), NULL);
2563                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_remove), NULL);
2564                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2565                 }
2567                 // connect to global selection changed signal (so we can change desktops) and
2568                 // external_change (so we're not fooled by undo)
2569                 g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (clonetiler_change_selection), dlg);
2570                 g_signal_connect (G_OBJECT (INKSCAPE), "external_change", G_CALLBACK (clonetiler_external_change), dlg);
2571                 g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), G_OBJECT (INKSCAPE));
2573                 // update now
2574                 clonetiler_change_selection (NULL, SP_DT_SELECTION(SP_ACTIVE_DESKTOP), dlg);
2575             }
2577             {
2578                 GtkWidget *b = gtk_button_new_with_mnemonic (_(" R_eset "));
2579                 // TRANSLATORS: "change" is a noun here
2580                 gtk_tooltips_set_tip (tt, b, _("Reset all shifts, scales, rotates, opacity and color changes in the dialog to zero"), NULL);
2581                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_reset), NULL);
2582                 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2583             }
2584         }
2586         gtk_widget_show_all (mainbox);
2588     } // end of if (!dlg)
2590     gtk_window_present ((GtkWindow *) dlg);
2594 /*
2595   Local Variables:
2596   mode:c++
2597   c-file-style:"stroustrup"
2598   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2599   indent-tabs-mode:nil
2600   fill-column:99
2601   End:
2602 */
2603 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :