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