Code

Merge and cleanup of GSoC C++-ification project.
[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  *   Jon A. Cruz <jon@joncruz.org>
8  *   Abhishek Sharma
9  *
10  * Copyright (C) 2004-2006 Authors
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
17 #include <glib/gmem.h>
18 #include <gtk/gtk.h>
19 #include <glibmm/i18n.h>
21 #include "../desktop.h"
22 #include "../desktop-handles.h"
23 #include "dialog-events.h"
24 #include "display/nr-arena.h"
25 #include "display/nr-arena-item.h"
26 #include "../document.h"
27 #include "../filter-chemistry.h"
28 #include "helper/unit-menu.h"
29 #include "helper/units.h"
30 #include "helper/window.h"
31 #include "../inkscape.h"
32 #include "../interface.h"
33 #include "../macros.h"
34 #include "../message-stack.h"
35 #include "preferences.h"
36 #include "../selection.h"
37 #include "../sp-filter.h"
38 #include "../sp-namedview.h"
39 #include "../sp-use.h"
40 #include "../style.h"
41 #include "svg/svg-color.h"
42 #include "svg/svg.h"
43 #include "ui/icon-names.h"
44 #include "ui/widget/color-picker.h"
45 #include "unclump.h"
46 #include "../verbs.h"
47 #include "widgets/icon.h"
48 #include "xml/repr.h"
50 using Inkscape::DocumentUndo;
52 #define MIN_ONSCREEN_DISTANCE 50
54 static GtkWidget *dlg = NULL;
55 static win_data wd;
57 // impossible original values to make sure they are read from prefs
58 static gint x = -1000, y = -1000, w = 0, h = 0;
59 static Glib::ustring const prefs_path = "/dialogs/clonetiler/";
61 #define SB_MARGIN 1
62 #define VB_MARGIN 4
64 enum {
65     PICK_COLOR,
66     PICK_OPACITY,
67     PICK_R,
68     PICK_G,
69     PICK_B,
70     PICK_H,
71     PICK_S,
72     PICK_L
73 };
75 static GtkSizeGroup* table_row_labels = NULL;
77 static sigc::connection _shutdown_connection;
78 static sigc::connection _dialogs_hidden_connection;
79 static sigc::connection _dialogs_unhidden_connection;
80 static sigc::connection _desktop_activated_connection;
81 static sigc::connection _color_changed_connection;
83 static Inkscape::UI::Widget::ColorPicker *color_picker;
85 static void
86 clonetiler_dialog_destroy( GtkObject */*object*/, gpointer /*data*/ )
87 {
88     sp_signal_disconnect_by_data (INKSCAPE, dlg);
89     _color_changed_connection.disconnect();
91     delete color_picker;
93     wd.win = dlg = NULL;
94     wd.stop = 0;
96 }
98 static gboolean
99 clonetiler_dialog_delete (GtkObject */*object*/, GdkEvent * /*event*/, gpointer /*data*/)
101     gtk_window_get_position ((GtkWindow *) dlg, &x, &y);
102     gtk_window_get_size ((GtkWindow *) dlg, &w, &h);
104     if (x<0) x=0;
105     if (y<0) y=0;
107     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
108     prefs->setInt(prefs_path + "x", x);
109     prefs->setInt(prefs_path + "y", y);
110     prefs->setInt(prefs_path + "w", w);
111     prefs->setInt(prefs_path + "h", h);
113     return FALSE; // which means, go ahead and destroy it
117 static void
118 on_picker_color_changed (guint rgba)
120     static bool is_updating = false;
121     if (is_updating || !SP_ACTIVE_DESKTOP)
122         return;
124     is_updating = true;
126     gchar c[32];
127     sp_svg_write_color(c, sizeof(c), rgba);
128     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
129     prefs->setString(prefs_path + "initial_color", c);
131     is_updating = false;
134 static guint clonetiler_number_of_clones (SPObject *obj);
136 static void
137 clonetiler_change_selection (Inkscape::Application * /*inkscape*/, Inkscape::Selection *selection, GtkWidget *dlg)
139     GtkWidget *buttons = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "buttons_on_tiles");
140     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
142     if (selection->isEmpty()) {
143         gtk_widget_set_sensitive (buttons, FALSE);
144         gtk_label_set_markup (GTK_LABEL(status), _("<small>Nothing selected.</small>"));
145         return;
146     }
148     if (g_slist_length ((GSList *) selection->itemList()) > 1) {
149         gtk_widget_set_sensitive (buttons, FALSE);
150         gtk_label_set_markup (GTK_LABEL(status), _("<small>More than one object selected.</small>"));
151         return;
152     }
154     guint n = clonetiler_number_of_clones(selection->singleItem());
155     if (n > 0) {
156         gtk_widget_set_sensitive (buttons, TRUE);
157         gchar *sta = g_strdup_printf (_("<small>Object has <b>%d</b> tiled clones.</small>"), n);
158         gtk_label_set_markup (GTK_LABEL(status), sta);
159         g_free (sta);
160     } else {
161         gtk_widget_set_sensitive (buttons, FALSE);
162         gtk_label_set_markup (GTK_LABEL(status), _("<small>Object has no tiled clones.</small>"));
163     }
166 static void
167 clonetiler_external_change (Inkscape::Application * /*inkscape*/, GtkWidget *dlg)
169     clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
172 static void clonetiler_disconnect_gsignal (GObject *widget, gpointer source) {
173     if (source && G_IS_OBJECT(source))
174         sp_signal_disconnect_by_data (source, widget);
178 enum {
179     TILE_P1,
180     TILE_P2,
181     TILE_PM,
182     TILE_PG,
183     TILE_CM,
184     TILE_PMM,
185     TILE_PMG,
186     TILE_PGG,
187     TILE_CMM,
188     TILE_P4,
189     TILE_P4M,
190     TILE_P4G,
191     TILE_P3,
192     TILE_P31M,
193     TILE_P3M1,
194     TILE_P6,
195     TILE_P6M
196 };
199 static Geom::Matrix
200 clonetiler_get_transform (
202     // symmetry group
203     int type,
205     // row, column
206     int i, int j,
208     // center, width, height of the tile
209     double cx, double cy,
210     double w,  double h,
212     // values from the dialog:
213     // Shift
214     double shiftx_per_i,      double shifty_per_i,
215     double shiftx_per_j,      double shifty_per_j,
216     double shiftx_rand,       double shifty_rand,
217     double shiftx_exp,        double shifty_exp,
218     int    shiftx_alternate,  int    shifty_alternate,
219     int    shiftx_cumulate,   int    shifty_cumulate,
220     int    shiftx_excludew,   int    shifty_excludeh,
222     // Scale
223     double scalex_per_i,      double scaley_per_i,
224     double scalex_per_j,      double scaley_per_j,
225     double scalex_rand,       double scaley_rand,
226     double scalex_exp,        double scaley_exp,
227     double scalex_log,        double scaley_log,
228     int    scalex_alternate,  int    scaley_alternate,
229     int    scalex_cumulate,   int    scaley_cumulate,
231     // Rotation
232     double rotate_per_i,      double rotate_per_j,
233     double rotate_rand,
234     int    rotate_alternatei, int    rotate_alternatej,
235     int    rotate_cumulatei,  int    rotate_cumulatej
236     )
239     // Shift (in units of tile width or height) -------------
240     double delta_shifti = 0.0;
241     double delta_shiftj = 0.0;
243     if( shiftx_alternate ) {
244         delta_shifti = (double)(i%2);
245     } else {
246         if( shiftx_cumulate ) {  // Should the delta shifts be cumulative (i.e. 1, 1+2, 1+2+3, ...)
247             delta_shifti = (double)(i*i);
248         } else {
249             delta_shifti = (double)i;
250         }
251     }
253     if( shifty_alternate ) {
254         delta_shiftj = (double)(j%2);
255     } else {
256         if( shifty_cumulate ) {
257             delta_shiftj = (double)(j*j);
258         } else {
259             delta_shiftj = (double)j;
260         }
261     }
263     // Random shift, only calculate if non-zero.
264     double delta_shiftx_rand = 0.0;
265     double delta_shifty_rand = 0.0;
266     if( shiftx_rand != 0.0 ) delta_shiftx_rand = shiftx_rand * g_random_double_range (-1, 1);
267     if( shifty_rand != 0.0 ) delta_shifty_rand = shifty_rand * g_random_double_range (-1, 1);
270     // Delta shift (units of tile width/height)
271     double di = shiftx_per_i * delta_shifti  + shiftx_per_j * delta_shiftj + delta_shiftx_rand;
272     double dj = shifty_per_i * delta_shifti  + shifty_per_j * delta_shiftj + delta_shifty_rand;
274     // Shift in actual x and y, used below
275     double dx = w * di;
276     double dy = h * dj;
278     double shifti = di;
279     double shiftj = dj;
281     // Include tile width and height in shift if required
282     if( !shiftx_excludew ) shifti += i;
283     if( !shifty_excludeh ) shiftj += j;
285     // Add exponential shift if necessary
286     if ( shiftx_exp != 1.0 ) shifti = pow( shifti, shiftx_exp );
287     if ( shifty_exp != 1.0 ) shiftj = pow( shiftj, shifty_exp );
289     // Final shift
290     Geom::Matrix rect_translate (Geom::Translate (w * shifti, h * shiftj));
292     // Rotation (in degrees) ------------
293     double delta_rotationi = 0.0;
294     double delta_rotationj = 0.0;
296     if( rotate_alternatei ) {
297         delta_rotationi = (double)(i%2);
298     } else {
299         if( rotate_cumulatei ) {
300             delta_rotationi = (double)(i*i + i)/2.0;
301         } else {
302             delta_rotationi = (double)i;
303         }
304     }
306     if( rotate_alternatej ) {
307         delta_rotationj = (double)(j%2);
308     } else {
309         if( rotate_cumulatej ) {
310             delta_rotationj = (double)(j*j + j)/2.0;
311         } else {
312             delta_rotationj = (double)j;
313         }
314     }
316     double delta_rotate_rand = 0.0;
317     if( rotate_rand != 0.0 ) delta_rotate_rand = rotate_rand * 180.0 * g_random_double_range (-1, 1);
319     double dr = rotate_per_i * delta_rotationi + rotate_per_j * delta_rotationj + delta_rotate_rand;
321     // Scale (times the original) -----------
322     double delta_scalei = 0.0;
323     double delta_scalej = 0.0;
325     if( scalex_alternate ) {
326         delta_scalei = (double)(i%2);
327     } else {
328         if( scalex_cumulate ) {  // Should the delta scales be cumulative (i.e. 1, 1+2, 1+2+3, ...)
329             delta_scalei = (double)(i*i + i)/2.0;
330         } else {
331             delta_scalei = (double)i;
332         }
333     }
335     if( scaley_alternate ) {
336         delta_scalej = (double)(j%2);
337     } else {
338         if( scaley_cumulate ) {
339             delta_scalej = (double)(j*j + j)/2.0;
340         } else {
341             delta_scalej = (double)j;
342         }
343     }
345     // Random scale, only calculate if non-zero.
346     double delta_scalex_rand = 0.0;
347     double delta_scaley_rand = 0.0;
348     if( scalex_rand != 0.0 ) delta_scalex_rand = scalex_rand * g_random_double_range (-1, 1);
349     if( scaley_rand != 0.0 ) delta_scaley_rand = scaley_rand * g_random_double_range (-1, 1);
350     // But if random factors are same, scale x and y proportionally
351     if( scalex_rand == scaley_rand ) delta_scalex_rand = delta_scaley_rand;
353     // Total delta scale
354     double scalex = 1.0 + scalex_per_i * delta_scalei  + scalex_per_j * delta_scalej + delta_scalex_rand;
355     double scaley = 1.0 + scaley_per_i * delta_scalei  + scaley_per_j * delta_scalej + delta_scaley_rand;
357     if( scalex < 0.0 ) scalex = 0.0;
358     if( scaley < 0.0 ) scaley = 0.0;
360     // Add exponential scale if necessary
361     if ( scalex_exp != 1.0 ) scalex = pow( scalex, scalex_exp );
362     if ( scaley_exp != 1.0 ) scaley = pow( scaley, scaley_exp );
364     // Add logarithmic factor if necessary
365     if ( scalex_log  > 0.0 ) scalex = pow( scalex_log, scalex - 1.0 );
366     if ( scaley_log  > 0.0 ) scaley = pow( scaley_log, scaley - 1.0 );
367     // Alternative using rotation angle
368     //if ( scalex_log  != 1.0 ) scalex *= pow( scalex_log, M_PI*dr/180 );
369     //if ( scaley_log  != 1.0 ) scaley *= pow( scaley_log, M_PI*dr/180 );
372     // Calculate transformation matrices, translating back to "center of tile" (rotation center) before transforming
373     Geom::Matrix drot_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (M_PI*dr/180)    * Geom::Translate(cx, cy);
375     Geom::Matrix dscale_c = Geom::Translate(-cx, -cy) * Geom::Scale (scalex, scaley)  * Geom::Translate(cx, cy);
377     Geom::Matrix d_s_r = dscale_c * drot_c;
379     Geom::Matrix rotate_180_c  = Geom::Translate(-cx, -cy) * Geom::Rotate (M_PI)      * Geom::Translate(cx, cy);
381     Geom::Matrix rotate_90_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (-M_PI/2)   * Geom::Translate(cx, cy);
382     Geom::Matrix rotate_m90_c  = Geom::Translate(-cx, -cy) * Geom::Rotate ( M_PI/2)   * Geom::Translate(cx, cy);
384     Geom::Matrix rotate_120_c  = Geom::Translate(-cx, -cy) * Geom::Rotate (-2*M_PI/3) * Geom::Translate(cx, cy);
385     Geom::Matrix rotate_m120_c = Geom::Translate(-cx, -cy) * Geom::Rotate ( 2*M_PI/3) * Geom::Translate(cx, cy);
387     Geom::Matrix rotate_60_c   = Geom::Translate(-cx, -cy) * Geom::Rotate (-M_PI/3)   * Geom::Translate(cx, cy);
388     Geom::Matrix rotate_m60_c  = Geom::Translate(-cx, -cy) * Geom::Rotate ( M_PI/3)   * Geom::Translate(cx, cy);
390     Geom::Matrix flip_x        = Geom::Translate(-cx, -cy) * Geom::Scale (-1, 1)      * Geom::Translate(cx, cy);
391     Geom::Matrix flip_y        = Geom::Translate(-cx, -cy) * Geom::Scale (1, -1)      * Geom::Translate(cx, cy);
394     // Create tile with required symmetry
395     const double cos60 = cos(M_PI/3);
396     const double sin60 = sin(M_PI/3);
397     const double cos30 = cos(M_PI/6);
398     const double sin30 = sin(M_PI/6);
400     switch (type) {
402     case TILE_P1:
403         return d_s_r * rect_translate;
404         break;
406     case TILE_P2:
407         if (i % 2 == 0) {
408             return d_s_r * rect_translate;
409         } else {
410             return d_s_r * rotate_180_c * rect_translate;
411         }
412         break;
414     case TILE_PM:
415         if (i % 2 == 0) {
416             return d_s_r * rect_translate;
417         } else {
418             return d_s_r * flip_x * rect_translate;
419         }
420         break;
422     case TILE_PG:
423         if (j % 2 == 0) {
424             return d_s_r * rect_translate;
425         } else {
426             return d_s_r * flip_x * rect_translate;
427         }
428         break;
430     case TILE_CM:
431         if ((i + j) % 2 == 0) {
432             return d_s_r * rect_translate;
433         } else {
434             return d_s_r * flip_x * rect_translate;
435         }
436         break;
438     case TILE_PMM:
439         if (j % 2 == 0) {
440             if (i % 2 == 0) {
441                 return d_s_r * rect_translate;
442             } else {
443                 return d_s_r * flip_x * rect_translate;
444             }
445         } else {
446             if (i % 2 == 0) {
447                 return d_s_r * flip_y * rect_translate;
448             } else {
449                 return d_s_r * flip_x * flip_y * rect_translate;
450             }
451         }
452         break;
454     case TILE_PMG:
455         if (j % 2 == 0) {
456             if (i % 2 == 0) {
457                 return d_s_r * rect_translate;
458             } else {
459                 return d_s_r * rotate_180_c * rect_translate;
460             }
461         } else {
462             if (i % 2 == 0) {
463                 return d_s_r * flip_y * rect_translate;
464             } else {
465                 return d_s_r * rotate_180_c * flip_y * rect_translate;
466             }
467         }
468         break;
470     case TILE_PGG:
471         if (j % 2 == 0) {
472             if (i % 2 == 0) {
473                 return d_s_r * rect_translate;
474             } else {
475                 return d_s_r * flip_y * rect_translate;
476             }
477         } else {
478             if (i % 2 == 0) {
479                 return d_s_r * rotate_180_c * rect_translate;
480             } else {
481                 return d_s_r * rotate_180_c * flip_y * rect_translate;
482             }
483         }
484         break;
486     case TILE_CMM:
487         if (j % 4 == 0) {
488             if (i % 2 == 0) {
489                 return d_s_r * rect_translate;
490             } else {
491                 return d_s_r * flip_x * rect_translate;
492             }
493         } else if (j % 4 == 1) {
494             if (i % 2 == 0) {
495                 return d_s_r * flip_y * rect_translate;
496             } else {
497                 return d_s_r * flip_x * flip_y * rect_translate;
498             }
499         } else if (j % 4 == 2) {
500             if (i % 2 == 1) {
501                 return d_s_r * rect_translate;
502             } else {
503                 return d_s_r * flip_x * rect_translate;
504             }
505         } else {
506             if (i % 2 == 1) {
507                 return d_s_r * flip_y * rect_translate;
508             } else {
509                 return d_s_r * flip_x * flip_y * rect_translate;
510             }
511         }
512         break;
514     case TILE_P4:
515     {
516         Geom::Matrix ori  (Geom::Translate ((w + h) * pow((i/2), shiftx_exp) + dx,  (h + w) * pow((j/2), shifty_exp) + dy));
517         Geom::Matrix dia1 (Geom::Translate (w/2 + h/2, -h/2 + w/2));
518         Geom::Matrix dia2 (Geom::Translate (-w/2 + h/2, h/2 + w/2));
519         if (j % 2 == 0) {
520             if (i % 2 == 0) {
521                 return d_s_r * ori;
522             } else {
523                 return d_s_r * rotate_m90_c * dia1 * ori;
524             }
525         } else {
526             if (i % 2 == 0) {
527                 return d_s_r * rotate_90_c * dia2 * ori;
528             } else {
529                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
530             }
531         }
532     }
533     break;
535     case TILE_P4M:
536     {
537         double max = MAX(w, h);
538         Geom::Matrix ori (Geom::Translate ((max + max) * pow((i/4), shiftx_exp) + dx,  (max + max) * pow((j/2), shifty_exp) + dy));
539         Geom::Matrix dia1 (Geom::Translate ( w/2 - h/2, h/2 - w/2));
540         Geom::Matrix dia2 (Geom::Translate (-h/2 + w/2, w/2 - h/2));
541         if (j % 2 == 0) {
542             if (i % 4 == 0) {
543                 return d_s_r * ori;
544             } else if (i % 4 == 1) {
545                 return d_s_r * flip_y * rotate_m90_c * dia1 * ori;
546             } else if (i % 4 == 2) {
547                 return d_s_r * rotate_m90_c * dia1 * Geom::Translate (h, 0) * ori;
548             } else if (i % 4 == 3) {
549                 return d_s_r * flip_x * Geom::Translate (w, 0) * ori;
550             }
551         } else {
552             if (i % 4 == 0) {
553                 return d_s_r * flip_y * Geom::Translate(0, h) * ori;
554             } else if (i % 4 == 1) {
555                 return d_s_r * rotate_90_c * dia2 * Geom::Translate(0, h) * ori;
556             } else if (i % 4 == 2) {
557                 return d_s_r * flip_y * rotate_90_c * dia2 * Geom::Translate(h, 0) * Geom::Translate(0, h) * ori;
558             } else if (i % 4 == 3) {
559                 return d_s_r * flip_y * flip_x * Geom::Translate(w, 0) * Geom::Translate(0, h) * ori;
560             }
561         }
562     }
563     break;
565     case TILE_P4G:
566     {
567         double max = MAX(w, h);
568         Geom::Matrix ori (Geom::Translate ((max + max) * pow((i/4), shiftx_exp) + dx,  (max + max) * pow(j, shifty_exp) + dy));
569         Geom::Matrix dia1 (Geom::Translate ( w/2 + h/2, h/2 - w/2));
570         Geom::Matrix dia2 (Geom::Translate (-h/2 + w/2, w/2 + h/2));
571         if (((i/4) + j) % 2 == 0) {
572             if (i % 4 == 0) {
573                 return d_s_r * ori;
574             } else if (i % 4 == 1) {
575                 return d_s_r * rotate_m90_c * dia1 * ori;
576             } else if (i % 4 == 2) {
577                 return d_s_r * rotate_90_c * dia2 * ori;
578             } else if (i % 4 == 3) {
579                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
580             }
581         } else {
582             if (i % 4 == 0) {
583                 return d_s_r * flip_y * Geom::Translate (0, h) * ori;
584             } else if (i % 4 == 1) {
585                 return d_s_r * flip_y * rotate_m90_c * dia1 * Geom::Translate (-h, 0) * ori;
586             } else if (i % 4 == 2) {
587                 return d_s_r * flip_y * rotate_90_c * dia2 * Geom::Translate (h, 0) * ori;
588             } else if (i % 4 == 3) {
589                 return d_s_r * flip_x * Geom::Translate (w, 0) * ori;
590             }
591         }
592     }
593     break;
595     case TILE_P3:
596     {
597         double width;
598         double height;
599         Geom::Matrix dia1;
600         Geom::Matrix dia2;
601         if (w > h) {
602             width  = w + w * cos60;
603             height = 2 * w * sin60;
604             dia1 = Geom::Matrix (Geom::Translate (w/2 + w/2 * cos60, -(w/2 * sin60)));
605             dia2 = dia1 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60)));
606         } else {
607             width = h * cos (M_PI/6);
608             height = h;
609             dia1 = Geom::Matrix (Geom::Translate (h/2 * cos30, -(h/2 * sin30)));
610             dia2 = dia1 * Geom::Matrix (Geom::Translate (0, h/2));
611         }
612         Geom::Matrix ori (Geom::Translate (width * pow((2*(i/3) + j%2), shiftx_exp) + dx,  (height/2) * pow(j, shifty_exp) + dy));
613         if (i % 3 == 0) {
614             return d_s_r * ori;
615         } else if (i % 3 == 1) {
616             return d_s_r * rotate_m120_c * dia1 * ori;
617         } else if (i % 3 == 2) {
618             return d_s_r * rotate_120_c * dia2 * ori;
619         }
620     }
621     break;
623     case TILE_P31M:
624     {
625         Geom::Matrix ori;
626         Geom::Matrix dia1;
627         Geom::Matrix dia2;
628         Geom::Matrix dia3;
629         Geom::Matrix dia4;
630         if (w > h) {
631             ori = Geom::Matrix(Geom::Translate (w * pow((i/6) + 0.5*(j%2), shiftx_exp) + dx,  (w * cos30) * pow(j, shifty_exp) + dy));
632             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) );
633             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
634             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
635             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
636         } else {
637             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));
638             dia1 = Geom::Matrix (Geom::Translate (0, -h/2) * Geom::Translate (h/2 * cos30, h/2 * sin30));
639             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
640             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, h/2));
641             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
642         }
643         if (i % 6 == 0) {
644             return d_s_r * ori;
645         } else if (i % 6 == 1) {
646             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
647         } else if (i % 6 == 2) {
648             return d_s_r * rotate_m120_c * dia2 * ori;
649         } else if (i % 6 == 3) {
650             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
651         } else if (i % 6 == 4) {
652             return d_s_r * rotate_120_c * dia4 * ori;
653         } else if (i % 6 == 5) {
654             return d_s_r * flip_y * Geom::Translate(0, h) * ori;
655         }
656     }
657     break;
659     case TILE_P3M1:
660     {
661         double width;
662         double height;
663         Geom::Matrix dia1;
664         Geom::Matrix dia2;
665         Geom::Matrix dia3;
666         Geom::Matrix dia4;
667         if (w > h) {
668             width = w + w * cos60;
669             height = 2 * w * sin60;
670             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) );
671             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
672             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
673             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
674         } else {
675             width = 2 * h * cos (M_PI/6);
676             height = 2 * h;
677             dia1 = Geom::Matrix (Geom::Translate (0, -h/2) * Geom::Translate (h/2 * cos30, h/2 * sin30));
678             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
679             dia3 = dia2 * Geom::Matrix (Geom::Translate (0, h/2));
680             dia4 = dia3 * Geom::Matrix (Geom::Translate (-h * cos30, h * sin30));
681         }
682         Geom::Matrix ori (Geom::Translate (width * pow((2*(i/6) + j%2), shiftx_exp) + dx,  (height/2) * pow(j, shifty_exp) + dy));
683         if (i % 6 == 0) {
684             return d_s_r * ori;
685         } else if (i % 6 == 1) {
686             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
687         } else if (i % 6 == 2) {
688             return d_s_r * rotate_m120_c * dia2 * ori;
689         } else if (i % 6 == 3) {
690             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
691         } else if (i % 6 == 4) {
692             return d_s_r * rotate_120_c * dia4 * ori;
693         } else if (i % 6 == 5) {
694             return d_s_r * flip_y * Geom::Translate(0, h) * ori;
695         }
696     }
697     break;
699     case TILE_P6:
700     {
701         Geom::Matrix ori;
702         Geom::Matrix dia1;
703         Geom::Matrix dia2;
704         Geom::Matrix dia3;
705         Geom::Matrix dia4;
706         Geom::Matrix dia5;
707         if (w > h) {
708             ori = Geom::Matrix(Geom::Translate (w * pow((2*(i/6) + (j%2)), shiftx_exp) + dx,  (2*w * sin60) * pow(j, shifty_exp) + dy));
709             dia1 = Geom::Matrix (Geom::Translate (w/2 * cos60, -w/2 * sin60));
710             dia2 = dia1 * Geom::Matrix (Geom::Translate (w/2, 0));
711             dia3 = dia2 * Geom::Matrix (Geom::Translate (w/2 * cos60, w/2 * sin60));
712             dia4 = dia3 * Geom::Matrix (Geom::Translate (-w/2 * cos60, w/2 * sin60));
713             dia5 = dia4 * Geom::Matrix (Geom::Translate (-w/2, 0));
714         } else {
715             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));
716             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));
717             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));
718             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));
719             dia4 = dia3 * dia1.inverse();
720             dia5 = dia3 * dia2.inverse();
721         }
722         if (i % 6 == 0) {
723             return d_s_r * ori;
724         } else if (i % 6 == 1) {
725             return d_s_r * rotate_m60_c * dia1 * ori;
726         } else if (i % 6 == 2) {
727             return d_s_r * rotate_m120_c * dia2 * ori;
728         } else if (i % 6 == 3) {
729             return d_s_r * rotate_180_c * dia3 * ori;
730         } else if (i % 6 == 4) {
731             return d_s_r * rotate_120_c * dia4 * ori;
732         } else if (i % 6 == 5) {
733             return d_s_r * rotate_60_c * dia5 * ori;
734         }
735     }
736     break;
738     case TILE_P6M:
739     {
741         Geom::Matrix ori;
742         Geom::Matrix dia1, dia2, dia3, dia4, dia5, dia6, dia7, dia8, dia9, dia10;
743         if (w > h) {
744             ori = Geom::Matrix(Geom::Translate (w * pow((2*(i/12) + (j%2)), shiftx_exp) + dx,  (2*w * sin60) * pow(j, shifty_exp) + dy));
745             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));
746             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, -h * sin30));
747             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));
748             dia4 = dia3 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
749             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));
750             dia6 = dia5 * Geom::Matrix (Geom::Translate (0, h));
751             dia7 = dia6 * dia1.inverse();
752             dia8 = dia6 * dia2.inverse();
753             dia9 = dia6 * dia3.inverse();
754             dia10 = dia6 * dia4.inverse();
755         } else {
756             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));
757             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));
758             dia2 = dia1 * Geom::Matrix (Geom::Translate (h * cos30, -h * sin30));
759             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));
760             dia4 = dia3 * Geom::Matrix (Geom::Translate (h * cos30, h * sin30));
761             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));
762             dia6 = dia5 * Geom::Matrix (Geom::Translate (0, h));
763             dia7 = dia6 * dia1.inverse();
764             dia8 = dia6 * dia2.inverse();
765             dia9 = dia6 * dia3.inverse();
766             dia10 = dia6 * dia4.inverse();
767         }
768         if (i % 12 == 0) {
769             return d_s_r * ori;
770         } else if (i % 12 == 1) {
771             return d_s_r * flip_y * rotate_m60_c * dia1 * ori;
772         } else if (i % 12 == 2) {
773             return d_s_r * rotate_m60_c * dia2 * ori;
774         } else if (i % 12 == 3) {
775             return d_s_r * flip_y * rotate_m120_c * dia3 * ori;
776         } else if (i % 12 == 4) {
777             return d_s_r * rotate_m120_c * dia4 * ori;
778         } else if (i % 12 == 5) {
779             return d_s_r * flip_x * dia5 * ori;
780         } else if (i % 12 == 6) {
781             return d_s_r * flip_x * flip_y * dia6 * ori;
782         } else if (i % 12 == 7) {
783             return d_s_r * flip_y * rotate_120_c * dia7 * ori;
784         } else if (i % 12 == 8) {
785             return d_s_r * rotate_120_c * dia8 * ori;
786         } else if (i % 12 == 9) {
787             return d_s_r * flip_y * rotate_60_c * dia9 * ori;
788         } else if (i % 12 == 10) {
789             return d_s_r * rotate_60_c * dia10 * ori;
790         } else if (i % 12 == 11) {
791             return d_s_r * flip_y * Geom::Translate (0, h) * ori;
792         }
793     }
794     break;
796     default:
797         break;
798     }
800     return Geom::identity();
803 static bool
804 clonetiler_is_a_clone_of (SPObject *tile, SPObject *obj)
806     char *id_href = NULL;
808     if (obj) {
809         Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
810         id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
811     }
813     if (SP_IS_USE(tile) &&
814         SP_OBJECT_REPR(tile)->attribute("xlink:href") &&
815         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("xlink:href"))) &&
816         SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of") &&
817         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of"))))
818     {
819         if (id_href)
820             g_free (id_href);
821         return true;
822     } else {
823         if (id_href)
824             g_free (id_href);
825         return false;
826     }
829 static NRArena const *trace_arena = NULL;
830 static unsigned trace_visionkey;
831 static NRArenaItem *trace_root;
832 static gdouble trace_zoom;
833 static SPDocument *trace_doc;
835 static void
836 clonetiler_trace_hide_tiled_clones_recursively (SPObject *from)
838     if (!trace_arena)
839         return;
841     for (SPObject *o = from->firstChild(); o != NULL; o = o->next) {
842         if (SP_IS_ITEM(o) && clonetiler_is_a_clone_of (o, NULL))
843             SP_ITEM(o)->invoke_hide(trace_visionkey); // FIXME: hide each tiled clone's original too!
844         clonetiler_trace_hide_tiled_clones_recursively (o);
845     }
848 static void
849 clonetiler_trace_setup (SPDocument *doc, gdouble zoom, SPItem *original)
851     trace_arena = NRArena::create();
852     /* Create ArenaItem and set transform */
853     trace_visionkey = SPItem::display_key_new(1);
854     trace_doc = doc;
855     trace_root = SP_ITEM(trace_doc->getRoot())->invoke_show((NRArena *) trace_arena, trace_visionkey, SP_ITEM_SHOW_DISPLAY);
857     // hide the (current) original and any tiled clones, we only want to pick the background
858     original->invoke_hide(trace_visionkey);
859     clonetiler_trace_hide_tiled_clones_recursively(SP_OBJECT(trace_doc->getRoot()));
861     trace_doc->getRoot()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
862     trace_doc->ensureUpToDate();
864     trace_zoom = zoom;
867 static guint32
868 clonetiler_trace_pick (Geom::Rect box)
870     if (!trace_arena)
871         return 0;
873     Geom::Matrix t(Geom::Scale(trace_zoom, trace_zoom));
874     nr_arena_item_set_transform(trace_root, &t);
875     NRGC gc(NULL);
876     gc.transform.setIdentity();
877     nr_arena_item_invoke_update( trace_root, NULL, &gc,
878                                  NR_ARENA_ITEM_STATE_ALL,
879                                  NR_ARENA_ITEM_STATE_NONE );
881     /* Item integer bbox in points */
882     NRRectL ibox;
883     ibox.x0 = (int) floor(trace_zoom * box[Geom::X].min() + 0.5);
884     ibox.y0 = (int) floor(trace_zoom * box[Geom::Y].min() + 0.5);
885     ibox.x1 = (int) floor(trace_zoom * box[Geom::X].max() + 0.5);
886     ibox.y1 = (int) floor(trace_zoom * box[Geom::Y].max() + 0.5);
888     /* Find visible area */
889     int width = ibox.x1 - ibox.x0;
890     int height = ibox.y1 - ibox.y0;
892     /* Set up pixblock */
893     guchar *px = g_new(guchar, 4 * width * height);
895     if (px == NULL) {
896         return 0; // buffer is too big or too small, cannot pick, so return 0
897     }
899     memset(px, 0x00, 4 * width * height);
901     /* Render */
902     NRPixBlock pb;
903     nr_pixblock_setup_extern( &pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
904                               ibox.x0, ibox.y0, ibox.x1, ibox.y1,
905                               px, 4 * width, FALSE, FALSE );
906     nr_arena_item_invoke_render(NULL, trace_root, &ibox, &pb,
907                                  NR_ARENA_ITEM_RENDER_NO_CACHE );
909     double R = 0, G = 0, B = 0, A = 0;
910     double count = 0;
911     double weight = 0;
913     for (int y = ibox.y0; y < ibox.y1; y++) {
914         const unsigned char *s = NR_PIXBLOCK_PX (&pb) + (y - ibox.y0) * pb.rs;
915         for (int x = ibox.x0; x < ibox.x1; x++) {
916             count += 1;
917             weight += s[3] / 255.0;
918             R += s[0] / 255.0;
919             G += s[1] / 255.0;
920             B += s[2] / 255.0;
921             A += s[3] / 255.0;
922             s += 4;
923         }
924     }
926     nr_pixblock_release(&pb);
928     R = R / weight;
929     G = G / weight;
930     B = B / weight;
931     A = A / count;
933     R = CLAMP (R, 0.0, 1.0);
934     G = CLAMP (G, 0.0, 1.0);
935     B = CLAMP (B, 0.0, 1.0);
936     A = CLAMP (A, 0.0, 1.0);
938     return SP_RGBA32_F_COMPOSE (R, G, B, A);
941 static void
942 clonetiler_trace_finish ()
944     if (trace_doc) {
945         SP_ITEM(trace_doc->getRoot())->invoke_hide(trace_visionkey);
946     }
947     if (trace_arena) {
948         ((NRObject *) trace_arena)->unreference();
949         trace_arena = NULL;
950     }
953 static void
954 clonetiler_unclump( GtkWidget */*widget*/, void * )
956     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
957     if (desktop == NULL)
958         return;
960     Inkscape::Selection *selection = sp_desktop_selection(desktop);
962     // check if something is selected
963     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
964         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump."));
965         return;
966     }
968     SPObject *obj = SP_OBJECT(selection->singleItem());
969     SPObject *parent = SP_OBJECT_PARENT (obj);
971     GSList *to_unclump = NULL; // not including the original
973     for (SPObject *child = parent->firstChild(); child != NULL; child = child->next) {
974         if (clonetiler_is_a_clone_of (child, obj)) {
975             to_unclump = g_slist_prepend (to_unclump, child);
976         }
977     }
979     sp_desktop_document(desktop)->ensureUpToDate();
981     unclump (to_unclump);
983     g_slist_free (to_unclump);
985     DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER,
986                        _("Unclump tiled clones"));
989 static guint
990 clonetiler_number_of_clones (SPObject *obj)
992     SPObject *parent = SP_OBJECT_PARENT (obj);
994     guint n = 0;
996     for (SPObject *child = parent->firstChild(); child != NULL; child = child->next) {
997         if (clonetiler_is_a_clone_of (child, obj)) {
998             n ++;
999         }
1000     }
1002     return n;
1005 static void
1006 clonetiler_remove( GtkWidget */*widget*/, void *, bool do_undo = true )
1008     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1009     if (desktop == NULL)
1010         return;
1012     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1014     // check if something is selected
1015     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
1016         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove."));
1017         return;
1018     }
1020     SPObject *obj = SP_OBJECT(selection->singleItem());
1021     SPObject *parent = SP_OBJECT_PARENT (obj);
1023 // remove old tiling
1024     GSList *to_delete = NULL;
1025     for (SPObject *child = parent->firstChild(); child != NULL; child = child->next) {
1026         if (clonetiler_is_a_clone_of (child, obj)) {
1027             to_delete = g_slist_prepend (to_delete, child);
1028         }
1029     }
1030     for (GSList *i = to_delete; i; i = i->next) {
1031         SP_OBJECT(i->data)->deleteObject();
1032     }
1033     g_slist_free (to_delete);
1035     clonetiler_change_selection (NULL, selection, dlg);
1037     if (do_undo) {
1038         DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER,
1039                            _("Delete tiled clones"));
1040     }
1043 static Geom::Rect
1044 transform_rect( Geom::Rect const &r, Geom::Matrix const &m)
1046     using Geom::X;
1047     using Geom::Y;
1048     Geom::Point const p1 = r.corner(1) * m;
1049     Geom::Point const p2 = r.corner(2) * m;
1050     Geom::Point const p3 = r.corner(3) * m;
1051     Geom::Point const p4 = r.corner(4) * m;
1052     return Geom::Rect(
1053         Geom::Point(
1054             std::min(std::min(p1[X], p2[X]), std::min(p3[X], p4[X])),
1055             std::min(std::min(p1[Y], p2[Y]), std::min(p3[Y], p4[Y]))),
1056         Geom::Point(
1057             std::max(std::max(p1[X], p2[X]), std::max(p3[X], p4[X])),
1058             std::max(std::max(p1[Y], p2[Y]), std::max(p3[Y], p4[Y]))));
1061 /**
1062 Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same
1063 probability of being displaced.
1064  */
1065 static double
1066 randomize01 (double val, double rand)
1068     double base = MIN (val - rand, 1 - 2*rand);
1069     if (base < 0) base = 0;
1070     val = base + g_random_double_range (0, MIN (2 * rand, 1 - base));
1071     return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case...
1075 static void
1076 clonetiler_apply( GtkWidget */*widget*/, void * )
1078     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1079     if (desktop == NULL)
1080         return;
1081     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1082     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1084     // check if something is selected
1085     if (selection->isEmpty()) {
1086         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone."));
1087         return;
1088     }
1090     // Check if more than one object is selected.
1091     if (g_slist_length((GSList *) selection->itemList()) > 1) {
1092         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>."));
1093         return;
1094     }
1096     // set "busy" cursor
1097     desktop->setWaitingCursor();
1099     // set statusbar text
1100     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
1101     gtk_label_set_markup (GTK_LABEL(status), _("<small>Creating tiled clones...</small>"));
1102     gtk_widget_queue_draw(GTK_WIDGET(status));
1103     gdk_window_process_all_updates();
1105     SPObject *obj = SP_OBJECT(selection->singleItem());
1106     Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
1107     const char *id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
1108     SPObject *parent = SP_OBJECT_PARENT (obj);
1110     clonetiler_remove (NULL, NULL, false);
1112     double shiftx_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_per_i", 0, -10000, 10000);
1113     double shifty_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_per_i", 0, -10000, 10000);
1114     double shiftx_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_per_j", 0, -10000, 10000);
1115     double shifty_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_per_j", 0, -10000, 10000);
1116     double shiftx_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_rand", 0, 0, 1000);
1117     double shifty_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_rand", 0, 0, 1000);
1118     double shiftx_exp   =        prefs->getDoubleLimited(prefs_path + "shiftx_exp",   1, 0, 10);
1119     double shifty_exp   =        prefs->getDoubleLimited(prefs_path + "shifty_exp", 1, 0, 10);
1120     bool   shiftx_alternate =    prefs->getBool(prefs_path + "shiftx_alternate");
1121     bool   shifty_alternate =    prefs->getBool(prefs_path + "shifty_alternate");
1122     bool   shiftx_cumulate  =    prefs->getBool(prefs_path + "shiftx_cumulate");
1123     bool   shifty_cumulate  =    prefs->getBool(prefs_path + "shifty_cumulate");
1124     bool   shiftx_excludew  =    prefs->getBool(prefs_path + "shiftx_excludew");
1125     bool   shifty_excludeh  =    prefs->getBool(prefs_path + "shifty_excludeh");
1127     double scalex_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_per_i", 0, -100, 1000);
1128     double scaley_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_per_i", 0, -100, 1000);
1129     double scalex_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_per_j", 0, -100, 1000);
1130     double scaley_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_per_j", 0, -100, 1000);
1131     double scalex_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_rand",  0, 0, 1000);
1132     double scaley_rand  = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_rand",  0, 0, 1000);
1133     double scalex_exp   =        prefs->getDoubleLimited(prefs_path + "scalex_exp",   1, 0, 10);
1134     double scaley_exp   =        prefs->getDoubleLimited(prefs_path + "scaley_exp",   1, 0, 10);
1135     double scalex_log       =    prefs->getDoubleLimited(prefs_path + "scalex_log",   0, 0, 10);
1136     double scaley_log       =    prefs->getDoubleLimited(prefs_path + "scaley_log",   0, 0, 10);
1137     bool   scalex_alternate =    prefs->getBool(prefs_path + "scalex_alternate");
1138     bool   scaley_alternate =    prefs->getBool(prefs_path + "scaley_alternate");
1139     bool   scalex_cumulate  =    prefs->getBool(prefs_path + "scalex_cumulate");
1140     bool   scaley_cumulate  =    prefs->getBool(prefs_path + "scaley_cumulate");
1142     double rotate_per_i =        prefs->getDoubleLimited(prefs_path + "rotate_per_i", 0, -180, 180);
1143     double rotate_per_j =        prefs->getDoubleLimited(prefs_path + "rotate_per_j", 0, -180, 180);
1144     double rotate_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "rotate_rand", 0, 0, 100);
1145     bool   rotate_alternatei   = prefs->getBool(prefs_path + "rotate_alternatei");
1146     bool   rotate_alternatej   = prefs->getBool(prefs_path + "rotate_alternatej");
1147     bool   rotate_cumulatei    = prefs->getBool(prefs_path + "rotate_cumulatei");
1148     bool   rotate_cumulatej    = prefs->getBool(prefs_path + "rotate_cumulatej");
1150     double blur_per_i =   0.01 * prefs->getDoubleLimited(prefs_path + "blur_per_i", 0, 0, 100);
1151     double blur_per_j =   0.01 * prefs->getDoubleLimited(prefs_path + "blur_per_j", 0, 0, 100);
1152     bool   blur_alternatei =     prefs->getBool(prefs_path + "blur_alternatei");
1153     bool   blur_alternatej =     prefs->getBool(prefs_path + "blur_alternatej");
1154     double blur_rand =    0.01 * prefs->getDoubleLimited(prefs_path + "blur_rand", 0, 0, 100);
1156     double opacity_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "opacity_per_i", 0, 0, 100);
1157     double opacity_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "opacity_per_j", 0, 0, 100);
1158     bool   opacity_alternatei =   prefs->getBool(prefs_path + "opacity_alternatei");
1159     bool   opacity_alternatej =   prefs->getBool(prefs_path + "opacity_alternatej");
1160     double opacity_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "opacity_rand", 0, 0, 100);
1162     Glib::ustring initial_color =    prefs->getString(prefs_path + "initial_color");
1163     double hue_per_j =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_per_j", 0, -100, 100);
1164     double hue_per_i =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_per_i", 0, -100, 100);
1165     double hue_rand  =        0.01 * prefs->getDoubleLimited(prefs_path + "hue_rand", 0, 0, 100);
1166     double saturation_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "saturation_per_j", 0, -100, 100);
1167     double saturation_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "saturation_per_i", 0, -100, 100);
1168     double saturation_rand =  0.01 * prefs->getDoubleLimited(prefs_path + "saturation_rand", 0, 0, 100);
1169     double lightness_per_j =  0.01 * prefs->getDoubleLimited(prefs_path + "lightness_per_j", 0, -100, 100);
1170     double lightness_per_i =  0.01 * prefs->getDoubleLimited(prefs_path + "lightness_per_i", 0, -100, 100);
1171     double lightness_rand =   0.01 * prefs->getDoubleLimited(prefs_path + "lightness_rand", 0, 0, 100);
1172     bool   color_alternatej = prefs->getBool(prefs_path + "color_alternatej");
1173     bool   color_alternatei = prefs->getBool(prefs_path + "color_alternatei");
1175     int    type = prefs->getInt(prefs_path + "symmetrygroup", 0);
1176     bool   keepbbox = prefs->getBool(prefs_path + "keepbbox", true);
1177     int    imax = prefs->getInt(prefs_path + "imax", 2);
1178     int    jmax = prefs->getInt(prefs_path + "jmax", 2);
1180     bool   fillrect = prefs->getBool(prefs_path + "fillrect");
1181     double fillwidth = prefs->getDoubleLimited(prefs_path + "fillwidth", 50, 0, 1e6);
1182     double fillheight = prefs->getDoubleLimited(prefs_path + "fillheight", 50, 0, 1e6);
1184     bool   dotrace = prefs->getBool(prefs_path + "dotrace");
1185     int    pick = prefs->getInt(prefs_path + "pick");
1186     bool   pick_to_presence = prefs->getBool(prefs_path + "pick_to_presence");
1187     bool   pick_to_size = prefs->getBool(prefs_path + "pick_to_size");
1188     bool   pick_to_color = prefs->getBool(prefs_path + "pick_to_color");
1189     bool   pick_to_opacity = prefs->getBool(prefs_path + "pick_to_opacity");
1190     double rand_picked = 0.01 * prefs->getDoubleLimited(prefs_path + "rand_picked", 0, 0, 100);
1191     bool   invert_picked = prefs->getBool(prefs_path + "invert_picked");
1192     double gamma_picked = prefs->getDoubleLimited(prefs_path + "gamma_picked", 0, -10, 10);
1194     if (dotrace) {
1195         clonetiler_trace_setup (sp_desktop_document(desktop), 1.0, SP_ITEM (obj));
1196     }
1198     Geom::Point center;
1199     double w;
1200     double h;
1201     double x0;
1202     double y0;
1204     if (keepbbox &&
1205         obj_repr->attribute("inkscape:tile-w") &&
1206         obj_repr->attribute("inkscape:tile-h") &&
1207         obj_repr->attribute("inkscape:tile-x0") &&
1208         obj_repr->attribute("inkscape:tile-y0") &&
1209         obj_repr->attribute("inkscape:tile-cx") &&
1210         obj_repr->attribute("inkscape:tile-cy")) {
1212         double cx = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cx", 0);
1213         double cy = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cy", 0);
1214         center = Geom::Point (cx, cy);
1216         w = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-w", 0);
1217         h = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-h", 0);
1218         x0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-x0", 0);
1219         y0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-y0", 0);
1220     } else {
1221         bool prefs_bbox = prefs->getBool("/tools/bounding_box", false);
1222         SPItem::BBoxType bbox_type = ( prefs_bbox ? 
1223             SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX );
1224         Geom::OptRect r = SP_ITEM(obj)->getBounds(SP_ITEM(obj)->i2doc_affine(),
1225                                                         bbox_type);
1226         if (r) {
1227             w = r->dimensions()[Geom::X];
1228             h = r->dimensions()[Geom::Y];
1229             x0 = r->min()[Geom::X];
1230             y0 = r->min()[Geom::Y];
1231             center = desktop->dt2doc(SP_ITEM(obj)->getCenter());
1233             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", center[Geom::X]);
1234             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", center[Geom::Y]);
1235             sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
1236             sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
1237             sp_repr_set_svg_double(obj_repr, "inkscape:tile-x0", x0);
1238             sp_repr_set_svg_double(obj_repr, "inkscape:tile-y0", y0);
1239         } else {
1240             center = Geom::Point(0, 0);
1241             w = h = 0;
1242             x0 = y0 = 0;
1243         }
1244     }
1246     Geom::Point cur(0, 0);
1247     Geom::Rect bbox_original (Geom::Point (x0, y0), Geom::Point (x0 + w, y0 + h));
1248     double perimeter_original = (w + h)/4;
1250     // The integers i and j are reserved for tile column and row.
1251     // The doubles x and y are used for coordinates
1252     for (int i = 0;
1253          fillrect?
1254              (fabs(cur[Geom::X]) < fillwidth && i < 200) // prevent "freezing" with too large fillrect, arbitrarily limit rows
1255              : (i < imax);
1256          i ++) {
1257         for (int j = 0;
1258              fillrect?
1259                  (fabs(cur[Geom::Y]) < fillheight && j < 200) // prevent "freezing" with too large fillrect, arbitrarily limit cols
1260                  : (j < jmax);
1261              j ++) {
1263             // Note: We create a clone at 0,0 too, right over the original, in case our clones are colored
1265             // Get transform from symmetry, shift, scale, rotation
1266             Geom::Matrix t = clonetiler_get_transform (type, i, j, center[Geom::X], center[Geom::Y], w, h,
1267                                                        shiftx_per_i,     shifty_per_i,
1268                                                        shiftx_per_j,     shifty_per_j,
1269                                                        shiftx_rand,      shifty_rand,
1270                                                        shiftx_exp,       shifty_exp,
1271                                                        shiftx_alternate, shifty_alternate,
1272                                                        shiftx_cumulate,  shifty_cumulate,
1273                                                        shiftx_excludew,  shifty_excludeh,
1274                                                        scalex_per_i,     scaley_per_i,
1275                                                        scalex_per_j,     scaley_per_j,
1276                                                        scalex_rand,      scaley_rand,
1277                                                        scalex_exp,       scaley_exp,
1278                                                        scalex_log,       scaley_log,
1279                                                        scalex_alternate, scaley_alternate,
1280                                                        scalex_cumulate,  scaley_cumulate,
1281                                                        rotate_per_i,     rotate_per_j,
1282                                                        rotate_rand,
1283                                                        rotate_alternatei, rotate_alternatej,
1284                                                        rotate_cumulatei,  rotate_cumulatej      );
1286             cur = center * t - center;
1287             if (fillrect) {
1288                 if ((cur[Geom::X] > fillwidth) || (cur[Geom::Y] > fillheight)) { // off limits
1289                     continue;
1290                 }
1291             }
1293             gchar color_string[32]; *color_string = 0;
1295             // Color tab
1296             if (!initial_color.empty()) {
1297                 guint32 rgba = sp_svg_read_color (initial_color.data(), 0x000000ff);
1298                 float hsl[3];
1299                 sp_color_rgb_to_hsl_floatv (hsl, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba));
1301                 double eff_i = (color_alternatei? (i%2) : (i));
1302                 double eff_j = (color_alternatej? (j%2) : (j));
1304                 hsl[0] += hue_per_i * eff_i + hue_per_j * eff_j + hue_rand * g_random_double_range (-1, 1);
1305                 double notused;
1306                 hsl[0] = modf( hsl[0], &notused ); // Restrict to 0-1
1307                 hsl[1] += saturation_per_i * eff_i + saturation_per_j * eff_j + saturation_rand * g_random_double_range (-1, 1);
1308                 hsl[1] = CLAMP (hsl[1], 0, 1);
1309                 hsl[2] += lightness_per_i * eff_i + lightness_per_j * eff_j + lightness_rand * g_random_double_range (-1, 1);
1310                 hsl[2] = CLAMP (hsl[2], 0, 1);
1312                 float rgb[3];
1313                 sp_color_hsl_to_rgb_floatv (rgb, hsl[0], hsl[1], hsl[2]);
1314                 sp_svg_write_color(color_string, sizeof(color_string), SP_RGBA32_F_COMPOSE(rgb[0], rgb[1], rgb[2], 1.0));
1315             }
1317             // Blur
1318             double blur = 0.0;
1319             {
1320             int eff_i = (blur_alternatei? (i%2) : (i));
1321             int eff_j = (blur_alternatej? (j%2) : (j));
1322             blur =  (blur_per_i * eff_i + blur_per_j * eff_j + blur_rand * g_random_double_range (-1, 1));
1323             blur = CLAMP (blur, 0, 1);
1324             }
1326             // Opacity
1327             double opacity = 1.0;
1328             {
1329             int eff_i = (opacity_alternatei? (i%2) : (i));
1330             int eff_j = (opacity_alternatej? (j%2) : (j));
1331             opacity = 1 - (opacity_per_i * eff_i + opacity_per_j * eff_j + opacity_rand * g_random_double_range (-1, 1));
1332             opacity = CLAMP (opacity, 0, 1);
1333             }
1335             // Trace tab
1336             if (dotrace) {
1337                 Geom::Rect bbox_t = transform_rect (bbox_original, t);
1339                 guint32 rgba = clonetiler_trace_pick (bbox_t);
1340                 float r = SP_RGBA32_R_F(rgba);
1341                 float g = SP_RGBA32_G_F(rgba);
1342                 float b = SP_RGBA32_B_F(rgba);
1343                 float a = SP_RGBA32_A_F(rgba);
1345                 float hsl[3];
1346                 sp_color_rgb_to_hsl_floatv (hsl, r, g, b);
1348                 gdouble val = 0;
1349                 switch (pick) {
1350                 case PICK_COLOR:
1351                     val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max
1352                     break;
1353                 case PICK_OPACITY:
1354                     val = a;
1355                     break;
1356                 case PICK_R:
1357                     val = r;
1358                     break;
1359                 case PICK_G:
1360                     val = g;
1361                     break;
1362                 case PICK_B:
1363                     val = b;
1364                     break;
1365                 case PICK_H:
1366                     val = hsl[0];
1367                     break;
1368                 case PICK_S:
1369                     val = hsl[1];
1370                     break;
1371                 case PICK_L:
1372                     val = 1 - hsl[2];
1373                     break;
1374                 default:
1375                     break;
1376                 }
1378                 if (rand_picked > 0) {
1379                     val = randomize01 (val, rand_picked);
1380                     r = randomize01 (r, rand_picked);
1381                     g = randomize01 (g, rand_picked);
1382                     b = randomize01 (b, rand_picked);
1383                 }
1385                 if (gamma_picked != 0) {
1386                     double power;
1387                     if (gamma_picked > 0)
1388                         power = 1/(1 + fabs(gamma_picked));
1389                     else
1390                         power = 1 + fabs(gamma_picked);
1392                     val = pow (val, power);
1393                     r = pow (r, power);
1394                     g = pow (g, power);
1395                     b = pow (b, power);
1396                 }
1398                 if (invert_picked) {
1399                     val = 1 - val;
1400                     r = 1 - r;
1401                     g = 1 - g;
1402                     b = 1 - b;
1403                 }
1405                 val = CLAMP (val, 0, 1);
1406                 r = CLAMP (r, 0, 1);
1407                 g = CLAMP (g, 0, 1);
1408                 b = CLAMP (b, 0, 1);
1410                 // recompose tweaked color
1411                 rgba = SP_RGBA32_F_COMPOSE(r, g, b, a);
1413                 if (pick_to_presence) {
1414                     if (g_random_double_range (0, 1) > val) {
1415                         continue; // skip!
1416                     }
1417                 }
1418                 if (pick_to_size) {
1419                     t = Geom::Translate(-center[Geom::X], -center[Geom::Y]) * Geom::Scale (val, val) * Geom::Translate(center[Geom::X], center[Geom::Y]) * t;
1420                 }
1421                 if (pick_to_opacity) {
1422                     opacity *= val;
1423                 }
1424                 if (pick_to_color) {
1425                     sp_svg_write_color(color_string, sizeof(color_string), rgba);
1426                 }
1427             }
1429             if (opacity < 1e-6) { // invisibly transparent, skip
1430                     continue;
1431             }
1433             if (fabs(t[0]) + fabs (t[1]) + fabs(t[2]) + fabs(t[3]) < 1e-6) { // too small, skip
1434                     continue;
1435             }
1437             // Create the clone
1438             Inkscape::XML::Node *clone = obj_repr->document()->createElement("svg:use");
1439             clone->setAttribute("x", "0");
1440             clone->setAttribute("y", "0");
1441             clone->setAttribute("inkscape:tiled-clone-of", id_href);
1442             clone->setAttribute("xlink:href", id_href);
1444             Geom::Point new_center;
1445             bool center_set = false;
1446             if (obj_repr->attribute("inkscape:transform-center-x") || obj_repr->attribute("inkscape:transform-center-y")) {
1447                 new_center = desktop->dt2doc(SP_ITEM(obj)->getCenter()) * t;
1448                 center_set = true;
1449             }
1451             gchar *affinestr=sp_svg_transform_write(t);
1452             clone->setAttribute("transform", affinestr);
1453             g_free(affinestr);
1455             if (opacity < 1.0) {
1456                 sp_repr_set_css_double(clone, "opacity", opacity);
1457             }
1459             if (*color_string) {
1460                 clone->setAttribute("fill", color_string);
1461                 clone->setAttribute("stroke", color_string);
1462             }
1464             // add the new clone to the top of the original's parent
1465             SP_OBJECT_REPR(parent)->appendChild(clone);
1467             if (blur > 0.0) {
1468                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1469                 double perimeter = perimeter_original * t.descrim();
1470                 double radius = blur * perimeter;
1471                 // this is necessary for all newly added clones to have correct bboxes,
1472                 // otherwise filters won't work:
1473                 sp_desktop_document(desktop)->ensureUpToDate();
1474                 // it's hard to figure out exact width/height of the tile without having an object
1475                 // that we can take bbox of; however here we only need a lower bound so that blur
1476                 // margins are not too small, and the perimeter should work
1477                 SPFilter *constructed = new_filter_gaussian_blur(sp_desktop_document(desktop), radius, t.descrim(), t.expansionX(), t.expansionY(), perimeter, perimeter);
1478                 sp_style_set_property_url (clone_object, "filter", SP_OBJECT(constructed), false);
1479             }
1481             if (center_set) {
1482                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1483                 if (clone_object && SP_IS_ITEM(clone_object)) {
1484                     clone_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1485                     SP_ITEM(clone_object)->setCenter(desktop->doc2dt(new_center));
1486                     clone_object->updateRepr();
1487                 }
1488             }
1490             Inkscape::GC::release(clone);
1491         }
1492         cur[Geom::Y] = 0;
1493     }
1495     if (dotrace) {
1496         clonetiler_trace_finish ();
1497     }
1499     clonetiler_change_selection (NULL, selection, dlg);
1501     desktop->clearWaitingCursor();
1503     DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER,
1504                        _("Create tiled clones"));
1507 static GtkWidget *
1508 clonetiler_new_tab (GtkWidget *nb, const gchar *label)
1510     GtkWidget *l = gtk_label_new_with_mnemonic (label);
1511     GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN);
1512     gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN);
1513     gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l);
1514     return vb;
1517 static void
1518 clonetiler_checkbox_toggled (GtkToggleButton *tb, gpointer *data)
1520     const gchar *attr = (const gchar *) data;
1521     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1522     prefs->setBool(prefs_path + attr, gtk_toggle_button_get_active(tb));
1525 static GtkWidget *
1526 clonetiler_checkbox (GtkTooltips *tt, const char *tip, const char *attr)
1528     GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
1530     GtkWidget *b = gtk_check_button_new ();
1531     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, tip, NULL);
1533     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1534     bool value = prefs->getBool(prefs_path + attr);
1535     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(b), value);
1537     gtk_box_pack_end (GTK_BOX (hb), b, FALSE, TRUE, 0);
1538     gtk_signal_connect ( GTK_OBJECT (b), "clicked",
1539                          GTK_SIGNAL_FUNC (clonetiler_checkbox_toggled), (gpointer) attr);
1541     g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
1543     return hb;
1547 static void
1548 clonetiler_value_changed (GtkAdjustment *adj, gpointer data)
1550     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1551     const gchar *pref = (const gchar *) data;
1552     prefs->setDouble(prefs_path + pref, adj->value);
1555 static GtkWidget *
1556 clonetiler_spinbox (GtkTooltips *tt, const char *tip, const char *attr, double lower, double upper, const gchar *suffix, bool exponent = false)
1558     GtkWidget *hb = gtk_hbox_new(FALSE, 0);
1560     {
1561         GtkObject *a;
1562         if (exponent)
1563             a = gtk_adjustment_new(1.0, lower, upper, 0.01, 0.05, 0.1);
1564         else
1565             a = gtk_adjustment_new(0.0, lower, upper, 0.1, 0.5, 2);
1567         GtkWidget *sb;
1568         if (exponent)
1569             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.01, 2);
1570         else
1571             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.1, 1);
1573         gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, tip, NULL);
1574         gtk_entry_set_width_chars (GTK_ENTRY (sb), 4);
1575         gtk_box_pack_start (GTK_BOX (hb), sb, FALSE, FALSE, SB_MARGIN);
1577         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1578         double value = prefs->getDoubleLimited(prefs_path + attr, exponent? 1.0 : 0.0, lower, upper);
1579         gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
1580         gtk_signal_connect(GTK_OBJECT(a), "value_changed",
1581                            GTK_SIGNAL_FUNC(clonetiler_value_changed), (gpointer) attr);
1583         if (exponent)
1584             g_object_set_data (G_OBJECT(sb), "oneable", GINT_TO_POINTER(TRUE));
1585         else
1586             g_object_set_data (G_OBJECT(sb), "zeroable", GINT_TO_POINTER(TRUE));
1587     }
1589     {
1590         GtkWidget *l = gtk_label_new ("");
1591         gtk_label_set_markup (GTK_LABEL(l), suffix);
1592         gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0);
1593         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
1594     }
1596     return hb;
1599 static void
1600 clonetiler_symgroup_changed( GtkMenuItem */*item*/, gpointer data )
1602     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1603     gint group_new = GPOINTER_TO_INT (data);
1604     prefs->setInt(prefs_path + "symmetrygroup", group_new);
1607 static void
1608 clonetiler_xy_changed (GtkAdjustment *adj, gpointer data)
1610     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1611     const gchar *pref = (const gchar *) data;
1612     prefs->setInt(prefs_path + pref, (int) floor(adj->value + 0.5));
1615 static void
1616 clonetiler_keep_bbox_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1618     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1619     prefs->setBool(prefs_path + "keepbbox", gtk_toggle_button_get_active(tb));
1622 static void
1623 clonetiler_pick_to (GtkToggleButton *tb, gpointer data)
1625     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1626     const gchar *pref = (const gchar *) data;
1627     prefs->setBool(prefs_path + pref, gtk_toggle_button_get_active(tb));
1631 static void
1632 clonetiler_reset_recursive (GtkWidget *w)
1634     if (w && GTK_IS_OBJECT(w)) {
1635         {
1636             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "zeroable"));
1637             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1638                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1639                 gtk_adjustment_set_value (a, 0);
1640             }
1641         }
1642         {
1643             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "oneable"));
1644             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1645                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1646                 gtk_adjustment_set_value (a, 1);
1647             }
1648         }
1649         {
1650             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "uncheckable"));
1651             if (r && GTK_IS_TOGGLE_BUTTON(w)) { // checkbox
1652                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(w), FALSE);
1653             }
1654         }
1655     }
1657     if (GTK_IS_CONTAINER(w)) {
1658         GList *ch = gtk_container_get_children (GTK_CONTAINER(w));
1659         for (GList *i = ch; i != NULL; i = i->next) {
1660             clonetiler_reset_recursive (GTK_WIDGET(i->data));
1661         }
1662         g_list_free (ch);
1663     }
1666 static void
1667 clonetiler_reset( GtkWidget */*widget*/, void * )
1669     clonetiler_reset_recursive (dlg);
1672 static void
1673 clonetiler_table_attach (GtkWidget *table, GtkWidget *widget, float align, int row, int col)
1675     GtkWidget *a = gtk_alignment_new (align, 0, 0, 0);
1676     gtk_container_add(GTK_CONTAINER(a), widget);
1677     gtk_table_attach ( GTK_TABLE (table), a, col, col + 1, row, row + 1, (GtkAttachOptions)4, (GtkAttachOptions)0, 0, 0 );
1680 static GtkWidget *
1681 clonetiler_table_x_y_rand (int values)
1683     GtkWidget *table = gtk_table_new (values + 2, 5, FALSE);
1684     gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
1685     gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1686     gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1688     {
1689         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1691         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, INKSCAPE_ICON_OBJECT_ROWS);
1692         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1694         GtkWidget *l = gtk_label_new ("");
1695         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per row:</small>"));
1696         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1698         clonetiler_table_attach (table, hb, 0, 1, 2);
1699     }
1701     {
1702         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1704         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, INKSCAPE_ICON_OBJECT_COLUMNS);
1705         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1707         GtkWidget *l = gtk_label_new ("");
1708         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per column:</small>"));
1709         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1711         clonetiler_table_attach (table, hb, 0, 1, 3);
1712     }
1714     {
1715         GtkWidget *l = gtk_label_new ("");
1716         gtk_label_set_markup (GTK_LABEL(l), _("<small>Randomize:</small>"));
1717         clonetiler_table_attach (table, l, 0, 1, 4);
1718     }
1720     return table;
1723 static void
1724 clonetiler_pick_switched( GtkToggleButton */*tb*/, gpointer data )
1726     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1727     guint v = GPOINTER_TO_INT (data);
1728     prefs->setInt(prefs_path + "pick", v);
1732 static void
1733 clonetiler_switch_to_create( GtkToggleButton */*tb*/, GtkWidget *dlg )
1735     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1736     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1738     if (rowscols) {
1739         gtk_widget_set_sensitive (rowscols, TRUE);
1740     }
1741     if (widthheight) {
1742         gtk_widget_set_sensitive (widthheight, FALSE);
1743     }
1745     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1746     prefs->setBool(prefs_path + "fillrect", false);
1750 static void
1751 clonetiler_switch_to_fill( GtkToggleButton */*tb*/, GtkWidget *dlg )
1753     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1754     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1756     if (rowscols) {
1757         gtk_widget_set_sensitive (rowscols, FALSE);
1758     }
1759     if (widthheight) {
1760         gtk_widget_set_sensitive (widthheight, TRUE);
1761     }
1763     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1764     prefs->setBool(prefs_path + "fillrect", true);
1770 static void
1771 clonetiler_fill_width_changed (GtkAdjustment *adj, GtkWidget *u)
1773     gdouble const raw_dist = adj->value;
1774     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1775     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1777     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1778     prefs->setDouble(prefs_path + "fillwidth", pixels);
1781 static void
1782 clonetiler_fill_height_changed (GtkAdjustment *adj, GtkWidget *u)
1784     gdouble const raw_dist = adj->value;
1785     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1786     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1788     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1789     prefs->setDouble(prefs_path + "fillheight", pixels);
1793 static void
1794 clonetiler_do_pick_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1796     GtkWidget *vvb = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "dotrace");
1798     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1799     prefs->setBool(prefs_path + "dotrace", gtk_toggle_button_get_active (tb));
1801     if (vvb)
1802         gtk_widget_set_sensitive (vvb, gtk_toggle_button_get_active (tb));
1808 void
1809 clonetiler_dialog (void)
1811     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1812     if (!dlg)
1813     {
1814         gchar title[500];
1815         sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_CLONETILER), title);
1817         dlg = sp_window_new (title, TRUE);
1818         if (x == -1000 || y == -1000) {
1819             x = prefs->getInt(prefs_path + "x", -1000);
1820             y = prefs->getInt(prefs_path + "y", -1000);
1821         }
1823         if (w ==0 || h == 0) {
1824             w = prefs->getInt(prefs_path + "w", 0);
1825             h = prefs->getInt(prefs_path + "h", 0);
1826         }
1828 //        if (x<0) x=0;
1829 //        if (y<0) y=0;
1831         if (w && h) {
1832             gtk_window_resize ((GtkWindow *) dlg, w, h);
1833         }
1834         if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) {
1835             gtk_window_move ((GtkWindow *) dlg, x, y);
1837         } else {
1838             gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
1839         }
1842         sp_transientize (dlg);
1843         wd.win = dlg;
1844         wd.stop = 0;
1847         gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);
1849         gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (clonetiler_dialog_destroy), dlg);
1850         gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (clonetiler_dialog_delete), dlg);
1852         g_signal_connect   ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (clonetiler_dialog_delete), dlg);
1853         g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg);
1854         g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg);
1855         g_signal_connect   ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd);
1857         GtkTooltips *tt = gtk_tooltips_new();
1859         GtkWidget *mainbox = gtk_vbox_new(FALSE, 4);
1860         gtk_container_set_border_width (GTK_CONTAINER (mainbox), 6);
1861         gtk_container_add (GTK_CONTAINER (dlg), mainbox);
1863         GtkWidget *nb = gtk_notebook_new ();
1864         gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0);
1867 // Symmetry
1868         {
1869             GtkWidget *vb = clonetiler_new_tab (nb, _("_Symmetry"));
1871             GtkWidget *om = gtk_option_menu_new ();
1872             /* TRANSLATORS: For the following 17 symmetry groups, see
1873              * http://www.bib.ulb.ac.be/coursmath/doc/17.htm (visual examples);
1874              * http://www.clarku.edu/~djoyce/wallpaper/seventeen.html (English vocabulary); or
1875              * http://membres.lycos.fr/villemingerard/Geometri/Sym1D.htm (French vocabulary).
1876              */
1877             gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), om, _("Select one of the 17 symmetry groups for the tiling"), NULL);
1878             gtk_box_pack_start (GTK_BOX (vb), om, FALSE, FALSE, SB_MARGIN);
1880             GtkWidget *m = gtk_menu_new ();
1881             int current = prefs->getInt(prefs_path + "symmetrygroup", 0);
1883             struct SymGroups {
1884                 int group;
1885                 gchar const *label;
1886             } const sym_groups[] = {
1887                 // TRANSLATORS: "translation" means "shift" / "displacement" here.
1888                 {TILE_P1, _("<b>P1</b>: simple translation")},
1889                 {TILE_P2, _("<b>P2</b>: 180&#176; rotation")},
1890                 {TILE_PM, _("<b>PM</b>: reflection")},
1891                 // TRANSLATORS: "glide reflection" is a reflection and a translation combined.
1892                 //  For more info, see http://mathforum.org/sum95/suzanne/symsusan.html
1893                 {TILE_PG, _("<b>PG</b>: glide reflection")},
1894                 {TILE_CM, _("<b>CM</b>: reflection + glide reflection")},
1895                 {TILE_PMM, _("<b>PMM</b>: reflection + reflection")},
1896                 {TILE_PMG, _("<b>PMG</b>: reflection + 180&#176; rotation")},
1897                 {TILE_PGG, _("<b>PGG</b>: glide reflection + 180&#176; rotation")},
1898                 {TILE_CMM, _("<b>CMM</b>: reflection + reflection + 180&#176; rotation")},
1899                 {TILE_P4, _("<b>P4</b>: 90&#176; rotation")},
1900                 {TILE_P4M, _("<b>P4M</b>: 90&#176; rotation + 45&#176; reflection")},
1901                 {TILE_P4G, _("<b>P4G</b>: 90&#176; rotation + 90&#176; reflection")},
1902                 {TILE_P3, _("<b>P3</b>: 120&#176; rotation")},
1903                 {TILE_P31M, _("<b>P31M</b>: reflection + 120&#176; rotation, dense")},
1904                 {TILE_P3M1, _("<b>P3M1</b>: reflection + 120&#176; rotation, sparse")},
1905                 {TILE_P6, _("<b>P6</b>: 60&#176; rotation")},
1906                 {TILE_P6M, _("<b>P6M</b>: reflection + 60&#176; rotation")},
1907             };
1909             for (unsigned j = 0; j < G_N_ELEMENTS(sym_groups); ++j) {
1910                 SymGroups const &sg = sym_groups[j];
1912                 GtkWidget *l = gtk_label_new ("");
1913                 gtk_label_set_markup (GTK_LABEL(l), sg.label);
1914                 gtk_misc_set_alignment (GTK_MISC(l), 0, 0.5);
1916                 GtkWidget *item = gtk_menu_item_new ();
1917                 gtk_container_add (GTK_CONTAINER (item), l);
1919                 gtk_signal_connect ( GTK_OBJECT (item), "activate",
1920                                      GTK_SIGNAL_FUNC (clonetiler_symgroup_changed),
1921                                      GINT_TO_POINTER (sg.group) );
1923                 gtk_menu_append (GTK_MENU (m), item);
1924             }
1926             gtk_option_menu_set_menu (GTK_OPTION_MENU (om), m);
1927             gtk_option_menu_set_history ( GTK_OPTION_MENU (om), current);
1928         }
1930         table_row_labels = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1932 // Shift
1933         {
1934             GtkWidget *vb = clonetiler_new_tab (nb, _("S_hift"));
1936             GtkWidget *table = clonetiler_table_x_y_rand (3);
1937             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1939             // X
1940             {
1941                 GtkWidget *l = gtk_label_new ("");
1942                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) horizontally by this amount
1943                     // xgettext:no-c-format
1944                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift X:</b>"));
1945                 gtk_size_group_add_widget(table_row_labels, l);
1946                 clonetiler_table_attach (table, l, 1, 2, 1);
1947             }
1949             {
1950                 GtkWidget *l = clonetiler_spinbox (tt,
1951                     // xgettext:no-c-format
1952                                                    _("Horizontal shift per row (in % of tile width)"), "shiftx_per_j",
1953                                                    -10000, 10000, "%");
1954                 clonetiler_table_attach (table, l, 0, 2, 2);
1955             }
1957             {
1958                 GtkWidget *l = clonetiler_spinbox (tt,
1959                     // xgettext:no-c-format
1960                                                    _("Horizontal shift per column (in % of tile width)"), "shiftx_per_i",
1961                                                    -10000, 10000, "%");
1962                 clonetiler_table_attach (table, l, 0, 2, 3);
1963             }
1965             {
1966                 GtkWidget *l = clonetiler_spinbox (tt,
1967                                                    _("Randomize the horizontal shift by this percentage"), "shiftx_rand",
1968                                                    0, 1000, "%");
1969                 clonetiler_table_attach (table, l, 0, 2, 4);
1970             }
1972             // Y
1973             {
1974                 GtkWidget *l = gtk_label_new ("");
1975                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) vertically by this amount
1976                     // xgettext:no-c-format
1977                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift Y:</b>"));
1978                 gtk_size_group_add_widget(table_row_labels, l);
1979                 clonetiler_table_attach (table, l, 1, 3, 1);
1980             }
1982             {
1983                 GtkWidget *l = clonetiler_spinbox (tt,
1984                     // xgettext:no-c-format
1985                                                    _("Vertical shift per row (in % of tile height)"), "shifty_per_j",
1986                                                    -10000, 10000, "%");
1987                 clonetiler_table_attach (table, l, 0, 3, 2);
1988             }
1990             {
1991                 GtkWidget *l = clonetiler_spinbox (tt,
1992                     // xgettext:no-c-format
1993                                                    _("Vertical shift per column (in % of tile height)"), "shifty_per_i",
1994                                                    -10000, 10000, "%");
1995                 clonetiler_table_attach (table, l, 0, 3, 3);
1996             }
1998             {
1999                 GtkWidget *l = clonetiler_spinbox (tt,
2000                                                    _("Randomize the vertical shift by this percentage"), "shifty_rand",
2001                                                    0, 1000, "%");
2002                 clonetiler_table_attach (table, l, 0, 3, 4);
2003             }
2005             // Exponent
2006             {
2007                 GtkWidget *l = gtk_label_new ("");
2008                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2009                 gtk_size_group_add_widget(table_row_labels, l);
2010                 clonetiler_table_attach (table, l, 1, 4, 1);
2011             }
2013             {
2014                 GtkWidget *l = clonetiler_spinbox (tt,
2015                                                    _("Whether rows are spaced evenly (1), converge (<1) or diverge (>1)"), "shifty_exp",
2016                                                    0, 10, "", true);
2017                 clonetiler_table_attach (table, l, 0, 4, 2);
2018             }
2020             {
2021                 GtkWidget *l = clonetiler_spinbox (tt,
2022                                                    _("Whether columns are spaced evenly (1), converge (<1) or diverge (>1)"), "shiftx_exp",
2023                                                    0, 10, "", true);
2024                 clonetiler_table_attach (table, l, 0, 4, 3);
2025             }
2027             { // alternates
2028                 GtkWidget *l = gtk_label_new ("");
2029                 // TRANSLATORS: "Alternate" is a verb here
2030                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2031                 gtk_size_group_add_widget(table_row_labels, l);
2032                 clonetiler_table_attach (table, l, 1, 5, 1);
2033             }
2035             {
2036                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each row"), "shifty_alternate");
2037                 clonetiler_table_attach (table, l, 0, 5, 2);
2038             }
2040             {
2041                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each column"), "shiftx_alternate");
2042                 clonetiler_table_attach (table, l, 0, 5, 3);
2043             }
2045             { // Cumulate
2046                 GtkWidget *l = gtk_label_new ("");
2047                 // TRANSLATORS: "Cumulate" is a verb here
2048                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2049                 gtk_size_group_add_widget(table_row_labels, l);
2050                 clonetiler_table_attach (table, l, 1, 6, 1);
2051             }
2053             {
2054                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each row"), "shifty_cumulate");
2055                 clonetiler_table_attach (table, l, 0, 6, 2);
2056             }
2058             {
2059                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each column"), "shiftx_cumulate");
2060                 clonetiler_table_attach (table, l, 0, 6, 3);
2061             }
2063             { // Exclude tile width and height in shift
2064                 GtkWidget *l = gtk_label_new ("");
2065                 // TRANSLATORS: "Cumulate" is a verb here
2066                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Exclude tile:</small>"));
2067                 gtk_size_group_add_widget(table_row_labels, l);
2068                 clonetiler_table_attach (table, l, 1, 7, 1);
2069             }
2071             {
2072                 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile height in shift"), "shifty_excludeh");
2073                 clonetiler_table_attach (table, l, 0, 7, 2);
2074             }
2076             {
2077                 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile width in shift"), "shiftx_excludew");
2078                 clonetiler_table_attach (table, l, 0, 7, 3);
2079             }
2081         }
2084 // Scale
2085         {
2086             GtkWidget *vb = clonetiler_new_tab (nb, _("Sc_ale"));
2088             GtkWidget *table = clonetiler_table_x_y_rand (2);
2089             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2091             // X
2092             {
2093                 GtkWidget *l = gtk_label_new ("");
2094                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale X:</b>"));
2095                 gtk_size_group_add_widget(table_row_labels, l);
2096                 clonetiler_table_attach (table, l, 1, 2, 1);
2097             }
2099             {
2100                 GtkWidget *l = clonetiler_spinbox (tt,
2101                     // xgettext:no-c-format
2102                                                    _("Horizontal scale per row (in % of tile width)"), "scalex_per_j",
2103                                                    -100, 1000, "%");
2104                 clonetiler_table_attach (table, l, 0, 2, 2);
2105             }
2107             {
2108                 GtkWidget *l = clonetiler_spinbox (tt,
2109                     // xgettext:no-c-format
2110                                                    _("Horizontal scale per column (in % of tile width)"), "scalex_per_i",
2111                                                    -100, 1000, "%");
2112                 clonetiler_table_attach (table, l, 0, 2, 3);
2113             }
2115             {
2116                 GtkWidget *l = clonetiler_spinbox (tt,
2117                                                    _("Randomize the horizontal scale by this percentage"), "scalex_rand",
2118                                                    0, 1000, "%");
2119                 clonetiler_table_attach (table, l, 0, 2, 4);
2120             }
2122             // Y
2123             {
2124                 GtkWidget *l = gtk_label_new ("");
2125                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale Y:</b>"));
2126                 gtk_size_group_add_widget(table_row_labels, l);
2127                 clonetiler_table_attach (table, l, 1, 3, 1);
2128             }
2130             {
2131                 GtkWidget *l = clonetiler_spinbox (tt,
2132                     // xgettext:no-c-format
2133                                                    _("Vertical scale per row (in % of tile height)"), "scaley_per_j",
2134                                                    -100, 1000, "%");
2135                 clonetiler_table_attach (table, l, 0, 3, 2);
2136             }
2138             {
2139                 GtkWidget *l = clonetiler_spinbox (tt,
2140                     // xgettext:no-c-format
2141                                                    _("Vertical scale per column (in % of tile height)"), "scaley_per_i",
2142                                                    -100, 1000, "%");
2143                 clonetiler_table_attach (table, l, 0, 3, 3);
2144             }
2146             {
2147                 GtkWidget *l = clonetiler_spinbox (tt,
2148                                                    _("Randomize the vertical scale by this percentage"), "scaley_rand",
2149                                                    0, 1000, "%");
2150                 clonetiler_table_attach (table, l, 0, 3, 4);
2151             }
2153             // Exponent
2154             {
2155                 GtkWidget *l = gtk_label_new ("");
2156                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2157                 gtk_size_group_add_widget(table_row_labels, l);
2158                 clonetiler_table_attach (table, l, 1, 4, 1);
2159             }
2161             {
2162                 GtkWidget *l = clonetiler_spinbox (tt,
2163                                                    _("Whether row scaling is uniform (1), converge (<1) or diverge (>1)"), "scaley_exp",
2164                                                    0, 10, "", true);
2165                 clonetiler_table_attach (table, l, 0, 4, 2);
2166             }
2168             {
2169                 GtkWidget *l = clonetiler_spinbox (tt,
2170                                                    _("Whether column scaling is uniform (1), converge (<1) or diverge (>1)"), "scalex_exp",
2171                                                    0, 10, "", true);
2172                 clonetiler_table_attach (table, l, 0, 4, 3);
2173             }
2175             // Logarithmic (as in logarithmic spiral)
2176             {
2177                 GtkWidget *l = gtk_label_new ("");
2178                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Base:</b>"));
2179                 gtk_size_group_add_widget(table_row_labels, l);
2180                 clonetiler_table_attach (table, l, 1, 5, 1);
2181             }
2183             {
2184                 GtkWidget *l = clonetiler_spinbox (tt,
2185                                                    _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scaley_log",
2186                                                    0, 10, "", false);
2187                 clonetiler_table_attach (table, l, 0, 5, 2);
2188             }
2190             {
2191                 GtkWidget *l = clonetiler_spinbox (tt,
2192                                                    _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scalex_log",
2193                                                    0, 10, "", false);
2194                 clonetiler_table_attach (table, l, 0, 5, 3);
2195             }
2197             { // alternates
2198                 GtkWidget *l = gtk_label_new ("");
2199                 // TRANSLATORS: "Alternate" is a verb here
2200                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2201                 gtk_size_group_add_widget(table_row_labels, l);
2202                 clonetiler_table_attach (table, l, 1, 6, 1);
2203             }
2205             {
2206                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each row"), "scaley_alternate");
2207                 clonetiler_table_attach (table, l, 0, 6, 2);
2208             }
2210             {
2211                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each column"), "scalex_alternate");
2212                 clonetiler_table_attach (table, l, 0, 6, 3);
2213             }
2215             { // Cumulate
2216                 GtkWidget *l = gtk_label_new ("");
2217                 // TRANSLATORS: "Cumulate" is a verb here
2218                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2219                 gtk_size_group_add_widget(table_row_labels, l);
2220                 clonetiler_table_attach (table, l, 1, 7, 1);
2221             }
2223             {
2224                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each row"), "scaley_cumulate");
2225                 clonetiler_table_attach (table, l, 0, 7, 2);
2226             }
2228             {
2229                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each column"), "scalex_cumulate");
2230                 clonetiler_table_attach (table, l, 0, 7, 3);
2231             }
2233         }
2236 // Rotation
2237         {
2238             GtkWidget *vb = clonetiler_new_tab (nb, _("_Rotation"));
2240             GtkWidget *table = clonetiler_table_x_y_rand (1);
2241             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2243             // Angle
2244             {
2245                 GtkWidget *l = gtk_label_new ("");
2246                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Angle:</b>"));
2247                 gtk_size_group_add_widget(table_row_labels, l);
2248                 clonetiler_table_attach (table, l, 1, 2, 1);
2249             }
2251             {
2252                 GtkWidget *l = clonetiler_spinbox (tt,
2253                     // xgettext:no-c-format
2254                                                    _("Rotate tiles by this angle for each row"), "rotate_per_j",
2255                                                    -180, 180, "&#176;");
2256                 clonetiler_table_attach (table, l, 0, 2, 2);
2257             }
2259             {
2260                 GtkWidget *l = clonetiler_spinbox (tt,
2261                     // xgettext:no-c-format
2262                                                    _("Rotate tiles by this angle for each column"), "rotate_per_i",
2263                                                    -180, 180, "&#176;");
2264                 clonetiler_table_attach (table, l, 0, 2, 3);
2265             }
2267             {
2268                 GtkWidget *l = clonetiler_spinbox (tt,
2269                                                    _("Randomize the rotation angle by this percentage"), "rotate_rand",
2270                                                    0, 100, "%");
2271                 clonetiler_table_attach (table, l, 0, 2, 4);
2272             }
2274             { // alternates
2275                 GtkWidget *l = gtk_label_new ("");
2276                 // TRANSLATORS: "Alternate" is a verb here
2277                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2278                 gtk_size_group_add_widget(table_row_labels, l);
2279                 clonetiler_table_attach (table, l, 1, 3, 1);
2280             }
2282             {
2283                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each row"), "rotate_alternatej");
2284                 clonetiler_table_attach (table, l, 0, 3, 2);
2285             }
2287             {
2288                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each column"), "rotate_alternatei");
2289                 clonetiler_table_attach (table, l, 0, 3, 3);
2290             }
2292             { // Cumulate
2293                 GtkWidget *l = gtk_label_new ("");
2294                 // TRANSLATORS: "Cumulate" is a verb here
2295                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2296                 gtk_size_group_add_widget(table_row_labels, l);
2297                 clonetiler_table_attach (table, l, 1, 4, 1);
2298             }
2300             {
2301                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each row"), "rotate_cumulatej");
2302                 clonetiler_table_attach (table, l, 0, 4, 2);
2303             }
2305             {
2306                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each column"), "rotate_cumulatei");
2307                 clonetiler_table_attach (table, l, 0, 4, 3);
2308             }
2310         }
2313 // Blur and opacity
2314         {
2315             GtkWidget *vb = clonetiler_new_tab (nb, _("_Blur & opacity"));
2317             GtkWidget *table = clonetiler_table_x_y_rand (1);
2318             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2321             // Blur
2322             {
2323                 GtkWidget *l = gtk_label_new ("");
2324                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Blur:</b>"));
2325                 gtk_size_group_add_widget(table_row_labels, l);
2326                 clonetiler_table_attach (table, l, 1, 2, 1);
2327             }
2329             {
2330                 GtkWidget *l = clonetiler_spinbox (tt,
2331                                                    _("Blur tiles by this percentage for each row"), "blur_per_j",
2332                                                    0, 100, "%");
2333                 clonetiler_table_attach (table, l, 0, 2, 2);
2334             }
2336             {
2337                 GtkWidget *l = clonetiler_spinbox (tt,
2338                                                    _("Blur tiles by this percentage for each column"), "blur_per_i",
2339                                                    0, 100, "%");
2340                 clonetiler_table_attach (table, l, 0, 2, 3);
2341             }
2343             {
2344                 GtkWidget *l = clonetiler_spinbox (tt,
2345                                                    _("Randomize the tile blur by this percentage"), "blur_rand",
2346                                                    0, 100, "%");
2347                 clonetiler_table_attach (table, l, 0, 2, 4);
2348             }
2350             { // alternates
2351                 GtkWidget *l = gtk_label_new ("");
2352                 // TRANSLATORS: "Alternate" is a verb here
2353                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2354                 gtk_size_group_add_widget(table_row_labels, l);
2355                 clonetiler_table_attach (table, l, 1, 3, 1);
2356             }
2358             {
2359                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each row"), "blur_alternatej");
2360                 clonetiler_table_attach (table, l, 0, 3, 2);
2361             }
2363             {
2364                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each column"), "blur_alternatei");
2365                 clonetiler_table_attach (table, l, 0, 3, 3);
2366             }
2370             // Dissolve
2371             {
2372                 GtkWidget *l = gtk_label_new ("");
2373                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Fade out:</b>"));
2374                 gtk_size_group_add_widget(table_row_labels, l);
2375                 clonetiler_table_attach (table, l, 1, 4, 1);
2376             }
2378             {
2379                 GtkWidget *l = clonetiler_spinbox (tt,
2380                                                    _("Decrease tile opacity by this percentage for each row"), "opacity_per_j",
2381                                                    0, 100, "%");
2382                 clonetiler_table_attach (table, l, 0, 4, 2);
2383             }
2385             {
2386                 GtkWidget *l = clonetiler_spinbox (tt,
2387                                                    _("Decrease tile opacity by this percentage for each column"), "opacity_per_i",
2388                                                    0, 100, "%");
2389                 clonetiler_table_attach (table, l, 0, 4, 3);
2390             }
2392             {
2393                 GtkWidget *l = clonetiler_spinbox (tt,
2394                                                    _("Randomize the tile opacity by this percentage"), "opacity_rand",
2395                                                    0, 100, "%");
2396                 clonetiler_table_attach (table, l, 0, 4, 4);
2397             }
2399             { // alternates
2400                 GtkWidget *l = gtk_label_new ("");
2401                 // TRANSLATORS: "Alternate" is a verb here
2402                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2403                 gtk_size_group_add_widget(table_row_labels, l);
2404                 clonetiler_table_attach (table, l, 1, 5, 1);
2405             }
2407             {
2408                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each row"), "opacity_alternatej");
2409                 clonetiler_table_attach (table, l, 0, 5, 2);
2410             }
2412             {
2413                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each column"), "opacity_alternatei");
2414                 clonetiler_table_attach (table, l, 0, 5, 3);
2415             }
2416         }
2419 // Color
2420         {
2421             GtkWidget *vb = clonetiler_new_tab (nb, _("Co_lor"));
2423             {
2424             GtkWidget *hb = gtk_hbox_new (FALSE, 0);
2426             GtkWidget *l = gtk_label_new (_("Initial color: "));
2427             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2429             guint32 rgba = 0x000000ff | sp_svg_read_color (prefs->getString(prefs_path + "initial_color").data(), 0x000000ff);
2430             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);
2431             _color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed));
2433             gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast<GtkWidget*>(color_picker->gobj()), FALSE, FALSE, 0);
2435             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2436             }
2439             GtkWidget *table = clonetiler_table_x_y_rand (3);
2440             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2442             // Hue
2443             {
2444                 GtkWidget *l = gtk_label_new ("");
2445                 gtk_label_set_markup (GTK_LABEL(l), _("<b>H:</b>"));
2446                 gtk_size_group_add_widget(table_row_labels, l);
2447                 clonetiler_table_attach (table, l, 1, 2, 1);
2448             }
2450             {
2451                 GtkWidget *l = clonetiler_spinbox (tt,
2452                                                    _("Change the tile hue by this percentage for each row"), "hue_per_j",
2453                                                    -100, 100, "%");
2454                 clonetiler_table_attach (table, l, 0, 2, 2);
2455             }
2457             {
2458                 GtkWidget *l = clonetiler_spinbox (tt,
2459                                                    _("Change the tile hue by this percentage for each column"), "hue_per_i",
2460                                                    -100, 100, "%");
2461                 clonetiler_table_attach (table, l, 0, 2, 3);
2462             }
2464             {
2465                 GtkWidget *l = clonetiler_spinbox (tt,
2466                                                    _("Randomize the tile hue by this percentage"), "hue_rand",
2467                                                    0, 100, "%");
2468                 clonetiler_table_attach (table, l, 0, 2, 4);
2469             }
2472             // Saturation
2473             {
2474                 GtkWidget *l = gtk_label_new ("");
2475                 gtk_label_set_markup (GTK_LABEL(l), _("<b>S:</b>"));
2476                 gtk_size_group_add_widget(table_row_labels, l);
2477                 clonetiler_table_attach (table, l, 1, 3, 1);
2478             }
2480             {
2481                 GtkWidget *l = clonetiler_spinbox (tt,
2482                                                    _("Change the color saturation by this percentage for each row"), "saturation_per_j",
2483                                                    -100, 100, "%");
2484                 clonetiler_table_attach (table, l, 0, 3, 2);
2485             }
2487             {
2488                 GtkWidget *l = clonetiler_spinbox (tt,
2489                                                    _("Change the color saturation by this percentage for each column"), "saturation_per_i",
2490                                                    -100, 100, "%");
2491                 clonetiler_table_attach (table, l, 0, 3, 3);
2492             }
2494             {
2495                 GtkWidget *l = clonetiler_spinbox (tt,
2496                                                    _("Randomize the color saturation by this percentage"), "saturation_rand",
2497                                                    0, 100, "%");
2498                 clonetiler_table_attach (table, l, 0, 3, 4);
2499             }
2501             // Lightness
2502             {
2503                 GtkWidget *l = gtk_label_new ("");
2504                 gtk_label_set_markup (GTK_LABEL(l), _("<b>L:</b>"));
2505                 gtk_size_group_add_widget(table_row_labels, l);
2506                 clonetiler_table_attach (table, l, 1, 4, 1);
2507             }
2509             {
2510                 GtkWidget *l = clonetiler_spinbox (tt,
2511                                                    _("Change the color lightness by this percentage for each row"), "lightness_per_j",
2512                                                    -100, 100, "%");
2513                 clonetiler_table_attach (table, l, 0, 4, 2);
2514             }
2516             {
2517                 GtkWidget *l = clonetiler_spinbox (tt,
2518                                                    _("Change the color lightness by this percentage for each column"), "lightness_per_i",
2519                                                    -100, 100, "%");
2520                 clonetiler_table_attach (table, l, 0, 4, 3);
2521             }
2523             {
2524                 GtkWidget *l = clonetiler_spinbox (tt,
2525                                                    _("Randomize the color lightness by this percentage"), "lightness_rand",
2526                                                    0, 100, "%");
2527                 clonetiler_table_attach (table, l, 0, 4, 4);
2528             }
2531             { // alternates
2532                 GtkWidget *l = gtk_label_new ("");
2533                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2534                 gtk_size_group_add_widget(table_row_labels, l);
2535                 clonetiler_table_attach (table, l, 1, 5, 1);
2536             }
2538             {
2539                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each row"), "color_alternatej");
2540                 clonetiler_table_attach (table, l, 0, 5, 2);
2541             }
2543             {
2544                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each column"), "color_alternatei");
2545                 clonetiler_table_attach (table, l, 0, 5, 3);
2546             }
2548         }
2550 // Trace
2551         {
2552             GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace"));
2555         {
2556             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2557             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2559             GtkWidget *b  = gtk_check_button_new_with_label (_("Trace the drawing under the tiles"));
2560             g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
2561             bool old = prefs->getBool(prefs_path + "dotrace");
2562             gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2563             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);
2564             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2566             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2567                                GTK_SIGNAL_FUNC(clonetiler_do_pick_toggled), dlg);
2568         }
2570         {
2571             GtkWidget *vvb = gtk_vbox_new (FALSE, 0);
2572             gtk_box_pack_start (GTK_BOX (vb), vvb, FALSE, FALSE, 0);
2573             g_object_set_data (G_OBJECT(dlg), "dotrace", (gpointer) vvb);
2576             {
2577                 GtkWidget *frame = gtk_frame_new (_("1. Pick from the drawing:"));
2578                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2580                 GtkWidget *table = gtk_table_new (3, 3, FALSE);
2581                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2582                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2583                 gtk_container_add(GTK_CONTAINER(frame), table);
2586                 GtkWidget* radio;
2587                 {
2588                     radio = gtk_radio_button_new_with_label (NULL, _("Color"));
2589                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the visible color and opacity"), NULL);
2590                     clonetiler_table_attach (table, radio, 0.0, 1, 1);
2591                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2592                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_COLOR));
2593                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_COLOR);
2594                 }
2595                 {
2596                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Opacity"));
2597                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the total accumulated opacity"), NULL);
2598                     clonetiler_table_attach (table, radio, 0.0, 2, 1);
2599                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2600                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_OPACITY));
2601                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_OPACITY);
2602                 }
2603                 {
2604                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("R"));
2605                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Red component of the color"), NULL);
2606                     clonetiler_table_attach (table, radio, 0.0, 1, 2);
2607                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2608                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_R));
2609                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_R);
2610                 }
2611                 {
2612                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("G"));
2613                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Green component of the color"), NULL);
2614                     clonetiler_table_attach (table, radio, 0.0, 2, 2);
2615                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2616                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_G));
2617                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_G);
2618                 }
2619                 {
2620                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("B"));
2621                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Blue component of the color"), NULL);
2622                     clonetiler_table_attach (table, radio, 0.0, 3, 2);
2623                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2624                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_B));
2625                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_B);
2626                 }
2627                 {
2628                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), C_("Clonetiler color hue", "H"));
2629                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the hue of the color"), NULL);
2630                     clonetiler_table_attach (table, radio, 0.0, 1, 3);
2631                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2632                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_H));
2633                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_H);
2634                 }
2635                 {
2636                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), C_("Clonetiler color saturation", "S"));
2637                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the saturation of the color"), NULL);
2638                     clonetiler_table_attach (table, radio, 0.0, 2, 3);
2639                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2640                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_S));
2641                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_S);
2642                 }
2643                 {
2644                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), C_("Clonetiler color lightness", "L"));
2645                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the lightness of the color"), NULL);
2646                     clonetiler_table_attach (table, radio, 0.0, 3, 3);
2647                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2648                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_L));
2649                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_L);
2650                 }
2652             }
2654             {
2655                 GtkWidget *frame = gtk_frame_new (_("2. Tweak the picked value:"));
2656                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, VB_MARGIN);
2658                 GtkWidget *table = gtk_table_new (4, 2, FALSE);
2659                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2660                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2661                 gtk_container_add(GTK_CONTAINER(frame), table);
2663                 {
2664                     GtkWidget *l = gtk_label_new ("");
2665                     gtk_label_set_markup (GTK_LABEL(l), _("Gamma-correct:"));
2666                     clonetiler_table_attach (table, l, 1.0, 1, 1);
2667                 }
2668                 {
2669                     GtkWidget *l = clonetiler_spinbox (tt,
2670                                                        _("Shift the mid-range of the picked value upwards (>0) or downwards (<0)"), "gamma_picked",
2671                                                        -10, 10, "");
2672                     clonetiler_table_attach (table, l, 0.0, 1, 2);
2673                 }
2675                 {
2676                     GtkWidget *l = gtk_label_new ("");
2677                     gtk_label_set_markup (GTK_LABEL(l), _("Randomize:"));
2678                     clonetiler_table_attach (table, l, 1.0, 1, 3);
2679                 }
2680                 {
2681                     GtkWidget *l = clonetiler_spinbox (tt,
2682                                                        _("Randomize the picked value by this percentage"), "rand_picked",
2683                                                        0, 100, "%");
2684                     clonetiler_table_attach (table, l, 0.0, 1, 4);
2685                 }
2687                 {
2688                     GtkWidget *l = gtk_label_new ("");
2689                     gtk_label_set_markup (GTK_LABEL(l), _("Invert:"));
2690                     clonetiler_table_attach (table, l, 1.0, 2, 1);
2691                 }
2692                 {
2693                     GtkWidget *l = clonetiler_checkbox (tt, _("Invert the picked value"), "invert_picked");
2694                     clonetiler_table_attach (table, l, 0.0, 2, 2);
2695                 }
2696             }
2698             {
2699                 GtkWidget *frame = gtk_frame_new (_("3. Apply the value to the clones':"));
2700                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2703                 GtkWidget *table = gtk_table_new (2, 2, FALSE);
2704                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2705                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2706                 gtk_container_add(GTK_CONTAINER(frame), table);
2708                 {
2709                     GtkWidget *b  = gtk_check_button_new_with_label (_("Presence"));
2710                     bool old = prefs->getBool(prefs_path + "pick_to_presence", true);
2711                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2712                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone is created with the probability determined by the picked value in that point"), NULL);
2713                     clonetiler_table_attach (table, b, 0.0, 1, 1);
2714                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2715                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_presence");
2716                 }
2718                 {
2719                     GtkWidget *b  = gtk_check_button_new_with_label (_("Size"));
2720                     bool old = prefs->getBool(prefs_path + "pick_to_size");
2721                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2722                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's size is determined by the picked value in that point"), NULL);
2723                     clonetiler_table_attach (table, b, 0.0, 2, 1);
2724                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2725                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_size");
2726                 }
2728                 {
2729                     GtkWidget *b  = gtk_check_button_new_with_label (_("Color"));
2730                     bool old = prefs->getBool(prefs_path + "pick_to_color", 0);
2731                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2732                     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);
2733                     clonetiler_table_attach (table, b, 0.0, 1, 2);
2734                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2735                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_color");
2736                 }
2738                 {
2739                     GtkWidget *b  = gtk_check_button_new_with_label (_("Opacity"));
2740                     bool old = prefs->getBool(prefs_path + "pick_to_opacity", 0);
2741                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2742                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's opacity is determined by the picked value in that point"), NULL);
2743                     clonetiler_table_attach (table, b, 0.0, 2, 2);
2744                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2745                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_opacity");
2746                 }
2747             }
2748            gtk_widget_set_sensitive (vvb, prefs->getBool(prefs_path + "dotrace"));
2749         }
2750         }
2752 // Rows/columns, width/height
2753         {
2754             GtkWidget *table = gtk_table_new (2, 2, FALSE);
2755             gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
2756             gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2757             gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2758             gtk_box_pack_start (GTK_BOX (mainbox), table, FALSE, FALSE, 0);
2760             {
2761                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2762                 g_object_set_data (G_OBJECT(dlg), "rowscols", (gpointer) hb);
2764                 {
2765                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2766                     int value = prefs->getInt(prefs_path + "jmax", 2);
2767                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2768                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2769                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many rows in the tiling"), NULL);
2770                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2771                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2773                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2774                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "jmax");
2775                 }
2777                 {
2778                     GtkWidget *l = gtk_label_new ("");
2779                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2780                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2781                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2782                 }
2784                 {
2785                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2786                     int value = prefs->getInt(prefs_path + "imax", 2);
2787                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2788                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2789                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many columns in the tiling"), NULL);
2790                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2791                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2793                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2794                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "imax");
2795                 }
2797                 clonetiler_table_attach (table, hb, 0.0, 1, 2);
2798             }
2800             {
2801                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2802                 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
2804                 // unitmenu
2805                 GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
2806                 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
2808                 {
2809                     // Width spinbutton
2810                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2811                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2813                     double value = prefs->getDouble(prefs_path + "fillwidth", 50.0);
2814                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2815                     gdouble const units = sp_pixels_get_units (value, unit);
2816                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2818                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2819                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Width of the rectangle to be filled"), NULL);
2820                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2821                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2822                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2823                                        GTK_SIGNAL_FUNC(clonetiler_fill_width_changed), u);
2824                 }
2825                 {
2826                     GtkWidget *l = gtk_label_new ("");
2827                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2828                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2829                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2830                 }
2832                 {
2833                     // Height spinbutton
2834                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2835                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2837                     double value = prefs->getDouble(prefs_path + "fillheight", 50.0);
2838                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2839                     gdouble const units = sp_pixels_get_units (value, unit);
2840                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2843                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2844                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Height of the rectangle to be filled"), NULL);
2845                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2846                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2847                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2848                                        GTK_SIGNAL_FUNC(clonetiler_fill_height_changed), u);
2849                 }
2851                 gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);
2852                 clonetiler_table_attach (table, hb, 0.0, 2, 2);
2854             }
2856             // Switch
2857             GtkWidget* radio;
2858             {
2859                 radio = gtk_radio_button_new_with_label (NULL, _("Rows, columns: "));
2860                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Create the specified number of rows and columns"), NULL);
2861                 clonetiler_table_attach (table, radio, 0.0, 1, 1);
2862                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_create), (gpointer) dlg);
2863             }
2864             if (!prefs->getBool(prefs_path + "fillrect")) {
2865                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2866                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2867             }
2868             {
2869                 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Width, height: "));
2870                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Fill the specified width and height with the tiling"), NULL);
2871                 clonetiler_table_attach (table, radio, 0.0, 2, 1);
2872                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_fill), (gpointer) dlg);
2873             }
2874             if (prefs->getBool(prefs_path + "fillrect")) {
2875                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2876                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2877             }
2878         }
2881 // Use saved pos
2882         {
2883             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2884             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2886             GtkWidget *b  = gtk_check_button_new_with_label (_("Use saved size and position of the tile"));
2887             bool keepbbox = prefs->getBool(prefs_path + "keepbbox", true);
2888             gtk_toggle_button_set_active ((GtkToggleButton *) b, keepbbox);
2889             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);
2890             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2892             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2893                                GTK_SIGNAL_FUNC(clonetiler_keep_bbox_toggled), NULL);
2894         }
2896 // Statusbar
2897         {
2898             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2899             gtk_box_pack_end (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2900             GtkWidget *l = gtk_label_new("");
2901             g_object_set_data (G_OBJECT(dlg), "status", (gpointer) l);
2902             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2903         }
2905 // Buttons
2906         {
2907             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2908             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2910             {
2911                 GtkWidget *b = gtk_button_new ();
2912                 GtkWidget *l = gtk_label_new ("");
2913                 gtk_label_set_markup_with_mnemonic (GTK_LABEL(l), _(" <b>_Create</b> "));
2914                 gtk_container_add (GTK_CONTAINER(b), l);
2915                 gtk_tooltips_set_tip (tt, b, _("Create and tile the clones of the selection"), NULL);
2916                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_apply), NULL);
2917                 gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0);
2918             }
2920             { // buttons which are enabled only when there are tiled clones
2921                 GtkWidget *sb = gtk_hbox_new(FALSE, 0);
2922                 gtk_box_pack_end (GTK_BOX (hb), sb, FALSE, FALSE, 0);
2923                 g_object_set_data (G_OBJECT(dlg), "buttons_on_tiles", (gpointer) sb);
2924                 {
2925                     // TRANSLATORS: if a group of objects are "clumped" together, then they
2926                     //  are unevenly spread in the given amount of space - as shown in the
2927                     //  diagrams on the left in the following screenshot:
2928                     //  http://www.inkscape.org/screenshots/gallery/inkscape-0.42-CVS-tiles-unclump.png
2929                     //  So unclumping is the process of spreading a number of objects out more evenly.
2930                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" _Unclump "));
2931                     gtk_tooltips_set_tip (tt, b, _("Spread out clones to reduce clumping; can be applied repeatedly"), NULL);
2932                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_unclump), NULL);
2933                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2934                 }
2936                 {
2937                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" Re_move "));
2938                     gtk_tooltips_set_tip (tt, b, _("Remove existing tiled clones of the selected object (siblings only)"), NULL);
2939                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_remove), NULL);
2940                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2941                 }
2943                 // connect to global selection changed signal (so we can change desktops) and
2944                 // external_change (so we're not fooled by undo)
2945                 g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (clonetiler_change_selection), dlg);
2946                 g_signal_connect (G_OBJECT (INKSCAPE), "external_change", G_CALLBACK (clonetiler_external_change), dlg);
2947                 g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), G_OBJECT (INKSCAPE));
2949                 // update now
2950                 clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
2951             }
2953             {
2954                 GtkWidget *b = gtk_button_new_with_mnemonic (_(" R_eset "));
2955                 // TRANSLATORS: "change" is a noun here
2956                 gtk_tooltips_set_tip (tt, b, _("Reset all shifts, scales, rotates, opacity and color changes in the dialog to zero"), NULL);
2957                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_reset), NULL);
2958                 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2959             }
2960         }
2962         gtk_widget_show_all (mainbox);
2964     } // end of if (!dlg)
2966     gtk_window_present ((GtkWindow *) dlg);
2970 /*
2971   Local Variables:
2972   mode:c++
2973   c-file-style:"stroustrup"
2974   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2975   indent-tabs-mode:nil
2976   fill-column:99
2977   End:
2978 */
2979 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :