Code

warning cleanup
[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;
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, sizeof(c), 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     switch (type) {
298     case TILE_P1:
299         return d_s_r * rect_translate;
300         break;
302     case TILE_P2:
303         if (x % 2 == 0) {
304             return d_s_r * rect_translate;
305         } else {
306             return d_s_r * rotate_180_c * rect_translate;
307         }
308         break;
310     case TILE_PM:
311         if (x % 2 == 0) {
312             return d_s_r * rect_translate;
313         } else {
314             return d_s_r * flip_x * rect_translate;
315         }
316         break;
318     case TILE_PG:
319         if (y % 2 == 0) {
320             return d_s_r * rect_translate;
321         } else {
322             return d_s_r * flip_x * rect_translate;
323         }
324         break;
326     case TILE_CM:
327         if ((x + y) % 2 == 0) {
328             return d_s_r * rect_translate;
329         } else {
330             return d_s_r * flip_x * rect_translate;
331         }
332         break;
334     case TILE_PMM:
335         if (y % 2 == 0) {
336             if (x % 2 == 0) {
337                 return d_s_r * rect_translate;
338             } else {
339                 return d_s_r * flip_x * rect_translate;
340             }
341         } else {
342             if (x % 2 == 0) {
343                 return d_s_r * flip_y * rect_translate;
344             } else {
345                 return d_s_r * flip_x * flip_y * rect_translate;
346             }
347         }
348         break;
350     case TILE_PMG:
351         if (y % 4 == 0) {
352             return d_s_r * rect_translate;
353         } else if (y % 4 == 1) {
354             return d_s_r * flip_y * rect_translate;
355         } else if (y % 4 == 2) {
356             return d_s_r * flip_x * rect_translate;
357         } else if (y % 4 == 3) {
358             return d_s_r * flip_x * flip_y * rect_translate;
359         }
360         break;
362     case TILE_PGG:
363         if (y % 2 == 0) {
364             if (x % 2 == 0) {
365                 return d_s_r * rect_translate;
366             } else {
367                 return d_s_r * flip_y * rect_translate;
368             }
369         } else {
370             if (x % 2 == 0) {
371                 return d_s_r * rotate_180_c * rect_translate;
372             } else {
373                 return d_s_r * rotate_180_c * flip_y * rect_translate;
374             }
375         }
376         break;
378     case TILE_CMM:
379         if (y % 4 == 0) {
380             if (x % 2 == 0) {
381                 return d_s_r * rect_translate;
382             } else {
383                 return d_s_r * flip_x * rect_translate;
384             }
385         } else if (y % 4 == 1) {
386             if (x % 2 == 0) {
387                 return d_s_r * flip_y * rect_translate;
388             } else {
389                 return d_s_r * flip_x * flip_y * rect_translate;
390             }
391         } else if (y % 4 == 2) {
392             if (x % 2 == 1) {
393                 return d_s_r * rect_translate;
394             } else {
395                 return d_s_r * flip_x * rect_translate;
396             }
397         } else {
398             if (x % 2 == 1) {
399                 return d_s_r * flip_y * rect_translate;
400             } else {
401                 return d_s_r * flip_x * flip_y * rect_translate;
402             }
403         }
404         break;
406     case TILE_P4:
407     {
408         NR::Matrix ori (NR::translate ((w + h) * pow((x/2), d_per_x_exp) + dx,  (h + w) * pow((y/2), d_per_y_exp) + dy));
409         NR::Matrix dia1 (NR::translate (w/2 + h/2, -h/2 + w/2));
410         NR::Matrix dia2 (NR::translate (-w/2 + h/2, h/2 + w/2));
411         if (y % 2 == 0) {
412             if (x % 2 == 0) {
413                 return d_s_r * ori;
414             } else {
415                 return d_s_r * rotate_m90_c * dia1 * ori;
416             }
417         } else {
418             if (x % 2 == 0) {
419                 return d_s_r * rotate_90_c * dia2 * ori;
420             } else {
421                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
422             }
423         }
424     }
425     break;
427     case TILE_P4M:
428     {
429         double max = MAX(w, h);
430         NR::Matrix ori (NR::translate ((max + max) * pow((x/4), d_per_x_exp) + dx,  (max + max) * pow((y/2), d_per_y_exp) + dy));
431         NR::Matrix dia1 (NR::translate (w/2 - h/2, h/2 - w/2));
432         NR::Matrix dia2 (NR::translate (-h/2 + w/2, w/2 - h/2));
433         if (y % 2 == 0) {
434             if (x % 4 == 0) {
435                 return d_s_r * ori;
436             } else if (x % 4 == 1) {
437                 return d_s_r * flip_y * rotate_m90_c * dia1 * ori;
438             } else if (x % 4 == 2) {
439                 return d_s_r * rotate_m90_c * dia1 * NR::translate (h, 0) * ori;
440             } else if (x % 4 == 3) {
441                 return d_s_r * flip_x * NR::translate (w, 0) * ori;
442             }
443         } else {
444             if (x % 4 == 0) {
445                 return d_s_r * flip_y * NR::translate(0, h) * ori;
446             } else if (x % 4 == 1) {
447                 return d_s_r * rotate_90_c * dia2 * NR::translate(0, h) * ori;
448             } else if (x % 4 == 2) {
449                 return d_s_r * flip_y * rotate_90_c * dia2 * NR::translate(h, 0) * NR::translate(0, h) * ori;
450             } else if (x % 4 == 3) {
451                 return d_s_r * flip_y * flip_x * NR::translate(w, 0) * NR::translate(0, h) * ori;
452             }
453         }
454     }
455     break;
457     case TILE_P4G:
458     {
459         double max = MAX(w, h);
460         NR::Matrix ori (NR::translate ((max + max) * pow((x/4), d_per_x_exp) + dx,  (max + max) * pow(y, d_per_y_exp) + dy));
461         NR::Matrix dia1 (NR::translate (w/2 + h/2, h/2 - w/2));
462         NR::Matrix dia2 (NR::translate (-h/2 + w/2, w/2 + h/2));
463         if (((x/4) + y) % 2 == 0) {
464             if (x % 4 == 0) {
465                 return d_s_r * ori;
466             } else if (x % 4 == 1) {
467                 return d_s_r * rotate_m90_c * dia1 * ori;
468             } else if (x % 4 == 2) {
469                 return d_s_r * rotate_90_c * dia2 * ori;
470             } else if (x % 4 == 3) {
471                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
472             }
473         } else {
474             if (x % 4 == 0) {
475                 return d_s_r * flip_y * NR::translate (0, h) * ori;
476             } else if (x % 4 == 1) {
477                 return d_s_r * flip_y * rotate_m90_c * dia1 * NR::translate (-h, 0) * ori;
478             } else if (x % 4 == 2) {
479                 return d_s_r * flip_y * rotate_90_c * dia2 * NR::translate (h, 0) * ori;
480             } else if (x % 4 == 3) {
481                 return d_s_r * flip_x * NR::translate (w, 0) * ori;
482             }
483         }
484     }
485     break;
487     case TILE_P3:
488     {
489         double width;
490         double height;
491         NR::Matrix dia1;
492         NR::Matrix dia2;
493         if (w > h) {
494             width = w + w * cos60;
495             height = 2 * w * sin60;
496             dia1 = NR::Matrix (NR::translate (w/2 + w/2 * cos60, -(w/2 * sin60)));
497             dia2 = dia1 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60)));
498         } else {
499             width = h * cos (M_PI/6);
500             height = h;
501             dia1 = NR::Matrix (NR::translate (h/2 * cos30, -(h/2 * sin30)));
502             dia2 = dia1 * NR::Matrix (NR::translate (0, h/2));
503         }
504         NR::Matrix ori (NR::translate (width * pow((2*(x/3) + y%2), d_per_x_exp) + dx,  (height/2) * pow(y, d_per_y_exp) + dy));
505         if (x % 3 == 0) {
506             return d_s_r * ori;
507         } else if (x % 3 == 1) {
508             return d_s_r * rotate_m120_c * dia1 * ori;
509         } else if (x % 3 == 2) {
510             return d_s_r * rotate_120_c * dia2 * ori;
511         }
512     }
513     break;
515     case TILE_P31M:
516     {
517         NR::Matrix ori;
518         NR::Matrix dia1;
519         NR::Matrix dia2;
520         NR::Matrix dia3;
521         NR::Matrix dia4;
522         if (w > h) {
523             ori = NR::Matrix(NR::translate (w * pow((x/6) + 1/2 * (y%2), d_per_x_exp) + dx,  (w * cos30) * pow(y, d_per_y_exp) + dy));
524             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) );
525             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
526             dia3 = dia2 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
527             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
528         } else {
529             ori  = NR::Matrix (NR::translate (2*h * cos30  * pow((x/6 + 0.5*(y%2)), d_per_x_exp) + dx,  (2*h - h * sin30) * pow(y, d_per_y_exp) + dy));
530             dia1 = NR::Matrix (NR::translate (0, -h/2) * NR::translate (h/2 * cos30, h/2 * sin30));
531             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
532             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
533             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
534         }
535         if (x % 6 == 0) {
536             return d_s_r * ori;
537         } else if (x % 6 == 1) {
538             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
539         } else if (x % 6 == 2) {
540             return d_s_r * rotate_m120_c * dia2 * ori;
541         } else if (x % 6 == 3) {
542             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
543         } else if (x % 6 == 4) {
544             return d_s_r * rotate_120_c * dia4 * ori;
545         } else if (x % 6 == 5) {
546             return d_s_r * flip_y * NR::translate(0, h) * ori;
547         }
548     }
549     break;
551     case TILE_P3M1:
552     {
553         double width;
554         double height;
555         NR::Matrix dia1;
556         NR::Matrix dia2;
557         NR::Matrix dia3;
558         NR::Matrix dia4;
559         if (w > h) {
560             width = w + w * cos60;
561             height = 2 * w * sin60;
562             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) );
563             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
564             dia3 = dia2 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
565             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
566         } else {
567             width = 2 * h * cos (M_PI/6);
568             height = 2 * h;
569             dia1 = NR::Matrix (NR::translate (0, -h/2) * NR::translate (h/2 * cos30, h/2 * sin30));
570             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
571             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
572             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
573         }
574         NR::Matrix ori (NR::translate (width * pow((2*(x/6) + y%2), d_per_x_exp) + dx,  (height/2) * pow(y, d_per_y_exp) + dy));
575         if (x % 6 == 0) {
576             return d_s_r * ori;
577         } else if (x % 6 == 1) {
578             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
579         } else if (x % 6 == 2) {
580             return d_s_r * rotate_m120_c * dia2 * ori;
581         } else if (x % 6 == 3) {
582             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
583         } else if (x % 6 == 4) {
584             return d_s_r * rotate_120_c * dia4 * ori;
585         } else if (x % 6 == 5) {
586             return d_s_r * flip_y * NR::translate(0, h) * ori;
587         }
588     }
589     break;
591     case TILE_P6:
592     {
593         NR::Matrix ori;
594         NR::Matrix dia1;
595         NR::Matrix dia2;
596         NR::Matrix dia3;
597         NR::Matrix dia4;
598         NR::Matrix dia5;
599         if (w > h) {
600             ori = NR::Matrix(NR::translate (w * pow((2*(x/6) + (y%2)), d_per_x_exp) + dx,  (2*w * sin60) * pow(y, d_per_y_exp) + dy));
601             dia1 = NR::Matrix (NR::translate (w/2 * cos60, -w/2 * sin60));
602             dia2 = dia1 * NR::Matrix (NR::translate (w/2, 0));
603             dia3 = dia2 * NR::Matrix (NR::translate (w/2 * cos60, w/2 * sin60));
604             dia4 = dia3 * NR::Matrix (NR::translate (-w/2 * cos60, w/2 * sin60));
605             dia5 = dia4 * NR::Matrix (NR::translate (-w/2, 0));
606         } else {
607             ori = NR::Matrix(NR::translate (2*h * cos30 * pow((x/6 + 0.5*(y%2)), d_per_x_exp) + dx,  (h + h * sin30) * pow(y, d_per_y_exp) + dy));
608             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));
609             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));
610             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));
611             dia4 = dia3 * dia1.inverse();
612             dia5 = dia3 * dia2.inverse();
613         }
614         if (x % 6 == 0) {
615             return d_s_r * ori;
616         } else if (x % 6 == 1) {
617             return d_s_r * rotate_m60_c * dia1 * ori;
618         } else if (x % 6 == 2) {
619             return d_s_r * rotate_m120_c * dia2 * ori;
620         } else if (x % 6 == 3) {
621             return d_s_r * rotate_180_c * dia3 * ori;
622         } else if (x % 6 == 4) {
623             return d_s_r * rotate_120_c * dia4 * ori;
624         } else if (x % 6 == 5) {
625             return d_s_r * rotate_60_c * dia5 * ori;
626         }
627     }
628     break;
630     case TILE_P6M:
631     {
633         NR::Matrix ori;
634         NR::Matrix dia1, dia2, dia3, dia4, dia5, dia6, dia7, dia8, dia9, dia10;
635         if (w > h) {
636             ori = NR::Matrix(NR::translate (w * pow((2*(x/12) + (y%2)), d_per_x_exp) + dx,  (2*w * sin60) * pow(y, d_per_y_exp) + dy));
637             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));
638             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, -h * sin30));
639             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));
640             dia4 = dia3 * NR::Matrix (NR::translate (h * cos30, h * sin30));
641             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));
642             dia6 = dia5 * NR::Matrix (NR::translate (0, h));
643             dia7 = dia6 * dia1.inverse();
644             dia8 = dia6 * dia2.inverse();
645             dia9 = dia6 * dia3.inverse();
646             dia10 = dia6 * dia4.inverse();
647         } else {
648             ori = NR::Matrix(NR::translate (4*h * cos30 * pow((x/12 + 0.5*(y%2)), d_per_x_exp) + dx,  (2*h  + 2*h * sin30) * pow(y, d_per_y_exp) + dy));
649             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));
650             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, -h * sin30));
651             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));
652             dia4 = dia3 * NR::Matrix (NR::translate (h * cos30, h * sin30));
653             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));
654             dia6 = dia5 * NR::Matrix (NR::translate (0, h));
655             dia7 = dia6 * dia1.inverse();
656             dia8 = dia6 * dia2.inverse();
657             dia9 = dia6 * dia3.inverse();
658             dia10 = dia6 * dia4.inverse();
659         }
660         if (x % 12 == 0) {
661             return d_s_r * ori;
662         } else if (x % 12 == 1) {
663             return d_s_r * flip_y * rotate_m60_c * dia1 * ori;
664         } else if (x % 12 == 2) {
665             return d_s_r * rotate_m60_c * dia2 * ori;
666         } else if (x % 12 == 3) {
667             return d_s_r * flip_y * rotate_m120_c * dia3 * ori;
668         } else if (x % 12 == 4) {
669             return d_s_r * rotate_m120_c * dia4 * ori;
670         } else if (x % 12 == 5) {
671             return d_s_r * flip_x * dia5 * ori;
672         } else if (x % 12 == 6) {
673             return d_s_r * flip_x * flip_y * dia6 * ori;
674         } else if (x % 12 == 7) {
675             return d_s_r * flip_y * rotate_120_c * dia7 * ori;
676         } else if (x % 12 == 8) {
677             return d_s_r * rotate_120_c * dia8 * ori;
678         } else if (x % 12 == 9) {
679             return d_s_r * flip_y * rotate_60_c * dia9 * ori;
680         } else if (x % 12 == 10) {
681             return d_s_r * rotate_60_c * dia10 * ori;
682         } else if (x % 12 == 11) {
683             return d_s_r * flip_y * NR::translate (0, h) * ori;
684         }
685     }
686     break;
688     default:
689         break;
690     }
692     return NR::identity();
695 static bool
696 clonetiler_is_a_clone_of (SPObject *tile, SPObject *obj)
698     char *id_href = NULL;
700     if (obj) {
701         Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
702         id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
703     }
705     if (SP_IS_USE(tile) &&
706         SP_OBJECT_REPR(tile)->attribute("xlink:href") &&
707         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("xlink:href"))) &&
708         SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of") &&
709         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of"))))
710     {
711         if (id_href)
712             g_free (id_href);
713         return true;
714     } else {
715         if (id_href)
716             g_free (id_href);
717         return false;
718     }
721 static NRArena const *trace_arena = NULL;
722 static unsigned trace_visionkey;
723 static NRArenaItem *trace_root;
724 static gdouble trace_zoom;
726 static void
727 clonetiler_trace_hide_tiled_clones_recursively (SPObject *from)
729     if (!trace_arena)
730         return;
732     for (SPObject *o = sp_object_first_child(from); o != NULL; o = SP_OBJECT_NEXT(o)) {
733         if (SP_IS_ITEM(o) && clonetiler_is_a_clone_of (o, NULL))
734             sp_item_invoke_hide(SP_ITEM(o), trace_visionkey); // FIXME: hide each tiled clone's original too!
735         clonetiler_trace_hide_tiled_clones_recursively (o);
736     }
739 static void
740 clonetiler_trace_setup (SPDocument *doc, gdouble zoom, SPItem *original)
742     trace_arena = NRArena::create();
743     /* Create ArenaItem and set transform */
744     trace_visionkey = sp_item_display_key_new(1);
745     trace_root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT (doc)),
746                                       (NRArena *) trace_arena, trace_visionkey, SP_ITEM_SHOW_DISPLAY);
748     // hide the (current) original and any tiled clones, we only want to pick the background
749     sp_item_invoke_hide(original, trace_visionkey);
750     clonetiler_trace_hide_tiled_clones_recursively (SP_OBJECT(SP_DOCUMENT_ROOT (doc)));
752     sp_document_root (doc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
753     sp_document_ensure_up_to_date(doc);
755     trace_zoom = zoom;
758 static guint32
759 clonetiler_trace_pick (NR::Rect box)
761     if (!trace_arena)
762         return 0;
764     NRMatrix t;
765     nr_matrix_set_scale(&t, trace_zoom, trace_zoom);
766     nr_arena_item_set_transform(trace_root, &t);
767     NRGC gc(NULL);
768     nr_matrix_set_identity(&gc.transform);
769     nr_arena_item_invoke_update( trace_root, NULL, &gc,
770                                  NR_ARENA_ITEM_STATE_ALL,
771                                  NR_ARENA_ITEM_STATE_NONE );
773     /* Item integer bbox in points */
774     NRRectL ibox;
775     ibox.x0 = (int) floor(trace_zoom * box.min()[NR::X] + 0.5);
776     ibox.y0 = (int) floor(trace_zoom * box.min()[NR::Y] + 0.5);
777     ibox.x1 = (int) floor(trace_zoom * box.max()[NR::X] + 0.5);
778     ibox.y1 = (int) floor(trace_zoom * box.max()[NR::Y] + 0.5);
780     /* Find visible area */
781     int width = ibox.x1 - ibox.x0;
782     int height = ibox.y1 - ibox.y0;
784     /* Set up pixblock */
785     guchar *px = g_new(guchar, 4 * width * height);
787     if (px == NULL) {
788         return 0; // buffer is too big or too small, cannot pick, so return 0
789     }
791     memset(px, 0x00, 4 * width * height);
793     /* Render */
794     NRPixBlock pb;
795     nr_pixblock_setup_extern( &pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
796                               ibox.x0, ibox.y0, ibox.x1, ibox.y1,
797                               px, 4 * width, FALSE, FALSE );
798     nr_arena_item_invoke_render(NULL, trace_root, &ibox, &pb,
799                                  NR_ARENA_ITEM_RENDER_NO_CACHE );
801     double R = 0, G = 0, B = 0, A = 0;
802     double count = 0;
803     double weight = 0;
805     for (int y = ibox.y0; y < ibox.y1; y++) {
806         const unsigned char *s = NR_PIXBLOCK_PX (&pb) + (y - ibox.y0) * pb.rs;
807         for (int x = ibox.x0; x < ibox.x1; x++) {
808             count += 1;
809             weight += s[3] / 255.0;
810             R += s[0] / 255.0;
811             G += s[1] / 255.0;
812             B += s[2] / 255.0;
813             A += s[3] / 255.0;
814             s += 4;
815         }
816     }
818     nr_pixblock_release(&pb);
820     R = R / weight;
821     G = G / weight;
822     B = B / weight;
823     A = A / count;
825     R = CLAMP (R, 0.0, 1.0);
826     G = CLAMP (G, 0.0, 1.0);
827     B = CLAMP (B, 0.0, 1.0);
828     A = CLAMP (A, 0.0, 1.0);
830     return SP_RGBA32_F_COMPOSE (R, G, B, A);
833 static void
834 clonetiler_trace_finish ()
836     if (trace_arena) {
837         ((NRObject *) trace_arena)->unreference();
838         trace_arena = NULL;
839     }
842 static void
843 clonetiler_unclump( GtkWidget */*widget*/, void * )
845     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
846     if (desktop == NULL)
847         return;
849     Inkscape::Selection *selection = sp_desktop_selection(desktop);
851     // check if something is selected
852     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
853         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump."));
854         return;
855     }
857     SPObject *obj = SP_OBJECT(selection->singleItem());
858     SPObject *parent = SP_OBJECT_PARENT (obj);
860     GSList *to_unclump = NULL; // not including the original
862     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
863         if (clonetiler_is_a_clone_of (child, obj)) {
864             to_unclump = g_slist_prepend (to_unclump, child);
865         }
866     }
868     sp_document_ensure_up_to_date(sp_desktop_document(desktop));
870     unclump (to_unclump);
872     g_slist_free (to_unclump);
874     sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
875                       _("Unclump tiled clones"));
878 static guint
879 clonetiler_number_of_clones (SPObject *obj)
881     SPObject *parent = SP_OBJECT_PARENT (obj);
883     guint n = 0;
885     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
886         if (clonetiler_is_a_clone_of (child, obj)) {
887             n ++;
888         }
889     }
891     return n;
894 static void
895 clonetiler_remove( GtkWidget */*widget*/, void *, bool do_undo = true )
897     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
898     if (desktop == NULL)
899         return;
901     Inkscape::Selection *selection = sp_desktop_selection(desktop);
903     // check if something is selected
904     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
905         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove."));
906         return;
907     }
909     SPObject *obj = SP_OBJECT(selection->singleItem());
910     SPObject *parent = SP_OBJECT_PARENT (obj);
912 // remove old tiling
913     GSList *to_delete = NULL;
914     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
915         if (clonetiler_is_a_clone_of (child, obj)) {
916             to_delete = g_slist_prepend (to_delete, child);
917         }
918     }
919     for (GSList *i = to_delete; i; i = i->next) {
920         SP_OBJECT(i->data)->deleteObject();
921     }
922     g_slist_free (to_delete);
924     clonetiler_change_selection (NULL, selection, dlg);
926     if (do_undo)
927         sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
928                           _("Delete tiled clones"));
931 static NR::Rect
932 transform_rect(NR::Rect const &r, NR::Matrix const &m)
934     using NR::X;
935     using NR::Y;
936     NR::Point const p1 = r.corner(1) * m;
937     NR::Point const p2 = r.corner(2) * m;
938     NR::Point const p3 = r.corner(3) * m;
939     NR::Point const p4 = r.corner(4) * m;
940     return NR::Rect(
941         NR::Point(
942             std::min(std::min(p1[X], p2[X]), std::min(p3[X], p4[X])),
943             std::min(std::min(p1[Y], p2[Y]), std::min(p3[Y], p4[Y]))),
944         NR::Point(
945             std::max(std::max(p1[X], p2[X]), std::max(p3[X], p4[X])),
946             std::max(std::max(p1[Y], p2[Y]), std::max(p3[Y], p4[Y]))));
949 /**
950 Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same
951 probability of being displaced.
952  */
953 static double
954 randomize01 (double val, double rand)
956     double base = MIN (val - rand, 1 - 2*rand);
957     if (base < 0) base = 0;
958     val = base + g_random_double_range (0, MIN (2 * rand, 1 - base));
959     return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case...
963 static void
964 clonetiler_apply( GtkWidget */*widget*/, void * )
966     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
967     if (desktop == NULL)
968         return;
970     Inkscape::Selection *selection = sp_desktop_selection(desktop);
972     // check if something is selected
973     if (selection->isEmpty()) {
974         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone."));
975         return;
976     }
978     // Check if more than one object is selected.
979     if (g_slist_length((GSList *) selection->itemList()) > 1) {
980         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>."));
981         return;
982     }
984     SPObject *obj = SP_OBJECT(selection->singleItem());
985     Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
986     const char *id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
987     SPObject *parent = SP_OBJECT_PARENT (obj);
989     clonetiler_remove (NULL, NULL, false);
991     double d_x_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_x_per_x", 0, -100, 1000);
992     double d_y_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_y_per_x", 0, -100, 1000);
993     double d_per_x_exp = prefs_get_double_attribute_limited (prefs_path, "d_per_x_exp", 1, 0, 10);
994     double d_x_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_x_per_y", 0, -100, 1000);
995     double d_y_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_y_per_y", 0, -100, 1000);
996     double d_per_y_exp = prefs_get_double_attribute_limited (prefs_path, "d_per_y_exp", 1, 0, 10);
997     int alternate_x = prefs_get_int_attribute (prefs_path, "alternate_x", 0);
998     int alternate_y = prefs_get_int_attribute (prefs_path, "alternate_y", 0);
999     double rand_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_x", 0, 0, 1000);
1000     double rand_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_y", 0, 0, 1000);
1002     double d_scalex_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scalex_per_x", 0, -100, 1000);
1003     double d_scaley_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scaley_per_x", 0, -100, 1000);
1004     double d_scalex_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scalex_per_y", 0, -100, 1000);
1005     double d_scaley_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_scaley_per_y", 0, -100, 1000);
1006     int alternate_scalex = prefs_get_int_attribute (prefs_path, "alternate_scalex", 0);
1007     int alternate_scaley = prefs_get_int_attribute (prefs_path, "alternate_scaley", 0);
1008     double rand_scalex = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_scalex", 0, 0, 1000);
1009     double rand_scaley = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_scaley", 0, 0, 1000);
1011     double d_rot_per_x = prefs_get_double_attribute_limited (prefs_path, "d_rot_per_x", 0, -180, 180);
1012     double d_rot_per_y = prefs_get_double_attribute_limited (prefs_path, "d_rot_per_y", 0, -180, 180);
1013     int alternate_rotx = prefs_get_int_attribute (prefs_path, "alternate_rotx", 0);
1014     int alternate_roty = prefs_get_int_attribute (prefs_path, "alternate_roty", 0);
1015     double rand_rot = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_rot", 0, 0, 100);
1017     double d_blur_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_blur_per_y", 0, 0, 100);
1018     double d_blur_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_blur_per_x", 0, 0, 100);
1019     int alternate_blury = prefs_get_int_attribute (prefs_path, "alternate_blury", 0);
1020     int alternate_blurx = prefs_get_int_attribute (prefs_path, "alternate_blurx", 0);
1021     double rand_blur = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_blur", 0, 0, 100);
1023     double d_opacity_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_opacity_per_y", 0, 0, 100);
1024     double d_opacity_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_opacity_per_x", 0, 0, 100);
1025     int alternate_opacityy = prefs_get_int_attribute (prefs_path, "alternate_opacityy", 0);
1026     int alternate_opacityx = prefs_get_int_attribute (prefs_path, "alternate_opacityx", 0);
1027     double rand_opacity = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_opacity", 0, 0, 100);
1029     const gchar *initial_color = prefs_get_string_attribute (prefs_path, "initial_color");
1030     double d_hue_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_hue_per_y", 0, -100, 100);
1031     double d_hue_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_hue_per_x", 0, -100, 100);
1032     double rand_hue = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_hue", 0, 0, 100);
1033     double d_saturation_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_saturation_per_y", 0, -100, 100);
1034     double d_saturation_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_saturation_per_x", 0, -100, 100);
1035     double rand_saturation = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_saturation", 0, 0, 100);
1036     double d_lightness_per_y = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_lightness_per_y", 0, -100, 100);
1037     double d_lightness_per_x = 0.01 * prefs_get_double_attribute_limited (prefs_path, "d_lightness_per_x", 0, -100, 100);
1038     double rand_lightness = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_lightness", 0, 0, 100);
1039     int alternate_color_y = prefs_get_int_attribute (prefs_path, "alternate_color_y", 0);
1040     int alternate_color_x = prefs_get_int_attribute (prefs_path, "alternate_color_x", 0);
1042     int type = prefs_get_int_attribute (prefs_path, "symmetrygroup", 0);
1044     int keepbbox = prefs_get_int_attribute (prefs_path, "keepbbox", 1);
1046     int xmax = prefs_get_int_attribute (prefs_path, "xmax", 2);
1047     int ymax = prefs_get_int_attribute (prefs_path, "ymax", 2);
1049     int fillrect = prefs_get_int_attribute (prefs_path, "fillrect", 0);
1050     double fillwidth = prefs_get_double_attribute_limited (prefs_path, "fillwidth", 50, 0, 1e6);
1051     double fillheight = prefs_get_double_attribute_limited (prefs_path, "fillheight", 50, 0, 1e6);
1053     int dotrace = prefs_get_int_attribute (prefs_path, "dotrace", 0);
1054     int pick = prefs_get_int_attribute (prefs_path, "pick", 0);
1055     int pick_to_presence = prefs_get_int_attribute (prefs_path, "pick_to_presence", 0);
1056     int pick_to_size = prefs_get_int_attribute (prefs_path, "pick_to_size", 0);
1057     int pick_to_color = prefs_get_int_attribute (prefs_path, "pick_to_color", 0);
1058     int pick_to_opacity = prefs_get_int_attribute (prefs_path, "pick_to_opacity", 0);
1059     double rand_picked = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_picked", 0, 0, 100);
1060     int invert_picked = prefs_get_int_attribute (prefs_path, "invert_picked", 0);
1061     double gamma_picked = prefs_get_double_attribute_limited (prefs_path, "gamma_picked", 0, -10, 10);
1063     if (dotrace) {
1064         clonetiler_trace_setup (sp_desktop_document(desktop), 1.0, SP_ITEM (obj));
1065     }
1067     NR::Point center;
1068     double w;
1069     double h;
1070     double x0;
1071     double y0;
1073     if (keepbbox &&
1074         obj_repr->attribute("inkscape:tile-w") &&
1075         obj_repr->attribute("inkscape:tile-h") &&
1076         obj_repr->attribute("inkscape:tile-x0") &&
1077         obj_repr->attribute("inkscape:tile-y0") &&
1078         obj_repr->attribute("inkscape:tile-cx") &&
1079         obj_repr->attribute("inkscape:tile-cy")) {
1081         double cx = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cx", 0);
1082         double cy = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cy", 0);
1083         center = NR::Point (cx, cy);
1085         w = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-w", 0);
1086         h = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-h", 0);
1087         x0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-x0", 0);
1088         y0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-y0", 0);
1089     } else {
1090         NR::Maybe<NR::Rect> r = SP_ITEM(obj)->getBounds(sp_item_i2doc_affine(SP_ITEM(obj)),
1091                                                         SPItem::GEOMETRIC_BBOX);
1092         /* impl: Use of GEOMETRIC_BBOX is so that the stroke of rectangles will be shared
1093          * (overlapped) rather than effectively doubled in width.
1094          *
1095          * (If you wish to change this, then please consider discussing at bug #1722238.) */
1097         if (r) {
1098             w = r->dimensions()[NR::X];
1099             h = r->dimensions()[NR::Y];
1100             x0 = r->min()[NR::X];
1101             y0 = r->min()[NR::Y];
1102             center = desktop->dt2doc(SP_ITEM(obj)->getCenter());
1104             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", center[NR::X]);
1105             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", center[NR::Y]);
1106             sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
1107             sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
1108             sp_repr_set_svg_double(obj_repr, "inkscape:tile-x0", x0);
1109             sp_repr_set_svg_double(obj_repr, "inkscape:tile-y0", y0);
1110         } else {
1111             center = NR::Point(0, 0);
1112             w = h = 0;
1113             x0 = y0 = 0;
1114         }
1115     }
1117     NR::Point cur = NR::Point (0, 0);
1118     NR::Rect bbox_original = NR::Rect (NR::Point (x0, y0), NR::Point (x0 + w, y0 + h));
1119     double perimeter_original = (w + h)/4;
1121     for (int x = 0;
1122          fillrect?
1123              (fabs(cur[NR::X]) < fillwidth && x < 200) // prevent "freezing" with too large fillrect, arbitrarily limit rows
1124              : (x < xmax);
1125          x ++) {
1126         for (int y = 0;
1127              fillrect?
1128                  (fabs(cur[NR::Y]) < fillheight && y < 200) // prevent "freezing" with too large fillrect, arbitrarily limit cols
1129                  : (y < ymax);
1130              y ++) {
1132             // Note: We create a clone at 0,0 too, right over the original, in case our clones are colored
1134             // Get transform from symmetry, shift, scale, rotation
1135             NR::Matrix t = clonetiler_get_transform (type, x, y, center[NR::X], center[NR::Y], w, h,
1136                                                      d_x_per_x, d_y_per_x, d_x_per_y, d_y_per_y, alternate_x, alternate_y, rand_x, rand_y,
1137                                                      d_per_x_exp, d_per_y_exp,
1138                                                      d_rot_per_x, d_rot_per_y, alternate_rotx, alternate_roty, rand_rot,
1139                                                      d_scalex_per_x, d_scaley_per_x, d_scalex_per_y, d_scaley_per_y,
1140                                                      alternate_scalex, alternate_scaley, rand_scalex, rand_scaley);
1142             cur = center * t - center;
1143             if (fillrect) {
1144                 if ((cur[NR::X] > fillwidth) || (cur[NR::Y] > fillheight)) { // off limits
1145                     continue;
1146                 }
1147             }
1149             gchar color_string[32]; *color_string = 0;
1151             // Color tab
1152             if (initial_color) {
1153                 guint32 rgba = sp_svg_read_color (initial_color, 0x000000ff);
1154                 float hsl[3];
1155                 sp_color_rgb_to_hsl_floatv (hsl, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba));
1157                 double eff_x = (alternate_color_x? (x%2) : (x));
1158                 double eff_y = (alternate_color_y? (y%2) : (y));
1160                 hsl[0] += d_hue_per_x * eff_x + d_hue_per_y * eff_y + rand_hue * g_random_double_range (-1, 1);
1161                 if (hsl[0] < 0) hsl[0] += 1;
1162                 if (hsl[0] > 1) hsl[0] -= 1;
1163                 hsl[1] += d_saturation_per_x * eff_x + d_saturation_per_y * eff_y + rand_saturation * g_random_double_range (-1, 1);
1164                 hsl[1] = CLAMP (hsl[1], 0, 1);
1165                 hsl[2] += d_lightness_per_x * eff_x + d_lightness_per_y * eff_y + rand_lightness * g_random_double_range (-1, 1);
1166                 hsl[2] = CLAMP (hsl[2], 0, 1);
1168                 float rgb[3];
1169                 sp_color_hsl_to_rgb_floatv (rgb, hsl[0], hsl[1], hsl[2]);
1170                 sp_svg_write_color(color_string, sizeof(color_string), SP_RGBA32_F_COMPOSE(rgb[0], rgb[1], rgb[2], 1.0));
1171             }
1173             // Blur
1174             double blur = 0.0;
1175             {
1176             int eff_x = (alternate_blurx? (x%2) : (x));
1177             int eff_y = (alternate_blury? (y%2) : (y));
1178             blur =  (d_blur_per_x * eff_x + d_blur_per_y * eff_y + rand_blur * g_random_double_range (-1, 1));
1179             blur = CLAMP (blur, 0, 1);
1180             }
1182             // Opacity
1183             double opacity = 1.0;
1184             {
1185             int eff_x = (alternate_opacityx? (x%2) : (x));
1186             int eff_y = (alternate_opacityy? (y%2) : (y));
1187             opacity = 1 - (d_opacity_per_x * eff_x + d_opacity_per_y * eff_y + rand_opacity * g_random_double_range (-1, 1));
1188             opacity = CLAMP (opacity, 0, 1);
1189             }
1191             // Trace tab
1192             if (dotrace) {
1193                 NR::Rect bbox_t = transform_rect (bbox_original, t);
1195                 guint32 rgba = clonetiler_trace_pick (bbox_t);
1196                 float r = SP_RGBA32_R_F(rgba);
1197                 float g = SP_RGBA32_G_F(rgba);
1198                 float b = SP_RGBA32_B_F(rgba);
1199                 float a = SP_RGBA32_A_F(rgba);
1201                 float hsl[3];
1202                 sp_color_rgb_to_hsl_floatv (hsl, r, g, b);
1204                 gdouble val = 0;
1205                 switch (pick) {
1206                 case PICK_COLOR:
1207                     val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max
1208                     break;
1209                 case PICK_OPACITY:
1210                     val = a;
1211                     break;
1212                 case PICK_R:
1213                     val = r;
1214                     break;
1215                 case PICK_G:
1216                     val = g;
1217                     break;
1218                 case PICK_B:
1219                     val = b;
1220                     break;
1221                 case PICK_H:
1222                     val = hsl[0];
1223                     break;
1224                 case PICK_S:
1225                     val = hsl[1];
1226                     break;
1227                 case PICK_L:
1228                     val = 1 - hsl[2];
1229                     break;
1230                 default:
1231                     break;
1232                 }
1234                 if (rand_picked > 0) {
1235                     val = randomize01 (val, rand_picked);
1236                     r = randomize01 (r, rand_picked);
1237                     g = randomize01 (g, rand_picked);
1238                     b = randomize01 (b, rand_picked);
1239                 }
1241                 if (gamma_picked != 0) {
1242                     double power;
1243                     if (gamma_picked < 0)
1244                         power = 1/(1 + fabs(gamma_picked));
1245                     else
1246                         power = 1 + gamma_picked;
1248                     val = pow (val, power);
1249                     r = pow (r, power);
1250                     g = pow (g, power);
1251                     b = pow (b, power);
1252                 }
1254                 if (invert_picked) {
1255                     val = 1 - val;
1256                     r = 1 - r;
1257                     g = 1 - g;
1258                     b = 1 - b;
1259                 }
1261                 val = CLAMP (val, 0, 1);
1262                 r = CLAMP (r, 0, 1);
1263                 g = CLAMP (g, 0, 1);
1264                 b = CLAMP (b, 0, 1);
1266                 // recompose tweaked color
1267                 rgba = SP_RGBA32_F_COMPOSE(r, g, b, a);
1269                 if (pick_to_presence) {
1270                     if (g_random_double_range (0, 1) > val) {
1271                         continue; // skip!
1272                     }
1273                 }
1274                 if (pick_to_size) {
1275                     t = NR::translate(-center[NR::X], -center[NR::Y]) * NR::scale (val, val) * NR::translate(center[NR::X], center[NR::Y]) * t;
1276                 }
1277                 if (pick_to_opacity) {
1278                     opacity *= val;
1279                 }
1280                 if (pick_to_color) {
1281                     sp_svg_write_color(color_string, sizeof(color_string), rgba);
1282                 }
1283             }
1285             if (opacity < 1e-6) { // invisibly transparent, skip
1286                     continue;
1287             }
1289             if (fabs(t[0]) + fabs (t[1]) + fabs(t[2]) + fabs(t[3]) < 1e-6) { // too small, skip
1290                     continue;
1291             }
1293             // Create the clone
1294             Inkscape::XML::Node *clone = obj_repr->document()->createElement("svg:use");
1295             clone->setAttribute("x", "0");
1296             clone->setAttribute("y", "0");
1297             clone->setAttribute("inkscape:tiled-clone-of", id_href);
1298             clone->setAttribute("xlink:href", id_href);
1300             NR::Point new_center;
1301             bool center_set = false;
1302             if (obj_repr->attribute("inkscape:transform-center-x") || obj_repr->attribute("inkscape:transform-center-y")) {
1303                 new_center = desktop->dt2doc(SP_ITEM(obj)->getCenter()) * t;
1304                 center_set = true;
1305             }
1307             gchar *affinestr=sp_svg_transform_write(t);
1308             clone->setAttribute("transform", affinestr);
1309             g_free(affinestr);
1311             if (opacity < 1.0) {
1312                 sp_repr_set_css_double(clone, "opacity", opacity);
1313             }
1315             if (*color_string) {
1316                 clone->setAttribute("fill", color_string);
1317                 clone->setAttribute("stroke", color_string);
1318             }
1320             // add the new clone to the top of the original's parent
1321             SP_OBJECT_REPR(parent)->appendChild(clone);
1323             if (blur > 0.0) {
1324                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1325                 double perimeter = perimeter_original * t.expansion();
1326                 double radius = blur * perimeter;
1327                 // it's hard to figure out exact width/height of the tile without having an object
1328                 // that we can take bbox of; however here we only need a lower bound so that blur
1329                 // margins are not too small, and the perimeter should work
1330                 SPFilter *constructed = new_filter_gaussian_blur(sp_desktop_document(desktop), radius, t.expansion(), t.expansionX(), t.expansionY(), perimeter, perimeter);
1331                 sp_style_set_property_url (clone_object, "filter", SP_OBJECT(constructed), false);
1332             }
1334             if (center_set) {
1335                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1336                 if (clone_object && SP_IS_ITEM(clone_object)) {
1337                     clone_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1338                     SP_ITEM(clone_object)->setCenter(desktop->doc2dt(new_center));
1339                     clone_object->updateRepr();
1340                 }
1341             }
1343             Inkscape::GC::release(clone);
1344         }
1345         cur[NR::Y] = 0;
1346     }
1348     if (dotrace) {
1349         clonetiler_trace_finish ();
1350     }
1352     clonetiler_change_selection (NULL, selection, dlg);
1354     sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER,
1355                      _("Create tiled clones"));
1358 static GtkWidget *
1359 clonetiler_new_tab (GtkWidget *nb, const gchar *label)
1361     GtkWidget *l = gtk_label_new_with_mnemonic (label);
1362     GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN);
1363     gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN);
1364     gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l);
1365     return vb;
1368 static void
1369 clonetiler_checkbox_toggled (GtkToggleButton *tb, gpointer *data)
1371     const gchar *attr = (const gchar *) data;
1372     prefs_set_int_attribute (prefs_path, attr, gtk_toggle_button_get_active (tb));
1375 static GtkWidget *
1376 clonetiler_checkbox (GtkTooltips *tt, const char *tip, const char *attr)
1378     GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
1380     GtkWidget *b = gtk_check_button_new ();
1381     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, tip, NULL);
1383     int value = prefs_get_int_attribute (prefs_path, attr, 0);
1384     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(b), value);
1386     gtk_box_pack_end (GTK_BOX (hb), b, FALSE, TRUE, 0);
1387     gtk_signal_connect ( GTK_OBJECT (b), "clicked",
1388                          GTK_SIGNAL_FUNC (clonetiler_checkbox_toggled), (gpointer) attr);
1390     g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
1392     return hb;
1396 static void
1397 clonetiler_value_changed (GtkAdjustment *adj, gpointer data)
1399     const gchar *pref = (const gchar *) data;
1400     prefs_set_double_attribute (prefs_path, pref, adj->value);
1403 static GtkWidget *
1404 clonetiler_spinbox (GtkTooltips *tt, const char *tip, const char *attr, double lower, double upper, const gchar *suffix, bool exponent = false)
1406     GtkWidget *hb = gtk_hbox_new(FALSE, 0);
1408     {
1409         GtkObject *a;
1410         if (exponent)
1411             a = gtk_adjustment_new(1.0, lower, upper, 0.01, 0.05, 0.1);
1412         else
1413             a = gtk_adjustment_new(0.0, lower, upper, 0.1, 0.5, 2);
1415         GtkWidget *sb;
1416         if (exponent)
1417             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.01, 2);
1418         else
1419             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.1, 1);
1421         gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, tip, NULL);
1422         gtk_entry_set_width_chars (GTK_ENTRY (sb), 4);
1423         gtk_box_pack_start (GTK_BOX (hb), sb, FALSE, FALSE, SB_MARGIN);
1425         double value = prefs_get_double_attribute_limited (prefs_path, attr, exponent? 1 : 0, lower, upper);
1426         gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
1427         gtk_signal_connect(GTK_OBJECT(a), "value_changed",
1428                            GTK_SIGNAL_FUNC(clonetiler_value_changed), (gpointer) attr);
1430         if (exponent)
1431             g_object_set_data (G_OBJECT(sb), "oneable", GINT_TO_POINTER(TRUE));
1432         else
1433             g_object_set_data (G_OBJECT(sb), "zeroable", GINT_TO_POINTER(TRUE));
1434     }
1436     {
1437         GtkWidget *l = gtk_label_new ("");
1438         gtk_label_set_markup (GTK_LABEL(l), suffix);
1439         gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0);
1440         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
1441     }
1443     return hb;
1446 static void
1447 clonetiler_symgroup_changed( GtkMenuItem */*item*/, gpointer data )
1449     gint group_new = GPOINTER_TO_INT (data);
1450     prefs_set_int_attribute ( prefs_path, "symmetrygroup", group_new );
1453 static void
1454 clonetiler_xy_changed (GtkAdjustment *adj, gpointer data)
1456     const gchar *pref = (const gchar *) data;
1457     prefs_set_int_attribute (prefs_path, pref, (int) floor(adj->value + 0.5));
1460 static void
1461 clonetiler_keep_bbox_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1463     prefs_set_int_attribute (prefs_path, "keepbbox", gtk_toggle_button_get_active (tb));
1466 static void
1467 clonetiler_pick_to (GtkToggleButton *tb, gpointer data)
1469     const gchar *pref = (const gchar *) data;
1470     prefs_set_int_attribute (prefs_path, pref, gtk_toggle_button_get_active (tb));
1474 static void
1475 clonetiler_reset_recursive (GtkWidget *w)
1477     if (w && GTK_IS_OBJECT(w)) {
1478         {
1479             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "zeroable"));
1480             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1481                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1482                 gtk_adjustment_set_value (a, 0);
1483             }
1484         }
1485         {
1486             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "oneable"));
1487             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1488                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1489                 gtk_adjustment_set_value (a, 1);
1490             }
1491         }
1492         {
1493             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "uncheckable"));
1494             if (r && GTK_IS_TOGGLE_BUTTON(w)) { // checkbox
1495                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(w), FALSE);
1496             }
1497         }
1498     }
1500     if (GTK_IS_CONTAINER(w)) {
1501         GList *ch = gtk_container_get_children (GTK_CONTAINER(w));
1502         for (GList *i = ch; i != NULL; i = i->next) {
1503             clonetiler_reset_recursive (GTK_WIDGET(i->data));
1504         }
1505         g_list_free (ch);
1506     }
1509 static void
1510 clonetiler_reset( GtkWidget */*widget*/, void * )
1512     clonetiler_reset_recursive (dlg);
1515 static void
1516 clonetiler_table_attach (GtkWidget *table, GtkWidget *widget, float align, int row, int col)
1518     GtkWidget *a = gtk_alignment_new (align, 0, 0, 0);
1519     gtk_container_add(GTK_CONTAINER(a), widget);
1520     gtk_table_attach ( GTK_TABLE (table), a, col, col + 1, row, row + 1, (GtkAttachOptions)4, (GtkAttachOptions)0, 0, 0 );
1523 static GtkWidget *
1524 clonetiler_table_x_y_rand (int values)
1526     GtkWidget *table = gtk_table_new (values + 2, 5, FALSE);
1527     gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
1528     gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1529     gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1531     {
1532         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1534         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "clonetiler_per_row");
1535         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1537         GtkWidget *l = gtk_label_new ("");
1538         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per row:</small>"));
1539         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1541         clonetiler_table_attach (table, hb, 0, 1, 2);
1542     }
1544     {
1545         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1547         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "clonetiler_per_column");
1548         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1550         GtkWidget *l = gtk_label_new ("");
1551         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per column:</small>"));
1552         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1554         clonetiler_table_attach (table, hb, 0, 1, 3);
1555     }
1557     {
1558         GtkWidget *l = gtk_label_new ("");
1559         gtk_label_set_markup (GTK_LABEL(l), _("<small>Randomize:</small>"));
1560         clonetiler_table_attach (table, l, 0, 1, 4);
1561     }
1563     return table;
1566 static void
1567 clonetiler_pick_switched( GtkToggleButton */*tb*/, gpointer data )
1569     guint v = GPOINTER_TO_INT (data);
1570     prefs_set_int_attribute (prefs_path, "pick", v);
1574 static void
1575 clonetiler_switch_to_create( GtkToggleButton */*tb*/, GtkWidget *dlg )
1577     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1578     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1580     if (rowscols) {
1581         gtk_widget_set_sensitive (rowscols, TRUE);
1582     }
1583     if (widthheight) {
1584         gtk_widget_set_sensitive (widthheight, FALSE);
1585     }
1587     prefs_set_int_attribute (prefs_path, "fillrect", 0);
1591 static void
1592 clonetiler_switch_to_fill( GtkToggleButton */*tb*/, GtkWidget *dlg )
1594     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1595     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1597     if (rowscols) {
1598         gtk_widget_set_sensitive (rowscols, FALSE);
1599     }
1600     if (widthheight) {
1601         gtk_widget_set_sensitive (widthheight, TRUE);
1602     }
1604     prefs_set_int_attribute (prefs_path, "fillrect", 1);
1610 static void
1611 clonetiler_fill_width_changed (GtkAdjustment *adj, GtkWidget *u)
1613     gdouble const raw_dist = adj->value;
1614     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1615     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1617     prefs_set_double_attribute (prefs_path, "fillwidth", pixels);
1620 static void
1621 clonetiler_fill_height_changed (GtkAdjustment *adj, GtkWidget *u)
1623     gdouble const raw_dist = adj->value;
1624     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1625     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1627     prefs_set_double_attribute (prefs_path, "fillheight", pixels);
1631 static void
1632 clonetiler_do_pick_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1634     GtkWidget *vvb = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "dotrace");
1636     prefs_set_int_attribute (prefs_path, "dotrace", gtk_toggle_button_get_active (tb));
1638     if (vvb)
1639         gtk_widget_set_sensitive (vvb, gtk_toggle_button_get_active (tb));
1645 void
1646 clonetiler_dialog (void)
1648     if (!dlg)
1649     {
1650         gchar title[500];
1651         sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_CLONETILER), title);
1653         dlg = sp_window_new (title, TRUE);
1654         if (x == -1000 || y == -1000) {
1655             x = prefs_get_int_attribute (prefs_path, "x", -1000);
1656             y = prefs_get_int_attribute (prefs_path, "y", -1000);
1657         }
1659         if (w ==0 || h == 0) {
1660             w = prefs_get_int_attribute (prefs_path, "w", 0);
1661             h = prefs_get_int_attribute (prefs_path, "h", 0);
1662         }
1664 //        if (x<0) x=0;
1665 //        if (y<0) y=0;
1667         if (w && h) {
1668             gtk_window_resize ((GtkWindow *) dlg, w, h);
1669         }
1670         if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) {
1671             gtk_window_move ((GtkWindow *) dlg, x, y);
1673         } else {
1674             gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
1675         }
1678         sp_transientize (dlg);
1679         wd.win = dlg;
1680         wd.stop = 0;
1683         gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);
1685         gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (clonetiler_dialog_destroy), dlg);
1686         gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (clonetiler_dialog_delete), dlg);
1688         if (Inkscape::NSApplication::Application::getNewGui())
1689         {
1690             _shutdown_connection = Inkscape::NSApplication::Editor::connectShutdown (&on_delete);
1691             _dialogs_hidden_connection = Inkscape::NSApplication::Editor::connectDialogsHidden (sigc::bind (&on_dialog_hide, dlg));
1692             _dialogs_unhidden_connection = Inkscape::NSApplication::Editor::connectDialogsUnhidden (sigc::bind (&on_dialog_unhide, dlg));
1693             _desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::bind (&on_transientize, &wd));
1694         } else {
1695             g_signal_connect   ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (clonetiler_dialog_delete), dlg);
1696             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg);
1697             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg);
1698             g_signal_connect   ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd);
1699         }
1701         GtkTooltips *tt = gtk_tooltips_new();
1703         GtkWidget *mainbox = gtk_vbox_new(FALSE, 4);
1704         gtk_container_set_border_width (GTK_CONTAINER (mainbox), 6);
1705         gtk_container_add (GTK_CONTAINER (dlg), mainbox);
1707         GtkWidget *nb = gtk_notebook_new ();
1708         gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0);
1711 // Symmetry
1712         {
1713             GtkWidget *vb = clonetiler_new_tab (nb, _("_Symmetry"));
1715             GtkWidget *om = gtk_option_menu_new ();
1716             /* TRANSLATORS: For the following 17 symmetry groups, see
1717              * http://www.bib.ulb.ac.be/coursmath/doc/17.htm (visual examples);
1718              * http://www.clarku.edu/~djoyce/wallpaper/seventeen.html (English vocabulary); or
1719              * http://membres.lycos.fr/villemingerard/Geometri/Sym1D.htm (French vocabulary).
1720              */
1721             gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), om, _("Select one of the 17 symmetry groups for the tiling"), NULL);
1722             gtk_box_pack_start (GTK_BOX (vb), om, FALSE, FALSE, SB_MARGIN);
1724             GtkWidget *m = gtk_menu_new ();
1725             int current = prefs_get_int_attribute (prefs_path, "symmetrygroup", 0);
1727             struct SymGroups {
1728                 int group;
1729                 gchar const *label;
1730             } const sym_groups[] = {
1731                 // TRANSLATORS: "translation" means "shift" / "displacement" here.
1732                 {TILE_P1, _("<b>P1</b>: simple translation")},
1733                 {TILE_P2, _("<b>P2</b>: 180&#176; rotation")},
1734                 {TILE_PM, _("<b>PM</b>: reflection")},
1735                 // TRANSLATORS: "glide reflection" is a reflection and a translation combined.
1736                 //  For more info, see http://mathforum.org/sum95/suzanne/symsusan.html
1737                 {TILE_PG, _("<b>PG</b>: glide reflection")},
1738                 {TILE_CM, _("<b>CM</b>: reflection + glide reflection")},
1739                 {TILE_PMM, _("<b>PMM</b>: reflection + reflection")},
1740                 {TILE_PMG, _("<b>PMG</b>: reflection + 180&#176; rotation")},
1741                 {TILE_PGG, _("<b>PGG</b>: glide reflection + 180&#176; rotation")},
1742                 {TILE_CMM, _("<b>CMM</b>: reflection + reflection + 180&#176; rotation")},
1743                 {TILE_P4, _("<b>P4</b>: 90&#176; rotation")},
1744                 {TILE_P4M, _("<b>P4M</b>: 90&#176; rotation + 45&#176; reflection")},
1745                 {TILE_P4G, _("<b>P4G</b>: 90&#176; rotation + 90&#176; reflection")},
1746                 {TILE_P3, _("<b>P3</b>: 120&#176; rotation")},
1747                 {TILE_P31M, _("<b>P31M</b>: reflection + 120&#176; rotation, dense")},
1748                 {TILE_P3M1, _("<b>P3M1</b>: reflection + 120&#176; rotation, sparse")},
1749                 {TILE_P6, _("<b>P6</b>: 60&#176; rotation")},
1750                 {TILE_P6M, _("<b>P6M</b>: reflection + 60&#176; rotation")},
1751             };
1753             for (unsigned j = 0; j < G_N_ELEMENTS(sym_groups); ++j) {
1754                 SymGroups const &sg = sym_groups[j];
1756                 GtkWidget *l = gtk_label_new ("");
1757                 gtk_label_set_markup (GTK_LABEL(l), sg.label);
1758                 gtk_misc_set_alignment (GTK_MISC(l), 0, 0.5);
1760                 GtkWidget *item = gtk_menu_item_new ();
1761                 gtk_container_add (GTK_CONTAINER (item), l);
1763                 gtk_signal_connect ( GTK_OBJECT (item), "activate",
1764                                      GTK_SIGNAL_FUNC (clonetiler_symgroup_changed),
1765                                      GINT_TO_POINTER (sg.group) );
1767                 gtk_menu_append (GTK_MENU (m), item);
1768             }
1770             gtk_option_menu_set_menu (GTK_OPTION_MENU (om), m);
1771             gtk_option_menu_set_history ( GTK_OPTION_MENU (om), current);
1772         }
1774         table_row_labels = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1776 // Shift
1777         {
1778             GtkWidget *vb = clonetiler_new_tab (nb, _("S_hift"));
1780             GtkWidget *table = clonetiler_table_x_y_rand (3);
1781             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1783             // X
1784             {
1785                 GtkWidget *l = gtk_label_new ("");
1786                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) horizontally by this amount
1787                     // xgettext:no-c-format
1788                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift X:</b>"));
1789                 gtk_size_group_add_widget(table_row_labels, l);
1790                 clonetiler_table_attach (table, l, 1, 2, 1);
1791             }
1793             {
1794                 GtkWidget *l = clonetiler_spinbox (tt,
1795                     // xgettext:no-c-format
1796                                                    _("Horizontal shift per row (in % of tile width)"), "d_x_per_y",
1797                                                    -100, 1000, "%");
1798                 clonetiler_table_attach (table, l, 0, 2, 2);
1799             }
1801             {
1802                 GtkWidget *l = clonetiler_spinbox (tt,
1803                     // xgettext:no-c-format
1804                                                    _("Horizontal shift per column (in % of tile width)"), "d_x_per_x",
1805                                                    -100, 1000, "%");
1806                 clonetiler_table_attach (table, l, 0, 2, 3);
1807             }
1809             {
1810                 GtkWidget *l = clonetiler_spinbox (tt,
1811                                                    _("Randomize the horizontal shift by this percentage"), "rand_x",
1812                                                    0, 1000, "%");
1813                 clonetiler_table_attach (table, l, 0, 2, 4);
1814             }
1816             // Y
1817             {
1818                 GtkWidget *l = gtk_label_new ("");
1819                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) vertically by this amount
1820                     // xgettext:no-c-format
1821                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift Y:</b>"));
1822                 gtk_size_group_add_widget(table_row_labels, l);
1823                 clonetiler_table_attach (table, l, 1, 3, 1);
1824             }
1826             {
1827                 GtkWidget *l = clonetiler_spinbox (tt,
1828                     // xgettext:no-c-format
1829                                                    _("Vertical shift per row (in % of tile height)"), "d_y_per_y",
1830                                                    -100, 1000, "%");
1831                 clonetiler_table_attach (table, l, 0, 3, 2);
1832             }
1834             {
1835                 GtkWidget *l = clonetiler_spinbox (tt,
1836                     // xgettext:no-c-format
1837                                                    _("Vertical shift per column (in % of tile height)"), "d_y_per_x",
1838                                                    -100, 1000, "%");
1839                 clonetiler_table_attach (table, l, 0, 3, 3);
1840             }
1842             {
1843                 GtkWidget *l = clonetiler_spinbox (tt,
1844                                                    _("Randomize the vertical shift by this percentage"), "rand_y",
1845                                                    0, 1000, "%");
1846                 clonetiler_table_attach (table, l, 0, 3, 4);
1847             }
1849             // Exponent
1850             {
1851                 GtkWidget *l = gtk_label_new ("");
1852                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
1853                 gtk_size_group_add_widget(table_row_labels, l);
1854                 clonetiler_table_attach (table, l, 1, 4, 1);
1855             }
1857             {
1858                 GtkWidget *l = clonetiler_spinbox (tt,
1859                                                    _("Whether rows are spaced evenly (1), converge (<1) or diverge (>1)"), "d_per_y_exp",
1860                                                    0, 10, "", true);
1861                 clonetiler_table_attach (table, l, 0, 4, 2);
1862             }
1864             {
1865                 GtkWidget *l = clonetiler_spinbox (tt,
1866                                                    _("Whether columns are spaced evenly (1), converge (<1) or diverge (>1)"), "d_per_x_exp",
1867                                                    0, 10, "", true);
1868                 clonetiler_table_attach (table, l, 0, 4, 3);
1869             }
1871             { // alternates
1872                 GtkWidget *l = gtk_label_new ("");
1873                 // TRANSLATORS: "Alternate" is a verb here
1874                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
1875                 gtk_size_group_add_widget(table_row_labels, l);
1876                 clonetiler_table_attach (table, l, 1, 5, 1);
1877             }
1879             {
1880                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each row"), "alternate_y");
1881                 clonetiler_table_attach (table, l, 0, 5, 2);
1882             }
1884             {
1885                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each column"), "alternate_x");
1886                 clonetiler_table_attach (table, l, 0, 5, 3);
1887             }
1889         }
1892 // Scale
1893         {
1894             GtkWidget *vb = clonetiler_new_tab (nb, _("Sc_ale"));
1896             GtkWidget *table = clonetiler_table_x_y_rand (2);
1897             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1899             // X
1900             {
1901                 GtkWidget *l = gtk_label_new ("");
1902                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale X:</b>"));
1903                 gtk_size_group_add_widget(table_row_labels, l);
1904                 clonetiler_table_attach (table, l, 1, 2, 1);
1905             }
1907             {
1908                 GtkWidget *l = clonetiler_spinbox (tt,
1909                     // xgettext:no-c-format
1910                                                    _("Horizontal scale per row (in % of tile width)"), "d_scalex_per_y",
1911                                                    -100, 1000, "%");
1912                 clonetiler_table_attach (table, l, 0, 2, 2);
1913             }
1915             {
1916                 GtkWidget *l = clonetiler_spinbox (tt,
1917                     // xgettext:no-c-format
1918                                                    _("Horizontal scale per column (in % of tile width)"), "d_scalex_per_x",
1919                                                    -100, 1000, "%");
1920                 clonetiler_table_attach (table, l, 0, 2, 3);
1921             }
1923             {
1924                 GtkWidget *l = clonetiler_spinbox (tt,
1925                                                    _("Randomize the horizontal scale by this percentage"), "rand_scalex",
1926                                                    0, 1000, "%");
1927                 clonetiler_table_attach (table, l, 0, 2, 4);
1928             }
1930             // Y
1931             {
1932                 GtkWidget *l = gtk_label_new ("");
1933                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale Y:</b>"));
1934                 gtk_size_group_add_widget(table_row_labels, l);
1935                 clonetiler_table_attach (table, l, 1, 3, 1);
1936             }
1938             {
1939                 GtkWidget *l = clonetiler_spinbox (tt,
1940                     // xgettext:no-c-format
1941                                                    _("Vertical scale per row (in % of tile height)"), "d_scaley_per_y",
1942                                                    -100, 1000, "%");
1943                 clonetiler_table_attach (table, l, 0, 3, 2);
1944             }
1946             {
1947                 GtkWidget *l = clonetiler_spinbox (tt,
1948                     // xgettext:no-c-format
1949                                                    _("Vertical scale per column (in % of tile height)"), "d_scaley_per_x",
1950                                                    -100, 1000, "%");
1951                 clonetiler_table_attach (table, l, 0, 3, 3);
1952             }
1954             {
1955                 GtkWidget *l = clonetiler_spinbox (tt,
1956                                                    _("Randomize the vertical scale by this percentage"), "rand_scaley",
1957                                                    0, 1000, "%");
1958                 clonetiler_table_attach (table, l, 0, 3, 4);
1959             }
1961             { // alternates
1962                 GtkWidget *l = gtk_label_new ("");
1963                 // TRANSLATORS: "Alternate" is a verb here
1964                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
1965                 gtk_size_group_add_widget(table_row_labels, l);
1966                 clonetiler_table_attach (table, l, 1, 4, 1);
1967             }
1969             {
1970                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each row"), "alternate_scaley");
1971                 clonetiler_table_attach (table, l, 0, 4, 2);
1972             }
1974             {
1975                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each column"), "alternate_scalex");
1976                 clonetiler_table_attach (table, l, 0, 4, 3);
1977             }
1979         }
1982 // Rotation
1983         {
1984             GtkWidget *vb = clonetiler_new_tab (nb, _("_Rotation"));
1986             GtkWidget *table = clonetiler_table_x_y_rand (1);
1987             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1989             // Angle
1990             {
1991                 GtkWidget *l = gtk_label_new ("");
1992                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Angle:</b>"));
1993                 gtk_size_group_add_widget(table_row_labels, l);
1994                 clonetiler_table_attach (table, l, 1, 2, 1);
1995             }
1997             {
1998                 GtkWidget *l = clonetiler_spinbox (tt,
1999                     // xgettext:no-c-format
2000                                                    _("Rotate tiles by this angle for each row"), "d_rot_per_y",
2001                                                    -180, 180, "&#176;");
2002                 clonetiler_table_attach (table, l, 0, 2, 2);
2003             }
2005             {
2006                 GtkWidget *l = clonetiler_spinbox (tt,
2007                     // xgettext:no-c-format
2008                                                    _("Rotate tiles by this angle for each column"), "d_rot_per_x",
2009                                                    -180, 180, "&#176;");
2010                 clonetiler_table_attach (table, l, 0, 2, 3);
2011             }
2013             {
2014                 GtkWidget *l = clonetiler_spinbox (tt,
2015                                                    _("Randomize the rotation angle by this percentage"), "rand_rot",
2016                                                    0, 100, "%");
2017                 clonetiler_table_attach (table, l, 0, 2, 4);
2018             }
2020             { // alternates
2021                 GtkWidget *l = gtk_label_new ("");
2022                 // TRANSLATORS: "Alternate" is a verb here
2023                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2024                 gtk_size_group_add_widget(table_row_labels, l);
2025                 clonetiler_table_attach (table, l, 1, 3, 1);
2026             }
2028             {
2029                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each row"), "alternate_roty");
2030                 clonetiler_table_attach (table, l, 0, 3, 2);
2031             }
2033             {
2034                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each column"), "alternate_rotx");
2035                 clonetiler_table_attach (table, l, 0, 3, 3);
2036             }
2037         }
2040 // Blur and opacity
2041         {
2042             GtkWidget *vb = clonetiler_new_tab (nb, _("_Blur & opacity"));
2044             GtkWidget *table = clonetiler_table_x_y_rand (1);
2045             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2048             // Blur
2049             {
2050                 GtkWidget *l = gtk_label_new ("");
2051                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Blur:</b>"));
2052                 gtk_size_group_add_widget(table_row_labels, l);
2053                 clonetiler_table_attach (table, l, 1, 2, 1);
2054             }
2056             {
2057                 GtkWidget *l = clonetiler_spinbox (tt,
2058                                                    _("Blur tiles by this percentage for each row"), "d_blur_per_y",
2059                                                    0, 100, "%");
2060                 clonetiler_table_attach (table, l, 0, 2, 2);
2061             }
2063             {
2064                 GtkWidget *l = clonetiler_spinbox (tt,
2065                                                    _("Blur tiles by this percentage for each column"), "d_blur_per_x",
2066                                                    0, 100, "%");
2067                 clonetiler_table_attach (table, l, 0, 2, 3);
2068             }
2070             {
2071                 GtkWidget *l = clonetiler_spinbox (tt,
2072                                                    _("Randomize the tile blur by this percentage"), "rand_blur",
2073                                                    0, 100, "%");
2074                 clonetiler_table_attach (table, l, 0, 2, 4);
2075             }
2077             { // alternates
2078                 GtkWidget *l = gtk_label_new ("");
2079                 // TRANSLATORS: "Alternate" is a verb here
2080                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2081                 gtk_size_group_add_widget(table_row_labels, l);
2082                 clonetiler_table_attach (table, l, 1, 3, 1);
2083             }
2085             {
2086                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each row"), "alternate_blury");
2087                 clonetiler_table_attach (table, l, 0, 3, 2);
2088             }
2090             {
2091                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each column"), "alternate_blurx");
2092                 clonetiler_table_attach (table, l, 0, 3, 3);
2093             }
2097             // Dissolve
2098             {
2099                 GtkWidget *l = gtk_label_new ("");
2100                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Fade out:</b>"));
2101                 gtk_size_group_add_widget(table_row_labels, l);
2102                 clonetiler_table_attach (table, l, 1, 4, 1);
2103             }
2105             {
2106                 GtkWidget *l = clonetiler_spinbox (tt,
2107                                                    _("Decrease tile opacity by this percentage for each row"), "d_opacity_per_y",
2108                                                    0, 100, "%");
2109                 clonetiler_table_attach (table, l, 0, 4, 2);
2110             }
2112             {
2113                 GtkWidget *l = clonetiler_spinbox (tt,
2114                                                    _("Decrease tile opacity by this percentage for each column"), "d_opacity_per_x",
2115                                                    0, 100, "%");
2116                 clonetiler_table_attach (table, l, 0, 4, 3);
2117             }
2119             {
2120                 GtkWidget *l = clonetiler_spinbox (tt,
2121                                                    _("Randomize the tile opacity by this percentage"), "rand_opacity",
2122                                                    0, 100, "%");
2123                 clonetiler_table_attach (table, l, 0, 4, 4);
2124             }
2126             { // alternates
2127                 GtkWidget *l = gtk_label_new ("");
2128                 // TRANSLATORS: "Alternate" is a verb here
2129                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2130                 gtk_size_group_add_widget(table_row_labels, l);
2131                 clonetiler_table_attach (table, l, 1, 5, 1);
2132             }
2134             {
2135                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each row"), "alternate_opacityy");
2136                 clonetiler_table_attach (table, l, 0, 5, 2);
2137             }
2139             {
2140                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each column"), "alternate_opacityx");
2141                 clonetiler_table_attach (table, l, 0, 5, 3);
2142             }
2143         }
2146 // Color
2147         {
2148             GtkWidget *vb = clonetiler_new_tab (nb, _("Co_lor"));
2150             {
2151             GtkWidget *hb = gtk_hbox_new (FALSE, 0);
2153             GtkWidget *l = gtk_label_new (_("Initial color: "));
2154             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2156             guint32 rgba = 0x000000ff | sp_svg_read_color (prefs_get_string_attribute(prefs_path, "initial_color"), 0x000000ff);
2157             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);
2158             _color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed));
2160             gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast<GtkWidget*>(color_picker->gobj()), FALSE, FALSE, 0);
2162             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2163             }
2166             GtkWidget *table = clonetiler_table_x_y_rand (3);
2167             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2169             // Hue
2170             {
2171                 GtkWidget *l = gtk_label_new ("");
2172                 gtk_label_set_markup (GTK_LABEL(l), _("<b>H:</b>"));
2173                 gtk_size_group_add_widget(table_row_labels, l);
2174                 clonetiler_table_attach (table, l, 1, 2, 1);
2175             }
2177             {
2178                 GtkWidget *l = clonetiler_spinbox (tt,
2179                                                    _("Change the tile hue by this percentage for each row"), "d_hue_per_y",
2180                                                    -100, 100, "%");
2181                 clonetiler_table_attach (table, l, 0, 2, 2);
2182             }
2184             {
2185                 GtkWidget *l = clonetiler_spinbox (tt,
2186                                                    _("Change the tile hue by this percentage for each column"), "d_hue_per_x",
2187                                                    -100, 100, "%");
2188                 clonetiler_table_attach (table, l, 0, 2, 3);
2189             }
2191             {
2192                 GtkWidget *l = clonetiler_spinbox (tt,
2193                                                    _("Randomize the tile hue by this percentage"), "rand_hue",
2194                                                    0, 100, "%");
2195                 clonetiler_table_attach (table, l, 0, 2, 4);
2196             }
2199             // Saturation
2200             {
2201                 GtkWidget *l = gtk_label_new ("");
2202                 gtk_label_set_markup (GTK_LABEL(l), _("<b>S:</b>"));
2203                 gtk_size_group_add_widget(table_row_labels, l);
2204                 clonetiler_table_attach (table, l, 1, 3, 1);
2205             }
2207             {
2208                 GtkWidget *l = clonetiler_spinbox (tt,
2209                                                    _("Change the color saturation by this percentage for each row"), "d_saturation_per_y",
2210                                                    -100, 100, "%");
2211                 clonetiler_table_attach (table, l, 0, 3, 2);
2212             }
2214             {
2215                 GtkWidget *l = clonetiler_spinbox (tt,
2216                                                    _("Change the color saturation by this percentage for each column"), "d_saturation_per_x",
2217                                                    -100, 100, "%");
2218                 clonetiler_table_attach (table, l, 0, 3, 3);
2219             }
2221             {
2222                 GtkWidget *l = clonetiler_spinbox (tt,
2223                                                    _("Randomize the color saturation by this percentage"), "rand_saturation",
2224                                                    0, 100, "%");
2225                 clonetiler_table_attach (table, l, 0, 3, 4);
2226             }
2228             // Lightness
2229             {
2230                 GtkWidget *l = gtk_label_new ("");
2231                 gtk_label_set_markup (GTK_LABEL(l), _("<b>L:</b>"));
2232                 gtk_size_group_add_widget(table_row_labels, l);
2233                 clonetiler_table_attach (table, l, 1, 4, 1);
2234             }
2236             {
2237                 GtkWidget *l = clonetiler_spinbox (tt,
2238                                                    _("Change the color lightness by this percentage for each row"), "d_lightness_per_y",
2239                                                    -100, 100, "%");
2240                 clonetiler_table_attach (table, l, 0, 4, 2);
2241             }
2243             {
2244                 GtkWidget *l = clonetiler_spinbox (tt,
2245                                                    _("Change the color lightness by this percentage for each column"), "d_lightness_per_x",
2246                                                    -100, 100, "%");
2247                 clonetiler_table_attach (table, l, 0, 4, 3);
2248             }
2250             {
2251                 GtkWidget *l = clonetiler_spinbox (tt,
2252                                                    _("Randomize the color lightness by this percentage"), "rand_lightness",
2253                                                    0, 100, "%");
2254                 clonetiler_table_attach (table, l, 0, 4, 4);
2255             }
2258             { // alternates
2259                 GtkWidget *l = gtk_label_new ("");
2260                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2261                 gtk_size_group_add_widget(table_row_labels, l);
2262                 clonetiler_table_attach (table, l, 1, 5, 1);
2263             }
2265             {
2266                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each row"), "alternate_color_y");
2267                 clonetiler_table_attach (table, l, 0, 5, 2);
2268             }
2270             {
2271                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each column"), "alternate_color_x");
2272                 clonetiler_table_attach (table, l, 0, 5, 3);
2273             }
2275         }
2277 // Trace
2278         {
2279             GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace"));
2282         {
2283             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2284             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2286             GtkWidget *b  = gtk_check_button_new_with_label (_("Trace the drawing under the tiles"));
2287             g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
2288             gint old = prefs_get_int_attribute (prefs_path, "dotrace", 0);
2289             gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2290             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);
2291             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2293             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2294                                GTK_SIGNAL_FUNC(clonetiler_do_pick_toggled), dlg);
2295         }
2297         {
2298             GtkWidget *vvb = gtk_vbox_new (FALSE, 0);
2299             gtk_box_pack_start (GTK_BOX (vb), vvb, FALSE, FALSE, 0);
2300             g_object_set_data (G_OBJECT(dlg), "dotrace", (gpointer) vvb);
2303             {
2304                 GtkWidget *frame = gtk_frame_new (_("1. Pick from the drawing:"));
2305                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2307                 GtkWidget *table = gtk_table_new (3, 3, FALSE);
2308                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2309                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2310                 gtk_container_add(GTK_CONTAINER(frame), table);
2313                 GtkWidget* radio;
2314                 {
2315                     radio = gtk_radio_button_new_with_label (NULL, _("Color"));
2316                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the visible color and opacity"), NULL);
2317                     clonetiler_table_attach (table, radio, 0.0, 1, 1);
2318                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2319                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_COLOR));
2320                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_COLOR);
2321                 }
2322                 {
2323                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Opacity"));
2324                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the total accumulated opacity"), NULL);
2325                     clonetiler_table_attach (table, radio, 0.0, 2, 1);
2326                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2327                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_OPACITY));
2328                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_OPACITY);
2329                 }
2330                 {
2331                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("R"));
2332                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Red component of the color"), NULL);
2333                     clonetiler_table_attach (table, radio, 0.0, 1, 2);
2334                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2335                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_R));
2336                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_R);
2337                 }
2338                 {
2339                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("G"));
2340                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Green component of the color"), NULL);
2341                     clonetiler_table_attach (table, radio, 0.0, 2, 2);
2342                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2343                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_G));
2344                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_G);
2345                 }
2346                 {
2347                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("B"));
2348                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Blue component of the color"), NULL);
2349                     clonetiler_table_attach (table, radio, 0.0, 3, 2);
2350                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2351                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_B));
2352                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_B);
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|H"));
2358                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the hue of the color"), NULL);
2359                     clonetiler_table_attach (table, radio, 0.0, 1, 3);
2360                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2361                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_H));
2362                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_H);
2363                 }
2364                 {
2365                     //TRANSLATORS: only translate "string" in "context|string".
2366                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2367                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|S"));
2368                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the saturation of the color"), NULL);
2369                     clonetiler_table_attach (table, radio, 0.0, 2, 3);
2370                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2371                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_S));
2372                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_S);
2373                 }
2374                 {
2375                     //TRANSLATORS: only translate "string" in "context|string".
2376                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2377                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|L"));
2378                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the lightness of the color"), NULL);
2379                     clonetiler_table_attach (table, radio, 0.0, 3, 3);
2380                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2381                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_L));
2382                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_L);
2383                 }
2385             }
2387             {
2388                 GtkWidget *frame = gtk_frame_new (_("2. Tweak the picked value:"));
2389                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, VB_MARGIN);
2391                 GtkWidget *table = gtk_table_new (4, 2, FALSE);
2392                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2393                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2394                 gtk_container_add(GTK_CONTAINER(frame), table);
2396                 {
2397                     GtkWidget *l = gtk_label_new ("");
2398                     gtk_label_set_markup (GTK_LABEL(l), _("Gamma-correct:"));
2399                     clonetiler_table_attach (table, l, 1.0, 1, 1);
2400                 }
2401                 {
2402                     GtkWidget *l = clonetiler_spinbox (tt,
2403                                                        _("Shift the mid-range of the picked value upwards (>0) or downwards (<0)"), "gamma_picked",
2404                                                        -10, 10, "");
2405                     clonetiler_table_attach (table, l, 0.0, 1, 2);
2406                 }
2408                 {
2409                     GtkWidget *l = gtk_label_new ("");
2410                     gtk_label_set_markup (GTK_LABEL(l), _("Randomize:"));
2411                     clonetiler_table_attach (table, l, 1.0, 1, 3);
2412                 }
2413                 {
2414                     GtkWidget *l = clonetiler_spinbox (tt,
2415                                                        _("Randomize the picked value by this percentage"), "rand_picked",
2416                                                        0, 100, "%");
2417                     clonetiler_table_attach (table, l, 0.0, 1, 4);
2418                 }
2420                 {
2421                     GtkWidget *l = gtk_label_new ("");
2422                     gtk_label_set_markup (GTK_LABEL(l), _("Invert:"));
2423                     clonetiler_table_attach (table, l, 1.0, 2, 1);
2424                 }
2425                 {
2426                     GtkWidget *l = clonetiler_checkbox (tt, _("Invert the picked value"), "invert_picked");
2427                     clonetiler_table_attach (table, l, 0.0, 2, 2);
2428                 }
2429             }
2431             {
2432                 GtkWidget *frame = gtk_frame_new (_("3. Apply the value to the clones':"));
2433                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2436                 GtkWidget *table = gtk_table_new (2, 2, FALSE);
2437                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2438                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2439                 gtk_container_add(GTK_CONTAINER(frame), table);
2441                 {
2442                     GtkWidget *b  = gtk_check_button_new_with_label (_("Presence"));
2443                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_presence", 1);
2444                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2445                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone is created with the probability determined by the picked value in that point"), NULL);
2446                     clonetiler_table_attach (table, b, 0.0, 1, 1);
2447                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2448                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_presence");
2449                 }
2451                 {
2452                     GtkWidget *b  = gtk_check_button_new_with_label (_("Size"));
2453                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_size", 0);
2454                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2455                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's size is determined by the picked value in that point"), NULL);
2456                     clonetiler_table_attach (table, b, 0.0, 2, 1);
2457                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2458                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_size");
2459                 }
2461                 {
2462                     GtkWidget *b  = gtk_check_button_new_with_label (_("Color"));
2463                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_color", 0);
2464                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2465                     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);
2466                     clonetiler_table_attach (table, b, 0.0, 1, 2);
2467                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2468                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_color");
2469                 }
2471                 {
2472                     GtkWidget *b  = gtk_check_button_new_with_label (_("Opacity"));
2473                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_opacity", 0);
2474                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2475                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's opacity is determined by the picked value in that point"), NULL);
2476                     clonetiler_table_attach (table, b, 0.0, 2, 2);
2477                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2478                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_opacity");
2479                 }
2480             }
2481            gtk_widget_set_sensitive (vvb, prefs_get_int_attribute (prefs_path, "dotrace", 0));
2482         }
2483         }
2485 // Rows/columns, width/height
2486         {
2487             GtkWidget *table = gtk_table_new (2, 2, FALSE);
2488             gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
2489             gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2490             gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2491             gtk_box_pack_start (GTK_BOX (mainbox), table, FALSE, FALSE, 0);
2493             {
2494                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2495                 g_object_set_data (G_OBJECT(dlg), "rowscols", (gpointer) hb);
2497                 {
2498                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2499                     int value = prefs_get_int_attribute (prefs_path, "ymax", 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 rows 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) "ymax");
2508                 }
2510                 {
2511                     GtkWidget *l = gtk_label_new ("");
2512                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2513                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2514                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2515                 }
2517                 {
2518                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2519                     int value = prefs_get_int_attribute (prefs_path, "xmax", 2);
2520                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2521                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2522                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many columns in the tiling"), NULL);
2523                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2524                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2526                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2527                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "xmax");
2528                 }
2530                 clonetiler_table_attach (table, hb, 0.0, 1, 2);
2531             }
2533             {
2534                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2535                 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
2537                 // unitmenu
2538                 GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
2539                 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
2541                 {
2542                     // Width spinbutton
2543                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2544                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2546                     double value = prefs_get_double_attribute (prefs_path, "fillwidth", 50);
2547                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2548                     gdouble const units = sp_pixels_get_units (value, unit);
2549                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2551                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2552                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Width of the rectangle to be filled"), NULL);
2553                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2554                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2555                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2556                                        GTK_SIGNAL_FUNC(clonetiler_fill_width_changed), u);
2557                 }
2558                 {
2559                     GtkWidget *l = gtk_label_new ("");
2560                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2561                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2562                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2563                 }
2565                 {
2566                     // Height spinbutton
2567                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2568                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2570                     double value = prefs_get_double_attribute (prefs_path, "fillheight", 50);
2571                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2572                     gdouble const units = sp_pixels_get_units (value, unit);
2573                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2576                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2577                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Height of the rectangle to be filled"), NULL);
2578                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2579                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2580                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2581                                        GTK_SIGNAL_FUNC(clonetiler_fill_height_changed), u);
2582                 }
2584                 gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);
2585                 clonetiler_table_attach (table, hb, 0.0, 2, 2);
2587             }
2589             // Switch
2590             GtkWidget* radio;
2591             {
2592                 radio = gtk_radio_button_new_with_label (NULL, _("Rows, columns: "));
2593                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Create the specified number of rows and columns"), NULL);
2594                 clonetiler_table_attach (table, radio, 0.0, 1, 1);
2595                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_create), (gpointer) dlg);
2596             }
2597             if (prefs_get_int_attribute(prefs_path, "fillrect", 0) == 0) {
2598                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2599                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2600             }
2601             {
2602                 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Width, height: "));
2603                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Fill the specified width and height with the tiling"), NULL);
2604                 clonetiler_table_attach (table, radio, 0.0, 2, 1);
2605                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_fill), (gpointer) dlg);
2606             }
2607             if (prefs_get_int_attribute(prefs_path, "fillrect", 0) == 1) {
2608                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2609                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2610             }
2611         }
2614 // Use saved pos
2615         {
2616             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2617             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2619             GtkWidget *b  = gtk_check_button_new_with_label (_("Use saved size and position of the tile"));
2620             gint keepbbox = prefs_get_int_attribute (prefs_path, "keepbbox", 1);
2621             gtk_toggle_button_set_active ((GtkToggleButton *) b, keepbbox != 0);
2622             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);
2623             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2625             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2626                                GTK_SIGNAL_FUNC(clonetiler_keep_bbox_toggled), NULL);
2627         }
2629 // Statusbar
2630         {
2631             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2632             gtk_box_pack_end (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2633             GtkWidget *l = gtk_label_new("");
2634             g_object_set_data (G_OBJECT(dlg), "status", (gpointer) l);
2635             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2636         }
2638 // Buttons
2639         {
2640             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2641             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2643             {
2644                 GtkWidget *b = gtk_button_new ();
2645                 GtkWidget *l = gtk_label_new ("");
2646                 gtk_label_set_markup_with_mnemonic (GTK_LABEL(l), _(" <b>_Create</b> "));
2647                 gtk_container_add (GTK_CONTAINER(b), l);
2648                 gtk_tooltips_set_tip (tt, b, _("Create and tile the clones of the selection"), NULL);
2649                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_apply), NULL);
2650                 gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0);
2651             }
2653             { // buttons which are enabled only when there are tiled clones
2654                 GtkWidget *sb = gtk_hbox_new(FALSE, 0);
2655                 gtk_box_pack_end (GTK_BOX (hb), sb, FALSE, FALSE, 0);
2656                 g_object_set_data (G_OBJECT(dlg), "buttons_on_tiles", (gpointer) sb);
2657                 {
2658                     // TRANSLATORS: if a group of objects are "clumped" together, then they
2659                     //  are unevenly spread in the given amount of space - as shown in the
2660                     //  diagrams on the left in the following screenshot:
2661                     //  http://www.inkscape.org/screenshots/gallery/inkscape-0.42-CVS-tiles-unclump.png
2662                     //  So unclumping is the process of spreading a number of objects out more evenly.
2663                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" _Unclump "));
2664                     gtk_tooltips_set_tip (tt, b, _("Spread out clones to reduce clumping; can be applied repeatedly"), NULL);
2665                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_unclump), NULL);
2666                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2667                 }
2669                 {
2670                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" Re_move "));
2671                     gtk_tooltips_set_tip (tt, b, _("Remove existing tiled clones of the selected object (siblings only)"), NULL);
2672                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_remove), NULL);
2673                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2674                 }
2676                 // connect to global selection changed signal (so we can change desktops) and
2677                 // external_change (so we're not fooled by undo)
2678                 g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (clonetiler_change_selection), dlg);
2679                 g_signal_connect (G_OBJECT (INKSCAPE), "external_change", G_CALLBACK (clonetiler_external_change), dlg);
2680                 g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), G_OBJECT (INKSCAPE));
2682                 // update now
2683                 clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
2684             }
2686             {
2687                 GtkWidget *b = gtk_button_new_with_mnemonic (_(" R_eset "));
2688                 // TRANSLATORS: "change" is a noun here
2689                 gtk_tooltips_set_tip (tt, b, _("Reset all shifts, scales, rotates, opacity and color changes in the dialog to zero"), NULL);
2690                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_reset), NULL);
2691                 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2692             }
2693         }
2695         gtk_widget_show_all (mainbox);
2697     } // end of if (!dlg)
2699     gtk_window_present ((GtkWindow *) dlg);
2703 /*
2704   Local Variables:
2705   mode:c++
2706   c-file-style:"stroustrup"
2707   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2708   indent-tabs-mode:nil
2709   fill-column:99
2710   End:
2711 */
2712 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :