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