Code

since all values are 0..1, shifting gamma up must use power<1 so that the values...
[inkscape.git] / src / dialogs / clonetiler.cpp
1 #define __SP_CLONE_TILER_C__
3 /*
4  * Clone tiling dialog
5  *
6  * Authors:
7  *   bulia byak <buliabyak@users.sf.net>
8  *   Johan Engelen <goejendaagh@zonnet.nl>
9  *
10  * Copyright (C) 2004-2006 Authors
11  * Released under GNU GPL
12  */
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
17 #include <glib/gmem.h>
18 #include <gtk/gtk.h>
19 #include <glibmm/i18n.h>
21 #include "application/application.h"
22 #include "application/editor.h"
23 #include "helper/window.h"
24 #include "helper/unit-menu.h"
25 #include "helper/units.h"
26 #include "widgets/icon.h"
27 #include "../inkscape.h"
28 #include "../prefs-utils.h"
29 #include "dialog-events.h"
30 #include "../macros.h"
31 #include "../verbs.h"
32 #include "../interface.h"
33 #include "../selection.h"
34 #include "../style.h"
35 #include "../desktop.h"
36 #include "../desktop-handles.h"
37 #include "../sp-namedview.h"
38 #include "../document.h"
39 #include "../message-stack.h"
40 #include "../sp-use.h"
41 #include "unclump.h"
43 #include "xml/repr.h"
45 #include "svg/svg.h"
46 #include "svg/svg-color.h"
48 #include "libnr/nr-matrix-fns.h"
49 #include "libnr/nr-matrix-ops.h"
51 #include "libnr/nr-matrix-translate-ops.h"
52 #include "libnr/nr-translate-ops.h"
53 #include "libnr/nr-translate-rotate-ops.h"
54 #include "libnr/nr-translate-scale-ops.h"
56 #include "display/nr-arena.h"
57 #include "display/nr-arena-item.h"
59 #include "ui/widget/color-picker.h"
61 #include "../sp-filter.h"
62 #include "../filter-chemistry.h"
64 #define MIN_ONSCREEN_DISTANCE 50
66 static GtkWidget *dlg = NULL;
67 static win_data wd;
69 // impossible original values to make sure they are read from prefs
70 static gint x = -1000, y = -1000, w = 0, h = 0;
71 static gchar const *prefs_path = "dialogs.clonetiler";
73 #define SB_MARGIN 1
74 #define VB_MARGIN 4
76 enum {
77     PICK_COLOR,
78     PICK_OPACITY,
79     PICK_R,
80     PICK_G,
81     PICK_B,
82     PICK_H,
83     PICK_S,
84     PICK_L
85 };
87 static GtkSizeGroup* table_row_labels = NULL;
89 static sigc::connection _shutdown_connection;
90 static sigc::connection _dialogs_hidden_connection;
91 static sigc::connection _dialogs_unhidden_connection;
92 static sigc::connection _desktop_activated_connection;
93 static sigc::connection _color_changed_connection;
95 static Inkscape::UI::Widget::ColorPicker *color_picker;
97 static void
98 clonetiler_dialog_destroy( GtkObject */*object*/, gpointer /*data*/ )
99 {
100     if (Inkscape::NSApplication::Application::getNewGui())
101     {
102         _shutdown_connection.disconnect();
103         _dialogs_hidden_connection.disconnect();
104         _dialogs_unhidden_connection.disconnect();
105         _desktop_activated_connection.disconnect();
106     } else {
107         sp_signal_disconnect_by_data (INKSCAPE, dlg);
108     }
109     _color_changed_connection.disconnect();
111     delete color_picker;
113     wd.win = dlg = NULL;
114     wd.stop = 0;
118 static gboolean
119 clonetiler_dialog_delete (GtkObject */*object*/, GdkEvent * /*event*/, gpointer /*data*/)
121     gtk_window_get_position ((GtkWindow *) dlg, &x, &y);
122     gtk_window_get_size ((GtkWindow *) dlg, &w, &h);
124     if (x<0) x=0;
125     if (y<0) y=0;
127     prefs_set_int_attribute (prefs_path, "x", x);
128     prefs_set_int_attribute (prefs_path, "y", y);
129     prefs_set_int_attribute (prefs_path, "w", w);
130     prefs_set_int_attribute (prefs_path, "h", h);
132     return FALSE; // which means, go ahead and destroy it
136 static void on_delete()
138     (void)clonetiler_dialog_delete (0, 0, NULL);
141 static void
142 on_picker_color_changed (guint rgba)
144     static bool is_updating = false;
145     if (is_updating || !SP_ACTIVE_DESKTOP)
146         return;
148     is_updating = true;
150     Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, prefs_path);
151     gchar c[32];
152     sp_svg_write_color(c, sizeof(c), rgba);
153     repr->setAttribute("initial_color", c);
155     is_updating = false;
158 static guint clonetiler_number_of_clones (SPObject *obj);
160 static void
161 clonetiler_change_selection (Inkscape::Application * /*inkscape*/, Inkscape::Selection *selection, GtkWidget *dlg)
163     GtkWidget *buttons = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "buttons_on_tiles");
164     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
166     if (selection->isEmpty()) {
167         gtk_widget_set_sensitive (buttons, FALSE);
168         gtk_label_set_markup (GTK_LABEL(status), _("<small>Nothing selected.</small>"));
169         return;
170     }
172     if (g_slist_length ((GSList *) selection->itemList()) > 1) {
173         gtk_widget_set_sensitive (buttons, FALSE);
174         gtk_label_set_markup (GTK_LABEL(status), _("<small>More than one object selected.</small>"));
175         return;
176     }
178     guint n = clonetiler_number_of_clones(selection->singleItem());
179     if (n > 0) {
180         gtk_widget_set_sensitive (buttons, TRUE);
181         gchar *sta = g_strdup_printf (_("<small>Object has <b>%d</b> tiled clones.</small>"), n);
182         gtk_label_set_markup (GTK_LABEL(status), sta);
183         g_free (sta);
184     } else {
185         gtk_widget_set_sensitive (buttons, FALSE);
186         gtk_label_set_markup (GTK_LABEL(status), _("<small>Object has no tiled clones.</small>"));
187     }
190 static void
191 clonetiler_external_change (Inkscape::Application * /*inkscape*/, GtkWidget *dlg)
193     clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
196 static void clonetiler_disconnect_gsignal (GObject *widget, gpointer source) {
197     if (source && G_IS_OBJECT(source))
198         sp_signal_disconnect_by_data (source, widget);
202 enum {
203     TILE_P1,
204     TILE_P2,
205     TILE_PM,
206     TILE_PG,
207     TILE_CM,
208     TILE_PMM,
209     TILE_PMG,
210     TILE_PGG,
211     TILE_CMM,
212     TILE_P4,
213     TILE_P4M,
214     TILE_P4G,
215     TILE_P3,
216     TILE_P31M,
217     TILE_P3M1,
218     TILE_P6,
219     TILE_P6M
220 };
223 static NR::Matrix
224 clonetiler_get_transform (
226     // symmetry group
227     int type,
229     // row, column
230     int i, int j,
232     // center, width, height of the tile
233     double cx, double cy,
234     double w,  double h,
236     // values from the dialog:
237     // Shift
238     double shiftx_per_i,      double shifty_per_i,
239     double shiftx_per_j,      double shifty_per_j,
240     double shiftx_rand,       double shifty_rand,
241     double shiftx_exp,        double shifty_exp,
242     int    shiftx_alternate,  int    shifty_alternate,
243     int    shiftx_cumulate,   int    shifty_cumulate,
244     int    shiftx_excludew,   int    shifty_excludeh,
246     // Scale
247     double scalex_per_i,      double scaley_per_i,
248     double scalex_per_j,      double scaley_per_j,
249     double scalex_rand,       double scaley_rand,
250     double scalex_exp,        double scaley_exp,
251     double scalex_log,        double scaley_log,
252     int    scalex_alternate,  int    scaley_alternate,
253     int    scalex_cumulate,   int    scaley_cumulate,
255     // Rotation
256     double rotate_per_i,      double rotate_per_j,
257     double rotate_rand,
258     int    rotate_alternatei, int    rotate_alternatej,
259     int    rotate_cumulatei,  int    rotate_cumulatej
260     )
263     // Shift (in units of tile width or height) -------------
264     double delta_shifti = 0.0;
265     double delta_shiftj = 0.0;
267     if( shiftx_alternate ) {
268         delta_shifti = (double)(i%2);
269     } else {
270         if( shiftx_cumulate ) {  // Should the delta shifts be cumulative (i.e. 1, 1+2, 1+2+3, ...)
271             delta_shifti = (double)(i*i);
272         } else {
273             delta_shifti = (double)i;
274         }
275     }
277     if( shifty_alternate ) {
278         delta_shiftj = (double)(j%2);
279     } else {
280         if( shifty_cumulate ) {
281             delta_shiftj = (double)(j*j);
282         } else {
283             delta_shiftj = (double)j;
284         }
285     }
287     // Random shift, only calculate if non-zero.
288     double delta_shiftx_rand = 0.0;
289     double delta_shifty_rand = 0.0;
290     if( shiftx_rand != 0.0 ) delta_shiftx_rand = shiftx_rand * g_random_double_range (-1, 1);
291     if( shifty_rand != 0.0 ) delta_shifty_rand = shifty_rand * g_random_double_range (-1, 1);
294     // Delta shift (units of tile width/height)
295     double di = shiftx_per_i * delta_shifti  + shiftx_per_j * delta_shiftj + delta_shiftx_rand;
296     double dj = shifty_per_i * delta_shifti  + shifty_per_j * delta_shiftj + delta_shifty_rand;
298     // Shift in actual x and y, used below
299     double dx = w * di;
300     double dy = h * dj;
302     double shifti = di;
303     double shiftj = dj;
305     // Include tile width and height in shift if required
306     if( !shiftx_excludew ) shifti += i;
307     if( !shifty_excludeh ) shiftj += j;
309     // Add exponential shift if necessary
310     if ( shiftx_exp != 1.0 ) shifti = pow( shifti, shiftx_exp );
311     if ( shifty_exp != 1.0 ) shiftj = pow( shiftj, shifty_exp );
313     // Final shift
314     NR::Matrix rect_translate (NR::translate (w * shifti, h * shiftj));
316     // Rotation (in degrees) ------------
317     double delta_rotationi = 0.0;
318     double delta_rotationj = 0.0;
320     if( rotate_alternatei ) {
321         delta_rotationi = (double)(i%2);
322     } else {
323         if( rotate_cumulatei ) {
324             delta_rotationi = (double)(i*i + i)/2.0;
325         } else {
326             delta_rotationi = (double)i;
327         }
328     }
330     if( rotate_alternatej ) {
331         delta_rotationj = (double)(j%2);
332     } else {
333         if( rotate_cumulatej ) {
334             delta_rotationj = (double)(j*j + j)/2.0;
335         } else {
336             delta_rotationj = (double)j;
337         }
338     }
340     double delta_rotate_rand = 0.0;
341     if( rotate_rand != 0.0 ) delta_rotate_rand = rotate_rand * 180.0 * g_random_double_range (-1, 1);
343     double dr = rotate_per_i * delta_rotationi + rotate_per_j * delta_rotationj + delta_rotate_rand;
345     // Scale (times the original) -----------
346     double delta_scalei = 0.0;
347     double delta_scalej = 0.0;
349     if( scalex_alternate ) {
350         delta_scalei = (double)(i%2);
351     } else {
352         if( scalex_cumulate ) {  // Should the delta scales be cumulative (i.e. 1, 1+2, 1+2+3, ...)
353             delta_scalei = (double)(i*i + i)/2.0;
354         } else {
355             delta_scalei = (double)i;
356         }
357     }
359     if( scaley_alternate ) {
360         delta_scalej = (double)(j%2);
361     } else {
362         if( scaley_cumulate ) {
363             delta_scalej = (double)(j*j + j)/2.0;
364         } else {
365             delta_scalej = (double)j;
366         }
367     }
369     // Random scale, only calculate if non-zero.
370     double delta_scalex_rand = 0.0;
371     double delta_scaley_rand = 0.0;
372     if( scalex_rand != 0.0 ) delta_scalex_rand = scalex_rand * g_random_double_range (-1, 1);
373     if( scaley_rand != 0.0 ) delta_scaley_rand = scaley_rand * g_random_double_range (-1, 1);
374     // But if random factors are same, scale x and y proportionally
375     if( scalex_rand == scaley_rand ) delta_scalex_rand = delta_scaley_rand;
377     // Total delta scale
378     double scalex = 1.0 + scalex_per_i * delta_scalei  + scalex_per_j * delta_scalej + delta_scalex_rand;
379     double scaley = 1.0 + scaley_per_i * delta_scalei  + scaley_per_j * delta_scalej + delta_scaley_rand;
381     if( scalex < 0.0 ) scalex = 0.0;
382     if( scaley < 0.0 ) scaley = 0.0;
384     // Add exponential scale if necessary
385     if ( scalex_exp != 1.0 ) scalex = pow( scalex, scalex_exp );
386     if ( scaley_exp != 1.0 ) scaley = pow( scaley, scaley_exp );
388     // Add logarithmic factor if necessary
389     if ( scalex_log  > 0.0 ) scalex = pow( scalex_log, scalex - 1.0 );
390     if ( scaley_log  > 0.0 ) scaley = pow( scaley_log, scaley - 1.0 );
391     // Alternative using rotation angle
392     //if ( scalex_log  != 1.0 ) scalex *= pow( scalex_log, M_PI*dr/180 );
393     //if ( scaley_log  != 1.0 ) scaley *= pow( scaley_log, M_PI*dr/180 );
396     // Calculate transformation matrices, translating back to "center of tile" (rotation center) before transforming
397     NR::Matrix drot_c   = NR::translate(-cx, -cy) * NR::rotate (M_PI*dr/180)    * NR::translate(cx, cy);
399     NR::Matrix dscale_c = NR::translate(-cx, -cy) * NR::scale (scalex, scaley)  * NR::translate(cx, cy);
401     NR::Matrix d_s_r = dscale_c * drot_c;
403     NR::Matrix rotate_180_c  = NR::translate(-cx, -cy) * NR::rotate (M_PI)      * NR::translate(cx, cy);
405     NR::Matrix rotate_90_c   = NR::translate(-cx, -cy) * NR::rotate (-M_PI/2)   * NR::translate(cx, cy);
406     NR::Matrix rotate_m90_c  = NR::translate(-cx, -cy) * NR::rotate ( M_PI/2)   * NR::translate(cx, cy);
408     NR::Matrix rotate_120_c  = NR::translate(-cx, -cy) * NR::rotate (-2*M_PI/3) * NR::translate(cx, cy);
409     NR::Matrix rotate_m120_c = NR::translate(-cx, -cy) * NR::rotate ( 2*M_PI/3) * NR::translate(cx, cy);
411     NR::Matrix rotate_60_c   = NR::translate(-cx, -cy) * NR::rotate (-M_PI/3)   * NR::translate(cx, cy);
412     NR::Matrix rotate_m60_c  = NR::translate(-cx, -cy) * NR::rotate ( M_PI/3)   * NR::translate(cx, cy);
414     NR::Matrix flip_x        = NR::translate(-cx, -cy) * NR::scale (-1, 1)      * NR::translate(cx, cy);
415     NR::Matrix flip_y        = NR::translate(-cx, -cy) * NR::scale (1, -1)      * NR::translate(cx, cy);
418     // Create tile with required symmetry
419     const double cos60 = cos(M_PI/3);
420     const double sin60 = sin(M_PI/3);
421     const double cos30 = cos(M_PI/6);
422     const double sin30 = sin(M_PI/6);
424     switch (type) {
426     case TILE_P1:
427         return d_s_r * rect_translate;
428         break;
430     case TILE_P2:
431         if (i % 2 == 0) {
432             return d_s_r * rect_translate;
433         } else {
434             return d_s_r * rotate_180_c * rect_translate;
435         }
436         break;
438     case TILE_PM:
439         if (i % 2 == 0) {
440             return d_s_r * rect_translate;
441         } else {
442             return d_s_r * flip_x * rect_translate;
443         }
444         break;
446     case TILE_PG:
447         if (j % 2 == 0) {
448             return d_s_r * rect_translate;
449         } else {
450             return d_s_r * flip_x * rect_translate;
451         }
452         break;
454     case TILE_CM:
455         if ((i + j) % 2 == 0) {
456             return d_s_r * rect_translate;
457         } else {
458             return d_s_r * flip_x * rect_translate;
459         }
460         break;
462     case TILE_PMM:
463         if (j % 2 == 0) {
464             if (i % 2 == 0) {
465                 return d_s_r * rect_translate;
466             } else {
467                 return d_s_r * flip_x * rect_translate;
468             }
469         } else {
470             if (i % 2 == 0) {
471                 return d_s_r * flip_y * rect_translate;
472             } else {
473                 return d_s_r * flip_x * flip_y * rect_translate;
474             }
475         }
476         break;
478     case TILE_PMG:
479         if (j % 2 == 0) {
480             if (i % 2 == 0) {
481                 return d_s_r * rect_translate;
482             } else {
483                 return d_s_r * rotate_180_c * rect_translate;
484             }
485         } else {
486             if (i % 2 == 0) {
487                 return d_s_r * flip_y * rect_translate;
488             } else {
489                 return d_s_r * rotate_180_c * flip_y * rect_translate;
490             }
491         }
492         break;
494     case TILE_PGG:
495         if (j % 2 == 0) {
496             if (i % 2 == 0) {
497                 return d_s_r * rect_translate;
498             } else {
499                 return d_s_r * flip_y * rect_translate;
500             }
501         } else {
502             if (i % 2 == 0) {
503                 return d_s_r * rotate_180_c * rect_translate;
504             } else {
505                 return d_s_r * rotate_180_c * flip_y * rect_translate;
506             }
507         }
508         break;
510     case TILE_CMM:
511         if (j % 4 == 0) {
512             if (i % 2 == 0) {
513                 return d_s_r * rect_translate;
514             } else {
515                 return d_s_r * flip_x * rect_translate;
516             }
517         } else if (j % 4 == 1) {
518             if (i % 2 == 0) {
519                 return d_s_r * flip_y * rect_translate;
520             } else {
521                 return d_s_r * flip_x * flip_y * rect_translate;
522             }
523         } else if (j % 4 == 2) {
524             if (i % 2 == 1) {
525                 return d_s_r * rect_translate;
526             } else {
527                 return d_s_r * flip_x * rect_translate;
528             }
529         } else {
530             if (i % 2 == 1) {
531                 return d_s_r * flip_y * rect_translate;
532             } else {
533                 return d_s_r * flip_x * flip_y * rect_translate;
534             }
535         }
536         break;
538     case TILE_P4:
539     {
540         NR::Matrix ori  (NR::translate ((w + h) * pow((i/2), shiftx_exp) + dx,  (h + w) * pow((j/2), shifty_exp) + dy));
541         NR::Matrix dia1 (NR::translate (w/2 + h/2, -h/2 + w/2));
542         NR::Matrix dia2 (NR::translate (-w/2 + h/2, h/2 + w/2));
543         if (j % 2 == 0) {
544             if (i % 2 == 0) {
545                 return d_s_r * ori;
546             } else {
547                 return d_s_r * rotate_m90_c * dia1 * ori;
548             }
549         } else {
550             if (i % 2 == 0) {
551                 return d_s_r * rotate_90_c * dia2 * ori;
552             } else {
553                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
554             }
555         }
556     }
557     break;
559     case TILE_P4M:
560     {
561         double max = MAX(w, h);
562         NR::Matrix ori (NR::translate ((max + max) * pow((i/4), shiftx_exp) + dx,  (max + max) * pow((j/2), shifty_exp) + dy));
563         NR::Matrix dia1 (NR::translate ( w/2 - h/2, h/2 - w/2));
564         NR::Matrix dia2 (NR::translate (-h/2 + w/2, w/2 - h/2));
565         if (j % 2 == 0) {
566             if (i % 4 == 0) {
567                 return d_s_r * ori;
568             } else if (i % 4 == 1) {
569                 return d_s_r * flip_y * rotate_m90_c * dia1 * ori;
570             } else if (i % 4 == 2) {
571                 return d_s_r * rotate_m90_c * dia1 * NR::translate (h, 0) * ori;
572             } else if (i % 4 == 3) {
573                 return d_s_r * flip_x * NR::translate (w, 0) * ori;
574             }
575         } else {
576             if (i % 4 == 0) {
577                 return d_s_r * flip_y * NR::translate(0, h) * ori;
578             } else if (i % 4 == 1) {
579                 return d_s_r * rotate_90_c * dia2 * NR::translate(0, h) * ori;
580             } else if (i % 4 == 2) {
581                 return d_s_r * flip_y * rotate_90_c * dia2 * NR::translate(h, 0) * NR::translate(0, h) * ori;
582             } else if (i % 4 == 3) {
583                 return d_s_r * flip_y * flip_x * NR::translate(w, 0) * NR::translate(0, h) * ori;
584             }
585         }
586     }
587     break;
589     case TILE_P4G:
590     {
591         double max = MAX(w, h);
592         NR::Matrix ori (NR::translate ((max + max) * pow((i/4), shiftx_exp) + dx,  (max + max) * pow(j, shifty_exp) + dy));
593         NR::Matrix dia1 (NR::translate ( w/2 + h/2, h/2 - w/2));
594         NR::Matrix dia2 (NR::translate (-h/2 + w/2, w/2 + h/2));
595         if (((i/4) + j) % 2 == 0) {
596             if (i % 4 == 0) {
597                 return d_s_r * ori;
598             } else if (i % 4 == 1) {
599                 return d_s_r * rotate_m90_c * dia1 * ori;
600             } else if (i % 4 == 2) {
601                 return d_s_r * rotate_90_c * dia2 * ori;
602             } else if (i % 4 == 3) {
603                 return d_s_r * rotate_180_c * dia1 * dia2 * ori;
604             }
605         } else {
606             if (i % 4 == 0) {
607                 return d_s_r * flip_y * NR::translate (0, h) * ori;
608             } else if (i % 4 == 1) {
609                 return d_s_r * flip_y * rotate_m90_c * dia1 * NR::translate (-h, 0) * ori;
610             } else if (i % 4 == 2) {
611                 return d_s_r * flip_y * rotate_90_c * dia2 * NR::translate (h, 0) * ori;
612             } else if (i % 4 == 3) {
613                 return d_s_r * flip_x * NR::translate (w, 0) * ori;
614             }
615         }
616     }
617     break;
619     case TILE_P3:
620     {
621         double width;
622         double height;
623         NR::Matrix dia1;
624         NR::Matrix dia2;
625         if (w > h) {
626             width  = w + w * cos60;
627             height = 2 * w * sin60;
628             dia1 = NR::Matrix (NR::translate (w/2 + w/2 * cos60, -(w/2 * sin60)));
629             dia2 = dia1 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60)));
630         } else {
631             width = h * cos (M_PI/6);
632             height = h;
633             dia1 = NR::Matrix (NR::translate (h/2 * cos30, -(h/2 * sin30)));
634             dia2 = dia1 * NR::Matrix (NR::translate (0, h/2));
635         }
636         NR::Matrix ori (NR::translate (width * pow((2*(i/3) + j%2), shiftx_exp) + dx,  (height/2) * pow(j, shifty_exp) + dy));
637         if (i % 3 == 0) {
638             return d_s_r * ori;
639         } else if (i % 3 == 1) {
640             return d_s_r * rotate_m120_c * dia1 * ori;
641         } else if (i % 3 == 2) {
642             return d_s_r * rotate_120_c * dia2 * ori;
643         }
644     }
645     break;
647     case TILE_P31M:
648     {
649         NR::Matrix ori;
650         NR::Matrix dia1;
651         NR::Matrix dia2;
652         NR::Matrix dia3;
653         NR::Matrix dia4;
654         if (w > h) {
655             ori = NR::Matrix(NR::translate (w * pow((i/6) + 0.5*(j%2), shiftx_exp) + dx,  (w * cos30) * pow(j, shifty_exp) + dy));
656             dia1 = NR::Matrix (NR::translate (0, h/2) * NR::translate (w/2, 0) * NR::translate (w/2 * cos60, -w/2 * sin60) * NR::translate (-h/2 * cos30, -h/2 * sin30) );
657             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
658             dia3 = dia2 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
659             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
660         } else {
661             ori  = NR::Matrix (NR::translate (2*h * cos30  * pow((i/6 + 0.5*(j%2)), shiftx_exp) + dx,  (2*h - h * sin30) * pow(j, shifty_exp) + dy));
662             dia1 = NR::Matrix (NR::translate (0, -h/2) * NR::translate (h/2 * cos30, h/2 * sin30));
663             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
664             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
665             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
666         }
667         if (i % 6 == 0) {
668             return d_s_r * ori;
669         } else if (i % 6 == 1) {
670             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
671         } else if (i % 6 == 2) {
672             return d_s_r * rotate_m120_c * dia2 * ori;
673         } else if (i % 6 == 3) {
674             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
675         } else if (i % 6 == 4) {
676             return d_s_r * rotate_120_c * dia4 * ori;
677         } else if (i % 6 == 5) {
678             return d_s_r * flip_y * NR::translate(0, h) * ori;
679         }
680     }
681     break;
683     case TILE_P3M1:
684     {
685         double width;
686         double height;
687         NR::Matrix dia1;
688         NR::Matrix dia2;
689         NR::Matrix dia3;
690         NR::Matrix dia4;
691         if (w > h) {
692             width = w + w * cos60;
693             height = 2 * w * sin60;
694             dia1 = NR::Matrix (NR::translate (0, h/2) * NR::translate (w/2, 0) * NR::translate (w/2 * cos60, -w/2 * sin60) * NR::translate (-h/2 * cos30, -h/2 * sin30) );
695             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
696             dia3 = dia2 * NR::Matrix (NR::translate (0, 2 * (w/2 * sin60 - h/2 * sin30)));
697             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
698         } else {
699             width = 2 * h * cos (M_PI/6);
700             height = 2 * h;
701             dia1 = NR::Matrix (NR::translate (0, -h/2) * NR::translate (h/2 * cos30, h/2 * sin30));
702             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, h * sin30));
703             dia3 = dia2 * NR::Matrix (NR::translate (0, h/2));
704             dia4 = dia3 * NR::Matrix (NR::translate (-h * cos30, h * sin30));
705         }
706         NR::Matrix ori (NR::translate (width * pow((2*(i/6) + j%2), shiftx_exp) + dx,  (height/2) * pow(j, shifty_exp) + dy));
707         if (i % 6 == 0) {
708             return d_s_r * ori;
709         } else if (i % 6 == 1) {
710             return d_s_r * flip_y * rotate_m120_c * dia1 * ori;
711         } else if (i % 6 == 2) {
712             return d_s_r * rotate_m120_c * dia2 * ori;
713         } else if (i % 6 == 3) {
714             return d_s_r * flip_y * rotate_120_c * dia3 * ori;
715         } else if (i % 6 == 4) {
716             return d_s_r * rotate_120_c * dia4 * ori;
717         } else if (i % 6 == 5) {
718             return d_s_r * flip_y * NR::translate(0, h) * ori;
719         }
720     }
721     break;
723     case TILE_P6:
724     {
725         NR::Matrix ori;
726         NR::Matrix dia1;
727         NR::Matrix dia2;
728         NR::Matrix dia3;
729         NR::Matrix dia4;
730         NR::Matrix dia5;
731         if (w > h) {
732             ori = NR::Matrix(NR::translate (w * pow((2*(i/6) + (j%2)), shiftx_exp) + dx,  (2*w * sin60) * pow(j, shifty_exp) + dy));
733             dia1 = NR::Matrix (NR::translate (w/2 * cos60, -w/2 * sin60));
734             dia2 = dia1 * NR::Matrix (NR::translate (w/2, 0));
735             dia3 = dia2 * NR::Matrix (NR::translate (w/2 * cos60, w/2 * sin60));
736             dia4 = dia3 * NR::Matrix (NR::translate (-w/2 * cos60, w/2 * sin60));
737             dia5 = dia4 * NR::Matrix (NR::translate (-w/2, 0));
738         } else {
739             ori = NR::Matrix(NR::translate (2*h * cos30 * pow((i/6 + 0.5*(j%2)), shiftx_exp) + dx,  (h + h * sin30) * pow(j, shifty_exp) + dy));
740             dia1 = NR::Matrix (NR::translate (-w/2, -h/2) * NR::translate (h/2 * cos30, -h/2 * sin30) * NR::translate (w/2 * cos60, w/2 * sin60));
741             dia2 = dia1 * NR::Matrix (NR::translate (-w/2 * cos60, -w/2 * sin60) * NR::translate (h/2 * cos30, -h/2 * sin30) * NR::translate (h/2 * cos30, h/2 * sin30) * NR::translate (-w/2 * cos60, w/2 * sin60));
742             dia3 = dia2 * NR::Matrix (NR::translate (w/2 * cos60, -w/2 * sin60) * NR::translate (h/2 * cos30, h/2 * sin30) * NR::translate (-w/2, h/2));
743             dia4 = dia3 * dia1.inverse();
744             dia5 = dia3 * dia2.inverse();
745         }
746         if (i % 6 == 0) {
747             return d_s_r * ori;
748         } else if (i % 6 == 1) {
749             return d_s_r * rotate_m60_c * dia1 * ori;
750         } else if (i % 6 == 2) {
751             return d_s_r * rotate_m120_c * dia2 * ori;
752         } else if (i % 6 == 3) {
753             return d_s_r * rotate_180_c * dia3 * ori;
754         } else if (i % 6 == 4) {
755             return d_s_r * rotate_120_c * dia4 * ori;
756         } else if (i % 6 == 5) {
757             return d_s_r * rotate_60_c * dia5 * ori;
758         }
759     }
760     break;
762     case TILE_P6M:
763     {
765         NR::Matrix ori;
766         NR::Matrix dia1, dia2, dia3, dia4, dia5, dia6, dia7, dia8, dia9, dia10;
767         if (w > h) {
768             ori = NR::Matrix(NR::translate (w * pow((2*(i/12) + (j%2)), shiftx_exp) + dx,  (2*w * sin60) * pow(j, shifty_exp) + dy));
769             dia1 = NR::Matrix (NR::translate (w/2, h/2) * NR::translate (-w/2 * cos60, -w/2 * sin60) * NR::translate (-h/2 * cos30, h/2 * sin30));
770             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, -h * sin30));
771             dia3 = dia2 * NR::Matrix (NR::translate (-h/2 * cos30, h/2 * sin30) * NR::translate (w * cos60, 0) * NR::translate (-h/2 * cos30, -h/2 * sin30));
772             dia4 = dia3 * NR::Matrix (NR::translate (h * cos30, h * sin30));
773             dia5 = dia4 * NR::Matrix (NR::translate (-h/2 * cos30, -h/2 * sin30) * NR::translate (-w/2 * cos60, w/2 * sin60) * NR::translate (w/2, -h/2));
774             dia6 = dia5 * NR::Matrix (NR::translate (0, h));
775             dia7 = dia6 * dia1.inverse();
776             dia8 = dia6 * dia2.inverse();
777             dia9 = dia6 * dia3.inverse();
778             dia10 = dia6 * dia4.inverse();
779         } else {
780             ori = NR::Matrix(NR::translate (4*h * cos30 * pow((i/12 + 0.5*(j%2)), shiftx_exp) + dx,  (2*h  + 2*h * sin30) * pow(j, shifty_exp) + dy));
781             dia1 = NR::Matrix (NR::translate (-w/2, -h/2) * NR::translate (h/2 * cos30, -h/2 * sin30) * NR::translate (w/2 * cos60, w/2 * sin60));
782             dia2 = dia1 * NR::Matrix (NR::translate (h * cos30, -h * sin30));
783             dia3 = dia2 * NR::Matrix (NR::translate (-w/2 * cos60, -w/2 * sin60) * NR::translate (h * cos30, 0) * NR::translate (-w/2 * cos60, w/2 * sin60));
784             dia4 = dia3 * NR::Matrix (NR::translate (h * cos30, h * sin30));
785             dia5 = dia4 * NR::Matrix (NR::translate (w/2 * cos60, -w/2 * sin60) * NR::translate (h/2 * cos30, h/2 * sin30) * NR::translate (-w/2, h/2));
786             dia6 = dia5 * NR::Matrix (NR::translate (0, h));
787             dia7 = dia6 * dia1.inverse();
788             dia8 = dia6 * dia2.inverse();
789             dia9 = dia6 * dia3.inverse();
790             dia10 = dia6 * dia4.inverse();
791         }
792         if (i % 12 == 0) {
793             return d_s_r * ori;
794         } else if (i % 12 == 1) {
795             return d_s_r * flip_y * rotate_m60_c * dia1 * ori;
796         } else if (i % 12 == 2) {
797             return d_s_r * rotate_m60_c * dia2 * ori;
798         } else if (i % 12 == 3) {
799             return d_s_r * flip_y * rotate_m120_c * dia3 * ori;
800         } else if (i % 12 == 4) {
801             return d_s_r * rotate_m120_c * dia4 * ori;
802         } else if (i % 12 == 5) {
803             return d_s_r * flip_x * dia5 * ori;
804         } else if (i % 12 == 6) {
805             return d_s_r * flip_x * flip_y * dia6 * ori;
806         } else if (i % 12 == 7) {
807             return d_s_r * flip_y * rotate_120_c * dia7 * ori;
808         } else if (i % 12 == 8) {
809             return d_s_r * rotate_120_c * dia8 * ori;
810         } else if (i % 12 == 9) {
811             return d_s_r * flip_y * rotate_60_c * dia9 * ori;
812         } else if (i % 12 == 10) {
813             return d_s_r * rotate_60_c * dia10 * ori;
814         } else if (i % 12 == 11) {
815             return d_s_r * flip_y * NR::translate (0, h) * ori;
816         }
817     }
818     break;
820     default:
821         break;
822     }
824     return NR::identity();
827 static bool
828 clonetiler_is_a_clone_of (SPObject *tile, SPObject *obj)
830     char *id_href = NULL;
832     if (obj) {
833         Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
834         id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
835     }
837     if (SP_IS_USE(tile) &&
838         SP_OBJECT_REPR(tile)->attribute("xlink:href") &&
839         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("xlink:href"))) &&
840         SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of") &&
841         (!id_href || !strcmp(id_href, SP_OBJECT_REPR(tile)->attribute("inkscape:tiled-clone-of"))))
842     {
843         if (id_href)
844             g_free (id_href);
845         return true;
846     } else {
847         if (id_href)
848             g_free (id_href);
849         return false;
850     }
853 static NRArena const *trace_arena = NULL;
854 static unsigned trace_visionkey;
855 static NRArenaItem *trace_root;
856 static gdouble trace_zoom;
858 static void
859 clonetiler_trace_hide_tiled_clones_recursively (SPObject *from)
861     if (!trace_arena)
862         return;
864     for (SPObject *o = sp_object_first_child(from); o != NULL; o = SP_OBJECT_NEXT(o)) {
865         if (SP_IS_ITEM(o) && clonetiler_is_a_clone_of (o, NULL))
866             sp_item_invoke_hide(SP_ITEM(o), trace_visionkey); // FIXME: hide each tiled clone's original too!
867         clonetiler_trace_hide_tiled_clones_recursively (o);
868     }
871 static void
872 clonetiler_trace_setup (SPDocument *doc, gdouble zoom, SPItem *original)
874     trace_arena = NRArena::create();
875     /* Create ArenaItem and set transform */
876     trace_visionkey = sp_item_display_key_new(1);
877     trace_root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT (doc)),
878                                       (NRArena *) trace_arena, trace_visionkey, SP_ITEM_SHOW_DISPLAY);
880     // hide the (current) original and any tiled clones, we only want to pick the background
881     sp_item_invoke_hide(original, trace_visionkey);
882     clonetiler_trace_hide_tiled_clones_recursively (SP_OBJECT(SP_DOCUMENT_ROOT (doc)));
884     sp_document_root (doc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
885     sp_document_ensure_up_to_date(doc);
887     trace_zoom = zoom;
890 static guint32
891 clonetiler_trace_pick (NR::Rect box)
893     if (!trace_arena)
894         return 0;
896     NR::Matrix t(NR::scale(trace_zoom, trace_zoom));
897     nr_arena_item_set_transform(trace_root, &t);
898     NRGC gc(NULL);
899     gc.transform.set_identity();
900     nr_arena_item_invoke_update( trace_root, NULL, &gc,
901                                  NR_ARENA_ITEM_STATE_ALL,
902                                  NR_ARENA_ITEM_STATE_NONE );
904     /* Item integer bbox in points */
905     NRRectL ibox;
906     ibox.x0 = (int) floor(trace_zoom * box.min()[NR::X] + 0.5);
907     ibox.y0 = (int) floor(trace_zoom * box.min()[NR::Y] + 0.5);
908     ibox.x1 = (int) floor(trace_zoom * box.max()[NR::X] + 0.5);
909     ibox.y1 = (int) floor(trace_zoom * box.max()[NR::Y] + 0.5);
911     /* Find visible area */
912     int width = ibox.x1 - ibox.x0;
913     int height = ibox.y1 - ibox.y0;
915     /* Set up pixblock */
916     guchar *px = g_new(guchar, 4 * width * height);
918     if (px == NULL) {
919         return 0; // buffer is too big or too small, cannot pick, so return 0
920     }
922     memset(px, 0x00, 4 * width * height);
924     /* Render */
925     NRPixBlock pb;
926     nr_pixblock_setup_extern( &pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
927                               ibox.x0, ibox.y0, ibox.x1, ibox.y1,
928                               px, 4 * width, FALSE, FALSE );
929     nr_arena_item_invoke_render(NULL, trace_root, &ibox, &pb,
930                                  NR_ARENA_ITEM_RENDER_NO_CACHE );
932     double R = 0, G = 0, B = 0, A = 0;
933     double count = 0;
934     double weight = 0;
936     for (int y = ibox.y0; y < ibox.y1; y++) {
937         const unsigned char *s = NR_PIXBLOCK_PX (&pb) + (y - ibox.y0) * pb.rs;
938         for (int x = ibox.x0; x < ibox.x1; x++) {
939             count += 1;
940             weight += s[3] / 255.0;
941             R += s[0] / 255.0;
942             G += s[1] / 255.0;
943             B += s[2] / 255.0;
944             A += s[3] / 255.0;
945             s += 4;
946         }
947     }
949     nr_pixblock_release(&pb);
951     R = R / weight;
952     G = G / weight;
953     B = B / weight;
954     A = A / count;
956     R = CLAMP (R, 0.0, 1.0);
957     G = CLAMP (G, 0.0, 1.0);
958     B = CLAMP (B, 0.0, 1.0);
959     A = CLAMP (A, 0.0, 1.0);
961     return SP_RGBA32_F_COMPOSE (R, G, B, A);
964 static void
965 clonetiler_trace_finish ()
967     if (trace_arena) {
968         ((NRObject *) trace_arena)->unreference();
969         trace_arena = NULL;
970     }
973 static void
974 clonetiler_unclump( GtkWidget */*widget*/, void * )
976     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
977     if (desktop == NULL)
978         return;
980     Inkscape::Selection *selection = sp_desktop_selection(desktop);
982     // check if something is selected
983     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
984         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump."));
985         return;
986     }
988     SPObject *obj = SP_OBJECT(selection->singleItem());
989     SPObject *parent = SP_OBJECT_PARENT (obj);
991     GSList *to_unclump = NULL; // not including the original
993     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
994         if (clonetiler_is_a_clone_of (child, obj)) {
995             to_unclump = g_slist_prepend (to_unclump, child);
996         }
997     }
999     sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1001     unclump (to_unclump);
1003     g_slist_free (to_unclump);
1005     sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
1006                       _("Unclump tiled clones"));
1009 static guint
1010 clonetiler_number_of_clones (SPObject *obj)
1012     SPObject *parent = SP_OBJECT_PARENT (obj);
1014     guint n = 0;
1016     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
1017         if (clonetiler_is_a_clone_of (child, obj)) {
1018             n ++;
1019         }
1020     }
1022     return n;
1025 static void
1026 clonetiler_remove( GtkWidget */*widget*/, void *, bool do_undo = true )
1028     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1029     if (desktop == NULL)
1030         return;
1032     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1034     // check if something is selected
1035     if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
1036         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove."));
1037         return;
1038     }
1040     SPObject *obj = SP_OBJECT(selection->singleItem());
1041     SPObject *parent = SP_OBJECT_PARENT (obj);
1043 // remove old tiling
1044     GSList *to_delete = NULL;
1045     for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
1046         if (clonetiler_is_a_clone_of (child, obj)) {
1047             to_delete = g_slist_prepend (to_delete, child);
1048         }
1049     }
1050     for (GSList *i = to_delete; i; i = i->next) {
1051         SP_OBJECT(i->data)->deleteObject();
1052     }
1053     g_slist_free (to_delete);
1055     clonetiler_change_selection (NULL, selection, dlg);
1057     if (do_undo)
1058         sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
1059                           _("Delete tiled clones"));
1062 static NR::Rect
1063 transform_rect(NR::Rect const &r, NR::Matrix const &m)
1065     using NR::X;
1066     using NR::Y;
1067     NR::Point const p1 = r.corner(1) * m;
1068     NR::Point const p2 = r.corner(2) * m;
1069     NR::Point const p3 = r.corner(3) * m;
1070     NR::Point const p4 = r.corner(4) * m;
1071     return NR::Rect(
1072         NR::Point(
1073             std::min(std::min(p1[X], p2[X]), std::min(p3[X], p4[X])),
1074             std::min(std::min(p1[Y], p2[Y]), std::min(p3[Y], p4[Y]))),
1075         NR::Point(
1076             std::max(std::max(p1[X], p2[X]), std::max(p3[X], p4[X])),
1077             std::max(std::max(p1[Y], p2[Y]), std::max(p3[Y], p4[Y]))));
1080 /**
1081 Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same
1082 probability of being displaced.
1083  */
1084 static double
1085 randomize01 (double val, double rand)
1087     double base = MIN (val - rand, 1 - 2*rand);
1088     if (base < 0) base = 0;
1089     val = base + g_random_double_range (0, MIN (2 * rand, 1 - base));
1090     return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case...
1094 static void
1095 clonetiler_apply( GtkWidget */*widget*/, void * )
1097     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1098     if (desktop == NULL)
1099         return;
1101     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1103     // check if something is selected
1104     if (selection->isEmpty()) {
1105         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone."));
1106         return;
1107     }
1109     // Check if more than one object is selected.
1110     if (g_slist_length((GSList *) selection->itemList()) > 1) {
1111         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>."));
1112         return;
1113     }
1115     // set "busy" cursor
1116     desktop->setWaitingCursor();
1118     // set statusbar text
1119     GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
1120     gtk_label_set_markup (GTK_LABEL(status), _("<small>Creating tiled clones...</small>"));
1121     gtk_widget_queue_draw(GTK_WIDGET(status));
1122     gdk_window_process_all_updates();
1124     SPObject *obj = SP_OBJECT(selection->singleItem());
1125     Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
1126     const char *id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
1127     SPObject *parent = SP_OBJECT_PARENT (obj);
1129     clonetiler_remove (NULL, NULL, false);
1131     double shiftx_per_i = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shiftx_per_i", 0, -10000, 10000);
1132     double shifty_per_i = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shifty_per_i", 0, -10000, 10000);
1133     double shiftx_per_j = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shiftx_per_j", 0, -10000, 10000);
1134     double shifty_per_j = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shifty_per_j", 0, -10000, 10000);
1135     double shiftx_rand  = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shiftx_rand", 0, 0, 1000);
1136     double shifty_rand  = 0.01 * prefs_get_double_attribute_limited (prefs_path, "shifty_rand", 0, 0, 1000);
1137     double shiftx_exp   =        prefs_get_double_attribute_limited (prefs_path, "shiftx_exp",   1, 0, 10);
1138     double shifty_exp   =        prefs_get_double_attribute_limited (prefs_path, "shifty_exp", 1, 0, 10);
1139     int    shiftx_alternate =    prefs_get_int_attribute (prefs_path, "shiftx_alternate", 0);
1140     int    shifty_alternate =    prefs_get_int_attribute (prefs_path, "shifty_alternate", 0);
1141     int    shiftx_cumulate  =    prefs_get_int_attribute (prefs_path, "shiftx_cumulate", 0);
1142     int    shifty_cumulate  =    prefs_get_int_attribute (prefs_path, "shifty_cumulate", 0);
1143     int    shiftx_excludew  =    prefs_get_int_attribute (prefs_path, "shiftx_excludew", 0);
1144     int    shifty_excludeh  =    prefs_get_int_attribute (prefs_path, "shifty_excludeh", 0);
1146     double scalex_per_i = 0.01 * prefs_get_double_attribute_limited (prefs_path, "scalex_per_i", 0, -100, 1000);
1147     double scaley_per_i = 0.01 * prefs_get_double_attribute_limited (prefs_path, "scaley_per_i", 0, -100, 1000);
1148     double scalex_per_j = 0.01 * prefs_get_double_attribute_limited (prefs_path, "scalex_per_j", 0, -100, 1000);
1149     double scaley_per_j = 0.01 * prefs_get_double_attribute_limited (prefs_path, "scaley_per_j", 0, -100, 1000);
1150     double scalex_rand  = 0.01 * prefs_get_double_attribute_limited (prefs_path, "scalex_rand",  0, 0, 1000);
1151     double scaley_rand  = 0.01 * prefs_get_double_attribute_limited (prefs_path, "scaley_rand",  0, 0, 1000);
1152     double scalex_exp   =        prefs_get_double_attribute_limited (prefs_path, "scalex_exp",   1, 0, 10);
1153     double scaley_exp   =        prefs_get_double_attribute_limited (prefs_path, "scaley_exp",   1, 0, 10);
1154     double scalex_log       =    prefs_get_double_attribute_limited (prefs_path, "scalex_log",   0, 0, 10);
1155     double scaley_log       =    prefs_get_double_attribute_limited (prefs_path, "scaley_log",   0, 0, 10);
1156     int    scalex_alternate =    prefs_get_int_attribute (prefs_path, "scalex_alternate", 0);
1157     int    scaley_alternate =    prefs_get_int_attribute (prefs_path, "scaley_alternate", 0);
1158     int    scalex_cumulate  =    prefs_get_int_attribute (prefs_path, "scalex_cumulate", 0);
1159     int    scaley_cumulate  =    prefs_get_int_attribute (prefs_path, "scaley_cumulate", 0);
1161     double rotate_per_i =        prefs_get_double_attribute_limited (prefs_path, "rotate_per_i", 0, -180, 180);
1162     double rotate_per_j =        prefs_get_double_attribute_limited (prefs_path, "rotate_per_j", 0, -180, 180);
1163     double rotate_rand =  0.01 * prefs_get_double_attribute_limited (prefs_path, "rotate_rand", 0, 0, 100);
1164     int    rotate_alternatei   = prefs_get_int_attribute (prefs_path, "rotate_alternatei", 0);
1165     int    rotate_alternatej   = prefs_get_int_attribute (prefs_path, "rotate_alternatej", 0);
1166     int    rotate_cumulatei    = prefs_get_int_attribute (prefs_path, "rotate_cumulatei", 0);
1167     int    rotate_cumulatej    = prefs_get_int_attribute (prefs_path, "rotate_cumulatej", 0);
1169     double blur_per_i =   0.01 * prefs_get_double_attribute_limited (prefs_path, "blur_per_i", 0, 0, 100);
1170     double blur_per_j =   0.01 * prefs_get_double_attribute_limited (prefs_path, "blur_per_j", 0, 0, 100);
1171     int    blur_alternatei =     prefs_get_int_attribute (prefs_path, "blur_alternatei", 0);
1172     int    blur_alternatej =     prefs_get_int_attribute (prefs_path, "blur_alternatej", 0);
1173     double blur_rand =    0.01 * prefs_get_double_attribute_limited (prefs_path, "blur_rand", 0, 0, 100);
1175     double opacity_per_i = 0.01 * prefs_get_double_attribute_limited (prefs_path, "opacity_per_i", 0, 0, 100);
1176     double opacity_per_j = 0.01 * prefs_get_double_attribute_limited (prefs_path, "opacity_per_j", 0, 0, 100);
1177     int    opacity_alternatei =   prefs_get_int_attribute (prefs_path, "opacity_alternatei", 0);
1178     int    opacity_alternatej =   prefs_get_int_attribute (prefs_path, "opacity_alternatej", 0);
1179     double opacity_rand =  0.01 * prefs_get_double_attribute_limited (prefs_path, "opacity_rand", 0, 0, 100);
1181     const gchar *initial_color =     prefs_get_string_attribute (prefs_path, "initial_color");
1182     double hue_per_j =        0.01 * prefs_get_double_attribute_limited (prefs_path, "hue_per_j", 0, -100, 100);
1183     double hue_per_i =        0.01 * prefs_get_double_attribute_limited (prefs_path, "hue_per_i", 0, -100, 100);
1184     double hue_rand  =        0.01 * prefs_get_double_attribute_limited (prefs_path, "hue_rand", 0, 0, 100);
1185     double saturation_per_j = 0.01 * prefs_get_double_attribute_limited (prefs_path, "saturation_per_j", 0, -100, 100);
1186     double saturation_per_i = 0.01 * prefs_get_double_attribute_limited (prefs_path, "saturation_per_i", 0, -100, 100);
1187     double saturation_rand =  0.01 * prefs_get_double_attribute_limited (prefs_path, "saturation_rand", 0, 0, 100);
1188     double lightness_per_j =  0.01 * prefs_get_double_attribute_limited (prefs_path, "lightness_per_j", 0, -100, 100);
1189     double lightness_per_i =  0.01 * prefs_get_double_attribute_limited (prefs_path, "lightness_per_i", 0, -100, 100);
1190     double lightness_rand =   0.01 * prefs_get_double_attribute_limited (prefs_path, "lightness_rand", 0, 0, 100);
1191     int    color_alternatej = prefs_get_int_attribute (prefs_path, "color_alternatej", 0);
1192     int    color_alternatei = prefs_get_int_attribute (prefs_path, "color_alternatei", 0);
1194     int type = prefs_get_int_attribute (prefs_path, "symmetrygroup", 0);
1196     int keepbbox = prefs_get_int_attribute (prefs_path, "keepbbox", 1);
1198     int imax = prefs_get_int_attribute (prefs_path, "imax", 2);
1199     int jmax = prefs_get_int_attribute (prefs_path, "jmax", 2);
1201     int fillrect = prefs_get_int_attribute (prefs_path, "fillrect", 0);
1202     double fillwidth = prefs_get_double_attribute_limited (prefs_path, "fillwidth", 50, 0, 1e6);
1203     double fillheight = prefs_get_double_attribute_limited (prefs_path, "fillheight", 50, 0, 1e6);
1205     int dotrace = prefs_get_int_attribute (prefs_path, "dotrace", 0);
1206     int pick = prefs_get_int_attribute (prefs_path, "pick", 0);
1207     int pick_to_presence = prefs_get_int_attribute (prefs_path, "pick_to_presence", 0);
1208     int pick_to_size = prefs_get_int_attribute (prefs_path, "pick_to_size", 0);
1209     int pick_to_color = prefs_get_int_attribute (prefs_path, "pick_to_color", 0);
1210     int pick_to_opacity = prefs_get_int_attribute (prefs_path, "pick_to_opacity", 0);
1211     double rand_picked = 0.01 * prefs_get_double_attribute_limited (prefs_path, "rand_picked", 0, 0, 100);
1212     int invert_picked = prefs_get_int_attribute (prefs_path, "invert_picked", 0);
1213     double gamma_picked = prefs_get_double_attribute_limited (prefs_path, "gamma_picked", 0, -10, 10);
1215     if (dotrace) {
1216         clonetiler_trace_setup (sp_desktop_document(desktop), 1.0, SP_ITEM (obj));
1217     }
1219     NR::Point center;
1220     double w;
1221     double h;
1222     double x0;
1223     double y0;
1225     if (keepbbox &&
1226         obj_repr->attribute("inkscape:tile-w") &&
1227         obj_repr->attribute("inkscape:tile-h") &&
1228         obj_repr->attribute("inkscape:tile-x0") &&
1229         obj_repr->attribute("inkscape:tile-y0") &&
1230         obj_repr->attribute("inkscape:tile-cx") &&
1231         obj_repr->attribute("inkscape:tile-cy")) {
1233         double cx = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cx", 0);
1234         double cy = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cy", 0);
1235         center = NR::Point (cx, cy);
1237         w = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-w", 0);
1238         h = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-h", 0);
1239         x0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-x0", 0);
1240         y0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-y0", 0);
1241     } else {
1242         int prefs_bbox = prefs_get_int_attribute("tools", "bounding_box", 0);
1243         SPItem::BBoxType bbox_type = (prefs_bbox ==0)? 
1244             SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
1245         boost::optional<NR::Rect> r = SP_ITEM(obj)->getBounds(sp_item_i2doc_affine(SP_ITEM(obj)),
1246                                                         bbox_type);
1247         if (r) {
1248             w = r->dimensions()[NR::X];
1249             h = r->dimensions()[NR::Y];
1250             x0 = r->min()[NR::X];
1251             y0 = r->min()[NR::Y];
1252             center = desktop->dt2doc(SP_ITEM(obj)->getCenter());
1254             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", center[NR::X]);
1255             sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", center[NR::Y]);
1256             sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
1257             sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
1258             sp_repr_set_svg_double(obj_repr, "inkscape:tile-x0", x0);
1259             sp_repr_set_svg_double(obj_repr, "inkscape:tile-y0", y0);
1260         } else {
1261             center = NR::Point(0, 0);
1262             w = h = 0;
1263             x0 = y0 = 0;
1264         }
1265     }
1267     NR::Point cur = NR::Point (0, 0);
1268     NR::Rect bbox_original = NR::Rect (NR::Point (x0, y0), NR::Point (x0 + w, y0 + h));
1269     double perimeter_original = (w + h)/4;
1271     // The integers i and j are reserved for tile column and row.
1272     // The doubles x and y are used for coordinates
1273     for (int i = 0;
1274          fillrect?
1275              (fabs(cur[NR::X]) < fillwidth && i < 200) // prevent "freezing" with too large fillrect, arbitrarily limit rows
1276              : (i < imax);
1277          i ++) {
1278         for (int j = 0;
1279              fillrect?
1280                  (fabs(cur[NR::Y]) < fillheight && j < 200) // prevent "freezing" with too large fillrect, arbitrarily limit cols
1281                  : (j < jmax);
1282              j ++) {
1284             // Note: We create a clone at 0,0 too, right over the original, in case our clones are colored
1286             // Get transform from symmetry, shift, scale, rotation
1287             NR::Matrix t = clonetiler_get_transform (type, i, j, center[NR::X], center[NR::Y], w, h,
1288                                                      shiftx_per_i,     shifty_per_i,
1289                                                      shiftx_per_j,     shifty_per_j,
1290                                                      shiftx_rand,      shifty_rand,
1291                                                      shiftx_exp,       shifty_exp,
1292                                                      shiftx_alternate, shifty_alternate,
1293                                                      shiftx_cumulate,  shifty_cumulate,
1294                                                      shiftx_excludew,  shifty_excludeh,
1295                                                      scalex_per_i,     scaley_per_i,
1296                                                      scalex_per_j,     scaley_per_j,
1297                                                      scalex_rand,      scaley_rand,
1298                                                      scalex_exp,       scaley_exp,
1299                                                      scalex_log,       scaley_log,
1300                                                      scalex_alternate, scaley_alternate,
1301                                                      scalex_cumulate,  scaley_cumulate,
1302                                                      rotate_per_i,     rotate_per_j,
1303                                                      rotate_rand,
1304                                                      rotate_alternatei, rotate_alternatej,
1305                                                      rotate_cumulatei,  rotate_cumulatej      );
1307             cur = center * t - center;
1308             if (fillrect) {
1309                 if ((cur[NR::X] > fillwidth) || (cur[NR::Y] > fillheight)) { // off limits
1310                     continue;
1311                 }
1312             }
1314             gchar color_string[32]; *color_string = 0;
1316             // Color tab
1317             if (initial_color) {
1318                 guint32 rgba = sp_svg_read_color (initial_color, 0x000000ff);
1319                 float hsl[3];
1320                 sp_color_rgb_to_hsl_floatv (hsl, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba));
1322                 double eff_i = (color_alternatei? (i%2) : (i));
1323                 double eff_j = (color_alternatej? (j%2) : (j));
1325                 hsl[0] += hue_per_i * eff_i + hue_per_j * eff_j + hue_rand * g_random_double_range (-1, 1);
1326                 double notused;
1327                 hsl[0] = modf( hsl[0], &notused ); // Restrict to 0-1
1328                 hsl[1] += saturation_per_i * eff_i + saturation_per_j * eff_j + saturation_rand * g_random_double_range (-1, 1);
1329                 hsl[1] = CLAMP (hsl[1], 0, 1);
1330                 hsl[2] += lightness_per_i * eff_i + lightness_per_j * eff_j + lightness_rand * g_random_double_range (-1, 1);
1331                 hsl[2] = CLAMP (hsl[2], 0, 1);
1333                 float rgb[3];
1334                 sp_color_hsl_to_rgb_floatv (rgb, hsl[0], hsl[1], hsl[2]);
1335                 sp_svg_write_color(color_string, sizeof(color_string), SP_RGBA32_F_COMPOSE(rgb[0], rgb[1], rgb[2], 1.0));
1336             }
1338             // Blur
1339             double blur = 0.0;
1340             {
1341             int eff_i = (blur_alternatei? (i%2) : (i));
1342             int eff_j = (blur_alternatej? (j%2) : (j));
1343             blur =  (blur_per_i * eff_i + blur_per_j * eff_j + blur_rand * g_random_double_range (-1, 1));
1344             blur = CLAMP (blur, 0, 1);
1345             }
1347             // Opacity
1348             double opacity = 1.0;
1349             {
1350             int eff_i = (opacity_alternatei? (i%2) : (i));
1351             int eff_j = (opacity_alternatej? (j%2) : (j));
1352             opacity = 1 - (opacity_per_i * eff_i + opacity_per_j * eff_j + opacity_rand * g_random_double_range (-1, 1));
1353             opacity = CLAMP (opacity, 0, 1);
1354             }
1356             // Trace tab
1357             if (dotrace) {
1358                 NR::Rect bbox_t = transform_rect (bbox_original, t);
1360                 guint32 rgba = clonetiler_trace_pick (bbox_t);
1361                 float r = SP_RGBA32_R_F(rgba);
1362                 float g = SP_RGBA32_G_F(rgba);
1363                 float b = SP_RGBA32_B_F(rgba);
1364                 float a = SP_RGBA32_A_F(rgba);
1366                 float hsl[3];
1367                 sp_color_rgb_to_hsl_floatv (hsl, r, g, b);
1369                 gdouble val = 0;
1370                 switch (pick) {
1371                 case PICK_COLOR:
1372                     val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max
1373                     break;
1374                 case PICK_OPACITY:
1375                     val = a;
1376                     break;
1377                 case PICK_R:
1378                     val = r;
1379                     break;
1380                 case PICK_G:
1381                     val = g;
1382                     break;
1383                 case PICK_B:
1384                     val = b;
1385                     break;
1386                 case PICK_H:
1387                     val = hsl[0];
1388                     break;
1389                 case PICK_S:
1390                     val = hsl[1];
1391                     break;
1392                 case PICK_L:
1393                     val = 1 - hsl[2];
1394                     break;
1395                 default:
1396                     break;
1397                 }
1399                 if (rand_picked > 0) {
1400                     val = randomize01 (val, rand_picked);
1401                     r = randomize01 (r, rand_picked);
1402                     g = randomize01 (g, rand_picked);
1403                     b = randomize01 (b, rand_picked);
1404                 }
1406                 if (gamma_picked != 0) {
1407                     double power;
1408                     if (gamma_picked > 0)
1409                         power = 1/(1 + fabs(gamma_picked));
1410                     else
1411                         power = 1 + fabs(gamma_picked);
1413                     val = pow (val, power);
1414                     r = pow (r, power);
1415                     g = pow (g, power);
1416                     b = pow (b, power);
1417                 }
1419                 if (invert_picked) {
1420                     val = 1 - val;
1421                     r = 1 - r;
1422                     g = 1 - g;
1423                     b = 1 - b;
1424                 }
1426                 val = CLAMP (val, 0, 1);
1427                 r = CLAMP (r, 0, 1);
1428                 g = CLAMP (g, 0, 1);
1429                 b = CLAMP (b, 0, 1);
1431                 // recompose tweaked color
1432                 rgba = SP_RGBA32_F_COMPOSE(r, g, b, a);
1434                 if (pick_to_presence) {
1435                     if (g_random_double_range (0, 1) > val) {
1436                         continue; // skip!
1437                     }
1438                 }
1439                 if (pick_to_size) {
1440                     t = NR::translate(-center[NR::X], -center[NR::Y]) * NR::scale (val, val) * NR::translate(center[NR::X], center[NR::Y]) * t;
1441                 }
1442                 if (pick_to_opacity) {
1443                     opacity *= val;
1444                 }
1445                 if (pick_to_color) {
1446                     sp_svg_write_color(color_string, sizeof(color_string), rgba);
1447                 }
1448             }
1450             if (opacity < 1e-6) { // invisibly transparent, skip
1451                     continue;
1452             }
1454             if (fabs(t[0]) + fabs (t[1]) + fabs(t[2]) + fabs(t[3]) < 1e-6) { // too small, skip
1455                     continue;
1456             }
1458             // Create the clone
1459             Inkscape::XML::Node *clone = obj_repr->document()->createElement("svg:use");
1460             clone->setAttribute("x", "0");
1461             clone->setAttribute("y", "0");
1462             clone->setAttribute("inkscape:tiled-clone-of", id_href);
1463             clone->setAttribute("xlink:href", id_href);
1465             NR::Point new_center;
1466             bool center_set = false;
1467             if (obj_repr->attribute("inkscape:transform-center-x") || obj_repr->attribute("inkscape:transform-center-y")) {
1468                 new_center = desktop->dt2doc(SP_ITEM(obj)->getCenter()) * t;
1469                 center_set = true;
1470             }
1472             gchar *affinestr=sp_svg_transform_write(t);
1473             clone->setAttribute("transform", affinestr);
1474             g_free(affinestr);
1476             if (opacity < 1.0) {
1477                 sp_repr_set_css_double(clone, "opacity", opacity);
1478             }
1480             if (*color_string) {
1481                 clone->setAttribute("fill", color_string);
1482                 clone->setAttribute("stroke", color_string);
1483             }
1485             // add the new clone to the top of the original's parent
1486             SP_OBJECT_REPR(parent)->appendChild(clone);
1488             if (blur > 0.0) {
1489                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1490                 double perimeter = perimeter_original * NR::expansion(t);
1491                 double radius = blur * perimeter;
1492                 // this is necessary for all newly added clones to have correct bboxes,
1493                 // otherwise filters won't work:
1494                 sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1495                 // it's hard to figure out exact width/height of the tile without having an object
1496                 // that we can take bbox of; however here we only need a lower bound so that blur
1497                 // margins are not too small, and the perimeter should work
1498                 SPFilter *constructed = new_filter_gaussian_blur(sp_desktop_document(desktop), radius, NR::expansion(t), NR::expansionX(t), NR::expansionY(t), perimeter, perimeter);
1499                 sp_style_set_property_url (clone_object, "filter", SP_OBJECT(constructed), false);
1500             }
1502             if (center_set) {
1503                 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1504                 if (clone_object && SP_IS_ITEM(clone_object)) {
1505                     clone_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1506                     SP_ITEM(clone_object)->setCenter(desktop->doc2dt(new_center));
1507                     clone_object->updateRepr();
1508                 }
1509             }
1511             Inkscape::GC::release(clone);
1512         }
1513         cur[NR::Y] = 0;
1514     }
1516     if (dotrace) {
1517         clonetiler_trace_finish ();
1518     }
1520     clonetiler_change_selection (NULL, selection, dlg);
1522     desktop->clearWaitingCursor();
1524     sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER,
1525                      _("Create tiled clones"));
1528 static GtkWidget *
1529 clonetiler_new_tab (GtkWidget *nb, const gchar *label)
1531     GtkWidget *l = gtk_label_new_with_mnemonic (label);
1532     GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN);
1533     gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN);
1534     gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l);
1535     return vb;
1538 static void
1539 clonetiler_checkbox_toggled (GtkToggleButton *tb, gpointer *data)
1541     const gchar *attr = (const gchar *) data;
1542     prefs_set_int_attribute (prefs_path, attr, gtk_toggle_button_get_active (tb));
1545 static GtkWidget *
1546 clonetiler_checkbox (GtkTooltips *tt, const char *tip, const char *attr)
1548     GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
1550     GtkWidget *b = gtk_check_button_new ();
1551     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, tip, NULL);
1553     int value = prefs_get_int_attribute (prefs_path, attr, 0);
1554     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(b), value);
1556     gtk_box_pack_end (GTK_BOX (hb), b, FALSE, TRUE, 0);
1557     gtk_signal_connect ( GTK_OBJECT (b), "clicked",
1558                          GTK_SIGNAL_FUNC (clonetiler_checkbox_toggled), (gpointer) attr);
1560     g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
1562     return hb;
1566 static void
1567 clonetiler_value_changed (GtkAdjustment *adj, gpointer data)
1569     const gchar *pref = (const gchar *) data;
1570     prefs_set_double_attribute (prefs_path, pref, adj->value);
1573 static GtkWidget *
1574 clonetiler_spinbox (GtkTooltips *tt, const char *tip, const char *attr, double lower, double upper, const gchar *suffix, bool exponent = false)
1576     GtkWidget *hb = gtk_hbox_new(FALSE, 0);
1578     {
1579         GtkObject *a;
1580         if (exponent)
1581             a = gtk_adjustment_new(1.0, lower, upper, 0.01, 0.05, 0.1);
1582         else
1583             a = gtk_adjustment_new(0.0, lower, upper, 0.1, 0.5, 2);
1585         GtkWidget *sb;
1586         if (exponent)
1587             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.01, 2);
1588         else
1589             sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.1, 1);
1591         gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, tip, NULL);
1592         gtk_entry_set_width_chars (GTK_ENTRY (sb), 4);
1593         gtk_box_pack_start (GTK_BOX (hb), sb, FALSE, FALSE, SB_MARGIN);
1595         double value = prefs_get_double_attribute_limited (prefs_path, attr, exponent? 1 : 0, lower, upper);
1596         gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
1597         gtk_signal_connect(GTK_OBJECT(a), "value_changed",
1598                            GTK_SIGNAL_FUNC(clonetiler_value_changed), (gpointer) attr);
1600         if (exponent)
1601             g_object_set_data (G_OBJECT(sb), "oneable", GINT_TO_POINTER(TRUE));
1602         else
1603             g_object_set_data (G_OBJECT(sb), "zeroable", GINT_TO_POINTER(TRUE));
1604     }
1606     {
1607         GtkWidget *l = gtk_label_new ("");
1608         gtk_label_set_markup (GTK_LABEL(l), suffix);
1609         gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0);
1610         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
1611     }
1613     return hb;
1616 static void
1617 clonetiler_symgroup_changed( GtkMenuItem */*item*/, gpointer data )
1619     gint group_new = GPOINTER_TO_INT (data);
1620     prefs_set_int_attribute ( prefs_path, "symmetrygroup", group_new );
1623 static void
1624 clonetiler_xy_changed (GtkAdjustment *adj, gpointer data)
1626     const gchar *pref = (const gchar *) data;
1627     prefs_set_int_attribute (prefs_path, pref, (int) floor(adj->value + 0.5));
1630 static void
1631 clonetiler_keep_bbox_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1633     prefs_set_int_attribute (prefs_path, "keepbbox", gtk_toggle_button_get_active (tb));
1636 static void
1637 clonetiler_pick_to (GtkToggleButton *tb, gpointer data)
1639     const gchar *pref = (const gchar *) data;
1640     prefs_set_int_attribute (prefs_path, pref, gtk_toggle_button_get_active (tb));
1644 static void
1645 clonetiler_reset_recursive (GtkWidget *w)
1647     if (w && GTK_IS_OBJECT(w)) {
1648         {
1649             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "zeroable"));
1650             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1651                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1652                 gtk_adjustment_set_value (a, 0);
1653             }
1654         }
1655         {
1656             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "oneable"));
1657             if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1658                 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1659                 gtk_adjustment_set_value (a, 1);
1660             }
1661         }
1662         {
1663             int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "uncheckable"));
1664             if (r && GTK_IS_TOGGLE_BUTTON(w)) { // checkbox
1665                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(w), FALSE);
1666             }
1667         }
1668     }
1670     if (GTK_IS_CONTAINER(w)) {
1671         GList *ch = gtk_container_get_children (GTK_CONTAINER(w));
1672         for (GList *i = ch; i != NULL; i = i->next) {
1673             clonetiler_reset_recursive (GTK_WIDGET(i->data));
1674         }
1675         g_list_free (ch);
1676     }
1679 static void
1680 clonetiler_reset( GtkWidget */*widget*/, void * )
1682     clonetiler_reset_recursive (dlg);
1685 static void
1686 clonetiler_table_attach (GtkWidget *table, GtkWidget *widget, float align, int row, int col)
1688     GtkWidget *a = gtk_alignment_new (align, 0, 0, 0);
1689     gtk_container_add(GTK_CONTAINER(a), widget);
1690     gtk_table_attach ( GTK_TABLE (table), a, col, col + 1, row, row + 1, (GtkAttachOptions)4, (GtkAttachOptions)0, 0, 0 );
1693 static GtkWidget *
1694 clonetiler_table_x_y_rand (int values)
1696     GtkWidget *table = gtk_table_new (values + 2, 5, FALSE);
1697     gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
1698     gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1699     gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1701     {
1702         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1704         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "clonetiler_per_row");
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 row:</small>"));
1709         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1711         clonetiler_table_attach (table, hb, 0, 1, 2);
1712     }
1714     {
1715         GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1717         GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "clonetiler_per_column");
1718         gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1720         GtkWidget *l = gtk_label_new ("");
1721         gtk_label_set_markup (GTK_LABEL(l), _("<small>Per column:</small>"));
1722         gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1724         clonetiler_table_attach (table, hb, 0, 1, 3);
1725     }
1727     {
1728         GtkWidget *l = gtk_label_new ("");
1729         gtk_label_set_markup (GTK_LABEL(l), _("<small>Randomize:</small>"));
1730         clonetiler_table_attach (table, l, 0, 1, 4);
1731     }
1733     return table;
1736 static void
1737 clonetiler_pick_switched( GtkToggleButton */*tb*/, gpointer data )
1739     guint v = GPOINTER_TO_INT (data);
1740     prefs_set_int_attribute (prefs_path, "pick", v);
1744 static void
1745 clonetiler_switch_to_create( GtkToggleButton */*tb*/, GtkWidget *dlg )
1747     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1748     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1750     if (rowscols) {
1751         gtk_widget_set_sensitive (rowscols, TRUE);
1752     }
1753     if (widthheight) {
1754         gtk_widget_set_sensitive (widthheight, FALSE);
1755     }
1757     prefs_set_int_attribute (prefs_path, "fillrect", 0);
1761 static void
1762 clonetiler_switch_to_fill( GtkToggleButton */*tb*/, GtkWidget *dlg )
1764     GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1765     GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1767     if (rowscols) {
1768         gtk_widget_set_sensitive (rowscols, FALSE);
1769     }
1770     if (widthheight) {
1771         gtk_widget_set_sensitive (widthheight, TRUE);
1772     }
1774     prefs_set_int_attribute (prefs_path, "fillrect", 1);
1780 static void
1781 clonetiler_fill_width_changed (GtkAdjustment *adj, GtkWidget *u)
1783     gdouble const raw_dist = adj->value;
1784     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1785     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1787     prefs_set_double_attribute (prefs_path, "fillwidth", pixels);
1790 static void
1791 clonetiler_fill_height_changed (GtkAdjustment *adj, GtkWidget *u)
1793     gdouble const raw_dist = adj->value;
1794     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1795     gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1797     prefs_set_double_attribute (prefs_path, "fillheight", pixels);
1801 static void
1802 clonetiler_do_pick_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1804     GtkWidget *vvb = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "dotrace");
1806     prefs_set_int_attribute (prefs_path, "dotrace", gtk_toggle_button_get_active (tb));
1808     if (vvb)
1809         gtk_widget_set_sensitive (vvb, gtk_toggle_button_get_active (tb));
1815 void
1816 clonetiler_dialog (void)
1818     if (!dlg)
1819     {
1820         gchar title[500];
1821         sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_CLONETILER), title);
1823         dlg = sp_window_new (title, TRUE);
1824         if (x == -1000 || y == -1000) {
1825             x = prefs_get_int_attribute (prefs_path, "x", -1000);
1826             y = prefs_get_int_attribute (prefs_path, "y", -1000);
1827         }
1829         if (w ==0 || h == 0) {
1830             w = prefs_get_int_attribute (prefs_path, "w", 0);
1831             h = prefs_get_int_attribute (prefs_path, "h", 0);
1832         }
1834 //        if (x<0) x=0;
1835 //        if (y<0) y=0;
1837         if (w && h) {
1838             gtk_window_resize ((GtkWindow *) dlg, w, h);
1839         }
1840         if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) {
1841             gtk_window_move ((GtkWindow *) dlg, x, y);
1843         } else {
1844             gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
1845         }
1848         sp_transientize (dlg);
1849         wd.win = dlg;
1850         wd.stop = 0;
1853         gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);
1855         gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (clonetiler_dialog_destroy), dlg);
1856         gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (clonetiler_dialog_delete), dlg);
1858         if (Inkscape::NSApplication::Application::getNewGui())
1859         {
1860             _shutdown_connection = Inkscape::NSApplication::Editor::connectShutdown (&on_delete);
1861             _dialogs_hidden_connection = Inkscape::NSApplication::Editor::connectDialogsHidden (sigc::bind (&on_dialog_hide, dlg));
1862             _dialogs_unhidden_connection = Inkscape::NSApplication::Editor::connectDialogsUnhidden (sigc::bind (&on_dialog_unhide, dlg));
1863             _desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::bind (&on_transientize, &wd));
1864         } else {
1865             g_signal_connect   ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (clonetiler_dialog_delete), dlg);
1866             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg);
1867             g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg);
1868             g_signal_connect   ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd);
1869         }
1871         GtkTooltips *tt = gtk_tooltips_new();
1873         GtkWidget *mainbox = gtk_vbox_new(FALSE, 4);
1874         gtk_container_set_border_width (GTK_CONTAINER (mainbox), 6);
1875         gtk_container_add (GTK_CONTAINER (dlg), mainbox);
1877         GtkWidget *nb = gtk_notebook_new ();
1878         gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0);
1881 // Symmetry
1882         {
1883             GtkWidget *vb = clonetiler_new_tab (nb, _("_Symmetry"));
1885             GtkWidget *om = gtk_option_menu_new ();
1886             /* TRANSLATORS: For the following 17 symmetry groups, see
1887              * http://www.bib.ulb.ac.be/coursmath/doc/17.htm (visual examples);
1888              * http://www.clarku.edu/~djoyce/wallpaper/seventeen.html (English vocabulary); or
1889              * http://membres.lycos.fr/villemingerard/Geometri/Sym1D.htm (French vocabulary).
1890              */
1891             gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), om, _("Select one of the 17 symmetry groups for the tiling"), NULL);
1892             gtk_box_pack_start (GTK_BOX (vb), om, FALSE, FALSE, SB_MARGIN);
1894             GtkWidget *m = gtk_menu_new ();
1895             int current = prefs_get_int_attribute (prefs_path, "symmetrygroup", 0);
1897             struct SymGroups {
1898                 int group;
1899                 gchar const *label;
1900             } const sym_groups[] = {
1901                 // TRANSLATORS: "translation" means "shift" / "displacement" here.
1902                 {TILE_P1, _("<b>P1</b>: simple translation")},
1903                 {TILE_P2, _("<b>P2</b>: 180&#176; rotation")},
1904                 {TILE_PM, _("<b>PM</b>: reflection")},
1905                 // TRANSLATORS: "glide reflection" is a reflection and a translation combined.
1906                 //  For more info, see http://mathforum.org/sum95/suzanne/symsusan.html
1907                 {TILE_PG, _("<b>PG</b>: glide reflection")},
1908                 {TILE_CM, _("<b>CM</b>: reflection + glide reflection")},
1909                 {TILE_PMM, _("<b>PMM</b>: reflection + reflection")},
1910                 {TILE_PMG, _("<b>PMG</b>: reflection + 180&#176; rotation")},
1911                 {TILE_PGG, _("<b>PGG</b>: glide reflection + 180&#176; rotation")},
1912                 {TILE_CMM, _("<b>CMM</b>: reflection + reflection + 180&#176; rotation")},
1913                 {TILE_P4, _("<b>P4</b>: 90&#176; rotation")},
1914                 {TILE_P4M, _("<b>P4M</b>: 90&#176; rotation + 45&#176; reflection")},
1915                 {TILE_P4G, _("<b>P4G</b>: 90&#176; rotation + 90&#176; reflection")},
1916                 {TILE_P3, _("<b>P3</b>: 120&#176; rotation")},
1917                 {TILE_P31M, _("<b>P31M</b>: reflection + 120&#176; rotation, dense")},
1918                 {TILE_P3M1, _("<b>P3M1</b>: reflection + 120&#176; rotation, sparse")},
1919                 {TILE_P6, _("<b>P6</b>: 60&#176; rotation")},
1920                 {TILE_P6M, _("<b>P6M</b>: reflection + 60&#176; rotation")},
1921             };
1923             for (unsigned j = 0; j < G_N_ELEMENTS(sym_groups); ++j) {
1924                 SymGroups const &sg = sym_groups[j];
1926                 GtkWidget *l = gtk_label_new ("");
1927                 gtk_label_set_markup (GTK_LABEL(l), sg.label);
1928                 gtk_misc_set_alignment (GTK_MISC(l), 0, 0.5);
1930                 GtkWidget *item = gtk_menu_item_new ();
1931                 gtk_container_add (GTK_CONTAINER (item), l);
1933                 gtk_signal_connect ( GTK_OBJECT (item), "activate",
1934                                      GTK_SIGNAL_FUNC (clonetiler_symgroup_changed),
1935                                      GINT_TO_POINTER (sg.group) );
1937                 gtk_menu_append (GTK_MENU (m), item);
1938             }
1940             gtk_option_menu_set_menu (GTK_OPTION_MENU (om), m);
1941             gtk_option_menu_set_history ( GTK_OPTION_MENU (om), current);
1942         }
1944         table_row_labels = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1946 // Shift
1947         {
1948             GtkWidget *vb = clonetiler_new_tab (nb, _("S_hift"));
1950             GtkWidget *table = clonetiler_table_x_y_rand (3);
1951             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1953             // X
1954             {
1955                 GtkWidget *l = gtk_label_new ("");
1956                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) horizontally by this amount
1957                     // xgettext:no-c-format
1958                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift X:</b>"));
1959                 gtk_size_group_add_widget(table_row_labels, l);
1960                 clonetiler_table_attach (table, l, 1, 2, 1);
1961             }
1963             {
1964                 GtkWidget *l = clonetiler_spinbox (tt,
1965                     // xgettext:no-c-format
1966                                                    _("Horizontal shift per row (in % of tile width)"), "shiftx_per_j",
1967                                                    -10000, 10000, "%");
1968                 clonetiler_table_attach (table, l, 0, 2, 2);
1969             }
1971             {
1972                 GtkWidget *l = clonetiler_spinbox (tt,
1973                     // xgettext:no-c-format
1974                                                    _("Horizontal shift per column (in % of tile width)"), "shiftx_per_i",
1975                                                    -10000, 10000, "%");
1976                 clonetiler_table_attach (table, l, 0, 2, 3);
1977             }
1979             {
1980                 GtkWidget *l = clonetiler_spinbox (tt,
1981                                                    _("Randomize the horizontal shift by this percentage"), "shiftx_rand",
1982                                                    0, 1000, "%");
1983                 clonetiler_table_attach (table, l, 0, 2, 4);
1984             }
1986             // Y
1987             {
1988                 GtkWidget *l = gtk_label_new ("");
1989                     // TRANSLATORS: "shift" means: the tiles will be shifted (offset) vertically by this amount
1990                     // xgettext:no-c-format
1991                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift Y:</b>"));
1992                 gtk_size_group_add_widget(table_row_labels, l);
1993                 clonetiler_table_attach (table, l, 1, 3, 1);
1994             }
1996             {
1997                 GtkWidget *l = clonetiler_spinbox (tt,
1998                     // xgettext:no-c-format
1999                                                    _("Vertical shift per row (in % of tile height)"), "shifty_per_j",
2000                                                    -10000, 10000, "%");
2001                 clonetiler_table_attach (table, l, 0, 3, 2);
2002             }
2004             {
2005                 GtkWidget *l = clonetiler_spinbox (tt,
2006                     // xgettext:no-c-format
2007                                                    _("Vertical shift per column (in % of tile height)"), "shifty_per_i",
2008                                                    -10000, 10000, "%");
2009                 clonetiler_table_attach (table, l, 0, 3, 3);
2010             }
2012             {
2013                 GtkWidget *l = clonetiler_spinbox (tt,
2014                                                    _("Randomize the vertical shift by this percentage"), "shifty_rand",
2015                                                    0, 1000, "%");
2016                 clonetiler_table_attach (table, l, 0, 3, 4);
2017             }
2019             // Exponent
2020             {
2021                 GtkWidget *l = gtk_label_new ("");
2022                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2023                 gtk_size_group_add_widget(table_row_labels, l);
2024                 clonetiler_table_attach (table, l, 1, 4, 1);
2025             }
2027             {
2028                 GtkWidget *l = clonetiler_spinbox (tt,
2029                                                    _("Whether rows are spaced evenly (1), converge (<1) or diverge (>1)"), "shifty_exp",
2030                                                    0, 10, "", true);
2031                 clonetiler_table_attach (table, l, 0, 4, 2);
2032             }
2034             {
2035                 GtkWidget *l = clonetiler_spinbox (tt,
2036                                                    _("Whether columns are spaced evenly (1), converge (<1) or diverge (>1)"), "shiftx_exp",
2037                                                    0, 10, "", true);
2038                 clonetiler_table_attach (table, l, 0, 4, 3);
2039             }
2041             { // alternates
2042                 GtkWidget *l = gtk_label_new ("");
2043                 // TRANSLATORS: "Alternate" is a verb here
2044                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2045                 gtk_size_group_add_widget(table_row_labels, l);
2046                 clonetiler_table_attach (table, l, 1, 5, 1);
2047             }
2049             {
2050                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each row"), "shifty_alternate");
2051                 clonetiler_table_attach (table, l, 0, 5, 2);
2052             }
2054             {
2055                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each column"), "shiftx_alternate");
2056                 clonetiler_table_attach (table, l, 0, 5, 3);
2057             }
2059             { // Cumulate
2060                 GtkWidget *l = gtk_label_new ("");
2061                 // TRANSLATORS: "Cumulate" is a verb here
2062                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2063                 gtk_size_group_add_widget(table_row_labels, l);
2064                 clonetiler_table_attach (table, l, 1, 6, 1);
2065             }
2067             {
2068                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each row"), "shifty_cumulate");
2069                 clonetiler_table_attach (table, l, 0, 6, 2);
2070             }
2072             {
2073                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each column"), "shiftx_cumulate");
2074                 clonetiler_table_attach (table, l, 0, 6, 3);
2075             }
2077             { // Exclude tile width and height in shift
2078                 GtkWidget *l = gtk_label_new ("");
2079                 // TRANSLATORS: "Cumulate" is a verb here
2080                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Exclude tile:</small>"));
2081                 gtk_size_group_add_widget(table_row_labels, l);
2082                 clonetiler_table_attach (table, l, 1, 7, 1);
2083             }
2085             {
2086                 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile height in shift"), "shifty_excludeh");
2087                 clonetiler_table_attach (table, l, 0, 7, 2);
2088             }
2090             {
2091                 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile width in shift"), "shiftx_excludew");
2092                 clonetiler_table_attach (table, l, 0, 7, 3);
2093             }
2095         }
2098 // Scale
2099         {
2100             GtkWidget *vb = clonetiler_new_tab (nb, _("Sc_ale"));
2102             GtkWidget *table = clonetiler_table_x_y_rand (2);
2103             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2105             // X
2106             {
2107                 GtkWidget *l = gtk_label_new ("");
2108                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale X:</b>"));
2109                 gtk_size_group_add_widget(table_row_labels, l);
2110                 clonetiler_table_attach (table, l, 1, 2, 1);
2111             }
2113             {
2114                 GtkWidget *l = clonetiler_spinbox (tt,
2115                     // xgettext:no-c-format
2116                                                    _("Horizontal scale per row (in % of tile width)"), "scalex_per_j",
2117                                                    -100, 1000, "%");
2118                 clonetiler_table_attach (table, l, 0, 2, 2);
2119             }
2121             {
2122                 GtkWidget *l = clonetiler_spinbox (tt,
2123                     // xgettext:no-c-format
2124                                                    _("Horizontal scale per column (in % of tile width)"), "scalex_per_i",
2125                                                    -100, 1000, "%");
2126                 clonetiler_table_attach (table, l, 0, 2, 3);
2127             }
2129             {
2130                 GtkWidget *l = clonetiler_spinbox (tt,
2131                                                    _("Randomize the horizontal scale by this percentage"), "scalex_rand",
2132                                                    0, 1000, "%");
2133                 clonetiler_table_attach (table, l, 0, 2, 4);
2134             }
2136             // Y
2137             {
2138                 GtkWidget *l = gtk_label_new ("");
2139                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale Y:</b>"));
2140                 gtk_size_group_add_widget(table_row_labels, l);
2141                 clonetiler_table_attach (table, l, 1, 3, 1);
2142             }
2144             {
2145                 GtkWidget *l = clonetiler_spinbox (tt,
2146                     // xgettext:no-c-format
2147                                                    _("Vertical scale per row (in % of tile height)"), "scaley_per_j",
2148                                                    -100, 1000, "%");
2149                 clonetiler_table_attach (table, l, 0, 3, 2);
2150             }
2152             {
2153                 GtkWidget *l = clonetiler_spinbox (tt,
2154                     // xgettext:no-c-format
2155                                                    _("Vertical scale per column (in % of tile height)"), "scaley_per_i",
2156                                                    -100, 1000, "%");
2157                 clonetiler_table_attach (table, l, 0, 3, 3);
2158             }
2160             {
2161                 GtkWidget *l = clonetiler_spinbox (tt,
2162                                                    _("Randomize the vertical scale by this percentage"), "scaley_rand",
2163                                                    0, 1000, "%");
2164                 clonetiler_table_attach (table, l, 0, 3, 4);
2165             }
2167             // Exponent
2168             {
2169                 GtkWidget *l = gtk_label_new ("");
2170                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2171                 gtk_size_group_add_widget(table_row_labels, l);
2172                 clonetiler_table_attach (table, l, 1, 4, 1);
2173             }
2175             {
2176                 GtkWidget *l = clonetiler_spinbox (tt,
2177                                                    _("Whether row scaling is uniform (1), converge (<1) or diverge (>1)"), "scaley_exp",
2178                                                    0, 10, "", true);
2179                 clonetiler_table_attach (table, l, 0, 4, 2);
2180             }
2182             {
2183                 GtkWidget *l = clonetiler_spinbox (tt,
2184                                                    _("Whether column scaling is uniform (1), converge (<1) or diverge (>1)"), "scalex_exp",
2185                                                    0, 10, "", true);
2186                 clonetiler_table_attach (table, l, 0, 4, 3);
2187             }
2189             // Logarithmic (as in logarithmic spiral)
2190             {
2191                 GtkWidget *l = gtk_label_new ("");
2192                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Base:</b>"));
2193                 gtk_size_group_add_widget(table_row_labels, l);
2194                 clonetiler_table_attach (table, l, 1, 5, 1);
2195             }
2197             {
2198                 GtkWidget *l = clonetiler_spinbox (tt,
2199                                                    _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scaley_log",
2200                                                    0, 10, "", false);
2201                 clonetiler_table_attach (table, l, 0, 5, 2);
2202             }
2204             {
2205                 GtkWidget *l = clonetiler_spinbox (tt,
2206                                                    _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scalex_log",
2207                                                    0, 10, "", false);
2208                 clonetiler_table_attach (table, l, 0, 5, 3);
2209             }
2211             { // alternates
2212                 GtkWidget *l = gtk_label_new ("");
2213                 // TRANSLATORS: "Alternate" is a verb here
2214                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2215                 gtk_size_group_add_widget(table_row_labels, l);
2216                 clonetiler_table_attach (table, l, 1, 6, 1);
2217             }
2219             {
2220                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each row"), "scaley_alternate");
2221                 clonetiler_table_attach (table, l, 0, 6, 2);
2222             }
2224             {
2225                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each column"), "scalex_alternate");
2226                 clonetiler_table_attach (table, l, 0, 6, 3);
2227             }
2229             { // Cumulate
2230                 GtkWidget *l = gtk_label_new ("");
2231                 // TRANSLATORS: "Cumulate" is a verb here
2232                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2233                 gtk_size_group_add_widget(table_row_labels, l);
2234                 clonetiler_table_attach (table, l, 1, 7, 1);
2235             }
2237             {
2238                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each row"), "scaley_cumulate");
2239                 clonetiler_table_attach (table, l, 0, 7, 2);
2240             }
2242             {
2243                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each column"), "scalex_cumulate");
2244                 clonetiler_table_attach (table, l, 0, 7, 3);
2245             }
2247         }
2250 // Rotation
2251         {
2252             GtkWidget *vb = clonetiler_new_tab (nb, _("_Rotation"));
2254             GtkWidget *table = clonetiler_table_x_y_rand (1);
2255             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2257             // Angle
2258             {
2259                 GtkWidget *l = gtk_label_new ("");
2260                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Angle:</b>"));
2261                 gtk_size_group_add_widget(table_row_labels, l);
2262                 clonetiler_table_attach (table, l, 1, 2, 1);
2263             }
2265             {
2266                 GtkWidget *l = clonetiler_spinbox (tt,
2267                     // xgettext:no-c-format
2268                                                    _("Rotate tiles by this angle for each row"), "rotate_per_j",
2269                                                    -180, 180, "&#176;");
2270                 clonetiler_table_attach (table, l, 0, 2, 2);
2271             }
2273             {
2274                 GtkWidget *l = clonetiler_spinbox (tt,
2275                     // xgettext:no-c-format
2276                                                    _("Rotate tiles by this angle for each column"), "rotate_per_i",
2277                                                    -180, 180, "&#176;");
2278                 clonetiler_table_attach (table, l, 0, 2, 3);
2279             }
2281             {
2282                 GtkWidget *l = clonetiler_spinbox (tt,
2283                                                    _("Randomize the rotation angle by this percentage"), "rotate_rand",
2284                                                    0, 100, "%");
2285                 clonetiler_table_attach (table, l, 0, 2, 4);
2286             }
2288             { // alternates
2289                 GtkWidget *l = gtk_label_new ("");
2290                 // TRANSLATORS: "Alternate" is a verb here
2291                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2292                 gtk_size_group_add_widget(table_row_labels, l);
2293                 clonetiler_table_attach (table, l, 1, 3, 1);
2294             }
2296             {
2297                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each row"), "rotate_alternatej");
2298                 clonetiler_table_attach (table, l, 0, 3, 2);
2299             }
2301             {
2302                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each column"), "rotate_alternatei");
2303                 clonetiler_table_attach (table, l, 0, 3, 3);
2304             }
2306             { // Cumulate
2307                 GtkWidget *l = gtk_label_new ("");
2308                 // TRANSLATORS: "Cumulate" is a verb here
2309                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2310                 gtk_size_group_add_widget(table_row_labels, l);
2311                 clonetiler_table_attach (table, l, 1, 4, 1);
2312             }
2314             {
2315                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each row"), "rotate_cumulatej");
2316                 clonetiler_table_attach (table, l, 0, 4, 2);
2317             }
2319             {
2320                 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each column"), "rotate_cumulatei");
2321                 clonetiler_table_attach (table, l, 0, 4, 3);
2322             }
2324         }
2327 // Blur and opacity
2328         {
2329             GtkWidget *vb = clonetiler_new_tab (nb, _("_Blur & opacity"));
2331             GtkWidget *table = clonetiler_table_x_y_rand (1);
2332             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2335             // Blur
2336             {
2337                 GtkWidget *l = gtk_label_new ("");
2338                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Blur:</b>"));
2339                 gtk_size_group_add_widget(table_row_labels, l);
2340                 clonetiler_table_attach (table, l, 1, 2, 1);
2341             }
2343             {
2344                 GtkWidget *l = clonetiler_spinbox (tt,
2345                                                    _("Blur tiles by this percentage for each row"), "blur_per_j",
2346                                                    0, 100, "%");
2347                 clonetiler_table_attach (table, l, 0, 2, 2);
2348             }
2350             {
2351                 GtkWidget *l = clonetiler_spinbox (tt,
2352                                                    _("Blur tiles by this percentage for each column"), "blur_per_i",
2353                                                    0, 100, "%");
2354                 clonetiler_table_attach (table, l, 0, 2, 3);
2355             }
2357             {
2358                 GtkWidget *l = clonetiler_spinbox (tt,
2359                                                    _("Randomize the tile blur by this percentage"), "blur_rand",
2360                                                    0, 100, "%");
2361                 clonetiler_table_attach (table, l, 0, 2, 4);
2362             }
2364             { // alternates
2365                 GtkWidget *l = gtk_label_new ("");
2366                 // TRANSLATORS: "Alternate" is a verb here
2367                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2368                 gtk_size_group_add_widget(table_row_labels, l);
2369                 clonetiler_table_attach (table, l, 1, 3, 1);
2370             }
2372             {
2373                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each row"), "blur_alternatej");
2374                 clonetiler_table_attach (table, l, 0, 3, 2);
2375             }
2377             {
2378                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each column"), "blur_alternatei");
2379                 clonetiler_table_attach (table, l, 0, 3, 3);
2380             }
2384             // Dissolve
2385             {
2386                 GtkWidget *l = gtk_label_new ("");
2387                 gtk_label_set_markup (GTK_LABEL(l), _("<b>Fade out:</b>"));
2388                 gtk_size_group_add_widget(table_row_labels, l);
2389                 clonetiler_table_attach (table, l, 1, 4, 1);
2390             }
2392             {
2393                 GtkWidget *l = clonetiler_spinbox (tt,
2394                                                    _("Decrease tile opacity by this percentage for each row"), "opacity_per_j",
2395                                                    0, 100, "%");
2396                 clonetiler_table_attach (table, l, 0, 4, 2);
2397             }
2399             {
2400                 GtkWidget *l = clonetiler_spinbox (tt,
2401                                                    _("Decrease tile opacity by this percentage for each column"), "opacity_per_i",
2402                                                    0, 100, "%");
2403                 clonetiler_table_attach (table, l, 0, 4, 3);
2404             }
2406             {
2407                 GtkWidget *l = clonetiler_spinbox (tt,
2408                                                    _("Randomize the tile opacity by this percentage"), "opacity_rand",
2409                                                    0, 100, "%");
2410                 clonetiler_table_attach (table, l, 0, 4, 4);
2411             }
2413             { // alternates
2414                 GtkWidget *l = gtk_label_new ("");
2415                 // TRANSLATORS: "Alternate" is a verb here
2416                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2417                 gtk_size_group_add_widget(table_row_labels, l);
2418                 clonetiler_table_attach (table, l, 1, 5, 1);
2419             }
2421             {
2422                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each row"), "opacity_alternatej");
2423                 clonetiler_table_attach (table, l, 0, 5, 2);
2424             }
2426             {
2427                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each column"), "opacity_alternatei");
2428                 clonetiler_table_attach (table, l, 0, 5, 3);
2429             }
2430         }
2433 // Color
2434         {
2435             GtkWidget *vb = clonetiler_new_tab (nb, _("Co_lor"));
2437             {
2438             GtkWidget *hb = gtk_hbox_new (FALSE, 0);
2440             GtkWidget *l = gtk_label_new (_("Initial color: "));
2441             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2443             guint32 rgba = 0x000000ff | sp_svg_read_color (prefs_get_string_attribute(prefs_path, "initial_color"), 0x000000ff);
2444             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);
2445             _color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed));
2447             gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast<GtkWidget*>(color_picker->gobj()), FALSE, FALSE, 0);
2449             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2450             }
2453             GtkWidget *table = clonetiler_table_x_y_rand (3);
2454             gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2456             // Hue
2457             {
2458                 GtkWidget *l = gtk_label_new ("");
2459                 gtk_label_set_markup (GTK_LABEL(l), _("<b>H:</b>"));
2460                 gtk_size_group_add_widget(table_row_labels, l);
2461                 clonetiler_table_attach (table, l, 1, 2, 1);
2462             }
2464             {
2465                 GtkWidget *l = clonetiler_spinbox (tt,
2466                                                    _("Change the tile hue by this percentage for each row"), "hue_per_j",
2467                                                    -100, 100, "%");
2468                 clonetiler_table_attach (table, l, 0, 2, 2);
2469             }
2471             {
2472                 GtkWidget *l = clonetiler_spinbox (tt,
2473                                                    _("Change the tile hue by this percentage for each column"), "hue_per_i",
2474                                                    -100, 100, "%");
2475                 clonetiler_table_attach (table, l, 0, 2, 3);
2476             }
2478             {
2479                 GtkWidget *l = clonetiler_spinbox (tt,
2480                                                    _("Randomize the tile hue by this percentage"), "hue_rand",
2481                                                    0, 100, "%");
2482                 clonetiler_table_attach (table, l, 0, 2, 4);
2483             }
2486             // Saturation
2487             {
2488                 GtkWidget *l = gtk_label_new ("");
2489                 gtk_label_set_markup (GTK_LABEL(l), _("<b>S:</b>"));
2490                 gtk_size_group_add_widget(table_row_labels, l);
2491                 clonetiler_table_attach (table, l, 1, 3, 1);
2492             }
2494             {
2495                 GtkWidget *l = clonetiler_spinbox (tt,
2496                                                    _("Change the color saturation by this percentage for each row"), "saturation_per_j",
2497                                                    -100, 100, "%");
2498                 clonetiler_table_attach (table, l, 0, 3, 2);
2499             }
2501             {
2502                 GtkWidget *l = clonetiler_spinbox (tt,
2503                                                    _("Change the color saturation by this percentage for each column"), "saturation_per_i",
2504                                                    -100, 100, "%");
2505                 clonetiler_table_attach (table, l, 0, 3, 3);
2506             }
2508             {
2509                 GtkWidget *l = clonetiler_spinbox (tt,
2510                                                    _("Randomize the color saturation by this percentage"), "saturation_rand",
2511                                                    0, 100, "%");
2512                 clonetiler_table_attach (table, l, 0, 3, 4);
2513             }
2515             // Lightness
2516             {
2517                 GtkWidget *l = gtk_label_new ("");
2518                 gtk_label_set_markup (GTK_LABEL(l), _("<b>L:</b>"));
2519                 gtk_size_group_add_widget(table_row_labels, l);
2520                 clonetiler_table_attach (table, l, 1, 4, 1);
2521             }
2523             {
2524                 GtkWidget *l = clonetiler_spinbox (tt,
2525                                                    _("Change the color lightness by this percentage for each row"), "lightness_per_j",
2526                                                    -100, 100, "%");
2527                 clonetiler_table_attach (table, l, 0, 4, 2);
2528             }
2530             {
2531                 GtkWidget *l = clonetiler_spinbox (tt,
2532                                                    _("Change the color lightness by this percentage for each column"), "lightness_per_i",
2533                                                    -100, 100, "%");
2534                 clonetiler_table_attach (table, l, 0, 4, 3);
2535             }
2537             {
2538                 GtkWidget *l = clonetiler_spinbox (tt,
2539                                                    _("Randomize the color lightness by this percentage"), "lightness_rand",
2540                                                    0, 100, "%");
2541                 clonetiler_table_attach (table, l, 0, 4, 4);
2542             }
2545             { // alternates
2546                 GtkWidget *l = gtk_label_new ("");
2547                 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2548                 gtk_size_group_add_widget(table_row_labels, l);
2549                 clonetiler_table_attach (table, l, 1, 5, 1);
2550             }
2552             {
2553                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each row"), "color_alternatej");
2554                 clonetiler_table_attach (table, l, 0, 5, 2);
2555             }
2557             {
2558                 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each column"), "color_alternatei");
2559                 clonetiler_table_attach (table, l, 0, 5, 3);
2560             }
2562         }
2564 // Trace
2565         {
2566             GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace"));
2569         {
2570             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2571             gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2573             GtkWidget *b  = gtk_check_button_new_with_label (_("Trace the drawing under the tiles"));
2574             g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
2575             gint old = prefs_get_int_attribute (prefs_path, "dotrace", 0);
2576             gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2577             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);
2578             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2580             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2581                                GTK_SIGNAL_FUNC(clonetiler_do_pick_toggled), dlg);
2582         }
2584         {
2585             GtkWidget *vvb = gtk_vbox_new (FALSE, 0);
2586             gtk_box_pack_start (GTK_BOX (vb), vvb, FALSE, FALSE, 0);
2587             g_object_set_data (G_OBJECT(dlg), "dotrace", (gpointer) vvb);
2590             {
2591                 GtkWidget *frame = gtk_frame_new (_("1. Pick from the drawing:"));
2592                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2594                 GtkWidget *table = gtk_table_new (3, 3, FALSE);
2595                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2596                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2597                 gtk_container_add(GTK_CONTAINER(frame), table);
2600                 GtkWidget* radio;
2601                 {
2602                     radio = gtk_radio_button_new_with_label (NULL, _("Color"));
2603                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the visible color and opacity"), NULL);
2604                     clonetiler_table_attach (table, radio, 0.0, 1, 1);
2605                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2606                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_COLOR));
2607                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_COLOR);
2608                 }
2609                 {
2610                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Opacity"));
2611                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the total accumulated opacity"), NULL);
2612                     clonetiler_table_attach (table, radio, 0.0, 2, 1);
2613                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2614                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_OPACITY));
2615                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_OPACITY);
2616                 }
2617                 {
2618                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("R"));
2619                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Red component of the color"), NULL);
2620                     clonetiler_table_attach (table, radio, 0.0, 1, 2);
2621                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2622                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_R));
2623                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_R);
2624                 }
2625                 {
2626                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("G"));
2627                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Green component of the color"), NULL);
2628                     clonetiler_table_attach (table, radio, 0.0, 2, 2);
2629                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2630                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_G));
2631                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_G);
2632                 }
2633                 {
2634                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("B"));
2635                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Blue component of the color"), NULL);
2636                     clonetiler_table_attach (table, radio, 0.0, 3, 2);
2637                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2638                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_B));
2639                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_B);
2640                 }
2641                 {
2642                     //TRANSLATORS: only translate "string" in "context|string".
2643                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2644                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|H"));
2645                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the hue of the color"), NULL);
2646                     clonetiler_table_attach (table, radio, 0.0, 1, 3);
2647                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2648                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_H));
2649                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_H);
2650                 }
2651                 {
2652                     //TRANSLATORS: only translate "string" in "context|string".
2653                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2654                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|S"));
2655                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the saturation of the color"), NULL);
2656                     clonetiler_table_attach (table, radio, 0.0, 2, 3);
2657                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2658                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_S));
2659                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_S);
2660                 }
2661                 {
2662                     //TRANSLATORS: only translate "string" in "context|string".
2663                     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2664                     radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|L"));
2665                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the lightness of the color"), NULL);
2666                     clonetiler_table_attach (table, radio, 0.0, 3, 3);
2667                     gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2668                                         GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_L));
2669                     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs_get_int_attribute(prefs_path, "pick", 0) == PICK_L);
2670                 }
2672             }
2674             {
2675                 GtkWidget *frame = gtk_frame_new (_("2. Tweak the picked value:"));
2676                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, VB_MARGIN);
2678                 GtkWidget *table = gtk_table_new (4, 2, FALSE);
2679                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2680                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2681                 gtk_container_add(GTK_CONTAINER(frame), table);
2683                 {
2684                     GtkWidget *l = gtk_label_new ("");
2685                     gtk_label_set_markup (GTK_LABEL(l), _("Gamma-correct:"));
2686                     clonetiler_table_attach (table, l, 1.0, 1, 1);
2687                 }
2688                 {
2689                     GtkWidget *l = clonetiler_spinbox (tt,
2690                                                        _("Shift the mid-range of the picked value upwards (>0) or downwards (<0)"), "gamma_picked",
2691                                                        -10, 10, "");
2692                     clonetiler_table_attach (table, l, 0.0, 1, 2);
2693                 }
2695                 {
2696                     GtkWidget *l = gtk_label_new ("");
2697                     gtk_label_set_markup (GTK_LABEL(l), _("Randomize:"));
2698                     clonetiler_table_attach (table, l, 1.0, 1, 3);
2699                 }
2700                 {
2701                     GtkWidget *l = clonetiler_spinbox (tt,
2702                                                        _("Randomize the picked value by this percentage"), "rand_picked",
2703                                                        0, 100, "%");
2704                     clonetiler_table_attach (table, l, 0.0, 1, 4);
2705                 }
2707                 {
2708                     GtkWidget *l = gtk_label_new ("");
2709                     gtk_label_set_markup (GTK_LABEL(l), _("Invert:"));
2710                     clonetiler_table_attach (table, l, 1.0, 2, 1);
2711                 }
2712                 {
2713                     GtkWidget *l = clonetiler_checkbox (tt, _("Invert the picked value"), "invert_picked");
2714                     clonetiler_table_attach (table, l, 0.0, 2, 2);
2715                 }
2716             }
2718             {
2719                 GtkWidget *frame = gtk_frame_new (_("3. Apply the value to the clones':"));
2720                 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2723                 GtkWidget *table = gtk_table_new (2, 2, FALSE);
2724                 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2725                 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2726                 gtk_container_add(GTK_CONTAINER(frame), table);
2728                 {
2729                     GtkWidget *b  = gtk_check_button_new_with_label (_("Presence"));
2730                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_presence", 1);
2731                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2732                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone is created with the probability determined by the picked value in that point"), NULL);
2733                     clonetiler_table_attach (table, b, 0.0, 1, 1);
2734                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2735                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_presence");
2736                 }
2738                 {
2739                     GtkWidget *b  = gtk_check_button_new_with_label (_("Size"));
2740                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_size", 0);
2741                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2742                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's size is determined by the picked value in that point"), NULL);
2743                     clonetiler_table_attach (table, b, 0.0, 2, 1);
2744                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2745                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_size");
2746                 }
2748                 {
2749                     GtkWidget *b  = gtk_check_button_new_with_label (_("Color"));
2750                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_color", 0);
2751                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2752                     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);
2753                     clonetiler_table_attach (table, b, 0.0, 1, 2);
2754                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2755                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_color");
2756                 }
2758                 {
2759                     GtkWidget *b  = gtk_check_button_new_with_label (_("Opacity"));
2760                     gint old = prefs_get_int_attribute (prefs_path, "pick_to_opacity", 0);
2761                     gtk_toggle_button_set_active ((GtkToggleButton *) b, old != 0);
2762                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's opacity is determined by the picked value in that point"), NULL);
2763                     clonetiler_table_attach (table, b, 0.0, 2, 2);
2764                     gtk_signal_connect(GTK_OBJECT(b), "toggled",
2765                                        GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_opacity");
2766                 }
2767             }
2768            gtk_widget_set_sensitive (vvb, prefs_get_int_attribute (prefs_path, "dotrace", 0));
2769         }
2770         }
2772 // Rows/columns, width/height
2773         {
2774             GtkWidget *table = gtk_table_new (2, 2, FALSE);
2775             gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
2776             gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2777             gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2778             gtk_box_pack_start (GTK_BOX (mainbox), table, FALSE, FALSE, 0);
2780             {
2781                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2782                 g_object_set_data (G_OBJECT(dlg), "rowscols", (gpointer) hb);
2784                 {
2785                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2786                     int value = prefs_get_int_attribute (prefs_path, "jmax", 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 rows 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) "jmax");
2795                 }
2797                 {
2798                     GtkWidget *l = gtk_label_new ("");
2799                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2800                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2801                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2802                 }
2804                 {
2805                     GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2806                     int value = prefs_get_int_attribute (prefs_path, "imax", 2);
2807                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2808                     GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2809                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many columns in the tiling"), NULL);
2810                     gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2811                     gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2813                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2814                                        GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "imax");
2815                 }
2817                 clonetiler_table_attach (table, hb, 0.0, 1, 2);
2818             }
2820             {
2821                 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2822                 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
2824                 // unitmenu
2825                 GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
2826                 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
2828                 {
2829                     // Width spinbutton
2830                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2831                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2833                     double value = prefs_get_double_attribute (prefs_path, "fillwidth", 50);
2834                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2835                     gdouble const units = sp_pixels_get_units (value, unit);
2836                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2838                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2839                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Width of the rectangle to be filled"), NULL);
2840                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2841                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2842                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2843                                        GTK_SIGNAL_FUNC(clonetiler_fill_width_changed), u);
2844                 }
2845                 {
2846                     GtkWidget *l = gtk_label_new ("");
2847                     gtk_label_set_markup (GTK_LABEL(l), "&#215;");
2848                     gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2849                     gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2850                 }
2852                 {
2853                     // Height spinbutton
2854                     GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2855                     sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2857                     double value = prefs_get_double_attribute (prefs_path, "fillheight", 50);
2858                     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2859                     gdouble const units = sp_pixels_get_units (value, unit);
2860                     gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2863                     GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2864                     gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Height of the rectangle to be filled"), NULL);
2865                     gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2866                     gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2867                     gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2868                                        GTK_SIGNAL_FUNC(clonetiler_fill_height_changed), u);
2869                 }
2871                 gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);
2872                 clonetiler_table_attach (table, hb, 0.0, 2, 2);
2874             }
2876             // Switch
2877             GtkWidget* radio;
2878             {
2879                 radio = gtk_radio_button_new_with_label (NULL, _("Rows, columns: "));
2880                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Create the specified number of rows and columns"), NULL);
2881                 clonetiler_table_attach (table, radio, 0.0, 1, 1);
2882                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_create), (gpointer) dlg);
2883             }
2884             if (prefs_get_int_attribute(prefs_path, "fillrect", 0) == 0) {
2885                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2886                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2887             }
2888             {
2889                 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Width, height: "));
2890                 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Fill the specified width and height with the tiling"), NULL);
2891                 clonetiler_table_attach (table, radio, 0.0, 2, 1);
2892                 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_fill), (gpointer) dlg);
2893             }
2894             if (prefs_get_int_attribute(prefs_path, "fillrect", 0) == 1) {
2895                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2896                 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2897             }
2898         }
2901 // Use saved pos
2902         {
2903             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2904             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2906             GtkWidget *b  = gtk_check_button_new_with_label (_("Use saved size and position of the tile"));
2907             gint keepbbox = prefs_get_int_attribute (prefs_path, "keepbbox", 1);
2908             gtk_toggle_button_set_active ((GtkToggleButton *) b, keepbbox != 0);
2909             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);
2910             gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2912             gtk_signal_connect(GTK_OBJECT(b), "toggled",
2913                                GTK_SIGNAL_FUNC(clonetiler_keep_bbox_toggled), NULL);
2914         }
2916 // Statusbar
2917         {
2918             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2919             gtk_box_pack_end (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2920             GtkWidget *l = gtk_label_new("");
2921             g_object_set_data (G_OBJECT(dlg), "status", (gpointer) l);
2922             gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2923         }
2925 // Buttons
2926         {
2927             GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2928             gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2930             {
2931                 GtkWidget *b = gtk_button_new ();
2932                 GtkWidget *l = gtk_label_new ("");
2933                 gtk_label_set_markup_with_mnemonic (GTK_LABEL(l), _(" <b>_Create</b> "));
2934                 gtk_container_add (GTK_CONTAINER(b), l);
2935                 gtk_tooltips_set_tip (tt, b, _("Create and tile the clones of the selection"), NULL);
2936                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_apply), NULL);
2937                 gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0);
2938             }
2940             { // buttons which are enabled only when there are tiled clones
2941                 GtkWidget *sb = gtk_hbox_new(FALSE, 0);
2942                 gtk_box_pack_end (GTK_BOX (hb), sb, FALSE, FALSE, 0);
2943                 g_object_set_data (G_OBJECT(dlg), "buttons_on_tiles", (gpointer) sb);
2944                 {
2945                     // TRANSLATORS: if a group of objects are "clumped" together, then they
2946                     //  are unevenly spread in the given amount of space - as shown in the
2947                     //  diagrams on the left in the following screenshot:
2948                     //  http://www.inkscape.org/screenshots/gallery/inkscape-0.42-CVS-tiles-unclump.png
2949                     //  So unclumping is the process of spreading a number of objects out more evenly.
2950                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" _Unclump "));
2951                     gtk_tooltips_set_tip (tt, b, _("Spread out clones to reduce clumping; can be applied repeatedly"), NULL);
2952                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_unclump), NULL);
2953                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2954                 }
2956                 {
2957                     GtkWidget *b = gtk_button_new_with_mnemonic (_(" Re_move "));
2958                     gtk_tooltips_set_tip (tt, b, _("Remove existing tiled clones of the selected object (siblings only)"), NULL);
2959                     gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_remove), NULL);
2960                     gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2961                 }
2963                 // connect to global selection changed signal (so we can change desktops) and
2964                 // external_change (so we're not fooled by undo)
2965                 g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (clonetiler_change_selection), dlg);
2966                 g_signal_connect (G_OBJECT (INKSCAPE), "external_change", G_CALLBACK (clonetiler_external_change), dlg);
2967                 g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), G_OBJECT (INKSCAPE));
2969                 // update now
2970                 clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
2971             }
2973             {
2974                 GtkWidget *b = gtk_button_new_with_mnemonic (_(" R_eset "));
2975                 // TRANSLATORS: "change" is a noun here
2976                 gtk_tooltips_set_tip (tt, b, _("Reset all shifts, scales, rotates, opacity and color changes in the dialog to zero"), NULL);
2977                 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_reset), NULL);
2978                 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2979             }
2980         }
2982         gtk_widget_show_all (mainbox);
2984     } // end of if (!dlg)
2986     gtk_window_present ((GtkWindow *) dlg);
2990 /*
2991   Local Variables:
2992   mode:c++
2993   c-file-style:"stroustrup"
2994   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2995   indent-tabs-mode:nil
2996   fill-column:99
2997   End:
2998 */
2999 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :