Code

Pot and Dutch translation update
[inkscape.git] / src / dialogs / clonetiler.cpp
1 /** @file
2  * Clone tiling dialog
3  */
4 /* Authors:
5  *   bulia byak <buliabyak@users.sf.net>
6  *   Johan Engelen <goejendaagh@zonnet.nl>
7  *
8  * Copyright (C) 2004-2006 Authors
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #ifdef HAVE_CONFIG_H
13 # include "config.h"
14 #endif
15 #include <glib/gmem.h>
16 #include <gtk/gtk.h>
17 #include <glibmm/i18n.h>
19 #include "../desktop.h"
20 #include "../desktop-handles.h"
21 #include "dialog-events.h"
22 #include "display/nr-arena.h"
23 #include "display/nr-arena-item.h"
24 #include "../document.h"
25 #include "../filter-chemistry.h"
26 #include "helper/unit-menu.h"
27 #include "helper/units.h"
28 #include "helper/window.h"
29 #include "../inkscape.h"
30 #include "../interface.h"
31 #include "../macros.h"
32 #include "../message-stack.h"
33 #include "preferences.h"
34 #include "../selection.h"
35 #include "../sp-filter.h"
36 #include "../sp-namedview.h"
37 #include "../sp-use.h"
38 #include "../style.h"
39 #include "svg/svg-color.h"
40 #include "svg/svg.h"
41 #include "ui/icon-names.h"
42 #include "ui/widget/color-picker.h"
43 #include "unclump.h"
44 #include "../verbs.h"
45 #include "widgets/icon.h"
46 #include "xml/repr.h"
48 #define MIN_ONSCREEN_DISTANCE 50
50 static GtkWidget *dlg = NULL;
51 static win_data wd;
53 // impossible original values to make sure they are read from prefs
54 static gint x = -1000, y = -1000, w = 0, h = 0;
55 static Glib::ustring const prefs_path = "/dialogs/clonetiler/";
57 #define SB_MARGIN 1
58 #define VB_MARGIN 4
60 enum {
61     PICK_COLOR,
62     PICK_OPACITY,
63     PICK_R,
64     PICK_G,
65     PICK_B,
66     PICK_H,
67     PICK_S,
68     PICK_L
69 };
71 static GtkSizeGroup* table_row_labels = NULL;
73 static sigc::connection _shutdown_connection;
74 static sigc::connection _dialogs_hidden_connection;
75 static sigc::connection _dialogs_unhidden_connection;
76 static sigc::connection _desktop_activated_connection;
77 static sigc::connection _color_changed_connection;
79 static Inkscape::UI::Widget::ColorPicker *color_picker;
81 static void
82 clonetiler_dialog_destroy( GtkObject */*object*/, gpointer /*data*/ )
83 {
84     sp_signal_disconnect_by_data (INKSCAPE, dlg);
85     _color_changed_connection.disconnect();
87     delete color_picker;
89     wd.win = dlg = NULL;
90     wd.stop = 0;
92 }
94 static gboolean
95 clonetiler_dialog_delete (GtkObject */*object*/, GdkEvent * /*event*/, gpointer /*data*/)
96 {
97     gtk_window_get_position ((GtkWindow *) dlg, &x, &y);
98     gtk_window_get_size ((GtkWindow *) dlg, &w, &h);
100     if (x<0) x=0;
101     if (y<0) y=0;
103     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
104     prefs->setInt(prefs_path + "x", x);
105     prefs->setInt(prefs_path + "y", y);
106     prefs->setInt(prefs_path + "w", w);
107     prefs->setInt(prefs_path + "h", h);
109     return FALSE; // which means, go ahead and destroy it
113 static void on_delete()
115     (void)clonetiler_dialog_delete (0, 0, NULL);
118 static void
119 on_picker_color_changed (guint rgba)
121     static bool is_updating = false;
122     if (is_updating || !SP_ACTIVE_DESKTOP)
123         return;
125     is_updating = true;
127     gchar c[32];
128     sp_svg_write_color(c, sizeof(c), rgba);
129     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
130     prefs->setString(prefs_path + "initial_color", c);
132     is_updating = false;
135 static guint clonetiler_number_of_clones (SPObject *obj);
137 static void
138 clonetiler_change_selection (Inkscape::Application * /*inkscape*/, Inkscape::Selection *selection, GtkWidget *dlg)
140     GtkWidget *buttons = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "buttons_on_tiles");
141     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
143     if (selection->isEmpty()) {
144         gtk_widget_set_sensitive (buttons, FALSE);
145         gtk_label_set_markup (GTK_LABEL(status), _("<small>Nothing selected.</small>"));
146         return;
147     }
149     if (g_slist_length ((GSList *) selection->itemList()) > 1) {
150         gtk_widget_set_sensitive (buttons, FALSE);
151         gtk_label_set_markup (GTK_LABEL(status), _("<small>More than one object selected.</small>"));
152         return;
153     }
155     guint n = clonetiler_number_of_clones(selection->singleItem());
156     if (n > 0) {
157         gtk_widget_set_sensitive (buttons, TRUE);
158         gchar *sta = g_strdup_printf (_("<small>Object has <b>%d</b> tiled clones.</small>"), n);
159         gtk_label_set_markup (GTK_LABEL(status), sta);
160         g_free (sta);
161     } else {
162         gtk_widget_set_sensitive (buttons, FALSE);
163         gtk_label_set_markup (GTK_LABEL(status), _("<small>Object has no tiled clones.</small>"));
164     }
167 static void
168 clonetiler_external_change (Inkscape::Application * /*inkscape*/, GtkWidget *dlg)
170     clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
173 static void clonetiler_disconnect_gsignal (GObject *widget, gpointer source) {
174     if (source && G_IS_OBJECT(source))
175         sp_signal_disconnect_by_data (source, widget);
179 enum {
180     TILE_P1,
181     TILE_P2,
182     TILE_PM,
183     TILE_PG,
184     TILE_CM,
185     TILE_PMM,
186     TILE_PMG,
187     TILE_PGG,
188     TILE_CMM,
189     TILE_P4,
190     TILE_P4M,
191     TILE_P4G,
192     TILE_P3,
193     TILE_P31M,
194     TILE_P3M1,
195     TILE_P6,
196     TILE_P6M
197 };
200 static Geom::Matrix
201 clonetiler_get_transform (
203     // symmetry group
204     int type,
206     // row, column
207     int i, int j,
209     // center, width, height of the tile
210     double cx, double cy,
211     double w,  double h,
213     // values from the dialog:
214     // Shift
215     double shiftx_per_i,      double shifty_per_i,
216     double shiftx_per_j,      double shifty_per_j,
217     double shiftx_rand,       double shifty_rand,
218     double shiftx_exp,        double shifty_exp,
219     int    shiftx_alternate,  int    shifty_alternate,
220     int    shiftx_cumulate,   int    shifty_cumulate,
221     int    shiftx_excludew,   int    shifty_excludeh,
223     // Scale
224     double scalex_per_i,      double scaley_per_i,
225     double scalex_per_j,      double scaley_per_j,
226     double scalex_rand,       double scaley_rand,
227     double scalex_exp,        double scaley_exp,
228     double scalex_log,        double scaley_log,
229     int    scalex_alternate,  int    scaley_alternate,
230     int    scalex_cumulate,   int    scaley_cumulate,
232     // Rotation
233     double rotate_per_i,      double rotate_per_j,
234     double rotate_rand,
235     int    rotate_alternatei, int    rotate_alternatej,
236     int    rotate_cumulatei,  int    rotate_cumulatej
237     )
240     // Shift (in units of tile width or height) -------------
241     double delta_shifti = 0.0;
242     double delta_shiftj = 0.0;
244     if( shiftx_alternate ) {
245         delta_shifti = (double)(i%2);
246     } else {
247         if( shiftx_cumulate ) {  // Should the delta shifts be cumulative (i.e. 1, 1+2, 1+2+3, ...)
248             delta_shifti = (double)(i*i);
249         } else {
250             delta_shifti = (double)i;
251         }
252     }
254     if( shifty_alternate ) {
255         delta_shiftj = (double)(j%2);
256     } else {
257         if( shifty_cumulate ) {
258             delta_shiftj = (double)(j*j);
259         } else {
260             delta_shiftj = (double)j;
261         }
262     }
264     // Random shift, only calculate if non-zero.
265     double delta_shiftx_rand = 0.0;
266     double delta_shifty_rand = 0.0;
267     if( shiftx_rand != 0.0 ) delta_shiftx_rand = shiftx_rand * g_random_double_range (-1, 1);
268     if( shifty_rand != 0.0 ) delta_shifty_rand = shifty_rand * g_random_double_range (-1, 1);
271     // Delta shift (units of tile width/height)
272     double di = shiftx_per_i * delta_shifti  + shiftx_per_j * delta_shiftj + delta_shiftx_rand;
273     double dj = shifty_per_i * delta_shifti  + shifty_per_j * delta_shiftj + delta_shifty_rand;
275     // Shift in actual x and y, used below
276     double dx = w * di;
277     double dy = h * dj;
279     double shifti = di;
280     double shiftj = dj;
282     // Include tile width and height in shift if required
283     if( !shiftx_excludew ) shifti += i;
284     if( !shifty_excludeh ) shiftj += j;
286     // Add exponential shift if necessary
287     if ( shiftx_exp != 1.0 ) shifti = pow( shifti, shiftx_exp );
288     if ( shifty_exp != 1.0 ) shiftj = pow( shiftj, shifty_exp );
290     // Final shift
291     Geom::Matrix rect_translate (Geom::Translate (w * shifti, h * shiftj));
293     // Rotation (in degrees) ------------
294     double delta_rotationi = 0.0;
295     double delta_rotationj = 0.0;
297     if( rotate_alternatei ) {
298         delta_rotationi = (double)(i%2);
299     } else {
300         if( rotate_cumulatei ) {
301             delta_rotationi = (double)(i*i + i)/2.0;
302         } else {
303             delta_rotationi = (double)i;
304         }
305     }
307     if( rotate_alternatej ) {
308         delta_rotationj = (double)(j%2);
309     } else {
310         if( rotate_cumulatej ) {
311             delta_rotationj = (double)(j*j + j)/2.0;
312         } else {
313             delta_rotationj = (double)j;
314         }
315     }
317     double delta_rotate_rand = 0.0;
318     if( rotate_rand != 0.0 ) delta_rotate_rand = rotate_rand * 180.0 * g_random_double_range (-1, 1);
320     double dr = rotate_per_i * delta_rotationi + rotate_per_j * delta_rotationj + delta_rotate_rand;
322     // Scale (times the original) -----------
323     double delta_scalei = 0.0;
324     double delta_scalej = 0.0;
326     if( scalex_alternate ) {
327         delta_scalei = (double)(i%2);
328     } else {
329         if( scalex_cumulate ) {  // Should the delta scales be cumulative (i.e. 1, 1+2, 1+2+3, ...)
330             delta_scalei = (double)(i*i + i)/2.0;
331         } else {
332             delta_scalei = (double)i;
333         }
334     }
336     if( scaley_alternate ) {
337         delta_scalej = (double)(j%2);
338     } else {
339         if( scaley_cumulate ) {
340             delta_scalej = (double)(j*j + j)/2.0;
341         } else {
342             delta_scalej = (double)j;
343         }
344     }
346     // Random scale, only calculate if non-zero.
347     double delta_scalex_rand = 0.0;
348     double delta_scaley_rand = 0.0;
349     if( scalex_rand != 0.0 ) delta_scalex_rand = scalex_rand * g_random_double_range (-1, 1);
350     if( scaley_rand != 0.0 ) delta_scaley_rand = scaley_rand * g_random_double_range (-1, 1);
351     // But if random factors are same, scale x and y proportionally
352     if( scalex_rand == scaley_rand ) delta_scalex_rand = delta_scaley_rand;
354     // Total delta scale
355     double scalex = 1.0 + scalex_per_i * delta_scalei  + scalex_per_j * delta_scalej + delta_scalex_rand;
356     double scaley = 1.0 + scaley_per_i * delta_scalei  + scaley_per_j * delta_scalej + delta_scaley_rand;
358     if( scalex < 0.0 ) scalex = 0.0;
359     if( scaley < 0.0 ) scaley = 0.0;
361     // Add exponential scale if necessary
362     if ( scalex_exp != 1.0 ) scalex = pow( scalex, scalex_exp );
363     if ( scaley_exp != 1.0 ) scaley = pow( scaley, scaley_exp );
365     // Add logarithmic factor if necessary
366     if ( scalex_log  > 0.0 ) scalex = pow( scalex_log, scalex - 1.0 );
367     if ( scaley_log  > 0.0 ) scaley = pow( scaley_log, scaley - 1.0 );
368     // Alternative using rotation angle
369     //if ( scalex_log  != 1.0 ) scalex *= pow( scalex_log, M_PI*dr/180 );
370     //if ( scaley_log  != 1.0 ) scaley *= pow( scaley_log, M_PI*dr/180 );
373     // Calculate transformation matrices, translating back to "center of tile" (rotation center) before transforming
374     Geom::Matrix drot_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (M_PI*dr/180)    * Geom::Translate(cx, cy);
376     Geom::Matrix dscale_c = Geom::Translate(-cx, -cy) * Geom::Scale (scalex, scaley)  * Geom::Translate(cx, cy);
378     Geom::Matrix d_s_r = dscale_c * drot_c;
380     Geom::Matrix rotate_180_c  = Geom::Translate(-cx, -cy) * Geom::Rotate (M_PI)      * Geom::Translate(cx, cy);
382     Geom::Matrix rotate_90_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (-M_PI/2)   * Geom::Translate(cx, cy);
383     Geom::Matrix rotate_m90_c  = Geom::Translate(-cx, -cy) * Geom::Rotate ( M_PI/2)   * Geom::Translate(cx, cy);
385     Geom::Matrix rotate_120_c  = Geom::Translate(-cx, -cy) * Geom::Rotate (-2*M_PI/3) * Geom::Translate(cx, cy);
386     Geom::Matrix rotate_m120_c = Geom::Translate(-cx, -cy) * Geom::Rotate ( 2*M_PI/3) * Geom::Translate(cx, cy);
388     Geom::Matrix rotate_60_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (-M_PI/3)   * Geom::Translate(cx, cy);
389     Geom::Matrix rotate_m60_c  = Geom::Translate(-cx, -cy) * Geom::Rotate ( M_PI/3)   * Geom::Translate(cx, cy);
391     Geom::Matrix flip_x        = Geom::Translate(-cx, -cy) * Geom::Scale (-1, 1)      * Geom::Translate(cx, cy);
392     Geom::Matrix flip_y        = Geom::Translate(-cx, -cy) * Geom::Scale (1, -1)      * Geom::Translate(cx, cy);
395     // Create tile with required symmetry
396     const double cos60 = cos(M_PI/3);
397     const double sin60 = sin(M_PI/3);
398     const double cos30 = cos(M_PI/6);
399     const double sin30 = sin(M_PI/6);
401     switch (type) {
403     case TILE_P1:
404         return d_s_r * rect_translate;
405         break;
407     case TILE_P2:
408         if (i % 2 == 0) {
409             return d_s_r * rect_translate;
410         } else {
411             return d_s_r * rotate_180_c * rect_translate;
412         }
413         break;
415     case TILE_PM:
416         if (i % 2 == 0) {
417             return d_s_r * rect_translate;
418         } else {
419             return d_s_r * flip_x * rect_translate;
420         }
421         break;
423     case TILE_PG:
424         if (j % 2 == 0) {
425             return d_s_r * rect_translate;
426         } else {
427             return d_s_r * flip_x * rect_translate;
428         }
429         break;
431     case TILE_CM:
432         if ((i + j) % 2 == 0) {
433             return d_s_r * rect_translate;
434         } else {
435             return d_s_r * flip_x * rect_translate;
436         }
437         break;
439     case TILE_PMM:
440         if (j % 2 == 0) {
441             if (i % 2 == 0) {
442                 return d_s_r * rect_translate;
443             } else {
444                 return d_s_r * flip_x * rect_translate;
445             }
446         } else {
447             if (i % 2 == 0) {
448                 return d_s_r * flip_y * rect_translate;
449             } else {
450                 return d_s_r * flip_x * flip_y * rect_translate;
451             }
452         }
453         break;
455     case TILE_PMG:
456         if (j % 2 == 0) {
457             if (i % 2 == 0) {
458                 return d_s_r * rect_translate;
459             } else {
460                 return d_s_r * rotate_180_c * rect_translate;
461             }
462         } else {
463             if (i % 2 == 0) {
464                 return d_s_r * flip_y * rect_translate;
465             } else {
466                 return d_s_r * rotate_180_c * flip_y * rect_translate;
467             }
468         }
469         break;
471     case TILE_PGG:
472         if (j % 2 == 0) {
473             if (i % 2 == 0) {
474                 return d_s_r * rect_translate;
475             } else {
476                 return d_s_r * flip_y * rect_translate;
477             }
478         } else {
479             if (i % 2 == 0) {
480                 return d_s_r * rotate_180_c * rect_translate;
481             } else {
482                 return d_s_r * rotate_180_c * flip_y * rect_translate;
483             }
484         }
485         break;
487     case TILE_CMM:
488         if (j % 4 == 0) {
489             if (i % 2 == 0) {
490                 return d_s_r * rect_translate;
491             } else {
492                 return d_s_r * flip_x * rect_translate;
493             }
494         } else if (j % 4 == 1) {
495             if (i % 2 == 0) {
496                 return d_s_r * flip_y * rect_translate;
497             } else {
498                 return d_s_r * flip_x * flip_y * rect_translate;
499             }
500         } else if (j % 4 == 2) {
501             if (i % 2 == 1) {
502                 return d_s_r * rect_translate;
503             } else {
504                 return d_s_r * flip_x * rect_translate;
505             }
506         } else {
507             if (i % 2 == 1) {
508                 return d_s_r * flip_y * rect_translate;
509             } else {
510                 return d_s_r * flip_x * flip_y * rect_translate;
511             }
512         }
513         break;
515     case TILE_P4:
516     {
517         Geom::Matrix ori  (Geom::Translate ((w + h) * pow((i/2), shiftx_exp) + dx,  (h + w) * pow((j/2), shifty_exp) + dy));
518         Geom::Matrix dia1 (Geom::Translate (w/2 + h/2, -h/2 + w/2));
519         Geom::Matrix dia2 (Geom::Translate (-w/2 + h/2, h/2 + w/2));
520         if (j % 2 == 0) {
521             if (i % 2 == 0) {
522                 return d_s_r * ori;
523             } else {
524                 return d_s_r * rotate_m90_c * dia1 * ori;
525             }
526         } else {
527             if (i % 2 == 0) {
528                 return d_s_r * rotate_90_c * dia2 * ori;
529             } else {
530                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
531             }
532         }
533     }
534     break;
536     case TILE_P4M:
537     {
538         double max = MAX(w, h);
539         Geom::Matrix ori (Geom::Translate ((max + max) * pow((i/4), shiftx_exp) + dx,  (max + max) * pow((j/2), shifty_exp) + dy));
540         Geom::Matrix dia1 (Geom::Translate ( w/2 - h/2, h/2 - w/2));
541         Geom::Matrix dia2 (Geom::Translate (-h/2 + w/2, w/2 - h/2));
542         if (j % 2 == 0) {
543             if (i % 4 == 0) {
544                 return d_s_r * ori;
545             } else if (i % 4 == 1) {
546                 return d_s_r * flip_y * rotate_m90_c * dia1 * ori;
547             } else if (i % 4 == 2) {
548                 return d_s_r * rotate_m90_c * dia1 * Geom::Translate (h, 0) * ori;
549             } else if (i % 4 == 3) {
550                 return d_s_r * flip_x * Geom::Translate (w, 0) * ori;
551             }
552         } else {
553             if (i % 4 == 0) {
554                 return d_s_r * flip_y * Geom::Translate(0, h) * ori;
555             } else if (i % 4 == 1) {
556                 return d_s_r * rotate_90_c * dia2 * Geom::Translate(0, h) * ori;
557             } else if (i % 4 == 2) {
558                 return d_s_r * flip_y * rotate_90_c * dia2 * Geom::Translate(h, 0) * Geom::Translate(0, h) * ori;
559             } else if (i % 4 == 3) {
560                 return d_s_r * flip_y * flip_x * Geom::Translate(w, 0) * Geom::Translate(0, h) * ori;
561             }
562         }
563     }
564     break;
566     case TILE_P4G:
567     {
568         double max = MAX(w, h);
569         Geom::Matrix ori (Geom::Translate ((max + max) * pow((i/4), shiftx_exp) + dx,  (max + max) * pow(j, shifty_exp) + dy));
570         Geom::Matrix dia1 (Geom::Translate ( w/2 + h/2, h/2 - w/2));
571         Geom::Matrix dia2 (Geom::Translate (-h/2 + w/2, w/2 + h/2));
572         if (((i/4) + j) % 2 == 0) {
573             if (i % 4 == 0) {
574                 return d_s_r * ori;
575             } else if (i % 4 == 1) {
576                 return d_s_r * rotate_m90_c * dia1 * ori;
577             } else if (i % 4 == 2) {
578                 return d_s_r * rotate_90_c * dia2 * ori;
579             } else if (i % 4 == 3) {
580                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
581             }
582         } else {
583             if (i % 4 == 0) {
584                 return d_s_r * flip_y * Geom::Translate (0, h) * ori;
585             } else if (i % 4 == 1) {
586                 return d_s_r * flip_y * rotate_m90_c * dia1 * Geom::Translate (-h, 0) * ori;
587             } else if (i % 4 == 2) {
588                 return d_s_r * flip_y * rotate_90_c * dia2 * Geom::Translate (h, 0) * ori;
589             } else if (i % 4 == 3) {
590                 return d_s_r * flip_x * Geom::Translate (w, 0) * ori;
591             }
592         }
593     }
594     break;
596     case TILE_P3:
597     {
598         double width;
599         double height;
600         Geom::Matrix dia1;
601         Geom::Matrix dia2;
602         if (w > h) {
603             width  = w + w * cos60;
604             height = 2 * w * sin60;
605             dia1 = Geom::Matrix (Geom::Translate (w/2 + w/2 * cos60, -(w/2 * sin60)));
606             dia2 = dia1 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60)));
607         } else {
608             width = h * cos (M_PI/6);
609             height = h;
610             dia1 = Geom::Matrix (Geom::Translate (h/2 * cos30, -(h/2 * sin30)));
611             dia2 = dia1 * Geom::Matrix (Geom::Translate (0, h/2));
612         }
613         Geom::Matrix ori (Geom::Translate (width * pow((2*(i/3) + j%2), shiftx_exp) + dx,  (height/2) * pow(j, shifty_exp) + dy));
614         if (i % 3 == 0) {
615             return d_s_r * ori;
616         } else if (i % 3 == 1) {
617             return d_s_r * rotate_m120_c * dia1 * ori;
618         } else if (i % 3 == 2) {
619             return d_s_r * rotate_120_c * dia2 * ori;
620         }
621     }
622     break;
624     case TILE_P31M:
625     {
626         Geom::Matrix ori;
627         Geom::Matrix dia1;
628         Geom::Matrix dia2;
629         Geom::Matrix dia3;
630         Geom::Matrix dia4;
631         if (w > h) {
632             ori = Geom::Matrix(Geom::Translate (w * pow((i/6) + 0.5*(j%2), shiftx_exp) + dx,  (w * cos30) * pow(j, shifty_exp) + dy));
633             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) );
634             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
635             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
636             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
637         } else {
638             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));
639             dia1 = Geom::Matrix (Geom::Translate (0, -h/2) * Geom::Translate (h/2 * cos30, h/2 * sin30));
640             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
641             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, h/2));
642             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
643         }
644         if (i % 6 == 0) {
645             return d_s_r * ori;
646         } else if (i % 6 == 1) {
647             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
648         } else if (i % 6 == 2) {
649             return d_s_r * rotate_m120_c * dia2 * ori;
650         } else if (i % 6 == 3) {
651             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
652         } else if (i % 6 == 4) {
653             return d_s_r * rotate_120_c * dia4 * ori;
654         } else if (i % 6 == 5) {
655             return d_s_r * flip_y * Geom::Translate(0, h) * ori;
656         }
657     }
658     break;
660     case TILE_P3M1:
661     {
662         double width;
663         double height;
664         Geom::Matrix dia1;
665         Geom::Matrix dia2;
666         Geom::Matrix dia3;
667         Geom::Matrix dia4;
668         if (w > h) {
669             width = w + w * cos60;
670             height = 2 * w * sin60;
671             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) );
672             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
673             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
674             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
675         } else {
676             width = 2 * h * cos (M_PI/6);
677             height = 2 * h;
678             dia1 = Geom::Matrix (Geom::Translate (0, -h/2) * Geom::Translate (h/2 * cos30, h/2 * sin30));
679             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
680             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, h/2));
681             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
682         }
683         Geom::Matrix ori (Geom::Translate (width * pow((2*(i/6) + j%2), shiftx_exp) + dx,  (height/2) * pow(j, shifty_exp) + dy));
684         if (i % 6 == 0) {
685             return d_s_r * ori;
686         } else if (i % 6 == 1) {
687             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
688         } else if (i % 6 == 2) {
689             return d_s_r * rotate_m120_c * dia2 * ori;
690         } else if (i % 6 == 3) {
691             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
692         } else if (i % 6 == 4) {
693             return d_s_r * rotate_120_c * dia4 * ori;
694         } else if (i % 6 == 5) {
695             return d_s_r * flip_y * Geom::Translate(0, h) * ori;
696         }
697     }
698     break;
700     case TILE_P6:
701     {
702         Geom::Matrix ori;
703         Geom::Matrix dia1;
704         Geom::Matrix dia2;
705         Geom::Matrix dia3;
706         Geom::Matrix dia4;
707         Geom::Matrix dia5;
708         if (w > h) {
709             ori = Geom::Matrix(Geom::Translate (w * pow((2*(i/6) + (j%2)), shiftx_exp) + dx,  (2*w * sin60) * pow(j, shifty_exp) + dy));
710             dia1 = Geom::Matrix (Geom::Translate (w/2 * cos60, -w/2 * sin60));
711             dia2 = dia1 * Geom::Matrix (Geom::Translate (w/2, 0));
712             dia3 = dia2 * Geom::Matrix (Geom::Translate (w/2 * cos60, w/2 * sin60));
713             dia4 = dia3 * Geom::Matrix (Geom::Translate (-w/2 * cos60, w/2 * sin60));
714             dia5 = dia4 * Geom::Matrix (Geom::Translate (-w/2, 0));
715         } else {
716             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));
717             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));
718             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));
719             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));
720             dia4 = dia3 * dia1.inverse();
721             dia5 = dia3 * dia2.inverse();
722         }
723         if (i % 6 == 0) {
724             return d_s_r * ori;
725         } else if (i % 6 == 1) {
726             return d_s_r * rotate_m60_c * dia1 * ori;
727         } else if (i % 6 == 2) {
728             return d_s_r * rotate_m120_c * dia2 * ori;
729         } else if (i % 6 == 3) {
730             return d_s_r * rotate_180_c * dia3 * ori;
731         } else if (i % 6 == 4) {
732             return d_s_r * rotate_120_c * dia4 * ori;
733         } else if (i % 6 == 5) {
734             return d_s_r * rotate_60_c * dia5 * ori;
735         }
736     }
737     break;
739     case TILE_P6M:
740     {
742         Geom::Matrix ori;
743         Geom::Matrix dia1, dia2, dia3, dia4, dia5, dia6, dia7, dia8, dia9, dia10;
744         if (w > h) {
745             ori = Geom::Matrix(Geom::Translate (w * pow((2*(i/12) + (j%2)), shiftx_exp) + dx,  (2*w * sin60) * pow(j, shifty_exp) + dy));
746             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));
747             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, -h * sin30));
748             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));
749             dia4 = dia3 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
750             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));
751             dia6 = dia5 * Geom::Matrix (Geom::Translate (0, h));
752             dia7 = dia6 * dia1.inverse();
753             dia8 = dia6 * dia2.inverse();
754             dia9 = dia6 * dia3.inverse();
755             dia10 = dia6 * dia4.inverse();
756         } else {
757             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));
758             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));
759             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, -h * sin30));
760             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));
761             dia4 = dia3 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
762             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));
763             dia6 = dia5 * Geom::Matrix (Geom::Translate (0, h));
764             dia7 = dia6 * dia1.inverse();
765             dia8 = dia6 * dia2.inverse();
766             dia9 = dia6 * dia3.inverse();
767             dia10 = dia6 * dia4.inverse();
768         }
769         if (i % 12 == 0) {
770             return d_s_r * ori;
771         } else if (i % 12 == 1) {
772             return d_s_r * flip_y * rotate_m60_c * dia1 * ori;
773         } else if (i % 12 == 2) {
774             return d_s_r * rotate_m60_c * dia2 * ori;
775         } else if (i % 12 == 3) {
776             return d_s_r * flip_y * rotate_m120_c * dia3 * ori;
777         } else if (i % 12 == 4) {
778             return d_s_r * rotate_m120_c * dia4 * ori;
779         } else if (i % 12 == 5) {
780             return d_s_r * flip_x * dia5 * ori;
781         } else if (i % 12 == 6) {
782             return d_s_r * flip_x * flip_y * dia6 * ori;
783         } else if (i % 12 == 7) {
784             return d_s_r * flip_y * rotate_120_c * dia7 * ori;
785         } else if (i % 12 == 8) {
786             return d_s_r * rotate_120_c * dia8 * ori;
787         } else if (i % 12 == 9) {
788             return d_s_r * flip_y * rotate_60_c * dia9 * ori;
789         } else if (i % 12 == 10) {
790             return d_s_r * rotate_60_c * dia10 * ori;
791         } else if (i % 12 == 11) {
792             return d_s_r * flip_y * Geom::Translate (0, h) * ori;
793         }
794     }
795     break;
797     default:
798         break;
799     }
801     return Geom::identity();
804 static bool
805 clonetiler_is_a_clone_of (SPObject *tile, SPObject *obj)
807     char *id_href = NULL;
809     if (obj) {
810         Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
811         id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
812     }
814     if (SP_IS_USE(tile) &&
815         SP_OBJECT_REPR(tile)->attribute("xlink:href") &&
816         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("xlink:href"))) &&
817         SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of") &&
818         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of"))))
819     {
820         if (id_href)
821             g_free (id_href);
822         return true;
823     } else {
824         if (id_href)
825             g_free (id_href);
826         return false;
827     }
830 static NRArena const *trace_arena = NULL;
831 static unsigned trace_visionkey;
832 static NRArenaItem *trace_root;
833 static gdouble trace_zoom;
834 static SPDocument *trace_doc;
836 static void
837 clonetiler_trace_hide_tiled_clones_recursively (SPObject *from)
839     if (!trace_arena)
840         return;
842     for (SPObject *o = sp_object_first_child(from); o != NULL; o = SP_OBJECT_NEXT(o)) {
843         if (SP_IS_ITEM(o) && clonetiler_is_a_clone_of (o, NULL))
844             sp_item_invoke_hide(SP_ITEM(o), trace_visionkey); // FIXME: hide each tiled clone's original too!
845         clonetiler_trace_hide_tiled_clones_recursively (o);
846     }
849 static void
850 clonetiler_trace_setup (SPDocument *doc, gdouble zoom, SPItem *original)
852     trace_arena = NRArena::create();
853     /* Create ArenaItem and set transform */
854     trace_visionkey = sp_item_display_key_new(1);
855     trace_doc = doc;
856     trace_root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT (trace_doc)),
857                                       (NRArena *) trace_arena, trace_visionkey, SP_ITEM_SHOW_DISPLAY);
859     // hide the (current) original and any tiled clones, we only want to pick the background
860     sp_item_invoke_hide(original, trace_visionkey);
861     clonetiler_trace_hide_tiled_clones_recursively (SP_OBJECT(SP_DOCUMENT_ROOT (trace_doc)));
863     sp_document_root (trace_doc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
864     sp_document_ensure_up_to_date(trace_doc);
866     trace_zoom = zoom;
869 static guint32
870 clonetiler_trace_pick (Geom::Rect box)
872     if (!trace_arena)
873         return 0;
875     Geom::Matrix t(Geom::Scale(trace_zoom, trace_zoom));
876     nr_arena_item_set_transform(trace_root, &t);
877     NRGC gc(NULL);
878     gc.transform.setIdentity();
879     nr_arena_item_invoke_update( trace_root, NULL, &gc,
880                                  NR_ARENA_ITEM_STATE_ALL,
881                                  NR_ARENA_ITEM_STATE_NONE );
883     /* Item integer bbox in points */
884     NRRectL ibox;
885     ibox.x0 = (int) floor(trace_zoom * box[Geom::X].min() + 0.5);
886     ibox.y0 = (int) floor(trace_zoom * box[Geom::Y].min() + 0.5);
887     ibox.x1 = (int) floor(trace_zoom * box[Geom::X].max() + 0.5);
888     ibox.y1 = (int) floor(trace_zoom * box[Geom::Y].max() + 0.5);
890     /* Find visible area */
891     int width = ibox.x1 - ibox.x0;
892     int height = ibox.y1 - ibox.y0;
894     /* Set up pixblock */
895     guchar *px = g_new(guchar, 4 * width * height);
897     if (px == NULL) {
898         return 0; // buffer is too big or too small, cannot pick, so return 0
899     }
901     memset(px, 0x00, 4 * width * height);
903     /* Render */
904     NRPixBlock pb;
905     nr_pixblock_setup_extern( &pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
906                               ibox.x0, ibox.y0, ibox.x1, ibox.y1,
907                               px, 4 * width, FALSE, FALSE );
908     nr_arena_item_invoke_render(NULL, trace_root, &ibox, &pb,
909                                  NR_ARENA_ITEM_RENDER_NO_CACHE );
911     double R = 0, G = 0, B = 0, A = 0;
912     double count = 0;
913     double weight = 0;
915     for (int y = ibox.y0; y < ibox.y1; y++) {
916         const unsigned char *s = NR_PIXBLOCK_PX (&pb) + (y - ibox.y0) * pb.rs;
917         for (int x = ibox.x0; x < ibox.x1; x++) {
918             count += 1;
919             weight += s[3] / 255.0;
920             R += s[0] / 255.0;
921             G += s[1] / 255.0;
922             B += s[2] / 255.0;
923             A += s[3] / 255.0;
924             s += 4;
925         }
926     }
928     nr_pixblock_release(&pb);
930     R = R / weight;
931     G = G / weight;
932     B = B / weight;
933     A = A / count;
935     R = CLAMP (R, 0.0, 1.0);
936     G = CLAMP (G, 0.0, 1.0);
937     B = CLAMP (B, 0.0, 1.0);
938     A = CLAMP (A, 0.0, 1.0);
940     return SP_RGBA32_F_COMPOSE (R, G, B, A);
943 static void
944 clonetiler_trace_finish ()
946     if (trace_doc) {
947         sp_item_invoke_hide(SP_ITEM(sp_document_root(trace_doc)), trace_visionkey);
948     }
949     if (trace_arena) {
950         ((NRObject *) trace_arena)->unreference();
951         trace_arena = NULL;
952     }
955 static void
956 clonetiler_unclump( GtkWidget */*widget*/, void * )
958     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
959     if (desktop == NULL)
960         return;
962     Inkscape::Selection *selection = sp_desktop_selection(desktop);
964     // check if something is selected
965     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
966         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump."));
967         return;
968     }
970     SPObject *obj = SP_OBJECT(selection->singleItem());
971     SPObject *parent = SP_OBJECT_PARENT (obj);
973     GSList *to_unclump = NULL; // not including the original
975     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
976         if (clonetiler_is_a_clone_of (child, obj)) {
977             to_unclump = g_slist_prepend (to_unclump, child);
978         }
979     }
981     sp_document_ensure_up_to_date(sp_desktop_document(desktop));
983     unclump (to_unclump);
985     g_slist_free (to_unclump);
987     sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
988                       _("Unclump tiled clones"));
991 static guint
992 clonetiler_number_of_clones (SPObject *obj)
994     SPObject *parent = SP_OBJECT_PARENT (obj);
996     guint n = 0;
998     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
999         if (clonetiler_is_a_clone_of (child, obj)) {
1000             n ++;
1001         }
1002     }
1004     return n;
1007 static void
1008 clonetiler_remove( GtkWidget */*widget*/, void *, bool do_undo = true )
1010     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1011     if (desktop == NULL)
1012         return;
1014     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1016     // check if something is selected
1017     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
1018         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove."));
1019         return;
1020     }
1022     SPObject *obj = SP_OBJECT(selection->singleItem());
1023     SPObject *parent = SP_OBJECT_PARENT (obj);
1025 // remove old tiling
1026     GSList *to_delete = NULL;
1027     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
1028         if (clonetiler_is_a_clone_of (child, obj)) {
1029             to_delete = g_slist_prepend (to_delete, child);
1030         }
1031     }
1032     for (GSList *i = to_delete; i; i = i->next) {
1033         SP_OBJECT(i->data)->deleteObject();
1034     }
1035     g_slist_free (to_delete);
1037     clonetiler_change_selection (NULL, selection, dlg);
1039     if (do_undo)
1040         sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
1041                           _("Delete tiled clones"));
1044 static Geom::Rect
1045 transform_rect( Geom::Rect const &r, Geom::Matrix const &m)
1047     using Geom::X;
1048     using Geom::Y;
1049     Geom::Point const p1 = r.corner(1) * m;
1050     Geom::Point const p2 = r.corner(2) * m;
1051     Geom::Point const p3 = r.corner(3) * m;
1052     Geom::Point const p4 = r.corner(4) * m;
1053     return Geom::Rect(
1054         Geom::Point(
1055             std::min(std::min(p1[X], p2[X]), std::min(p3[X], p4[X])),
1056             std::min(std::min(p1[Y], p2[Y]), std::min(p3[Y], p4[Y]))),
1057         Geom::Point(
1058             std::max(std::max(p1[X], p2[X]), std::max(p3[X], p4[X])),
1059             std::max(std::max(p1[Y], p2[Y]), std::max(p3[Y], p4[Y]))));
1062 /**
1063 Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same
1064 probability of being displaced.
1065  */
1066 static double
1067 randomize01 (double val, double rand)
1069     double base = MIN (val - rand, 1 - 2*rand);
1070     if (base < 0) base = 0;
1071     val = base + g_random_double_range (0, MIN (2 * rand, 1 - base));
1072     return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case...
1076 static void
1077 clonetiler_apply( GtkWidget */*widget*/, void * )
1079     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1080     if (desktop == NULL)
1081         return;
1082     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1083     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1085     // check if something is selected
1086     if (selection->isEmpty()) {
1087         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone."));
1088         return;
1089     }
1091     // Check if more than one object is selected.
1092     if (g_slist_length((GSList *) selection->itemList()) > 1) {
1093         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>."));
1094         return;
1095     }
1097     // set "busy" cursor
1098     desktop->setWaitingCursor();
1100     // set statusbar text
1101     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
1102     gtk_label_set_markup (GTK_LABEL(status), _("<small>Creating tiled clones...</small>"));
1103     gtk_widget_queue_draw(GTK_WIDGET(status));
1104     gdk_window_process_all_updates();
1106     SPObject *obj = SP_OBJECT(selection->singleItem());
1107     Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
1108     const char *id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
1109     SPObject *parent = SP_OBJECT_PARENT (obj);
1111     clonetiler_remove (NULL, NULL, false);
1113     double shiftx_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_per_i", 0, -10000, 10000);
1114     double shifty_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_per_i", 0, -10000, 10000);
1115     double shiftx_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_per_j", 0, -10000, 10000);
1116     double shifty_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_per_j", 0, -10000, 10000);
1117     double shiftx_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_rand", 0, 0, 1000);
1118     double shifty_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_rand", 0, 0, 1000);
1119     double shiftx_exp   =        prefs->getDoubleLimited(prefs_path + "shiftx_exp",   1, 0, 10);
1120     double shifty_exp   =        prefs->getDoubleLimited(prefs_path + "shifty_exp", 1, 0, 10);
1121     bool   shiftx_alternate =    prefs->getBool(prefs_path + "shiftx_alternate");
1122     bool   shifty_alternate =    prefs->getBool(prefs_path + "shifty_alternate");
1123     bool   shiftx_cumulate  =    prefs->getBool(prefs_path + "shiftx_cumulate");
1124     bool   shifty_cumulate  =    prefs->getBool(prefs_path + "shifty_cumulate");
1125     bool   shiftx_excludew  =    prefs->getBool(prefs_path + "shiftx_excludew");
1126     bool   shifty_excludeh  =    prefs->getBool(prefs_path + "shifty_excludeh");
1128     double scalex_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_per_i", 0, -100, 1000);
1129     double scaley_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_per_i", 0, -100, 1000);
1130     double scalex_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_per_j", 0, -100, 1000);
1131     double scaley_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_per_j", 0, -100, 1000);
1132     double scalex_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_rand",  0, 0, 1000);
1133     double scaley_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_rand",  0, 0, 1000);
1134     double scalex_exp   =        prefs->getDoubleLimited(prefs_path + "scalex_exp",   1, 0, 10);
1135     double scaley_exp   =        prefs->getDoubleLimited(prefs_path + "scaley_exp",   1, 0, 10);
1136     double scalex_log       =    prefs->getDoubleLimited(prefs_path + "scalex_log",   0, 0, 10);
1137     double scaley_log       =    prefs->getDoubleLimited(prefs_path + "scaley_log",   0, 0, 10);
1138     bool   scalex_alternate =    prefs->getBool(prefs_path + "scalex_alternate");
1139     bool   scaley_alternate =    prefs->getBool(prefs_path + "scaley_alternate");
1140     bool   scalex_cumulate  =    prefs->getBool(prefs_path + "scalex_cumulate");
1141     bool   scaley_cumulate  =    prefs->getBool(prefs_path + "scaley_cumulate");
1143     double rotate_per_i =        prefs->getDoubleLimited(prefs_path + "rotate_per_i", 0, -180, 180);
1144     double rotate_per_j =        prefs->getDoubleLimited(prefs_path + "rotate_per_j", 0, -180, 180);
1145     double rotate_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "rotate_rand", 0, 0, 100);
1146     bool   rotate_alternatei   = prefs->getBool(prefs_path + "rotate_alternatei");
1147     bool   rotate_alternatej   = prefs->getBool(prefs_path + "rotate_alternatej");
1148     bool   rotate_cumulatei    = prefs->getBool(prefs_path + "rotate_cumulatei");
1149     bool   rotate_cumulatej    = prefs->getBool(prefs_path + "rotate_cumulatej");
1151     double blur_per_i =   0.01 * prefs->getDoubleLimited(prefs_path + "blur_per_i", 0, 0, 100);
1152     double blur_per_j =   0.01 * prefs->getDoubleLimited(prefs_path + "blur_per_j", 0, 0, 100);
1153     bool   blur_alternatei =     prefs->getBool(prefs_path + "blur_alternatei");
1154     bool   blur_alternatej =     prefs->getBool(prefs_path + "blur_alternatej");
1155     double blur_rand =    0.01 * prefs->getDoubleLimited(prefs_path + "blur_rand", 0, 0, 100);
1157     double opacity_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "opacity_per_i", 0, 0, 100);
1158     double opacity_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "opacity_per_j", 0, 0, 100);
1159     bool   opacity_alternatei =   prefs->getBool(prefs_path + "opacity_alternatei");
1160     bool   opacity_alternatej =   prefs->getBool(prefs_path + "opacity_alternatej");
1161     double opacity_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "opacity_rand", 0, 0, 100);
1163     Glib::ustring initial_color =    prefs->getString(prefs_path + "initial_color");
1164     double hue_per_j =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_per_j", 0, -100, 100);
1165     double hue_per_i =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_per_i", 0, -100, 100);
1166     double hue_rand  =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_rand", 0, 0, 100);
1167     double saturation_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "saturation_per_j", 0, -100, 100);
1168     double saturation_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "saturation_per_i", 0, -100, 100);
1169     double saturation_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "saturation_rand", 0, 0, 100);
1170     double lightness_per_j =  0.01 * prefs->getDoubleLimited(prefs_path + "lightness_per_j", 0, -100, 100);
1171     double lightness_per_i =  0.01 * prefs->getDoubleLimited(prefs_path + "lightness_per_i", 0, -100, 100);
1172     double lightness_rand =   0.01 * prefs->getDoubleLimited(prefs_path + "lightness_rand", 0, 0, 100);
1173     bool   color_alternatej = prefs->getBool(prefs_path + "color_alternatej");
1174     bool   color_alternatei = prefs->getBool(prefs_path + "color_alternatei");
1176     int    type = prefs->getInt(prefs_path + "symmetrygroup", 0);
1177     bool   keepbbox = prefs->getBool(prefs_path + "keepbbox", true);
1178     int    imax = prefs->getInt(prefs_path + "imax", 2);
1179     int    jmax = prefs->getInt(prefs_path + "jmax", 2);
1181     bool   fillrect = prefs->getBool(prefs_path + "fillrect");
1182     double fillwidth = prefs->getDoubleLimited(prefs_path + "fillwidth", 50, 0, 1e6);
1183     double fillheight = prefs->getDoubleLimited(prefs_path + "fillheight", 50, 0, 1e6);
1185     bool   dotrace = prefs->getBool(prefs_path + "dotrace");
1186     int    pick = prefs->getInt(prefs_path + "pick");
1187     bool   pick_to_presence = prefs->getBool(prefs_path + "pick_to_presence");
1188     bool   pick_to_size = prefs->getBool(prefs_path + "pick_to_size");
1189     bool   pick_to_color = prefs->getBool(prefs_path + "pick_to_color");
1190     bool   pick_to_opacity = prefs->getBool(prefs_path + "pick_to_opacity");
1191     double rand_picked = 0.01 * prefs->getDoubleLimited(prefs_path + "rand_picked", 0, 0, 100);
1192     bool   invert_picked = prefs->getBool(prefs_path + "invert_picked");
1193     double gamma_picked = prefs->getDoubleLimited(prefs_path + "gamma_picked", 0, -10, 10);
1195     if (dotrace) {
1196         clonetiler_trace_setup (sp_desktop_document(desktop), 1.0, SP_ITEM (obj));
1197     }
1199     Geom::Point center;
1200     double w;
1201     double h;
1202     double x0;
1203     double y0;
1205     if (keepbbox &&
1206         obj_repr->attribute("inkscape:tile-w") &&
1207         obj_repr->attribute("inkscape:tile-h") &&
1208         obj_repr->attribute("inkscape:tile-x0") &&
1209         obj_repr->attribute("inkscape:tile-y0") &&
1210         obj_repr->attribute("inkscape:tile-cx") &&
1211         obj_repr->attribute("inkscape:tile-cy")) {
1213         double cx = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cx", 0);
1214         double cy = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cy", 0);
1215         center = Geom::Point (cx, cy);
1217         w = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-w", 0);
1218         h = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-h", 0);
1219         x0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-x0", 0);
1220         y0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-y0", 0);
1221     } else {
1222         bool prefs_bbox = prefs->getBool("/tools/bounding_box", false);
1223         SPItem::BBoxType bbox_type = ( prefs_bbox ? 
1224             SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX );
1225         Geom::OptRect r = SP_ITEM(obj)->getBounds(sp_item_i2doc_affine(SP_ITEM(obj)),
1226                                                         bbox_type);
1227         if (r) {
1228             w = r->dimensions()[Geom::X];
1229             h = r->dimensions()[Geom::Y];
1230             x0 = r->min()[Geom::X];
1231             y0 = r->min()[Geom::Y];
1232             center = desktop->dt2doc(SP_ITEM(obj)->getCenter());
1234             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", center[Geom::X]);
1235             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", center[Geom::Y]);
1236             sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
1237             sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
1238             sp_repr_set_svg_double(obj_repr, "inkscape:tile-x0", x0);
1239             sp_repr_set_svg_double(obj_repr, "inkscape:tile-y0", y0);
1240         } else {
1241             center = Geom::Point(0, 0);
1242             w = h = 0;
1243             x0 = y0 = 0;
1244         }
1245     }
1247     Geom::Point cur(0, 0);
1248     Geom::Rect bbox_original (Geom::Point (x0, y0), Geom::Point (x0 + w, y0 + h));
1249     double perimeter_original = (w + h)/4;
1251     // The integers i and j are reserved for tile column and row.
1252     // The doubles x and y are used for coordinates
1253     for (int i = 0;
1254          fillrect?
1255              (fabs(cur[Geom::X]) < fillwidth && i < 200) // prevent "freezing" with too large fillrect, arbitrarily limit rows
1256              : (i < imax);
1257          i ++) {
1258         for (int j = 0;
1259              fillrect?
1260                  (fabs(cur[Geom::Y]) < fillheight && j < 200) // prevent "freezing" with too large fillrect, arbitrarily limit cols
1261                  : (j < jmax);
1262              j ++) {
1264             // Note: We create a clone at 0,0 too, right over the original, in case our clones are colored
1266             // Get transform from symmetry, shift, scale, rotation
1267             Geom::Matrix t = clonetiler_get_transform (type, i, j, center[Geom::X], center[Geom::Y], w, h,
1268                                                        shiftx_per_i,     shifty_per_i,
1269                                                        shiftx_per_j,     shifty_per_j,
1270                                                        shiftx_rand,      shifty_rand,
1271                                                        shiftx_exp,       shifty_exp,
1272                                                        shiftx_alternate, shifty_alternate,
1273                                                        shiftx_cumulate,  shifty_cumulate,
1274                                                        shiftx_excludew,  shifty_excludeh,
1275                                                        scalex_per_i,     scaley_per_i,
1276                                                        scalex_per_j,     scaley_per_j,
1277                                                        scalex_rand,      scaley_rand,
1278                                                        scalex_exp,       scaley_exp,
1279                                                        scalex_log,       scaley_log,
1280                                                        scalex_alternate, scaley_alternate,
1281                                                        scalex_cumulate,  scaley_cumulate,
1282                                                        rotate_per_i,     rotate_per_j,
1283                                                        rotate_rand,
1284                                                        rotate_alternatei, rotate_alternatej,
1285                                                        rotate_cumulatei,  rotate_cumulatej      );
1287             cur = center * t - center;
1288             if (fillrect) {
1289                 if ((cur[Geom::X] > fillwidth) || (cur[Geom::Y] > fillheight)) { // off limits
1290                     continue;
1291                 }
1292             }
1294             gchar color_string[32]; *color_string = 0;
1296             // Color tab
1297             if (!initial_color.empty()) {
1298                 guint32 rgba = sp_svg_read_color (initial_color.data(), 0x000000ff);
1299                 float hsl[3];
1300                 sp_color_rgb_to_hsl_floatv (hsl, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba));
1302                 double eff_i = (color_alternatei? (i%2) : (i));
1303                 double eff_j = (color_alternatej? (j%2) : (j));
1305                 hsl[0] += hue_per_i * eff_i + hue_per_j * eff_j + hue_rand * g_random_double_range (-1, 1);
1306                 double notused;
1307                 hsl[0] = modf( hsl[0], &notused ); // Restrict to 0-1
1308                 hsl[1] += saturation_per_i * eff_i + saturation_per_j * eff_j + saturation_rand * g_random_double_range (-1, 1);
1309                 hsl[1] = CLAMP (hsl[1], 0, 1);
1310                 hsl[2] += lightness_per_i * eff_i + lightness_per_j * eff_j + lightness_rand * g_random_double_range (-1, 1);
1311                 hsl[2] = CLAMP (hsl[2], 0, 1);
1313                 float rgb[3];
1314                 sp_color_hsl_to_rgb_floatv (rgb, hsl[0], hsl[1], hsl[2]);
1315                 sp_svg_write_color(color_string, sizeof(color_string), SP_RGBA32_F_COMPOSE(rgb[0], rgb[1], rgb[2], 1.0));
1316             }
1318             // Blur
1319             double blur = 0.0;
1320             {
1321             int eff_i = (blur_alternatei? (i%2) : (i));
1322             int eff_j = (blur_alternatej? (j%2) : (j));
1323             blur =  (blur_per_i * eff_i + blur_per_j * eff_j + blur_rand * g_random_double_range (-1, 1));
1324             blur = CLAMP (blur, 0, 1);
1325             }
1327             // Opacity
1328             double opacity = 1.0;
1329             {
1330             int eff_i = (opacity_alternatei? (i%2) : (i));
1331             int eff_j = (opacity_alternatej? (j%2) : (j));
1332             opacity = 1 - (opacity_per_i * eff_i + opacity_per_j * eff_j + opacity_rand * g_random_double_range (-1, 1));
1333             opacity = CLAMP (opacity, 0, 1);
1334             }
1336             // Trace tab
1337             if (dotrace) {
1338                 Geom::Rect bbox_t = transform_rect (bbox_original, t);
1340                 guint32 rgba = clonetiler_trace_pick (bbox_t);
1341                 float r = SP_RGBA32_R_F(rgba);
1342                 float g = SP_RGBA32_G_F(rgba);
1343                 float b = SP_RGBA32_B_F(rgba);
1344                 float a = SP_RGBA32_A_F(rgba);
1346                 float hsl[3];
1347                 sp_color_rgb_to_hsl_floatv (hsl, r, g, b);
1349                 gdouble val = 0;
1350                 switch (pick) {
1351                 case PICK_COLOR:
1352                     val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max
1353                     break;
1354                 case PICK_OPACITY:
1355                     val = a;
1356                     break;
1357                 case PICK_R:
1358                     val = r;
1359                     break;
1360                 case PICK_G:
1361                     val = g;
1362                     break;
1363                 case PICK_B:
1364                     val = b;
1365                     break;
1366                 case PICK_H:
1367                     val = hsl[0];
1368                     break;
1369                 case PICK_S:
1370                     val = hsl[1];
1371                     break;
1372                 case PICK_L:
1373                     val = 1 - hsl[2];
1374                     break;
1375                 default:
1376                     break;
1377                 }
1379                 if (rand_picked > 0) {
1380                     val = randomize01 (val, rand_picked);
1381                     r = randomize01 (r, rand_picked);
1382                     g = randomize01 (g, rand_picked);
1383                     b = randomize01 (b, rand_picked);
1384                 }
1386                 if (gamma_picked != 0) {
1387                     double power;
1388                     if (gamma_picked > 0)
1389                         power = 1/(1 + fabs(gamma_picked));
1390                     else
1391                         power = 1 + fabs(gamma_picked);
1393                     val = pow (val, power);
1394                     r = pow (r, power);
1395                     g = pow (g, power);
1396                     b = pow (b, power);
1397                 }
1399                 if (invert_picked) {
1400                     val = 1 - val;
1401                     r = 1 - r;
1402                     g = 1 - g;
1403                     b = 1 - b;
1404                 }
1406                 val = CLAMP (val, 0, 1);
1407                 r = CLAMP (r, 0, 1);
1408                 g = CLAMP (g, 0, 1);
1409                 b = CLAMP (b, 0, 1);
1411                 // recompose tweaked color
1412                 rgba = SP_RGBA32_F_COMPOSE(r, g, b, a);
1414                 if (pick_to_presence) {
1415                     if (g_random_double_range (0, 1) > val) {
1416                         continue; // skip!
1417                     }
1418                 }
1419                 if (pick_to_size) {
1420                     t = Geom::Translate(-center[Geom::X], -center[Geom::Y]) * Geom::Scale (val, val) * Geom::Translate(center[Geom::X], center[Geom::Y]) * t;
1421                 }
1422                 if (pick_to_opacity) {
1423                     opacity *= val;
1424                 }
1425                 if (pick_to_color) {
1426                     sp_svg_write_color(color_string, sizeof(color_string), rgba);
1427                 }
1428             }
1430             if (opacity < 1e-6) { // invisibly transparent, skip
1431                     continue;
1432             }
1434             if (fabs(t[0]) + fabs (t[1]) + fabs(t[2]) + fabs(t[3]) < 1e-6) { // too small, skip
1435                     continue;
1436             }
1438             // Create the clone
1439             Inkscape::XML::Node *clone = obj_repr->document()->createElement("svg:use");
1440             clone->setAttribute("x", "0");
1441             clone->setAttribute("y", "0");
1442             clone->setAttribute("inkscape:tiled-clone-of", id_href);
1443             clone->setAttribute("xlink:href", id_href);
1445             Geom::Point new_center;
1446             bool center_set = false;
1447             if (obj_repr->attribute("inkscape:transform-center-x") || obj_repr->attribute("inkscape:transform-center-y")) {
1448                 new_center = desktop->dt2doc(SP_ITEM(obj)->getCenter()) * t;
1449                 center_set = true;
1450             }
1452             gchar *affinestr=sp_svg_transform_write(t);
1453             clone->setAttribute("transform", affinestr);
1454             g_free(affinestr);
1456             if (opacity < 1.0) {
1457                 sp_repr_set_css_double(clone, "opacity", opacity);
1458             }
1460             if (*color_string) {
1461                 clone->setAttribute("fill", color_string);
1462                 clone->setAttribute("stroke", color_string);
1463             }
1465             // add the new clone to the top of the original's parent
1466             SP_OBJECT_REPR(parent)->appendChild(clone);
1468             if (blur > 0.0) {
1469                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1470                 double perimeter = perimeter_original * t.descrim();
1471                 double radius = blur * perimeter;
1472                 // this is necessary for all newly added clones to have correct bboxes,
1473                 // otherwise filters won't work:
1474                 sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1475                 // it's hard to figure out exact width/height of the tile without having an object
1476                 // that we can take bbox of; however here we only need a lower bound so that blur
1477                 // margins are not too small, and the perimeter should work
1478                 SPFilter *constructed = new_filter_gaussian_blur(sp_desktop_document(desktop), radius, t.descrim(), t.expansionX(), t.expansionY(), perimeter, perimeter);
1479                 sp_style_set_property_url (clone_object, "filter", SP_OBJECT(constructed), false);
1480             }
1482             if (center_set) {
1483                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1484                 if (clone_object && SP_IS_ITEM(clone_object)) {
1485                     clone_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1486                     SP_ITEM(clone_object)->setCenter(desktop->doc2dt(new_center));
1487                     clone_object->updateRepr();
1488                 }
1489             }
1491             Inkscape::GC::release(clone);
1492         }
1493         cur[Geom::Y] = 0;
1494     }
1496     if (dotrace) {
1497         clonetiler_trace_finish ();
1498     }
1500     clonetiler_change_selection (NULL, selection, dlg);
1502     desktop->clearWaitingCursor();
1504     sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER,
1505                      _("Create tiled clones"));
1508 static GtkWidget *
1509 clonetiler_new_tab (GtkWidget *nb, const gchar *label)
1511     GtkWidget *l = gtk_label_new_with_mnemonic (label);
1512     GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN);
1513     gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN);
1514     gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l);
1515     return vb;
1518 static void
1519 clonetiler_checkbox_toggled (GtkToggleButton *tb, gpointer *data)
1521     const gchar *attr = (const gchar *) data;
1522     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1523     prefs->setBool(prefs_path + attr, gtk_toggle_button_get_active(tb));
1526 static GtkWidget *
1527 clonetiler_checkbox (GtkTooltips *tt, const char *tip, const char *attr)
1529     GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
1531     GtkWidget *b = gtk_check_button_new ();
1532     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, tip, NULL);
1534     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1535     bool value = prefs->getBool(prefs_path + attr);
1536     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(b), value);
1538     gtk_box_pack_end (GTK_BOX (hb), b, FALSE, TRUE, 0);
1539     gtk_signal_connect ( GTK_OBJECT (b), "clicked",
1540                          GTK_SIGNAL_FUNC (clonetiler_checkbox_toggled), (gpointer) attr);
1542     g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
1544     return hb;
1548 static void
1549 clonetiler_value_changed (GtkAdjustment *adj, gpointer data)
1551     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1552     const gchar *pref = (const gchar *) data;
1553     prefs->setDouble(prefs_path + pref, adj->value);
1556 static GtkWidget *
1557 clonetiler_spinbox (GtkTooltips *tt, const char *tip, const char *attr, double lower, double upper, const gchar *suffix, bool exponent = false)
1559     GtkWidget *hb = gtk_hbox_new(FALSE, 0);
1561     {
1562         GtkObject *a;
1563         if (exponent)
1564             a = gtk_adjustment_new(1.0, lower, upper, 0.01, 0.05, 0.1);
1565         else
1566             a = gtk_adjustment_new(0.0, lower, upper, 0.1, 0.5, 2);
1568         GtkWidget *sb;
1569         if (exponent)
1570             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.01, 2);
1571         else
1572             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.1, 1);
1574         gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, tip, NULL);
1575         gtk_entry_set_width_chars (GTK_ENTRY (sb), 4);
1576         gtk_box_pack_start (GTK_BOX (hb), sb, FALSE, FALSE, SB_MARGIN);
1578         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1579         double value = prefs->getDoubleLimited(prefs_path + attr, exponent? 1.0 : 0.0, lower, upper);
1580         gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
1581         gtk_signal_connect(GTK_OBJECT(a), "value_changed",
1582                            GTK_SIGNAL_FUNC(clonetiler_value_changed), (gpointer) attr);
1584         if (exponent)
1585             g_object_set_data (G_OBJECT(sb), "oneable", GINT_TO_POINTER(TRUE));
1586         else
1587             g_object_set_data (G_OBJECT(sb), "zeroable", GINT_TO_POINTER(TRUE));
1588     }
1590     {
1591         GtkWidget *l = gtk_label_new ("");
1592         gtk_label_set_markup (GTK_LABEL(l), suffix);
1593         gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0);
1594         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
1595     }
1597     return hb;
1600 static void
1601 clonetiler_symgroup_changed( GtkMenuItem */*item*/, gpointer data )
1603     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1604     gint group_new = GPOINTER_TO_INT (data);
1605     prefs->setInt(prefs_path + "symmetrygroup", group_new);
1608 static void
1609 clonetiler_xy_changed (GtkAdjustment *adj, gpointer data)
1611     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1612     const gchar *pref = (const gchar *) data;
1613     prefs->setInt(prefs_path + pref, (int) floor(adj->value + 0.5));
1616 static void
1617 clonetiler_keep_bbox_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1619     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1620     prefs->setBool(prefs_path + "keepbbox", gtk_toggle_button_get_active(tb));
1623 static void
1624 clonetiler_pick_to (GtkToggleButton *tb, gpointer data)
1626     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1627     const gchar *pref = (const gchar *) data;
1628     prefs->setBool(prefs_path + pref, gtk_toggle_button_get_active(tb));
1632 static void
1633 clonetiler_reset_recursive (GtkWidget *w)
1635     if (w && GTK_IS_OBJECT(w)) {
1636         {
1637             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "zeroable"));
1638             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1639                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1640                 gtk_adjustment_set_value (a, 0);
1641             }
1642         }
1643         {
1644             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "oneable"));
1645             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1646                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1647                 gtk_adjustment_set_value (a, 1);
1648             }
1649         }
1650         {
1651             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "uncheckable"));
1652             if (r && GTK_IS_TOGGLE_BUTTON(w)) { // checkbox
1653                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(w), FALSE);
1654             }
1655         }
1656     }
1658     if (GTK_IS_CONTAINER(w)) {
1659         GList *ch = gtk_container_get_children (GTK_CONTAINER(w));
1660         for (GList *i = ch; i != NULL; i = i->next) {
1661             clonetiler_reset_recursive (GTK_WIDGET(i->data));
1662         }
1663         g_list_free (ch);
1664     }
1667 static void
1668 clonetiler_reset( GtkWidget */*widget*/, void * )
1670     clonetiler_reset_recursive (dlg);
1673 static void
1674 clonetiler_table_attach (GtkWidget *table, GtkWidget *widget, float align, int row, int col)
1676     GtkWidget *a = gtk_alignment_new (align, 0, 0, 0);
1677     gtk_container_add(GTK_CONTAINER(a), widget);
1678     gtk_table_attach ( GTK_TABLE (table), a, col, col + 1, row, row + 1, (GtkAttachOptions)4, (GtkAttachOptions)0, 0, 0 );
1681 static GtkWidget *
1682 clonetiler_table_x_y_rand (int values)
1684     GtkWidget *table = gtk_table_new (values + 2, 5, FALSE);
1685     gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
1686     gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1687     gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1689     {
1690         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1692         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, INKSCAPE_ICON_OBJECT_ROWS);
1693         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1695         GtkWidget *l = gtk_label_new ("");
1696         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per row:</small>"));
1697         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1699         clonetiler_table_attach (table, hb, 0, 1, 2);
1700     }
1702     {
1703         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1705         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, INKSCAPE_ICON_OBJECT_COLUMNS);
1706         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1708         GtkWidget *l = gtk_label_new ("");
1709         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per column:</small>"));
1710         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1712         clonetiler_table_attach (table, hb, 0, 1, 3);
1713     }
1715     {
1716         GtkWidget *l = gtk_label_new ("");
1717         gtk_label_set_markup (GTK_LABEL(l), _("<small>Randomize:</small>"));
1718         clonetiler_table_attach (table, l, 0, 1, 4);
1719     }
1721     return table;
1724 static void
1725 clonetiler_pick_switched( GtkToggleButton */*tb*/, gpointer data )
1727     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1728     guint v = GPOINTER_TO_INT (data);
1729     prefs->setInt(prefs_path + "pick", v);
1733 static void
1734 clonetiler_switch_to_create( GtkToggleButton */*tb*/, GtkWidget *dlg )
1736     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1737     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1739     if (rowscols) {
1740         gtk_widget_set_sensitive (rowscols, TRUE);
1741     }
1742     if (widthheight) {
1743         gtk_widget_set_sensitive (widthheight, FALSE);
1744     }
1746     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1747     prefs->setBool(prefs_path + "fillrect", false);
1751 static void
1752 clonetiler_switch_to_fill( GtkToggleButton */*tb*/, GtkWidget *dlg )
1754     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1755     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1757     if (rowscols) {
1758         gtk_widget_set_sensitive (rowscols, FALSE);
1759     }
1760     if (widthheight) {
1761         gtk_widget_set_sensitive (widthheight, TRUE);
1762     }
1764     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1765     prefs->setBool(prefs_path + "fillrect", true);
1771 static void
1772 clonetiler_fill_width_changed (GtkAdjustment *adj, GtkWidget *u)
1774     gdouble const raw_dist = adj->value;
1775     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1776     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1778     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1779     prefs->setDouble(prefs_path + "fillwidth", pixels);
1782 static void
1783 clonetiler_fill_height_changed (GtkAdjustment *adj, GtkWidget *u)
1785     gdouble const raw_dist = adj->value;
1786     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1787     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1789     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1790     prefs->setDouble(prefs_path + "fillheight", pixels);
1794 static void
1795 clonetiler_do_pick_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1797     GtkWidget *vvb = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "dotrace");
1799     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1800     prefs->setBool(prefs_path + "dotrace", gtk_toggle_button_get_active (tb));
1802     if (vvb)
1803         gtk_widget_set_sensitive (vvb, gtk_toggle_button_get_active (tb));
1809 void
1810 clonetiler_dialog (void)
1812     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1813     if (!dlg)
1814     {
1815         gchar title[500];
1816         sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_CLONETILER), title);
1818         dlg = sp_window_new (title, TRUE);
1819         if (x == -1000 || y == -1000) {
1820             x = prefs->getInt(prefs_path + "x", -1000);
1821             y = prefs->getInt(prefs_path + "y", -1000);
1822         }
1824         if (w ==0 || h == 0) {
1825             w = prefs->getInt(prefs_path + "w", 0);
1826             h = prefs->getInt(prefs_path + "h", 0);
1827         }
1829 //        if (x<0) x=0;
1830 //        if (y<0) y=0;
1832         if (w && h) {
1833             gtk_window_resize ((GtkWindow *) dlg, w, h);
1834         }
1835         if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) {
1836             gtk_window_move ((GtkWindow *) dlg, x, y);
1838         } else {
1839             gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
1840         }
1843         sp_transientize (dlg);
1844         wd.win = dlg;
1845         wd.stop = 0;
1848         gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);
1850         gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (clonetiler_dialog_destroy), dlg);
1851         gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (clonetiler_dialog_delete), dlg);
1853         g_signal_connect   ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (clonetiler_dialog_delete), dlg);
1854         g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg);
1855         g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg);
1856         g_signal_connect   ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd);
1858         GtkTooltips *tt = gtk_tooltips_new();
1860         GtkWidget *mainbox = gtk_vbox_new(FALSE, 4);
1861         gtk_container_set_border_width (GTK_CONTAINER (mainbox), 6);
1862         gtk_container_add (GTK_CONTAINER (dlg), mainbox);
1864         GtkWidget *nb = gtk_notebook_new ();
1865         gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0);
1868 // Symmetry
1869         {
1870             GtkWidget *vb = clonetiler_new_tab (nb, _("_Symmetry"));
1872             GtkWidget *om = gtk_option_menu_new ();
1873             /* TRANSLATORS: For the following 17 symmetry groups, see
1874              * http://www.bib.ulb.ac.be/coursmath/doc/17.htm (visual examples);
1875              * http://www.clarku.edu/~djoyce/wallpaper/seventeen.html (English vocabulary); or
1876              * http://membres.lycos.fr/villemingerard/Geometri/Sym1D.htm (French vocabulary).
1877              */
1878             gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), om, _("Select one of the 17 symmetry groups for the tiling"), NULL);
1879             gtk_box_pack_start (GTK_BOX (vb), om, FALSE, FALSE, SB_MARGIN);
1881             GtkWidget *m = gtk_menu_new ();
1882             int current = prefs->getInt(prefs_path + "symmetrygroup", 0);
1884             struct SymGroups {
1885                 int group;
1886                 gchar const *label;
1887             } const sym_groups[] = {
1888                 // TRANSLATORS: "translation" means "shift" / "displacement" here.
1889                 {TILE_P1, _("<b>P1</b>: simple translation")},
1890                 {TILE_P2, _("<b>P2</b>: 180&#176; rotation")},
1891                 {TILE_PM, _("<b>PM</b>: reflection")},
1892                 // TRANSLATORS: "glide reflection" is a reflection and a translation combined.
1893                 //  For more info, see http://mathforum.org/sum95/suzanne/symsusan.html
1894                 {TILE_PG, _("<b>PG</b>: glide reflection")},
1895                 {TILE_CM, _("<b>CM</b>: reflection + glide reflection")},
1896                 {TILE_PMM, _("<b>PMM</b>: reflection + reflection")},
1897                 {TILE_PMG, _("<b>PMG</b>: reflection + 180&#176; rotation")},
1898                 {TILE_PGG, _("<b>PGG</b>: glide reflection + 180&#176; rotation")},
1899                 {TILE_CMM, _("<b>CMM</b>: reflection + reflection + 180&#176; rotation")},
1900                 {TILE_P4, _("<b>P4</b>: 90&#176; rotation")},
1901                 {TILE_P4M, _("<b>P4M</b>: 90&#176; rotation + 45&#176; reflection")},
1902                 {TILE_P4G, _("<b>P4G</b>: 90&#176; rotation + 90&#176; reflection")},
1903                 {TILE_P3, _("<b>P3</b>: 120&#176; rotation")},
1904                 {TILE_P31M, _("<b>P31M</b>: reflection + 120&#176; rotation, dense")},
1905                 {TILE_P3M1, _("<b>P3M1</b>: reflection + 120&#176; rotation, sparse")},
1906                 {TILE_P6, _("<b>P6</b>: 60&#176; rotation")},
1907                 {TILE_P6M, _("<b>P6M</b>: reflection + 60&#176; rotation")},
1908             };
1910             for (unsigned j = 0; j < G_N_ELEMENTS(sym_groups); ++j) {
1911                 SymGroups const &sg = sym_groups[j];
1913                 GtkWidget *l = gtk_label_new ("");
1914                 gtk_label_set_markup (GTK_LABEL(l), sg.label);
1915                 gtk_misc_set_alignment (GTK_MISC(l), 0, 0.5);
1917                 GtkWidget *item = gtk_menu_item_new ();
1918                 gtk_container_add (GTK_CONTAINER (item), l);
1920                 gtk_signal_connect ( GTK_OBJECT (item), "activate",
1921                                      GTK_SIGNAL_FUNC (clonetiler_symgroup_changed),
1922                                      GINT_TO_POINTER (sg.group) );
1924                 gtk_menu_append (GTK_MENU (m), item);
1925             }
1927             gtk_option_menu_set_menu (GTK_OPTION_MENU (om), m);
1928             gtk_option_menu_set_history ( GTK_OPTION_MENU (om), current);
1929         }
1931         table_row_labels = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1933 // Shift
1934         {
1935             GtkWidget *vb = clonetiler_new_tab (nb, _("S_hift"));
1937             GtkWidget *table = clonetiler_table_x_y_rand (3);
1938             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1940             // X
1941             {
1942                 GtkWidget *l = gtk_label_new ("");
1943                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) horizontally by this amount
1944                     // xgettext:no-c-format
1945                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift X:</b>"));
1946                 gtk_size_group_add_widget(table_row_labels, l);
1947                 clonetiler_table_attach (table, l, 1, 2, 1);
1948             }
1950             {
1951                 GtkWidget *l = clonetiler_spinbox (tt,
1952                     // xgettext:no-c-format
1953                                                    _("Horizontal shift per row (in % of tile width)"), "shiftx_per_j",
1954                                                    -10000, 10000, "%");
1955                 clonetiler_table_attach (table, l, 0, 2, 2);
1956             }
1958             {
1959                 GtkWidget *l = clonetiler_spinbox (tt,
1960                     // xgettext:no-c-format
1961                                                    _("Horizontal shift per column (in % of tile width)"), "shiftx_per_i",
1962                                                    -10000, 10000, "%");
1963                 clonetiler_table_attach (table, l, 0, 2, 3);
1964             }
1966             {
1967                 GtkWidget *l = clonetiler_spinbox (tt,
1968                                                    _("Randomize the horizontal shift by this percentage"), "shiftx_rand",
1969                                                    0, 1000, "%");
1970                 clonetiler_table_attach (table, l, 0, 2, 4);
1971             }
1973             // Y
1974             {
1975                 GtkWidget *l = gtk_label_new ("");
1976                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) vertically by this amount
1977                     // xgettext:no-c-format
1978                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift Y:</b>"));
1979                 gtk_size_group_add_widget(table_row_labels, l);
1980                 clonetiler_table_attach (table, l, 1, 3, 1);
1981             }
1983             {
1984                 GtkWidget *l = clonetiler_spinbox (tt,
1985                     // xgettext:no-c-format
1986                                                    _("Vertical shift per row (in % of tile height)"), "shifty_per_j",
1987                                                    -10000, 10000, "%");
1988                 clonetiler_table_attach (table, l, 0, 3, 2);
1989             }
1991             {
1992                 GtkWidget *l = clonetiler_spinbox (tt,
1993                     // xgettext:no-c-format
1994                                                    _("Vertical shift per column (in % of tile height)"), "shifty_per_i",
1995                                                    -10000, 10000, "%");
1996                 clonetiler_table_attach (table, l, 0, 3, 3);
1997             }
1999             {
2000                 GtkWidget *l = clonetiler_spinbox (tt,
2001                                                    _("Randomize the vertical shift by this percentage"), "shifty_rand",
2002                                                    0, 1000, "%");
2003                 clonetiler_table_attach (table, l, 0, 3, 4);
2004             }
2006             // Exponent
2007             {
2008                 GtkWidget *l = gtk_label_new ("");
2009                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2010                 gtk_size_group_add_widget(table_row_labels, l);
2011                 clonetiler_table_attach (table, l, 1, 4, 1);
2012             }
2014             {
2015                 GtkWidget *l = clonetiler_spinbox (tt,
2016                                                    _("Whether rows are spaced evenly (1), converge (<1) or diverge (>1)"), "shifty_exp",
2017                                                    0, 10, "", true);
2018                 clonetiler_table_attach (table, l, 0, 4, 2);
2019             }
2021             {
2022                 GtkWidget *l = clonetiler_spinbox (tt,
2023                                                    _("Whether columns are spaced evenly (1), converge (<1) or diverge (>1)"), "shiftx_exp",
2024                                                    0, 10, "", true);
2025                 clonetiler_table_attach (table, l, 0, 4, 3);
2026             }
2028             { // alternates
2029                 GtkWidget *l = gtk_label_new ("");
2030                 // TRANSLATORS: "Alternate" is a verb here
2031                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2032                 gtk_size_group_add_widget(table_row_labels, l);
2033                 clonetiler_table_attach (table, l, 1, 5, 1);
2034             }
2036             {
2037                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each row"), "shifty_alternate");
2038                 clonetiler_table_attach (table, l, 0, 5, 2);
2039             }
2041             {
2042                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each column"), "shiftx_alternate");
2043                 clonetiler_table_attach (table, l, 0, 5, 3);
2044             }
2046             { // Cumulate
2047                 GtkWidget *l = gtk_label_new ("");
2048                 // TRANSLATORS: "Cumulate" is a verb here
2049                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2050                 gtk_size_group_add_widget(table_row_labels, l);
2051                 clonetiler_table_attach (table, l, 1, 6, 1);
2052             }
2054             {
2055                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each row"), "shifty_cumulate");
2056                 clonetiler_table_attach (table, l, 0, 6, 2);
2057             }
2059             {
2060                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each column"), "shiftx_cumulate");
2061                 clonetiler_table_attach (table, l, 0, 6, 3);
2062             }
2064             { // Exclude tile width and height in shift
2065                 GtkWidget *l = gtk_label_new ("");
2066                 // TRANSLATORS: "Cumulate" is a verb here
2067                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Exclude tile:</small>"));
2068                 gtk_size_group_add_widget(table_row_labels, l);
2069                 clonetiler_table_attach (table, l, 1, 7, 1);
2070             }
2072             {
2073                 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile height in shift"), "shifty_excludeh");
2074                 clonetiler_table_attach (table, l, 0, 7, 2);
2075             }
2077             {
2078                 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile width in shift"), "shiftx_excludew");
2079                 clonetiler_table_attach (table, l, 0, 7, 3);
2080             }
2082         }
2085 // Scale
2086         {
2087             GtkWidget *vb = clonetiler_new_tab (nb, _("Sc_ale"));
2089             GtkWidget *table = clonetiler_table_x_y_rand (2);
2090             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2092             // X
2093             {
2094                 GtkWidget *l = gtk_label_new ("");
2095                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale X:</b>"));
2096                 gtk_size_group_add_widget(table_row_labels, l);
2097                 clonetiler_table_attach (table, l, 1, 2, 1);
2098             }
2100             {
2101                 GtkWidget *l = clonetiler_spinbox (tt,
2102                     // xgettext:no-c-format
2103                                                    _("Horizontal scale per row (in % of tile width)"), "scalex_per_j",
2104                                                    -100, 1000, "%");
2105                 clonetiler_table_attach (table, l, 0, 2, 2);
2106             }
2108             {
2109                 GtkWidget *l = clonetiler_spinbox (tt,
2110                     // xgettext:no-c-format
2111                                                    _("Horizontal scale per column (in % of tile width)"), "scalex_per_i",
2112                                                    -100, 1000, "%");
2113                 clonetiler_table_attach (table, l, 0, 2, 3);
2114             }
2116             {
2117                 GtkWidget *l = clonetiler_spinbox (tt,
2118                                                    _("Randomize the horizontal scale by this percentage"), "scalex_rand",
2119                                                    0, 1000, "%");
2120                 clonetiler_table_attach (table, l, 0, 2, 4);
2121             }
2123             // Y
2124             {
2125                 GtkWidget *l = gtk_label_new ("");
2126                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale Y:</b>"));
2127                 gtk_size_group_add_widget(table_row_labels, l);
2128                 clonetiler_table_attach (table, l, 1, 3, 1);
2129             }
2131             {
2132                 GtkWidget *l = clonetiler_spinbox (tt,
2133                     // xgettext:no-c-format
2134                                                    _("Vertical scale per row (in % of tile height)"), "scaley_per_j",
2135                                                    -100, 1000, "%");
2136                 clonetiler_table_attach (table, l, 0, 3, 2);
2137             }
2139             {
2140                 GtkWidget *l = clonetiler_spinbox (tt,
2141                     // xgettext:no-c-format
2142                                                    _("Vertical scale per column (in % of tile height)"), "scaley_per_i",
2143                                                    -100, 1000, "%");
2144                 clonetiler_table_attach (table, l, 0, 3, 3);
2145             }
2147             {
2148                 GtkWidget *l = clonetiler_spinbox (tt,
2149                                                    _("Randomize the vertical scale by this percentage"), "scaley_rand",
2150                                                    0, 1000, "%");
2151                 clonetiler_table_attach (table, l, 0, 3, 4);
2152             }
2154             // Exponent
2155             {
2156                 GtkWidget *l = gtk_label_new ("");
2157                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2158                 gtk_size_group_add_widget(table_row_labels, l);
2159                 clonetiler_table_attach (table, l, 1, 4, 1);
2160             }
2162             {
2163                 GtkWidget *l = clonetiler_spinbox (tt,
2164                                                    _("Whether row scaling is uniform (1), converge (<1) or diverge (>1)"), "scaley_exp",
2165                                                    0, 10, "", true);
2166                 clonetiler_table_attach (table, l, 0, 4, 2);
2167             }
2169             {
2170                 GtkWidget *l = clonetiler_spinbox (tt,
2171                                                    _("Whether column scaling is uniform (1), converge (<1) or diverge (>1)"), "scalex_exp",
2172                                                    0, 10, "", true);
2173                 clonetiler_table_attach (table, l, 0, 4, 3);
2174             }
2176             // Logarithmic (as in logarithmic spiral)
2177             {
2178                 GtkWidget *l = gtk_label_new ("");
2179                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Base:</b>"));
2180                 gtk_size_group_add_widget(table_row_labels, l);
2181                 clonetiler_table_attach (table, l, 1, 5, 1);
2182             }
2184             {
2185                 GtkWidget *l = clonetiler_spinbox (tt,
2186                                                    _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scaley_log",
2187                                                    0, 10, "", false);
2188                 clonetiler_table_attach (table, l, 0, 5, 2);
2189             }
2191             {
2192                 GtkWidget *l = clonetiler_spinbox (tt,
2193                                                    _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scalex_log",
2194                                                    0, 10, "", false);
2195                 clonetiler_table_attach (table, l, 0, 5, 3);
2196             }
2198             { // alternates
2199                 GtkWidget *l = gtk_label_new ("");
2200                 // TRANSLATORS: "Alternate" is a verb here
2201                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2202                 gtk_size_group_add_widget(table_row_labels, l);
2203                 clonetiler_table_attach (table, l, 1, 6, 1);
2204             }
2206             {
2207                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each row"), "scaley_alternate");
2208                 clonetiler_table_attach (table, l, 0, 6, 2);
2209             }
2211             {
2212                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each column"), "scalex_alternate");
2213                 clonetiler_table_attach (table, l, 0, 6, 3);
2214             }
2216             { // Cumulate
2217                 GtkWidget *l = gtk_label_new ("");
2218                 // TRANSLATORS: "Cumulate" is a verb here
2219                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2220                 gtk_size_group_add_widget(table_row_labels, l);
2221                 clonetiler_table_attach (table, l, 1, 7, 1);
2222             }
2224             {
2225                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each row"), "scaley_cumulate");
2226                 clonetiler_table_attach (table, l, 0, 7, 2);
2227             }
2229             {
2230                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each column"), "scalex_cumulate");
2231                 clonetiler_table_attach (table, l, 0, 7, 3);
2232             }
2234         }
2237 // Rotation
2238         {
2239             GtkWidget *vb = clonetiler_new_tab (nb, _("_Rotation"));
2241             GtkWidget *table = clonetiler_table_x_y_rand (1);
2242             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2244             // Angle
2245             {
2246                 GtkWidget *l = gtk_label_new ("");
2247                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Angle:</b>"));
2248                 gtk_size_group_add_widget(table_row_labels, l);
2249                 clonetiler_table_attach (table, l, 1, 2, 1);
2250             }
2252             {
2253                 GtkWidget *l = clonetiler_spinbox (tt,
2254                     // xgettext:no-c-format
2255                                                    _("Rotate tiles by this angle for each row"), "rotate_per_j",
2256                                                    -180, 180, "&#176;");
2257                 clonetiler_table_attach (table, l, 0, 2, 2);
2258             }
2260             {
2261                 GtkWidget *l = clonetiler_spinbox (tt,
2262                     // xgettext:no-c-format
2263                                                    _("Rotate tiles by this angle for each column"), "rotate_per_i",
2264                                                    -180, 180, "&#176;");
2265                 clonetiler_table_attach (table, l, 0, 2, 3);
2266             }
2268             {
2269                 GtkWidget *l = clonetiler_spinbox (tt,
2270                                                    _("Randomize the rotation angle by this percentage"), "rotate_rand",
2271                                                    0, 100, "%");
2272                 clonetiler_table_attach (table, l, 0, 2, 4);
2273             }
2275             { // alternates
2276                 GtkWidget *l = gtk_label_new ("");
2277                 // TRANSLATORS: "Alternate" is a verb here
2278                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2279                 gtk_size_group_add_widget(table_row_labels, l);
2280                 clonetiler_table_attach (table, l, 1, 3, 1);
2281             }
2283             {
2284                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each row"), "rotate_alternatej");
2285                 clonetiler_table_attach (table, l, 0, 3, 2);
2286             }
2288             {
2289                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each column"), "rotate_alternatei");
2290                 clonetiler_table_attach (table, l, 0, 3, 3);
2291             }
2293             { // Cumulate
2294                 GtkWidget *l = gtk_label_new ("");
2295                 // TRANSLATORS: "Cumulate" is a verb here
2296                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2297                 gtk_size_group_add_widget(table_row_labels, l);
2298                 clonetiler_table_attach (table, l, 1, 4, 1);
2299             }
2301             {
2302                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each row"), "rotate_cumulatej");
2303                 clonetiler_table_attach (table, l, 0, 4, 2);
2304             }
2306             {
2307                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each column"), "rotate_cumulatei");
2308                 clonetiler_table_attach (table, l, 0, 4, 3);
2309             }
2311         }
2314 // Blur and opacity
2315         {
2316             GtkWidget *vb = clonetiler_new_tab (nb, _("_Blur & opacity"));
2318             GtkWidget *table = clonetiler_table_x_y_rand (1);
2319             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2322             // Blur
2323             {
2324                 GtkWidget *l = gtk_label_new ("");
2325                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Blur:</b>"));
2326                 gtk_size_group_add_widget(table_row_labels, l);
2327                 clonetiler_table_attach (table, l, 1, 2, 1);
2328             }
2330             {
2331                 GtkWidget *l = clonetiler_spinbox (tt,
2332                                                    _("Blur tiles by this percentage for each row"), "blur_per_j",
2333                                                    0, 100, "%");
2334                 clonetiler_table_attach (table, l, 0, 2, 2);
2335             }
2337             {
2338                 GtkWidget *l = clonetiler_spinbox (tt,
2339                                                    _("Blur tiles by this percentage for each column"), "blur_per_i",
2340                                                    0, 100, "%");
2341                 clonetiler_table_attach (table, l, 0, 2, 3);
2342             }
2344             {
2345                 GtkWidget *l = clonetiler_spinbox (tt,
2346                                                    _("Randomize the tile blur by this percentage"), "blur_rand",
2347                                                    0, 100, "%");
2348                 clonetiler_table_attach (table, l, 0, 2, 4);
2349             }
2351             { // alternates
2352                 GtkWidget *l = gtk_label_new ("");
2353                 // TRANSLATORS: "Alternate" is a verb here
2354                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2355                 gtk_size_group_add_widget(table_row_labels, l);
2356                 clonetiler_table_attach (table, l, 1, 3, 1);
2357             }
2359             {
2360                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each row"), "blur_alternatej");
2361                 clonetiler_table_attach (table, l, 0, 3, 2);
2362             }
2364             {
2365                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each column"), "blur_alternatei");
2366                 clonetiler_table_attach (table, l, 0, 3, 3);
2367             }
2371             // Dissolve
2372             {
2373                 GtkWidget *l = gtk_label_new ("");
2374                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Fade out:</b>"));
2375                 gtk_size_group_add_widget(table_row_labels, l);
2376                 clonetiler_table_attach (table, l, 1, 4, 1);
2377             }
2379             {
2380                 GtkWidget *l = clonetiler_spinbox (tt,
2381                                                    _("Decrease tile opacity by this percentage for each row"), "opacity_per_j",
2382                                                    0, 100, "%");
2383                 clonetiler_table_attach (table, l, 0, 4, 2);
2384             }
2386             {
2387                 GtkWidget *l = clonetiler_spinbox (tt,
2388                                                    _("Decrease tile opacity by this percentage for each column"), "opacity_per_i",
2389                                                    0, 100, "%");
2390                 clonetiler_table_attach (table, l, 0, 4, 3);
2391             }
2393             {
2394                 GtkWidget *l = clonetiler_spinbox (tt,
2395                                                    _("Randomize the tile opacity by this percentage"), "opacity_rand",
2396                                                    0, 100, "%");
2397                 clonetiler_table_attach (table, l, 0, 4, 4);
2398             }
2400             { // alternates
2401                 GtkWidget *l = gtk_label_new ("");
2402                 // TRANSLATORS: "Alternate" is a verb here
2403                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2404                 gtk_size_group_add_widget(table_row_labels, l);
2405                 clonetiler_table_attach (table, l, 1, 5, 1);
2406             }
2408             {
2409                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each row"), "opacity_alternatej");
2410                 clonetiler_table_attach (table, l, 0, 5, 2);
2411             }
2413             {
2414                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each column"), "opacity_alternatei");
2415                 clonetiler_table_attach (table, l, 0, 5, 3);
2416             }
2417         }
2420 // Color
2421         {
2422             GtkWidget *vb = clonetiler_new_tab (nb, _("Co_lor"));
2424             {
2425             GtkWidget *hb = gtk_hbox_new (FALSE, 0);
2427             GtkWidget *l = gtk_label_new (_("Initial color: "));
2428             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2430             guint32 rgba = 0x000000ff | sp_svg_read_color (prefs->getString(prefs_path + "initial_color").data(), 0x000000ff);
2431             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);
2432             _color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed));
2434             gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast<GtkWidget*>(color_picker->gobj()), FALSE, FALSE, 0);
2436             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2437             }
2440             GtkWidget *table = clonetiler_table_x_y_rand (3);
2441             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2443             // Hue
2444             {
2445                 GtkWidget *l = gtk_label_new ("");
2446                 gtk_label_set_markup (GTK_LABEL(l), _("<b>H:</b>"));
2447                 gtk_size_group_add_widget(table_row_labels, l);
2448                 clonetiler_table_attach (table, l, 1, 2, 1);
2449             }
2451             {
2452                 GtkWidget *l = clonetiler_spinbox (tt,
2453                                                    _("Change the tile hue by this percentage for each row"), "hue_per_j",
2454                                                    -100, 100, "%");
2455                 clonetiler_table_attach (table, l, 0, 2, 2);
2456             }
2458             {
2459                 GtkWidget *l = clonetiler_spinbox (tt,
2460                                                    _("Change the tile hue by this percentage for each column"), "hue_per_i",
2461                                                    -100, 100, "%");
2462                 clonetiler_table_attach (table, l, 0, 2, 3);
2463             }
2465             {
2466                 GtkWidget *l = clonetiler_spinbox (tt,
2467                                                    _("Randomize the tile hue by this percentage"), "hue_rand",
2468                                                    0, 100, "%");
2469                 clonetiler_table_attach (table, l, 0, 2, 4);
2470             }
2473             // Saturation
2474             {
2475                 GtkWidget *l = gtk_label_new ("");
2476                 gtk_label_set_markup (GTK_LABEL(l), _("<b>S:</b>"));
2477                 gtk_size_group_add_widget(table_row_labels, l);
2478                 clonetiler_table_attach (table, l, 1, 3, 1);
2479             }
2481             {
2482                 GtkWidget *l = clonetiler_spinbox (tt,
2483                                                    _("Change the color saturation by this percentage for each row"), "saturation_per_j",
2484                                                    -100, 100, "%");
2485                 clonetiler_table_attach (table, l, 0, 3, 2);
2486             }
2488             {
2489                 GtkWidget *l = clonetiler_spinbox (tt,
2490                                                    _("Change the color saturation by this percentage for each column"), "saturation_per_i",
2491                                                    -100, 100, "%");
2492                 clonetiler_table_attach (table, l, 0, 3, 3);
2493             }
2495             {
2496                 GtkWidget *l = clonetiler_spinbox (tt,
2497                                                    _("Randomize the color saturation by this percentage"), "saturation_rand",
2498                                                    0, 100, "%");
2499                 clonetiler_table_attach (table, l, 0, 3, 4);
2500             }
2502             // Lightness
2503             {
2504                 GtkWidget *l = gtk_label_new ("");
2505                 gtk_label_set_markup (GTK_LABEL(l), _("<b>L:</b>"));
2506                 gtk_size_group_add_widget(table_row_labels, l);
2507                 clonetiler_table_attach (table, l, 1, 4, 1);
2508             }
2510             {
2511                 GtkWidget *l = clonetiler_spinbox (tt,
2512                                                    _("Change the color lightness by this percentage for each row"), "lightness_per_j",
2513                                                    -100, 100, "%");
2514                 clonetiler_table_attach (table, l, 0, 4, 2);
2515             }
2517             {
2518                 GtkWidget *l = clonetiler_spinbox (tt,
2519                                                    _("Change the color lightness by this percentage for each column"), "lightness_per_i",
2520                                                    -100, 100, "%");
2521                 clonetiler_table_attach (table, l, 0, 4, 3);
2522             }
2524             {
2525                 GtkWidget *l = clonetiler_spinbox (tt,
2526                                                    _("Randomize the color lightness by this percentage"), "lightness_rand",
2527                                                    0, 100, "%");
2528                 clonetiler_table_attach (table, l, 0, 4, 4);
2529             }
2532             { // alternates
2533                 GtkWidget *l = gtk_label_new ("");
2534                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2535                 gtk_size_group_add_widget(table_row_labels, l);
2536                 clonetiler_table_attach (table, l, 1, 5, 1);
2537             }
2539             {
2540                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each row"), "color_alternatej");
2541                 clonetiler_table_attach (table, l, 0, 5, 2);
2542             }
2544             {
2545                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each column"), "color_alternatei");
2546                 clonetiler_table_attach (table, l, 0, 5, 3);
2547             }
2549         }
2551 // Trace
2552         {
2553             GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace"));
2556         {
2557             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2558             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2560             GtkWidget *b  = gtk_check_button_new_with_label (_("Trace the drawing under the tiles"));
2561             g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
2562             bool old = prefs->getBool(prefs_path + "dotrace");
2563             gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2564             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);
2565             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2567             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2568                                GTK_SIGNAL_FUNC(clonetiler_do_pick_toggled), dlg);
2569         }
2571         {
2572             GtkWidget *vvb = gtk_vbox_new (FALSE, 0);
2573             gtk_box_pack_start (GTK_BOX (vb), vvb, FALSE, FALSE, 0);
2574             g_object_set_data (G_OBJECT(dlg), "dotrace", (gpointer) vvb);
2577             {
2578                 GtkWidget *frame = gtk_frame_new (_("1. Pick from the drawing:"));
2579                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2581                 GtkWidget *table = gtk_table_new (3, 3, FALSE);
2582                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2583                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2584                 gtk_container_add(GTK_CONTAINER(frame), table);
2587                 GtkWidget* radio;
2588                 {
2589                     radio = gtk_radio_button_new_with_label (NULL, _("Color"));
2590                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the visible color and opacity"), NULL);
2591                     clonetiler_table_attach (table, radio, 0.0, 1, 1);
2592                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2593                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_COLOR));
2594                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_COLOR);
2595                 }
2596                 {
2597                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Opacity"));
2598                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the total accumulated opacity"), NULL);
2599                     clonetiler_table_attach (table, radio, 0.0, 2, 1);
2600                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2601                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_OPACITY));
2602                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_OPACITY);
2603                 }
2604                 {
2605                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("R"));
2606                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Red component of the color"), NULL);
2607                     clonetiler_table_attach (table, radio, 0.0, 1, 2);
2608                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2609                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_R));
2610                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_R);
2611                 }
2612                 {
2613                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("G"));
2614                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Green component of the color"), NULL);
2615                     clonetiler_table_attach (table, radio, 0.0, 2, 2);
2616                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2617                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_G));
2618                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_G);
2619                 }
2620                 {
2621                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("B"));
2622                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Blue component of the color"), NULL);
2623                     clonetiler_table_attach (table, radio, 0.0, 3, 2);
2624                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2625                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_B));
2626                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_B);
2627                 }
2628                 {
2629                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), C_("Clonetiler color hue", "H"));
2630                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the hue of the color"), NULL);
2631                     clonetiler_table_attach (table, radio, 0.0, 1, 3);
2632                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2633                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_H));
2634                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_H);
2635                 }
2636                 {
2637                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), C_("Clonetiler color saturation", "S"));
2638                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the saturation of the color"), NULL);
2639                     clonetiler_table_attach (table, radio, 0.0, 2, 3);
2640                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2641                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_S));
2642                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_S);
2643                 }
2644                 {
2645                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), C_("Clonetiler color lightness", "L"));
2646                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the lightness of the color"), NULL);
2647                     clonetiler_table_attach (table, radio, 0.0, 3, 3);
2648                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2649                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_L));
2650                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_L);
2651                 }
2653             }
2655             {
2656                 GtkWidget *frame = gtk_frame_new (_("2. Tweak the picked value:"));
2657                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, VB_MARGIN);
2659                 GtkWidget *table = gtk_table_new (4, 2, FALSE);
2660                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2661                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2662                 gtk_container_add(GTK_CONTAINER(frame), table);
2664                 {
2665                     GtkWidget *l = gtk_label_new ("");
2666                     gtk_label_set_markup (GTK_LABEL(l), _("Gamma-correct:"));
2667                     clonetiler_table_attach (table, l, 1.0, 1, 1);
2668                 }
2669                 {
2670                     GtkWidget *l = clonetiler_spinbox (tt,
2671                                                        _("Shift the mid-range of the picked value upwards (>0) or downwards (<0)"), "gamma_picked",
2672                                                        -10, 10, "");
2673                     clonetiler_table_attach (table, l, 0.0, 1, 2);
2674                 }
2676                 {
2677                     GtkWidget *l = gtk_label_new ("");
2678                     gtk_label_set_markup (GTK_LABEL(l), _("Randomize:"));
2679                     clonetiler_table_attach (table, l, 1.0, 1, 3);
2680                 }
2681                 {
2682                     GtkWidget *l = clonetiler_spinbox (tt,
2683                                                        _("Randomize the picked value by this percentage"), "rand_picked",
2684                                                        0, 100, "%");
2685                     clonetiler_table_attach (table, l, 0.0, 1, 4);
2686                 }
2688                 {
2689                     GtkWidget *l = gtk_label_new ("");
2690                     gtk_label_set_markup (GTK_LABEL(l), _("Invert:"));
2691                     clonetiler_table_attach (table, l, 1.0, 2, 1);
2692                 }
2693                 {
2694                     GtkWidget *l = clonetiler_checkbox (tt, _("Invert the picked value"), "invert_picked");
2695                     clonetiler_table_attach (table, l, 0.0, 2, 2);
2696                 }
2697             }
2699             {
2700                 GtkWidget *frame = gtk_frame_new (_("3. Apply the value to the clones':"));
2701                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2704                 GtkWidget *table = gtk_table_new (2, 2, FALSE);
2705                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2706                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2707                 gtk_container_add(GTK_CONTAINER(frame), table);
2709                 {
2710                     GtkWidget *b  = gtk_check_button_new_with_label (_("Presence"));
2711                     bool old = prefs->getBool(prefs_path + "pick_to_presence", true);
2712                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2713                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone is created with the probability determined by the picked value in that point"), NULL);
2714                     clonetiler_table_attach (table, b, 0.0, 1, 1);
2715                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2716                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_presence");
2717                 }
2719                 {
2720                     GtkWidget *b  = gtk_check_button_new_with_label (_("Size"));
2721                     bool old = prefs->getBool(prefs_path + "pick_to_size");
2722                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2723                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's size is determined by the picked value in that point"), NULL);
2724                     clonetiler_table_attach (table, b, 0.0, 2, 1);
2725                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2726                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_size");
2727                 }
2729                 {
2730                     GtkWidget *b  = gtk_check_button_new_with_label (_("Color"));
2731                     bool old = prefs->getBool(prefs_path + "pick_to_color", 0);
2732                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2733                     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);
2734                     clonetiler_table_attach (table, b, 0.0, 1, 2);
2735                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2736                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_color");
2737                 }
2739                 {
2740                     GtkWidget *b  = gtk_check_button_new_with_label (_("Opacity"));
2741                     bool old = prefs->getBool(prefs_path + "pick_to_opacity", 0);
2742                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2743                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's opacity is determined by the picked value in that point"), NULL);
2744                     clonetiler_table_attach (table, b, 0.0, 2, 2);
2745                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2746                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_opacity");
2747                 }
2748             }
2749            gtk_widget_set_sensitive (vvb, prefs->getBool(prefs_path + "dotrace"));
2750         }
2751         }
2753 // Rows/columns, width/height
2754         {
2755             GtkWidget *table = gtk_table_new (2, 2, FALSE);
2756             gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
2757             gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2758             gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2759             gtk_box_pack_start (GTK_BOX (mainbox), table, FALSE, FALSE, 0);
2761             {
2762                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2763                 g_object_set_data (G_OBJECT(dlg), "rowscols", (gpointer) hb);
2765                 {
2766                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2767                     int value = prefs->getInt(prefs_path + "jmax", 2);
2768                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2769                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2770                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many rows in the tiling"), NULL);
2771                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2772                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2774                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2775                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "jmax");
2776                 }
2778                 {
2779                     GtkWidget *l = gtk_label_new ("");
2780                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2781                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2782                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2783                 }
2785                 {
2786                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2787                     int value = prefs->getInt(prefs_path + "imax", 2);
2788                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2789                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2790                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many columns in the tiling"), NULL);
2791                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2792                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2794                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2795                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "imax");
2796                 }
2798                 clonetiler_table_attach (table, hb, 0.0, 1, 2);
2799             }
2801             {
2802                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2803                 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
2805                 // unitmenu
2806                 GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
2807                 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
2809                 {
2810                     // Width spinbutton
2811                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2812                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2814                     double value = prefs->getDouble(prefs_path + "fillwidth", 50.0);
2815                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2816                     gdouble const units = sp_pixels_get_units (value, unit);
2817                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2819                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2820                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Width of the rectangle to be filled"), NULL);
2821                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2822                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2823                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2824                                        GTK_SIGNAL_FUNC(clonetiler_fill_width_changed), u);
2825                 }
2826                 {
2827                     GtkWidget *l = gtk_label_new ("");
2828                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2829                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2830                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2831                 }
2833                 {
2834                     // Height spinbutton
2835                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2836                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2838                     double value = prefs->getDouble(prefs_path + "fillheight", 50.0);
2839                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2840                     gdouble const units = sp_pixels_get_units (value, unit);
2841                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2844                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2845                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Height of the rectangle to be filled"), NULL);
2846                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2847                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2848                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2849                                        GTK_SIGNAL_FUNC(clonetiler_fill_height_changed), u);
2850                 }
2852                 gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);
2853                 clonetiler_table_attach (table, hb, 0.0, 2, 2);
2855             }
2857             // Switch
2858             GtkWidget* radio;
2859             {
2860                 radio = gtk_radio_button_new_with_label (NULL, _("Rows, columns: "));
2861                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Create the specified number of rows and columns"), NULL);
2862                 clonetiler_table_attach (table, radio, 0.0, 1, 1);
2863                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_create), (gpointer) dlg);
2864             }
2865             if (!prefs->getBool(prefs_path + "fillrect")) {
2866                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2867                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2868             }
2869             {
2870                 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Width, height: "));
2871                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Fill the specified width and height with the tiling"), NULL);
2872                 clonetiler_table_attach (table, radio, 0.0, 2, 1);
2873                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_fill), (gpointer) dlg);
2874             }
2875             if (prefs->getBool(prefs_path + "fillrect")) {
2876                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2877                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2878             }
2879         }
2882 // Use saved pos
2883         {
2884             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2885             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2887             GtkWidget *b  = gtk_check_button_new_with_label (_("Use saved size and position of the tile"));
2888             bool keepbbox = prefs->getBool(prefs_path + "keepbbox", true);
2889             gtk_toggle_button_set_active ((GtkToggleButton *) b, keepbbox);
2890             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);
2891             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2893             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2894                                GTK_SIGNAL_FUNC(clonetiler_keep_bbox_toggled), NULL);
2895         }
2897 // Statusbar
2898         {
2899             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2900             gtk_box_pack_end (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2901             GtkWidget *l = gtk_label_new("");
2902             g_object_set_data (G_OBJECT(dlg), "status", (gpointer) l);
2903             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2904         }
2906 // Buttons
2907         {
2908             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2909             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2911             {
2912                 GtkWidget *b = gtk_button_new ();
2913                 GtkWidget *l = gtk_label_new ("");
2914                 gtk_label_set_markup_with_mnemonic (GTK_LABEL(l), _(" <b>_Create</b> "));
2915                 gtk_container_add (GTK_CONTAINER(b), l);
2916                 gtk_tooltips_set_tip (tt, b, _("Create and tile the clones of the selection"), NULL);
2917                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_apply), NULL);
2918                 gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0);
2919             }
2921             { // buttons which are enabled only when there are tiled clones
2922                 GtkWidget *sb = gtk_hbox_new(FALSE, 0);
2923                 gtk_box_pack_end (GTK_BOX (hb), sb, FALSE, FALSE, 0);
2924                 g_object_set_data (G_OBJECT(dlg), "buttons_on_tiles", (gpointer) sb);
2925                 {
2926                     // TRANSLATORS: if a group of objects are "clumped" together, then they
2927                     //  are unevenly spread in the given amount of space - as shown in the
2928                     //  diagrams on the left in the following screenshot:
2929                     //  http://www.inkscape.org/screenshots/gallery/inkscape-0.42-CVS-tiles-unclump.png
2930                     //  So unclumping is the process of spreading a number of objects out more evenly.
2931                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" _Unclump "));
2932                     gtk_tooltips_set_tip (tt, b, _("Spread out clones to reduce clumping; can be applied repeatedly"), NULL);
2933                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_unclump), NULL);
2934                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2935                 }
2937                 {
2938                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" Re_move "));
2939                     gtk_tooltips_set_tip (tt, b, _("Remove existing tiled clones of the selected object (siblings only)"), NULL);
2940                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_remove), NULL);
2941                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2942                 }
2944                 // connect to global selection changed signal (so we can change desktops) and
2945                 // external_change (so we're not fooled by undo)
2946                 g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (clonetiler_change_selection), dlg);
2947                 g_signal_connect (G_OBJECT (INKSCAPE), "external_change", G_CALLBACK (clonetiler_external_change), dlg);
2948                 g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), G_OBJECT (INKSCAPE));
2950                 // update now
2951                 clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
2952             }
2954             {
2955                 GtkWidget *b = gtk_button_new_with_mnemonic (_(" R_eset "));
2956                 // TRANSLATORS: "change" is a noun here
2957                 gtk_tooltips_set_tip (tt, b, _("Reset all shifts, scales, rotates, opacity and color changes in the dialog to zero"), NULL);
2958                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_reset), NULL);
2959                 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2960             }
2961         }
2963         gtk_widget_show_all (mainbox);
2965     } // end of if (!dlg)
2967     gtk_window_present ((GtkWindow *) dlg);
2971 /*
2972   Local Variables:
2973   mode:c++
2974   c-file-style:"stroustrup"
2975   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2976   indent-tabs-mode:nil
2977   fill-column:99
2978   End:
2979 */
2980 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :