Code

start switching sp_repr_new* over to XML::Document::create*, and rename create method...
[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  *   Johan Engelen <goejendaagh@zonnet.nl>
9  *
10  * Copyright (C) 2004-2006 Authors
11  * Released under GNU GPL
12  */
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
17 #include <glib/gmem.h>
18 #include <gtk/gtk.h>
19 #include <glibmm/i18n.h>
21 #include "application/application.h"
22 #include "application/editor.h"
23 #include "helper/window.h"
24 #include "helper/unit-menu.h"
25 #include "helper/units.h"
26 #include "widgets/icon.h"
27 #include "../inkscape.h"
28 #include "../prefs-utils.h"
29 #include "dialog-events.h"
30 #include "../macros.h"
31 #include "../verbs.h"
32 #include "../interface.h"
33 #include "../selection.h"
34 #include "../style.h"
35 #include "../desktop.h"
36 #include "../desktop-handles.h"
37 #include "../sp-namedview.h"
38 #include "../document.h"
39 #include "../message-stack.h"
40 #include "../sp-use.h"
41 #include "unclump.h"
43 #include "xml/repr.h"
45 #include "svg/svg.h"
46 #include "svg/svg-color.h"
48 #include "libnr/nr-matrix-fns.h"
49 #include "libnr/nr-matrix-ops.h"
51 #include "libnr/nr-matrix-translate-ops.h"
52 #include "libnr/nr-translate-ops.h"
53 #include "libnr/nr-translate-rotate-ops.h"
54 #include "libnr/nr-translate-scale-ops.h"
56 #include "display/nr-arena.h"
57 #include "display/nr-arena-item.h"
59 #include "ui/widget/color-picker.h"
61 #include "../sp-filter.h"
62 #include "../filter-chemistry.h"
64 #define MIN_ONSCREEN_DISTANCE 50
66 static GtkWidget *dlg = NULL;
67 static win_data wd;
69 // impossible original values to make sure they are read from prefs
70 static gint x = -1000, y = -1000, w = 0, h = 0;
71 static gchar *prefs_path = "dialogs.clonetiler";
73 #define SB_MARGIN 1
74 #define VB_MARGIN 4
76 enum {
77     PICK_COLOR,
78     PICK_OPACITY,
79     PICK_R,
80     PICK_G,
81     PICK_B,
82     PICK_H,
83     PICK_S,
84     PICK_L
85 };
87 static GtkSizeGroup* table_row_labels = NULL;
89 static sigc::connection _shutdown_connection;
90 static sigc::connection _dialogs_hidden_connection;
91 static sigc::connection _dialogs_unhidden_connection;
92 static sigc::connection _desktop_activated_connection;
93 static sigc::connection _color_changed_connection;
95 static Inkscape::UI::Widget::ColorPicker *color_picker;
97 static void
98 clonetiler_dialog_destroy (GtkObject *object, gpointer data)
99 {
100     if (Inkscape::NSApplication::Application::getNewGui())
101     {
102         _shutdown_connection.disconnect();
103         _dialogs_hidden_connection.disconnect();
104         _dialogs_unhidden_connection.disconnect();
105         _desktop_activated_connection.disconnect();
106     } else {
107         sp_signal_disconnect_by_data (INKSCAPE, dlg);
108     }
109     _color_changed_connection.disconnect();
111     delete color_picker;
112     
113     wd.win = dlg = NULL;
114     wd.stop = 0;
118 static gboolean
119 clonetiler_dialog_delete (GtkObject *object, GdkEvent * /*event*/, gpointer data)
121     gtk_window_get_position ((GtkWindow *) dlg, &x, &y);
122     gtk_window_get_size ((GtkWindow *) dlg, &w, &h);
124     if (x<0) x=0;
125     if (y<0) y=0;
127     prefs_set_int_attribute (prefs_path, "x", x);
128     prefs_set_int_attribute (prefs_path, "y", y);
129     prefs_set_int_attribute (prefs_path, "w", w);
130     prefs_set_int_attribute (prefs_path, "h", h);
132     return FALSE; // which means, go ahead and destroy it
136 static void on_delete()
138     (void)clonetiler_dialog_delete (0, 0, NULL);
141 static void
142 on_picker_color_changed (guint rgba)
144     static bool is_updating = false;
145     if (is_updating || !SP_ACTIVE_DESKTOP)
146         return;
148     is_updating = true;
150     Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, prefs_path);
151     gchar c[32];
152     sp_svg_write_color(c, 32, rgba);
153     repr->setAttribute("initial_color", c);
155     is_updating = false;
158 static guint clonetiler_number_of_clones (SPObject *obj);
160 static void
161 clonetiler_change_selection (Inkscape::Application * /*inkscape*/, Inkscape::Selection *selection, GtkWidget *dlg)
163     GtkWidget *buttons = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "buttons_on_tiles");
164     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
166     if (selection->isEmpty()) {
167         gtk_widget_set_sensitive (buttons, FALSE);
168         gtk_label_set_markup (GTK_LABEL(status), _("<small>Nothing selected.</small>"));
169         return;
170     }
172     if (g_slist_length ((GSList *) selection->itemList()) > 1) {
173         gtk_widget_set_sensitive (buttons, FALSE);
174         gtk_label_set_markup (GTK_LABEL(status), _("<small>More than one object selected.</small>"));
175         return;
176     }
178     guint n = clonetiler_number_of_clones(selection->singleItem());
179     if (n > 0) {
180         gtk_widget_set_sensitive (buttons, TRUE);
181         gchar *sta = g_strdup_printf (_("<small>Object has <b>%d</b> tiled clones.</small>"), n);
182         gtk_label_set_markup (GTK_LABEL(status), sta);
183         g_free (sta);
184     } else {
185         gtk_widget_set_sensitive (buttons, FALSE);
186         gtk_label_set_markup (GTK_LABEL(status), _("<small>Object has no tiled clones.</small>"));
187     }
190 static void
191 clonetiler_external_change (Inkscape::Application * /*inkscape*/, GtkWidget *dlg)
193     clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
196 static void clonetiler_disconnect_gsignal (GObject *widget, gpointer source) {
197     if (source && G_IS_OBJECT(source))
198         sp_signal_disconnect_by_data (source, widget);
202 enum {
203     TILE_P1,
204     TILE_P2,
205     TILE_PM,
206     TILE_PG,
207     TILE_CM,
208     TILE_PMM,
209     TILE_PMG,
210     TILE_PGG,
211     TILE_CMM,
212     TILE_P4,
213     TILE_P4M,
214     TILE_P4G,
215     TILE_P3,
216     TILE_P31M,
217     TILE_P3M1,
218     TILE_P6,
219     TILE_P6M
220 };
223 static NR::Matrix
224 clonetiler_get_transform ( 
225     // symmetry group
226     int type,
227     // row, column
228     int x, int y,
229     // center, width, height of the tile
230     double cx, double cy,
231     double w, double h,
233     // values from the dialog:
234     double d_x_per_x, double d_y_per_x, double d_x_per_y, double d_y_per_y,
235     int alternate_x, int alternate_y, double rand_x, double rand_y,
236     double d_per_x_exp, double d_per_y_exp,
237     double d_rot_per_x, double d_rot_per_y, int alternate_rotx, int alternate_roty, double rand_rot,
238     double d_scalex_per_x, double d_scaley_per_x, double d_scalex_per_y, double d_scaley_per_y,
239     int alternate_scalex, int alternate_scaley, double rand_scalex, double rand_scaley
240     )
242     // in abs units
243     double eff_x = (alternate_x? (x%2) : pow ((double) x, d_per_x_exp));
244     double eff_y = (alternate_y? (y%2) : pow ((double) y, d_per_y_exp));
245     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);
246     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);
248     NR::Matrix rect_translate (NR::translate (w * pow ((double) x, d_per_x_exp) + dx, h * pow ((double) y, d_per_y_exp) + dy));
250     // in deg
251     double eff_x_rot = (alternate_rotx? (x%2) : (x));
252     double eff_y_rot = (alternate_roty? (y%2) : (y));
253     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);
255     // times the original
256     double eff_x_s = (alternate_scalex? (x%2) : (x));
257     double eff_y_s = (alternate_scaley? (y%2) : (y));
258     double rand_scale_x, rand_scale_y;
259     if (rand_scaley == rand_scalex) {
260         // if rands are equal, scale proportionally
261         rand_scale_x = rand_scale_y = rand_scalex * 1 * g_random_double_range (-1, 1);
262     } else {
263         rand_scale_x = rand_scalex * 1 * g_random_double_range (-1, 1);
264         rand_scale_y = rand_scaley * 1 * g_random_double_range (-1, 1);
265     }
266     double dscalex = 1 + d_scalex_per_x * eff_x_s + d_scalex_per_y * eff_y_s + rand_scale_x;
267     if (dscalex < 0) dscalex = 0;
268     double dscaley = 1 + d_scaley_per_x * eff_x_s + d_scaley_per_y * eff_y_s + rand_scale_y;
269     if (dscaley < 0) dscaley = 0;
271     NR::Matrix drot_c = NR::translate(-cx, -cy) * NR::rotate (M_PI*drot/180) * NR::translate(cx, cy);
273     NR::Matrix dscale_c = NR::translate(-cx, -cy) * NR::scale (dscalex, dscaley) * NR::translate(cx, cy);
275     NR::Matrix d_s_r = dscale_c * drot_c;
277     NR::Matrix rotate_180_c = NR::translate(-cx, -cy) * NR::rotate (M_PI) * NR::translate(cx, cy);
279     NR::Matrix rotate_90_c = NR::translate(-cx, -cy) * NR::rotate (-M_PI/2) * NR::translate(cx, cy);
280     NR::Matrix rotate_m90_c = NR::translate(-cx, -cy) * NR::rotate (M_PI/2) * NR::translate(cx, cy);
282     NR::Matrix rotate_120_c = NR::translate(-cx, -cy) * NR::rotate (-2*M_PI/3) * NR::translate(cx, cy);
283     NR::Matrix rotate_m120_c = NR::translate(-cx, -cy) * NR::rotate (2*M_PI/3) * NR::translate(cx, cy);
285     NR::Matrix rotate_60_c = NR::translate(-cx, -cy) * NR::rotate (-M_PI/3) * NR::translate(cx, cy);
286     NR::Matrix rotate_m60_c = NR::translate(-cx, -cy) * NR::rotate (M_PI/3) * NR::translate(cx, cy);
288     double cos60 = cos(M_PI/3);
289     double sin60 = sin(M_PI/3);
290     double cos30 = cos(M_PI/6);
291     double sin30 = sin(M_PI/6);
293     NR::Matrix flip_x = NR::translate(-cx, -cy) * NR::scale (-1, 1) * NR::translate(cx, cy);
294     NR::Matrix flip_y = NR::translate(-cx, -cy) * NR::scale (1, -1) * NR::translate(cx, cy);
296     x = (int) pow ((double) x, d_per_x_exp);
297     y = (int) pow ((double) y, d_per_y_exp);
299     switch (type) {
301     case TILE_P1:
302         return d_s_r * rect_translate;
303         break;
305     case TILE_P2:
306         if (x % 2 == 0) {
307             return d_s_r * rect_translate;
308         } else {
309             return d_s_r * rotate_180_c * rect_translate;
310         }
311         break;
313     case TILE_PM:
314         if (x % 2 == 0) {
315             return d_s_r * rect_translate;
316         } else {
317             return d_s_r * flip_x * rect_translate;
318         }
319         break;
321     case TILE_PG:
322         if (y % 2 == 0) {
323             return d_s_r * rect_translate;
324         } else {
325             return d_s_r * flip_x * rect_translate;
326         }
327         break;
329     case TILE_CM:
330         if ((x + y) % 2 == 0) {
331             return d_s_r * rect_translate;
332         } else {
333             return d_s_r * flip_x * rect_translate;
334         }
335         break;
337     case TILE_PMM:
338         if (y % 2 == 0) {
339             if (x % 2 == 0) {
340                 return d_s_r * rect_translate;
341             } else {
342                 return d_s_r * flip_x * rect_translate;
343             }
344         } else {
345             if (x % 2 == 0) {
346                 return d_s_r * flip_y * rect_translate;
347             } else {
348                 return d_s_r * flip_x * flip_y * rect_translate;
349             }
350         }
351         break;
353     case TILE_PMG:
354         if (y % 4 == 0) {
355             return d_s_r * rect_translate;
356         } else if (y % 4 == 1) {
357             return d_s_r * flip_y * rect_translate;
358         } else if (y % 4 == 2) {
359             return d_s_r * flip_x * rect_translate;
360         } else if (y % 4 == 3) {
361             return d_s_r * flip_x * flip_y * rect_translate;
362         }
363         break;
365     case TILE_PGG:
366         if (y % 2 == 0) {
367             if (x % 2 == 0) {
368                 return d_s_r * rect_translate;
369             } else {
370                 return d_s_r * flip_y * rect_translate;
371             }
372         } else {
373             if (x % 2 == 0) {
374                 return d_s_r * rotate_180_c * rect_translate;
375             } else {
376                 return d_s_r * rotate_180_c * flip_y * rect_translate;
377             }
378         }
379         break;
381     case TILE_CMM:
382         if (y % 4 == 0) {
383             if (x % 2 == 0) {
384                 return d_s_r * rect_translate;
385             } else {
386                 return d_s_r * flip_x * rect_translate;
387             }
388         } else if (y % 4 == 1) {
389             if (x % 2 == 0) {
390                 return d_s_r * flip_y * rect_translate;
391             } else {
392                 return d_s_r * flip_x * flip_y * rect_translate;
393             }
394         } else if (y % 4 == 2) {
395             if (x % 2 == 1) {
396                 return d_s_r * rect_translate;
397             } else {
398                 return d_s_r * flip_x * rect_translate;
399             }
400         } else {
401             if (x % 2 == 1) {
402                 return d_s_r * flip_y * rect_translate;
403             } else {
404                 return d_s_r * flip_x * flip_y * rect_translate;
405             }
406         }
407         break;
409     case TILE_P4:
410     {
411         NR::Matrix ori (NR::translate ((w + h) * (x/2) + dx,  (h + w) * (y/2) + dy));
412         NR::Matrix dia1 (NR::translate (w/2 + h/2, -h/2 + w/2));
413         NR::Matrix dia2 (NR::translate (-w/2 + h/2, h/2 + w/2));
414         if (y % 2 == 0) {
415             if (x % 2 == 0) {
416                 return d_s_r * ori;
417             } else {
418                 return d_s_r * rotate_m90_c * dia1 * ori;
419             }
420         } else {
421             if (x % 2 == 0) {
422                 return d_s_r * rotate_90_c * dia2 * ori;
423             } else {
424                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
425             }
426         }
427     }
428     break;
430     case TILE_P4M:
431     {
432         double max = MAX(w, h);
433         NR::Matrix ori (NR::translate ((max + max) * (x/4) + dx,  (max + max) * (y/2) + dy));
434         NR::Matrix dia1 (NR::translate (w/2 - h/2, h/2 - w/2));
435         NR::Matrix dia2 (NR::translate (-h/2 + w/2, w/2 - h/2));
436         if (y % 2 == 0) {
437             if (x % 4 == 0) {
438                 return d_s_r * ori;
439             } else if (x % 4 == 1) {
440                 return d_s_r * flip_y * rotate_m90_c * dia1 * ori;
441             } else if (x % 4 == 2) {
442                 return d_s_r * rotate_m90_c * dia1 * NR::translate (h, 0) * ori;
443             } else if (x % 4 == 3) {
444                 return d_s_r * flip_x * NR::translate (w, 0) * ori;
445             }
446         } else {
447             if (x % 4 == 0) {
448                 return d_s_r * flip_y * NR::translate(0, h) * ori;
449             } else if (x % 4 == 1) {
450                 return d_s_r * rotate_90_c * dia2 * NR::translate(0, h) * ori;
451             } else if (x % 4 == 2) {
452                 return d_s_r * flip_y * rotate_90_c * dia2 * NR::translate(h, 0) * NR::translate(0, h) * ori;
453             } else if (x % 4 == 3) {
454                 return d_s_r * flip_y * flip_x * NR::translate(w, 0) * NR::translate(0, h) * ori;
455             }
456         }
457     }
458     break;
460     case TILE_P4G:
461     {
462         double max = MAX(w, h);
463         NR::Matrix ori (NR::translate ((max + max) * (x/4) + dx,  (max + max) * y + dy));
464         NR::Matrix dia1 (NR::translate (w/2 + h/2, h/2 - w/2));
465         NR::Matrix dia2 (NR::translate (-h/2 + w/2, w/2 + h/2));
466         if (((x/4) + y) % 2 == 0) {
467             if (x % 4 == 0) {
468                 return d_s_r * ori;
469             } else if (x % 4 == 1) {
470                 return d_s_r * rotate_m90_c * dia1 * ori;
471             } else if (x % 4 == 2) {
472                 return d_s_r * rotate_90_c * dia2 * ori;
473             } else if (x % 4 == 3) {
474                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
475             }
476         } else {
477             if (x % 4 == 0) {
478                 return d_s_r * flip_y * NR::translate (0, h) * ori;
479             } else if (x % 4 == 1) {
480                 return d_s_r * flip_y * rotate_m90_c * dia1 * NR::translate (-h, 0) * ori;
481             } else if (x % 4 == 2) {
482                 return d_s_r * flip_y * rotate_90_c * dia2 * NR::translate (h, 0) * ori;
483             } else if (x % 4 == 3) {
484                 return d_s_r * flip_x * NR::translate (w, 0) * ori;
485             }
486         }
487     }
488     break;
490     case TILE_P3:
491     {
492         double width;
493         double height;
494         NR::Matrix dia1;
495         NR::Matrix dia2;
496         if (w > h) {
497             width = w + w * cos60;
498             height = 2 * w * sin60;
499             dia1 = NR::Matrix (NR::translate (w/2 + w/2 * cos60, -(w/2 * sin60)));
500             dia2 = dia1 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60)));
501         } else {
502             width = h * cos (M_PI/6);
503             height = h;
504             dia1 = NR::Matrix (NR::translate (h/2 * cos30, -(h/2 * sin30)));
505             dia2 = dia1 * NR::Matrix (NR::translate (0, h/2));
506         }
507         NR::Matrix ori (NR::translate (width * (2*(x/3) + y%2) + dx,  (height/2) * y + dy));
508         if (x % 3 == 0) {
509             return d_s_r * ori;
510         } else if (x % 3 == 1) {
511             return d_s_r * rotate_m120_c * dia1 * ori;
512         } else if (x % 3 == 2) {
513             return d_s_r * rotate_120_c * dia2 * ori;
514         }
515     }
516     break;
518     case TILE_P31M:
519     {
520         NR::Matrix ori;
521         NR::Matrix dia1;
522         NR::Matrix dia2;
523         NR::Matrix dia3;
524         NR::Matrix dia4;
525         if (w > h) {
526             ori = NR::Matrix(NR::translate (w * (x/6) + w/2 * (y%2) + dx,  (w * cos30) * y + dy));
527             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) );
528             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
529             dia3 = dia2 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
530             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
531         } else {
532             ori  = NR::Matrix (NR::translate (2*h * cos30  * (x/6 + 0.5*(y%2)) + dx,  (2*h - h * sin30) * y + dy));
533             dia1 = NR::Matrix (NR::translate (0, -h/2) * NR::translate (h/2 * cos30, h/2 * sin30));
534             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
535             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
536             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
537         }
538         if (x % 6 == 0) {
539             return d_s_r * ori;
540         } else if (x % 6 == 1) {
541             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
542         } else if (x % 6 == 2) {
543             return d_s_r * rotate_m120_c * dia2 * ori;
544         } else if (x % 6 == 3) {
545             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
546         } else if (x % 6 == 4) {
547             return d_s_r * rotate_120_c * dia4 * ori;
548         } else if (x % 6 == 5) {
549             return d_s_r * flip_y * NR::translate(0, h) * ori;
550         }
551     }
552     break;
554     case TILE_P3M1:
555     {
556         double width;
557         double height;
558         NR::Matrix dia1;
559         NR::Matrix dia2;
560         NR::Matrix dia3;
561         NR::Matrix dia4;
562         if (w > h) {
563             width = w + w * cos60;
564             height = 2 * w * sin60;
565             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) );
566             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
567             dia3 = dia2 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
568             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
569         } else {
570             width = 2 * h * cos (M_PI/6);
571             height = 2 * h;
572             dia1 = NR::Matrix (NR::translate (0, -h/2) * NR::translate (h/2 * cos30, h/2 * sin30));
573             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
574             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
575             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
576         }
577         NR::Matrix ori (NR::translate (width * (2*(x/6) + y%2) + dx,  (height/2) * y + dy));
578         if (x % 6 == 0) {
579             return d_s_r * ori;
580         } else if (x % 6 == 1) {
581             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
582         } else if (x % 6 == 2) {
583             return d_s_r * rotate_m120_c * dia2 * ori;
584         } else if (x % 6 == 3) {
585             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
586         } else if (x % 6 == 4) {
587             return d_s_r * rotate_120_c * dia4 * ori;
588         } else if (x % 6 == 5) {
589             return d_s_r * flip_y * NR::translate(0, h) * ori;
590         }
591     }
592     break;
594     case TILE_P6:
595     {
596         NR::Matrix ori;
597         NR::Matrix dia1;
598         NR::Matrix dia2;
599         NR::Matrix dia3;
600         NR::Matrix dia4;
601         NR::Matrix dia5;
602         if (w > h) {
603             ori = NR::Matrix(NR::translate (2*w * (x/6) + w * (y%2) + dx,  (2*w * sin60) * y + dy));
604             dia1 = NR::Matrix (NR::translate (w/2 * cos60, -w/2 * sin60));
605             dia2 = dia1 * NR::Matrix (NR::translate (w/2, 0));
606             dia3 = dia2 * NR::Matrix (NR::translate (w/2 * cos60, w/2 * sin60));
607             dia4 = dia3 * NR::Matrix (NR::translate (-w/2 * cos60, w/2 * sin60));
608             dia5 = dia4 * NR::Matrix (NR::translate (-w/2, 0));
609         } else {
610             ori = NR::Matrix(NR::translate (2*h * cos30 * (x/6 + 0.5*(y%2)) + dx,  (h + h * sin30) * y + dy));
611             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));
612             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));
613             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));
614             dia4 = dia3 * dia1.inverse();
615             dia5 = dia3 * dia2.inverse();
616         }
617         if (x % 6 == 0) {
618             return d_s_r * ori;
619         } else if (x % 6 == 1) {
620             return d_s_r * rotate_m60_c * dia1 * ori;
621         } else if (x % 6 == 2) {
622             return d_s_r * rotate_m120_c * dia2 * ori;
623         } else if (x % 6 == 3) {
624             return d_s_r * rotate_180_c * dia3 * ori;
625         } else if (x % 6 == 4) {
626             return d_s_r * rotate_120_c * dia4 * ori;
627         } else if (x % 6 == 5) {
628             return d_s_r * rotate_60_c * dia5 * ori;
629         }
630     }
631     break;
633     case TILE_P6M:
634     {
636         NR::Matrix ori;
637         NR::Matrix dia1, dia2, dia3, dia4, dia5, dia6, dia7, dia8, dia9, dia10;
638         if (w > h) {
639             ori = NR::Matrix(NR::translate (2*w * (x/12) + w * (y%2) + dx,  (2*w * sin60) * y + dy));
640             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));
641             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, -h * sin30));
642             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));
643             dia4 = dia3 * NR::Matrix (NR::translate (h * cos30, h * sin30));
644             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));
645             dia6 = dia5 * NR::Matrix (NR::translate (0, h));
646             dia7 = dia6 * dia1.inverse();
647             dia8 = dia6 * dia2.inverse();
648             dia9 = dia6 * dia3.inverse();
649             dia10 = dia6 * dia4.inverse();
650         } else {
651             ori = NR::Matrix(NR::translate (4*h * cos30 * (x/12 + 0.5*(y%2)) + dx,  (2*h  + 2*h * sin30) * y + dy));
652             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));
653             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, -h * sin30));
654             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));
655             dia4 = dia3 * NR::Matrix (NR::translate (h * cos30, h * sin30));
656             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));
657             dia6 = dia5 * NR::Matrix (NR::translate (0, h));
658             dia7 = dia6 * dia1.inverse();
659             dia8 = dia6 * dia2.inverse();
660             dia9 = dia6 * dia3.inverse();
661             dia10 = dia6 * dia4.inverse();
662         }
663         if (x % 12 == 0) {
664             return d_s_r * ori;
665         } else if (x % 12 == 1) {
666             return d_s_r * flip_y * rotate_m60_c * dia1 * ori;
667         } else if (x % 12 == 2) {
668             return d_s_r * rotate_m60_c * dia2 * ori;
669         } else if (x % 12 == 3) {
670             return d_s_r * flip_y * rotate_m120_c * dia3 * ori;
671         } else if (x % 12 == 4) {
672             return d_s_r * rotate_m120_c * dia4 * ori;
673         } else if (x % 12 == 5) {
674             return d_s_r * flip_x * dia5 * ori;
675         } else if (x % 12 == 6) {
676             return d_s_r * flip_x * flip_y * dia6 * ori;
677         } else if (x % 12 == 7) {
678             return d_s_r * flip_y * rotate_120_c * dia7 * ori;
679         } else if (x % 12 == 8) {
680             return d_s_r * rotate_120_c * dia8 * ori;
681         } else if (x % 12 == 9) {
682             return d_s_r * flip_y * rotate_60_c * dia9 * ori;
683         } else if (x % 12 == 10) {
684             return d_s_r * rotate_60_c * dia10 * ori;
685         } else if (x % 12 == 11) {
686             return d_s_r * flip_y * NR::translate (0, h) * ori;
687         }
688     }
689     break;
691     default:
692         break;
693     }
695     return NR::identity();
698 static bool
699 clonetiler_is_a_clone_of (SPObject *tile, SPObject *obj)
701     char *id_href = NULL;
703     if (obj) {
704         Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
705         id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
706     }
708     if (SP_IS_USE(tile) &&
709         SP_OBJECT_REPR(tile)->attribute("xlink:href") &&
710         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("xlink:href"))) &&
711         SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of") &&
712         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of"))))
713     {
714         if (id_href)
715             g_free (id_href);
716         return true;
717     } else {
718         if (id_href)
719             g_free (id_href);
720         return false;
721     }
724 static NRArena const *trace_arena = NULL;
725 static unsigned trace_visionkey;
726 static NRArenaItem *trace_root;
727 static gdouble trace_zoom;
729 static void
730 clonetiler_trace_hide_tiled_clones_recursively (SPObject *from)
732     if (!trace_arena)
733         return;
735     for (SPObject *o = sp_object_first_child(from); o != NULL; o = SP_OBJECT_NEXT(o)) {
736         if (SP_IS_ITEM(o) && clonetiler_is_a_clone_of (o, NULL))
737             sp_item_invoke_hide(SP_ITEM(o), trace_visionkey); // FIXME: hide each tiled clone's original too!
738         clonetiler_trace_hide_tiled_clones_recursively (o);
739     }
742 static void
743 clonetiler_trace_setup (SPDocument *doc, gdouble zoom, SPItem *original)
745     trace_arena = NRArena::create();
746     /* Create ArenaItem and set transform */
747     trace_visionkey = sp_item_display_key_new(1);
748     trace_root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT (doc)), 
749                                       (NRArena *) trace_arena, trace_visionkey, SP_ITEM_SHOW_DISPLAY);
751     // hide the (current) original and any tiled clones, we only want to pick the background
752     sp_item_invoke_hide(original, trace_visionkey); 
753     clonetiler_trace_hide_tiled_clones_recursively (SP_OBJECT(SP_DOCUMENT_ROOT (doc)));
755     sp_document_root (doc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
756     sp_document_ensure_up_to_date(doc);
758     trace_zoom = zoom;
761 static guint32
762 clonetiler_trace_pick (NR::Rect box)
764     if (!trace_arena)
765         return 0;
767     NRMatrix t;
768     nr_matrix_set_scale(&t, trace_zoom, trace_zoom);
769     nr_arena_item_set_transform(trace_root, &t);
770     NRGC gc(NULL);
771     nr_matrix_set_identity(&gc.transform);
772     nr_arena_item_invoke_update( trace_root, NULL, &gc,
773                                  NR_ARENA_ITEM_STATE_ALL,
774                                  NR_ARENA_ITEM_STATE_NONE );
776     /* Item integer bbox in points */
777     NRRectL ibox;
778     ibox.x0 = (int) floor(trace_zoom * box.min()[NR::X] + 0.5);
779     ibox.y0 = (int) floor(trace_zoom * box.min()[NR::Y] + 0.5);
780     ibox.x1 = (int) floor(trace_zoom * box.max()[NR::X] + 0.5);
781     ibox.y1 = (int) floor(trace_zoom * box.max()[NR::Y] + 0.5);
783     /* Find visible area */
784     int width = ibox.x1 - ibox.x0;
785     int height = ibox.y1 - ibox.y0;
787     /* Set up pixblock */
788     guchar *px = g_new(guchar, 4 * width * height);
789     memset(px, 0x00, 4 * width * height);
791     /* Render */
792     NRPixBlock pb;
793     nr_pixblock_setup_extern( &pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
794                               ibox.x0, ibox.y0, ibox.x1, ibox.y1,
795                               px, 4 * width, FALSE, FALSE );
796     nr_arena_item_invoke_render( trace_root, &ibox, &pb,
797                                  NR_ARENA_ITEM_RENDER_NO_CACHE );
799     double R = 0, G = 0, B = 0, A = 0;
800     double count = 0;
801     double weight = 0;
803     for (int y = ibox.y0; y < ibox.y1; y++) {
804         const unsigned char *s = NR_PIXBLOCK_PX (&pb) + (y - ibox.y0) * pb.rs;
805         for (int x = ibox.x0; x < ibox.x1; x++) {
806             count += 1;
807             weight += s[3] / 255.0;
808             R += s[0] / 255.0;
809             G += s[1] / 255.0;
810             B += s[2] / 255.0;
811             A += s[3] / 255.0;
812             s += 4;
813         }
814     }
816     nr_pixblock_release(&pb);
818     R = R / weight;
819     G = G / weight;
820     B = B / weight;
821     A = A / count;
823     R = CLAMP (R, 0.0, 1.0);
824     G = CLAMP (G, 0.0, 1.0);
825     B = CLAMP (B, 0.0, 1.0);
826     A = CLAMP (A, 0.0, 1.0);
828     return SP_RGBA32_F_COMPOSE (R, G, B, A);
831 static void
832 clonetiler_trace_finish ()
834     if (trace_arena) {
835         ((NRObject *) trace_arena)->unreference();
836         trace_arena = NULL;
837     }
840 static void
841 clonetiler_unclump (GtkWidget *widget, void *)
843     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
844     if (desktop == NULL)
845         return;
847     Inkscape::Selection *selection = sp_desktop_selection(desktop);
849     // check if something is selected
850     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
851         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump."));
852         return;
853     }
855     SPObject *obj = SP_OBJECT(selection->singleItem());
856     SPObject *parent = SP_OBJECT_PARENT (obj);
858     GSList *to_unclump = NULL; // not including the original
860     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
861         if (clonetiler_is_a_clone_of (child, obj)) {
862             to_unclump = g_slist_prepend (to_unclump, child);
863         }
864     }
866     sp_document_ensure_up_to_date(sp_desktop_document(desktop));
868     unclump (to_unclump);
870     g_slist_free (to_unclump);
872     sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER, 
873                       _("Unclump tiled clones"));
876 static guint
877 clonetiler_number_of_clones (SPObject *obj)
879     SPObject *parent = SP_OBJECT_PARENT (obj);
881     guint n = 0;
883     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
884         if (clonetiler_is_a_clone_of (child, obj)) {
885             n ++;
886         }
887     }
889     return n;
892 static void
893 clonetiler_remove (GtkWidget *widget, void *, bool do_undo = true)
895     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
896     if (desktop == NULL)
897         return;
899     Inkscape::Selection *selection = sp_desktop_selection(desktop);
901     // check if something is selected
902     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
903         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove."));
904         return;
905     }
907     SPObject *obj = SP_OBJECT(selection->singleItem());
908     SPObject *parent = SP_OBJECT_PARENT (obj);
910 // remove old tiling
911     GSList *to_delete = NULL;
912     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
913         if (clonetiler_is_a_clone_of (child, obj)) {
914             to_delete = g_slist_prepend (to_delete, child);
915         }
916     }
917     for (GSList *i = to_delete; i; i = i->next) {
918         SP_OBJECT(i->data)->deleteObject();
919     }
920     g_slist_free (to_delete);
922     clonetiler_change_selection (NULL, selection, dlg);
924     if (do_undo)
925         sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER, 
926                           _("Delete tiled clones"));
929 static NR::Rect
930 transform_rect(NR::Rect const &r, NR::Matrix const &m)
932     using NR::X;
933     using NR::Y;
934     NR::Point const p1 = r.corner(1) * m;
935     NR::Point const p2 = r.corner(2) * m;
936     NR::Point const p3 = r.corner(3) * m;
937     NR::Point const p4 = r.corner(4) * m;
938     return NR::Rect(
939         NR::Point(
940             std::min(std::min(p1[X], p2[X]), std::min(p3[X], p4[X])), 
941             std::min(std::min(p1[Y], p2[Y]), std::min(p3[Y], p4[Y]))), 
942         NR::Point(
943             std::max(std::max(p1[X], p2[X]), std::max(p3[X], p4[X])), 
944             std::max(std::max(p1[Y], p2[Y]), std::max(p3[Y], p4[Y]))));
947 /**
948 Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same
949 probability of being displaced.
950  */
951 static double
952 randomize01 (double val, double rand)
954     double base = MIN (val - rand, 1 - 2*rand);
955     if (base < 0) base = 0;
956     val = base + g_random_double_range (0, MIN (2 * rand, 1 - base));
957     return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case...
961 static void
962 clonetiler_apply (GtkWidget *widget, void *)
964     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
965     if (desktop == NULL)
966         return;
968     Inkscape::Selection *selection = sp_desktop_selection(desktop);
970     // check if something is selected
971     if (selection->isEmpty()) {
972         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone."));
973         return;
974     }
976     // Check if more than one object is selected.
977     if (g_slist_length((GSList *) selection->itemList()) > 1) {
978         sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("If you want to clone several objects, <b>group</b> them and <b>clone the group</b>."));
979         return;
980     }
982     SPObject *obj = SP_OBJECT(selection->singleItem());
983     Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
984     const char *id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
985     SPObject *parent = SP_OBJECT_PARENT (obj);
987     clonetiler_remove (NULL, NULL, false);
989     double d_x_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_x_per_x", 0, -100, 1000);
990     double d_y_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_y_per_x", 0, -100, 1000);
991     double d_per_x_exp = prefs_get_double_attribute_limited (prefs_path, "d_per_x_exp", 1, 0, 10);
992     double d_x_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_x_per_y", 0, -100, 1000);
993     double d_y_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_y_per_y", 0, -100, 1000);
994     double d_per_y_exp = prefs_get_double_attribute_limited (prefs_path, "d_per_y_exp", 1, 0, 10);
995     int alternate_x = prefs_get_int_attribute (prefs_path, "alternate_x", 0);
996     int alternate_y = prefs_get_int_attribute (prefs_path, "alternate_y", 0);
997     double rand_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_x", 0, 0, 1000);
998     double rand_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_y", 0, 0, 1000);
1000     double d_scalex_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scalex_per_x", 0, -100, 1000);
1001     double d_scaley_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scaley_per_x", 0, -100, 1000);
1002     double d_scalex_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scalex_per_y", 0, -100, 1000);
1003     double d_scaley_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scaley_per_y", 0, -100, 1000);
1004     int alternate_scalex = prefs_get_int_attribute (prefs_path, "alternate_scalex", 0);
1005     int alternate_scaley = prefs_get_int_attribute (prefs_path, "alternate_scaley", 0);
1006     double rand_scalex = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_scalex", 0, 0, 1000);
1007     double rand_scaley = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_scaley", 0, 0, 1000);
1009     double d_rot_per_x = prefs_get_double_attribute_limited (prefs_path, "d_rot_per_x", 0, -180, 180);
1010     double d_rot_per_y = prefs_get_double_attribute_limited (prefs_path, "d_rot_per_y", 0, -180, 180);
1011     int alternate_rotx = prefs_get_int_attribute (prefs_path, "alternate_rotx", 0);
1012     int alternate_roty = prefs_get_int_attribute (prefs_path, "alternate_roty", 0);
1013     double rand_rot = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_rot", 0, 0, 100);
1015     double d_blur_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_blur_per_y", 0, 0, 100);
1016     double d_blur_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_blur_per_x", 0, 0, 100);
1017     int alternate_blury = prefs_get_int_attribute (prefs_path, "alternate_blury", 0);
1018     int alternate_blurx = prefs_get_int_attribute (prefs_path, "alternate_blurx", 0);
1019     double rand_blur = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_blur", 0, 0, 100);
1021     double d_opacity_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_opacity_per_y", 0, 0, 100);
1022     double d_opacity_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_opacity_per_x", 0, 0, 100);
1023     int alternate_opacityy = prefs_get_int_attribute (prefs_path, "alternate_opacityy", 0);
1024     int alternate_opacityx = prefs_get_int_attribute (prefs_path, "alternate_opacityx", 0);
1025     double rand_opacity = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_opacity", 0, 0, 100);
1027     const gchar *initial_color = prefs_get_string_attribute (prefs_path, "initial_color");
1028     double d_hue_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_hue_per_y", 0, -100, 100);
1029     double d_hue_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_hue_per_x", 0, -100, 100);
1030     double rand_hue = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_hue", 0, 0, 100);
1031     double d_saturation_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_saturation_per_y", 0, -100, 100);
1032     double d_saturation_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_saturation_per_x", 0, -100, 100);
1033     double rand_saturation = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_saturation", 0, 0, 100);
1034     double d_lightness_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_lightness_per_y", 0, -100, 100);
1035     double d_lightness_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_lightness_per_x", 0, -100, 100);
1036     double rand_lightness = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_lightness", 0, 0, 100);
1037     int alternate_color_y = prefs_get_int_attribute (prefs_path, "alternate_color_y", 0);
1038     int alternate_color_x = prefs_get_int_attribute (prefs_path, "alternate_color_x", 0);
1040     int type = prefs_get_int_attribute (prefs_path, "symmetrygroup", 0);
1042     int keepbbox = prefs_get_int_attribute (prefs_path, "keepbbox", 1);
1044     int xmax = prefs_get_int_attribute (prefs_path, "xmax", 2);
1045     int ymax = prefs_get_int_attribute (prefs_path, "ymax", 2);
1047     int fillrect = prefs_get_int_attribute (prefs_path, "fillrect", 0);
1048     double fillwidth = prefs_get_double_attribute_limited (prefs_path, "fillwidth", 50, 0, 6000);
1049     double fillheight = prefs_get_double_attribute_limited (prefs_path, "fillheight", 50, 0, 6000);
1051     int dotrace = prefs_get_int_attribute (prefs_path, "dotrace", 0);
1052     int pick = prefs_get_int_attribute (prefs_path, "pick", 0);
1053     int pick_to_presence = prefs_get_int_attribute (prefs_path, "pick_to_presence", 0);
1054     int pick_to_size = prefs_get_int_attribute (prefs_path, "pick_to_size", 0);
1055     int pick_to_color = prefs_get_int_attribute (prefs_path, "pick_to_color", 0);
1056     int pick_to_opacity = prefs_get_int_attribute (prefs_path, "pick_to_opacity", 0);
1057     double rand_picked = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_picked", 0, 0, 100);
1058     int invert_picked = prefs_get_int_attribute (prefs_path, "invert_picked", 0);
1059     double gamma_picked = prefs_get_double_attribute_limited (prefs_path, "gamma_picked", 0, -10, 10);
1061     if (dotrace) {
1062         clonetiler_trace_setup (sp_desktop_document(desktop), 1.0, SP_ITEM (obj));
1063     }
1065     NR::Point c;
1066     double w;
1067     double h;
1069     if (keepbbox &&
1070         obj_repr->attribute("inkscape:tile-w") &&
1071         obj_repr->attribute("inkscape:tile-h") &&
1072         obj_repr->attribute("inkscape:tile-cx") &&
1073         obj_repr->attribute("inkscape:tile-cy")) {
1075         double cx = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cx", 0);
1076         double cy = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cy", 0);
1078         c = NR::Point (cx, cy);
1080         w = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-w", 0);
1081         h = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-h", 0);
1082     } else {
1083         NR::Rect const r = SP_ITEM(obj)->invokeBbox(sp_item_i2doc_affine(SP_ITEM(obj)));
1084         c = r.midpoint();
1085         w = r.dimensions()[NR::X];
1086         h = r.dimensions()[NR::Y];
1088         sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
1089         sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
1090         sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", c[NR::X]);
1091         sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", c[NR::Y]);
1092     }
1094     NR::Point cur = NR::Point (0, 0);
1095     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));
1096     double perimeter_original = (w + h)/4;
1098     for (int x = 0;
1099          fillrect?
1100              (fabs(cur[NR::X]) < fillwidth && x < 200) // prevent "freezing" with too large fillrect, arbitrarily limit rows
1101              : (x < xmax);
1102          x ++) {
1103         for (int y = 0;
1104              fillrect?
1105                  (fabs(cur[NR::Y]) < fillheight && y < 200) // prevent "freezing" with too large fillrect, arbitrarily limit cols
1106                  : (y < ymax);
1107              y ++) {
1109             // Note: We create a clone at 0,0 too, right over the original, in case our clones are colored
1111             // Get transform from symmetry, shift, scale, rotation
1112             NR::Matrix t = clonetiler_get_transform (type, x, y, c[NR::X], c[NR::Y], w, h,
1113                                                      d_x_per_x, d_y_per_x, d_x_per_y, d_y_per_y, alternate_x, alternate_y, rand_x, rand_y,
1114                                                      d_per_x_exp, d_per_y_exp,
1115                                                      d_rot_per_x, d_rot_per_y, alternate_rotx, alternate_roty, rand_rot,
1116                                                      d_scalex_per_x, d_scaley_per_x, d_scalex_per_y, d_scaley_per_y,
1117                                                      alternate_scalex, alternate_scaley, rand_scalex, rand_scaley);
1119             cur = c * t - c;
1120             if (fillrect) {
1121                 if ((cur[NR::X] > fillwidth) || (cur[NR::Y] > fillheight)) { // off limits
1122                     continue;
1123                 }
1124             }
1126             gchar color_string[32]; *color_string = 0;
1128             // Color tab
1129             if (initial_color) {
1130                 guint32 rgba = sp_svg_read_color (initial_color, 0x000000ff);
1131                 float hsl[3];
1132                 sp_color_rgb_to_hsl_floatv (hsl, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba));
1134                 double eff_x = (alternate_color_x? (x%2) : (x));
1135                 double eff_y = (alternate_color_y? (y%2) : (y));
1137                 hsl[0] += d_hue_per_x * eff_x + d_hue_per_y * eff_y + rand_hue * g_random_double_range (-1, 1);
1138                 if (hsl[0] < 0) hsl[0] += 1;
1139                 if (hsl[0] > 1) hsl[0] -= 1;
1140                 hsl[1] += d_saturation_per_x * eff_x + d_saturation_per_y * eff_y + rand_saturation * g_random_double_range (-1, 1);
1141                 hsl[1] = CLAMP (hsl[1], 0, 1);
1142                 hsl[2] += d_lightness_per_x * eff_x + d_lightness_per_y * eff_y + rand_lightness * g_random_double_range (-1, 1);
1143                 hsl[2] = CLAMP (hsl[2], 0, 1);
1145                 float rgb[3];
1146                 sp_color_hsl_to_rgb_floatv (rgb, hsl[0], hsl[1], hsl[2]);
1147                 sp_svg_write_color(color_string, 32, SP_RGBA32_F_COMPOSE(rgb[0], rgb[1], rgb[2], 1.0));
1148             }
1150             // Blur
1151             double blur = 0.0;
1152             {
1153             int eff_x = (alternate_blurx? (x%2) : (x));
1154             int eff_y = (alternate_blury? (y%2) : (y));
1155             blur =  (d_blur_per_x * eff_x + d_blur_per_y * eff_y + rand_blur * g_random_double_range (-1, 1));
1156             blur = CLAMP (blur, 0, 1);
1157             }
1159             // Opacity
1160             double opacity = 1.0;
1161             {
1162             int eff_x = (alternate_opacityx? (x%2) : (x));
1163             int eff_y = (alternate_opacityy? (y%2) : (y));
1164             opacity = 1 - (d_opacity_per_x * eff_x + d_opacity_per_y * eff_y + rand_opacity * g_random_double_range (-1, 1));
1165             opacity = CLAMP (opacity, 0, 1);
1166             }
1168             // Trace tab
1169             if (dotrace) {
1170                 NR::Rect bbox_t = transform_rect (bbox_original, t);
1172                 guint32 rgba = clonetiler_trace_pick (bbox_t);
1173                 float r = SP_RGBA32_R_F(rgba);
1174                 float g = SP_RGBA32_G_F(rgba);
1175                 float b = SP_RGBA32_B_F(rgba);
1176                 float a = SP_RGBA32_A_F(rgba);
1178                 float hsl[3];
1179                 sp_color_rgb_to_hsl_floatv (hsl, r, g, b);
1181                 gdouble val = 0;
1182                 switch (pick) {
1183                 case PICK_COLOR:
1184                     val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max
1185                     break;
1186                 case PICK_OPACITY:
1187                     val = a;
1188                     break;
1189                 case PICK_R:
1190                     val = r;
1191                     break;
1192                 case PICK_G:
1193                     val = g;
1194                     break;
1195                 case PICK_B:
1196                     val = b;
1197                     break;
1198                 case PICK_H:
1199                     val = hsl[0];
1200                     break;
1201                 case PICK_S:
1202                     val = hsl[1];
1203                     break;
1204                 case PICK_L:
1205                     val = 1 - hsl[2];
1206                     break;
1207                 default:
1208                     break;
1209                 }
1211                 if (rand_picked > 0) {
1212                     val = randomize01 (val, rand_picked);
1213                     r = randomize01 (r, rand_picked);
1214                     g = randomize01 (g, rand_picked);
1215                     b = randomize01 (b, rand_picked);
1216                 }
1218                 if (gamma_picked != 0) {
1219                     double power;
1220                     if (gamma_picked < 0)
1221                         power = 1/(1 + fabs(gamma_picked));
1222                     else
1223                         power = 1 + gamma_picked;
1225                     val = pow (val, power);
1226                     r = pow (r, power);
1227                     g = pow (g, power);
1228                     b = pow (b, power);
1229                 }
1231                 if (invert_picked) {
1232                     val = 1 - val;
1233                     r = 1 - r;
1234                     g = 1 - g;
1235                     b = 1 - b;
1236                 }
1238                 val = CLAMP (val, 0, 1);
1239                 r = CLAMP (r, 0, 1);
1240                 g = CLAMP (g, 0, 1);
1241                 b = CLAMP (b, 0, 1);
1243                 // recompose tweaked color
1244                 rgba = SP_RGBA32_F_COMPOSE(r, g, b, a);
1246                 if (pick_to_presence) {
1247                     if (g_random_double_range (0, 1) > val) {
1248                         continue; // skip!
1249                     }
1250                 }
1251                 if (pick_to_size) {
1252                     t = NR::translate(-c[NR::X], -c[NR::Y]) * NR::scale (val, val) * NR::translate(c[NR::X], c[NR::Y]) * t;
1253                 }
1254                 if (pick_to_opacity) {
1255                     opacity *= val;
1256                 }
1257                 if (pick_to_color) {
1258                     sp_svg_write_color(color_string, 32, rgba);
1259                 }
1260             }
1262             if (opacity < 1e-6) { // invisibly transparent, skip
1263                     continue;
1264             }
1266             if (fabs(t[0]) + fabs (t[1]) + fabs(t[2]) + fabs(t[3]) < 1e-6) { // too small, skip
1267                     continue;
1268             }
1270             // Create the clone
1271             Inkscape::XML::Node *clone = obj_repr->document()->createElement("svg:use");
1272             clone->setAttribute("x", "0");
1273             clone->setAttribute("y", "0");
1274             clone->setAttribute("inkscape:tiled-clone-of", id_href);
1275             clone->setAttribute("xlink:href", id_href);
1277             NR::Point new_center;
1278             bool center_set = false;
1279             if (obj_repr->attribute("inkscape:transform-center-x") || obj_repr->attribute("inkscape:transform-center-y")) {
1280                 new_center = desktop->dt2doc(SP_ITEM(obj)->getCenter()) * t;
1281                 center_set = true;
1282             }
1284             gchar affinestr[80];
1285             if (sp_svg_transform_write(affinestr, 79, t)) {
1286                 clone->setAttribute("transform", affinestr);
1287             } else {
1288                 clone->setAttribute("transform", NULL);
1289             }
1291             if (opacity < 1.0) {
1292                 sp_repr_set_css_double(clone, "opacity", opacity);
1293             }
1295             if (*color_string) {
1296                 clone->setAttribute("fill", color_string);
1297                 clone->setAttribute("stroke", color_string);
1298             }
1300             // add the new clone to the top of the original's parent
1301             SP_OBJECT_REPR(parent)->appendChild(clone);
1303             if (blur > 0.0) {
1304                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1305                 double perimeter = perimeter_original * t.expansion();
1306                 double radius = blur * perimeter;
1307                 // it's hard to figure out exact width/height of the tile without having an object
1308                 // that we can take bbox of; however here we only need a lower bound so that blur
1309                 // margins are not too small, and the perimeter should work
1310                 SPFilter *constructed = new_filter_gaussian_blur(sp_desktop_document(desktop), radius, t.expansion(), t.expansionX(), t.expansionY(), perimeter, perimeter);
1311                 sp_style_set_property_url (clone_object, "filter", SP_OBJECT(constructed), false);
1312             }
1314             if (center_set) {
1315                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1316                 if (clone_object && SP_IS_ITEM(clone_object)) {
1317                     clone_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1318                     SP_ITEM(clone_object)->setCenter(desktop->doc2dt(new_center));
1319                     clone_object->updateRepr();
1320                 }
1321             }
1323             Inkscape::GC::release(clone);
1324         }
1325         cur[NR::Y] = 0;
1326     }
1328     if (dotrace) {
1329         clonetiler_trace_finish ();
1330     }
1332     clonetiler_change_selection (NULL, selection, dlg);
1334     sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER, 
1335                      _("Create tiled clones"));
1338 static GtkWidget *
1339 clonetiler_new_tab (GtkWidget *nb, const gchar *label)
1341     GtkWidget *l = gtk_label_new_with_mnemonic (label);
1342     GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN);
1343     gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN);
1344     gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l);
1345     return vb;
1348 static void
1349 clonetiler_checkbox_toggled (GtkToggleButton *tb, gpointer *data)
1351     const gchar *attr = (const gchar *) data;
1352     prefs_set_int_attribute (prefs_path, attr, gtk_toggle_button_get_active (tb));
1355 static GtkWidget *
1356 clonetiler_checkbox (GtkTooltips *tt, const char *tip, const char *attr)
1358     GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
1360     GtkWidget *b = gtk_check_button_new ();
1361     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, tip, NULL);
1363     int value = prefs_get_int_attribute (prefs_path, attr, 0);
1364     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(b), value);
1366     gtk_box_pack_end (GTK_BOX (hb), b, FALSE, TRUE, 0);
1367     gtk_signal_connect ( GTK_OBJECT (b), "clicked",
1368                          GTK_SIGNAL_FUNC (clonetiler_checkbox_toggled), (gpointer) attr);
1370     g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
1372     return hb;
1376 static void
1377 clonetiler_value_changed (GtkAdjustment *adj, gpointer data)
1379     const gchar *pref = (const gchar *) data;
1380     prefs_set_double_attribute (prefs_path, pref, adj->value);
1383 static GtkWidget *
1384 clonetiler_spinbox (GtkTooltips *tt, const char *tip, const char *attr, double lower, double upper, const gchar *suffix, bool exponent = false)
1386     GtkWidget *hb = gtk_hbox_new(FALSE, 0);
1388     {
1389         GtkObject *a;
1390         if (exponent)
1391             a = gtk_adjustment_new(1.0, lower, upper, 0.01, 0.05, 0.1);
1392         else
1393             a = gtk_adjustment_new(0.0, lower, upper, 0.1, 0.5, 2);
1395         GtkWidget *sb;
1396         if (exponent)
1397             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.01, 2);
1398         else
1399             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.1, 1);
1401         gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, tip, NULL);
1402         gtk_entry_set_width_chars (GTK_ENTRY (sb), 4);
1403         gtk_box_pack_start (GTK_BOX (hb), sb, FALSE, FALSE, SB_MARGIN);
1405         double value = prefs_get_double_attribute_limited (prefs_path, attr, exponent? 1 : 0, lower, upper);
1406         gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
1407         gtk_signal_connect(GTK_OBJECT(a), "value_changed",
1408                            GTK_SIGNAL_FUNC(clonetiler_value_changed), (gpointer) attr);
1410         if (exponent)
1411             g_object_set_data (G_OBJECT(sb), "oneable", GINT_TO_POINTER(TRUE));
1412         else
1413             g_object_set_data (G_OBJECT(sb), "zeroable", GINT_TO_POINTER(TRUE));
1414     }
1416     {
1417         GtkWidget *l = gtk_label_new ("");
1418         gtk_label_set_markup (GTK_LABEL(l), suffix);
1419         gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0);
1420         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
1421     }
1423     return hb;
1426 static void
1427 clonetiler_symgroup_changed (GtkMenuItem *item, gpointer data)
1429     gint group_new = GPOINTER_TO_INT (data);
1430     prefs_set_int_attribute ( prefs_path, "symmetrygroup", group_new );
1433 static void
1434 clonetiler_xy_changed (GtkAdjustment *adj, gpointer data)
1436     const gchar *pref = (const gchar *) data;
1437     prefs_set_int_attribute (prefs_path, pref, (int) floor(adj->value + 0.5));
1440 static void
1441 clonetiler_keep_bbox_toggled (GtkToggleButton *tb, gpointer data)
1443     prefs_set_int_attribute (prefs_path, "keepbbox", gtk_toggle_button_get_active (tb));
1446 static void
1447 clonetiler_pick_to (GtkToggleButton *tb, gpointer data)
1449     const gchar *pref = (const gchar *) data;
1450     prefs_set_int_attribute (prefs_path, pref, gtk_toggle_button_get_active (tb));
1454 static void
1455 clonetiler_reset_recursive (GtkWidget *w)
1457     if (w && GTK_IS_OBJECT(w)) {
1458         {
1459             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "zeroable"));
1460             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1461                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1462                 gtk_adjustment_set_value (a, 0);
1463             }
1464         }
1465         {
1466             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "oneable"));
1467             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1468                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1469                 gtk_adjustment_set_value (a, 1);
1470             }
1471         }
1472         {
1473             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "uncheckable"));
1474             if (r && GTK_IS_TOGGLE_BUTTON(w)) { // checkbox
1475                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(w), FALSE);
1476             }
1477         }
1478     }
1480     if (GTK_IS_CONTAINER(w)) {
1481         GList *ch = gtk_container_get_children (GTK_CONTAINER(w));
1482         for (GList *i = ch; i != NULL; i = i->next) {
1483             clonetiler_reset_recursive (GTK_WIDGET(i->data));
1484         }
1485         g_list_free (ch);
1486     }
1489 static void
1490 clonetiler_reset (GtkWidget *widget, void *)
1492     clonetiler_reset_recursive (dlg);
1495 static void
1496 clonetiler_table_attach (GtkWidget *table, GtkWidget *widget, float align, int row, int col)
1498     GtkWidget *a = gtk_alignment_new (align, 0, 0, 0);
1499     gtk_container_add(GTK_CONTAINER(a), widget);
1500     gtk_table_attach ( GTK_TABLE (table), a, col, col + 1, row, row + 1, (GtkAttachOptions)4, (GtkAttachOptions)0, 0, 0 );
1503 static GtkWidget *
1504 clonetiler_table_x_y_rand (int values)
1506     GtkWidget *table = gtk_table_new (values + 2, 5, FALSE);
1507     gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
1508     gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1509     gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1511     {
1512         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1514         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "clonetiler_per_row");
1515         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1517         GtkWidget *l = gtk_label_new ("");
1518         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per row:</small>"));
1519         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1521         clonetiler_table_attach (table, hb, 0, 1, 2);
1522     }
1524     {
1525         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1527         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "clonetiler_per_column");
1528         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1530         GtkWidget *l = gtk_label_new ("");
1531         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per column:</small>"));
1532         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1534         clonetiler_table_attach (table, hb, 0, 1, 3);
1535     }
1537     {
1538         GtkWidget *l = gtk_label_new ("");
1539         gtk_label_set_markup (GTK_LABEL(l), _("<small>Randomize:</small>"));
1540         clonetiler_table_attach (table, l, 0, 1, 4);
1541     }
1543     return table;
1546 static void
1547 clonetiler_pick_switched (GtkToggleButton *tb, gpointer data)
1549     guint v = GPOINTER_TO_INT (data);
1550     prefs_set_int_attribute (prefs_path, "pick", v);
1554 static void
1555 clonetiler_switch_to_create (GtkToggleButton *tb, GtkWidget *dlg)
1557     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1558     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1560     if (rowscols) {
1561         gtk_widget_set_sensitive (rowscols, TRUE);
1562     }
1563     if (widthheight) {
1564         gtk_widget_set_sensitive (widthheight, FALSE);
1565     }
1567     prefs_set_int_attribute (prefs_path, "fillrect", 0);
1571 static void
1572 clonetiler_switch_to_fill (GtkToggleButton *tb, GtkWidget *dlg)
1574     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1575     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1577     if (rowscols) {
1578         gtk_widget_set_sensitive (rowscols, FALSE);
1579     }
1580     if (widthheight) {
1581         gtk_widget_set_sensitive (widthheight, TRUE);
1582     }
1584     prefs_set_int_attribute (prefs_path, "fillrect", 1);
1590 static void
1591 clonetiler_fill_width_changed (GtkAdjustment *adj, GtkWidget *u)
1593     gdouble const raw_dist = adj->value;
1594     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1595     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1597     prefs_set_double_attribute (prefs_path, "fillwidth", pixels);
1600 static void
1601 clonetiler_fill_height_changed (GtkAdjustment *adj, GtkWidget *u)
1603     gdouble const raw_dist = adj->value;
1604     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1605     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1607     prefs_set_double_attribute (prefs_path, "fillheight", pixels);
1611 static void
1612 clonetiler_do_pick_toggled (GtkToggleButton *tb, gpointer data)
1614     GtkWidget *vvb = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "dotrace");
1616     prefs_set_int_attribute (prefs_path, "dotrace", gtk_toggle_button_get_active (tb));
1618     if (vvb)
1619         gtk_widget_set_sensitive (vvb, gtk_toggle_button_get_active (tb));
1625 void
1626 clonetiler_dialog (void)
1628     if (!dlg)
1629     {
1630         gchar title[500];
1631         sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_CLONETILER), title);
1633         dlg = sp_window_new (title, TRUE);
1634         if (x == -1000 || y == -1000) {
1635             x = prefs_get_int_attribute (prefs_path, "x", -1000);
1636             y = prefs_get_int_attribute (prefs_path, "y", -1000);
1637         }
1638         
1639         if (w ==0 || h == 0) {
1640             w = prefs_get_int_attribute (prefs_path, "w", 0);
1641             h = prefs_get_int_attribute (prefs_path, "h", 0);
1642         }
1643         
1644 //        if (x<0) x=0;
1645 //        if (y<0) y=0;
1647         if (w && h) {
1648             gtk_window_resize ((GtkWindow *) dlg, w, h);
1649         }
1650         if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) {
1651             gtk_window_move ((GtkWindow *) dlg, x, y);
1652         
1653         } else {
1654             gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
1655         }
1656         
1657         
1658         sp_transientize (dlg);
1659         wd.win = dlg;
1660         wd.stop = 0;
1661         
1662                              
1663         gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);
1664         
1665         gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (clonetiler_dialog_destroy), dlg);
1666         gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (clonetiler_dialog_delete), dlg);
1668         if (Inkscape::NSApplication::Application::getNewGui())
1669         {
1670             _shutdown_connection = Inkscape::NSApplication::Editor::connectShutdown (&on_delete);
1671             _dialogs_hidden_connection = Inkscape::NSApplication::Editor::connectDialogsHidden (sigc::bind (&on_dialog_hide, dlg));
1672             _dialogs_unhidden_connection = Inkscape::NSApplication::Editor::connectDialogsUnhidden (sigc::bind (&on_dialog_unhide, dlg));
1673             _desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::bind (&on_transientize, &wd));
1674         } else {            
1675             g_signal_connect   ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (clonetiler_dialog_delete), dlg);
1676             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg);
1677             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg);
1678             g_signal_connect   ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd);
1679         }
1681         GtkTooltips *tt = gtk_tooltips_new();
1683         GtkWidget *mainbox = gtk_vbox_new(FALSE, 4);
1684         gtk_container_set_border_width (GTK_CONTAINER (mainbox), 6);
1685         gtk_container_add (GTK_CONTAINER (dlg), mainbox);
1687         GtkWidget *nb = gtk_notebook_new ();
1688         gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0);
1691 // Symmetry
1692         {
1693             GtkWidget *vb = clonetiler_new_tab (nb, _("_Symmetry"));
1695             GtkWidget *om = gtk_option_menu_new ();
1696             /* TRANSLATORS: For the following 17 symmetry groups, see
1697              * http://www.bib.ulb.ac.be/coursmath/doc/17.htm (visual examples);
1698              * http://www.clarku.edu/~djoyce/wallpaper/seventeen.html (English vocabulary); or
1699              * http://membres.lycos.fr/villemingerard/Geometri/Sym1D.htm (French vocabulary).
1700              */
1701             gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), om, _("Select one of the 17 symmetry groups for the tiling"), NULL);
1702             gtk_box_pack_start (GTK_BOX (vb), om, FALSE, FALSE, SB_MARGIN);
1704             GtkWidget *m = gtk_menu_new ();
1705             int current = prefs_get_int_attribute (prefs_path, "symmetrygroup", 0);
1707             struct SymGroups {
1708                 int group;
1709                 gchar const *label;
1710             } const sym_groups[] = {
1711                 // TRANSLATORS: "translation" means "shift" / "displacement" here.
1712                 {TILE_P1, _("<b>P1</b>: simple translation")},
1713                 {TILE_P2, _("<b>P2</b>: 180&#176; rotation")},
1714                 {TILE_PM, _("<b>PM</b>: reflection")},
1715                 // TRANSLATORS: "glide reflection" is a reflection and a translation combined.
1716                 //  For more info, see http://mathforum.org/sum95/suzanne/symsusan.html
1717                 {TILE_PG, _("<b>PG</b>: glide reflection")},
1718                 {TILE_CM, _("<b>CM</b>: reflection + glide reflection")},
1719                 {TILE_PMM, _("<b>PMM</b>: reflection + reflection")},
1720                 {TILE_PMG, _("<b>PMG</b>: reflection + 180&#176; rotation")},
1721                 {TILE_PGG, _("<b>PGG</b>: glide reflection + 180&#176; rotation")},
1722                 {TILE_CMM, _("<b>CMM</b>: reflection + reflection + 180&#176; rotation")},
1723                 {TILE_P4, _("<b>P4</b>: 90&#176; rotation")},
1724                 {TILE_P4M, _("<b>P4M</b>: 90&#176; rotation + 45&#176; reflection")},
1725                 {TILE_P4G, _("<b>P4G</b>: 90&#176; rotation + 90&#176; reflection")},
1726                 {TILE_P3, _("<b>P3</b>: 120&#176; rotation")},
1727                 {TILE_P31M, _("<b>P31M</b>: reflection + 120&#176; rotation, dense")},
1728                 {TILE_P3M1, _("<b>P3M1</b>: reflection + 120&#176; rotation, sparse")},
1729                 {TILE_P6, _("<b>P6</b>: 60&#176; rotation")},
1730                 {TILE_P6M, _("<b>P6M</b>: reflection + 60&#176; rotation")},
1731             };
1733             for (unsigned j = 0; j < G_N_ELEMENTS(sym_groups); ++j) {
1734                 SymGroups const &sg = sym_groups[j];
1736                 GtkWidget *l = gtk_label_new ("");
1737                 gtk_label_set_markup (GTK_LABEL(l), sg.label);
1738                 gtk_misc_set_alignment (GTK_MISC(l), 0, 0.5);
1740                 GtkWidget *item = gtk_menu_item_new ();
1741                 gtk_container_add (GTK_CONTAINER (item), l);
1743                 gtk_signal_connect ( GTK_OBJECT (item), "activate",
1744                                      GTK_SIGNAL_FUNC (clonetiler_symgroup_changed),
1745                                      GINT_TO_POINTER (sg.group) );
1747                 gtk_menu_append (GTK_MENU (m), item);
1748             }
1750             gtk_option_menu_set_menu (GTK_OPTION_MENU (om), m);
1751             gtk_option_menu_set_history ( GTK_OPTION_MENU (om), current);
1752         }
1754         table_row_labels = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1756 // Shift
1757         {
1758             GtkWidget *vb = clonetiler_new_tab (nb, _("S_hift"));
1760             GtkWidget *table = clonetiler_table_x_y_rand (3);
1761             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1763             // X
1764             {
1765                 GtkWidget *l = gtk_label_new ("");
1766                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) horizontally by this amount
1767                     // xgettext:no-c-format
1768                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift X:</b>"));
1769                 gtk_size_group_add_widget(table_row_labels, l);
1770                 clonetiler_table_attach (table, l, 1, 2, 1);
1771             }
1773             {
1774                 GtkWidget *l = clonetiler_spinbox (tt,
1775                     // xgettext:no-c-format
1776                                                    _("Horizontal shift per row (in % of tile width)"), "d_x_per_y",
1777                                                    -100, 1000, "%");
1778                 clonetiler_table_attach (table, l, 0, 2, 2);
1779             }
1781             {
1782                 GtkWidget *l = clonetiler_spinbox (tt,
1783                     // xgettext:no-c-format
1784                                                    _("Horizontal shift per column (in % of tile width)"), "d_x_per_x",
1785                                                    -100, 1000, "%");
1786                 clonetiler_table_attach (table, l, 0, 2, 3);
1787             }
1789             {
1790                 GtkWidget *l = clonetiler_spinbox (tt,
1791                                                    _("Randomize the horizontal shift by this percentage"), "rand_x",
1792                                                    0, 1000, "%");
1793                 clonetiler_table_attach (table, l, 0, 2, 4);
1794             }
1796             // Y
1797             {
1798                 GtkWidget *l = gtk_label_new ("");
1799                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) vertically by this amount
1800                     // xgettext:no-c-format
1801                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift Y:</b>"));
1802                 gtk_size_group_add_widget(table_row_labels, l);
1803                 clonetiler_table_attach (table, l, 1, 3, 1);
1804             }
1806             {
1807                 GtkWidget *l = clonetiler_spinbox (tt,
1808                     // xgettext:no-c-format
1809                                                    _("Vertical shift per row (in % of tile height)"), "d_y_per_y",
1810                                                    -100, 1000, "%");
1811                 clonetiler_table_attach (table, l, 0, 3, 2);
1812             }
1814             {
1815                 GtkWidget *l = clonetiler_spinbox (tt,
1816                     // xgettext:no-c-format
1817                                                    _("Vertical shift per column (in % of tile height)"), "d_y_per_x",
1818                                                    -100, 1000, "%");
1819                 clonetiler_table_attach (table, l, 0, 3, 3);
1820             }
1822             {
1823                 GtkWidget *l = clonetiler_spinbox (tt,
1824                                                    _("Randomize the vertical shift by this percentage"), "rand_y",
1825                                                    0, 1000, "%");
1826                 clonetiler_table_attach (table, l, 0, 3, 4);
1827             }
1829             // Exponent
1830             {
1831                 GtkWidget *l = gtk_label_new ("");
1832                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
1833                 gtk_size_group_add_widget(table_row_labels, l);
1834                 clonetiler_table_attach (table, l, 1, 4, 1);
1835             }
1837             {
1838                 GtkWidget *l = clonetiler_spinbox (tt,
1839                                                    _("Whether rows are spaced evenly (1), converge (<1) or diverge (>1)"), "d_per_y_exp",
1840                                                    0, 10, "", true);
1841                 clonetiler_table_attach (table, l, 0, 4, 2);
1842             }
1844             {
1845                 GtkWidget *l = clonetiler_spinbox (tt,
1846                                                    _("Whether columns are spaced evenly (1), converge (<1) or diverge (>1)"), "d_per_x_exp",
1847                                                    0, 10, "", true);
1848                 clonetiler_table_attach (table, l, 0, 4, 3);
1849             }
1851             { // alternates
1852                 GtkWidget *l = gtk_label_new ("");
1853                 // TRANSLATORS: "Alternate" is a verb here
1854                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
1855                 gtk_size_group_add_widget(table_row_labels, l);
1856                 clonetiler_table_attach (table, l, 1, 5, 1);
1857             }
1859             {
1860                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each row"), "alternate_y");
1861                 clonetiler_table_attach (table, l, 0, 5, 2);
1862             }
1864             {
1865                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each column"), "alternate_x");
1866                 clonetiler_table_attach (table, l, 0, 5, 3);
1867             }
1869         }
1872 // Scale
1873         {
1874             GtkWidget *vb = clonetiler_new_tab (nb, _("Sc_ale"));
1876             GtkWidget *table = clonetiler_table_x_y_rand (2);
1877             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1879             // X
1880             {
1881                 GtkWidget *l = gtk_label_new ("");
1882                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale X:</b>"));
1883                 gtk_size_group_add_widget(table_row_labels, l);
1884                 clonetiler_table_attach (table, l, 1, 2, 1);
1885             }
1887             {
1888                 GtkWidget *l = clonetiler_spinbox (tt,
1889                     // xgettext:no-c-format
1890                                                    _("Horizontal scale per row (in % of tile width)"), "d_scalex_per_y",
1891                                                    -100, 1000, "%");
1892                 clonetiler_table_attach (table, l, 0, 2, 2);
1893             }
1895             {
1896                 GtkWidget *l = clonetiler_spinbox (tt,
1897                     // xgettext:no-c-format
1898                                                    _("Horizontal scale per column (in % of tile width)"), "d_scalex_per_x",
1899                                                    -100, 1000, "%");
1900                 clonetiler_table_attach (table, l, 0, 2, 3);
1901             }
1903             {
1904                 GtkWidget *l = clonetiler_spinbox (tt,
1905                                                    _("Randomize the horizontal scale by this percentage"), "rand_scalex",
1906                                                    0, 1000, "%");
1907                 clonetiler_table_attach (table, l, 0, 2, 4);
1908             }
1910             // Y
1911             {
1912                 GtkWidget *l = gtk_label_new ("");
1913                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale Y:</b>"));
1914                 gtk_size_group_add_widget(table_row_labels, l);
1915                 clonetiler_table_attach (table, l, 1, 3, 1);
1916             }
1918             {
1919                 GtkWidget *l = clonetiler_spinbox (tt,
1920                     // xgettext:no-c-format
1921                                                    _("Vertical scale per row (in % of tile height)"), "d_scaley_per_y",
1922                                                    -100, 1000, "%");
1923                 clonetiler_table_attach (table, l, 0, 3, 2);
1924             }
1926             {
1927                 GtkWidget *l = clonetiler_spinbox (tt,
1928                     // xgettext:no-c-format
1929                                                    _("Vertical scale per column (in % of tile height)"), "d_scaley_per_x",
1930                                                    -100, 1000, "%");
1931                 clonetiler_table_attach (table, l, 0, 3, 3);
1932             }
1934             {
1935                 GtkWidget *l = clonetiler_spinbox (tt,
1936                                                    _("Randomize the vertical scale by this percentage"), "rand_scaley",
1937                                                    0, 1000, "%");
1938                 clonetiler_table_attach (table, l, 0, 3, 4);
1939             }
1941             { // alternates
1942                 GtkWidget *l = gtk_label_new ("");
1943                 // TRANSLATORS: "Alternate" is a verb here
1944                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
1945                 gtk_size_group_add_widget(table_row_labels, l);
1946                 clonetiler_table_attach (table, l, 1, 4, 1);
1947             }
1949             {
1950                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each row"), "alternate_scaley");
1951                 clonetiler_table_attach (table, l, 0, 4, 2);
1952             }
1954             {
1955                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each column"), "alternate_scalex");
1956                 clonetiler_table_attach (table, l, 0, 4, 3);
1957             }
1959         }
1962 // Rotation
1963         {
1964             GtkWidget *vb = clonetiler_new_tab (nb, _("_Rotation"));
1966             GtkWidget *table = clonetiler_table_x_y_rand (1);
1967             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1969             // Angle
1970             {
1971                 GtkWidget *l = gtk_label_new ("");
1972                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Angle:</b>"));
1973                 gtk_size_group_add_widget(table_row_labels, l);
1974                 clonetiler_table_attach (table, l, 1, 2, 1);
1975             }
1977             {
1978                 GtkWidget *l = clonetiler_spinbox (tt,
1979                     // xgettext:no-c-format
1980                                                    _("Rotate tiles by this angle for each row"), "d_rot_per_y",
1981                                                    -180, 180, "&#176;");
1982                 clonetiler_table_attach (table, l, 0, 2, 2);
1983             }
1985             {
1986                 GtkWidget *l = clonetiler_spinbox (tt,
1987                     // xgettext:no-c-format
1988                                                    _("Rotate tiles by this angle for each column"), "d_rot_per_x",
1989                                                    -180, 180, "&#176;");
1990                 clonetiler_table_attach (table, l, 0, 2, 3);
1991             }
1993             {
1994                 GtkWidget *l = clonetiler_spinbox (tt,
1995                                                    _("Randomize the rotation angle by this percentage"), "rand_rot",
1996                                                    0, 100, "%");
1997                 clonetiler_table_attach (table, l, 0, 2, 4);
1998             }
2000             { // alternates
2001                 GtkWidget *l = gtk_label_new ("");
2002                 // TRANSLATORS: "Alternate" is a verb here
2003                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2004                 gtk_size_group_add_widget(table_row_labels, l);
2005                 clonetiler_table_attach (table, l, 1, 3, 1);
2006             }
2008             {
2009                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each row"), "alternate_roty");
2010                 clonetiler_table_attach (table, l, 0, 3, 2);
2011             }
2013             {
2014                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each column"), "alternate_rotx");
2015                 clonetiler_table_attach (table, l, 0, 3, 3);
2016             }
2017         }
2020 // Blur and opacity
2021         {
2022             GtkWidget *vb = clonetiler_new_tab (nb, _("_Blur & opacity"));
2024             GtkWidget *table = clonetiler_table_x_y_rand (1);
2025             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2028             // Blur
2029             {
2030                 GtkWidget *l = gtk_label_new ("");
2031                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Blur:</b>"));
2032                 gtk_size_group_add_widget(table_row_labels, l);
2033                 clonetiler_table_attach (table, l, 1, 2, 1);
2034             }
2036             {
2037                 GtkWidget *l = clonetiler_spinbox (tt,
2038                                                    _("Blur tiles by this percentage for each row"), "d_blur_per_y",
2039                                                    0, 100, "%");
2040                 clonetiler_table_attach (table, l, 0, 2, 2);
2041             }
2043             {
2044                 GtkWidget *l = clonetiler_spinbox (tt,
2045                                                    _("Blur tiles by this percentage for each column"), "d_blur_per_x",
2046                                                    0, 100, "%");
2047                 clonetiler_table_attach (table, l, 0, 2, 3);
2048             }
2050             {
2051                 GtkWidget *l = clonetiler_spinbox (tt,
2052                                                    _("Randomize the tile blur by this percentage"), "rand_blur",
2053                                                    0, 100, "%");
2054                 clonetiler_table_attach (table, l, 0, 2, 4);
2055             }
2057             { // alternates
2058                 GtkWidget *l = gtk_label_new ("");
2059                 // TRANSLATORS: "Alternate" is a verb here
2060                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2061                 gtk_size_group_add_widget(table_row_labels, l);
2062                 clonetiler_table_attach (table, l, 1, 3, 1);
2063             }
2065             {
2066                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each row"), "alternate_blury");
2067                 clonetiler_table_attach (table, l, 0, 3, 2);
2068             }
2070             {
2071                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each column"), "alternate_blurx");
2072                 clonetiler_table_attach (table, l, 0, 3, 3);
2073             }
2077             // Dissolve
2078             {
2079                 GtkWidget *l = gtk_label_new ("");
2080                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Fade out:</b>"));
2081                 gtk_size_group_add_widget(table_row_labels, l);
2082                 clonetiler_table_attach (table, l, 1, 4, 1);
2083             }
2085             {
2086                 GtkWidget *l = clonetiler_spinbox (tt,
2087                                                    _("Decrease tile opacity by this percentage for each row"), "d_opacity_per_y",
2088                                                    0, 100, "%");
2089                 clonetiler_table_attach (table, l, 0, 4, 2);
2090             }
2092             {
2093                 GtkWidget *l = clonetiler_spinbox (tt,
2094                                                    _("Decrease tile opacity by this percentage for each column"), "d_opacity_per_x",
2095                                                    0, 100, "%");
2096                 clonetiler_table_attach (table, l, 0, 4, 3);
2097             }
2099             {
2100                 GtkWidget *l = clonetiler_spinbox (tt,
2101                                                    _("Randomize the tile opacity by this percentage"), "rand_opacity",
2102                                                    0, 100, "%");
2103                 clonetiler_table_attach (table, l, 0, 4, 4);
2104             }
2106             { // alternates
2107                 GtkWidget *l = gtk_label_new ("");
2108                 // TRANSLATORS: "Alternate" is a verb here
2109                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2110                 gtk_size_group_add_widget(table_row_labels, l);
2111                 clonetiler_table_attach (table, l, 1, 5, 1);
2112             }
2114             {
2115                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each row"), "alternate_opacityy");
2116                 clonetiler_table_attach (table, l, 0, 5, 2);
2117             }
2119             {
2120                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each column"), "alternate_opacityx");
2121                 clonetiler_table_attach (table, l, 0, 5, 3);
2122             }
2123         }
2126 // Color
2127         {
2128             GtkWidget *vb = clonetiler_new_tab (nb, _("Co_lor"));
2130             {
2131             GtkWidget *hb = gtk_hbox_new (FALSE, 0);
2133             GtkWidget *l = gtk_label_new (_("Initial color: "));
2134             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2136             guint32 rgba = 0x000000ff | sp_svg_read_color (prefs_get_string_attribute(prefs_path, "initial_color"), 0x000000ff);
2137             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);
2138             _color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed));
2140             gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast<GtkWidget*>(color_picker->gobj()), FALSE, FALSE, 0);
2142             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2143             }
2146             GtkWidget *table = clonetiler_table_x_y_rand (3);
2147             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2149             // Hue
2150             {
2151                 GtkWidget *l = gtk_label_new ("");
2152                 gtk_label_set_markup (GTK_LABEL(l), _("<b>H:</b>"));
2153                 gtk_size_group_add_widget(table_row_labels, l);
2154                 clonetiler_table_attach (table, l, 1, 2, 1);
2155             }
2157             {
2158                 GtkWidget *l = clonetiler_spinbox (tt,
2159                                                    _("Change the tile hue by this percentage for each row"), "d_hue_per_y",
2160                                                    -100, 100, "%");
2161                 clonetiler_table_attach (table, l, 0, 2, 2);
2162             }
2164             {
2165                 GtkWidget *l = clonetiler_spinbox (tt,
2166                                                    _("Change the tile hue by this percentage for each column"), "d_hue_per_x",
2167                                                    -100, 100, "%");
2168                 clonetiler_table_attach (table, l, 0, 2, 3);
2169             }
2171             {
2172                 GtkWidget *l = clonetiler_spinbox (tt,
2173                                                    _("Randomize the tile hue by this percentage"), "rand_hue",
2174                                                    0, 100, "%");
2175                 clonetiler_table_attach (table, l, 0, 2, 4);
2176             }
2179             // Saturation
2180             {
2181                 GtkWidget *l = gtk_label_new ("");
2182                 gtk_label_set_markup (GTK_LABEL(l), _("<b>S:</b>"));
2183                 gtk_size_group_add_widget(table_row_labels, l);
2184                 clonetiler_table_attach (table, l, 1, 3, 1);
2185             }
2187             {
2188                 GtkWidget *l = clonetiler_spinbox (tt,
2189                                                    _("Change the color saturation by this percentage for each row"), "d_saturation_per_y",
2190                                                    -100, 100, "%");
2191                 clonetiler_table_attach (table, l, 0, 3, 2);
2192             }
2194             {
2195                 GtkWidget *l = clonetiler_spinbox (tt,
2196                                                    _("Change the color saturation by this percentage for each column"), "d_saturation_per_x",
2197                                                    -100, 100, "%");
2198                 clonetiler_table_attach (table, l, 0, 3, 3);
2199             }
2201             {
2202                 GtkWidget *l = clonetiler_spinbox (tt,
2203                                                    _("Randomize the color saturation by this percentage"), "rand_saturation",
2204                                                    0, 100, "%");
2205                 clonetiler_table_attach (table, l, 0, 3, 4);
2206             }
2208             // Lightness
2209             {
2210                 GtkWidget *l = gtk_label_new ("");
2211                 gtk_label_set_markup (GTK_LABEL(l), _("<b>L:</b>"));
2212                 gtk_size_group_add_widget(table_row_labels, l);
2213                 clonetiler_table_attach (table, l, 1, 4, 1);
2214             }
2216             {
2217                 GtkWidget *l = clonetiler_spinbox (tt,
2218                                                    _("Change the color lightness by this percentage for each row"), "d_lightness_per_y",
2219                                                    -100, 100, "%");
2220                 clonetiler_table_attach (table, l, 0, 4, 2);
2221             }
2223             {
2224                 GtkWidget *l = clonetiler_spinbox (tt,
2225                                                    _("Change the color lightness by this percentage for each column"), "d_lightness_per_x",
2226                                                    -100, 100, "%");
2227                 clonetiler_table_attach (table, l, 0, 4, 3);
2228             }
2230             {
2231                 GtkWidget *l = clonetiler_spinbox (tt,
2232                                                    _("Randomize the color lightness by this percentage"), "rand_lightness",
2233                                                    0, 100, "%");
2234                 clonetiler_table_attach (table, l, 0, 4, 4);
2235             }
2238             { // alternates
2239                 GtkWidget *l = gtk_label_new ("");
2240                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2241                 gtk_size_group_add_widget(table_row_labels, l);
2242                 clonetiler_table_attach (table, l, 1, 5, 1);
2243             }
2245             {
2246                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each row"), "alternate_color_y");
2247                 clonetiler_table_attach (table, l, 0, 5, 2);
2248             }
2250             {
2251                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each column"), "alternate_color_x");
2252                 clonetiler_table_attach (table, l, 0, 5, 3);
2253             }
2255         }
2257 // Trace
2258         {
2259             GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace"));
2262         {
2263             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2264             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2266             GtkWidget *b  = gtk_check_button_new_with_label (_("Trace the drawing under the tiles"));
2267             g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
2268             gint old = prefs_get_int_attribute (prefs_path, "dotrace", 0);
2269             gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2270             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);
2271             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2273             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2274                                GTK_SIGNAL_FUNC(clonetiler_do_pick_toggled), dlg);
2275         }
2277         {
2278             GtkWidget *vvb = gtk_vbox_new (FALSE, 0);
2279             gtk_box_pack_start (GTK_BOX (vb), vvb, FALSE, FALSE, 0);
2280             g_object_set_data (G_OBJECT(dlg), "dotrace", (gpointer) vvb);
2283             {
2284                 GtkWidget *frame = gtk_frame_new (_("1. Pick from the drawing:"));
2285                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2287                 GtkWidget *table = gtk_table_new (3, 3, FALSE);
2288                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2289                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2290                 gtk_container_add(GTK_CONTAINER(frame), table);
2293                 GtkWidget* radio;
2294                 {
2295                     radio = gtk_radio_button_new_with_label (NULL, _("Color"));
2296                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the visible color and opacity"), NULL);
2297                     clonetiler_table_attach (table, radio, 0.0, 1, 1);
2298                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2299                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_COLOR));
2300                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_COLOR);
2301                 }
2302                 {
2303                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Opacity"));
2304                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the total accumulated opacity"), NULL);
2305                     clonetiler_table_attach (table, radio, 0.0, 2, 1);
2306                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2307                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_OPACITY));
2308                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_OPACITY);
2309                 }
2310                 {
2311                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("R"));
2312                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Red component of the color"), NULL);
2313                     clonetiler_table_attach (table, radio, 0.0, 1, 2);
2314                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2315                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_R));
2316                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_R);
2317                 }
2318                 {
2319                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("G"));
2320                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Green component of the color"), NULL);
2321                     clonetiler_table_attach (table, radio, 0.0, 2, 2);
2322                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2323                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_G));
2324                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_G);
2325                 }
2326                 {
2327                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("B"));
2328                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Blue component of the color"), NULL);
2329                     clonetiler_table_attach (table, radio, 0.0, 3, 2);
2330                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2331                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_B));
2332                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_B);
2333                 }
2334                 {
2335                     //TRANSLATORS: only translate "string" in "context|string". 
2336                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2337                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|H"));
2338                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the hue of the color"), NULL);
2339                     clonetiler_table_attach (table, radio, 0.0, 1, 3);
2340                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2341                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_H));
2342                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_H);
2343                 }
2344                 {
2345                     //TRANSLATORS: only translate "string" in "context|string". 
2346                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2347                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|S"));
2348                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the saturation of the color"), NULL);
2349                     clonetiler_table_attach (table, radio, 0.0, 2, 3);
2350                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2351                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_S));
2352                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_S);
2353                 }
2354                 {
2355                     //TRANSLATORS: only translate "string" in "context|string". 
2356                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2357                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|L"));
2358                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the lightness of the color"), NULL);
2359                     clonetiler_table_attach (table, radio, 0.0, 3, 3);
2360                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2361                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_L));
2362                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_L);
2363                 }
2365             }
2367             {
2368                 GtkWidget *frame = gtk_frame_new (_("2. Tweak the picked value:"));
2369                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, VB_MARGIN);
2371                 GtkWidget *table = gtk_table_new (4, 2, FALSE);
2372                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2373                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2374                 gtk_container_add(GTK_CONTAINER(frame), table);
2376                 {
2377                     GtkWidget *l = gtk_label_new ("");
2378                     gtk_label_set_markup (GTK_LABEL(l), _("Gamma-correct:"));
2379                     clonetiler_table_attach (table, l, 1.0, 1, 1);
2380                 }
2381                 {
2382                     GtkWidget *l = clonetiler_spinbox (tt,
2383                                                        _("Shift the mid-range of the picked value upwards (>0) or downwards (<0)"), "gamma_picked",
2384                                                        -10, 10, "");
2385                     clonetiler_table_attach (table, l, 0.0, 1, 2);
2386                 }
2388                 {
2389                     GtkWidget *l = gtk_label_new ("");
2390                     gtk_label_set_markup (GTK_LABEL(l), _("Randomize:"));
2391                     clonetiler_table_attach (table, l, 1.0, 1, 3);
2392                 }
2393                 {
2394                     GtkWidget *l = clonetiler_spinbox (tt,
2395                                                        _("Randomize the picked value by this percentage"), "rand_picked",
2396                                                        0, 100, "%");
2397                     clonetiler_table_attach (table, l, 0.0, 1, 4);
2398                 }
2400                 {
2401                     GtkWidget *l = gtk_label_new ("");
2402                     gtk_label_set_markup (GTK_LABEL(l), _("Invert:"));
2403                     clonetiler_table_attach (table, l, 1.0, 2, 1);
2404                 }
2405                 {
2406                     GtkWidget *l = clonetiler_checkbox (tt, _("Invert the picked value"), "invert_picked");
2407                     clonetiler_table_attach (table, l, 0.0, 2, 2);
2408                 }
2409             }
2411             {
2412                 GtkWidget *frame = gtk_frame_new (_("3. Apply the value to the clones':"));
2413                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2416                 GtkWidget *table = gtk_table_new (2, 2, FALSE);
2417                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2418                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2419                 gtk_container_add(GTK_CONTAINER(frame), table);
2421                 {
2422                     GtkWidget *b  = gtk_check_button_new_with_label (_("Presence"));
2423                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_presence", 1);
2424                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2425                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone is created with the probability determined by the picked value in that point"), NULL);
2426                     clonetiler_table_attach (table, b, 0.0, 1, 1);
2427                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2428                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_presence");
2429                 }
2431                 {
2432                     GtkWidget *b  = gtk_check_button_new_with_label (_("Size"));
2433                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_size", 0);
2434                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2435                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's size is determined by the picked value in that point"), NULL);
2436                     clonetiler_table_attach (table, b, 0.0, 2, 1);
2437                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2438                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_size");
2439                 }
2441                 {
2442                     GtkWidget *b  = gtk_check_button_new_with_label (_("Color"));
2443                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_color", 0);
2444                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2445                     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);
2446                     clonetiler_table_attach (table, b, 0.0, 1, 2);
2447                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2448                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_color");
2449                 }
2451                 {
2452                     GtkWidget *b  = gtk_check_button_new_with_label (_("Opacity"));
2453                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_opacity", 0);
2454                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2455                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's opacity is determined by the picked value in that point"), NULL);
2456                     clonetiler_table_attach (table, b, 0.0, 2, 2);
2457                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2458                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_opacity");
2459                 }
2460             }
2461            gtk_widget_set_sensitive (vvb, prefs_get_int_attribute (prefs_path, "dotrace", 0));
2462         }
2463         }
2465 // Rows/columns, width/height
2466         {
2467             GtkWidget *table = gtk_table_new (2, 2, FALSE);
2468             gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
2469             gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2470             gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2471             gtk_box_pack_start (GTK_BOX (mainbox), table, FALSE, FALSE, 0);
2473             {
2474                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2475                 g_object_set_data (G_OBJECT(dlg), "rowscols", (gpointer) hb);
2477                 {
2478                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2479                     int value = prefs_get_int_attribute (prefs_path, "ymax", 2);
2480                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2481                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2482                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many rows in the tiling"), NULL);
2483                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2484                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2486                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2487                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "ymax");
2488                 }
2490                 {
2491                     GtkWidget *l = gtk_label_new ("");
2492                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2493                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2494                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2495                 }
2497                 {
2498                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2499                     int value = prefs_get_int_attribute (prefs_path, "xmax", 2);
2500                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2501                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2502                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many columns in the tiling"), NULL);
2503                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2504                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2506                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2507                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "xmax");
2508                 }
2510                 clonetiler_table_attach (table, hb, 0.0, 1, 2);
2511             }
2513             {
2514                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2515                 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
2517                 // unitmenu
2518                 GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
2519                 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
2520     
2521                 {
2522                     // Width spinbutton 
2523                     GtkObject *a = gtk_adjustment_new (0.0, -SP_DESKTOP_SCROLL_LIMIT, SP_DESKTOP_SCROLL_LIMIT, 1.0, 10.0, 10.0);
2524                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2526                     double value = prefs_get_double_attribute (prefs_path, "fillwidth", 50);
2527                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2528                     gdouble const units = sp_pixels_get_units (value, unit);
2529                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2531                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2532                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Width of the rectangle to be filled"), NULL);
2533                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2534                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2535                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2536                                        GTK_SIGNAL_FUNC(clonetiler_fill_width_changed), u);
2537                 }
2538                 {
2539                     GtkWidget *l = gtk_label_new ("");
2540                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2541                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2542                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2543                 }
2545                 {
2546                     // Height spinbutton
2547                     GtkObject *a = gtk_adjustment_new (0.0, -SP_DESKTOP_SCROLL_LIMIT, SP_DESKTOP_SCROLL_LIMIT, 1.0, 10.0, 10.0);
2548                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2550                     double value = prefs_get_double_attribute (prefs_path, "fillheight", 50);
2551                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2552                     gdouble const units = sp_pixels_get_units (value, unit);
2553                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2556                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2557                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Height of the rectangle to be filled"), NULL);
2558                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2559                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2560                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2561                                        GTK_SIGNAL_FUNC(clonetiler_fill_height_changed), u);
2562                 }
2564                 gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);
2565                 clonetiler_table_attach (table, hb, 0.0, 2, 2);
2567             }
2569             // Switch
2570             GtkWidget* radio;
2571             {
2572                 radio = gtk_radio_button_new_with_label (NULL, _("Rows, columns: "));
2573                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Create the specified number of rows and columns"), NULL);
2574                 clonetiler_table_attach (table, radio, 0.0, 1, 1);
2575                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_create), (gpointer) dlg);
2576             }
2577             if (prefs_get_int_attribute(prefs_path, "fillrect", 0) == 0) {
2578                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2579                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2580             }
2581             {
2582                 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Width, height: "));
2583                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Fill the specified width and height with the tiling"), NULL);
2584                 clonetiler_table_attach (table, radio, 0.0, 2, 1);
2585                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_fill), (gpointer) dlg);
2586             }
2587             if (prefs_get_int_attribute(prefs_path, "fillrect", 0) == 1) {
2588                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2589                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2590             }
2591         }
2594 // Use saved pos
2595         {
2596             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2597             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2599             GtkWidget *b  = gtk_check_button_new_with_label (_("Use saved size and position of the tile"));
2600             gint keepbbox = prefs_get_int_attribute (prefs_path, "keepbbox", 1);
2601             gtk_toggle_button_set_active ((GtkToggleButton *) b, keepbbox != 0);
2602             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);
2603             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2605             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2606                                GTK_SIGNAL_FUNC(clonetiler_keep_bbox_toggled), NULL);
2607         }
2609 // Statusbar
2610         {
2611             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2612             gtk_box_pack_end (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2613             GtkWidget *l = gtk_label_new("");
2614             g_object_set_data (G_OBJECT(dlg), "status", (gpointer) l);
2615             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2616         }
2618 // Buttons
2619         {
2620             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2621             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2623             {
2624                 GtkWidget *b = gtk_button_new ();
2625                 GtkWidget *l = gtk_label_new ("");
2626                 gtk_label_set_markup_with_mnemonic (GTK_LABEL(l), _(" <b>_Create</b> "));
2627                 gtk_container_add (GTK_CONTAINER(b), l);
2628                 gtk_tooltips_set_tip (tt, b, _("Create and tile the clones of the selection"), NULL);
2629                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_apply), NULL);
2630                 gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0);
2631             }
2633             { // buttons which are enabled only when there are tiled clones
2634                 GtkWidget *sb = gtk_hbox_new(FALSE, 0);
2635                 gtk_box_pack_end (GTK_BOX (hb), sb, FALSE, FALSE, 0);
2636                 g_object_set_data (G_OBJECT(dlg), "buttons_on_tiles", (gpointer) sb);
2637                 {
2638                     // TRANSLATORS: if a group of objects are "clumped" together, then they
2639                     //  are unevenly spread in the given amount of space - as shown in the
2640                     //  diagrams on the left in the following screenshot:
2641                     //  http://www.inkscape.org/screenshots/gallery/inkscape-0.42-CVS-tiles-unclump.png
2642                     //  So unclumping is the process of spreading a number of objects out more evenly.
2643                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" _Unclump "));
2644                     gtk_tooltips_set_tip (tt, b, _("Spread out clones to reduce clumping; can be applied repeatedly"), NULL);
2645                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_unclump), NULL);
2646                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2647                 }
2649                 {
2650                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" Re_move "));
2651                     gtk_tooltips_set_tip (tt, b, _("Remove existing tiled clones of the selected object (siblings only)"), NULL);
2652                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_remove), NULL);
2653                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2654                 }
2656                 // connect to global selection changed signal (so we can change desktops) and
2657                 // external_change (so we're not fooled by undo)
2658                 g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (clonetiler_change_selection), dlg);
2659                 g_signal_connect (G_OBJECT (INKSCAPE), "external_change", G_CALLBACK (clonetiler_external_change), dlg);
2660                 g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), G_OBJECT (INKSCAPE));
2662                 // update now
2663                 clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
2664             }
2666             {
2667                 GtkWidget *b = gtk_button_new_with_mnemonic (_(" R_eset "));
2668                 // TRANSLATORS: "change" is a noun here
2669                 gtk_tooltips_set_tip (tt, b, _("Reset all shifts, scales, rotates, opacity and color changes in the dialog to zero"), NULL);
2670                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_reset), NULL);
2671                 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2672             }
2673         }
2675         gtk_widget_show_all (mainbox);
2677     } // end of if (!dlg)
2679     gtk_window_present ((GtkWindow *) dlg);
2683 /*
2684   Local Variables:
2685   mode:c++
2686   c-file-style:"stroustrup"
2687   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2688   indent-tabs-mode:nil
2689   fill-column:99
2690   End:
2691 */
2692 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :