The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

OverviewTools.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/OverviewTools.vala.
Merge branch '2.10'
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 15 using Cairo; 16 17 namespace BirdFont { 18 19 public class OverviewTools : ToolCollection { 20 21 static LabelTool all_glyphs; 22 static LabelTool default_glyphs; 23 static LabelTool unicode; 24 25 static Gee.ArrayList<LabelTool> custom_character_sets; 26 27 public static Gee.ArrayList<Expander> expanders; 28 public ZoomBar zoom_bar; 29 30 public static Expander zoom_expander; 31 32 public OverviewTools () { 33 Expander font_name = new Expander (); 34 Expander character_sets = new Expander (t_("Character Sets")); 35 Expander zoom_expander = new Expander (t_("Zoom")); 36 37 expanders = new Gee.ArrayList<Expander> (); 38 custom_character_sets = new Gee.ArrayList<LabelTool> (); 39 40 font_name.add_tool (new FontName ()); 41 42 zoom_bar = new ZoomBar (); 43 zoom_bar.new_zoom.connect ((z) => { 44 get_overview ().set_zoom (z); 45 }); 46 zoom_expander.add_tool (zoom_bar); 47 48 all_glyphs = new LabelTool (t_("All Glyphs")); 49 all_glyphs.has_counter = true; 50 all_glyphs.select_action.connect ((self) => { 51 OverView overview = get_overview (); 52 overview.display_all_available_glyphs (); 53 update_overview_characterset (); 54 FontDisplay.dirty_scrollbar = true; 55 }); 56 character_sets.add_tool (all_glyphs); 57 58 default_glyphs = new LabelTool (t_("Default")); 59 default_glyphs.has_counter = true; 60 default_glyphs.select_action.connect ((self) => { 61 OverView overview = get_overview (); 62 GlyphRange gr = new GlyphRange (); 63 DefaultCharacterSet.use_default_range (gr); 64 overview.set_current_glyph_range (gr); 65 update_overview_characterset (); 66 FontDisplay.dirty_scrollbar = true; 67 }); 68 character_sets.add_tool (default_glyphs); 69 70 unicode = new LabelTool (t_("Unicode")); 71 unicode.has_counter = true; 72 unicode.select_action.connect ((self) => { 73 OverView overview = get_overview (); 74 GlyphRange gr = new GlyphRange (); 75 DefaultCharacterSet.use_full_unicode_range (gr); 76 overview.set_current_glyph_range (gr); 77 update_overview_characterset (); 78 FontDisplay.dirty_scrollbar = true; 79 }); 80 character_sets.add_tool (unicode); 81 82 character_sets.set_persistent (true); 83 character_sets.set_unique (false); 84 85 expanders.add (font_name); 86 expanders.add (zoom_expander); 87 expanders.add (character_sets); 88 } 89 90 public OverView get_overview () { 91 FontDisplay fd = MainWindow.get_current_display (); 92 93 if (fd is OverView || fd is GlyphSelection) { 94 return (OverView) fd; 95 } 96 97 warning ("Current tab is not overview."); 98 99 return new OverView (); 100 } 101 102 public static void show_all_available_characters () { 103 all_glyphs.select_action (all_glyphs); 104 } 105 106 public static void update_overview_characterset (OverView? tab = null) { 107 GlyphRange gr; 108 uint size; 109 OverView overview; 110 111 // All characters 112 size = BirdFont.get_current_font ().length (); 113 all_glyphs.number = get_display_value (size); 114 115 // Default 116 gr = new GlyphRange (); 117 DefaultCharacterSet.use_default_range (gr); 118 size = gr.get_length (); 119 default_glyphs.number = get_display_value (size); 120 121 // Unicode 122 gr = new GlyphRange (); 123 DefaultCharacterSet.use_full_unicode_range (gr); 124 size = gr.get_length (); 125 unicode.number = get_display_value (size); 126 127 overview = (tab == null) ? MainWindow.get_overview () : (!) tab; 128 129 // set selected item 130 all_glyphs.set_selected (false); 131 default_glyphs.set_selected (false); 132 unicode.set_selected (false); 133 134 if (overview.all_available) { 135 all_glyphs.set_selected (true); 136 } else if (overview.glyph_range.name == "Default") { 137 default_glyphs.set_selected (true); 138 } else if (overview.glyph_range.name == "Unicode") { 139 unicode.set_selected (true); 140 } 141 142 Toolbox.redraw_tool_box (); 143 } 144 145 static string get_display_value (uint size) { 146 double k; 147 string display_size; 148 149 if (size >= 1000) { 150 k = size / 1000.0; 151 size = (uint) Math.rint (k); 152 display_size = @"$(size)k"; 153 } else { 154 display_size = @"$(size)"; 155 } 156 157 return display_size; 158 } 159 160 public override Gee.ArrayList<Expander> get_expanders () { 161 return expanders; 162 } 163 164 public override Gee.ArrayList<string> get_displays () { 165 Gee.ArrayList<string> d = new Gee.ArrayList<string> (); 166 d.add ("Overview"); 167 return d; 168 } 169 } 170 171 } 172