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