The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

SpacingClassTab.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/SpacingClassTab.vala.
Redraw after switching from rsb to lsb in spacing tab
1 /* 2 Copyright (C) 2014 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 using Cairo; 15 using Math; 16 17 namespace BirdFont { 18 19 public class SpacingClassTab : Table { 20 21 public static int NEW_CLASS = -1; 22 Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> (); 23 public static SpacingClass current_class; 24 public static bool current_class_first_element; 25 26 public SpacingClassTab () { 27 current_class = new SpacingClass ("", ""); 28 } 29 30 public override Gee.ArrayList<Row> get_rows () { 31 return rows; 32 } 33 34 public static void set_class (string glyph) { 35 print(@"G: $(glyph)\n"); 36 if (current_class_first_element) { 37 current_class.first = glyph; 38 } else { 39 current_class.next = glyph; 40 } 41 42 MainWindow.get_spacing_class_tab ().update_rows (); 43 } 44 45 public override void selected_row (Row row, int column, bool delete_button) { 46 Font font = BirdFont.get_current_font (); 47 SpacingData spacing = font.get_spacing (); 48 49 if (row.get_index () == -1) { 50 spacing.add_class ("?", "?"); 51 TabContent.hide_text_input (); 52 update_rows (); 53 update_scrollbar (); 54 font.touch (); 55 } else if (spacing.classes.size != 0) { 56 if (delete_button) { 57 return_if_fail (0 <= row.get_index () < spacing.classes.size); 58 spacing.classes.remove_at (row.get_index ()); 59 TabContent.hide_text_input (); 60 update_rows (); 61 update_scrollbar (); 62 font.touch (); 63 } else if (column == 0) { 64 if (!(0 <= row.get_index () < spacing.classes.size)) { 65 warning (@"Index: $(row.get_index ()) classes.size: $(spacing.classes.size)"); 66 return; 67 } 68 current_class = spacing.classes.get (row.get_index ()); 69 current_class.set_first (); 70 current_class_first_element = true; 71 font.touch (); 72 } else if (column == 2) { 73 return_if_fail (0 <= row.get_index () < spacing.classes.size); 74 current_class = spacing.classes.get (row.get_index ()); 75 current_class.set_next (); 76 current_class_first_element = false; 77 font.touch (); 78 } 79 } 80 } 81 82 public override void update_rows () { 83 int i = 0; 84 SpacingData spacing = BirdFont.get_current_font ().get_spacing (); 85 86 rows.clear (); 87 rows.add (new Row (t_("New spacing class"), NEW_CLASS, false)); 88 89 foreach (SpacingClass c in spacing.classes) { 90 rows.add (new Row.columns_3 (@"$(c.first)", "->", @"$(c.next)", i)); 91 i++; 92 } 93 94 GlyphCanvas.redraw (); 95 } 96 97 public override string get_label () { 98 return t_("Spacing Classes"); 99 } 100 101 public override string get_name () { 102 return "SpacingClasses"; 103 } 104 } 105 106 } 107