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