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
Circle boundaries heads/master
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 if (current_class_first_element) { 36 current_class.first = glyph; 37 } else { 38 current_class.next = glyph; 39 } 40 41 MainWindow.get_spacing_class_tab ().update_rows (); 42 } 43 44 public override void selected_row (Row row, int column, bool delete_button) { 45 Font font = BirdFont.get_current_font (); 46 SpacingData spacing = font.get_spacing (); 47 48 if (row.get_index () == -1) { 49 spacing.add_class ("?", "?"); 50 TabContent.hide_text_input (); 51 update_rows (); 52 update_scrollbar (); 53 font.touch (); 54 } else if (spacing.classes.size != 0) { 55 if (delete_button) { 56 return_if_fail (0 <= row.get_index () < spacing.classes.size); 57 spacing.classes.remove_at (row.get_index ()); 58 TabContent.hide_text_input (); 59 update_rows (); 60 update_scrollbar (); 61 font.touch (); 62 } else if (column == 0) { 63 if (!(0 <= row.get_index () < spacing.classes.size)) { 64 warning (@"Index: $(row.get_index ()) classes.size: $(spacing.classes.size)"); 65 return; 66 } 67 current_class = spacing.classes.get (row.get_index ()); 68 current_class.set_first (); 69 current_class_first_element = true; 70 font.touch (); 71 } else if (column == 2) { 72 return_if_fail (0 <= row.get_index () < spacing.classes.size); 73 current_class = spacing.classes.get (row.get_index ()); 74 current_class.set_next (); 75 current_class_first_element = false; 76 font.touch (); 77 } 78 } 79 } 80 81 public override void update_rows () { 82 int i = 0; 83 SpacingData spacing = BirdFont.get_current_font ().get_spacing (); 84 85 rows.clear (); 86 rows.add (new Row (t_("New spacing class"), NEW_CLASS, false)); 87 88 foreach (SpacingClass c in spacing.classes) { 89 rows.add (new Row.columns_3 (@"$(c.first)", "->", @"$(c.next)", i)); 90 i++; 91 } 92 93 GlyphCanvas.redraw (); 94 } 95 96 public override string get_label () { 97 return t_("Spacing Classes"); 98 } 99 100 public override string get_name () { 101 return "SpacingClasses"; 102 } 103 } 104 105 } 106