Code

From trunk
[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 "preferences.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 Glib::ustring const 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     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
128     prefs->setInt(prefs_path + "x", x);
129     prefs->setInt(prefs_path + "y", y);
130     prefs->setInt(prefs_path + "w", w);
131     prefs->setInt(prefs_path + "h", h);
133     return FALSE; // which means, go ahead and destroy it
137 static void on_delete()
139     (void)clonetiler_dialog_delete (0, 0, NULL);
142 static void
143 on_picker_color_changed (guint rgba)
145     static bool is_updating = false;
146     if (is_updating || !SP_ACTIVE_DESKTOP)
147         return;
149     is_updating = true;
151     gchar c[32];
152     sp_svg_write_color(c, sizeof(c), rgba);
153     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
154     prefs->setString(prefs_path + "initial_color", c);
156     is_updating = false;
159 static guint clonetiler_number_of_clones (SPObject *obj);
161 static void
162 clonetiler_change_selection (Inkscape::Application * /*inkscape*/, Inkscape::Selection *selection, GtkWidget *dlg)
164     GtkWidget *buttons = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "buttons_on_tiles");
165     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
167     if (selection->isEmpty()) {
168         gtk_widget_set_sensitive (buttons, FALSE);
169         gtk_label_set_markup (GTK_LABEL(status), _("<small>Nothing selected.</small>"));
170         return;
171     }
173     if (g_slist_length ((GSList *) selection->itemList()) > 1) {
174         gtk_widget_set_sensitive (buttons, FALSE);
175         gtk_label_set_markup (GTK_LABEL(status), _("<small>More than one object selected.</small>"));
176         return;
177     }
179     guint n = clonetiler_number_of_clones(selection->singleItem());
180     if (n > 0) {
181         gtk_widget_set_sensitive (buttons, TRUE);
182         gchar *sta = g_strdup_printf (_("<small>Object has <b>%d</b> tiled clones.</small>"), n);
183         gtk_label_set_markup (GTK_LABEL(status), sta);
184         g_free (sta);
185     } else {
186         gtk_widget_set_sensitive (buttons, FALSE);
187         gtk_label_set_markup (GTK_LABEL(status), _("<small>Object has no tiled clones.</small>"));
188     }
191 static void
192 clonetiler_external_change (Inkscape::Application * /*inkscape*/, GtkWidget *dlg)
194     clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
197 static void clonetiler_disconnect_gsignal (GObject *widget, gpointer source) {
198     if (source && G_IS_OBJECT(source))
199         sp_signal_disconnect_by_data (source, widget);
203 enum {
204     TILE_P1,
205     TILE_P2,
206     TILE_PM,
207     TILE_PG,
208     TILE_CM,
209     TILE_PMM,
210     TILE_PMG,
211     TILE_PGG,
212     TILE_CMM,
213     TILE_P4,
214     TILE_P4M,
215     TILE_P4G,
216     TILE_P3,
217     TILE_P31M,
218     TILE_P3M1,
219     TILE_P6,
220     TILE_P6M
221 };
224 static Geom::Matrix
225 clonetiler_get_transform (
227     // symmetry group
228     int type,
230     // row, column
231     int i, int j,
233     // center, width, height of the tile
234     double cx, double cy,
235     double w,  double h,
237     // values from the dialog:
238     // Shift
239     double shiftx_per_i,      double shifty_per_i,
240     double shiftx_per_j,      double shifty_per_j,
241     double shiftx_rand,       double shifty_rand,
242     double shiftx_exp,        double shifty_exp,
243     int    shiftx_alternate,  int    shifty_alternate,
244     int    shiftx_cumulate,   int    shifty_cumulate,
245     int    shiftx_excludew,   int    shifty_excludeh,
247     // Scale
248     double scalex_per_i,      double scaley_per_i,
249     double scalex_per_j,      double scaley_per_j,
250     double scalex_rand,       double scaley_rand,
251     double scalex_exp,        double scaley_exp,
252     double scalex_log,        double scaley_log,
253     int    scalex_alternate,  int    scaley_alternate,
254     int    scalex_cumulate,   int    scaley_cumulate,
256     // Rotation
257     double rotate_per_i,      double rotate_per_j,
258     double rotate_rand,
259     int    rotate_alternatei, int    rotate_alternatej,
260     int    rotate_cumulatei,  int    rotate_cumulatej
261     )
264     // Shift (in units of tile width or height) -------------
265     double delta_shifti = 0.0;
266     double delta_shiftj = 0.0;
268     if( shiftx_alternate ) {
269         delta_shifti = (double)(i%2);
270     } else {
271         if( shiftx_cumulate ) {  // Should the delta shifts be cumulative (i.e. 1, 1+2, 1+2+3, ...)
272             delta_shifti = (double)(i*i);
273         } else {
274             delta_shifti = (double)i;
275         }
276     }
278     if( shifty_alternate ) {
279         delta_shiftj = (double)(j%2);
280     } else {
281         if( shifty_cumulate ) {
282             delta_shiftj = (double)(j*j);
283         } else {
284             delta_shiftj = (double)j;
285         }
286     }
288     // Random shift, only calculate if non-zero.
289     double delta_shiftx_rand = 0.0;
290     double delta_shifty_rand = 0.0;
291     if( shiftx_rand != 0.0 ) delta_shiftx_rand = shiftx_rand * g_random_double_range (-1, 1);
292     if( shifty_rand != 0.0 ) delta_shifty_rand = shifty_rand * g_random_double_range (-1, 1);
295     // Delta shift (units of tile width/height)
296     double di = shiftx_per_i * delta_shifti  + shiftx_per_j * delta_shiftj + delta_shiftx_rand;
297     double dj = shifty_per_i * delta_shifti  + shifty_per_j * delta_shiftj + delta_shifty_rand;
299     // Shift in actual x and y, used below
300     double dx = w * di;
301     double dy = h * dj;
303     double shifti = di;
304     double shiftj = dj;
306     // Include tile width and height in shift if required
307     if( !shiftx_excludew ) shifti += i;
308     if( !shifty_excludeh ) shiftj += j;
310     // Add exponential shift if necessary
311     if ( shiftx_exp != 1.0 ) shifti = pow( shifti, shiftx_exp );
312     if ( shifty_exp != 1.0 ) shiftj = pow( shiftj, shifty_exp );
314     // Final shift
315     Geom::Matrix rect_translate (Geom::Translate (w * shifti, h * shiftj));
317     // Rotation (in degrees) ------------
318     double delta_rotationi = 0.0;
319     double delta_rotationj = 0.0;
321     if( rotate_alternatei ) {
322         delta_rotationi = (double)(i%2);
323     } else {
324         if( rotate_cumulatei ) {
325             delta_rotationi = (double)(i*i + i)/2.0;
326         } else {
327             delta_rotationi = (double)i;
328         }
329     }
331     if( rotate_alternatej ) {
332         delta_rotationj = (double)(j%2);
333     } else {
334         if( rotate_cumulatej ) {
335             delta_rotationj = (double)(j*j + j)/2.0;
336         } else {
337             delta_rotationj = (double)j;
338         }
339     }
341     double delta_rotate_rand = 0.0;
342     if( rotate_rand != 0.0 ) delta_rotate_rand = rotate_rand * 180.0 * g_random_double_range (-1, 1);
344     double dr = rotate_per_i * delta_rotationi + rotate_per_j * delta_rotationj + delta_rotate_rand;
346     // Scale (times the original) -----------
347     double delta_scalei = 0.0;
348     double delta_scalej = 0.0;
350     if( scalex_alternate ) {
351         delta_scalei = (double)(i%2);
352     } else {
353         if( scalex_cumulate ) {  // Should the delta scales be cumulative (i.e. 1, 1+2, 1+2+3, ...)
354             delta_scalei = (double)(i*i + i)/2.0;
355         } else {
356             delta_scalei = (double)i;
357         }
358     }
360     if( scaley_alternate ) {
361         delta_scalej = (double)(j%2);
362     } else {
363         if( scaley_cumulate ) {
364             delta_scalej = (double)(j*j + j)/2.0;
365         } else {
366             delta_scalej = (double)j;
367         }
368     }
370     // Random scale, only calculate if non-zero.
371     double delta_scalex_rand = 0.0;
372     double delta_scaley_rand = 0.0;
373     if( scalex_rand != 0.0 ) delta_scalex_rand = scalex_rand * g_random_double_range (-1, 1);
374     if( scaley_rand != 0.0 ) delta_scaley_rand = scaley_rand * g_random_double_range (-1, 1);
375     // But if random factors are same, scale x and y proportionally
376     if( scalex_rand == scaley_rand ) delta_scalex_rand = delta_scaley_rand;
378     // Total delta scale
379     double scalex = 1.0 + scalex_per_i * delta_scalei  + scalex_per_j * delta_scalej + delta_scalex_rand;
380     double scaley = 1.0 + scaley_per_i * delta_scalei  + scaley_per_j * delta_scalej + delta_scaley_rand;
382     if( scalex < 0.0 ) scalex = 0.0;
383     if( scaley < 0.0 ) scaley = 0.0;
385     // Add exponential scale if necessary
386     if ( scalex_exp != 1.0 ) scalex = pow( scalex, scalex_exp );
387     if ( scaley_exp != 1.0 ) scaley = pow( scaley, scaley_exp );
389     // Add logarithmic factor if necessary
390     if ( scalex_log  > 0.0 ) scalex = pow( scalex_log, scalex - 1.0 );
391     if ( scaley_log  > 0.0 ) scaley = pow( scaley_log, scaley - 1.0 );
392     // Alternative using rotation angle
393     //if ( scalex_log  != 1.0 ) scalex *= pow( scalex_log, M_PI*dr/180 );
394     //if ( scaley_log  != 1.0 ) scaley *= pow( scaley_log, M_PI*dr/180 );
397     // Calculate transformation matrices, translating back to "center of tile" (rotation center) before transforming
398     Geom::Matrix drot_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (M_PI*dr/180)    * Geom::Translate(cx, cy);
400     Geom::Matrix dscale_c = Geom::Translate(-cx, -cy) * Geom::Scale (scalex, scaley)  * Geom::Translate(cx, cy);
402     Geom::Matrix d_s_r = dscale_c * drot_c;
404     Geom::Matrix rotate_180_c  = Geom::Translate(-cx, -cy) * Geom::Rotate (M_PI)      * Geom::Translate(cx, cy);
406     Geom::Matrix rotate_90_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (-M_PI/2)   * Geom::Translate(cx, cy);
407     Geom::Matrix rotate_m90_c  = Geom::Translate(-cx, -cy) * Geom::Rotate ( M_PI/2)   * Geom::Translate(cx, cy);
409     Geom::Matrix rotate_120_c  = Geom::Translate(-cx, -cy) * Geom::Rotate (-2*M_PI/3) * Geom::Translate(cx, cy);
410     Geom::Matrix rotate_m120_c = Geom::Translate(-cx, -cy) * Geom::Rotate ( 2*M_PI/3) * Geom::Translate(cx, cy);
412     Geom::Matrix rotate_60_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (-M_PI/3)   * Geom::Translate(cx, cy);
413     Geom::Matrix rotate_m60_c  = Geom::Translate(-cx, -cy) * Geom::Rotate ( M_PI/3)   * Geom::Translate(cx, cy);
415     Geom::Matrix flip_x        = Geom::Translate(-cx, -cy) * Geom::Scale (-1, 1)      * Geom::Translate(cx, cy);
416     Geom::Matrix flip_y        = Geom::Translate(-cx, -cy) * Geom::Scale (1, -1)      * Geom::Translate(cx, cy);
419     // Create tile with required symmetry
420     const double cos60 = cos(M_PI/3);
421     const double sin60 = sin(M_PI/3);
422     const double cos30 = cos(M_PI/6);
423     const double sin30 = sin(M_PI/6);
425     switch (type) {
427     case TILE_P1:
428         return d_s_r * rect_translate;
429         break;
431     case TILE_P2:
432         if (i % 2 == 0) {
433             return d_s_r * rect_translate;
434         } else {
435             return d_s_r * rotate_180_c * rect_translate;
436         }
437         break;
439     case TILE_PM:
440         if (i % 2 == 0) {
441             return d_s_r * rect_translate;
442         } else {
443             return d_s_r * flip_x * rect_translate;
444         }
445         break;
447     case TILE_PG:
448         if (j % 2 == 0) {
449             return d_s_r * rect_translate;
450         } else {
451             return d_s_r * flip_x * rect_translate;
452         }
453         break;
455     case TILE_CM:
456         if ((i + j) % 2 == 0) {
457             return d_s_r * rect_translate;
458         } else {
459             return d_s_r * flip_x * rect_translate;
460         }
461         break;
463     case TILE_PMM:
464         if (j % 2 == 0) {
465             if (i % 2 == 0) {
466                 return d_s_r * rect_translate;
467             } else {
468                 return d_s_r * flip_x * rect_translate;
469             }
470         } else {
471             if (i % 2 == 0) {
472                 return d_s_r * flip_y * rect_translate;
473             } else {
474                 return d_s_r * flip_x * flip_y * rect_translate;
475             }
476         }
477         break;
479     case TILE_PMG:
480         if (j % 2 == 0) {
481             if (i % 2 == 0) {
482                 return d_s_r * rect_translate;
483             } else {
484                 return d_s_r * rotate_180_c * rect_translate;
485             }
486         } else {
487             if (i % 2 == 0) {
488                 return d_s_r * flip_y * rect_translate;
489             } else {
490                 return d_s_r * rotate_180_c * flip_y * rect_translate;
491             }
492         }
493         break;
495     case TILE_PGG:
496         if (j % 2 == 0) {
497             if (i % 2 == 0) {
498                 return d_s_r * rect_translate;
499             } else {
500                 return d_s_r * flip_y * rect_translate;
501             }
502         } else {
503             if (i % 2 == 0) {
504                 return d_s_r * rotate_180_c * rect_translate;
505             } else {
506                 return d_s_r * rotate_180_c * flip_y * rect_translate;
507             }
508         }
509         break;
511     case TILE_CMM:
512         if (j % 4 == 0) {
513             if (i % 2 == 0) {
514                 return d_s_r * rect_translate;
515             } else {
516                 return d_s_r * flip_x * rect_translate;
517             }
518         } else if (j % 4 == 1) {
519             if (i % 2 == 0) {
520                 return d_s_r * flip_y * rect_translate;
521             } else {
522                 return d_s_r * flip_x * flip_y * rect_translate;
523             }
524         } else if (j % 4 == 2) {
525             if (i % 2 == 1) {
526                 return d_s_r * rect_translate;
527             } else {
528                 return d_s_r * flip_x * rect_translate;
529             }
530         } else {
531             if (i % 2 == 1) {
532                 return d_s_r * flip_y * rect_translate;
533             } else {
534                 return d_s_r * flip_x * flip_y * rect_translate;
535             }
536         }
537         break;
539     case TILE_P4:
540     {
541         Geom::Matrix ori  (Geom::Translate ((w + h) * pow((i/2), shiftx_exp) + dx,  (h + w) * pow((j/2), shifty_exp) + dy));
542         Geom::Matrix dia1 (Geom::Translate (w/2 + h/2, -h/2 + w/2));
543         Geom::Matrix dia2 (Geom::Translate (-w/2 + h/2, h/2 + w/2));
544         if (j % 2 == 0) {
545             if (i % 2 == 0) {
546                 return d_s_r * ori;
547             } else {
548                 return d_s_r * rotate_m90_c * dia1 * ori;
549             }
550         } else {
551             if (i % 2 == 0) {
552                 return d_s_r * rotate_90_c * dia2 * ori;
553             } else {
554                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
555             }
556         }
557     }
558     break;
560     case TILE_P4M:
561     {
562         double max = MAX(w, h);
563         Geom::Matrix ori (Geom::Translate ((max + max) * pow((i/4), shiftx_exp) + dx,  (max + max) * pow((j/2), shifty_exp) + dy));
564         Geom::Matrix dia1 (Geom::Translate ( w/2 - h/2, h/2 - w/2));
565         Geom::Matrix dia2 (Geom::Translate (-h/2 + w/2, w/2 - h/2));
566         if (j % 2 == 0) {
567             if (i % 4 == 0) {
568                 return d_s_r * ori;
569             } else if (i % 4 == 1) {
570                 return d_s_r * flip_y * rotate_m90_c * dia1 * ori;
571             } else if (i % 4 == 2) {
572                 return d_s_r * rotate_m90_c * dia1 * Geom::Translate (h, 0) * ori;
573             } else if (i % 4 == 3) {
574                 return d_s_r * flip_x * Geom::Translate (w, 0) * ori;
575             }
576         } else {
577             if (i % 4 == 0) {
578                 return d_s_r * flip_y * Geom::Translate(0, h) * ori;
579             } else if (i % 4 == 1) {
580                 return d_s_r * rotate_90_c * dia2 * Geom::Translate(0, h) * ori;
581             } else if (i % 4 == 2) {
582                 return d_s_r * flip_y * rotate_90_c * dia2 * Geom::Translate(h, 0) * Geom::Translate(0, h) * ori;
583             } else if (i % 4 == 3) {
584                 return d_s_r * flip_y * flip_x * Geom::Translate(w, 0) * Geom::Translate(0, h) * ori;
585             }
586         }
587     }
588     break;
590     case TILE_P4G:
591     {
592         double max = MAX(w, h);
593         Geom::Matrix ori (Geom::Translate ((max + max) * pow((i/4), shiftx_exp) + dx,  (max + max) * pow(j, shifty_exp) + dy));
594         Geom::Matrix dia1 (Geom::Translate ( w/2 + h/2, h/2 - w/2));
595         Geom::Matrix dia2 (Geom::Translate (-h/2 + w/2, w/2 + h/2));
596         if (((i/4) + j) % 2 == 0) {
597             if (i % 4 == 0) {
598                 return d_s_r * ori;
599             } else if (i % 4 == 1) {
600                 return d_s_r * rotate_m90_c * dia1 * ori;
601             } else if (i % 4 == 2) {
602                 return d_s_r * rotate_90_c * dia2 * ori;
603             } else if (i % 4 == 3) {
604                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
605             }
606         } else {
607             if (i % 4 == 0) {
608                 return d_s_r * flip_y * Geom::Translate (0, h) * ori;
609             } else if (i % 4 == 1) {
610                 return d_s_r * flip_y * rotate_m90_c * dia1 * Geom::Translate (-h, 0) * ori;
611             } else if (i % 4 == 2) {
612                 return d_s_r * flip_y * rotate_90_c * dia2 * Geom::Translate (h, 0) * ori;
613             } else if (i % 4 == 3) {
614                 return d_s_r * flip_x * Geom::Translate (w, 0) * ori;
615             }
616         }
617     }
618     break;
620     case TILE_P3:
621     {
622         double width;
623         double height;
624         Geom::Matrix dia1;
625         Geom::Matrix dia2;
626         if (w > h) {
627             width  = w + w * cos60;
628             height = 2 * w * sin60;
629             dia1 = Geom::Matrix (Geom::Translate (w/2 + w/2 * cos60, -(w/2 * sin60)));
630             dia2 = dia1 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60)));
631         } else {
632             width = h * cos (M_PI/6);
633             height = h;
634             dia1 = Geom::Matrix (Geom::Translate (h/2 * cos30, -(h/2 * sin30)));
635             dia2 = dia1 * Geom::Matrix (Geom::Translate (0, h/2));
636         }
637         Geom::Matrix ori (Geom::Translate (width * pow((2*(i/3) + j%2), shiftx_exp) + dx,  (height/2) * pow(j, shifty_exp) + dy));
638         if (i % 3 == 0) {
639             return d_s_r * ori;
640         } else if (i % 3 == 1) {
641             return d_s_r * rotate_m120_c * dia1 * ori;
642         } else if (i % 3 == 2) {
643             return d_s_r * rotate_120_c * dia2 * ori;
644         }
645     }
646     break;
648     case TILE_P31M:
649     {
650         Geom::Matrix ori;
651         Geom::Matrix dia1;
652         Geom::Matrix dia2;
653         Geom::Matrix dia3;
654         Geom::Matrix dia4;
655         if (w > h) {
656             ori = Geom::Matrix(Geom::Translate (w * pow((i/6) + 0.5*(j%2), shiftx_exp) + dx,  (w * cos30) * pow(j, shifty_exp) + dy));
657             dia1 = Geom::Matrix (Geom::Translate (0, h/2) * Geom::Translate (w/2, 0) * Geom::Translate (w/2 * cos60, -w/2 * sin60) * Geom::Translate (-h/2 * cos30, -h/2 * sin30) );
658             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
659             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
660             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
661         } else {
662             ori  = Geom::Matrix (Geom::Translate (2*h * cos30  * pow((i/6 + 0.5*(j%2)), shiftx_exp) + dx,  (2*h - h * sin30) * pow(j, shifty_exp) + dy));
663             dia1 = Geom::Matrix (Geom::Translate (0, -h/2) * Geom::Translate (h/2 * cos30, h/2 * sin30));
664             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
665             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, h/2));
666             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
667         }
668         if (i % 6 == 0) {
669             return d_s_r * ori;
670         } else if (i % 6 == 1) {
671             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
672         } else if (i % 6 == 2) {
673             return d_s_r * rotate_m120_c * dia2 * ori;
674         } else if (i % 6 == 3) {
675             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
676         } else if (i % 6 == 4) {
677             return d_s_r * rotate_120_c * dia4 * ori;
678         } else if (i % 6 == 5) {
679             return d_s_r * flip_y * Geom::Translate(0, h) * ori;
680         }
681     }
682     break;
684     case TILE_P3M1:
685     {
686         double width;
687         double height;
688         Geom::Matrix dia1;
689         Geom::Matrix dia2;
690         Geom::Matrix dia3;
691         Geom::Matrix dia4;
692         if (w > h) {
693             width = w + w * cos60;
694             height = 2 * w * sin60;
695             dia1 = Geom::Matrix (Geom::Translate (0, h/2) * Geom::Translate (w/2, 0) * Geom::Translate (w/2 * cos60, -w/2 * sin60) * Geom::Translate (-h/2 * cos30, -h/2 * sin30) );
696             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
697             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
698             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
699         } else {
700             width = 2 * h * cos (M_PI/6);
701             height = 2 * h;
702             dia1 = Geom::Matrix (Geom::Translate (0, -h/2) * Geom::Translate (h/2 * cos30, h/2 * sin30));
703             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
704             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, h/2));
705             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
706         }
707         Geom::Matrix ori (Geom::Translate (width * pow((2*(i/6) + j%2), shiftx_exp) + dx,  (height/2) * pow(j, shifty_exp) + dy));
708         if (i % 6 == 0) {
709             return d_s_r * ori;
710         } else if (i % 6 == 1) {
711             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
712         } else if (i % 6 == 2) {
713             return d_s_r * rotate_m120_c * dia2 * ori;
714         } else if (i % 6 == 3) {
715             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
716         } else if (i % 6 == 4) {
717             return d_s_r * rotate_120_c * dia4 * ori;
718         } else if (i % 6 == 5) {
719             return d_s_r * flip_y * Geom::Translate(0, h) * ori;
720         }
721     }
722     break;
724     case TILE_P6:
725     {
726         Geom::Matrix ori;
727         Geom::Matrix dia1;
728         Geom::Matrix dia2;
729         Geom::Matrix dia3;
730         Geom::Matrix dia4;
731         Geom::Matrix dia5;
732         if (w > h) {
733             ori = Geom::Matrix(Geom::Translate (w * pow((2*(i/6) + (j%2)), shiftx_exp) + dx,  (2*w * sin60) * pow(j, shifty_exp) + dy));
734             dia1 = Geom::Matrix (Geom::Translate (w/2 * cos60, -w/2 * sin60));
735             dia2 = dia1 * Geom::Matrix (Geom::Translate (w/2, 0));
736             dia3 = dia2 * Geom::Matrix (Geom::Translate (w/2 * cos60, w/2 * sin60));
737             dia4 = dia3 * Geom::Matrix (Geom::Translate (-w/2 * cos60, w/2 * sin60));
738             dia5 = dia4 * Geom::Matrix (Geom::Translate (-w/2, 0));
739         } else {
740             ori = Geom::Matrix(Geom::Translate (2*h * cos30 * pow((i/6 + 0.5*(j%2)), shiftx_exp) + dx,  (h + h * sin30) * pow(j, shifty_exp) + dy));
741             dia1 = Geom::Matrix (Geom::Translate (-w/2, -h/2) * Geom::Translate (h/2 * cos30, -h/2 * sin30) * Geom::Translate (w/2 * cos60, w/2 * sin60));
742             dia2 = dia1 * Geom::Matrix (Geom::Translate (-w/2 * cos60, -w/2 * sin60) * Geom::Translate (h/2 * cos30, -h/2 * sin30) * Geom::Translate (h/2 * cos30, h/2 * sin30) * Geom::Translate (-w/2 * cos60, w/2 * sin60));
743             dia3 = dia2 * Geom::Matrix (Geom::Translate (w/2 * cos60, -w/2 * sin60) * Geom::Translate (h/2 * cos30, h/2 * sin30) * Geom::Translate (-w/2, h/2));
744             dia4 = dia3 * dia1.inverse();
745             dia5 = dia3 * dia2.inverse();
746         }
747         if (i % 6 == 0) {
748             return d_s_r * ori;
749         } else if (i % 6 == 1) {
750             return d_s_r * rotate_m60_c * dia1 * ori;
751         } else if (i % 6 == 2) {
752             return d_s_r * rotate_m120_c * dia2 * ori;
753         } else if (i % 6 == 3) {
754             return d_s_r * rotate_180_c * dia3 * ori;
755         } else if (i % 6 == 4) {
756             return d_s_r * rotate_120_c * dia4 * ori;
757         } else if (i % 6 == 5) {
758             return d_s_r * rotate_60_c * dia5 * ori;
759         }
760     }
761     break;
763     case TILE_P6M:
764     {
766         Geom::Matrix ori;
767         Geom::Matrix dia1, dia2, dia3, dia4, dia5, dia6, dia7, dia8, dia9, dia10;
768         if (w > h) {
769             ori = Geom::Matrix(Geom::Translate (w * pow((2*(i/12) + (j%2)), shiftx_exp) + dx,  (2*w * sin60) * pow(j, shifty_exp) + dy));
770             dia1 = Geom::Matrix (Geom::Translate (w/2, h/2) * Geom::Translate (-w/2 * cos60, -w/2 * sin60) * Geom::Translate (-h/2 * cos30, h/2 * sin30));
771             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, -h * sin30));
772             dia3 = dia2 * Geom::Matrix (Geom::Translate (-h/2 * cos30, h/2 * sin30) * Geom::Translate (w * cos60, 0) * Geom::Translate (-h/2 * cos30, -h/2 * sin30));
773             dia4 = dia3 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
774             dia5 = dia4 * Geom::Matrix (Geom::Translate (-h/2 * cos30, -h/2 * sin30) * Geom::Translate (-w/2 * cos60, w/2 * sin60) * Geom::Translate (w/2, -h/2));
775             dia6 = dia5 * Geom::Matrix (Geom::Translate (0, h));
776             dia7 = dia6 * dia1.inverse();
777             dia8 = dia6 * dia2.inverse();
778             dia9 = dia6 * dia3.inverse();
779             dia10 = dia6 * dia4.inverse();
780         } else {
781             ori = Geom::Matrix(Geom::Translate (4*h * cos30 * pow((i/12 + 0.5*(j%2)), shiftx_exp) + dx,  (2*h  + 2*h * sin30) * pow(j, shifty_exp) + dy));
782             dia1 = Geom::Matrix (Geom::Translate (-w/2, -h/2) * Geom::Translate (h/2 * cos30, -h/2 * sin30) * Geom::Translate (w/2 * cos60, w/2 * sin60));
783             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, -h * sin30));
784             dia3 = dia2 * Geom::Matrix (Geom::Translate (-w/2 * cos60, -w/2 * sin60) * Geom::Translate (h * cos30, 0) * Geom::Translate (-w/2 * cos60, w/2 * sin60));
785             dia4 = dia3 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
786             dia5 = dia4 * Geom::Matrix (Geom::Translate (w/2 * cos60, -w/2 * sin60) * Geom::Translate (h/2 * cos30, h/2 * sin30) * Geom::Translate (-w/2, h/2));
787             dia6 = dia5 * Geom::Matrix (Geom::Translate (0, h));
788             dia7 = dia6 * dia1.inverse();
789             dia8 = dia6 * dia2.inverse();
790             dia9 = dia6 * dia3.inverse();
791             dia10 = dia6 * dia4.inverse();
792         }
793         if (i % 12 == 0) {
794             return d_s_r * ori;
795         } else if (i % 12 == 1) {
796             return d_s_r * flip_y * rotate_m60_c * dia1 * ori;
797         } else if (i % 12 == 2) {
798             return d_s_r * rotate_m60_c * dia2 * ori;
799         } else if (i % 12 == 3) {
800             return d_s_r * flip_y * rotate_m120_c * dia3 * ori;
801         } else if (i % 12 == 4) {
802             return d_s_r * rotate_m120_c * dia4 * ori;
803         } else if (i % 12 == 5) {
804             return d_s_r * flip_x * dia5 * ori;
805         } else if (i % 12 == 6) {
806             return d_s_r * flip_x * flip_y * dia6 * ori;
807         } else if (i % 12 == 7) {
808             return d_s_r * flip_y * rotate_120_c * dia7 * ori;
809         } else if (i % 12 == 8) {
810             return d_s_r * rotate_120_c * dia8 * ori;
811         } else if (i % 12 == 9) {
812             return d_s_r * flip_y * rotate_60_c * dia9 * ori;
813         } else if (i % 12 == 10) {
814             return d_s_r * rotate_60_c * dia10 * ori;
815         } else if (i % 12 == 11) {
816             return d_s_r * flip_y * Geom::Translate (0, h) * ori;
817         }
818     }
819     break;
821     default:
822         break;
823     }
825     return NR::identity();
828 static bool
829 clonetiler_is_a_clone_of (SPObject *tile, SPObject *obj)
831     char *id_href = NULL;
833     if (obj) {
834         Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
835         id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
836     }
838     if (SP_IS_USE(tile) &&
839         SP_OBJECT_REPR(tile)->attribute("xlink:href") &&
840         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("xlink:href"))) &&
841         SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of") &&
842         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of"))))
843     {
844         if (id_href)
845             g_free (id_href);
846         return true;
847     } else {
848         if (id_href)
849             g_free (id_href);
850         return false;
851     }
854 static NRArena const *trace_arena = NULL;
855 static unsigned trace_visionkey;
856 static NRArenaItem *trace_root;
857 static gdouble trace_zoom;
858 static SPDocument *trace_doc;
860 static void
861 clonetiler_trace_hide_tiled_clones_recursively (SPObject *from)
863     if (!trace_arena)
864         return;
866     for (SPObject *o = sp_object_first_child(from); o != NULL; o = SP_OBJECT_NEXT(o)) {
867         if (SP_IS_ITEM(o) && clonetiler_is_a_clone_of (o, NULL))
868             sp_item_invoke_hide(SP_ITEM(o), trace_visionkey); // FIXME: hide each tiled clone's original too!
869         clonetiler_trace_hide_tiled_clones_recursively (o);
870     }
873 static void
874 clonetiler_trace_setup (SPDocument *doc, gdouble zoom, SPItem *original)
876     trace_arena = NRArena::create();
877     /* Create ArenaItem and set transform */
878     trace_visionkey = sp_item_display_key_new(1);
879     trace_doc = doc;
880     trace_root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT (trace_doc)),
881                                       (NRArena *) trace_arena, trace_visionkey, SP_ITEM_SHOW_DISPLAY);
883     // hide the (current) original and any tiled clones, we only want to pick the background
884     sp_item_invoke_hide(original, trace_visionkey);
885     clonetiler_trace_hide_tiled_clones_recursively (SP_OBJECT(SP_DOCUMENT_ROOT (trace_doc)));
887     sp_document_root (trace_doc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
888     sp_document_ensure_up_to_date(trace_doc);
890     trace_zoom = zoom;
893 static guint32
894 clonetiler_trace_pick (NR::Rect box)
896     if (!trace_arena)
897         return 0;
899     Geom::Matrix t(Geom::Scale(trace_zoom, trace_zoom));
900     nr_arena_item_set_transform(trace_root, &t);
901     NRGC gc(NULL);
902     gc.transform.setIdentity();
903     nr_arena_item_invoke_update( trace_root, NULL, &gc,
904                                  NR_ARENA_ITEM_STATE_ALL,
905                                  NR_ARENA_ITEM_STATE_NONE );
907     /* Item integer bbox in points */
908     NRRectL ibox;
909     ibox.x0 = (int) floor(trace_zoom * box.min()[NR::X] + 0.5);
910     ibox.y0 = (int) floor(trace_zoom * box.min()[NR::Y] + 0.5);
911     ibox.x1 = (int) floor(trace_zoom * box.max()[NR::X] + 0.5);
912     ibox.y1 = (int) floor(trace_zoom * box.max()[NR::Y] + 0.5);
914     /* Find visible area */
915     int width = ibox.x1 - ibox.x0;
916     int height = ibox.y1 - ibox.y0;
918     /* Set up pixblock */
919     guchar *px = g_new(guchar, 4 * width * height);
921     if (px == NULL) {
922         return 0; // buffer is too big or too small, cannot pick, so return 0
923     }
925     memset(px, 0x00, 4 * width * height);
927     /* Render */
928     NRPixBlock pb;
929     nr_pixblock_setup_extern( &pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
930                               ibox.x0, ibox.y0, ibox.x1, ibox.y1,
931                               px, 4 * width, FALSE, FALSE );
932     nr_arena_item_invoke_render(NULL, trace_root, &ibox, &pb,
933                                  NR_ARENA_ITEM_RENDER_NO_CACHE );
935     double R = 0, G = 0, B = 0, A = 0;
936     double count = 0;
937     double weight = 0;
939     for (int y = ibox.y0; y < ibox.y1; y++) {
940         const unsigned char *s = NR_PIXBLOCK_PX (&pb) + (y - ibox.y0) * pb.rs;
941         for (int x = ibox.x0; x < ibox.x1; x++) {
942             count += 1;
943             weight += s[3] / 255.0;
944             R += s[0] / 255.0;
945             G += s[1] / 255.0;
946             B += s[2] / 255.0;
947             A += s[3] / 255.0;
948             s += 4;
949         }
950     }
952     nr_pixblock_release(&pb);
954     R = R / weight;
955     G = G / weight;
956     B = B / weight;
957     A = A / count;
959     R = CLAMP (R, 0.0, 1.0);
960     G = CLAMP (G, 0.0, 1.0);
961     B = CLAMP (B, 0.0, 1.0);
962     A = CLAMP (A, 0.0, 1.0);
964     return SP_RGBA32_F_COMPOSE (R, G, B, A);
967 static void
968 clonetiler_trace_finish ()
970     if (trace_doc) {
971         sp_item_invoke_hide(SP_ITEM(sp_document_root(trace_doc)), trace_visionkey);
972     }
973     if (trace_arena) {
974         ((NRObject *) trace_arena)->unreference();
975         trace_arena = NULL;
976     }
979 static void
980 clonetiler_unclump( GtkWidget */*widget*/, void * )
982     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
983     if (desktop == NULL)
984         return;
986     Inkscape::Selection *selection = sp_desktop_selection(desktop);
988     // check if something is selected
989     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
990         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump."));
991         return;
992     }
994     SPObject *obj = SP_OBJECT(selection->singleItem());
995     SPObject *parent = SP_OBJECT_PARENT (obj);
997     GSList *to_unclump = NULL; // not including the original
999     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
1000         if (clonetiler_is_a_clone_of (child, obj)) {
1001             to_unclump = g_slist_prepend (to_unclump, child);
1002         }
1003     }
1005     sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1007     unclump (to_unclump);
1009     g_slist_free (to_unclump);
1011     sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
1012                       _("Unclump tiled clones"));
1015 static guint
1016 clonetiler_number_of_clones (SPObject *obj)
1018     SPObject *parent = SP_OBJECT_PARENT (obj);
1020     guint n = 0;
1022     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
1023         if (clonetiler_is_a_clone_of (child, obj)) {
1024             n ++;
1025         }
1026     }
1028     return n;
1031 static void
1032 clonetiler_remove( GtkWidget */*widget*/, void *, bool do_undo = true )
1034     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1035     if (desktop == NULL)
1036         return;
1038     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1040     // check if something is selected
1041     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
1042         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove."));
1043         return;
1044     }
1046     SPObject *obj = SP_OBJECT(selection->singleItem());
1047     SPObject *parent = SP_OBJECT_PARENT (obj);
1049 // remove old tiling
1050     GSList *to_delete = NULL;
1051     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
1052         if (clonetiler_is_a_clone_of (child, obj)) {
1053             to_delete = g_slist_prepend (to_delete, child);
1054         }
1055     }
1056     for (GSList *i = to_delete; i; i = i->next) {
1057         SP_OBJECT(i->data)->deleteObject();
1058     }
1059     g_slist_free (to_delete);
1061     clonetiler_change_selection (NULL, selection, dlg);
1063     if (do_undo)
1064         sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
1065                           _("Delete tiled clones"));
1068 static NR::Rect
1069 transform_rect(NR::Rect const &r, NR::Matrix const &m)
1071     using NR::X;
1072     using NR::Y;
1073     NR::Point const p1 = r.corner(1) * m;
1074     NR::Point const p2 = r.corner(2) * m;
1075     NR::Point const p3 = r.corner(3) * m;
1076     NR::Point const p4 = r.corner(4) * m;
1077     return NR::Rect(
1078         NR::Point(
1079             std::min(std::min(p1[X], p2[X]), std::min(p3[X], p4[X])),
1080             std::min(std::min(p1[Y], p2[Y]), std::min(p3[Y], p4[Y]))),
1081         NR::Point(
1082             std::max(std::max(p1[X], p2[X]), std::max(p3[X], p4[X])),
1083             std::max(std::max(p1[Y], p2[Y]), std::max(p3[Y], p4[Y]))));
1086 /**
1087 Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same
1088 probability of being displaced.
1089  */
1090 static double
1091 randomize01 (double val, double rand)
1093     double base = MIN (val - rand, 1 - 2*rand);
1094     if (base < 0) base = 0;
1095     val = base + g_random_double_range (0, MIN (2 * rand, 1 - base));
1096     return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case...
1100 static void
1101 clonetiler_apply( GtkWidget */*widget*/, void * )
1103     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1104     if (desktop == NULL)
1105         return;
1106     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1107     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1109     // check if something is selected
1110     if (selection->isEmpty()) {
1111         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone."));
1112         return;
1113     }
1115     // Check if more than one object is selected.
1116     if (g_slist_length((GSList *) selection->itemList()) > 1) {
1117         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>."));
1118         return;
1119     }
1121     // set "busy" cursor
1122     desktop->setWaitingCursor();
1124     // set statusbar text
1125     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
1126     gtk_label_set_markup (GTK_LABEL(status), _("<small>Creating tiled clones...</small>"));
1127     gtk_widget_queue_draw(GTK_WIDGET(status));
1128     gdk_window_process_all_updates();
1130     SPObject *obj = SP_OBJECT(selection->singleItem());
1131     Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
1132     const char *id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
1133     SPObject *parent = SP_OBJECT_PARENT (obj);
1135     clonetiler_remove (NULL, NULL, false);
1137     double shiftx_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_per_i", 0, -10000, 10000);
1138     double shifty_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_per_i", 0, -10000, 10000);
1139     double shiftx_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_per_j", 0, -10000, 10000);
1140     double shifty_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_per_j", 0, -10000, 10000);
1141     double shiftx_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_rand", 0, 0, 1000);
1142     double shifty_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_rand", 0, 0, 1000);
1143     double shiftx_exp   =        prefs->getDoubleLimited(prefs_path + "shiftx_exp",   1, 0, 10);
1144     double shifty_exp   =        prefs->getDoubleLimited(prefs_path + "shifty_exp", 1, 0, 10);
1145     bool   shiftx_alternate =    prefs->getBool(prefs_path + "shiftx_alternate");
1146     bool   shifty_alternate =    prefs->getBool(prefs_path + "shifty_alternate");
1147     bool   shiftx_cumulate  =    prefs->getBool(prefs_path + "shiftx_cumulate");
1148     bool   shifty_cumulate  =    prefs->getBool(prefs_path + "shifty_cumulate");
1149     bool   shiftx_excludew  =    prefs->getBool(prefs_path + "shiftx_excludew");
1150     bool   shifty_excludeh  =    prefs->getBool(prefs_path + "shifty_excludeh");
1152     double scalex_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_per_i", 0, -100, 1000);
1153     double scaley_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_per_i", 0, -100, 1000);
1154     double scalex_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_per_j", 0, -100, 1000);
1155     double scaley_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_per_j", 0, -100, 1000);
1156     double scalex_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_rand",  0, 0, 1000);
1157     double scaley_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_rand",  0, 0, 1000);
1158     double scalex_exp   =        prefs->getDoubleLimited(prefs_path + "scalex_exp",   1, 0, 10);
1159     double scaley_exp   =        prefs->getDoubleLimited(prefs_path + "scaley_exp",   1, 0, 10);
1160     double scalex_log       =    prefs->getDoubleLimited(prefs_path + "scalex_log",   0, 0, 10);
1161     double scaley_log       =    prefs->getDoubleLimited(prefs_path + "scaley_log",   0, 0, 10);
1162     bool   scalex_alternate =    prefs->getBool(prefs_path + "scalex_alternate");
1163     bool   scaley_alternate =    prefs->getBool(prefs_path + "scaley_alternate");
1164     bool   scalex_cumulate  =    prefs->getBool(prefs_path + "scalex_cumulate");
1165     bool   scaley_cumulate  =    prefs->getBool(prefs_path + "scaley_cumulate");
1167     double rotate_per_i =        prefs->getDoubleLimited(prefs_path + "rotate_per_i", 0, -180, 180);
1168     double rotate_per_j =        prefs->getDoubleLimited(prefs_path + "rotate_per_j", 0, -180, 180);
1169     double rotate_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "rotate_rand", 0, 0, 100);
1170     bool   rotate_alternatei   = prefs->getBool(prefs_path + "rotate_alternatei");
1171     bool   rotate_alternatej   = prefs->getBool(prefs_path + "rotate_alternatej");
1172     bool   rotate_cumulatei    = prefs->getBool(prefs_path + "rotate_cumulatei");
1173     bool   rotate_cumulatej    = prefs->getBool(prefs_path + "rotate_cumulatej");
1175     double blur_per_i =   0.01 * prefs->getDoubleLimited(prefs_path + "blur_per_i", 0, 0, 100);
1176     double blur_per_j =   0.01 * prefs->getDoubleLimited(prefs_path + "blur_per_j", 0, 0, 100);
1177     bool   blur_alternatei =     prefs->getBool(prefs_path + "blur_alternatei");
1178     bool   blur_alternatej =     prefs->getBool(prefs_path + "blur_alternatej");
1179     double blur_rand =    0.01 * prefs->getDoubleLimited(prefs_path + "blur_rand", 0, 0, 100);
1181     double opacity_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "opacity_per_i", 0, 0, 100);
1182     double opacity_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "opacity_per_j", 0, 0, 100);
1183     bool   opacity_alternatei =   prefs->getBool(prefs_path + "opacity_alternatei");
1184     bool   opacity_alternatej =   prefs->getBool(prefs_path + "opacity_alternatej");
1185     double opacity_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "opacity_rand", 0, 0, 100);
1187     Glib::ustring initial_color =    prefs->getString(prefs_path + "initial_color");
1188     double hue_per_j =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_per_j", 0, -100, 100);
1189     double hue_per_i =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_per_i", 0, -100, 100);
1190     double hue_rand  =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_rand", 0, 0, 100);
1191     double saturation_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "saturation_per_j", 0, -100, 100);
1192     double saturation_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "saturation_per_i", 0, -100, 100);
1193     double saturation_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "saturation_rand", 0, 0, 100);
1194     double lightness_per_j =  0.01 * prefs->getDoubleLimited(prefs_path + "lightness_per_j", 0, -100, 100);
1195     double lightness_per_i =  0.01 * prefs->getDoubleLimited(prefs_path + "lightness_per_i", 0, -100, 100);
1196     double lightness_rand =   0.01 * prefs->getDoubleLimited(prefs_path + "lightness_rand", 0, 0, 100);
1197     bool   color_alternatej = prefs->getBool(prefs_path + "color_alternatej");
1198     bool   color_alternatei = prefs->getBool(prefs_path + "color_alternatei");
1200     int    type = prefs->getInt(prefs_path + "symmetrygroup", 0);
1201     bool   keepbbox = prefs->getBool(prefs_path + "keepbbox", true);
1202     int    imax = prefs->getInt(prefs_path + "imax", 2);
1203     int    jmax = prefs->getInt(prefs_path + "jmax", 2);
1205     bool   fillrect = prefs->getBool(prefs_path + "fillrect");
1206     double fillwidth = prefs->getDoubleLimited(prefs_path + "fillwidth", 50, 0, 1e6);
1207     double fillheight = prefs->getDoubleLimited(prefs_path + "fillheight", 50, 0, 1e6);
1209     bool   dotrace = prefs->getBool(prefs_path + "dotrace");
1210     int    pick = prefs->getInt(prefs_path + "pick");
1211     bool   pick_to_presence = prefs->getBool(prefs_path + "pick_to_presence");
1212     bool   pick_to_size = prefs->getBool(prefs_path + "pick_to_size");
1213     bool   pick_to_color = prefs->getBool(prefs_path + "pick_to_color");
1214     bool   pick_to_opacity = prefs->getBool(prefs_path + "pick_to_opacity");
1215     double rand_picked = 0.01 * prefs->getDoubleLimited(prefs_path + "rand_picked", 0, 0, 100);
1216     bool   invert_picked = prefs->getBool(prefs_path + "invert_picked");
1217     double gamma_picked = prefs->getDoubleLimited(prefs_path + "gamma_picked", 0, -10, 10);
1219     if (dotrace) {
1220         clonetiler_trace_setup (sp_desktop_document(desktop), 1.0, SP_ITEM (obj));
1221     }
1223     Geom::Point center;
1224     double w;
1225     double h;
1226     double x0;
1227     double y0;
1229     if (keepbbox &&
1230         obj_repr->attribute("inkscape:tile-w") &&
1231         obj_repr->attribute("inkscape:tile-h") &&
1232         obj_repr->attribute("inkscape:tile-x0") &&
1233         obj_repr->attribute("inkscape:tile-y0") &&
1234         obj_repr->attribute("inkscape:tile-cx") &&
1235         obj_repr->attribute("inkscape:tile-cy")) {
1237         double cx = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cx", 0);
1238         double cy = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cy", 0);
1239         center = Geom::Point (cx, cy);
1241         w = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-w", 0);
1242         h = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-h", 0);
1243         x0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-x0", 0);
1244         y0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-y0", 0);
1245     } else {
1246         bool prefs_bbox = prefs->getBool("/tools/bounding_box", false);
1247         SPItem::BBoxType bbox_type = ( prefs_bbox ? 
1248             SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX );
1249         boost::optional<Geom::Rect> r = SP_ITEM(obj)->getBounds(sp_item_i2doc_affine(SP_ITEM(obj)),
1250                                                         bbox_type);
1251         if (r) {
1252             w = r->dimensions()[Geom::X];
1253             h = r->dimensions()[Geom::Y];
1254             x0 = r->min()[Geom::X];
1255             y0 = r->min()[Geom::Y];
1256             center = desktop->dt2doc(SP_ITEM(obj)->getCenter());
1258             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", center[Geom::X]);
1259             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", center[Geom::Y]);
1260             sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
1261             sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
1262             sp_repr_set_svg_double(obj_repr, "inkscape:tile-x0", x0);
1263             sp_repr_set_svg_double(obj_repr, "inkscape:tile-y0", y0);
1264         } else {
1265             center = Geom::Point(0, 0);
1266             w = h = 0;
1267             x0 = y0 = 0;
1268         }
1269     }
1271     NR::Point cur = NR::Point (0, 0);
1272     NR::Rect bbox_original = NR::Rect (NR::Point (x0, y0), NR::Point (x0 + w, y0 + h));
1273     double perimeter_original = (w + h)/4;
1275     // The integers i and j are reserved for tile column and row.
1276     // The doubles x and y are used for coordinates
1277     for (int i = 0;
1278          fillrect?
1279              (fabs(cur[NR::X]) < fillwidth && i < 200) // prevent "freezing" with too large fillrect, arbitrarily limit rows
1280              : (i < imax);
1281          i ++) {
1282         for (int j = 0;
1283              fillrect?
1284                  (fabs(cur[NR::Y]) < fillheight && j < 200) // prevent "freezing" with too large fillrect, arbitrarily limit cols
1285                  : (j < jmax);
1286              j ++) {
1288             // Note: We create a clone at 0,0 too, right over the original, in case our clones are colored
1290             // Get transform from symmetry, shift, scale, rotation
1291             Geom::Matrix t = clonetiler_get_transform (type, i, j, center[Geom::X], center[Geom::Y], w, h,
1292                                                        shiftx_per_i,     shifty_per_i,
1293                                                        shiftx_per_j,     shifty_per_j,
1294                                                        shiftx_rand,      shifty_rand,
1295                                                        shiftx_exp,       shifty_exp,
1296                                                        shiftx_alternate, shifty_alternate,
1297                                                        shiftx_cumulate,  shifty_cumulate,
1298                                                        shiftx_excludew,  shifty_excludeh,
1299                                                        scalex_per_i,     scaley_per_i,
1300                                                        scalex_per_j,     scaley_per_j,
1301                                                        scalex_rand,      scaley_rand,
1302                                                        scalex_exp,       scaley_exp,
1303                                                        scalex_log,       scaley_log,
1304                                                        scalex_alternate, scaley_alternate,
1305                                                        scalex_cumulate,  scaley_cumulate,
1306                                                        rotate_per_i,     rotate_per_j,
1307                                                        rotate_rand,
1308                                                        rotate_alternatei, rotate_alternatej,
1309                                                        rotate_cumulatei,  rotate_cumulatej      );
1311             cur = center * t - center;
1312             if (fillrect) {
1313                 if ((cur[NR::X] > fillwidth) || (cur[NR::Y] > fillheight)) { // off limits
1314                     continue;
1315                 }
1316             }
1318             gchar color_string[32]; *color_string = 0;
1320             // Color tab
1321             if (!initial_color.empty()) {
1322                 guint32 rgba = sp_svg_read_color (initial_color.data(), 0x000000ff);
1323                 float hsl[3];
1324                 sp_color_rgb_to_hsl_floatv (hsl, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba));
1326                 double eff_i = (color_alternatei? (i%2) : (i));
1327                 double eff_j = (color_alternatej? (j%2) : (j));
1329                 hsl[0] += hue_per_i * eff_i + hue_per_j * eff_j + hue_rand * g_random_double_range (-1, 1);
1330                 double notused;
1331                 hsl[0] = modf( hsl[0], &notused ); // Restrict to 0-1
1332                 hsl[1] += saturation_per_i * eff_i + saturation_per_j * eff_j + saturation_rand * g_random_double_range (-1, 1);
1333                 hsl[1] = CLAMP (hsl[1], 0, 1);
1334                 hsl[2] += lightness_per_i * eff_i + lightness_per_j * eff_j + lightness_rand * g_random_double_range (-1, 1);
1335                 hsl[2] = CLAMP (hsl[2], 0, 1);
1337                 float rgb[3];
1338                 sp_color_hsl_to_rgb_floatv (rgb, hsl[0], hsl[1], hsl[2]);
1339                 sp_svg_write_color(color_string, sizeof(color_string), SP_RGBA32_F_COMPOSE(rgb[0], rgb[1], rgb[2], 1.0));
1340             }
1342             // Blur
1343             double blur = 0.0;
1344             {
1345             int eff_i = (blur_alternatei? (i%2) : (i));
1346             int eff_j = (blur_alternatej? (j%2) : (j));
1347             blur =  (blur_per_i * eff_i + blur_per_j * eff_j + blur_rand * g_random_double_range (-1, 1));
1348             blur = CLAMP (blur, 0, 1);
1349             }
1351             // Opacity
1352             double opacity = 1.0;
1353             {
1354             int eff_i = (opacity_alternatei? (i%2) : (i));
1355             int eff_j = (opacity_alternatej? (j%2) : (j));
1356             opacity = 1 - (opacity_per_i * eff_i + opacity_per_j * eff_j + opacity_rand * g_random_double_range (-1, 1));
1357             opacity = CLAMP (opacity, 0, 1);
1358             }
1360             // Trace tab
1361             if (dotrace) {
1362                 NR::Rect bbox_t = transform_rect (bbox_original, t);
1364                 guint32 rgba = clonetiler_trace_pick (bbox_t);
1365                 float r = SP_RGBA32_R_F(rgba);
1366                 float g = SP_RGBA32_G_F(rgba);
1367                 float b = SP_RGBA32_B_F(rgba);
1368                 float a = SP_RGBA32_A_F(rgba);
1370                 float hsl[3];
1371                 sp_color_rgb_to_hsl_floatv (hsl, r, g, b);
1373                 gdouble val = 0;
1374                 switch (pick) {
1375                 case PICK_COLOR:
1376                     val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max
1377                     break;
1378                 case PICK_OPACITY:
1379                     val = a;
1380                     break;
1381                 case PICK_R:
1382                     val = r;
1383                     break;
1384                 case PICK_G:
1385                     val = g;
1386                     break;
1387                 case PICK_B:
1388                     val = b;
1389                     break;
1390                 case PICK_H:
1391                     val = hsl[0];
1392                     break;
1393                 case PICK_S:
1394                     val = hsl[1];
1395                     break;
1396                 case PICK_L:
1397                     val = 1 - hsl[2];
1398                     break;
1399                 default:
1400                     break;
1401                 }
1403                 if (rand_picked > 0) {
1404                     val = randomize01 (val, rand_picked);
1405                     r = randomize01 (r, rand_picked);
1406                     g = randomize01 (g, rand_picked);
1407                     b = randomize01 (b, rand_picked);
1408                 }
1410                 if (gamma_picked != 0) {
1411                     double power;
1412                     if (gamma_picked > 0)
1413                         power = 1/(1 + fabs(gamma_picked));
1414                     else
1415                         power = 1 + fabs(gamma_picked);
1417                     val = pow (val, power);
1418                     r = pow (r, power);
1419                     g = pow (g, power);
1420                     b = pow (b, power);
1421                 }
1423                 if (invert_picked) {
1424                     val = 1 - val;
1425                     r = 1 - r;
1426                     g = 1 - g;
1427                     b = 1 - b;
1428                 }
1430                 val = CLAMP (val, 0, 1);
1431                 r = CLAMP (r, 0, 1);
1432                 g = CLAMP (g, 0, 1);
1433                 b = CLAMP (b, 0, 1);
1435                 // recompose tweaked color
1436                 rgba = SP_RGBA32_F_COMPOSE(r, g, b, a);
1438                 if (pick_to_presence) {
1439                     if (g_random_double_range (0, 1) > val) {
1440                         continue; // skip!
1441                     }
1442                 }
1443                 if (pick_to_size) {
1444                     t = Geom::Translate(-center[Geom::X], -center[Geom::Y]) * Geom::Scale (val, val) * Geom::Translate(center[Geom::X], center[Geom::Y]) * t;
1445                 }
1446                 if (pick_to_opacity) {
1447                     opacity *= val;
1448                 }
1449                 if (pick_to_color) {
1450                     sp_svg_write_color(color_string, sizeof(color_string), rgba);
1451                 }
1452             }
1454             if (opacity < 1e-6) { // invisibly transparent, skip
1455                     continue;
1456             }
1458             if (fabs(t[0]) + fabs (t[1]) + fabs(t[2]) + fabs(t[3]) < 1e-6) { // too small, skip
1459                     continue;
1460             }
1462             // Create the clone
1463             Inkscape::XML::Node *clone = obj_repr->document()->createElement("svg:use");
1464             clone->setAttribute("x", "0");
1465             clone->setAttribute("y", "0");
1466             clone->setAttribute("inkscape:tiled-clone-of", id_href);
1467             clone->setAttribute("xlink:href", id_href);
1469             Geom::Point new_center;
1470             bool center_set = false;
1471             if (obj_repr->attribute("inkscape:transform-center-x") || obj_repr->attribute("inkscape:transform-center-y")) {
1472                 new_center = desktop->dt2doc(SP_ITEM(obj)->getCenter()) * t;
1473                 center_set = true;
1474             }
1476             gchar *affinestr=sp_svg_transform_write(t);
1477             clone->setAttribute("transform", affinestr);
1478             g_free(affinestr);
1480             if (opacity < 1.0) {
1481                 sp_repr_set_css_double(clone, "opacity", opacity);
1482             }
1484             if (*color_string) {
1485                 clone->setAttribute("fill", color_string);
1486                 clone->setAttribute("stroke", color_string);
1487             }
1489             // add the new clone to the top of the original's parent
1490             SP_OBJECT_REPR(parent)->appendChild(clone);
1492             if (blur > 0.0) {
1493                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1494                 double perimeter = perimeter_original * NR::expansion(t);
1495                 double radius = blur * perimeter;
1496                 // this is necessary for all newly added clones to have correct bboxes,
1497                 // otherwise filters won't work:
1498                 sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1499                 // it's hard to figure out exact width/height of the tile without having an object
1500                 // that we can take bbox of; however here we only need a lower bound so that blur
1501                 // margins are not too small, and the perimeter should work
1502                 SPFilter *constructed = new_filter_gaussian_blur(sp_desktop_document(desktop), radius, NR::expansion(t), NR::expansionX(t), NR::expansionY(t), perimeter, perimeter);
1503                 sp_style_set_property_url (clone_object, "filter", SP_OBJECT(constructed), false);
1504             }
1506             if (center_set) {
1507                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1508                 if (clone_object && SP_IS_ITEM(clone_object)) {
1509                     clone_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1510                     SP_ITEM(clone_object)->setCenter(desktop->doc2dt(new_center));
1511                     clone_object->updateRepr();
1512                 }
1513             }
1515             Inkscape::GC::release(clone);
1516         }
1517         cur[NR::Y] = 0;
1518     }
1520     if (dotrace) {
1521         clonetiler_trace_finish ();
1522     }
1524     clonetiler_change_selection (NULL, selection, dlg);
1526     desktop->clearWaitingCursor();
1528     sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER,
1529                      _("Create tiled clones"));
1532 static GtkWidget *
1533 clonetiler_new_tab (GtkWidget *nb, const gchar *label)
1535     GtkWidget *l = gtk_label_new_with_mnemonic (label);
1536     GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN);
1537     gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN);
1538     gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l);
1539     return vb;
1542 static void
1543 clonetiler_checkbox_toggled (GtkToggleButton *tb, gpointer *data)
1545     const gchar *attr = (const gchar *) data;
1546     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1547     prefs->setBool(prefs_path + attr, gtk_toggle_button_get_active(tb));
1550 static GtkWidget *
1551 clonetiler_checkbox (GtkTooltips *tt, const char *tip, const char *attr)
1553     GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
1555     GtkWidget *b = gtk_check_button_new ();
1556     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, tip, NULL);
1558     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1559     bool value = prefs->getBool(prefs_path + attr);
1560     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(b), value);
1562     gtk_box_pack_end (GTK_BOX (hb), b, FALSE, TRUE, 0);
1563     gtk_signal_connect ( GTK_OBJECT (b), "clicked",
1564                          GTK_SIGNAL_FUNC (clonetiler_checkbox_toggled), (gpointer) attr);
1566     g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
1568     return hb;
1572 static void
1573 clonetiler_value_changed (GtkAdjustment *adj, gpointer data)
1575     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1576     const gchar *pref = (const gchar *) data;
1577     prefs->setDouble(prefs_path + pref, adj->value);
1580 static GtkWidget *
1581 clonetiler_spinbox (GtkTooltips *tt, const char *tip, const char *attr, double lower, double upper, const gchar *suffix, bool exponent = false)
1583     GtkWidget *hb = gtk_hbox_new(FALSE, 0);
1585     {
1586         GtkObject *a;
1587         if (exponent)
1588             a = gtk_adjustment_new(1.0, lower, upper, 0.01, 0.05, 0.1);
1589         else
1590             a = gtk_adjustment_new(0.0, lower, upper, 0.1, 0.5, 2);
1592         GtkWidget *sb;
1593         if (exponent)
1594             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.01, 2);
1595         else
1596             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.1, 1);
1598         gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, tip, NULL);
1599         gtk_entry_set_width_chars (GTK_ENTRY (sb), 4);
1600         gtk_box_pack_start (GTK_BOX (hb), sb, FALSE, FALSE, SB_MARGIN);
1602         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1603         double value = prefs->getDoubleLimited(prefs_path + attr, exponent? 1.0 : 0.0, lower, upper);
1604         gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
1605         gtk_signal_connect(GTK_OBJECT(a), "value_changed",
1606                            GTK_SIGNAL_FUNC(clonetiler_value_changed), (gpointer) attr);
1608         if (exponent)
1609             g_object_set_data (G_OBJECT(sb), "oneable", GINT_TO_POINTER(TRUE));
1610         else
1611             g_object_set_data (G_OBJECT(sb), "zeroable", GINT_TO_POINTER(TRUE));
1612     }
1614     {
1615         GtkWidget *l = gtk_label_new ("");
1616         gtk_label_set_markup (GTK_LABEL(l), suffix);
1617         gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0);
1618         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
1619     }
1621     return hb;
1624 static void
1625 clonetiler_symgroup_changed( GtkMenuItem */*item*/, gpointer data )
1627     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1628     gint group_new = GPOINTER_TO_INT (data);
1629     prefs->setInt(prefs_path + "symmetrygroup", group_new);
1632 static void
1633 clonetiler_xy_changed (GtkAdjustment *adj, gpointer data)
1635     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1636     const gchar *pref = (const gchar *) data;
1637     prefs->setInt(prefs_path + pref, (int) floor(adj->value + 0.5));
1640 static void
1641 clonetiler_keep_bbox_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1643     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1644     prefs->setBool(prefs_path + "keepbbox", gtk_toggle_button_get_active(tb));
1647 static void
1648 clonetiler_pick_to (GtkToggleButton *tb, gpointer data)
1650     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1651     const gchar *pref = (const gchar *) data;
1652     prefs->setBool(prefs_path + pref, gtk_toggle_button_get_active(tb));
1656 static void
1657 clonetiler_reset_recursive (GtkWidget *w)
1659     if (w && GTK_IS_OBJECT(w)) {
1660         {
1661             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "zeroable"));
1662             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1663                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1664                 gtk_adjustment_set_value (a, 0);
1665             }
1666         }
1667         {
1668             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "oneable"));
1669             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1670                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1671                 gtk_adjustment_set_value (a, 1);
1672             }
1673         }
1674         {
1675             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "uncheckable"));
1676             if (r && GTK_IS_TOGGLE_BUTTON(w)) { // checkbox
1677                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(w), FALSE);
1678             }
1679         }
1680     }
1682     if (GTK_IS_CONTAINER(w)) {
1683         GList *ch = gtk_container_get_children (GTK_CONTAINER(w));
1684         for (GList *i = ch; i != NULL; i = i->next) {
1685             clonetiler_reset_recursive (GTK_WIDGET(i->data));
1686         }
1687         g_list_free (ch);
1688     }
1691 static void
1692 clonetiler_reset( GtkWidget */*widget*/, void * )
1694     clonetiler_reset_recursive (dlg);
1697 static void
1698 clonetiler_table_attach (GtkWidget *table, GtkWidget *widget, float align, int row, int col)
1700     GtkWidget *a = gtk_alignment_new (align, 0, 0, 0);
1701     gtk_container_add(GTK_CONTAINER(a), widget);
1702     gtk_table_attach ( GTK_TABLE (table), a, col, col + 1, row, row + 1, (GtkAttachOptions)4, (GtkAttachOptions)0, 0, 0 );
1705 static GtkWidget *
1706 clonetiler_table_x_y_rand (int values)
1708     GtkWidget *table = gtk_table_new (values + 2, 5, FALSE);
1709     gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
1710     gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1711     gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1713     {
1714         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1716         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "clonetiler_per_row");
1717         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1719         GtkWidget *l = gtk_label_new ("");
1720         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per row:</small>"));
1721         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1723         clonetiler_table_attach (table, hb, 0, 1, 2);
1724     }
1726     {
1727         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1729         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "clonetiler_per_column");
1730         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1732         GtkWidget *l = gtk_label_new ("");
1733         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per column:</small>"));
1734         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1736         clonetiler_table_attach (table, hb, 0, 1, 3);
1737     }
1739     {
1740         GtkWidget *l = gtk_label_new ("");
1741         gtk_label_set_markup (GTK_LABEL(l), _("<small>Randomize:</small>"));
1742         clonetiler_table_attach (table, l, 0, 1, 4);
1743     }
1745     return table;
1748 static void
1749 clonetiler_pick_switched( GtkToggleButton */*tb*/, gpointer data )
1751     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1752     guint v = GPOINTER_TO_INT (data);
1753     prefs->setInt(prefs_path + "pick", v);
1757 static void
1758 clonetiler_switch_to_create( GtkToggleButton */*tb*/, GtkWidget *dlg )
1760     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1761     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1763     if (rowscols) {
1764         gtk_widget_set_sensitive (rowscols, TRUE);
1765     }
1766     if (widthheight) {
1767         gtk_widget_set_sensitive (widthheight, FALSE);
1768     }
1770     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1771     prefs->setBool(prefs_path + "fillrect", false);
1775 static void
1776 clonetiler_switch_to_fill( GtkToggleButton */*tb*/, GtkWidget *dlg )
1778     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1779     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1781     if (rowscols) {
1782         gtk_widget_set_sensitive (rowscols, FALSE);
1783     }
1784     if (widthheight) {
1785         gtk_widget_set_sensitive (widthheight, TRUE);
1786     }
1788     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1789     prefs->setBool(prefs_path + "fillrect", true);
1795 static void
1796 clonetiler_fill_width_changed (GtkAdjustment *adj, GtkWidget *u)
1798     gdouble const raw_dist = adj->value;
1799     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1800     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1802     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1803     prefs->setDouble(prefs_path + "fillwidth", pixels);
1806 static void
1807 clonetiler_fill_height_changed (GtkAdjustment *adj, GtkWidget *u)
1809     gdouble const raw_dist = adj->value;
1810     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1811     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1813     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1814     prefs->setDouble(prefs_path + "fillheight", pixels);
1818 static void
1819 clonetiler_do_pick_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1821     GtkWidget *vvb = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "dotrace");
1823     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1824     prefs->setBool(prefs_path + "dotrace", gtk_toggle_button_get_active (tb));
1826     if (vvb)
1827         gtk_widget_set_sensitive (vvb, gtk_toggle_button_get_active (tb));
1833 void
1834 clonetiler_dialog (void)
1836     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1837     if (!dlg)
1838     {
1839         gchar title[500];
1840         sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_CLONETILER), title);
1842         dlg = sp_window_new (title, TRUE);
1843         if (x == -1000 || y == -1000) {
1844             x = prefs->getInt(prefs_path + "x", -1000);
1845             y = prefs->getInt(prefs_path + "y", -1000);
1846         }
1848         if (w ==0 || h == 0) {
1849             w = prefs->getInt(prefs_path + "w", 0);
1850             h = prefs->getInt(prefs_path + "h", 0);
1851         }
1853 //        if (x<0) x=0;
1854 //        if (y<0) y=0;
1856         if (w && h) {
1857             gtk_window_resize ((GtkWindow *) dlg, w, h);
1858         }
1859         if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) {
1860             gtk_window_move ((GtkWindow *) dlg, x, y);
1862         } else {
1863             gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
1864         }
1867         sp_transientize (dlg);
1868         wd.win = dlg;
1869         wd.stop = 0;
1872         gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);
1874         gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (clonetiler_dialog_destroy), dlg);
1875         gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (clonetiler_dialog_delete), dlg);
1877         if (Inkscape::NSApplication::Application::getNewGui())
1878         {
1879             _shutdown_connection = Inkscape::NSApplication::Editor::connectShutdown (&on_delete);
1880             _dialogs_hidden_connection = Inkscape::NSApplication::Editor::connectDialogsHidden (sigc::bind (&on_dialog_hide, dlg));
1881             _dialogs_unhidden_connection = Inkscape::NSApplication::Editor::connectDialogsUnhidden (sigc::bind (&on_dialog_unhide, dlg));
1882             _desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::bind (&on_transientize, &wd));
1883         } else {
1884             g_signal_connect   ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (clonetiler_dialog_delete), dlg);
1885             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg);
1886             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg);
1887             g_signal_connect   ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd);
1888         }
1890         GtkTooltips *tt = gtk_tooltips_new();
1892         GtkWidget *mainbox = gtk_vbox_new(FALSE, 4);
1893         gtk_container_set_border_width (GTK_CONTAINER (mainbox), 6);
1894         gtk_container_add (GTK_CONTAINER (dlg), mainbox);
1896         GtkWidget *nb = gtk_notebook_new ();
1897         gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0);
1900 // Symmetry
1901         {
1902             GtkWidget *vb = clonetiler_new_tab (nb, _("_Symmetry"));
1904             GtkWidget *om = gtk_option_menu_new ();
1905             /* TRANSLATORS: For the following 17 symmetry groups, see
1906              * http://www.bib.ulb.ac.be/coursmath/doc/17.htm (visual examples);
1907              * http://www.clarku.edu/~djoyce/wallpaper/seventeen.html (English vocabulary); or
1908              * http://membres.lycos.fr/villemingerard/Geometri/Sym1D.htm (French vocabulary).
1909              */
1910             gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), om, _("Select one of the 17 symmetry groups for the tiling"), NULL);
1911             gtk_box_pack_start (GTK_BOX (vb), om, FALSE, FALSE, SB_MARGIN);
1913             GtkWidget *m = gtk_menu_new ();
1914             int current = prefs->getInt(prefs_path + "symmetrygroup", 0);
1916             struct SymGroups {
1917                 int group;
1918                 gchar const *label;
1919             } const sym_groups[] = {
1920                 // TRANSLATORS: "translation" means "shift" / "displacement" here.
1921                 {TILE_P1, _("<b>P1</b>: simple translation")},
1922                 {TILE_P2, _("<b>P2</b>: 180&#176; rotation")},
1923                 {TILE_PM, _("<b>PM</b>: reflection")},
1924                 // TRANSLATORS: "glide reflection" is a reflection and a translation combined.
1925                 //  For more info, see http://mathforum.org/sum95/suzanne/symsusan.html
1926                 {TILE_PG, _("<b>PG</b>: glide reflection")},
1927                 {TILE_CM, _("<b>CM</b>: reflection + glide reflection")},
1928                 {TILE_PMM, _("<b>PMM</b>: reflection + reflection")},
1929                 {TILE_PMG, _("<b>PMG</b>: reflection + 180&#176; rotation")},
1930                 {TILE_PGG, _("<b>PGG</b>: glide reflection + 180&#176; rotation")},
1931                 {TILE_CMM, _("<b>CMM</b>: reflection + reflection + 180&#176; rotation")},
1932                 {TILE_P4, _("<b>P4</b>: 90&#176; rotation")},
1933                 {TILE_P4M, _("<b>P4M</b>: 90&#176; rotation + 45&#176; reflection")},
1934                 {TILE_P4G, _("<b>P4G</b>: 90&#176; rotation + 90&#176; reflection")},
1935                 {TILE_P3, _("<b>P3</b>: 120&#176; rotation")},
1936                 {TILE_P31M, _("<b>P31M</b>: reflection + 120&#176; rotation, dense")},
1937                 {TILE_P3M1, _("<b>P3M1</b>: reflection + 120&#176; rotation, sparse")},
1938                 {TILE_P6, _("<b>P6</b>: 60&#176; rotation")},
1939                 {TILE_P6M, _("<b>P6M</b>: reflection + 60&#176; rotation")},
1940             };
1942             for (unsigned j = 0; j < G_N_ELEMENTS(sym_groups); ++j) {
1943                 SymGroups const &sg = sym_groups[j];
1945                 GtkWidget *l = gtk_label_new ("");
1946                 gtk_label_set_markup (GTK_LABEL(l), sg.label);
1947                 gtk_misc_set_alignment (GTK_MISC(l), 0, 0.5);
1949                 GtkWidget *item = gtk_menu_item_new ();
1950                 gtk_container_add (GTK_CONTAINER (item), l);
1952                 gtk_signal_connect ( GTK_OBJECT (item), "activate",
1953                                      GTK_SIGNAL_FUNC (clonetiler_symgroup_changed),
1954                                      GINT_TO_POINTER (sg.group) );
1956                 gtk_menu_append (GTK_MENU (m), item);
1957             }
1959             gtk_option_menu_set_menu (GTK_OPTION_MENU (om), m);
1960             gtk_option_menu_set_history ( GTK_OPTION_MENU (om), current);
1961         }
1963         table_row_labels = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1965 // Shift
1966         {
1967             GtkWidget *vb = clonetiler_new_tab (nb, _("S_hift"));
1969             GtkWidget *table = clonetiler_table_x_y_rand (3);
1970             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1972             // X
1973             {
1974                 GtkWidget *l = gtk_label_new ("");
1975                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) horizontally by this amount
1976                     // xgettext:no-c-format
1977                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift X:</b>"));
1978                 gtk_size_group_add_widget(table_row_labels, l);
1979                 clonetiler_table_attach (table, l, 1, 2, 1);
1980             }
1982             {
1983                 GtkWidget *l = clonetiler_spinbox (tt,
1984                     // xgettext:no-c-format
1985                                                    _("Horizontal shift per row (in % of tile width)"), "shiftx_per_j",
1986                                                    -10000, 10000, "%");
1987                 clonetiler_table_attach (table, l, 0, 2, 2);
1988             }
1990             {
1991                 GtkWidget *l = clonetiler_spinbox (tt,
1992                     // xgettext:no-c-format
1993                                                    _("Horizontal shift per column (in % of tile width)"), "shiftx_per_i",
1994                                                    -10000, 10000, "%");
1995                 clonetiler_table_attach (table, l, 0, 2, 3);
1996             }
1998             {
1999                 GtkWidget *l = clonetiler_spinbox (tt,
2000                                                    _("Randomize the horizontal shift by this percentage"), "shiftx_rand",
2001                                                    0, 1000, "%");
2002                 clonetiler_table_attach (table, l, 0, 2, 4);
2003             }
2005             // Y
2006             {
2007                 GtkWidget *l = gtk_label_new ("");
2008                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) vertically by this amount
2009                     // xgettext:no-c-format
2010                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift Y:</b>"));
2011                 gtk_size_group_add_widget(table_row_labels, l);
2012                 clonetiler_table_attach (table, l, 1, 3, 1);
2013             }
2015             {
2016                 GtkWidget *l = clonetiler_spinbox (tt,
2017                     // xgettext:no-c-format
2018                                                    _("Vertical shift per row (in % of tile height)"), "shifty_per_j",
2019                                                    -10000, 10000, "%");
2020                 clonetiler_table_attach (table, l, 0, 3, 2);
2021             }
2023             {
2024                 GtkWidget *l = clonetiler_spinbox (tt,
2025                     // xgettext:no-c-format
2026                                                    _("Vertical shift per column (in % of tile height)"), "shifty_per_i",
2027                                                    -10000, 10000, "%");
2028                 clonetiler_table_attach (table, l, 0, 3, 3);
2029             }
2031             {
2032                 GtkWidget *l = clonetiler_spinbox (tt,
2033                                                    _("Randomize the vertical shift by this percentage"), "shifty_rand",
2034                                                    0, 1000, "%");
2035                 clonetiler_table_attach (table, l, 0, 3, 4);
2036             }
2038             // Exponent
2039             {
2040                 GtkWidget *l = gtk_label_new ("");
2041                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2042                 gtk_size_group_add_widget(table_row_labels, l);
2043                 clonetiler_table_attach (table, l, 1, 4, 1);
2044             }
2046             {
2047                 GtkWidget *l = clonetiler_spinbox (tt,
2048                                                    _("Whether rows are spaced evenly (1), converge (<1) or diverge (>1)"), "shifty_exp",
2049                                                    0, 10, "", true);
2050                 clonetiler_table_attach (table, l, 0, 4, 2);
2051             }
2053             {
2054                 GtkWidget *l = clonetiler_spinbox (tt,
2055                                                    _("Whether columns are spaced evenly (1), converge (<1) or diverge (>1)"), "shiftx_exp",
2056                                                    0, 10, "", true);
2057                 clonetiler_table_attach (table, l, 0, 4, 3);
2058             }
2060             { // alternates
2061                 GtkWidget *l = gtk_label_new ("");
2062                 // TRANSLATORS: "Alternate" is a verb here
2063                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2064                 gtk_size_group_add_widget(table_row_labels, l);
2065                 clonetiler_table_attach (table, l, 1, 5, 1);
2066             }
2068             {
2069                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each row"), "shifty_alternate");
2070                 clonetiler_table_attach (table, l, 0, 5, 2);
2071             }
2073             {
2074                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each column"), "shiftx_alternate");
2075                 clonetiler_table_attach (table, l, 0, 5, 3);
2076             }
2078             { // Cumulate
2079                 GtkWidget *l = gtk_label_new ("");
2080                 // TRANSLATORS: "Cumulate" is a verb here
2081                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2082                 gtk_size_group_add_widget(table_row_labels, l);
2083                 clonetiler_table_attach (table, l, 1, 6, 1);
2084             }
2086             {
2087                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each row"), "shifty_cumulate");
2088                 clonetiler_table_attach (table, l, 0, 6, 2);
2089             }
2091             {
2092                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each column"), "shiftx_cumulate");
2093                 clonetiler_table_attach (table, l, 0, 6, 3);
2094             }
2096             { // Exclude tile width and height in shift
2097                 GtkWidget *l = gtk_label_new ("");
2098                 // TRANSLATORS: "Cumulate" is a verb here
2099                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Exclude tile:</small>"));
2100                 gtk_size_group_add_widget(table_row_labels, l);
2101                 clonetiler_table_attach (table, l, 1, 7, 1);
2102             }
2104             {
2105                 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile height in shift"), "shifty_excludeh");
2106                 clonetiler_table_attach (table, l, 0, 7, 2);
2107             }
2109             {
2110                 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile width in shift"), "shiftx_excludew");
2111                 clonetiler_table_attach (table, l, 0, 7, 3);
2112             }
2114         }
2117 // Scale
2118         {
2119             GtkWidget *vb = clonetiler_new_tab (nb, _("Sc_ale"));
2121             GtkWidget *table = clonetiler_table_x_y_rand (2);
2122             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2124             // X
2125             {
2126                 GtkWidget *l = gtk_label_new ("");
2127                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale X:</b>"));
2128                 gtk_size_group_add_widget(table_row_labels, l);
2129                 clonetiler_table_attach (table, l, 1, 2, 1);
2130             }
2132             {
2133                 GtkWidget *l = clonetiler_spinbox (tt,
2134                     // xgettext:no-c-format
2135                                                    _("Horizontal scale per row (in % of tile width)"), "scalex_per_j",
2136                                                    -100, 1000, "%");
2137                 clonetiler_table_attach (table, l, 0, 2, 2);
2138             }
2140             {
2141                 GtkWidget *l = clonetiler_spinbox (tt,
2142                     // xgettext:no-c-format
2143                                                    _("Horizontal scale per column (in % of tile width)"), "scalex_per_i",
2144                                                    -100, 1000, "%");
2145                 clonetiler_table_attach (table, l, 0, 2, 3);
2146             }
2148             {
2149                 GtkWidget *l = clonetiler_spinbox (tt,
2150                                                    _("Randomize the horizontal scale by this percentage"), "scalex_rand",
2151                                                    0, 1000, "%");
2152                 clonetiler_table_attach (table, l, 0, 2, 4);
2153             }
2155             // Y
2156             {
2157                 GtkWidget *l = gtk_label_new ("");
2158                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale Y:</b>"));
2159                 gtk_size_group_add_widget(table_row_labels, l);
2160                 clonetiler_table_attach (table, l, 1, 3, 1);
2161             }
2163             {
2164                 GtkWidget *l = clonetiler_spinbox (tt,
2165                     // xgettext:no-c-format
2166                                                    _("Vertical scale per row (in % of tile height)"), "scaley_per_j",
2167                                                    -100, 1000, "%");
2168                 clonetiler_table_attach (table, l, 0, 3, 2);
2169             }
2171             {
2172                 GtkWidget *l = clonetiler_spinbox (tt,
2173                     // xgettext:no-c-format
2174                                                    _("Vertical scale per column (in % of tile height)"), "scaley_per_i",
2175                                                    -100, 1000, "%");
2176                 clonetiler_table_attach (table, l, 0, 3, 3);
2177             }
2179             {
2180                 GtkWidget *l = clonetiler_spinbox (tt,
2181                                                    _("Randomize the vertical scale by this percentage"), "scaley_rand",
2182                                                    0, 1000, "%");
2183                 clonetiler_table_attach (table, l, 0, 3, 4);
2184             }
2186             // Exponent
2187             {
2188                 GtkWidget *l = gtk_label_new ("");
2189                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2190                 gtk_size_group_add_widget(table_row_labels, l);
2191                 clonetiler_table_attach (table, l, 1, 4, 1);
2192             }
2194             {
2195                 GtkWidget *l = clonetiler_spinbox (tt,
2196                                                    _("Whether row scaling is uniform (1), converge (<1) or diverge (>1)"), "scaley_exp",
2197                                                    0, 10, "", true);
2198                 clonetiler_table_attach (table, l, 0, 4, 2);
2199             }
2201             {
2202                 GtkWidget *l = clonetiler_spinbox (tt,
2203                                                    _("Whether column scaling is uniform (1), converge (<1) or diverge (>1)"), "scalex_exp",
2204                                                    0, 10, "", true);
2205                 clonetiler_table_attach (table, l, 0, 4, 3);
2206             }
2208             // Logarithmic (as in logarithmic spiral)
2209             {
2210                 GtkWidget *l = gtk_label_new ("");
2211                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Base:</b>"));
2212                 gtk_size_group_add_widget(table_row_labels, l);
2213                 clonetiler_table_attach (table, l, 1, 5, 1);
2214             }
2216             {
2217                 GtkWidget *l = clonetiler_spinbox (tt,
2218                                                    _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scaley_log",
2219                                                    0, 10, "", false);
2220                 clonetiler_table_attach (table, l, 0, 5, 2);
2221             }
2223             {
2224                 GtkWidget *l = clonetiler_spinbox (tt,
2225                                                    _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scalex_log",
2226                                                    0, 10, "", false);
2227                 clonetiler_table_attach (table, l, 0, 5, 3);
2228             }
2230             { // alternates
2231                 GtkWidget *l = gtk_label_new ("");
2232                 // TRANSLATORS: "Alternate" is a verb here
2233                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2234                 gtk_size_group_add_widget(table_row_labels, l);
2235                 clonetiler_table_attach (table, l, 1, 6, 1);
2236             }
2238             {
2239                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each row"), "scaley_alternate");
2240                 clonetiler_table_attach (table, l, 0, 6, 2);
2241             }
2243             {
2244                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each column"), "scalex_alternate");
2245                 clonetiler_table_attach (table, l, 0, 6, 3);
2246             }
2248             { // Cumulate
2249                 GtkWidget *l = gtk_label_new ("");
2250                 // TRANSLATORS: "Cumulate" is a verb here
2251                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2252                 gtk_size_group_add_widget(table_row_labels, l);
2253                 clonetiler_table_attach (table, l, 1, 7, 1);
2254             }
2256             {
2257                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each row"), "scaley_cumulate");
2258                 clonetiler_table_attach (table, l, 0, 7, 2);
2259             }
2261             {
2262                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each column"), "scalex_cumulate");
2263                 clonetiler_table_attach (table, l, 0, 7, 3);
2264             }
2266         }
2269 // Rotation
2270         {
2271             GtkWidget *vb = clonetiler_new_tab (nb, _("_Rotation"));
2273             GtkWidget *table = clonetiler_table_x_y_rand (1);
2274             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2276             // Angle
2277             {
2278                 GtkWidget *l = gtk_label_new ("");
2279                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Angle:</b>"));
2280                 gtk_size_group_add_widget(table_row_labels, l);
2281                 clonetiler_table_attach (table, l, 1, 2, 1);
2282             }
2284             {
2285                 GtkWidget *l = clonetiler_spinbox (tt,
2286                     // xgettext:no-c-format
2287                                                    _("Rotate tiles by this angle for each row"), "rotate_per_j",
2288                                                    -180, 180, "&#176;");
2289                 clonetiler_table_attach (table, l, 0, 2, 2);
2290             }
2292             {
2293                 GtkWidget *l = clonetiler_spinbox (tt,
2294                     // xgettext:no-c-format
2295                                                    _("Rotate tiles by this angle for each column"), "rotate_per_i",
2296                                                    -180, 180, "&#176;");
2297                 clonetiler_table_attach (table, l, 0, 2, 3);
2298             }
2300             {
2301                 GtkWidget *l = clonetiler_spinbox (tt,
2302                                                    _("Randomize the rotation angle by this percentage"), "rotate_rand",
2303                                                    0, 100, "%");
2304                 clonetiler_table_attach (table, l, 0, 2, 4);
2305             }
2307             { // alternates
2308                 GtkWidget *l = gtk_label_new ("");
2309                 // TRANSLATORS: "Alternate" is a verb here
2310                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2311                 gtk_size_group_add_widget(table_row_labels, l);
2312                 clonetiler_table_attach (table, l, 1, 3, 1);
2313             }
2315             {
2316                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each row"), "rotate_alternatej");
2317                 clonetiler_table_attach (table, l, 0, 3, 2);
2318             }
2320             {
2321                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each column"), "rotate_alternatei");
2322                 clonetiler_table_attach (table, l, 0, 3, 3);
2323             }
2325             { // Cumulate
2326                 GtkWidget *l = gtk_label_new ("");
2327                 // TRANSLATORS: "Cumulate" is a verb here
2328                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2329                 gtk_size_group_add_widget(table_row_labels, l);
2330                 clonetiler_table_attach (table, l, 1, 4, 1);
2331             }
2333             {
2334                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each row"), "rotate_cumulatej");
2335                 clonetiler_table_attach (table, l, 0, 4, 2);
2336             }
2338             {
2339                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each column"), "rotate_cumulatei");
2340                 clonetiler_table_attach (table, l, 0, 4, 3);
2341             }
2343         }
2346 // Blur and opacity
2347         {
2348             GtkWidget *vb = clonetiler_new_tab (nb, _("_Blur & opacity"));
2350             GtkWidget *table = clonetiler_table_x_y_rand (1);
2351             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2354             // Blur
2355             {
2356                 GtkWidget *l = gtk_label_new ("");
2357                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Blur:</b>"));
2358                 gtk_size_group_add_widget(table_row_labels, l);
2359                 clonetiler_table_attach (table, l, 1, 2, 1);
2360             }
2362             {
2363                 GtkWidget *l = clonetiler_spinbox (tt,
2364                                                    _("Blur tiles by this percentage for each row"), "blur_per_j",
2365                                                    0, 100, "%");
2366                 clonetiler_table_attach (table, l, 0, 2, 2);
2367             }
2369             {
2370                 GtkWidget *l = clonetiler_spinbox (tt,
2371                                                    _("Blur tiles by this percentage for each column"), "blur_per_i",
2372                                                    0, 100, "%");
2373                 clonetiler_table_attach (table, l, 0, 2, 3);
2374             }
2376             {
2377                 GtkWidget *l = clonetiler_spinbox (tt,
2378                                                    _("Randomize the tile blur by this percentage"), "blur_rand",
2379                                                    0, 100, "%");
2380                 clonetiler_table_attach (table, l, 0, 2, 4);
2381             }
2383             { // alternates
2384                 GtkWidget *l = gtk_label_new ("");
2385                 // TRANSLATORS: "Alternate" is a verb here
2386                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2387                 gtk_size_group_add_widget(table_row_labels, l);
2388                 clonetiler_table_attach (table, l, 1, 3, 1);
2389             }
2391             {
2392                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each row"), "blur_alternatej");
2393                 clonetiler_table_attach (table, l, 0, 3, 2);
2394             }
2396             {
2397                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each column"), "blur_alternatei");
2398                 clonetiler_table_attach (table, l, 0, 3, 3);
2399             }
2403             // Dissolve
2404             {
2405                 GtkWidget *l = gtk_label_new ("");
2406                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Fade out:</b>"));
2407                 gtk_size_group_add_widget(table_row_labels, l);
2408                 clonetiler_table_attach (table, l, 1, 4, 1);
2409             }
2411             {
2412                 GtkWidget *l = clonetiler_spinbox (tt,
2413                                                    _("Decrease tile opacity by this percentage for each row"), "opacity_per_j",
2414                                                    0, 100, "%");
2415                 clonetiler_table_attach (table, l, 0, 4, 2);
2416             }
2418             {
2419                 GtkWidget *l = clonetiler_spinbox (tt,
2420                                                    _("Decrease tile opacity by this percentage for each column"), "opacity_per_i",
2421                                                    0, 100, "%");
2422                 clonetiler_table_attach (table, l, 0, 4, 3);
2423             }
2425             {
2426                 GtkWidget *l = clonetiler_spinbox (tt,
2427                                                    _("Randomize the tile opacity by this percentage"), "opacity_rand",
2428                                                    0, 100, "%");
2429                 clonetiler_table_attach (table, l, 0, 4, 4);
2430             }
2432             { // alternates
2433                 GtkWidget *l = gtk_label_new ("");
2434                 // TRANSLATORS: "Alternate" is a verb here
2435                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2436                 gtk_size_group_add_widget(table_row_labels, l);
2437                 clonetiler_table_attach (table, l, 1, 5, 1);
2438             }
2440             {
2441                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each row"), "opacity_alternatej");
2442                 clonetiler_table_attach (table, l, 0, 5, 2);
2443             }
2445             {
2446                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each column"), "opacity_alternatei");
2447                 clonetiler_table_attach (table, l, 0, 5, 3);
2448             }
2449         }
2452 // Color
2453         {
2454             GtkWidget *vb = clonetiler_new_tab (nb, _("Co_lor"));
2456             {
2457             GtkWidget *hb = gtk_hbox_new (FALSE, 0);
2459             GtkWidget *l = gtk_label_new (_("Initial color: "));
2460             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2462             guint32 rgba = 0x000000ff | sp_svg_read_color (prefs->getString(prefs_path + "initial_color").data(), 0x000000ff);
2463             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);
2464             _color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed));
2466             gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast<GtkWidget*>(color_picker->gobj()), FALSE, FALSE, 0);
2468             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2469             }
2472             GtkWidget *table = clonetiler_table_x_y_rand (3);
2473             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2475             // Hue
2476             {
2477                 GtkWidget *l = gtk_label_new ("");
2478                 gtk_label_set_markup (GTK_LABEL(l), _("<b>H:</b>"));
2479                 gtk_size_group_add_widget(table_row_labels, l);
2480                 clonetiler_table_attach (table, l, 1, 2, 1);
2481             }
2483             {
2484                 GtkWidget *l = clonetiler_spinbox (tt,
2485                                                    _("Change the tile hue by this percentage for each row"), "hue_per_j",
2486                                                    -100, 100, "%");
2487                 clonetiler_table_attach (table, l, 0, 2, 2);
2488             }
2490             {
2491                 GtkWidget *l = clonetiler_spinbox (tt,
2492                                                    _("Change the tile hue by this percentage for each column"), "hue_per_i",
2493                                                    -100, 100, "%");
2494                 clonetiler_table_attach (table, l, 0, 2, 3);
2495             }
2497             {
2498                 GtkWidget *l = clonetiler_spinbox (tt,
2499                                                    _("Randomize the tile hue by this percentage"), "hue_rand",
2500                                                    0, 100, "%");
2501                 clonetiler_table_attach (table, l, 0, 2, 4);
2502             }
2505             // Saturation
2506             {
2507                 GtkWidget *l = gtk_label_new ("");
2508                 gtk_label_set_markup (GTK_LABEL(l), _("<b>S:</b>"));
2509                 gtk_size_group_add_widget(table_row_labels, l);
2510                 clonetiler_table_attach (table, l, 1, 3, 1);
2511             }
2513             {
2514                 GtkWidget *l = clonetiler_spinbox (tt,
2515                                                    _("Change the color saturation by this percentage for each row"), "saturation_per_j",
2516                                                    -100, 100, "%");
2517                 clonetiler_table_attach (table, l, 0, 3, 2);
2518             }
2520             {
2521                 GtkWidget *l = clonetiler_spinbox (tt,
2522                                                    _("Change the color saturation by this percentage for each column"), "saturation_per_i",
2523                                                    -100, 100, "%");
2524                 clonetiler_table_attach (table, l, 0, 3, 3);
2525             }
2527             {
2528                 GtkWidget *l = clonetiler_spinbox (tt,
2529                                                    _("Randomize the color saturation by this percentage"), "saturation_rand",
2530                                                    0, 100, "%");
2531                 clonetiler_table_attach (table, l, 0, 3, 4);
2532             }
2534             // Lightness
2535             {
2536                 GtkWidget *l = gtk_label_new ("");
2537                 gtk_label_set_markup (GTK_LABEL(l), _("<b>L:</b>"));
2538                 gtk_size_group_add_widget(table_row_labels, l);
2539                 clonetiler_table_attach (table, l, 1, 4, 1);
2540             }
2542             {
2543                 GtkWidget *l = clonetiler_spinbox (tt,
2544                                                    _("Change the color lightness by this percentage for each row"), "lightness_per_j",
2545                                                    -100, 100, "%");
2546                 clonetiler_table_attach (table, l, 0, 4, 2);
2547             }
2549             {
2550                 GtkWidget *l = clonetiler_spinbox (tt,
2551                                                    _("Change the color lightness by this percentage for each column"), "lightness_per_i",
2552                                                    -100, 100, "%");
2553                 clonetiler_table_attach (table, l, 0, 4, 3);
2554             }
2556             {
2557                 GtkWidget *l = clonetiler_spinbox (tt,
2558                                                    _("Randomize the color lightness by this percentage"), "lightness_rand",
2559                                                    0, 100, "%");
2560                 clonetiler_table_attach (table, l, 0, 4, 4);
2561             }
2564             { // alternates
2565                 GtkWidget *l = gtk_label_new ("");
2566                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2567                 gtk_size_group_add_widget(table_row_labels, l);
2568                 clonetiler_table_attach (table, l, 1, 5, 1);
2569             }
2571             {
2572                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each row"), "color_alternatej");
2573                 clonetiler_table_attach (table, l, 0, 5, 2);
2574             }
2576             {
2577                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each column"), "color_alternatei");
2578                 clonetiler_table_attach (table, l, 0, 5, 3);
2579             }
2581         }
2583 // Trace
2584         {
2585             GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace"));
2588         {
2589             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2590             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2592             GtkWidget *b  = gtk_check_button_new_with_label (_("Trace the drawing under the tiles"));
2593             g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
2594             bool old = prefs->getBool(prefs_path + "dotrace");
2595             gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2596             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);
2597             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2599             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2600                                GTK_SIGNAL_FUNC(clonetiler_do_pick_toggled), dlg);
2601         }
2603         {
2604             GtkWidget *vvb = gtk_vbox_new (FALSE, 0);
2605             gtk_box_pack_start (GTK_BOX (vb), vvb, FALSE, FALSE, 0);
2606             g_object_set_data (G_OBJECT(dlg), "dotrace", (gpointer) vvb);
2609             {
2610                 GtkWidget *frame = gtk_frame_new (_("1. Pick from the drawing:"));
2611                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2613                 GtkWidget *table = gtk_table_new (3, 3, FALSE);
2614                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2615                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2616                 gtk_container_add(GTK_CONTAINER(frame), table);
2619                 GtkWidget* radio;
2620                 {
2621                     radio = gtk_radio_button_new_with_label (NULL, _("Color"));
2622                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the visible color and opacity"), NULL);
2623                     clonetiler_table_attach (table, radio, 0.0, 1, 1);
2624                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2625                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_COLOR));
2626                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_COLOR);
2627                 }
2628                 {
2629                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Opacity"));
2630                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the total accumulated opacity"), NULL);
2631                     clonetiler_table_attach (table, radio, 0.0, 2, 1);
2632                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2633                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_OPACITY));
2634                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_OPACITY);
2635                 }
2636                 {
2637                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("R"));
2638                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Red component of the color"), NULL);
2639                     clonetiler_table_attach (table, radio, 0.0, 1, 2);
2640                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2641                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_R));
2642                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_R);
2643                 }
2644                 {
2645                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("G"));
2646                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Green component of the color"), NULL);
2647                     clonetiler_table_attach (table, radio, 0.0, 2, 2);
2648                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2649                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_G));
2650                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_G);
2651                 }
2652                 {
2653                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("B"));
2654                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Blue component of the color"), NULL);
2655                     clonetiler_table_attach (table, radio, 0.0, 3, 2);
2656                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2657                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_B));
2658                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_B);
2659                 }
2660                 {
2661                     //TRANSLATORS: only translate "string" in "context|string".
2662                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2663                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|H"));
2664                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the hue of the color"), NULL);
2665                     clonetiler_table_attach (table, radio, 0.0, 1, 3);
2666                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2667                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_H));
2668                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_H);
2669                 }
2670                 {
2671                     //TRANSLATORS: only translate "string" in "context|string".
2672                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2673                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|S"));
2674                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the saturation of the color"), NULL);
2675                     clonetiler_table_attach (table, radio, 0.0, 2, 3);
2676                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2677                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_S));
2678                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_S);
2679                 }
2680                 {
2681                     //TRANSLATORS: only translate "string" in "context|string".
2682                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2683                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|L"));
2684                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the lightness of the color"), NULL);
2685                     clonetiler_table_attach (table, radio, 0.0, 3, 3);
2686                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2687                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_L));
2688                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_L);
2689                 }
2691             }
2693             {
2694                 GtkWidget *frame = gtk_frame_new (_("2. Tweak the picked value:"));
2695                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, VB_MARGIN);
2697                 GtkWidget *table = gtk_table_new (4, 2, FALSE);
2698                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2699                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2700                 gtk_container_add(GTK_CONTAINER(frame), table);
2702                 {
2703                     GtkWidget *l = gtk_label_new ("");
2704                     gtk_label_set_markup (GTK_LABEL(l), _("Gamma-correct:"));
2705                     clonetiler_table_attach (table, l, 1.0, 1, 1);
2706                 }
2707                 {
2708                     GtkWidget *l = clonetiler_spinbox (tt,
2709                                                        _("Shift the mid-range of the picked value upwards (>0) or downwards (<0)"), "gamma_picked",
2710                                                        -10, 10, "");
2711                     clonetiler_table_attach (table, l, 0.0, 1, 2);
2712                 }
2714                 {
2715                     GtkWidget *l = gtk_label_new ("");
2716                     gtk_label_set_markup (GTK_LABEL(l), _("Randomize:"));
2717                     clonetiler_table_attach (table, l, 1.0, 1, 3);
2718                 }
2719                 {
2720                     GtkWidget *l = clonetiler_spinbox (tt,
2721                                                        _("Randomize the picked value by this percentage"), "rand_picked",
2722                                                        0, 100, "%");
2723                     clonetiler_table_attach (table, l, 0.0, 1, 4);
2724                 }
2726                 {
2727                     GtkWidget *l = gtk_label_new ("");
2728                     gtk_label_set_markup (GTK_LABEL(l), _("Invert:"));
2729                     clonetiler_table_attach (table, l, 1.0, 2, 1);
2730                 }
2731                 {
2732                     GtkWidget *l = clonetiler_checkbox (tt, _("Invert the picked value"), "invert_picked");
2733                     clonetiler_table_attach (table, l, 0.0, 2, 2);
2734                 }
2735             }
2737             {
2738                 GtkWidget *frame = gtk_frame_new (_("3. Apply the value to the clones':"));
2739                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2742                 GtkWidget *table = gtk_table_new (2, 2, FALSE);
2743                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2744                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2745                 gtk_container_add(GTK_CONTAINER(frame), table);
2747                 {
2748                     GtkWidget *b  = gtk_check_button_new_with_label (_("Presence"));
2749                     bool old = prefs->getBool(prefs_path + "pick_to_presence", true);
2750                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2751                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone is created with the probability determined by the picked value in that point"), NULL);
2752                     clonetiler_table_attach (table, b, 0.0, 1, 1);
2753                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2754                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_presence");
2755                 }
2757                 {
2758                     GtkWidget *b  = gtk_check_button_new_with_label (_("Size"));
2759                     bool old = prefs->getBool(prefs_path + "pick_to_size");
2760                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2761                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's size is determined by the picked value in that point"), NULL);
2762                     clonetiler_table_attach (table, b, 0.0, 2, 1);
2763                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2764                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_size");
2765                 }
2767                 {
2768                     GtkWidget *b  = gtk_check_button_new_with_label (_("Color"));
2769                     bool old = prefs->getBool(prefs_path + "pick_to_color", 0);
2770                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2771                     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);
2772                     clonetiler_table_attach (table, b, 0.0, 1, 2);
2773                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2774                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_color");
2775                 }
2777                 {
2778                     GtkWidget *b  = gtk_check_button_new_with_label (_("Opacity"));
2779                     bool old = prefs->getBool(prefs_path + "pick_to_opacity", 0);
2780                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2781                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's opacity is determined by the picked value in that point"), NULL);
2782                     clonetiler_table_attach (table, b, 0.0, 2, 2);
2783                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2784                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_opacity");
2785                 }
2786             }
2787            gtk_widget_set_sensitive (vvb, prefs->getBool(prefs_path + "dotrace"));
2788         }
2789         }
2791 // Rows/columns, width/height
2792         {
2793             GtkWidget *table = gtk_table_new (2, 2, FALSE);
2794             gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
2795             gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2796             gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2797             gtk_box_pack_start (GTK_BOX (mainbox), table, FALSE, FALSE, 0);
2799             {
2800                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2801                 g_object_set_data (G_OBJECT(dlg), "rowscols", (gpointer) hb);
2803                 {
2804                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2805                     int value = prefs->getInt(prefs_path + "jmax", 2);
2806                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2807                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2808                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many rows in the tiling"), NULL);
2809                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2810                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2812                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2813                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "jmax");
2814                 }
2816                 {
2817                     GtkWidget *l = gtk_label_new ("");
2818                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2819                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2820                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2821                 }
2823                 {
2824                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2825                     int value = prefs->getInt(prefs_path + "imax", 2);
2826                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2827                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2828                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many columns in the tiling"), NULL);
2829                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2830                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2832                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2833                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "imax");
2834                 }
2836                 clonetiler_table_attach (table, hb, 0.0, 1, 2);
2837             }
2839             {
2840                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2841                 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
2843                 // unitmenu
2844                 GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
2845                 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
2847                 {
2848                     // Width spinbutton
2849                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2850                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2852                     double value = prefs->getDouble(prefs_path + "fillwidth", 50.0);
2853                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2854                     gdouble const units = sp_pixels_get_units (value, unit);
2855                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2857                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2858                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Width of the rectangle to be filled"), NULL);
2859                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2860                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2861                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2862                                        GTK_SIGNAL_FUNC(clonetiler_fill_width_changed), u);
2863                 }
2864                 {
2865                     GtkWidget *l = gtk_label_new ("");
2866                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2867                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2868                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2869                 }
2871                 {
2872                     // Height spinbutton
2873                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2874                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2876                     double value = prefs->getDouble(prefs_path + "fillheight", 50.0);
2877                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2878                     gdouble const units = sp_pixels_get_units (value, unit);
2879                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2882                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2883                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Height of the rectangle to be filled"), NULL);
2884                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2885                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2886                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2887                                        GTK_SIGNAL_FUNC(clonetiler_fill_height_changed), u);
2888                 }
2890                 gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);
2891                 clonetiler_table_attach (table, hb, 0.0, 2, 2);
2893             }
2895             // Switch
2896             GtkWidget* radio;
2897             {
2898                 radio = gtk_radio_button_new_with_label (NULL, _("Rows, columns: "));
2899                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Create the specified number of rows and columns"), NULL);
2900                 clonetiler_table_attach (table, radio, 0.0, 1, 1);
2901                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_create), (gpointer) dlg);
2902             }
2903             if (!prefs->getBool(prefs_path + "fillrect")) {
2904                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2905                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2906             }
2907             {
2908                 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Width, height: "));
2909                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Fill the specified width and height with the tiling"), NULL);
2910                 clonetiler_table_attach (table, radio, 0.0, 2, 1);
2911                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_fill), (gpointer) dlg);
2912             }
2913             if (prefs->getBool(prefs_path + "fillrect")) {
2914                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2915                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2916             }
2917         }
2920 // Use saved pos
2921         {
2922             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2923             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2925             GtkWidget *b  = gtk_check_button_new_with_label (_("Use saved size and position of the tile"));
2926             bool keepbbox = prefs->getBool(prefs_path + "keepbbox", true);
2927             gtk_toggle_button_set_active ((GtkToggleButton *) b, keepbbox);
2928             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);
2929             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2931             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2932                                GTK_SIGNAL_FUNC(clonetiler_keep_bbox_toggled), NULL);
2933         }
2935 // Statusbar
2936         {
2937             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2938             gtk_box_pack_end (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2939             GtkWidget *l = gtk_label_new("");
2940             g_object_set_data (G_OBJECT(dlg), "status", (gpointer) l);
2941             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2942         }
2944 // Buttons
2945         {
2946             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2947             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2949             {
2950                 GtkWidget *b = gtk_button_new ();
2951                 GtkWidget *l = gtk_label_new ("");
2952                 gtk_label_set_markup_with_mnemonic (GTK_LABEL(l), _(" <b>_Create</b> "));
2953                 gtk_container_add (GTK_CONTAINER(b), l);
2954                 gtk_tooltips_set_tip (tt, b, _("Create and tile the clones of the selection"), NULL);
2955                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_apply), NULL);
2956                 gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0);
2957             }
2959             { // buttons which are enabled only when there are tiled clones
2960                 GtkWidget *sb = gtk_hbox_new(FALSE, 0);
2961                 gtk_box_pack_end (GTK_BOX (hb), sb, FALSE, FALSE, 0);
2962                 g_object_set_data (G_OBJECT(dlg), "buttons_on_tiles", (gpointer) sb);
2963                 {
2964                     // TRANSLATORS: if a group of objects are "clumped" together, then they
2965                     //  are unevenly spread in the given amount of space - as shown in the
2966                     //  diagrams on the left in the following screenshot:
2967                     //  http://www.inkscape.org/screenshots/gallery/inkscape-0.42-CVS-tiles-unclump.png
2968                     //  So unclumping is the process of spreading a number of objects out more evenly.
2969                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" _Unclump "));
2970                     gtk_tooltips_set_tip (tt, b, _("Spread out clones to reduce clumping; can be applied repeatedly"), NULL);
2971                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_unclump), NULL);
2972                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2973                 }
2975                 {
2976                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" Re_move "));
2977                     gtk_tooltips_set_tip (tt, b, _("Remove existing tiled clones of the selected object (siblings only)"), NULL);
2978                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_remove), NULL);
2979                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2980                 }
2982                 // connect to global selection changed signal (so we can change desktops) and
2983                 // external_change (so we're not fooled by undo)
2984                 g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (clonetiler_change_selection), dlg);
2985                 g_signal_connect (G_OBJECT (INKSCAPE), "external_change", G_CALLBACK (clonetiler_external_change), dlg);
2986                 g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), G_OBJECT (INKSCAPE));
2988                 // update now
2989                 clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
2990             }
2992             {
2993                 GtkWidget *b = gtk_button_new_with_mnemonic (_(" R_eset "));
2994                 // TRANSLATORS: "change" is a noun here
2995                 gtk_tooltips_set_tip (tt, b, _("Reset all shifts, scales, rotates, opacity and color changes in the dialog to zero"), NULL);
2996                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_reset), NULL);
2997                 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2998             }
2999         }
3001         gtk_widget_show_all (mainbox);
3003     } // end of if (!dlg)
3005     gtk_window_present ((GtkWindow *) dlg);
3009 /*
3010   Local Variables:
3011   mode:c++
3012   c-file-style:"stroustrup"
3013   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
3014   indent-tabs-mode:nil
3015   fill-column:99
3016   End:
3017 */
3018 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :