The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

DrawingTools.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/DrawingTools.vala.
Store autotrace settings
1 /* 2 Copyright (C) 2012 2013 2014 2015 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 using Cairo; 16 using Math; 17 18 namespace BirdFont { 19 20 public class DrawingTools : ToolCollection { 21 GlyphCanvas glyph_canvas; 22 23 public Gee.ArrayList<Expander> expanders = new Gee.ArrayList<Expander> (); 24 25 public static Expander draw_tools { get; set; } 26 public static Expander grid_expander { get; set; } 27 public static Expander shape_tools { get; set; } 28 public static Expander draw_tool_modifiers { get; set; } 29 public static Expander layer_tools { get; set; } 30 public static Expander layer_settings { get; set; } 31 public static Expander stroke_expander { get; set; } 32 public static Expander zoombar_tool { get; set; } 33 public static Expander guideline_tools { get; set; } 34 35 public static Expander font_name { get; set; } 36 public static Expander key_tools { get; set; } 37 public static Expander test_tools { get; set; } 38 public static Expander grid { get; set; } 39 40 public static PointType point_type = PointType.DOUBLE_CURVE; 41 42 public static Tool add_stroke { get; set; } 43 public static SpinButton object_stroke; 44 Tool outline; 45 46 public static MoveTool move_tool { get; set; } 47 public static PenTool pen_tool; 48 49 public static BezierTool bezier_tool; 50 PointTool point_tool; 51 public static ZoomTool zoom_tool; 52 public static ResizeTool resize_tool; 53 public static TrackTool track_tool; 54 public static BackgroundTool move_background; 55 public static Tool move_canvas; 56 public static Tool add_layer; 57 public static Tool show_layers; 58 59 static Tool quadratic_points; 60 static Tool cubic_points; 61 static Tool double_points; 62 static Tool convert_points; 63 64 public static CutBackgroundTool cut_background; 65 Tool show_bg; 66 Tool bg_selection; 67 public static SpinButton background_threshold; 68 public static SpinButton background_scale; 69 Tool high_contrast_background; 70 public static SpinButton auto_trace_resolution; 71 Tool auto_trace; 72 public static SpinButton auto_trace_simplify; 73 Tool delete_background; 74 75 Tool rectangle; 76 Tool circle; 77 78 public static Tool help_lines { get; set; } 79 public static Tool xheight_help_lines { get; set; } 80 public static Tool background_help_lines { get; set; } 81 public static GridTool show_grid { get; set; } 82 public static Tool lock_grid { get; set; } 83 84 SpinButton x_coordinate; 85 SpinButton y_coordinate; 86 SpinButton rotation; 87 SpinButton width; 88 SpinButton height; 89 SpinButton skew; 90 91 Tool tie_handles; 92 Tool reflect_handle; 93 Tool create_line; 94 Tool close_path_tool; 95 96 Tool delete_button; 97 public Tool insert_point_on_path_tool; 98 Tool undo_tool; 99 Tool select_all_button; 100 101 OrientationTool reverse_path_tool; 102 Tool move_layer; 103 Tool flip_vertical; 104 Tool flip_horizontal; 105 106 public ZoomBar zoom_bar; 107 108 static Tool line_cap_butt; 109 static Tool line_cap_round; 110 static Tool line_cap_square; 111 112 public DrawingTools (GlyphCanvas main_glyph_canvas) { 113 bool selected_line; 114 115 glyph_canvas = main_glyph_canvas; 116 117 background_scale = new SpinButton (); 118 119 draw_tools = new Expander (t_("Drawing Tools")); 120 draw_tool_modifiers = new Expander (t_("Control Point")); 121 layer_tools = new Expander (); 122 layer_settings = new Expander (t_("Layers")); 123 stroke_expander = new Expander (t_("Stroke")); 124 shape_tools = new Expander (t_("Geometrical Shapes")); 125 zoombar_tool = new Expander (t_("Zoom")); 126 guideline_tools = new Expander (t_("Guidelines & Grid")); 127 128 font_name = new Expander (); 129 key_tools = new Expander (); // tools on android 130 test_tools = new Expander (); 131 grid = new Expander (t_("Grid Size")); 132 133 grid_expander = grid; 134 135 // font name 136 font_name.add_tool (new FontName ()); 137 138 // Draw tools 139 bezier_tool = new BezierTool ("bezier_tool"); 140 bezier_tool.select_action.connect ((self) => { 141 update_drawing_and_background_tools (self); 142 }); 143 draw_tools.add_tool (bezier_tool); 144 145 pen_tool = new PenTool ("pen_tool"); 146 pen_tool.select_action.connect ((self) => { 147 update_drawing_and_background_tools (self); 148 }); 149 draw_tools.add_tool (pen_tool); 150 151 point_tool = new PointTool ("point_tool"); 152 point_tool.select_action.connect ((self) => { 153 update_drawing_and_background_tools (self); 154 }); 155 draw_tools.add_tool (point_tool); 156 157 zoom_tool = new ZoomTool ("zoom_tool"); 158 zoom_tool.select_action.connect ((self) => { 159 update_drawing_and_background_tools (self); 160 }); 161 #if ANDROID 162 Toolbox.hidden_tools.hidden_expander.add_tool (zoom_tool); 163 #else 164 draw_tools.add_tool (zoom_tool); 165 #endif 166 move_tool = new MoveTool ("move"); 167 move_tool.select_action.connect ((self) => { 168 update_drawing_and_background_tools (self); 169 }); 170 draw_tools.add_tool (move_tool); 171 172 resize_tool = new ResizeTool ("resize"); 173 resize_tool.select_action.connect ((self) => { 174 update_drawing_and_background_tools (self); 175 }); 176 draw_tools.add_tool (resize_tool); 177 178 track_tool = new TrackTool ("track"); // draw outline on freehand 179 track_tool.select_action.connect ((self) => { 180 update_drawing_and_background_tools (self); 181 }); 182 draw_tools.add_tool (track_tool); 183 184 move_background = new BackgroundTool ("move_background"); 185 move_background.select_action.connect ((self) => { 186 update_drawing_and_background_tools (self); 187 }); 188 draw_tools.add_tool (move_background); 189 190 move_canvas = new Tool ("move_canvas", t_("Move canvas")); 191 move_canvas.select_action.connect ((self) => { 192 update_drawing_and_background_tools (self); 193 }); 194 draw_tools.add_tool (move_canvas); 195 196 // Tools on android 197 // Delete key 198 delete_button = new Tool ("delete_button", t_("Delete")); 199 delete_button.select_action.connect ((self) => { 200 TabContent.key_press (Key.DEL); 201 }); 202 key_tools.add_tool (delete_button); 203 204 // Select all points or paths 205 select_all_button = new Tool ("select_all", t_("Select all points or paths")); 206 select_all_button.select_action.connect ((self) => { 207 Glyph g = MainWindow.get_current_glyph (); 208 209 if (point_tool.is_selected () 210 || pen_tool.is_selected () 211 || track_tool.is_selected ()) { 212 pen_tool.select_all_points (); 213 g.open_path (); 214 } else { 215 DrawingTools.move_tool.select_all_paths (); 216 } 217 }); 218 key_tools.add_tool (select_all_button); 219 220 // Undo 221 undo_tool = new Tool ("undo_tool", t_("Undo")); 222 undo_tool.select_action.connect ((self) => { 223 TabContent.undo (); 224 }); 225 key_tools.add_tool (undo_tool); 226 227 bool insert_points = false; 228 insert_point_on_path_tool = new Tool ("new_point_on_path", t_("Insert new points on path")); 229 insert_point_on_path_tool.select_action.connect ((self) => { 230 insert_points = !insert_points; 231 insert_point_on_path_tool.set_selected (insert_points); 232 }); 233 insert_point_on_path_tool.set_persistent (true); 234 key_tools.add_tool (insert_point_on_path_tool); 235 236 // quadratic Bézier points 237 quadratic_points = new Tool ("quadratic_points", t_("Create quadratic Bézier curves")); 238 quadratic_points.select_action.connect ((self) => { 239 point_type = PointType.QUADRATIC; 240 Preferences.set ("point_type", "quadratic_points"); 241 update_type_selection (); 242 }); 243 draw_tool_modifiers.add_tool (quadratic_points); 244 245 // cubic Bézier points 246 cubic_points = new Tool ("cubic_points", t_("Create cubic Bézier curves")); 247 cubic_points.select_action.connect ((self) => { 248 point_type = PointType.CUBIC; 249 Preferences.set ("point_type", "cubic_points"); 250 update_type_selection (); 251 }); 252 draw_tool_modifiers.add_tool (cubic_points); 253 254 // two quadratic points off curve points for each quadratic control point 255 double_points = new Tool ("double_points", t_("Quadratic path with two line handles")); 256 double_points.select_action.connect ((self) => { 257 point_type = PointType.DOUBLE_CURVE; 258 Preferences.set ("point_type", "double_points"); 259 update_type_selection (); 260 }); 261 draw_tool_modifiers.add_tool (double_points); 262 263 // convert point 264 convert_points = new Tool ("convert_point", t_("Convert selected points")); 265 convert_points.select_action.connect ((self) => { 266 PenTool.convert_point_types (); 267 GlyphCanvas.redraw (); 268 update_type_selection (); 269 PenTool.reset_stroke (); 270 }); 271 convert_points.set_persistent (false); 272 draw_tool_modifiers.add_tool (convert_points); 273 274 // x coordinate 275 x_coordinate = new SpinButton ("x_coordinate", t_("X coordinate")); 276 x_coordinate.set_big_number (true); 277 x_coordinate.set_int_value ("0.000"); 278 x_coordinate.set_int_step (0.1); 279 x_coordinate.set_min (-999.99); 280 x_coordinate.set_max (999.99); 281 x_coordinate.show_icon (true); 282 x_coordinate.set_persistent (false); 283 x_coordinate.new_value_action.connect((self) => { 284 Glyph glyph = MainWindow.get_current_glyph (); 285 double x, y, w, h; 286 double delta; 287 288 glyph.selection_boundaries (out x, out y, out w, out h); 289 delta = x_coordinate.get_value () - x + glyph.left_limit; 290 291 foreach (Path path in glyph.active_paths) { 292 path.move (delta, 0); 293 } 294 295 GlyphCanvas.redraw (); 296 }); 297 draw_tool_modifiers.add_tool (x_coordinate); 298 299 move_tool.objects_moved.connect (() => { 300 Glyph glyph = MainWindow.get_current_glyph (); 301 x_coordinate.set_value_round (MoveTool.selection_box_center_x 302 - (MoveTool.selection_box_width / 2) 303 - glyph.left_limit, true, false); 304 }); 305 306 move_tool.selection_changed.connect (() => { 307 Glyph glyph = MainWindow.get_current_glyph (); 308 x_coordinate.set_value_round (MoveTool.selection_box_center_x 309 - (MoveTool.selection_box_width / 2) 310 - glyph.left_limit, true, false); 311 }); 312 313 move_tool.objects_deselected.connect (() => { 314 x_coordinate.set_value_round (0, true, false); 315 x_coordinate.hide_value (); 316 }); 317 318 // y coordinate 319 y_coordinate = new SpinButton ("y_coordinate", t_("Y coordinate")); 320 y_coordinate.set_big_number (true); 321 y_coordinate.set_int_value ("0.000"); 322 y_coordinate.set_int_step (0.1); 323 y_coordinate.set_min (-999.99); 324 y_coordinate.set_max (999.99); 325 y_coordinate.show_icon (true); 326 y_coordinate.set_persistent (false); 327 y_coordinate.new_value_action.connect((self) => { 328 double x, y, w, h; 329 Glyph glyph = MainWindow.get_current_glyph (); 330 Font font = BirdFont.get_current_font (); 331 332 glyph.selection_boundaries (out x, out y, out w, out h); 333 334 foreach (Path path in glyph.active_paths) { 335 path.move (0, y_coordinate.get_value () - (y - h) - font.base_line); 336 } 337 338 GlyphCanvas.redraw (); 339 }); 340 draw_tool_modifiers.add_tool (y_coordinate); 341 342 move_tool.objects_moved.connect (() => { 343 Font font = BirdFont.get_current_font (); 344 y_coordinate.set_value_round (MoveTool.selection_box_center_y 345 - (MoveTool.selection_box_height / 2) 346 + font.base_line, true, false); 347 }); 348 349 move_tool.selection_changed.connect (() => { 350 Font font = BirdFont.get_current_font (); 351 y_coordinate.set_value_round (MoveTool.selection_box_center_y 352 - (MoveTool.selection_box_height / 2) 353 + font.base_line, true, false); 354 }); 355 356 move_tool.objects_deselected.connect (() => { 357 y_coordinate.set_value_round (0, true, false); 358 y_coordinate.hide_value (); 359 }); 360 361 // rotation 362 rotation = new SpinButton ("rotation", t_("Rotation")); 363 rotation.set_big_number (true); 364 rotation.set_int_value ("0.000"); 365 rotation.set_int_step (0.1); 366 rotation.set_min (-360); 367 rotation.set_max (360); 368 rotation.show_icon (true); 369 rotation.set_persistent (false); 370 rotation.new_value_action.connect ((self) => { 371 double x, y, w, h; 372 Glyph glyph = MainWindow.get_current_glyph (); 373 double angle = (self.get_value () / 360) * 2 * PI; 374 Path last_path; 375 glyph.selection_boundaries (out x, out y, out w, out h); 376 377 x += w / 2; 378 y -= h / 2; 379 380 if (glyph.active_paths.size > 0) { 381 last_path = glyph.active_paths.get (glyph.active_paths.size - 1); 382 resize_tool.rotate_selected_paths (angle - last_path.rotation, x, y); 383 } 384 385 GlyphCanvas.redraw (); 386 }); 387 388 resize_tool.objects_rotated.connect ((angle) => { 389 rotation.set_value_round (angle, true, false); 390 PenTool.reset_stroke (); 391 }); 392 393 move_tool.objects_deselected.connect (() => { 394 rotation.set_value_round (0, true, false); 395 rotation.hide_value (); 396 }); 397 398 draw_tool_modifiers.add_tool (rotation); 399 400 // skew 401 skew = new SpinButton ("skew", t_("Skew")); 402 skew.set_big_number (true); 403 skew.set_int_value ("0.000"); 404 skew.set_int_step (1); 405 skew.set_min (-100); 406 skew.set_max (100); 407 skew.show_icon (true); 408 skew.set_persistent (false); 409 skew.new_value_action.connect ((self) => { 410 resize_tool.skew (-skew.get_value ()); 411 PenTool.reset_stroke (); 412 GlyphCanvas.redraw (); 413 }); 414 415 move_tool.objects_moved.connect (() => { 416 Glyph glyph = MainWindow.get_current_glyph (); 417 double d; 418 419 if (glyph.active_paths.size > 0) { 420 d = glyph.active_paths.get (0).skew; 421 resize_tool.last_skew = d; 422 skew.set_value_round (-d, true, false); 423 } 424 }); 425 426 move_tool.objects_deselected.connect (() => { 427 skew.set_value_round (0, true, false); 428 skew.hide_value (); 429 }); 430 431 draw_tool_modifiers.add_tool (skew); 432 433 // width 434 width = new SpinButton ("width", t_("Width")); 435 width.set_big_number (true); 436 width.set_int_value ("0.0000"); 437 width.set_int_step (0.01); 438 width.show_icon (true); 439 width.set_persistent (false); 440 width.new_value_action.connect ((self) => { 441 double x, y, w, h; 442 Glyph glyph; 443 double new_size; 444 445 glyph = MainWindow.get_current_glyph (); 446 glyph.selection_boundaries (out x, out y, out w, out h); 447 448 new_size = self.get_value () / w; 449 450 if (self.get_value () > 0 && new_size != 1) { 451 resize_tool.resize_selected_paths (new_size); 452 } 453 454 GlyphCanvas.redraw (); 455 }); 456 draw_tool_modifiers.add_tool (width); 457 458 // height 459 height = new SpinButton ("height", t_("Height")); 460 height.set_big_number (true); 461 height.set_int_value ("0.0000"); 462 height.set_int_step (0.01); 463 height.show_icon (true); 464 height.set_persistent (false); 465 height.new_value_action.connect ((self) => { 466 double x, y, w, h; 467 Glyph glyph; 468 double new_size; 469 470 glyph = MainWindow.get_current_glyph (); 471 glyph.selection_boundaries (out x, out y, out w, out h); 472 473 new_size = self.get_value () / h; 474 475 if (self.get_value () > 0 && new_size != 1) { 476 resize_tool.resize_selected_paths (new_size); 477 } 478 479 GlyphCanvas.redraw (); 480 }); 481 draw_tool_modifiers.add_tool (height); 482 483 resize_tool.objects_resized.connect ((w, h) => { 484 height.set_value_round (h, true, false); 485 width.set_value_round (w, true, false); 486 }); 487 488 move_tool.objects_deselected.connect (() => { 489 width.set_value_round (0, true, false); 490 width.hide_value (); 491 492 height.set_value_round (0, true, false); 493 height.hide_value (); 494 }); 495 496 move_tool.objects_moved.connect (() => { 497 width.set_value_round (MoveTool.selection_box_width, true, false); 498 height.set_value_round (MoveTool.selection_box_height, true, false); 499 }); 500 501 // tie edit point handles 502 tie_handles = new Tool ("tie_point", t_("Tie curve handles for the selected edit point")); 503 tie_handles.select_action.connect ((self) => { 504 bool tie, end_point; 505 EditPoint p; 506 507 if (PenTool.move_selected_handle) { 508 p = PenTool.active_handle.parent; 509 tie = !p.tie_handles; 510 511 // don't tie end points 512 foreach (Path path in MainWindow.get_current_glyph ().active_paths) { 513 if (path.is_open ()) { 514 if (p == path.get_first_point () || p == path.get_last_point ()) { 515 tie = false; 516 } 517 } 518 } 519 520 if (tie) { 521 p.process_tied_handle (); 522 p.set_reflective_handles (false); 523 } 524 525 p.set_tie_handle (tie); 526 527 PenTool.handle_selection.path.update_region_boundaries (); 528 } else { 529 foreach (PointSelection ep in PenTool.selected_points) { 530 tie = !ep.point.tie_handles; 531 532 end_point = ep.point == ep.path.get_first_point () 533 || ep.point == ep.path.get_last_point (); 534 535 if (!ep.path.is_open () || !end_point) { 536 if (tie) { 537 ep.point.process_tied_handle (); 538 ep.point.set_reflective_handles (false); 539 } 540 541 ep.point.set_tie_handle (tie); 542 ep.path.update_region_boundaries (); 543 } 544 } 545 } 546 547 MainWindow.get_current_glyph ().update_view (); 548 PenTool.reset_stroke (); 549 }); 550 draw_tool_modifiers.add_tool (tie_handles); 551 552 // symmetrical handles 553 reflect_handle = new Tool ("symmetric", t_("Symmetrical handles")); 554 reflect_handle.select_action.connect ((self) => { 555 bool symmetrical, end_point; 556 PointSelection ep; 557 if (PenTool.selected_points.size > 0) { 558 ep = PenTool.selected_points.get (0); 559 symmetrical = ep.point.reflective_point; 560 561 foreach (PointSelection p in PenTool.selected_points) { 562 end_point = p.point == p.path.get_first_point () 563 || p.point == p.path.get_last_point (); 564 565 if (!p.path.is_open () || !end_point) { 566 p.point.set_reflective_handles (!symmetrical); 567 p.point.process_symmetrical_handles (); 568 569 if (symmetrical) { 570 ep.point.set_tie_handle (false); 571 } 572 573 p.path.update_region_boundaries (); 574 } 575 } 576 MainWindow.get_current_glyph ().update_view (); 577 } 578 579 PenTool.reset_stroke (); 580 }); 581 draw_tool_modifiers.add_tool (reflect_handle); 582 583 create_line = new Tool ("create_line", t_("Convert segment to line.")); 584 create_line.select_action.connect ((self) => { 585 PenTool.convert_segment_to_line (); 586 MainWindow.get_current_glyph ().update_view (); 587 PenTool.reset_stroke (); 588 }); 589 draw_tool_modifiers.add_tool (create_line); 590 591 reverse_path_tool = new OrientationTool ("reverse_path", t_("Create counter from outline")); 592 draw_tool_modifiers.add_tool (reverse_path_tool); 593 594 // close path 595 close_path_tool = new Tool ("close_path", t_("Close path")); 596 close_path_tool.select_action.connect ((self) => { 597 Tool current; 598 Glyph g; 599 600 current = MainWindow.get_toolbox ().get_current_tool (); 601 602 if (current is BezierTool) { 603 ((BezierTool) current).stop_drawing (); 604 } 605 606 PenTool.reset_stroke (); 607 608 g = MainWindow.get_current_glyph (); 609 g.close_path (); 610 g.clear_active_paths (); 611 612 self.set_selected (false); 613 GlyphCanvas.redraw (); 614 }); 615 draw_tool_modifiers.add_tool (close_path_tool); 616 617 move_layer = new Tool ("move_layer", t_("Move to path to the bottom of the layer")); 618 move_layer.select_action.connect ((self) => { 619 Glyph g = MainWindow.get_current_glyph (); 620 Layer layer = g.get_current_layer (); 621 622 foreach (Path p in g.active_paths) { 623 layer.paths.remove (p); 624 layer.paths.paths.insert (0, p); 625 } 626 627 GlyphCanvas.redraw (); 628 }); 629 draw_tool_modifiers.add_tool (move_layer); 630 631 flip_vertical = new Tool ("flip_vertical", t_("Flip path vertically")); 632 flip_vertical.select_action.connect ((self) => { 633 MoveTool.flip_vertical (); 634 MainWindow.get_current_glyph ().update_view (); 635 PenTool.reset_stroke (); 636 }); 637 draw_tool_modifiers.add_tool (flip_vertical); 638 639 flip_horizontal = new Tool ("flip_horizontal", t_("Flip path horizontally")); 640 flip_horizontal.select_action.connect ((self) => { 641 MoveTool.flip_horizontal (); 642 MainWindow.get_current_glyph ().update_view (); 643 PenTool.reset_stroke (); 644 }); 645 draw_tool_modifiers.add_tool (flip_horizontal); 646 647 // background tools 648 background_scale = new SpinButton ("scale_background", t_("Set size for background image")); 649 background_scale.show_icon (true); 650 background_scale.set_int_value ("1.000"); 651 652 background_scale.new_value_action.connect((self) => { 653 background_scale.select_action (self); 654 }); 655 656 background_scale.select_action.connect((self) => { 657 SpinButton sb = (SpinButton) self; 658 Glyph g = MainWindow.get_current_glyph (); 659 BackgroundImage? img = g.get_background_image (); 660 double s = sb.get_value (); 661 BackgroundImage i; 662 double xc, yc; 663 664 if (img != null) { 665 i = (!) img; 666 xc = i.img_middle_x; 667 yc = i.img_middle_y; 668 669 i.set_img_scale (s, s); 670 671 i.img_middle_x = xc; 672 i.img_middle_y = yc; 673 } 674 675 GlyphCanvas.redraw (); 676 }); 677 678 draw_tool_modifiers.add_tool (background_scale); 679 680 cut_background = new CutBackgroundTool ("cut_background"); 681 cut_background.select_action.connect ((self) => { 682 update_drawing_and_background_tools (self); 683 }); 684 draw_tool_modifiers.add_tool (cut_background); 685 686 show_bg = new Tool ("show_background", t_("Show/hide background image")); 687 show_bg.select_action.connect ((self) => { 688 update_drawing_and_background_tools (self); 689 }); 690 show_bg.select_action.connect ((self) => { 691 Glyph g = MainWindow.get_current_glyph (); 692 g.set_background_visible (!g.get_background_visible ()); 693 GlyphCanvas.redraw (); 694 }); 695 draw_tool_modifiers.add_tool (show_bg); 696 697 bg_selection = new Tool ("insert_background", t_("Insert a new background image")); 698 bg_selection.select_action.connect ((self) => { 699 update_drawing_and_background_tools (self); 700 }); 701 702 bg_selection.select_action.connect((self) => { 703 if (MainWindow.get_current_display () is Glyph) { 704 BackgroundTool.import_background_image (); 705 } 706 }); 707 708 bg_selection.set_show_background (true); 709 draw_tool_modifiers.add_tool (bg_selection); 710 711 high_contrast_background = new Tool ("high_contrast_background", t_("High contrast")); 712 high_contrast_background.select_action.connect ((self) => { 713 Glyph g = MainWindow.get_current_glyph (); 714 BackgroundImage? bg = g.get_background_image (); 715 BackgroundImage b; 716 717 if (bg != null) { 718 b = (!) bg; 719 b.set_high_contrast (!b.high_contrast); 720 b.update_background (); 721 } 722 }); 723 draw_tool_modifiers.add_tool (high_contrast_background); 724 725 background_threshold = new SpinButton ("contrast_threshold", t_("Set background threshold")); 726 background_threshold.show_icon (true); 727 background_threshold.set_value_round (1); 728 729 background_threshold.new_value_action.connect ((self) => { 730 Glyph g = MainWindow.get_current_glyph (); 731 BackgroundImage? bg = g.get_background_image (); 732 BackgroundImage b; 733 734 if (bg != null) { 735 b = (!) bg; 736 b.update_background (); 737 } 738 }); 739 740 draw_tool_modifiers.add_tool (background_threshold); 741 742 auto_trace_resolution = new SpinButton ("auto_trace_resolution", t_("Amount of autotrace details")); 743 auto_trace_resolution.set_value_round (1); 744 auto_trace_resolution.show_icon (true); 745 746 auto_trace_resolution.new_value_action.connect ((self) => { 747 Glyph g = MainWindow.get_current_glyph (); 748 BackgroundImage? bg = g.get_background_image (); 749 BackgroundImage b; 750 751 if (bg != null) { 752 b = (!) bg; 753 b.update_background (); 754 } 755 }); 756 757 draw_tool_modifiers.add_tool (auto_trace_resolution); 758 759 auto_trace_simplify = new SpinButton ("auto_trace_simplify", t_("Autotrace simplification")); 760 auto_trace_simplify.set_value_round (0.5); 761 auto_trace_simplify.show_icon (true); 762 763 auto_trace_simplify.new_value_action.connect ((self) => { 764 }); 765 766 draw_tool_modifiers.add_tool (auto_trace_simplify); 767 768 auto_trace = new Tool ("autotrace", t_("Autotrace background image")); 769 auto_trace.select_action.connect ((self) => { 770 Task t = new Task (); 771 t.task.connect (auto_trace_background); 772 MainWindow.native_window.run_background_thread (t); 773 }); 774 775 draw_tool_modifiers.add_tool (auto_trace); 776 777 delete_background = new Tool ("delete_background", t_("Delete background image")); 778 delete_background.select_action.connect ((self) => { 779 MainWindow.get_current_glyph ().delete_background (); 780 }); 781 782 draw_tool_modifiers.add_tool (delete_background); 783 784 add_layer = new Tool ("add_layer", t_("Add layer")); 785 add_layer.select_action.connect ((self) => { 786 layer_tools.visible = true; 787 MainWindow.get_current_glyph ().add_new_layer (); 788 update_layers (); 789 show_layers.selected = true; 790 add_layer.selected = false; 791 }); 792 layer_settings.add_tool (add_layer); 793 794 show_layers = new Tool ("show_layers", t_("Show layers")); 795 show_layers.select_action.connect ((self) => { 796 layer_tools.visible = !layer_tools.visible; 797 MainWindow.get_toolbox ().update_expanders (); 798 Toolbox.redraw_tool_box (); 799 show_layers.selected = layer_tools.visible; 800 }); 801 layer_settings.add_tool (show_layers); 802 803 // add stroke to path 804 add_stroke = new Tool ("apply_stroke", t_("Apply stroke")); 805 add_stroke.select_action.connect ((self) => { 806 Font f; 807 Glyph g = MainWindow.get_current_glyph (); 808 StrokeTool.add_stroke = !StrokeTool.add_stroke; 809 StrokeTool.stroke_width = object_stroke.get_value (); 810 811 add_stroke.selected = StrokeTool.add_stroke; 812 set_stroke_tool_visibility (); 813 GlyphCanvas.redraw (); 814 g.store_undo_state (); 815 816 if (StrokeTool.add_stroke) { 817 foreach (Path p in g.active_paths) { 818 p.stroke = StrokeTool.stroke_width; 819 p.line_cap = StrokeTool.line_cap; 820 } 821 } else { 822 foreach (Path p in g.active_paths) { 823 p.stroke = 0; 824 } 825 } 826 827 f = BirdFont.get_current_font (); 828 f.settings.set_setting ("apply_stroke", @"$(StrokeTool.add_stroke)"); 829 830 stroke_expander.redraw (); 831 MainWindow.get_toolbox ().update_expanders (); 832 }); 833 stroke_expander.add_tool (add_stroke); 834 add_stroke.selected = StrokeTool.add_stroke; 835 836 // edit stroke width 837 object_stroke = new SpinButton ("object_stroke", t_("Stroke width")); 838 object_stroke.set_big_number (true); 839 object_stroke.set_value_round (2); 840 object_stroke.set_max (0.01); 841 object_stroke.set_max (50); 842 843 object_stroke.new_value_action.connect((self) => { 844 Font f; 845 Glyph g = MainWindow.get_current_glyph (); 846 847 bool tool = resize_tool.is_selected () 848 || move_tool.is_selected () 849 || pen_tool.is_selected () 850 || track_tool.is_selected () 851 || point_tool.is_selected () 852 || bezier_tool.is_selected (); 853 854 StrokeTool.stroke_width = object_stroke.get_value (); 855 856 if (tool && StrokeTool.add_stroke) { 857 foreach (Path p in g.active_paths) { 858 p.stroke = StrokeTool.stroke_width; 859 p.reset_stroke (); 860 } 861 } 862 863 f = BirdFont.get_current_font (); 864 f.settings.set_setting ("stroke_width", object_stroke.get_display_value ()); 865 866 GlyphCanvas.redraw (); 867 }); 868 stroke_expander.add_tool (object_stroke); 869 870 move_tool.selection_changed.connect (() => { 871 update_stroke_settings (); 872 }); 873 874 move_tool.objects_moved.connect (() => { 875 update_stroke_settings (); 876 }); 877 878 // create outline from path 879 outline = new Tool ("stroke_to_outline", t_("Create outline form stroke")); 880 outline.select_action.connect ((self) => { 881 StrokeTool.stroke_selected_paths (); 882 outline.set_selected (false); 883 }); 884 stroke_expander.add_tool (outline); 885 886 // set line cap 887 line_cap_butt = new Tool ("line_cap_butt", t_("Butt line cap")); 888 line_cap_butt.select_action.connect ((self) => { 889 Glyph g; 890 891 g = MainWindow.get_current_glyph (); 892 g.store_undo_state (); 893 894 foreach (Path p in g.active_paths) { 895 p.line_cap = LineCap.BUTT; 896 p.reset_stroke (); 897 } 898 899 StrokeTool.line_cap = LineCap.BUTT; 900 Font f = BirdFont.get_current_font (); 901 f.settings.set_setting ("line_cap", @"butt"); 902 903 line_cap_butt.selected = true; 904 line_cap_round.selected = false; 905 line_cap_square.selected = false; 906 907 GlyphCanvas.redraw (); 908 }); 909 stroke_expander.add_tool (line_cap_butt); 910 911 line_cap_round = new Tool ("line_cap_round", t_("Round line cap")); 912 line_cap_round.select_action.connect ((self) => { 913 Glyph g; 914 915 g = MainWindow.get_current_glyph (); 916 g.store_undo_state (); 917 918 foreach (Path p in g.active_paths) { 919 p.line_cap = LineCap.ROUND; 920 p.reset_stroke (); 921 } 922 923 StrokeTool.line_cap = LineCap.ROUND; 924 925 Font f = BirdFont.get_current_font (); 926 f.settings.set_setting ("line_cap", @"round"); 927 928 line_cap_butt.selected = false; 929 line_cap_round.selected = true; 930 line_cap_square.selected = false; 931 932 GlyphCanvas.redraw (); 933 }); 934 stroke_expander.add_tool (line_cap_round); 935 936 line_cap_square = new Tool ("line_cap_square", t_("Square line cap")); 937 line_cap_square.select_action.connect ((self) => { 938 Glyph g; 939 940 g = MainWindow.get_current_glyph (); 941 g.store_undo_state (); 942 943 foreach (Path p in g.active_paths) { 944 p.line_cap = LineCap.SQUARE; 945 p.reset_stroke (); 946 } 947 948 StrokeTool.line_cap = LineCap.SQUARE; 949 950 Font f = BirdFont.get_current_font (); 951 f.settings.set_setting ("line_cap", @"square"); 952 953 line_cap_butt.selected = false; 954 line_cap_round.selected = false; 955 line_cap_square.selected = true; 956 957 GlyphCanvas.redraw (); 958 }); 959 stroke_expander.add_tool (line_cap_square); 960 961 // tests 962 if (BirdFont.has_argument ("--test")) { 963 Tool test_case = new Tool ("test_case"); 964 test_case.select_action.connect((self) => { 965 if (self.is_selected ()) { 966 if (TestBirdFont.is_running ()) { 967 TestBirdFont.pause (); 968 } else { 969 TestBirdFont.continue (); 970 } 971 } 972 }); 973 test_tools.add_tool (test_case); 974 975 Tool slow_test = new Tool ("slow_test"); 976 slow_test.select_action.connect((self) => { 977 bool s = TestBirdFont.is_slow_test (); 978 TestBirdFont.set_slow_test (!s); 979 s = TestBirdFont.is_slow_test (); 980 self.set_selected (s); 981 }); 982 983 test_tools.add_tool (slow_test); 984 985 // Run from commad line 986 string? st = BirdFont.get_argument ("--test"); 987 if (st != null && ((!)st).char_count () > 0) { 988 IdleSource idle = new IdleSource (); 989 990 idle.set_callback (() => { 991 MainWindow.get_toolbox ().select_tool (test_case); 992 return false; 993 }); 994 995 idle.attach (null); 996 } 997 998 if (BirdFont.has_argument ("--slow")) { 999 MainWindow.get_toolbox ().select_tool (slow_test); 1000 } 1001 1002 } 1003 1004 // guide lines, grid and other guidlines 1005 help_lines = new Tool ("help_lines", t_("Show guidelines")); 1006 help_lines.select_action.connect ((self) => { 1007 bool h; 1008 h = GlyphCanvas.get_current_glyph ().get_show_help_lines (); 1009 GlyphCanvas.get_current_glyph ().set_show_help_lines (!h); 1010 self.set_selected (!h); 1011 GlyphCanvas.get_current_glyph ().redraw_help_lines (); 1012 }); 1013 selected_line = GlyphCanvas.get_current_glyph ().get_show_help_lines (); 1014 help_lines.set_selected (selected_line); 1015 guideline_tools.add_tool (help_lines); 1016 1017 xheight_help_lines = new Tool ("show_xheight_helplines", t_("Show more guidelines")); 1018 xheight_help_lines.select_action.connect ((self) => { 1019 Glyph g = MainWindow.get_current_glyph (); 1020 bool v = !g.get_xheight_lines_visible (); 1021 g.set_xheight_lines_visible (v); 1022 self.set_selected (v); 1023 GlyphCanvas.redraw (); 1024 1025 if (v && !help_lines.is_selected ()) { 1026 MainWindow.get_toolbox ().select_tool (help_lines); 1027 } 1028 }); 1029 selected_line = GlyphCanvas.get_current_glyph ().get_xheight_lines_visible (); 1030 xheight_help_lines.set_selected (selected_line); 1031 guideline_tools.add_tool (xheight_help_lines); 1032 1033 background_help_lines = new Tool ("background_help_lines", t_("Show guidelines at top and bottom margin")); 1034 background_help_lines.select_action.connect ((self) => { 1035 Glyph g = MainWindow.get_current_glyph (); 1036 bool v = !g.get_margin_lines_visible (); 1037 g.set_margin_lines_visible (v); 1038 self.set_selected (v); 1039 GlyphCanvas.redraw (); 1040 1041 if (v && !help_lines.is_selected ()) { 1042 MainWindow.get_toolbox ().select_tool (help_lines); 1043 } 1044 }); 1045 selected_line = GlyphCanvas.get_current_glyph ().get_margin_lines_visible (); 1046 background_help_lines.set_selected (selected_line); 1047 guideline_tools.add_tool (background_help_lines); 1048 1049 show_grid = new GridTool ("show_grid"); 1050 show_grid.select_action.connect (() => { 1051 grid_expander.visible = show_grid.selected; 1052 MainWindow.get_toolbox ().update_expanders (); 1053 }); 1054 guideline_tools.add_tool (show_grid); 1055 grid_expander.visible = false; 1056 1057 lock_grid = new Tool ("lock_grid", t_("Lock guides and grid")); 1058 lock_grid.select_action.connect ((self) => { 1059 SpinButton sb; 1060 FontSettings fs; 1061 1062 GridTool.lock_grid = !GridTool.lock_grid; 1063 1064 foreach (Tool t in grid.tool) { 1065 if (t is SpinButton) { 1066 sb = (SpinButton) t; 1067 sb.locked = GridTool.lock_grid; 1068 } 1069 } 1070 1071 lock_grid.selected = GridTool.lock_grid; 1072 fs = BirdFont.get_current_font ().settings; 1073 fs.set_setting ("lock_grid", @"$(GridTool.lock_grid)"); 1074 }); 1075 guideline_tools.add_tool (lock_grid); 1076 1077 // Zoom tools 1078 zoom_bar = new ZoomBar (); 1079 zoom_bar.new_zoom.connect ((z) => { 1080 Glyph g = MainWindow.get_current_glyph (); 1081 double zoom = 20 * z + 1; 1082 double xc, yc, nxc, nyc; 1083 1084 xc = Glyph.path_coordinate_x (Glyph.xc ()); 1085 yc = Glyph.path_coordinate_y (Glyph.yc ()); 1086 1087 g.set_zoom (zoom); 1088 1089 nxc = Glyph.path_coordinate_x (Glyph.xc ()); 1090 nyc = Glyph.path_coordinate_y (Glyph.yc ()); 1091 1092 g.view_offset_x -= nxc - xc; 1093 g.view_offset_y += nyc - yc; 1094 1095 GlyphCanvas.redraw (); 1096 }); 1097 zoombar_tool.add_tool (zoom_bar); 1098 1099 Tool reset_zoom = new Tool ("zoom_1_1", t_("Zoom Out More")); 1100 reset_zoom.select_action.connect ((self) => { 1101 zoom_tool.store_current_view (); 1102 glyph_canvas.get_current_display ().reset_zoom (); 1103 glyph_canvas.redraw_area(0, 0, GlyphCanvas.allocation.width, GlyphCanvas.allocation.height); 1104 }); 1105 zoombar_tool.add_tool (reset_zoom); 1106 reset_zoom.set_tool_visibility (false); 1107 1108 Tool full_glyph = new Tool ("full_glyph", t_("Show full glyph")); 1109 full_glyph.select_action.connect((self) => { 1110 zoom_tool.store_current_view (); 1111 zoom_tool.zoom_full_glyph (); 1112 }); 1113 zoombar_tool.add_tool (full_glyph); 1114 1115 Tool zoom_boundaries = new Tool ("zoom_boundaries", t_("Fit in view")); 1116 zoom_boundaries.select_action.connect((self) => { 1117 zoom_tool.store_current_view (); 1118 glyph_canvas.get_current_display ().zoom_max (); 1119 }); 1120 zoombar_tool.add_tool (zoom_boundaries); 1121 1122 Tool zoom_bg = new Tool ("zoom_background_image", t_("Zoom in on background image")); 1123 zoom_bg.select_action.connect((self) => { 1124 if (MainWindow.get_current_glyph ().get_background_image () != null) { 1125 zoom_tool.store_current_view (); 1126 ZoomTool.zoom_full_background_image (); 1127 glyph_canvas.redraw_area(0, 0, GlyphCanvas.allocation.width, GlyphCanvas.allocation.height); 1128 } 1129 }); 1130 zoombar_tool.add_tool (zoom_bg); 1131 1132 Tool zoom_prev = new Tool ("prev", t_("Previous view")); 1133 zoom_prev.select_action.connect((self) => { 1134 zoom_tool.previous_view (); 1135 }); 1136 zoombar_tool.add_tool (zoom_prev); 1137 1138 Tool zoom_next = new Tool ("next", t_("Next view")); 1139 zoom_next.select_action.connect((self) => { 1140 zoom_tool.next_view (); 1141 }); 1142 zoombar_tool.add_tool (zoom_next); // view_tools 1143 zoom_next.set_tool_visibility (false); 1144 1145 // shape tools 1146 circle = new CircleTool ("circle"); 1147 circle.select_action.connect ((self) => { 1148 update_drawing_and_background_tools (self); 1149 }); 1150 shape_tools.add_tool (circle); 1151 1152 rectangle = new RectangleTool ("rectangle"); 1153 rectangle.select_action.connect ((self) => { 1154 update_drawing_and_background_tools (self); 1155 }); 1156 shape_tools.add_tool (rectangle); 1157 1158 add_expander (font_name); 1159 add_expander (draw_tools); 1160 1161 if (BirdFont.android) { 1162 add_expander (key_tools); 1163 } 1164 1165 add_expander (draw_tool_modifiers); 1166 add_expander (layer_settings); 1167 add_expander (layer_tools); 1168 add_expander (stroke_expander); 1169 add_expander (guideline_tools); 1170 add_expander (grid); 1171 add_expander (zoombar_tool); 1172 add_expander (shape_tools); 1173 1174 // Fixa: add_expander (trace); 1175 if (BirdFont.has_argument ("--test")) { 1176 add_expander (test_tools); 1177 } 1178 1179 layer_settings.set_persistent (true); 1180 layer_settings.set_unique (false); 1181 1182 draw_tools.set_persistent (true); 1183 draw_tools.set_unique (false); 1184 1185 stroke_expander.set_persistent (true); 1186 stroke_expander.set_unique (false); 1187 1188 key_tools.set_persistent (false); 1189 key_tools.set_unique (false); 1190 1191 draw_tool_modifiers.set_persistent (true); 1192 draw_tool_modifiers.set_unique (false); 1193 1194 test_tools.set_persistent (true); 1195 1196 guideline_tools.set_persistent (true); 1197 guideline_tools.set_unique (false); 1198 1199 grid.set_persistent (true); 1200 grid.set_unique (true); 1201 1202 shape_tools.set_persistent (true); 1203 shape_tools.set_unique (true); 1204 1205 // let these tools progagate events even when other tools are selected 1206 foreach (Tool t in draw_tools.tool) { 1207 t.editor_events = true; 1208 } 1209 1210 foreach (Tool t in shape_tools.tool) { 1211 t.editor_events = true; 1212 t.persistent = true; 1213 } 1214 1215 move_background.editor_events = true; 1216 cut_background.editor_events = true; 1217 move_canvas.editor_events = true; 1218 1219 move_background.persistent = true; 1220 cut_background.persistent = true; 1221 move_canvas.persistent = true; 1222 1223 // Default selection 1224 IdleSource idle = new IdleSource (); 1225 idle.set_callback (() => { 1226 Toolbox tb = MainWindow.get_toolbox (); 1227 1228 tb.reset_active_tool (); 1229 update_drawing_and_background_tools (point_tool); 1230 tb.select_tool (point_tool); 1231 tb.set_current_tool (point_tool); 1232 1233 set_point_type_from_preferences (); 1234 1235 if (GlyphCanvas.get_current_glyph ().get_show_help_lines ()) { 1236 help_lines.set_selected (true); 1237 help_lines.set_active (false); 1238 } 1239 1240 add_new_grid (1); 1241 add_new_grid (2); 1242 add_new_grid (4); 1243 1244 MainWindow.get_toolbox ().move (0, 0); 1245 set_stroke_tool_visibility (); 1246 1247 return false; 1248 }); 1249 idle.attach (null); 1250 1251 // update selelction when the user switches tab 1252 MainWindow.get_tab_bar ().signal_tab_selected.connect((tab) => { 1253 Glyph glyph; 1254 1255 if (tab.get_display () is Glyph) { 1256 glyph = (Glyph) tab.get_display (); 1257 show_bg.set_selected (glyph.get_background_visible ()); 1258 update_line_selection (glyph); 1259 } 1260 }); 1261 } 1262 1263 public static void update_stroke_settings () { 1264 bool stroke = false; 1265 Glyph g = MainWindow.get_current_glyph (); 1266 1267 foreach (Path p in g.active_paths) { 1268 if (p.stroke > 0) { 1269 stroke = true; 1270 } 1271 } 1272 1273 add_stroke.selected = stroke; 1274 StrokeTool.add_stroke = stroke; 1275 set_stroke_tool_visibility (); 1276 } 1277 1278 void auto_trace_background () { 1279 Glyph g = MainWindow.get_current_glyph (); 1280 BackgroundImage? bg = g.get_background_image (); 1281 BackgroundImage b; 1282 PathList pl; 1283 1284 if (bg != null) { 1285 b = (!) bg; 1286 pl = b.autotrace (); 1287 foreach (Path p in pl.paths) { 1288 g.add_path (p); 1289 } 1290 } 1291 } 1292 1293 void update_line_selection (Glyph glyph) { 1294 help_lines.set_selected (glyph.get_show_help_lines ()); 1295 xheight_help_lines.set_selected (glyph.get_xheight_lines_visible ()); 1296 background_help_lines.set_selected (glyph.get_margin_lines_visible ()); 1297 } 1298 1299 public static void set_point_type_from_preferences () { 1300 string type = Preferences.get ("point_type"); 1301 if (type == "double_points") { 1302 Toolbox.select_tool_by_name ("double_points"); 1303 } else if (type == "quadratic_points") { 1304 Toolbox.select_tool_by_name ("quadratic_points"); 1305 } if (type == "cubic_points") { 1306 Toolbox.select_tool_by_name ("cubic_points"); 1307 } 1308 } 1309 1310 void hide_all_modifiers () { 1311 x_coordinate.set_tool_visibility (false); 1312 y_coordinate.set_tool_visibility (false); 1313 rotation.set_tool_visibility (false); 1314 width.set_tool_visibility (false); 1315 height.set_tool_visibility (false); 1316 skew.set_tool_visibility (false); 1317 reverse_path_tool.set_tool_visibility (false); 1318 move_layer.set_tool_visibility (false); 1319 flip_vertical.set_tool_visibility (false); 1320 flip_horizontal.set_tool_visibility (false); 1321 1322 tie_handles.set_tool_visibility (false); 1323 reflect_handle.set_tool_visibility (false); 1324 create_line.set_tool_visibility (false); 1325 close_path_tool.set_tool_visibility (false); 1326 1327 quadratic_points.set_tool_visibility (false); 1328 cubic_points.set_tool_visibility (false); 1329 double_points.set_tool_visibility (false); 1330 convert_points.set_tool_visibility (false); 1331 1332 cut_background.set_tool_visibility (false); 1333 show_bg.set_tool_visibility (false); 1334 bg_selection.set_tool_visibility (false); 1335 background_threshold.set_tool_visibility (false); 1336 background_scale.set_tool_visibility (false); 1337 high_contrast_background.set_tool_visibility (false); 1338 auto_trace_resolution.set_tool_visibility (false); 1339 auto_trace.set_tool_visibility (false); 1340 auto_trace_simplify.set_tool_visibility (false); 1341 delete_background.set_tool_visibility (false); 1342 } 1343 1344 void show_background_tool_modifiers () { 1345 draw_tool_modifiers.set_headline (t_("Background Tools")); 1346 1347 cut_background.set_tool_visibility (true); 1348 show_bg.set_tool_visibility (true); 1349 bg_selection.set_tool_visibility (true); 1350 background_threshold.set_tool_visibility (true); 1351 background_scale.set_tool_visibility (true); 1352 high_contrast_background.set_tool_visibility (true); 1353 auto_trace_resolution.set_tool_visibility (true); 1354 auto_trace.set_tool_visibility (true); 1355 auto_trace_simplify.set_tool_visibility (true); 1356 delete_background.set_tool_visibility (true); 1357 } 1358 1359 void show_point_tool_modifiers () { 1360 draw_tool_modifiers.set_headline (t_("Control Points")); 1361 1362 tie_handles.set_tool_visibility (true); 1363 reflect_handle.set_tool_visibility (true); 1364 create_line.set_tool_visibility (true); 1365 close_path_tool.set_tool_visibility (true); 1366 1367 quadratic_points.set_tool_visibility (true); 1368 cubic_points.set_tool_visibility (true); 1369 double_points.set_tool_visibility (true); 1370 convert_points.set_tool_visibility (true); 1371 1372 reverse_path_tool.set_tool_visibility (true); 1373 } 1374 1375 void show_object_tool_modifiers () { 1376 draw_tool_modifiers.set_headline (t_("Object Tools")); 1377 1378 x_coordinate.set_tool_visibility (true); 1379 y_coordinate.set_tool_visibility (true); 1380 rotation.set_tool_visibility (true); 1381 width.set_tool_visibility (true); 1382 height.set_tool_visibility (true); 1383 skew.set_tool_visibility (true); 1384 1385 reverse_path_tool.set_tool_visibility (true); 1386 move_layer.set_tool_visibility (true); 1387 flip_vertical.set_tool_visibility (true); 1388 flip_horizontal.set_tool_visibility (true); 1389 } 1390 1391 public void update_drawing_and_background_tools (Tool current_tool) { 1392 IdleSource idle = new IdleSource (); 1393 1394 idle.set_callback (() => { 1395 Glyph g = MainWindow.get_current_glyph (); 1396 1397 hide_all_modifiers (); 1398 1399 foreach (Tool t in draw_tools.tool) { 1400 if (t != current_tool) { 1401 t.set_selected (false); 1402 } 1403 } 1404 1405 cut_background.set_selected (false); 1406 1407 bezier_tool.set_selected (false); 1408 pen_tool.set_selected (false); 1409 point_tool.set_selected (false); 1410 zoom_tool.set_selected (false); 1411 move_tool.set_selected (false); 1412 resize_tool.set_selected (false); 1413 track_tool.set_selected (false); 1414 move_canvas.set_selected (false); 1415 delete_background.set_selected (false); 1416 1417 show_bg.set_selected (g.get_background_visible ()); 1418 show_bg.set_active (false); 1419 bg_selection.set_selected (false); 1420 background_scale.set_active (false); 1421 1422 rectangle.set_selected (false); 1423 circle.set_selected (false); 1424 1425 reverse_path_tool.set_selected (false); 1426 move_layer.set_selected (false); 1427 flip_vertical.set_selected (false); 1428 flip_horizontal.set_selected (false); 1429 1430 current_tool.set_selected (true); 1431 1432 if (resize_tool.is_selected () || move_tool.is_selected ()) { 1433 show_object_tool_modifiers (); 1434 } else if (bezier_tool.is_selected () 1435 || pen_tool.is_selected () 1436 || point_tool.is_selected () 1437 || track_tool.is_selected ()) { 1438 show_point_tool_modifiers (); 1439 } else if (move_background.is_selected () 1440 || cut_background.is_selected () 1441 || show_bg.is_selected () 1442 || high_contrast_background.is_selected () 1443 || auto_trace.is_selected ()) { 1444 show_background_tool_modifiers (); 1445 } 1446 1447 MainWindow.get_toolbox ().update_expanders (); 1448 draw_tool_modifiers.redraw (); 1449 1450 return false; 1451 }); 1452 1453 idle.attach (null); 1454 } 1455 1456 void update_type_selection () { 1457 IdleSource idle = new IdleSource (); 1458 1459 // Do this in idle, after the animation 1460 idle.set_callback (() => { 1461 Font f = BirdFont.get_current_font (); 1462 1463 quadratic_points.set_selected (false); 1464 cubic_points.set_selected (false); 1465 double_points.set_selected (false); 1466 1467 switch (point_type) { 1468 case PointType.QUADRATIC: 1469 quadratic_points.set_selected (true); 1470 f.settings.set_setting ("point_type", "quadratic"); 1471 break; 1472 case PointType.CUBIC: 1473 cubic_points.set_selected (true); 1474 f.settings.set_setting ("point_type", "cubic"); 1475 break; 1476 case PointType.DOUBLE_CURVE: 1477 double_points.set_selected (true); 1478 f.settings.set_setting ("point_type", "double_curve"); 1479 break; 1480 } 1481 1482 convert_points.set_selected (false); 1483 1484 Toolbox.redraw_tool_box (); 1485 return false; 1486 }); 1487 1488 idle.attach (null); 1489 } 1490 1491 public static void set_default_point_type (string type) { 1492 if (type == "quadratic") { 1493 quadratic_points.set_selected (true); 1494 point_type = PointType.QUADRATIC; 1495 } else if (type == "cubic") { 1496 cubic_points.set_selected (true); 1497 point_type = PointType.CUBIC; 1498 } else if (type == "double_curve") { 1499 double_points.set_selected (true); 1500 point_type = PointType.DOUBLE_CURVE; 1501 } 1502 } 1503 1504 public override Gee.ArrayList<Expander> get_expanders () { 1505 return expanders; 1506 } 1507 1508 /** Insert new points of this type. */ 1509 public static PointType get_selected_point_type () { 1510 return point_type; 1511 } 1512 1513 public void remove_all_grid_buttons () { 1514 grid_expander.tool.clear (); 1515 1516 GridTool.sizes.clear (); 1517 1518 MainWindow.get_toolbox ().update_expanders (); 1519 MainWindow.get_toolbox ().redraw (0, 0, Toolbox.allocation_width, Toolbox.allocation_height); 1520 } 1521 1522 public void parse_grid (string spin_button_value) { 1523 SpinButton sb = add_new_grid (double.parse (spin_button_value), false); 1524 MainWindow.get_toolbox ().select_tool (sb); 1525 } 1526 1527 public static SpinButton add_new_grid (double size = 2, bool update_settings_in_font = true) { 1528 SpinButton grid_width = new SpinButton ("grid_width", t_("Set size for grid")); 1529 Toolbox tb = MainWindow.get_toolbox (); 1530 1531 grid_width.set_value_round (size); 1532 1533 grid_width.new_value_action.connect((self) => { 1534 Font font = BirdFont.get_current_font (); 1535 SpinButton w; 1536 1537 grid_width.select_action (grid_width); 1538 font.grid_width.clear (); 1539 1540 foreach (Tool t in grid_expander.tool) { 1541 return_if_fail (t is SpinButton); 1542 w = (SpinButton) t; 1543 font.grid_width.add (w.get_display_value ()); 1544 } 1545 }); 1546 1547 grid_width.select_action.connect((self) => { 1548 return_if_fail (self is SpinButton); 1549 SpinButton sb = (SpinButton) self; 1550 GridTool.set_grid_width (sb.get_value ()); 1551 GlyphCanvas.redraw (); 1552 }); 1553 1554 grid_expander.add_tool (grid_width); 1555 1556 tb.update_expanders (); 1557 1558 tb.redraw (0, 0, Toolbox.allocation_width, Toolbox.allocation_height); 1559 1560 tb.select_tool (grid_width); 1561 grid_width.set_active (false); 1562 1563 if (update_settings_in_font) { 1564 GridTool.sizes.add (grid_width); 1565 1566 foreach (Tool t in grid_expander.tool) { 1567 SpinButton sb = (SpinButton) t; 1568 BirdFont.get_current_font ().grid_width.add (sb.get_display_value ()); 1569 } 1570 } 1571 1572 return grid_width; 1573 } 1574 1575 public void remove_current_grid () { 1576 Tool grid_width; 1577 Toolbox tb = MainWindow.get_toolbox (); 1578 1579 foreach (Tool t in grid_expander.tool) { 1580 if (t.is_selected () && t is SpinButton) { 1581 GridTool.sizes.remove ((SpinButton)t); 1582 grid_expander.tool.remove (t); 1583 break; 1584 } 1585 } 1586 1587 if (grid_expander.tool.size > 0) { 1588 grid_width = grid_expander.tool.get (grid_expander.tool.size - 1); 1589 tb.select_tool (grid_width); 1590 grid_width.set_active (false); 1591 } 1592 1593 MainWindow.get_toolbox ().update_expanders (); 1594 tb.redraw (0, 0, Toolbox.allocation_width, Toolbox.allocation_height); 1595 } 1596 1597 private void add_expander (Expander e) { 1598 expanders.add (e); 1599 } 1600 1601 public override Gee.ArrayList<string> get_displays () { 1602 Gee.ArrayList<string> d = new Gee.ArrayList<string> (); 1603 d.add ("Glyph"); 1604 return d; 1605 } 1606 1607 public static void update_layers () 1608 requires (!is_null (layer_tools)) { 1609 Glyph g = MainWindow.get_current_glyph (); 1610 int i = 0; 1611 1612 layer_tools.tool.clear (); 1613 foreach (Layer layer in g.layers.subgroups) { 1614 LayerLabel label = new LayerLabel (layer); 1615 layer_tools.add_tool (label, 0); 1616 1617 if (i == g.current_layer) { 1618 label.select_layer (); 1619 } 1620 1621 i++; 1622 } 1623 1624 MainWindow.get_toolbox ().update_expanders (); 1625 layer_tools.redraw (); 1626 Toolbox.redraw_tool_box (); 1627 } 1628 1629 public static void deselect_layers () 1630 requires (!is_null (layer_tools)) { 1631 LayerLabel l; 1632 1633 foreach (Tool t in layer_tools.tool) { 1634 if (t is LayerLabel) { 1635 l = (LayerLabel) t; 1636 l.selected_layer = false; 1637 } 1638 } 1639 } 1640 1641 public static void set_stroke_tool_visibility () { 1642 object_stroke.visible = StrokeTool.add_stroke; 1643 line_cap_butt.visible = StrokeTool.add_stroke; 1644 line_cap_round.visible = StrokeTool.add_stroke; 1645 line_cap_square.visible = StrokeTool.add_stroke; 1646 MainWindow.get_toolbox ().update_expanders (); 1647 stroke_expander.redraw (); 1648 } 1649 } 1650 1651 } 1652