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