550370e90e9a694dd9b74090d9d85423a5dfc414
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(o)->invoke_hide(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 = SPItem::display_key_new(1);
865 trace_doc = doc;
866 trace_root = SP_ITEM(SP_DOCUMENT_ROOT (trace_doc))->invoke_show((NRArena *) trace_arena, trace_visionkey, SP_ITEM_SHOW_DISPLAY);
868 // hide the (current) original and any tiled clones, we only want to pick the background
869 original->invoke_hide(trace_visionkey);
870 clonetiler_trace_hide_tiled_clones_recursively (SP_OBJECT(SP_DOCUMENT_ROOT (trace_doc)));
872 sp_document_root (trace_doc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
873 sp_document_ensure_up_to_date(trace_doc);
875 trace_zoom = zoom;
876 }
878 static guint32
879 clonetiler_trace_pick (Geom::Rect box)
880 {
881 if (!trace_arena)
882 return 0;
884 Geom::Matrix t(Geom::Scale(trace_zoom, trace_zoom));
885 nr_arena_item_set_transform(trace_root, &t);
886 NRGC gc(NULL);
887 gc.transform.setIdentity();
888 nr_arena_item_invoke_update( trace_root, NULL, &gc,
889 NR_ARENA_ITEM_STATE_ALL,
890 NR_ARENA_ITEM_STATE_NONE );
892 /* Item integer bbox in points */
893 NRRectL ibox;
894 ibox.x0 = (int) floor(trace_zoom * box[Geom::X].min() + 0.5);
895 ibox.y0 = (int) floor(trace_zoom * box[Geom::Y].min() + 0.5);
896 ibox.x1 = (int) floor(trace_zoom * box[Geom::X].max() + 0.5);
897 ibox.y1 = (int) floor(trace_zoom * box[Geom::Y].max() + 0.5);
899 /* Find visible area */
900 int width = ibox.x1 - ibox.x0;
901 int height = ibox.y1 - ibox.y0;
903 /* Set up pixblock */
904 guchar *px = g_new(guchar, 4 * width * height);
906 if (px == NULL) {
907 return 0; // buffer is too big or too small, cannot pick, so return 0
908 }
910 memset(px, 0x00, 4 * width * height);
912 /* Render */
913 NRPixBlock pb;
914 nr_pixblock_setup_extern( &pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
915 ibox.x0, ibox.y0, ibox.x1, ibox.y1,
916 px, 4 * width, FALSE, FALSE );
917 nr_arena_item_invoke_render(NULL, trace_root, &ibox, &pb,
918 NR_ARENA_ITEM_RENDER_NO_CACHE );
920 double R = 0, G = 0, B = 0, A = 0;
921 double count = 0;
922 double weight = 0;
924 for (int y = ibox.y0; y < ibox.y1; y++) {
925 const unsigned char *s = NR_PIXBLOCK_PX (&pb) + (y - ibox.y0) * pb.rs;
926 for (int x = ibox.x0; x < ibox.x1; x++) {
927 count += 1;
928 weight += s[3] / 255.0;
929 R += s[0] / 255.0;
930 G += s[1] / 255.0;
931 B += s[2] / 255.0;
932 A += s[3] / 255.0;
933 s += 4;
934 }
935 }
937 nr_pixblock_release(&pb);
939 R = R / weight;
940 G = G / weight;
941 B = B / weight;
942 A = A / count;
944 R = CLAMP (R, 0.0, 1.0);
945 G = CLAMP (G, 0.0, 1.0);
946 B = CLAMP (B, 0.0, 1.0);
947 A = CLAMP (A, 0.0, 1.0);
949 return SP_RGBA32_F_COMPOSE (R, G, B, A);
950 }
952 static void
953 clonetiler_trace_finish ()
954 {
955 if (trace_doc) {
956 SP_ITEM(sp_document_root(trace_doc))->invoke_hide(trace_visionkey);
957 }
958 if (trace_arena) {
959 ((NRObject *) trace_arena)->unreference();
960 trace_arena = NULL;
961 }
962 }
964 static void
965 clonetiler_unclump( GtkWidget */*widget*/, void * )
966 {
967 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
968 if (desktop == NULL)
969 return;
971 Inkscape::Selection *selection = sp_desktop_selection(desktop);
973 // check if something is selected
974 if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
975 sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump."));
976 return;
977 }
979 SPObject *obj = SP_OBJECT(selection->singleItem());
980 SPObject *parent = SP_OBJECT_PARENT (obj);
982 GSList *to_unclump = NULL; // not including the original
984 for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
985 if (clonetiler_is_a_clone_of (child, obj)) {
986 to_unclump = g_slist_prepend (to_unclump, child);
987 }
988 }
990 sp_document_ensure_up_to_date(sp_desktop_document(desktop));
992 unclump (to_unclump);
994 g_slist_free (to_unclump);
996 sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
997 _("Unclump tiled clones"));
998 }
1000 static guint
1001 clonetiler_number_of_clones (SPObject *obj)
1002 {
1003 SPObject *parent = SP_OBJECT_PARENT (obj);
1005 guint n = 0;
1007 for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
1008 if (clonetiler_is_a_clone_of (child, obj)) {
1009 n ++;
1010 }
1011 }
1013 return n;
1014 }
1016 static void
1017 clonetiler_remove( GtkWidget */*widget*/, void *, bool do_undo = true )
1018 {
1019 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1020 if (desktop == NULL)
1021 return;
1023 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1025 // check if something is selected
1026 if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) {
1027 sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove."));
1028 return;
1029 }
1031 SPObject *obj = SP_OBJECT(selection->singleItem());
1032 SPObject *parent = SP_OBJECT_PARENT (obj);
1034 // remove old tiling
1035 GSList *to_delete = NULL;
1036 for (SPObject *child = sp_object_first_child(parent); child != NULL; child = SP_OBJECT_NEXT(child)) {
1037 if (clonetiler_is_a_clone_of (child, obj)) {
1038 to_delete = g_slist_prepend (to_delete, child);
1039 }
1040 }
1041 for (GSList *i = to_delete; i; i = i->next) {
1042 SP_OBJECT(i->data)->deleteObject();
1043 }
1044 g_slist_free (to_delete);
1046 clonetiler_change_selection (NULL, selection, dlg);
1048 if (do_undo)
1049 sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_CLONETILER,
1050 _("Delete tiled clones"));
1051 }
1053 static Geom::Rect
1054 transform_rect( Geom::Rect const &r, Geom::Matrix const &m)
1055 {
1056 using Geom::X;
1057 using Geom::Y;
1058 Geom::Point const p1 = r.corner(1) * m;
1059 Geom::Point const p2 = r.corner(2) * m;
1060 Geom::Point const p3 = r.corner(3) * m;
1061 Geom::Point const p4 = r.corner(4) * m;
1062 return Geom::Rect(
1063 Geom::Point(
1064 std::min(std::min(p1[X], p2[X]), std::min(p3[X], p4[X])),
1065 std::min(std::min(p1[Y], p2[Y]), std::min(p3[Y], p4[Y]))),
1066 Geom::Point(
1067 std::max(std::max(p1[X], p2[X]), std::max(p3[X], p4[X])),
1068 std::max(std::max(p1[Y], p2[Y]), std::max(p3[Y], p4[Y]))));
1069 }
1071 /**
1072 Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same
1073 probability of being displaced.
1074 */
1075 static double
1076 randomize01 (double val, double rand)
1077 {
1078 double base = MIN (val - rand, 1 - 2*rand);
1079 if (base < 0) base = 0;
1080 val = base + g_random_double_range (0, MIN (2 * rand, 1 - base));
1081 return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case...
1082 }
1085 static void
1086 clonetiler_apply( GtkWidget */*widget*/, void * )
1087 {
1088 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1089 if (desktop == NULL)
1090 return;
1091 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1092 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1094 // check if something is selected
1095 if (selection->isEmpty()) {
1096 sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone."));
1097 return;
1098 }
1100 // Check if more than one object is selected.
1101 if (g_slist_length((GSList *) selection->itemList()) > 1) {
1102 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>."));
1103 return;
1104 }
1106 // set "busy" cursor
1107 desktop->setWaitingCursor();
1109 // set statusbar text
1110 GtkWidget *status = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "status");
1111 gtk_label_set_markup (GTK_LABEL(status), _("<small>Creating tiled clones...</small>"));
1112 gtk_widget_queue_draw(GTK_WIDGET(status));
1113 gdk_window_process_all_updates();
1115 SPObject *obj = SP_OBJECT(selection->singleItem());
1116 Inkscape::XML::Node *obj_repr = SP_OBJECT_REPR(obj);
1117 const char *id_href = g_strdup_printf("#%s", obj_repr->attribute("id"));
1118 SPObject *parent = SP_OBJECT_PARENT (obj);
1120 clonetiler_remove (NULL, NULL, false);
1122 double shiftx_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_per_i", 0, -10000, 10000);
1123 double shifty_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_per_i", 0, -10000, 10000);
1124 double shiftx_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_per_j", 0, -10000, 10000);
1125 double shifty_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_per_j", 0, -10000, 10000);
1126 double shiftx_rand = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_rand", 0, 0, 1000);
1127 double shifty_rand = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_rand", 0, 0, 1000);
1128 double shiftx_exp = prefs->getDoubleLimited(prefs_path + "shiftx_exp", 1, 0, 10);
1129 double shifty_exp = prefs->getDoubleLimited(prefs_path + "shifty_exp", 1, 0, 10);
1130 bool shiftx_alternate = prefs->getBool(prefs_path + "shiftx_alternate");
1131 bool shifty_alternate = prefs->getBool(prefs_path + "shifty_alternate");
1132 bool shiftx_cumulate = prefs->getBool(prefs_path + "shiftx_cumulate");
1133 bool shifty_cumulate = prefs->getBool(prefs_path + "shifty_cumulate");
1134 bool shiftx_excludew = prefs->getBool(prefs_path + "shiftx_excludew");
1135 bool shifty_excludeh = prefs->getBool(prefs_path + "shifty_excludeh");
1137 double scalex_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_per_i", 0, -100, 1000);
1138 double scaley_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_per_i", 0, -100, 1000);
1139 double scalex_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_per_j", 0, -100, 1000);
1140 double scaley_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_per_j", 0, -100, 1000);
1141 double scalex_rand = 0.01 * prefs->getDoubleLimited(prefs_path + "scalex_rand", 0, 0, 1000);
1142 double scaley_rand = 0.01 * prefs->getDoubleLimited(prefs_path + "scaley_rand", 0, 0, 1000);
1143 double scalex_exp = prefs->getDoubleLimited(prefs_path + "scalex_exp", 1, 0, 10);
1144 double scaley_exp = prefs->getDoubleLimited(prefs_path + "scaley_exp", 1, 0, 10);
1145 double scalex_log = prefs->getDoubleLimited(prefs_path + "scalex_log", 0, 0, 10);
1146 double scaley_log = prefs->getDoubleLimited(prefs_path + "scaley_log", 0, 0, 10);
1147 bool scalex_alternate = prefs->getBool(prefs_path + "scalex_alternate");
1148 bool scaley_alternate = prefs->getBool(prefs_path + "scaley_alternate");
1149 bool scalex_cumulate = prefs->getBool(prefs_path + "scalex_cumulate");
1150 bool scaley_cumulate = prefs->getBool(prefs_path + "scaley_cumulate");
1152 double rotate_per_i = prefs->getDoubleLimited(prefs_path + "rotate_per_i", 0, -180, 180);
1153 double rotate_per_j = prefs->getDoubleLimited(prefs_path + "rotate_per_j", 0, -180, 180);
1154 double rotate_rand = 0.01 * prefs->getDoubleLimited(prefs_path + "rotate_rand", 0, 0, 100);
1155 bool rotate_alternatei = prefs->getBool(prefs_path + "rotate_alternatei");
1156 bool rotate_alternatej = prefs->getBool(prefs_path + "rotate_alternatej");
1157 bool rotate_cumulatei = prefs->getBool(prefs_path + "rotate_cumulatei");
1158 bool rotate_cumulatej = prefs->getBool(prefs_path + "rotate_cumulatej");
1160 double blur_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "blur_per_i", 0, 0, 100);
1161 double blur_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "blur_per_j", 0, 0, 100);
1162 bool blur_alternatei = prefs->getBool(prefs_path + "blur_alternatei");
1163 bool blur_alternatej = prefs->getBool(prefs_path + "blur_alternatej");
1164 double blur_rand = 0.01 * prefs->getDoubleLimited(prefs_path + "blur_rand", 0, 0, 100);
1166 double opacity_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "opacity_per_i", 0, 0, 100);
1167 double opacity_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "opacity_per_j", 0, 0, 100);
1168 bool opacity_alternatei = prefs->getBool(prefs_path + "opacity_alternatei");
1169 bool opacity_alternatej = prefs->getBool(prefs_path + "opacity_alternatej");
1170 double opacity_rand = 0.01 * prefs->getDoubleLimited(prefs_path + "opacity_rand", 0, 0, 100);
1172 Glib::ustring initial_color = prefs->getString(prefs_path + "initial_color");
1173 double hue_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "hue_per_j", 0, -100, 100);
1174 double hue_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "hue_per_i", 0, -100, 100);
1175 double hue_rand = 0.01 * prefs->getDoubleLimited(prefs_path + "hue_rand", 0, 0, 100);
1176 double saturation_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "saturation_per_j", 0, -100, 100);
1177 double saturation_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "saturation_per_i", 0, -100, 100);
1178 double saturation_rand = 0.01 * prefs->getDoubleLimited(prefs_path + "saturation_rand", 0, 0, 100);
1179 double lightness_per_j = 0.01 * prefs->getDoubleLimited(prefs_path + "lightness_per_j", 0, -100, 100);
1180 double lightness_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "lightness_per_i", 0, -100, 100);
1181 double lightness_rand = 0.01 * prefs->getDoubleLimited(prefs_path + "lightness_rand", 0, 0, 100);
1182 bool color_alternatej = prefs->getBool(prefs_path + "color_alternatej");
1183 bool color_alternatei = prefs->getBool(prefs_path + "color_alternatei");
1185 int type = prefs->getInt(prefs_path + "symmetrygroup", 0);
1186 bool keepbbox = prefs->getBool(prefs_path + "keepbbox", true);
1187 int imax = prefs->getInt(prefs_path + "imax", 2);
1188 int jmax = prefs->getInt(prefs_path + "jmax", 2);
1190 bool fillrect = prefs->getBool(prefs_path + "fillrect");
1191 double fillwidth = prefs->getDoubleLimited(prefs_path + "fillwidth", 50, 0, 1e6);
1192 double fillheight = prefs->getDoubleLimited(prefs_path + "fillheight", 50, 0, 1e6);
1194 bool dotrace = prefs->getBool(prefs_path + "dotrace");
1195 int pick = prefs->getInt(prefs_path + "pick");
1196 bool pick_to_presence = prefs->getBool(prefs_path + "pick_to_presence");
1197 bool pick_to_size = prefs->getBool(prefs_path + "pick_to_size");
1198 bool pick_to_color = prefs->getBool(prefs_path + "pick_to_color");
1199 bool pick_to_opacity = prefs->getBool(prefs_path + "pick_to_opacity");
1200 double rand_picked = 0.01 * prefs->getDoubleLimited(prefs_path + "rand_picked", 0, 0, 100);
1201 bool invert_picked = prefs->getBool(prefs_path + "invert_picked");
1202 double gamma_picked = prefs->getDoubleLimited(prefs_path + "gamma_picked", 0, -10, 10);
1204 if (dotrace) {
1205 clonetiler_trace_setup (sp_desktop_document(desktop), 1.0, SP_ITEM (obj));
1206 }
1208 Geom::Point center;
1209 double w;
1210 double h;
1211 double x0;
1212 double y0;
1214 if (keepbbox &&
1215 obj_repr->attribute("inkscape:tile-w") &&
1216 obj_repr->attribute("inkscape:tile-h") &&
1217 obj_repr->attribute("inkscape:tile-x0") &&
1218 obj_repr->attribute("inkscape:tile-y0") &&
1219 obj_repr->attribute("inkscape:tile-cx") &&
1220 obj_repr->attribute("inkscape:tile-cy")) {
1222 double cx = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cx", 0);
1223 double cy = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-cy", 0);
1224 center = Geom::Point (cx, cy);
1226 w = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-w", 0);
1227 h = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-h", 0);
1228 x0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-x0", 0);
1229 y0 = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-y0", 0);
1230 } else {
1231 bool prefs_bbox = prefs->getBool("/tools/bounding_box", false);
1232 SPItem::BBoxType bbox_type = ( prefs_bbox ?
1233 SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX );
1234 Geom::OptRect r = SP_ITEM(obj)->getBounds(SP_ITEM(obj)->i2doc_affine(),
1235 bbox_type);
1236 if (r) {
1237 w = r->dimensions()[Geom::X];
1238 h = r->dimensions()[Geom::Y];
1239 x0 = r->min()[Geom::X];
1240 y0 = r->min()[Geom::Y];
1241 center = desktop->dt2doc(SP_ITEM(obj)->getCenter());
1243 sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", center[Geom::X]);
1244 sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", center[Geom::Y]);
1245 sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
1246 sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
1247 sp_repr_set_svg_double(obj_repr, "inkscape:tile-x0", x0);
1248 sp_repr_set_svg_double(obj_repr, "inkscape:tile-y0", y0);
1249 } else {
1250 center = Geom::Point(0, 0);
1251 w = h = 0;
1252 x0 = y0 = 0;
1253 }
1254 }
1256 Geom::Point cur(0, 0);
1257 Geom::Rect bbox_original (Geom::Point (x0, y0), Geom::Point (x0 + w, y0 + h));
1258 double perimeter_original = (w + h)/4;
1260 // The integers i and j are reserved for tile column and row.
1261 // The doubles x and y are used for coordinates
1262 for (int i = 0;
1263 fillrect?
1264 (fabs(cur[Geom::X]) < fillwidth && i < 200) // prevent "freezing" with too large fillrect, arbitrarily limit rows
1265 : (i < imax);
1266 i ++) {
1267 for (int j = 0;
1268 fillrect?
1269 (fabs(cur[Geom::Y]) < fillheight && j < 200) // prevent "freezing" with too large fillrect, arbitrarily limit cols
1270 : (j < jmax);
1271 j ++) {
1273 // Note: We create a clone at 0,0 too, right over the original, in case our clones are colored
1275 // Get transform from symmetry, shift, scale, rotation
1276 Geom::Matrix t = clonetiler_get_transform (type, i, j, center[Geom::X], center[Geom::Y], w, h,
1277 shiftx_per_i, shifty_per_i,
1278 shiftx_per_j, shifty_per_j,
1279 shiftx_rand, shifty_rand,
1280 shiftx_exp, shifty_exp,
1281 shiftx_alternate, shifty_alternate,
1282 shiftx_cumulate, shifty_cumulate,
1283 shiftx_excludew, shifty_excludeh,
1284 scalex_per_i, scaley_per_i,
1285 scalex_per_j, scaley_per_j,
1286 scalex_rand, scaley_rand,
1287 scalex_exp, scaley_exp,
1288 scalex_log, scaley_log,
1289 scalex_alternate, scaley_alternate,
1290 scalex_cumulate, scaley_cumulate,
1291 rotate_per_i, rotate_per_j,
1292 rotate_rand,
1293 rotate_alternatei, rotate_alternatej,
1294 rotate_cumulatei, rotate_cumulatej );
1296 cur = center * t - center;
1297 if (fillrect) {
1298 if ((cur[Geom::X] > fillwidth) || (cur[Geom::Y] > fillheight)) { // off limits
1299 continue;
1300 }
1301 }
1303 gchar color_string[32]; *color_string = 0;
1305 // Color tab
1306 if (!initial_color.empty()) {
1307 guint32 rgba = sp_svg_read_color (initial_color.data(), 0x000000ff);
1308 float hsl[3];
1309 sp_color_rgb_to_hsl_floatv (hsl, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba));
1311 double eff_i = (color_alternatei? (i%2) : (i));
1312 double eff_j = (color_alternatej? (j%2) : (j));
1314 hsl[0] += hue_per_i * eff_i + hue_per_j * eff_j + hue_rand * g_random_double_range (-1, 1);
1315 double notused;
1316 hsl[0] = modf( hsl[0], ¬used ); // Restrict to 0-1
1317 hsl[1] += saturation_per_i * eff_i + saturation_per_j * eff_j + saturation_rand * g_random_double_range (-1, 1);
1318 hsl[1] = CLAMP (hsl[1], 0, 1);
1319 hsl[2] += lightness_per_i * eff_i + lightness_per_j * eff_j + lightness_rand * g_random_double_range (-1, 1);
1320 hsl[2] = CLAMP (hsl[2], 0, 1);
1322 float rgb[3];
1323 sp_color_hsl_to_rgb_floatv (rgb, hsl[0], hsl[1], hsl[2]);
1324 sp_svg_write_color(color_string, sizeof(color_string), SP_RGBA32_F_COMPOSE(rgb[0], rgb[1], rgb[2], 1.0));
1325 }
1327 // Blur
1328 double blur = 0.0;
1329 {
1330 int eff_i = (blur_alternatei? (i%2) : (i));
1331 int eff_j = (blur_alternatej? (j%2) : (j));
1332 blur = (blur_per_i * eff_i + blur_per_j * eff_j + blur_rand * g_random_double_range (-1, 1));
1333 blur = CLAMP (blur, 0, 1);
1334 }
1336 // Opacity
1337 double opacity = 1.0;
1338 {
1339 int eff_i = (opacity_alternatei? (i%2) : (i));
1340 int eff_j = (opacity_alternatej? (j%2) : (j));
1341 opacity = 1 - (opacity_per_i * eff_i + opacity_per_j * eff_j + opacity_rand * g_random_double_range (-1, 1));
1342 opacity = CLAMP (opacity, 0, 1);
1343 }
1345 // Trace tab
1346 if (dotrace) {
1347 Geom::Rect bbox_t = transform_rect (bbox_original, t);
1349 guint32 rgba = clonetiler_trace_pick (bbox_t);
1350 float r = SP_RGBA32_R_F(rgba);
1351 float g = SP_RGBA32_G_F(rgba);
1352 float b = SP_RGBA32_B_F(rgba);
1353 float a = SP_RGBA32_A_F(rgba);
1355 float hsl[3];
1356 sp_color_rgb_to_hsl_floatv (hsl, r, g, b);
1358 gdouble val = 0;
1359 switch (pick) {
1360 case PICK_COLOR:
1361 val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max
1362 break;
1363 case PICK_OPACITY:
1364 val = a;
1365 break;
1366 case PICK_R:
1367 val = r;
1368 break;
1369 case PICK_G:
1370 val = g;
1371 break;
1372 case PICK_B:
1373 val = b;
1374 break;
1375 case PICK_H:
1376 val = hsl[0];
1377 break;
1378 case PICK_S:
1379 val = hsl[1];
1380 break;
1381 case PICK_L:
1382 val = 1 - hsl[2];
1383 break;
1384 default:
1385 break;
1386 }
1388 if (rand_picked > 0) {
1389 val = randomize01 (val, rand_picked);
1390 r = randomize01 (r, rand_picked);
1391 g = randomize01 (g, rand_picked);
1392 b = randomize01 (b, rand_picked);
1393 }
1395 if (gamma_picked != 0) {
1396 double power;
1397 if (gamma_picked > 0)
1398 power = 1/(1 + fabs(gamma_picked));
1399 else
1400 power = 1 + fabs(gamma_picked);
1402 val = pow (val, power);
1403 r = pow (r, power);
1404 g = pow (g, power);
1405 b = pow (b, power);
1406 }
1408 if (invert_picked) {
1409 val = 1 - val;
1410 r = 1 - r;
1411 g = 1 - g;
1412 b = 1 - b;
1413 }
1415 val = CLAMP (val, 0, 1);
1416 r = CLAMP (r, 0, 1);
1417 g = CLAMP (g, 0, 1);
1418 b = CLAMP (b, 0, 1);
1420 // recompose tweaked color
1421 rgba = SP_RGBA32_F_COMPOSE(r, g, b, a);
1423 if (pick_to_presence) {
1424 if (g_random_double_range (0, 1) > val) {
1425 continue; // skip!
1426 }
1427 }
1428 if (pick_to_size) {
1429 t = Geom::Translate(-center[Geom::X], -center[Geom::Y]) * Geom::Scale (val, val) * Geom::Translate(center[Geom::X], center[Geom::Y]) * t;
1430 }
1431 if (pick_to_opacity) {
1432 opacity *= val;
1433 }
1434 if (pick_to_color) {
1435 sp_svg_write_color(color_string, sizeof(color_string), rgba);
1436 }
1437 }
1439 if (opacity < 1e-6) { // invisibly transparent, skip
1440 continue;
1441 }
1443 if (fabs(t[0]) + fabs (t[1]) + fabs(t[2]) + fabs(t[3]) < 1e-6) { // too small, skip
1444 continue;
1445 }
1447 // Create the clone
1448 Inkscape::XML::Node *clone = obj_repr->document()->createElement("svg:use");
1449 clone->setAttribute("x", "0");
1450 clone->setAttribute("y", "0");
1451 clone->setAttribute("inkscape:tiled-clone-of", id_href);
1452 clone->setAttribute("xlink:href", id_href);
1454 Geom::Point new_center;
1455 bool center_set = false;
1456 if (obj_repr->attribute("inkscape:transform-center-x") || obj_repr->attribute("inkscape:transform-center-y")) {
1457 new_center = desktop->dt2doc(SP_ITEM(obj)->getCenter()) * t;
1458 center_set = true;
1459 }
1461 gchar *affinestr=sp_svg_transform_write(t);
1462 clone->setAttribute("transform", affinestr);
1463 g_free(affinestr);
1465 if (opacity < 1.0) {
1466 sp_repr_set_css_double(clone, "opacity", opacity);
1467 }
1469 if (*color_string) {
1470 clone->setAttribute("fill", color_string);
1471 clone->setAttribute("stroke", color_string);
1472 }
1474 // add the new clone to the top of the original's parent
1475 SP_OBJECT_REPR(parent)->appendChild(clone);
1477 if (blur > 0.0) {
1478 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1479 double perimeter = perimeter_original * t.descrim();
1480 double radius = blur * perimeter;
1481 // this is necessary for all newly added clones to have correct bboxes,
1482 // otherwise filters won't work:
1483 sp_document_ensure_up_to_date(sp_desktop_document(desktop));
1484 // it's hard to figure out exact width/height of the tile without having an object
1485 // that we can take bbox of; however here we only need a lower bound so that blur
1486 // margins are not too small, and the perimeter should work
1487 SPFilter *constructed = new_filter_gaussian_blur(sp_desktop_document(desktop), radius, t.descrim(), t.expansionX(), t.expansionY(), perimeter, perimeter);
1488 sp_style_set_property_url (clone_object, "filter", SP_OBJECT(constructed), false);
1489 }
1491 if (center_set) {
1492 SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone);
1493 if (clone_object && SP_IS_ITEM(clone_object)) {
1494 clone_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1495 SP_ITEM(clone_object)->setCenter(desktop->doc2dt(new_center));
1496 clone_object->updateRepr();
1497 }
1498 }
1500 Inkscape::GC::release(clone);
1501 }
1502 cur[Geom::Y] = 0;
1503 }
1505 if (dotrace) {
1506 clonetiler_trace_finish ();
1507 }
1509 clonetiler_change_selection (NULL, selection, dlg);
1511 desktop->clearWaitingCursor();
1513 sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER,
1514 _("Create tiled clones"));
1515 }
1517 static GtkWidget *
1518 clonetiler_new_tab (GtkWidget *nb, const gchar *label)
1519 {
1520 GtkWidget *l = gtk_label_new_with_mnemonic (label);
1521 GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN);
1522 gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN);
1523 gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l);
1524 return vb;
1525 }
1527 static void
1528 clonetiler_checkbox_toggled (GtkToggleButton *tb, gpointer *data)
1529 {
1530 const gchar *attr = (const gchar *) data;
1531 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1532 prefs->setBool(prefs_path + attr, gtk_toggle_button_get_active(tb));
1533 }
1535 static GtkWidget *
1536 clonetiler_checkbox (GtkTooltips *tt, const char *tip, const char *attr)
1537 {
1538 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
1540 GtkWidget *b = gtk_check_button_new ();
1541 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, tip, NULL);
1543 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1544 bool value = prefs->getBool(prefs_path + attr);
1545 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(b), value);
1547 gtk_box_pack_end (GTK_BOX (hb), b, FALSE, TRUE, 0);
1548 gtk_signal_connect ( GTK_OBJECT (b), "clicked",
1549 GTK_SIGNAL_FUNC (clonetiler_checkbox_toggled), (gpointer) attr);
1551 g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
1553 return hb;
1554 }
1557 static void
1558 clonetiler_value_changed (GtkAdjustment *adj, gpointer data)
1559 {
1560 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1561 const gchar *pref = (const gchar *) data;
1562 prefs->setDouble(prefs_path + pref, adj->value);
1563 }
1565 static GtkWidget *
1566 clonetiler_spinbox (GtkTooltips *tt, const char *tip, const char *attr, double lower, double upper, const gchar *suffix, bool exponent = false)
1567 {
1568 GtkWidget *hb = gtk_hbox_new(FALSE, 0);
1570 {
1571 GtkObject *a;
1572 if (exponent)
1573 a = gtk_adjustment_new(1.0, lower, upper, 0.01, 0.05, 0.1);
1574 else
1575 a = gtk_adjustment_new(0.0, lower, upper, 0.1, 0.5, 2);
1577 GtkWidget *sb;
1578 if (exponent)
1579 sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.01, 2);
1580 else
1581 sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.1, 1);
1583 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, tip, NULL);
1584 gtk_entry_set_width_chars (GTK_ENTRY (sb), 4);
1585 gtk_box_pack_start (GTK_BOX (hb), sb, FALSE, FALSE, SB_MARGIN);
1587 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1588 double value = prefs->getDoubleLimited(prefs_path + attr, exponent? 1.0 : 0.0, lower, upper);
1589 gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
1590 gtk_signal_connect(GTK_OBJECT(a), "value_changed",
1591 GTK_SIGNAL_FUNC(clonetiler_value_changed), (gpointer) attr);
1593 if (exponent)
1594 g_object_set_data (G_OBJECT(sb), "oneable", GINT_TO_POINTER(TRUE));
1595 else
1596 g_object_set_data (G_OBJECT(sb), "zeroable", GINT_TO_POINTER(TRUE));
1597 }
1599 {
1600 GtkWidget *l = gtk_label_new ("");
1601 gtk_label_set_markup (GTK_LABEL(l), suffix);
1602 gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0);
1603 gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
1604 }
1606 return hb;
1607 }
1609 static void
1610 clonetiler_symgroup_changed( GtkMenuItem */*item*/, gpointer data )
1611 {
1612 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1613 gint group_new = GPOINTER_TO_INT (data);
1614 prefs->setInt(prefs_path + "symmetrygroup", group_new);
1615 }
1617 static void
1618 clonetiler_xy_changed (GtkAdjustment *adj, gpointer data)
1619 {
1620 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1621 const gchar *pref = (const gchar *) data;
1622 prefs->setInt(prefs_path + pref, (int) floor(adj->value + 0.5));
1623 }
1625 static void
1626 clonetiler_keep_bbox_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1627 {
1628 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1629 prefs->setBool(prefs_path + "keepbbox", gtk_toggle_button_get_active(tb));
1630 }
1632 static void
1633 clonetiler_pick_to (GtkToggleButton *tb, gpointer data)
1634 {
1635 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1636 const gchar *pref = (const gchar *) data;
1637 prefs->setBool(prefs_path + pref, gtk_toggle_button_get_active(tb));
1638 }
1641 static void
1642 clonetiler_reset_recursive (GtkWidget *w)
1643 {
1644 if (w && GTK_IS_OBJECT(w)) {
1645 {
1646 int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "zeroable"));
1647 if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1648 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1649 gtk_adjustment_set_value (a, 0);
1650 }
1651 }
1652 {
1653 int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "oneable"));
1654 if (r && GTK_IS_SPIN_BUTTON(w)) { // spinbutton
1655 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(w));
1656 gtk_adjustment_set_value (a, 1);
1657 }
1658 }
1659 {
1660 int r = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT(w), "uncheckable"));
1661 if (r && GTK_IS_TOGGLE_BUTTON(w)) { // checkbox
1662 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(w), FALSE);
1663 }
1664 }
1665 }
1667 if (GTK_IS_CONTAINER(w)) {
1668 GList *ch = gtk_container_get_children (GTK_CONTAINER(w));
1669 for (GList *i = ch; i != NULL; i = i->next) {
1670 clonetiler_reset_recursive (GTK_WIDGET(i->data));
1671 }
1672 g_list_free (ch);
1673 }
1674 }
1676 static void
1677 clonetiler_reset( GtkWidget */*widget*/, void * )
1678 {
1679 clonetiler_reset_recursive (dlg);
1680 }
1682 static void
1683 clonetiler_table_attach (GtkWidget *table, GtkWidget *widget, float align, int row, int col)
1684 {
1685 GtkWidget *a = gtk_alignment_new (align, 0, 0, 0);
1686 gtk_container_add(GTK_CONTAINER(a), widget);
1687 gtk_table_attach ( GTK_TABLE (table), a, col, col + 1, row, row + 1, (GtkAttachOptions)4, (GtkAttachOptions)0, 0, 0 );
1688 }
1690 static GtkWidget *
1691 clonetiler_table_x_y_rand (int values)
1692 {
1693 GtkWidget *table = gtk_table_new (values + 2, 5, FALSE);
1694 gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
1695 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
1696 gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1698 {
1699 GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1701 GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, INKSCAPE_ICON_OBJECT_ROWS);
1702 gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1704 GtkWidget *l = gtk_label_new ("");
1705 gtk_label_set_markup (GTK_LABEL(l), _("<small>Per row:</small>"));
1706 gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1708 clonetiler_table_attach (table, hb, 0, 1, 2);
1709 }
1711 {
1712 GtkWidget *hb = gtk_hbox_new (FALSE, 0);
1714 GtkWidget *i = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, INKSCAPE_ICON_OBJECT_COLUMNS);
1715 gtk_box_pack_start (GTK_BOX (hb), i, FALSE, FALSE, 2);
1717 GtkWidget *l = gtk_label_new ("");
1718 gtk_label_set_markup (GTK_LABEL(l), _("<small>Per column:</small>"));
1719 gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 2);
1721 clonetiler_table_attach (table, hb, 0, 1, 3);
1722 }
1724 {
1725 GtkWidget *l = gtk_label_new ("");
1726 gtk_label_set_markup (GTK_LABEL(l), _("<small>Randomize:</small>"));
1727 clonetiler_table_attach (table, l, 0, 1, 4);
1728 }
1730 return table;
1731 }
1733 static void
1734 clonetiler_pick_switched( GtkToggleButton */*tb*/, gpointer data )
1735 {
1736 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1737 guint v = GPOINTER_TO_INT (data);
1738 prefs->setInt(prefs_path + "pick", v);
1739 }
1742 static void
1743 clonetiler_switch_to_create( GtkToggleButton */*tb*/, GtkWidget *dlg )
1744 {
1745 GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1746 GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1748 if (rowscols) {
1749 gtk_widget_set_sensitive (rowscols, TRUE);
1750 }
1751 if (widthheight) {
1752 gtk_widget_set_sensitive (widthheight, FALSE);
1753 }
1755 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1756 prefs->setBool(prefs_path + "fillrect", false);
1757 }
1760 static void
1761 clonetiler_switch_to_fill( GtkToggleButton */*tb*/, GtkWidget *dlg )
1762 {
1763 GtkWidget *rowscols = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "rowscols");
1764 GtkWidget *widthheight = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "widthheight");
1766 if (rowscols) {
1767 gtk_widget_set_sensitive (rowscols, FALSE);
1768 }
1769 if (widthheight) {
1770 gtk_widget_set_sensitive (widthheight, TRUE);
1771 }
1773 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1774 prefs->setBool(prefs_path + "fillrect", true);
1775 }
1780 static void
1781 clonetiler_fill_width_changed (GtkAdjustment *adj, GtkWidget *u)
1782 {
1783 gdouble const raw_dist = adj->value;
1784 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1785 gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1787 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1788 prefs->setDouble(prefs_path + "fillwidth", pixels);
1789 }
1791 static void
1792 clonetiler_fill_height_changed (GtkAdjustment *adj, GtkWidget *u)
1793 {
1794 gdouble const raw_dist = adj->value;
1795 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
1796 gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
1798 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1799 prefs->setDouble(prefs_path + "fillheight", pixels);
1800 }
1803 static void
1804 clonetiler_do_pick_toggled( GtkToggleButton *tb, gpointer /*data*/ )
1805 {
1806 GtkWidget *vvb = (GtkWidget *) g_object_get_data (G_OBJECT(dlg), "dotrace");
1808 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1809 prefs->setBool(prefs_path + "dotrace", gtk_toggle_button_get_active (tb));
1811 if (vvb)
1812 gtk_widget_set_sensitive (vvb, gtk_toggle_button_get_active (tb));
1813 }
1818 void
1819 clonetiler_dialog (void)
1820 {
1821 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1822 if (!dlg)
1823 {
1824 gchar title[500];
1825 sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_CLONETILER), title);
1827 dlg = sp_window_new (title, TRUE);
1828 if (x == -1000 || y == -1000) {
1829 x = prefs->getInt(prefs_path + "x", -1000);
1830 y = prefs->getInt(prefs_path + "y", -1000);
1831 }
1833 if (w ==0 || h == 0) {
1834 w = prefs->getInt(prefs_path + "w", 0);
1835 h = prefs->getInt(prefs_path + "h", 0);
1836 }
1838 // if (x<0) x=0;
1839 // if (y<0) y=0;
1841 if (w && h) {
1842 gtk_window_resize ((GtkWindow *) dlg, w, h);
1843 }
1844 if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) {
1845 gtk_window_move ((GtkWindow *) dlg, x, y);
1847 } else {
1848 gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
1849 }
1852 sp_transientize (dlg);
1853 wd.win = dlg;
1854 wd.stop = 0;
1857 gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);
1859 gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (clonetiler_dialog_destroy), dlg);
1860 gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (clonetiler_dialog_delete), dlg);
1862 if (Inkscape::NSApplication::Application::getNewGui())
1863 {
1864 _shutdown_connection = Inkscape::NSApplication::Editor::connectShutdown (&on_delete);
1865 _dialogs_hidden_connection = Inkscape::NSApplication::Editor::connectDialogsHidden (sigc::bind (&on_dialog_hide, dlg));
1866 _dialogs_unhidden_connection = Inkscape::NSApplication::Editor::connectDialogsUnhidden (sigc::bind (&on_dialog_unhide, dlg));
1867 _desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::bind (&on_transientize, &wd));
1868 } else {
1869 g_signal_connect ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (clonetiler_dialog_delete), dlg);
1870 g_signal_connect ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg);
1871 g_signal_connect ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg);
1872 g_signal_connect ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd);
1873 }
1875 GtkTooltips *tt = gtk_tooltips_new();
1877 GtkWidget *mainbox = gtk_vbox_new(FALSE, 4);
1878 gtk_container_set_border_width (GTK_CONTAINER (mainbox), 6);
1879 gtk_container_add (GTK_CONTAINER (dlg), mainbox);
1881 GtkWidget *nb = gtk_notebook_new ();
1882 gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0);
1885 // Symmetry
1886 {
1887 GtkWidget *vb = clonetiler_new_tab (nb, _("_Symmetry"));
1889 GtkWidget *om = gtk_option_menu_new ();
1890 /* TRANSLATORS: For the following 17 symmetry groups, see
1891 * http://www.bib.ulb.ac.be/coursmath/doc/17.htm (visual examples);
1892 * http://www.clarku.edu/~djoyce/wallpaper/seventeen.html (English vocabulary); or
1893 * http://membres.lycos.fr/villemingerard/Geometri/Sym1D.htm (French vocabulary).
1894 */
1895 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), om, _("Select one of the 17 symmetry groups for the tiling"), NULL);
1896 gtk_box_pack_start (GTK_BOX (vb), om, FALSE, FALSE, SB_MARGIN);
1898 GtkWidget *m = gtk_menu_new ();
1899 int current = prefs->getInt(prefs_path + "symmetrygroup", 0);
1901 struct SymGroups {
1902 int group;
1903 gchar const *label;
1904 } const sym_groups[] = {
1905 // TRANSLATORS: "translation" means "shift" / "displacement" here.
1906 {TILE_P1, _("<b>P1</b>: simple translation")},
1907 {TILE_P2, _("<b>P2</b>: 180° rotation")},
1908 {TILE_PM, _("<b>PM</b>: reflection")},
1909 // TRANSLATORS: "glide reflection" is a reflection and a translation combined.
1910 // For more info, see http://mathforum.org/sum95/suzanne/symsusan.html
1911 {TILE_PG, _("<b>PG</b>: glide reflection")},
1912 {TILE_CM, _("<b>CM</b>: reflection + glide reflection")},
1913 {TILE_PMM, _("<b>PMM</b>: reflection + reflection")},
1914 {TILE_PMG, _("<b>PMG</b>: reflection + 180° rotation")},
1915 {TILE_PGG, _("<b>PGG</b>: glide reflection + 180° rotation")},
1916 {TILE_CMM, _("<b>CMM</b>: reflection + reflection + 180° rotation")},
1917 {TILE_P4, _("<b>P4</b>: 90° rotation")},
1918 {TILE_P4M, _("<b>P4M</b>: 90° rotation + 45° reflection")},
1919 {TILE_P4G, _("<b>P4G</b>: 90° rotation + 90° reflection")},
1920 {TILE_P3, _("<b>P3</b>: 120° rotation")},
1921 {TILE_P31M, _("<b>P31M</b>: reflection + 120° rotation, dense")},
1922 {TILE_P3M1, _("<b>P3M1</b>: reflection + 120° rotation, sparse")},
1923 {TILE_P6, _("<b>P6</b>: 60° rotation")},
1924 {TILE_P6M, _("<b>P6M</b>: reflection + 60° rotation")},
1925 };
1927 for (unsigned j = 0; j < G_N_ELEMENTS(sym_groups); ++j) {
1928 SymGroups const &sg = sym_groups[j];
1930 GtkWidget *l = gtk_label_new ("");
1931 gtk_label_set_markup (GTK_LABEL(l), sg.label);
1932 gtk_misc_set_alignment (GTK_MISC(l), 0, 0.5);
1934 GtkWidget *item = gtk_menu_item_new ();
1935 gtk_container_add (GTK_CONTAINER (item), l);
1937 gtk_signal_connect ( GTK_OBJECT (item), "activate",
1938 GTK_SIGNAL_FUNC (clonetiler_symgroup_changed),
1939 GINT_TO_POINTER (sg.group) );
1941 gtk_menu_append (GTK_MENU (m), item);
1942 }
1944 gtk_option_menu_set_menu (GTK_OPTION_MENU (om), m);
1945 gtk_option_menu_set_history ( GTK_OPTION_MENU (om), current);
1946 }
1948 table_row_labels = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1950 // Shift
1951 {
1952 GtkWidget *vb = clonetiler_new_tab (nb, _("S_hift"));
1954 GtkWidget *table = clonetiler_table_x_y_rand (3);
1955 gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
1957 // X
1958 {
1959 GtkWidget *l = gtk_label_new ("");
1960 // TRANSLATORS: "shift" means: the tiles will be shifted (offset) horizontally by this amount
1961 // xgettext:no-c-format
1962 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift X:</b>"));
1963 gtk_size_group_add_widget(table_row_labels, l);
1964 clonetiler_table_attach (table, l, 1, 2, 1);
1965 }
1967 {
1968 GtkWidget *l = clonetiler_spinbox (tt,
1969 // xgettext:no-c-format
1970 _("Horizontal shift per row (in % of tile width)"), "shiftx_per_j",
1971 -10000, 10000, "%");
1972 clonetiler_table_attach (table, l, 0, 2, 2);
1973 }
1975 {
1976 GtkWidget *l = clonetiler_spinbox (tt,
1977 // xgettext:no-c-format
1978 _("Horizontal shift per column (in % of tile width)"), "shiftx_per_i",
1979 -10000, 10000, "%");
1980 clonetiler_table_attach (table, l, 0, 2, 3);
1981 }
1983 {
1984 GtkWidget *l = clonetiler_spinbox (tt,
1985 _("Randomize the horizontal shift by this percentage"), "shiftx_rand",
1986 0, 1000, "%");
1987 clonetiler_table_attach (table, l, 0, 2, 4);
1988 }
1990 // Y
1991 {
1992 GtkWidget *l = gtk_label_new ("");
1993 // TRANSLATORS: "shift" means: the tiles will be shifted (offset) vertically by this amount
1994 // xgettext:no-c-format
1995 gtk_label_set_markup (GTK_LABEL(l), _("<b>Shift Y:</b>"));
1996 gtk_size_group_add_widget(table_row_labels, l);
1997 clonetiler_table_attach (table, l, 1, 3, 1);
1998 }
2000 {
2001 GtkWidget *l = clonetiler_spinbox (tt,
2002 // xgettext:no-c-format
2003 _("Vertical shift per row (in % of tile height)"), "shifty_per_j",
2004 -10000, 10000, "%");
2005 clonetiler_table_attach (table, l, 0, 3, 2);
2006 }
2008 {
2009 GtkWidget *l = clonetiler_spinbox (tt,
2010 // xgettext:no-c-format
2011 _("Vertical shift per column (in % of tile height)"), "shifty_per_i",
2012 -10000, 10000, "%");
2013 clonetiler_table_attach (table, l, 0, 3, 3);
2014 }
2016 {
2017 GtkWidget *l = clonetiler_spinbox (tt,
2018 _("Randomize the vertical shift by this percentage"), "shifty_rand",
2019 0, 1000, "%");
2020 clonetiler_table_attach (table, l, 0, 3, 4);
2021 }
2023 // Exponent
2024 {
2025 GtkWidget *l = gtk_label_new ("");
2026 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2027 gtk_size_group_add_widget(table_row_labels, l);
2028 clonetiler_table_attach (table, l, 1, 4, 1);
2029 }
2031 {
2032 GtkWidget *l = clonetiler_spinbox (tt,
2033 _("Whether rows are spaced evenly (1), converge (<1) or diverge (>1)"), "shifty_exp",
2034 0, 10, "", true);
2035 clonetiler_table_attach (table, l, 0, 4, 2);
2036 }
2038 {
2039 GtkWidget *l = clonetiler_spinbox (tt,
2040 _("Whether columns are spaced evenly (1), converge (<1) or diverge (>1)"), "shiftx_exp",
2041 0, 10, "", true);
2042 clonetiler_table_attach (table, l, 0, 4, 3);
2043 }
2045 { // alternates
2046 GtkWidget *l = gtk_label_new ("");
2047 // TRANSLATORS: "Alternate" is a verb here
2048 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2049 gtk_size_group_add_widget(table_row_labels, l);
2050 clonetiler_table_attach (table, l, 1, 5, 1);
2051 }
2053 {
2054 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each row"), "shifty_alternate");
2055 clonetiler_table_attach (table, l, 0, 5, 2);
2056 }
2058 {
2059 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of shifts for each column"), "shiftx_alternate");
2060 clonetiler_table_attach (table, l, 0, 5, 3);
2061 }
2063 { // Cumulate
2064 GtkWidget *l = gtk_label_new ("");
2065 // TRANSLATORS: "Cumulate" is a verb here
2066 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2067 gtk_size_group_add_widget(table_row_labels, l);
2068 clonetiler_table_attach (table, l, 1, 6, 1);
2069 }
2071 {
2072 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each row"), "shifty_cumulate");
2073 clonetiler_table_attach (table, l, 0, 6, 2);
2074 }
2076 {
2077 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the shifts for each column"), "shiftx_cumulate");
2078 clonetiler_table_attach (table, l, 0, 6, 3);
2079 }
2081 { // Exclude tile width and height in shift
2082 GtkWidget *l = gtk_label_new ("");
2083 // TRANSLATORS: "Cumulate" is a verb here
2084 gtk_label_set_markup (GTK_LABEL(l), _("<small>Exclude tile:</small>"));
2085 gtk_size_group_add_widget(table_row_labels, l);
2086 clonetiler_table_attach (table, l, 1, 7, 1);
2087 }
2089 {
2090 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile height in shift"), "shifty_excludeh");
2091 clonetiler_table_attach (table, l, 0, 7, 2);
2092 }
2094 {
2095 GtkWidget *l = clonetiler_checkbox (tt, _("Exclude tile width in shift"), "shiftx_excludew");
2096 clonetiler_table_attach (table, l, 0, 7, 3);
2097 }
2099 }
2102 // Scale
2103 {
2104 GtkWidget *vb = clonetiler_new_tab (nb, _("Sc_ale"));
2106 GtkWidget *table = clonetiler_table_x_y_rand (2);
2107 gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2109 // X
2110 {
2111 GtkWidget *l = gtk_label_new ("");
2112 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale X:</b>"));
2113 gtk_size_group_add_widget(table_row_labels, l);
2114 clonetiler_table_attach (table, l, 1, 2, 1);
2115 }
2117 {
2118 GtkWidget *l = clonetiler_spinbox (tt,
2119 // xgettext:no-c-format
2120 _("Horizontal scale per row (in % of tile width)"), "scalex_per_j",
2121 -100, 1000, "%");
2122 clonetiler_table_attach (table, l, 0, 2, 2);
2123 }
2125 {
2126 GtkWidget *l = clonetiler_spinbox (tt,
2127 // xgettext:no-c-format
2128 _("Horizontal scale per column (in % of tile width)"), "scalex_per_i",
2129 -100, 1000, "%");
2130 clonetiler_table_attach (table, l, 0, 2, 3);
2131 }
2133 {
2134 GtkWidget *l = clonetiler_spinbox (tt,
2135 _("Randomize the horizontal scale by this percentage"), "scalex_rand",
2136 0, 1000, "%");
2137 clonetiler_table_attach (table, l, 0, 2, 4);
2138 }
2140 // Y
2141 {
2142 GtkWidget *l = gtk_label_new ("");
2143 gtk_label_set_markup (GTK_LABEL(l), _("<b>Scale Y:</b>"));
2144 gtk_size_group_add_widget(table_row_labels, l);
2145 clonetiler_table_attach (table, l, 1, 3, 1);
2146 }
2148 {
2149 GtkWidget *l = clonetiler_spinbox (tt,
2150 // xgettext:no-c-format
2151 _("Vertical scale per row (in % of tile height)"), "scaley_per_j",
2152 -100, 1000, "%");
2153 clonetiler_table_attach (table, l, 0, 3, 2);
2154 }
2156 {
2157 GtkWidget *l = clonetiler_spinbox (tt,
2158 // xgettext:no-c-format
2159 _("Vertical scale per column (in % of tile height)"), "scaley_per_i",
2160 -100, 1000, "%");
2161 clonetiler_table_attach (table, l, 0, 3, 3);
2162 }
2164 {
2165 GtkWidget *l = clonetiler_spinbox (tt,
2166 _("Randomize the vertical scale by this percentage"), "scaley_rand",
2167 0, 1000, "%");
2168 clonetiler_table_attach (table, l, 0, 3, 4);
2169 }
2171 // Exponent
2172 {
2173 GtkWidget *l = gtk_label_new ("");
2174 gtk_label_set_markup (GTK_LABEL(l), _("<b>Exponent:</b>"));
2175 gtk_size_group_add_widget(table_row_labels, l);
2176 clonetiler_table_attach (table, l, 1, 4, 1);
2177 }
2179 {
2180 GtkWidget *l = clonetiler_spinbox (tt,
2181 _("Whether row scaling is uniform (1), converge (<1) or diverge (>1)"), "scaley_exp",
2182 0, 10, "", true);
2183 clonetiler_table_attach (table, l, 0, 4, 2);
2184 }
2186 {
2187 GtkWidget *l = clonetiler_spinbox (tt,
2188 _("Whether column scaling is uniform (1), converge (<1) or diverge (>1)"), "scalex_exp",
2189 0, 10, "", true);
2190 clonetiler_table_attach (table, l, 0, 4, 3);
2191 }
2193 // Logarithmic (as in logarithmic spiral)
2194 {
2195 GtkWidget *l = gtk_label_new ("");
2196 gtk_label_set_markup (GTK_LABEL(l), _("<b>Base:</b>"));
2197 gtk_size_group_add_widget(table_row_labels, l);
2198 clonetiler_table_attach (table, l, 1, 5, 1);
2199 }
2201 {
2202 GtkWidget *l = clonetiler_spinbox (tt,
2203 _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scaley_log",
2204 0, 10, "", false);
2205 clonetiler_table_attach (table, l, 0, 5, 2);
2206 }
2208 {
2209 GtkWidget *l = clonetiler_spinbox (tt,
2210 _("Base for a logarithmic spiral: not used (0), converge (<1), or diverge (>1)"), "scalex_log",
2211 0, 10, "", false);
2212 clonetiler_table_attach (table, l, 0, 5, 3);
2213 }
2215 { // alternates
2216 GtkWidget *l = gtk_label_new ("");
2217 // TRANSLATORS: "Alternate" is a verb here
2218 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2219 gtk_size_group_add_widget(table_row_labels, l);
2220 clonetiler_table_attach (table, l, 1, 6, 1);
2221 }
2223 {
2224 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each row"), "scaley_alternate");
2225 clonetiler_table_attach (table, l, 0, 6, 2);
2226 }
2228 {
2229 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of scales for each column"), "scalex_alternate");
2230 clonetiler_table_attach (table, l, 0, 6, 3);
2231 }
2233 { // Cumulate
2234 GtkWidget *l = gtk_label_new ("");
2235 // TRANSLATORS: "Cumulate" is a verb here
2236 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2237 gtk_size_group_add_widget(table_row_labels, l);
2238 clonetiler_table_attach (table, l, 1, 7, 1);
2239 }
2241 {
2242 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each row"), "scaley_cumulate");
2243 clonetiler_table_attach (table, l, 0, 7, 2);
2244 }
2246 {
2247 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the scales for each column"), "scalex_cumulate");
2248 clonetiler_table_attach (table, l, 0, 7, 3);
2249 }
2251 }
2254 // Rotation
2255 {
2256 GtkWidget *vb = clonetiler_new_tab (nb, _("_Rotation"));
2258 GtkWidget *table = clonetiler_table_x_y_rand (1);
2259 gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2261 // Angle
2262 {
2263 GtkWidget *l = gtk_label_new ("");
2264 gtk_label_set_markup (GTK_LABEL(l), _("<b>Angle:</b>"));
2265 gtk_size_group_add_widget(table_row_labels, l);
2266 clonetiler_table_attach (table, l, 1, 2, 1);
2267 }
2269 {
2270 GtkWidget *l = clonetiler_spinbox (tt,
2271 // xgettext:no-c-format
2272 _("Rotate tiles by this angle for each row"), "rotate_per_j",
2273 -180, 180, "°");
2274 clonetiler_table_attach (table, l, 0, 2, 2);
2275 }
2277 {
2278 GtkWidget *l = clonetiler_spinbox (tt,
2279 // xgettext:no-c-format
2280 _("Rotate tiles by this angle for each column"), "rotate_per_i",
2281 -180, 180, "°");
2282 clonetiler_table_attach (table, l, 0, 2, 3);
2283 }
2285 {
2286 GtkWidget *l = clonetiler_spinbox (tt,
2287 _("Randomize the rotation angle by this percentage"), "rotate_rand",
2288 0, 100, "%");
2289 clonetiler_table_attach (table, l, 0, 2, 4);
2290 }
2292 { // alternates
2293 GtkWidget *l = gtk_label_new ("");
2294 // TRANSLATORS: "Alternate" is a verb here
2295 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2296 gtk_size_group_add_widget(table_row_labels, l);
2297 clonetiler_table_attach (table, l, 1, 3, 1);
2298 }
2300 {
2301 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each row"), "rotate_alternatej");
2302 clonetiler_table_attach (table, l, 0, 3, 2);
2303 }
2305 {
2306 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the rotation direction for each column"), "rotate_alternatei");
2307 clonetiler_table_attach (table, l, 0, 3, 3);
2308 }
2310 { // Cumulate
2311 GtkWidget *l = gtk_label_new ("");
2312 // TRANSLATORS: "Cumulate" is a verb here
2313 gtk_label_set_markup (GTK_LABEL(l), _("<small>Cumulate:</small>"));
2314 gtk_size_group_add_widget(table_row_labels, l);
2315 clonetiler_table_attach (table, l, 1, 4, 1);
2316 }
2318 {
2319 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each row"), "rotate_cumulatej");
2320 clonetiler_table_attach (table, l, 0, 4, 2);
2321 }
2323 {
2324 GtkWidget *l = clonetiler_checkbox (tt, _("Cumulate the rotation for each column"), "rotate_cumulatei");
2325 clonetiler_table_attach (table, l, 0, 4, 3);
2326 }
2328 }
2331 // Blur and opacity
2332 {
2333 GtkWidget *vb = clonetiler_new_tab (nb, _("_Blur & opacity"));
2335 GtkWidget *table = clonetiler_table_x_y_rand (1);
2336 gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2339 // Blur
2340 {
2341 GtkWidget *l = gtk_label_new ("");
2342 gtk_label_set_markup (GTK_LABEL(l), _("<b>Blur:</b>"));
2343 gtk_size_group_add_widget(table_row_labels, l);
2344 clonetiler_table_attach (table, l, 1, 2, 1);
2345 }
2347 {
2348 GtkWidget *l = clonetiler_spinbox (tt,
2349 _("Blur tiles by this percentage for each row"), "blur_per_j",
2350 0, 100, "%");
2351 clonetiler_table_attach (table, l, 0, 2, 2);
2352 }
2354 {
2355 GtkWidget *l = clonetiler_spinbox (tt,
2356 _("Blur tiles by this percentage for each column"), "blur_per_i",
2357 0, 100, "%");
2358 clonetiler_table_attach (table, l, 0, 2, 3);
2359 }
2361 {
2362 GtkWidget *l = clonetiler_spinbox (tt,
2363 _("Randomize the tile blur by this percentage"), "blur_rand",
2364 0, 100, "%");
2365 clonetiler_table_attach (table, l, 0, 2, 4);
2366 }
2368 { // alternates
2369 GtkWidget *l = gtk_label_new ("");
2370 // TRANSLATORS: "Alternate" is a verb here
2371 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2372 gtk_size_group_add_widget(table_row_labels, l);
2373 clonetiler_table_attach (table, l, 1, 3, 1);
2374 }
2376 {
2377 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each row"), "blur_alternatej");
2378 clonetiler_table_attach (table, l, 0, 3, 2);
2379 }
2381 {
2382 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of blur change for each column"), "blur_alternatei");
2383 clonetiler_table_attach (table, l, 0, 3, 3);
2384 }
2388 // Dissolve
2389 {
2390 GtkWidget *l = gtk_label_new ("");
2391 gtk_label_set_markup (GTK_LABEL(l), _("<b>Fade out:</b>"));
2392 gtk_size_group_add_widget(table_row_labels, l);
2393 clonetiler_table_attach (table, l, 1, 4, 1);
2394 }
2396 {
2397 GtkWidget *l = clonetiler_spinbox (tt,
2398 _("Decrease tile opacity by this percentage for each row"), "opacity_per_j",
2399 0, 100, "%");
2400 clonetiler_table_attach (table, l, 0, 4, 2);
2401 }
2403 {
2404 GtkWidget *l = clonetiler_spinbox (tt,
2405 _("Decrease tile opacity by this percentage for each column"), "opacity_per_i",
2406 0, 100, "%");
2407 clonetiler_table_attach (table, l, 0, 4, 3);
2408 }
2410 {
2411 GtkWidget *l = clonetiler_spinbox (tt,
2412 _("Randomize the tile opacity by this percentage"), "opacity_rand",
2413 0, 100, "%");
2414 clonetiler_table_attach (table, l, 0, 4, 4);
2415 }
2417 { // alternates
2418 GtkWidget *l = gtk_label_new ("");
2419 // TRANSLATORS: "Alternate" is a verb here
2420 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2421 gtk_size_group_add_widget(table_row_labels, l);
2422 clonetiler_table_attach (table, l, 1, 5, 1);
2423 }
2425 {
2426 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each row"), "opacity_alternatej");
2427 clonetiler_table_attach (table, l, 0, 5, 2);
2428 }
2430 {
2431 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of opacity change for each column"), "opacity_alternatei");
2432 clonetiler_table_attach (table, l, 0, 5, 3);
2433 }
2434 }
2437 // Color
2438 {
2439 GtkWidget *vb = clonetiler_new_tab (nb, _("Co_lor"));
2441 {
2442 GtkWidget *hb = gtk_hbox_new (FALSE, 0);
2444 GtkWidget *l = gtk_label_new (_("Initial color: "));
2445 gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2447 guint32 rgba = 0x000000ff | sp_svg_read_color (prefs->getString(prefs_path + "initial_color").data(), 0x000000ff);
2448 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);
2449 _color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed));
2451 gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast<GtkWidget*>(color_picker->gobj()), FALSE, FALSE, 0);
2453 gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2454 }
2457 GtkWidget *table = clonetiler_table_x_y_rand (3);
2458 gtk_box_pack_start (GTK_BOX (vb), table, FALSE, FALSE, 0);
2460 // Hue
2461 {
2462 GtkWidget *l = gtk_label_new ("");
2463 gtk_label_set_markup (GTK_LABEL(l), _("<b>H:</b>"));
2464 gtk_size_group_add_widget(table_row_labels, l);
2465 clonetiler_table_attach (table, l, 1, 2, 1);
2466 }
2468 {
2469 GtkWidget *l = clonetiler_spinbox (tt,
2470 _("Change the tile hue by this percentage for each row"), "hue_per_j",
2471 -100, 100, "%");
2472 clonetiler_table_attach (table, l, 0, 2, 2);
2473 }
2475 {
2476 GtkWidget *l = clonetiler_spinbox (tt,
2477 _("Change the tile hue by this percentage for each column"), "hue_per_i",
2478 -100, 100, "%");
2479 clonetiler_table_attach (table, l, 0, 2, 3);
2480 }
2482 {
2483 GtkWidget *l = clonetiler_spinbox (tt,
2484 _("Randomize the tile hue by this percentage"), "hue_rand",
2485 0, 100, "%");
2486 clonetiler_table_attach (table, l, 0, 2, 4);
2487 }
2490 // Saturation
2491 {
2492 GtkWidget *l = gtk_label_new ("");
2493 gtk_label_set_markup (GTK_LABEL(l), _("<b>S:</b>"));
2494 gtk_size_group_add_widget(table_row_labels, l);
2495 clonetiler_table_attach (table, l, 1, 3, 1);
2496 }
2498 {
2499 GtkWidget *l = clonetiler_spinbox (tt,
2500 _("Change the color saturation by this percentage for each row"), "saturation_per_j",
2501 -100, 100, "%");
2502 clonetiler_table_attach (table, l, 0, 3, 2);
2503 }
2505 {
2506 GtkWidget *l = clonetiler_spinbox (tt,
2507 _("Change the color saturation by this percentage for each column"), "saturation_per_i",
2508 -100, 100, "%");
2509 clonetiler_table_attach (table, l, 0, 3, 3);
2510 }
2512 {
2513 GtkWidget *l = clonetiler_spinbox (tt,
2514 _("Randomize the color saturation by this percentage"), "saturation_rand",
2515 0, 100, "%");
2516 clonetiler_table_attach (table, l, 0, 3, 4);
2517 }
2519 // Lightness
2520 {
2521 GtkWidget *l = gtk_label_new ("");
2522 gtk_label_set_markup (GTK_LABEL(l), _("<b>L:</b>"));
2523 gtk_size_group_add_widget(table_row_labels, l);
2524 clonetiler_table_attach (table, l, 1, 4, 1);
2525 }
2527 {
2528 GtkWidget *l = clonetiler_spinbox (tt,
2529 _("Change the color lightness by this percentage for each row"), "lightness_per_j",
2530 -100, 100, "%");
2531 clonetiler_table_attach (table, l, 0, 4, 2);
2532 }
2534 {
2535 GtkWidget *l = clonetiler_spinbox (tt,
2536 _("Change the color lightness by this percentage for each column"), "lightness_per_i",
2537 -100, 100, "%");
2538 clonetiler_table_attach (table, l, 0, 4, 3);
2539 }
2541 {
2542 GtkWidget *l = clonetiler_spinbox (tt,
2543 _("Randomize the color lightness by this percentage"), "lightness_rand",
2544 0, 100, "%");
2545 clonetiler_table_attach (table, l, 0, 4, 4);
2546 }
2549 { // alternates
2550 GtkWidget *l = gtk_label_new ("");
2551 gtk_label_set_markup (GTK_LABEL(l), _("<small>Alternate:</small>"));
2552 gtk_size_group_add_widget(table_row_labels, l);
2553 clonetiler_table_attach (table, l, 1, 5, 1);
2554 }
2556 {
2557 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each row"), "color_alternatej");
2558 clonetiler_table_attach (table, l, 0, 5, 2);
2559 }
2561 {
2562 GtkWidget *l = clonetiler_checkbox (tt, _("Alternate the sign of color changes for each column"), "color_alternatei");
2563 clonetiler_table_attach (table, l, 0, 5, 3);
2564 }
2566 }
2568 // Trace
2569 {
2570 GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace"));
2573 {
2574 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2575 gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0);
2577 GtkWidget *b = gtk_check_button_new_with_label (_("Trace the drawing under the tiles"));
2578 g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE));
2579 bool old = prefs->getBool(prefs_path + "dotrace");
2580 gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2581 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);
2582 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2584 gtk_signal_connect(GTK_OBJECT(b), "toggled",
2585 GTK_SIGNAL_FUNC(clonetiler_do_pick_toggled), dlg);
2586 }
2588 {
2589 GtkWidget *vvb = gtk_vbox_new (FALSE, 0);
2590 gtk_box_pack_start (GTK_BOX (vb), vvb, FALSE, FALSE, 0);
2591 g_object_set_data (G_OBJECT(dlg), "dotrace", (gpointer) vvb);
2594 {
2595 GtkWidget *frame = gtk_frame_new (_("1. Pick from the drawing:"));
2596 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2598 GtkWidget *table = gtk_table_new (3, 3, FALSE);
2599 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2600 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2601 gtk_container_add(GTK_CONTAINER(frame), table);
2604 GtkWidget* radio;
2605 {
2606 radio = gtk_radio_button_new_with_label (NULL, _("Color"));
2607 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the visible color and opacity"), NULL);
2608 clonetiler_table_attach (table, radio, 0.0, 1, 1);
2609 gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2610 GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_COLOR));
2611 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_COLOR);
2612 }
2613 {
2614 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Opacity"));
2615 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the total accumulated opacity"), NULL);
2616 clonetiler_table_attach (table, radio, 0.0, 2, 1);
2617 gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2618 GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_OPACITY));
2619 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_OPACITY);
2620 }
2621 {
2622 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("R"));
2623 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Red component of the color"), NULL);
2624 clonetiler_table_attach (table, radio, 0.0, 1, 2);
2625 gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2626 GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_R));
2627 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_R);
2628 }
2629 {
2630 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("G"));
2631 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Green component of the color"), NULL);
2632 clonetiler_table_attach (table, radio, 0.0, 2, 2);
2633 gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2634 GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_G));
2635 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_G);
2636 }
2637 {
2638 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("B"));
2639 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the Blue component of the color"), NULL);
2640 clonetiler_table_attach (table, radio, 0.0, 3, 2);
2641 gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2642 GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_B));
2643 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_B);
2644 }
2645 {
2646 //TRANSLATORS: only translate "string" in "context|string".
2647 // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2648 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|H"));
2649 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the hue of the color"), NULL);
2650 clonetiler_table_attach (table, radio, 0.0, 1, 3);
2651 gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2652 GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_H));
2653 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_H);
2654 }
2655 {
2656 //TRANSLATORS: only translate "string" in "context|string".
2657 // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2658 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|S"));
2659 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the saturation of the color"), NULL);
2660 clonetiler_table_attach (table, radio, 0.0, 2, 3);
2661 gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2662 GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_S));
2663 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_S);
2664 }
2665 {
2666 //TRANSLATORS: only translate "string" in "context|string".
2667 // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2668 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), Q_("clonetiler|L"));
2669 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Pick the lightness of the color"), NULL);
2670 clonetiler_table_attach (table, radio, 0.0, 3, 3);
2671 gtk_signal_connect (GTK_OBJECT (radio), "toggled",
2672 GTK_SIGNAL_FUNC (clonetiler_pick_switched), GINT_TO_POINTER(PICK_L));
2673 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), prefs->getInt(prefs_path + "pick", 0) == PICK_L);
2674 }
2676 }
2678 {
2679 GtkWidget *frame = gtk_frame_new (_("2. Tweak the picked value:"));
2680 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, VB_MARGIN);
2682 GtkWidget *table = gtk_table_new (4, 2, FALSE);
2683 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2684 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2685 gtk_container_add(GTK_CONTAINER(frame), table);
2687 {
2688 GtkWidget *l = gtk_label_new ("");
2689 gtk_label_set_markup (GTK_LABEL(l), _("Gamma-correct:"));
2690 clonetiler_table_attach (table, l, 1.0, 1, 1);
2691 }
2692 {
2693 GtkWidget *l = clonetiler_spinbox (tt,
2694 _("Shift the mid-range of the picked value upwards (>0) or downwards (<0)"), "gamma_picked",
2695 -10, 10, "");
2696 clonetiler_table_attach (table, l, 0.0, 1, 2);
2697 }
2699 {
2700 GtkWidget *l = gtk_label_new ("");
2701 gtk_label_set_markup (GTK_LABEL(l), _("Randomize:"));
2702 clonetiler_table_attach (table, l, 1.0, 1, 3);
2703 }
2704 {
2705 GtkWidget *l = clonetiler_spinbox (tt,
2706 _("Randomize the picked value by this percentage"), "rand_picked",
2707 0, 100, "%");
2708 clonetiler_table_attach (table, l, 0.0, 1, 4);
2709 }
2711 {
2712 GtkWidget *l = gtk_label_new ("");
2713 gtk_label_set_markup (GTK_LABEL(l), _("Invert:"));
2714 clonetiler_table_attach (table, l, 1.0, 2, 1);
2715 }
2716 {
2717 GtkWidget *l = clonetiler_checkbox (tt, _("Invert the picked value"), "invert_picked");
2718 clonetiler_table_attach (table, l, 0.0, 2, 2);
2719 }
2720 }
2722 {
2723 GtkWidget *frame = gtk_frame_new (_("3. Apply the value to the clones':"));
2724 gtk_box_pack_start (GTK_BOX (vvb), frame, FALSE, FALSE, 0);
2727 GtkWidget *table = gtk_table_new (2, 2, FALSE);
2728 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2729 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2730 gtk_container_add(GTK_CONTAINER(frame), table);
2732 {
2733 GtkWidget *b = gtk_check_button_new_with_label (_("Presence"));
2734 bool old = prefs->getBool(prefs_path + "pick_to_presence", true);
2735 gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2736 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone is created with the probability determined by the picked value in that point"), NULL);
2737 clonetiler_table_attach (table, b, 0.0, 1, 1);
2738 gtk_signal_connect(GTK_OBJECT(b), "toggled",
2739 GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_presence");
2740 }
2742 {
2743 GtkWidget *b = gtk_check_button_new_with_label (_("Size"));
2744 bool old = prefs->getBool(prefs_path + "pick_to_size");
2745 gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2746 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's size is determined by the picked value in that point"), NULL);
2747 clonetiler_table_attach (table, b, 0.0, 2, 1);
2748 gtk_signal_connect(GTK_OBJECT(b), "toggled",
2749 GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_size");
2750 }
2752 {
2753 GtkWidget *b = gtk_check_button_new_with_label (_("Color"));
2754 bool old = prefs->getBool(prefs_path + "pick_to_color", 0);
2755 gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2756 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);
2757 clonetiler_table_attach (table, b, 0.0, 1, 2);
2758 gtk_signal_connect(GTK_OBJECT(b), "toggled",
2759 GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_color");
2760 }
2762 {
2763 GtkWidget *b = gtk_check_button_new_with_label (_("Opacity"));
2764 bool old = prefs->getBool(prefs_path + "pick_to_opacity", 0);
2765 gtk_toggle_button_set_active ((GtkToggleButton *) b, old);
2766 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), b, _("Each clone's opacity is determined by the picked value in that point"), NULL);
2767 clonetiler_table_attach (table, b, 0.0, 2, 2);
2768 gtk_signal_connect(GTK_OBJECT(b), "toggled",
2769 GTK_SIGNAL_FUNC(clonetiler_pick_to), (gpointer) "pick_to_opacity");
2770 }
2771 }
2772 gtk_widget_set_sensitive (vvb, prefs->getBool(prefs_path + "dotrace"));
2773 }
2774 }
2776 // Rows/columns, width/height
2777 {
2778 GtkWidget *table = gtk_table_new (2, 2, FALSE);
2779 gtk_container_set_border_width (GTK_CONTAINER (table), VB_MARGIN);
2780 gtk_table_set_row_spacings (GTK_TABLE (table), 4);
2781 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
2782 gtk_box_pack_start (GTK_BOX (mainbox), table, FALSE, FALSE, 0);
2784 {
2785 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2786 g_object_set_data (G_OBJECT(dlg), "rowscols", (gpointer) hb);
2788 {
2789 GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2790 int value = prefs->getInt(prefs_path + "jmax", 2);
2791 gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2792 GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2793 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many rows in the tiling"), NULL);
2794 gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2795 gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2797 gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2798 GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "jmax");
2799 }
2801 {
2802 GtkWidget *l = gtk_label_new ("");
2803 gtk_label_set_markup (GTK_LABEL(l), "×");
2804 gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2805 gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2806 }
2808 {
2809 GtkObject *a = gtk_adjustment_new(0.0, 1, 500, 1, 10, 10);
2810 int value = prefs->getInt(prefs_path + "imax", 2);
2811 gtk_adjustment_set_value (GTK_ADJUSTMENT (a), value);
2812 GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 0);
2813 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), sb, _("How many columns in the tiling"), NULL);
2814 gtk_entry_set_width_chars (GTK_ENTRY (sb), 5);
2815 gtk_box_pack_start (GTK_BOX (hb), sb, TRUE, TRUE, 0);
2817 gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2818 GTK_SIGNAL_FUNC(clonetiler_xy_changed), (gpointer) "imax");
2819 }
2821 clonetiler_table_attach (table, hb, 0.0, 1, 2);
2822 }
2824 {
2825 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2826 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
2828 // unitmenu
2829 GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
2830 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
2832 {
2833 // Width spinbutton
2834 GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2835 sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2837 double value = prefs->getDouble(prefs_path + "fillwidth", 50.0);
2838 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2839 gdouble const units = sp_pixels_get_units (value, unit);
2840 gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2842 GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2843 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Width of the rectangle to be filled"), NULL);
2844 gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2845 gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2846 gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2847 GTK_SIGNAL_FUNC(clonetiler_fill_width_changed), u);
2848 }
2849 {
2850 GtkWidget *l = gtk_label_new ("");
2851 gtk_label_set_markup (GTK_LABEL(l), "×");
2852 gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5);
2853 gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 0);
2854 }
2856 {
2857 // Height spinbutton
2858 GtkObject *a = gtk_adjustment_new (0.0, -1e6, 1e6, 1.0, 10.0, 10.0);
2859 sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a));
2861 double value = prefs->getDouble(prefs_path + "fillheight", 50.0);
2862 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
2863 gdouble const units = sp_pixels_get_units (value, unit);
2864 gtk_adjustment_set_value (GTK_ADJUSTMENT (a), units);
2867 GtkWidget *e = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0 , 2);
2868 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), e, _("Height of the rectangle to be filled"), NULL);
2869 gtk_entry_set_width_chars (GTK_ENTRY (e), 5);
2870 gtk_box_pack_start (GTK_BOX (hb), e, TRUE, TRUE, 0);
2871 gtk_signal_connect(GTK_OBJECT(a), "value_changed",
2872 GTK_SIGNAL_FUNC(clonetiler_fill_height_changed), u);
2873 }
2875 gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);
2876 clonetiler_table_attach (table, hb, 0.0, 2, 2);
2878 }
2880 // Switch
2881 GtkWidget* radio;
2882 {
2883 radio = gtk_radio_button_new_with_label (NULL, _("Rows, columns: "));
2884 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Create the specified number of rows and columns"), NULL);
2885 clonetiler_table_attach (table, radio, 0.0, 1, 1);
2886 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_create), (gpointer) dlg);
2887 }
2888 if (!prefs->getBool(prefs_path + "fillrect")) {
2889 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2890 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2891 }
2892 {
2893 radio = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (radio)), _("Width, height: "));
2894 gtk_tooltips_set_tip (GTK_TOOLTIPS (tt), radio, _("Fill the specified width and height with the tiling"), NULL);
2895 clonetiler_table_attach (table, radio, 0.0, 2, 1);
2896 gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (clonetiler_switch_to_fill), (gpointer) dlg);
2897 }
2898 if (prefs->getBool(prefs_path + "fillrect")) {
2899 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
2900 gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (radio));
2901 }
2902 }
2905 // Use saved pos
2906 {
2907 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2908 gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2910 GtkWidget *b = gtk_check_button_new_with_label (_("Use saved size and position of the tile"));
2911 bool keepbbox = prefs->getBool(prefs_path + "keepbbox", true);
2912 gtk_toggle_button_set_active ((GtkToggleButton *) b, keepbbox);
2913 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);
2914 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2916 gtk_signal_connect(GTK_OBJECT(b), "toggled",
2917 GTK_SIGNAL_FUNC(clonetiler_keep_bbox_toggled), NULL);
2918 }
2920 // Statusbar
2921 {
2922 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2923 gtk_box_pack_end (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2924 GtkWidget *l = gtk_label_new("");
2925 g_object_set_data (G_OBJECT(dlg), "status", (gpointer) l);
2926 gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
2927 }
2929 // Buttons
2930 {
2931 GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN);
2932 gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0);
2934 {
2935 GtkWidget *b = gtk_button_new ();
2936 GtkWidget *l = gtk_label_new ("");
2937 gtk_label_set_markup_with_mnemonic (GTK_LABEL(l), _(" <b>_Create</b> "));
2938 gtk_container_add (GTK_CONTAINER(b), l);
2939 gtk_tooltips_set_tip (tt, b, _("Create and tile the clones of the selection"), NULL);
2940 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_apply), NULL);
2941 gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0);
2942 }
2944 { // buttons which are enabled only when there are tiled clones
2945 GtkWidget *sb = gtk_hbox_new(FALSE, 0);
2946 gtk_box_pack_end (GTK_BOX (hb), sb, FALSE, FALSE, 0);
2947 g_object_set_data (G_OBJECT(dlg), "buttons_on_tiles", (gpointer) sb);
2948 {
2949 // TRANSLATORS: if a group of objects are "clumped" together, then they
2950 // are unevenly spread in the given amount of space - as shown in the
2951 // diagrams on the left in the following screenshot:
2952 // http://www.inkscape.org/screenshots/gallery/inkscape-0.42-CVS-tiles-unclump.png
2953 // So unclumping is the process of spreading a number of objects out more evenly.
2954 GtkWidget *b = gtk_button_new_with_mnemonic (_(" _Unclump "));
2955 gtk_tooltips_set_tip (tt, b, _("Spread out clones to reduce clumping; can be applied repeatedly"), NULL);
2956 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_unclump), NULL);
2957 gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2958 }
2960 {
2961 GtkWidget *b = gtk_button_new_with_mnemonic (_(" Re_move "));
2962 gtk_tooltips_set_tip (tt, b, _("Remove existing tiled clones of the selected object (siblings only)"), NULL);
2963 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_remove), NULL);
2964 gtk_box_pack_end (GTK_BOX (sb), b, FALSE, FALSE, 0);
2965 }
2967 // connect to global selection changed signal (so we can change desktops) and
2968 // external_change (so we're not fooled by undo)
2969 g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (clonetiler_change_selection), dlg);
2970 g_signal_connect (G_OBJECT (INKSCAPE), "external_change", G_CALLBACK (clonetiler_external_change), dlg);
2971 g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), G_OBJECT (INKSCAPE));
2973 // update now
2974 clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg);
2975 }
2977 {
2978 GtkWidget *b = gtk_button_new_with_mnemonic (_(" R_eset "));
2979 // TRANSLATORS: "change" is a noun here
2980 gtk_tooltips_set_tip (tt, b, _("Reset all shifts, scales, rotates, opacity and color changes in the dialog to zero"), NULL);
2981 gtk_signal_connect (GTK_OBJECT (b), "clicked", GTK_SIGNAL_FUNC (clonetiler_reset), NULL);
2982 gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0);
2983 }
2984 }
2986 gtk_widget_show_all (mainbox);
2988 } // end of if (!dlg)
2990 gtk_window_present ((GtkWindow *) dlg);
2991 }
2994 /*
2995 Local Variables:
2996 mode:c++
2997 c-file-style:"stroustrup"
2998 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2999 indent-tabs-mode:nil
3000 fill-column:99
3001 End:
3002 */
3003 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :