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