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.
Revert "Error handeling in merge code"
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 BirdFont.get_current_font ().settings.set_setting ("autotrace_threshold", background_threshold.get_display_value ()); 740 }); 741 742 draw_tool_modifiers.add_tool (background_threshold); 743 744 auto_trace_resolution = new SpinButton ("auto_trace_resolution", t_("Amount of autotrace details")); 745 auto_trace_resolution.set_value_round (1); 746 auto_trace_resolution.show_icon (true); 747 748 auto_trace_resolution.new_value_action.connect ((self) => { 749 Glyph g = MainWindow.get_current_glyph (); 750 BackgroundImage? bg = g.get_background_image (); 751 BackgroundImage b; 752 753 if (bg != null) { 754 b = (!) bg; 755 b.update_background (); 756 } 757 758 BirdFont.get_current_font ().settings.set_setting ("autotrace_resolution", auto_trace_resolution.get_display_value ()); 759 }); 760 761 draw_tool_modifiers.add_tool (auto_trace_resolution); 762 763 auto_trace_simplify = new SpinButton ("auto_trace_simplify", t_("Autotrace simplification")); 764 auto_trace_simplify.set_value_round (0.5); 765 auto_trace_simplify.show_icon (true); 766 767 auto_trace_simplify.new_value_action.connect ((self) => { 768 BirdFont.get_current_font ().settings.set_setting ("autotrace_simplification", background_threshold.get_display_value ()); 769 }); 770 771 draw_tool_modifiers.add_tool (auto_trace_simplify); 772 773 auto_trace = new Tool ("autotrace", t_("Autotrace background image")); 774 auto_trace.select_action.connect ((self) => { 775 Task t = new Task (auto_trace_background); 776 MainWindow.native_window.run_background_thread (t); 777 }); 778 779 draw_tool_modifiers.add_tool (auto_trace); 780 781 delete_background = new Tool ("delete_background", t_("Delete background image")); 782 delete_background.select_action.connect ((self) => { 783 MainWindow.get_current_glyph ().delete_background (); 784 }); 785 786 draw_tool_modifiers.add_tool (delete_background); 787 788 add_layer = new Tool ("add_layer", t_("Add layer")); 789 add_layer.select_action.connect ((self) => { 790 layer_tools.visible = true; 791 MainWindow.get_current_glyph ().add_new_layer (); 792 update_layers (); 793 show_layers.selected = true; 794 add_layer.selected = false; 795 }); 796 layer_settings.add_tool (add_layer); 797 798 show_layers = new Tool ("show_layers", t_("Show layers")); 799 show_layers.select_action.connect ((self) => { 800 layer_tools.visible = !layer_tools.visible; 801 MainWindow.get_toolbox ().update_expanders (); 802 Toolbox.redraw_tool_box (); 803 show_layers.selected = layer_tools.visible; 804 }); 805 layer_settings.add_tool (show_layers); 806 807 // add stroke to path 808 add_stroke = new Tool ("apply_stroke", t_("Apply stroke")); 809 add_stroke.select_action.connect ((self) => { 810 Font f; 811 Glyph g = MainWindow.get_current_glyph (); 812 StrokeTool.add_stroke = !StrokeTool.add_stroke; 813 StrokeTool.stroke_width = object_stroke.get_value (); 814 815 add_stroke.selected = StrokeTool.add_stroke; 816 set_stroke_tool_visibility (); 817 GlyphCanvas.redraw (); 818 g.store_undo_state (); 819 820 if (StrokeTool.add_stroke) { 821 foreach (Path p in g.active_paths) { 822 p.stroke = StrokeTool.stroke_width; 823 p.line_cap = StrokeTool.line_cap; 824 } 825 } else { 826 foreach (Path p in g.active_paths) { 827 p.stroke = 0; 828 } 829 } 830 831 f = BirdFont.get_current_font (); 832 f.settings.set_setting ("apply_stroke", @"$(StrokeTool.add_stroke)"); 833 834 stroke_expander.redraw (); 835 MainWindow.get_toolbox ().update_expanders (); 836 }); 837 stroke_expander.add_tool (add_stroke); 838 add_stroke.selected = StrokeTool.add_stroke; 839 840 // edit stroke width 841 object_stroke = new SpinButton ("object_stroke", t_("Stroke width")); 842 object_stroke.set_big_number (true); 843 object_stroke.set_value_round (2); 844 object_stroke.set_max (0.01); 845 object_stroke.set_max (50); 846 847 object_stroke.new_value_action.connect((self) => { 848 Font f; 849 Glyph g = MainWindow.get_current_glyph (); 850 851 bool tool = resize_tool.is_selected () 852 || move_tool.is_selected () 853 || pen_tool.is_selected () 854 || track_tool.is_selected () 855 || point_tool.is_selected () 856 || bezier_tool.is_selected (); 857 858 StrokeTool.stroke_width = object_stroke.get_value (); 859 860 if (tool && StrokeTool.add_stroke) { 861 foreach (Path p in g.active_paths) { 862 p.stroke = StrokeTool.stroke_width; 863 p.reset_stroke (); 864 } 865 } 866 867 f = BirdFont.get_current_font (); 868 f.settings.set_setting ("stroke_width", object_stroke.get_display_value ()); 869 870 GlyphCanvas.redraw (); 871 }); 872 stroke_expander.add_tool (object_stroke); 873 874 move_tool.selection_changed.connect (() => { 875 update_stroke_settings (); 876 }); 877 878 move_tool.objects_moved.connect (() => { 879 update_stroke_settings (); 880 }); 881 882 // create outline from path 883 outline = new Tool ("stroke_to_outline", t_("Create outline form stroke")); 884 outline.select_action.connect ((self) => { 885 StrokeTool.stroke_selected_paths (); 886 outline.set_selected (false); 887 }); 888 stroke_expander.add_tool (outline); 889 890 // set line cap 891 line_cap_butt = new Tool ("line_cap_butt", t_("Butt line cap")); 892 line_cap_butt.select_action.connect ((self) => { 893 Glyph g; 894 895 g = MainWindow.get_current_glyph (); 896 g.store_undo_state (); 897 898 foreach (Path p in g.active_paths) { 899 p.line_cap = LineCap.BUTT; 900 p.reset_stroke (); 901 } 902 903 StrokeTool.line_cap = LineCap.BUTT; 904 Font f = BirdFont.get_current_font (); 905 f.settings.set_setting ("line_cap", @"butt"); 906 907 line_cap_butt.selected = true; 908 line_cap_round.selected = false; 909 line_cap_square.selected = false; 910 911 GlyphCanvas.redraw (); 912 }); 913 stroke_expander.add_tool (line_cap_butt); 914 915 line_cap_round = new Tool ("line_cap_round", t_("Round line cap")); 916 line_cap_round.select_action.connect ((self) => { 917 Glyph g; 918 919 g = MainWindow.get_current_glyph (); 920 g.store_undo_state (); 921 922 foreach (Path p in g.active_paths) { 923 p.line_cap = LineCap.ROUND; 924 p.reset_stroke (); 925 } 926 927 StrokeTool.line_cap = LineCap.ROUND; 928 929 Font f = BirdFont.get_current_font (); 930 f.settings.set_setting ("line_cap", @"round"); 931 932 line_cap_butt.selected = false; 933 line_cap_round.selected = true; 934 line_cap_square.selected = false; 935 936 GlyphCanvas.redraw (); 937 }); 938 stroke_expander.add_tool (line_cap_round); 939 940 line_cap_square = new Tool ("line_cap_square", t_("Square line cap")); 941 line_cap_square.select_action.connect ((self) => { 942 Glyph g; 943 944 g = MainWindow.get_current_glyph (); 945 g.store_undo_state (); 946 947 foreach (Path p in g.active_paths) { 948 p.line_cap = LineCap.SQUARE; 949 p.reset_stroke (); 950 } 951 952 StrokeTool.line_cap = LineCap.SQUARE; 953 954 Font f = BirdFont.get_current_font (); 955 f.settings.set_setting ("line_cap", @"square"); 956 957 line_cap_butt.selected = false; 958 line_cap_round.selected = false; 959 line_cap_square.selected = true; 960 961 GlyphCanvas.redraw (); 962 }); 963 stroke_expander.add_tool (line_cap_square); 964 965 // tests 966 if (BirdFont.has_argument ("--test")) { 967 Tool test_case = new Tool ("test_case"); 968 test_case.select_action.connect((self) => { 969 if (self.is_selected ()) { 970 if (TestBirdFont.is_running ()) { 971 TestBirdFont.pause (); 972 } else { 973 TestBirdFont.continue (); 974 } 975 } 976 }); 977 test_tools.add_tool (test_case); 978 979 Tool slow_test = new Tool ("slow_test"); 980 slow_test.select_action.connect((self) => { 981 bool s = TestBirdFont.is_slow_test (); 982 TestBirdFont.set_slow_test (!s); 983 s = TestBirdFont.is_slow_test (); 984 self.set_selected (s); 985 }); 986 987 test_tools.add_tool (slow_test); 988 989 // Run from commad line 990 string? st = BirdFont.get_argument ("--test"); 991 if (st != null && ((!)st).char_count () > 0) { 992 IdleSource idle = new IdleSource (); 993 994 idle.set_callback (() => { 995 MainWindow.get_toolbox ().select_tool (test_case); 996 return false; 997 }); 998 999 idle.attach (null); 1000 } 1001 1002 if (BirdFont.has_argument ("--slow")) { 1003 MainWindow.get_toolbox ().select_tool (slow_test); 1004 } 1005 1006 } 1007 1008 // guide lines, grid and other guidlines 1009 help_lines = new Tool ("help_lines", t_("Show guidelines")); 1010 help_lines.select_action.connect ((self) => { 1011 bool h; 1012 h = GlyphCanvas.get_current_glyph ().get_show_help_lines (); 1013 GlyphCanvas.get_current_glyph ().set_show_help_lines (!h); 1014 self.set_selected (!h); 1015 GlyphCanvas.get_current_glyph ().redraw_help_lines (); 1016 }); 1017 selected_line = GlyphCanvas.get_current_glyph ().get_show_help_lines (); 1018 help_lines.set_selected (selected_line); 1019 guideline_tools.add_tool (help_lines); 1020 1021 xheight_help_lines = new Tool ("show_xheight_helplines", t_("Show more guidelines")); 1022 xheight_help_lines.select_action.connect ((self) => { 1023 Glyph g = MainWindow.get_current_glyph (); 1024 bool v = !g.get_xheight_lines_visible (); 1025 g.set_xheight_lines_visible (v); 1026 self.set_selected (v); 1027 GlyphCanvas.redraw (); 1028 1029 if (v && !help_lines.is_selected ()) { 1030 MainWindow.get_toolbox ().select_tool (help_lines); 1031 } 1032 }); 1033 selected_line = GlyphCanvas.get_current_glyph ().get_xheight_lines_visible (); 1034 xheight_help_lines.set_selected (selected_line); 1035 guideline_tools.add_tool (xheight_help_lines); 1036 1037 background_help_lines = new Tool ("background_help_lines", t_("Show guidelines at top and bottom margin")); 1038 background_help_lines.select_action.connect ((self) => { 1039 Glyph g = MainWindow.get_current_glyph (); 1040 bool v = !g.get_margin_lines_visible (); 1041 g.set_margin_lines_visible (v); 1042 self.set_selected (v); 1043 GlyphCanvas.redraw (); 1044 1045 if (v && !help_lines.is_selected ()) { 1046 MainWindow.get_toolbox ().select_tool (help_lines); 1047 } 1048 }); 1049 selected_line = GlyphCanvas.get_current_glyph ().get_margin_lines_visible (); 1050 background_help_lines.set_selected (selected_line); 1051 guideline_tools.add_tool (background_help_lines); 1052 1053 show_grid = new GridTool ("show_grid"); 1054 show_grid.select_action.connect (() => { 1055 grid_expander.visible = show_grid.selected; 1056 MainWindow.get_toolbox ().update_expanders (); 1057 }); 1058 guideline_tools.add_tool (show_grid); 1059 grid_expander.visible = false; 1060 1061 lock_grid = new Tool ("lock_grid", t_("Lock guides and grid")); 1062 lock_grid.select_action.connect ((self) => { 1063 SpinButton sb; 1064 FontSettings fs; 1065 1066 GridTool.lock_grid = !GridTool.lock_grid; 1067 1068 foreach (Tool t in grid.tool) { 1069 if (t is SpinButton) { 1070 sb = (SpinButton) t; 1071 sb.locked = GridTool.lock_grid; 1072 } 1073 } 1074 1075 lock_grid.selected = GridTool.lock_grid; 1076 fs = BirdFont.get_current_font ().settings; 1077 fs.set_setting ("lock_grid", @"$(GridTool.lock_grid)"); 1078 }); 1079 guideline_tools.add_tool (lock_grid); 1080 1081 // Zoom tools 1082 zoom_bar = new ZoomBar (); 1083 zoom_bar.new_zoom.connect ((z) => { 1084 Glyph g = MainWindow.get_current_glyph (); 1085 double zoom = 20 * z + 1; 1086 double xc, yc, nxc, nyc; 1087 1088 xc = Glyph.path_coordinate_x (Glyph.xc ()); 1089 yc = Glyph.path_coordinate_y (Glyph.yc ()); 1090 1091 g.set_zoom (zoom); 1092 1093 nxc = Glyph.path_coordinate_x (Glyph.xc ()); 1094 nyc = Glyph.path_coordinate_y (Glyph.yc ()); 1095 1096 g.view_offset_x -= nxc - xc; 1097 g.view_offset_y += nyc - yc; 1098 1099 GlyphCanvas.redraw (); 1100 }); 1101 zoombar_tool.add_tool (zoom_bar); 1102 1103 Tool reset_zoom = new Tool ("zoom_1_1", t_("Zoom Out More")); 1104 reset_zoom.select_action.connect ((self) => { 1105 zoom_tool.store_current_view (); 1106 glyph_canvas.get_current_display ().reset_zoom (); 1107 glyph_canvas.redraw_area(0, 0, GlyphCanvas.allocation.width, GlyphCanvas.allocation.height); 1108 }); 1109 zoombar_tool.add_tool (reset_zoom); 1110 reset_zoom.set_tool_visibility (false); 1111 1112 Tool full_glyph = new Tool ("full_glyph", t_("Show full glyph")); 1113 full_glyph.select_action.connect((self) => { 1114 zoom_tool.store_current_view (); 1115 zoom_tool.zoom_full_glyph (); 1116 }); 1117 zoombar_tool.add_tool (full_glyph); 1118 1119 Tool zoom_boundaries = new Tool ("zoom_boundaries", t_("Fit in view")); 1120 zoom_boundaries.select_action.connect((self) => { 1121 zoom_tool.store_current_view (); 1122 glyph_canvas.get_current_display ().zoom_max (); 1123 }); 1124 zoombar_tool.add_tool (zoom_boundaries); 1125 1126 Tool zoom_bg = new Tool ("zoom_background_image", t_("Zoom in on background image")); 1127 zoom_bg.select_action.connect((self) => { 1128 if (MainWindow.get_current_glyph ().get_background_image () != null) { 1129 zoom_tool.store_current_view (); 1130 ZoomTool.zoom_full_background_image (); 1131 glyph_canvas.redraw_area(0, 0, GlyphCanvas.allocation.width, GlyphCanvas.allocation.height); 1132 } 1133 }); 1134 zoombar_tool.add_tool (zoom_bg); 1135 1136 Tool zoom_prev = new Tool ("prev", t_("Previous view")); 1137 zoom_prev.select_action.connect((self) => { 1138 zoom_tool.previous_view (); 1139 }); 1140 zoombar_tool.add_tool (zoom_prev); 1141 1142 Tool zoom_next = new Tool ("next", t_("Next view")); 1143 zoom_next.select_action.connect((self) => { 1144 zoom_tool.next_view (); 1145 }); 1146 zoombar_tool.add_tool (zoom_next); // view_tools 1147 zoom_next.set_tool_visibility (false); 1148 1149 // shape tools 1150 circle = new CircleTool ("circle"); 1151 circle.select_action.connect ((self) => { 1152 update_drawing_and_background_tools (self); 1153 }); 1154 shape_tools.add_tool (circle); 1155 1156 rectangle = new RectangleTool ("rectangle"); 1157 rectangle.select_action.connect ((self) => { 1158 update_drawing_and_background_tools (self); 1159 }); 1160 shape_tools.add_tool (rectangle); 1161 1162 add_expander (font_name); 1163 add_expander (draw_tools); 1164 1165 if (BirdFont.android) { 1166 add_expander (key_tools); 1167 } 1168 1169 add_expander (draw_tool_modifiers); 1170 add_expander (layer_settings); 1171 add_expander (layer_tools); 1172 add_expander (stroke_expander); 1173 add_expander (guideline_tools); 1174 add_expander (grid); 1175 add_expander (zoombar_tool); 1176 add_expander (shape_tools); 1177 1178 // Fixa: add_expander (trace); 1179 if (BirdFont.has_argument ("--test")) { 1180 add_expander (test_tools); 1181 } 1182 1183 layer_settings.set_persistent (true); 1184 layer_settings.set_unique (false); 1185 1186 draw_tools.set_persistent (true); 1187 draw_tools.set_unique (false); 1188 1189 stroke_expander.set_persistent (true); 1190 stroke_expander.set_unique (false); 1191 1192 key_tools.set_persistent (false); 1193 key_tools.set_unique (false); 1194 1195 draw_tool_modifiers.set_persistent (true); 1196 draw_tool_modifiers.set_unique (false); 1197 1198 test_tools.set_persistent (true); 1199 1200 guideline_tools.set_persistent (true); 1201 guideline_tools.set_unique (false); 1202 1203 grid.set_persistent (true); 1204 grid.set_unique (true); 1205 1206 shape_tools.set_persistent (true); 1207 shape_tools.set_unique (true); 1208 1209 // let these tools progagate events even when other tools are selected 1210 foreach (Tool t in draw_tools.tool) { 1211 t.editor_events = true; 1212 } 1213 1214 foreach (Tool t in shape_tools.tool) { 1215 t.editor_events = true; 1216 t.persistent = true; 1217 } 1218 1219 move_background.editor_events = true; 1220 cut_background.editor_events = true; 1221 move_canvas.editor_events = true; 1222 1223 move_background.persistent = true; 1224 cut_background.persistent = true; 1225 move_canvas.persistent = true; 1226 1227 // Default selection 1228 IdleSource idle = new IdleSource (); 1229 idle.set_callback (() => { 1230 Toolbox tb = MainWindow.get_toolbox (); 1231 1232 tb.reset_active_tool (); 1233 update_drawing_and_background_tools (point_tool); 1234 tb.select_tool (point_tool); 1235 tb.set_current_tool (point_tool); 1236 1237 set_point_type_from_preferences (); 1238 1239 if (GlyphCanvas.get_current_glyph ().get_show_help_lines ()) { 1240 help_lines.set_selected (true); 1241 help_lines.set_active (false); 1242 } 1243 1244 add_new_grid (1); 1245 add_new_grid (2); 1246 add_new_grid (4); 1247 1248 MainWindow.get_toolbox ().move (0, 0); 1249 set_stroke_tool_visibility (); 1250 1251 return false; 1252 }); 1253 idle.attach (null); 1254 1255 // update selelction when the user switches tab 1256 MainWindow.get_tab_bar ().signal_tab_selected.connect((tab) => { 1257 Glyph glyph; 1258 1259 if (tab.get_display () is Glyph) { 1260 glyph = (Glyph) tab.get_display (); 1261 show_bg.set_selected (glyph.get_background_visible ()); 1262 update_line_selection (glyph); 1263 } 1264 }); 1265 } 1266 1267 public static void update_stroke_settings () { 1268 bool stroke = false; 1269 Glyph g = MainWindow.get_current_glyph (); 1270 1271 foreach (Path p in g.active_paths) { 1272 if (p.stroke > 0) { 1273 stroke = true; 1274 } 1275 } 1276 1277 add_stroke.selected = stroke; 1278 StrokeTool.add_stroke = stroke; 1279 set_stroke_tool_visibility (); 1280 } 1281 1282 void auto_trace_background () { 1283 Glyph g = MainWindow.get_current_glyph (); 1284 BackgroundImage? bg = g.get_background_image (); 1285 BackgroundImage b; 1286 PathList pl; 1287 1288 if (bg != null) { 1289 b = (!) bg; 1290 pl = b.autotrace (); 1291 foreach (Path p in pl.paths) { 1292 g.add_path (p); 1293 } 1294 } 1295 } 1296 1297 void update_line_selection (Glyph glyph) { 1298 help_lines.set_selected (glyph.get_show_help_lines ()); 1299 xheight_help_lines.set_selected (glyph.get_xheight_lines_visible ()); 1300 background_help_lines.set_selected (glyph.get_margin_lines_visible ()); 1301 } 1302 1303 public static void set_point_type_from_preferences () { 1304 string type = Preferences.get ("point_type"); 1305 if (type == "double_points") { 1306 Toolbox.select_tool_by_name ("double_points"); 1307 } else if (type == "quadratic_points") { 1308 Toolbox.select_tool_by_name ("quadratic_points"); 1309 } if (type == "cubic_points") { 1310 Toolbox.select_tool_by_name ("cubic_points"); 1311 } 1312 } 1313 1314 void hide_all_modifiers () { 1315 x_coordinate.set_tool_visibility (false); 1316 y_coordinate.set_tool_visibility (false); 1317 rotation.set_tool_visibility (false); 1318 width.set_tool_visibility (false); 1319 height.set_tool_visibility (false); 1320 skew.set_tool_visibility (false); 1321 reverse_path_tool.set_tool_visibility (false); 1322 move_layer.set_tool_visibility (false); 1323 flip_vertical.set_tool_visibility (false); 1324 flip_horizontal.set_tool_visibility (false); 1325 1326 tie_handles.set_tool_visibility (false); 1327 reflect_handle.set_tool_visibility (false); 1328 create_line.set_tool_visibility (false); 1329 close_path_tool.set_tool_visibility (false); 1330 1331 quadratic_points.set_tool_visibility (false); 1332 cubic_points.set_tool_visibility (false); 1333 double_points.set_tool_visibility (false); 1334 convert_points.set_tool_visibility (false); 1335 1336 cut_background.set_tool_visibility (false); 1337 show_bg.set_tool_visibility (false); 1338 bg_selection.set_tool_visibility (false); 1339 background_threshold.set_tool_visibility (false); 1340 background_scale.set_tool_visibility (false); 1341 high_contrast_background.set_tool_visibility (false); 1342 auto_trace_resolution.set_tool_visibility (false); 1343 auto_trace.set_tool_visibility (false); 1344 auto_trace_simplify.set_tool_visibility (false); 1345 delete_background.set_tool_visibility (false); 1346 } 1347 1348 void show_background_tool_modifiers () { 1349 draw_tool_modifiers.set_headline (t_("Background Tools")); 1350 1351 cut_background.set_tool_visibility (true); 1352 show_bg.set_tool_visibility (true); 1353 bg_selection.set_tool_visibility (true); 1354 background_threshold.set_tool_visibility (true); 1355 background_scale.set_tool_visibility (true); 1356 high_contrast_background.set_tool_visibility (true); 1357 auto_trace_resolution.set_tool_visibility (true); 1358 auto_trace.set_tool_visibility (true); 1359 auto_trace_simplify.set_tool_visibility (true); 1360 delete_background.set_tool_visibility (true); 1361 } 1362 1363 void show_point_tool_modifiers () { 1364 draw_tool_modifiers.set_headline (t_("Control Points")); 1365 1366 tie_handles.set_tool_visibility (true); 1367 reflect_handle.set_tool_visibility (true); 1368 create_line.set_tool_visibility (true); 1369 close_path_tool.set_tool_visibility (true); 1370 1371 quadratic_points.set_tool_visibility (true); 1372 cubic_points.set_tool_visibility (true); 1373 double_points.set_tool_visibility (true); 1374 convert_points.set_tool_visibility (true); 1375 1376 reverse_path_tool.set_tool_visibility (true); 1377 } 1378 1379 void show_object_tool_modifiers () { 1380 draw_tool_modifiers.set_headline (t_("Object Tools")); 1381 1382 x_coordinate.set_tool_visibility (true); 1383 y_coordinate.set_tool_visibility (true); 1384 rotation.set_tool_visibility (true); 1385 width.set_tool_visibility (true); 1386 height.set_tool_visibility (true); 1387 skew.set_tool_visibility (true); 1388 1389 reverse_path_tool.set_tool_visibility (true); 1390 move_layer.set_tool_visibility (true); 1391 flip_vertical.set_tool_visibility (true); 1392 flip_horizontal.set_tool_visibility (true); 1393 } 1394 1395 public void update_drawing_and_background_tools (Tool current_tool) { 1396 IdleSource idle = new IdleSource (); 1397 1398 idle.set_callback (() => { 1399 Glyph g = MainWindow.get_current_glyph (); 1400 1401 hide_all_modifiers (); 1402 1403 foreach (Tool t in draw_tools.tool) { 1404 if (t != current_tool) { 1405 t.set_selected (false); 1406 } 1407 } 1408 1409 cut_background.set_selected (false); 1410 1411 bezier_tool.set_selected (false); 1412 pen_tool.set_selected (false); 1413 point_tool.set_selected (false); 1414 zoom_tool.set_selected (false); 1415 move_tool.set_selected (false); 1416 resize_tool.set_selected (false); 1417 track_tool.set_selected (false); 1418 move_canvas.set_selected (false); 1419 delete_background.set_selected (false); 1420 1421 show_bg.set_selected (g.get_background_visible ()); 1422 show_bg.set_active (false); 1423 bg_selection.set_selected (false); 1424 background_scale.set_active (false); 1425 1426 rectangle.set_selected (false); 1427 circle.set_selected (false); 1428 1429 reverse_path_tool.set_selected (false); 1430 move_layer.set_selected (false); 1431 flip_vertical.set_selected (false); 1432 flip_horizontal.set_selected (false); 1433 1434 current_tool.set_selected (true); 1435 1436 if (resize_tool.is_selected () || move_tool.is_selected ()) { 1437 show_object_tool_modifiers (); 1438 } else if (bezier_tool.is_selected () 1439 || pen_tool.is_selected () 1440 || point_tool.is_selected () 1441 || track_tool.is_selected ()) { 1442 show_point_tool_modifiers (); 1443 } else if (move_background.is_selected () 1444 || cut_background.is_selected () 1445 || show_bg.is_selected () 1446 || high_contrast_background.is_selected () 1447 || auto_trace.is_selected ()) { 1448 show_background_tool_modifiers (); 1449 } else { 1450 show_point_tool_modifiers (); 1451 } 1452 1453 MainWindow.get_toolbox ().update_expanders (); 1454 draw_tool_modifiers.redraw (); 1455 1456 return false; 1457 }); 1458 1459 idle.attach (null); 1460 } 1461 1462 void update_type_selection () { 1463 IdleSource idle = new IdleSource (); 1464 1465 // Do this in idle, after the animation 1466 idle.set_callback (() => { 1467 Font f = BirdFont.get_current_font (); 1468 1469 quadratic_points.set_selected (false); 1470 cubic_points.set_selected (false); 1471 double_points.set_selected (false); 1472 1473 switch (point_type) { 1474 case PointType.QUADRATIC: 1475 quadratic_points.set_selected (true); 1476 f.settings.set_setting ("point_type", "quadratic"); 1477 break; 1478 case PointType.CUBIC: 1479 cubic_points.set_selected (true); 1480 f.settings.set_setting ("point_type", "cubic"); 1481 break; 1482 case PointType.DOUBLE_CURVE: 1483 double_points.set_selected (true); 1484 f.settings.set_setting ("point_type", "double_curve"); 1485 break; 1486 } 1487 1488 convert_points.set_selected (false); 1489 1490 Toolbox.redraw_tool_box (); 1491 return false; 1492 }); 1493 1494 idle.attach (null); 1495 } 1496 1497 public static void set_default_point_type (string type) { 1498 if (type == "quadratic") { 1499 quadratic_points.set_selected (true); 1500 point_type = PointType.QUADRATIC; 1501 } else if (type == "cubic") { 1502 cubic_points.set_selected (true); 1503 point_type = PointType.CUBIC; 1504 } else if (type == "double_curve") { 1505 double_points.set_selected (true); 1506 point_type = PointType.DOUBLE_CURVE; 1507 } 1508 } 1509 1510 public override Gee.ArrayList<Expander> get_expanders () { 1511 return expanders; 1512 } 1513 1514 /** Insert new points of this type. */ 1515 public static PointType get_selected_point_type () { 1516 return point_type; 1517 } 1518 1519 public void remove_all_grid_buttons () { 1520 grid_expander.tool.clear (); 1521 1522 GridTool.sizes.clear (); 1523 1524 MainWindow.get_toolbox ().update_expanders (); 1525 MainWindow.get_toolbox ().redraw (0, 0, Toolbox.allocation_width, Toolbox.allocation_height); 1526 } 1527 1528 public void parse_grid (string spin_button_value) { 1529 SpinButton sb = add_new_grid (double.parse (spin_button_value), false); 1530 MainWindow.get_toolbox ().select_tool (sb); 1531 } 1532 1533 public static SpinButton add_new_grid (double size = 2, bool update_settings_in_font = true) { 1534 SpinButton grid_width = new SpinButton ("grid_width", t_("Set size for grid")); 1535 Toolbox tb = MainWindow.get_toolbox (); 1536 1537 grid_width.set_value_round (size); 1538 1539 grid_width.new_value_action.connect((self) => { 1540 Font font = BirdFont.get_current_font (); 1541 SpinButton w; 1542 1543 grid_width.select_action (grid_width); 1544 font.grid_width.clear (); 1545 1546 foreach (Tool t in grid_expander.tool) { 1547 return_if_fail (t is SpinButton); 1548 w = (SpinButton) t; 1549 font.grid_width.add (w.get_display_value ()); 1550 } 1551 }); 1552 1553 grid_width.select_action.connect((self) => { 1554 return_if_fail (self is SpinButton); 1555 SpinButton sb = (SpinButton) self; 1556 GridTool.set_grid_width (sb.get_value ()); 1557 GlyphCanvas.redraw (); 1558 }); 1559 1560 grid_expander.add_tool (grid_width); 1561 1562 tb.update_expanders (); 1563 1564 tb.redraw (0, 0, Toolbox.allocation_width, Toolbox.allocation_height); 1565 1566 tb.select_tool (grid_width); 1567 grid_width.set_active (false); 1568 1569 if (update_settings_in_font) { 1570 GridTool.sizes.add (grid_width); 1571 1572 foreach (Tool t in grid_expander.tool) { 1573 SpinButton sb = (SpinButton) t; 1574 BirdFont.get_current_font ().grid_width.add (sb.get_display_value ()); 1575 } 1576 } 1577 1578 return grid_width; 1579 } 1580 1581 public void remove_current_grid () { 1582 Tool grid_width; 1583 Toolbox tb = MainWindow.get_toolbox (); 1584 1585 foreach (Tool t in grid_expander.tool) { 1586 if (t.is_selected () && t is SpinButton) { 1587 GridTool.sizes.remove ((SpinButton)t); 1588 grid_expander.tool.remove (t); 1589 break; 1590 } 1591 } 1592 1593 if (grid_expander.tool.size > 0) { 1594 grid_width = grid_expander.tool.get (grid_expander.tool.size - 1); 1595 tb.select_tool (grid_width); 1596 grid_width.set_active (false); 1597 } 1598 1599 MainWindow.get_toolbox ().update_expanders (); 1600 tb.redraw (0, 0, Toolbox.allocation_width, Toolbox.allocation_height); 1601 } 1602 1603 private void add_expander (Expander e) { 1604 expanders.add (e); 1605 } 1606 1607 public override Gee.ArrayList<string> get_displays () { 1608 Gee.ArrayList<string> d = new Gee.ArrayList<string> (); 1609 d.add ("Glyph"); 1610 return d; 1611 } 1612 1613 public static void update_layers () 1614 requires (!is_null (layer_tools)) { 1615 Glyph g = MainWindow.get_current_glyph (); 1616 int i = 0; 1617 1618 layer_tools.tool.clear (); 1619 foreach (Layer layer in g.layers.subgroups) { 1620 LayerLabel label = new LayerLabel (layer); 1621 layer_tools.add_tool (label, 0); 1622 1623 if (i == g.current_layer) { 1624 label.select_layer (); 1625 } 1626 1627 i++; 1628 } 1629 1630 MainWindow.get_toolbox ().update_expanders (); 1631 layer_tools.redraw (); 1632 Toolbox.redraw_tool_box (); 1633 } 1634 1635 public static void deselect_layers () 1636 requires (!is_null (layer_tools)) { 1637 LayerLabel l; 1638 1639 foreach (Tool t in layer_tools.tool) { 1640 if (t is LayerLabel) { 1641 l = (LayerLabel) t; 1642 l.selected_layer = false; 1643 } 1644 } 1645 } 1646 1647 public static void set_stroke_tool_visibility () { 1648 object_stroke.visible = StrokeTool.add_stroke; 1649 line_cap_butt.visible = StrokeTool.add_stroke; 1650 line_cap_round.visible = StrokeTool.add_stroke; 1651 line_cap_square.visible = StrokeTool.add_stroke; 1652 MainWindow.get_toolbox ().update_expanders (); 1653 stroke_expander.redraw (); 1654 } 1655 } 1656 1657 } 1658