The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

ThemeTab.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/ThemeTab.vala.
Fix self intersecting stroke
1 /* 2 Copyright (C) 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 ThemeTab : SettingsDisplay { 21 22 public ThemeTab () { 23 base (); 24 create_setting_items (); 25 } 26 27 public override void create_setting_items () { 28 tools.clear (); 29 tools.add (new SettingsItem.head_line (t_("Themes"))); 30 31 Gee.ArrayList<Tool> theme_buttons = new Gee.ArrayList<Tool> (); 32 33 foreach (string theme in Theme.themes) { 34 string label; 35 Tool select_theme = new Tool (theme); 36 37 select_theme.deselect_action.connect((self) => { 38 self.set_active (false); 39 }); 40 41 select_theme.select_action.connect((self) => { 42 string theme_file = self.get_name (); 43 TabBar tb; 44 45 Preferences.set ("theme", theme_file); 46 Theme.load_theme (theme_file); 47 48 foreach (Tool t in theme_buttons) { 49 t.set_selected (false); 50 t.set_active (false); 51 } 52 53 self.set_selected (true); 54 create_setting_items (); 55 56 Toolbox.redraw_tool_box (); 57 GlyphCanvas.redraw (); 58 59 tb = MainWindow.get_tab_bar (); 60 tb.redraw (0, 0, tb.width, tb.height); 61 }); 62 63 select_theme.set_icon ("theme"); 64 65 label = get_label_from_file_name (theme); 66 67 tools.add (new SettingsItem (select_theme, label)); 68 theme_buttons.add (select_theme); 69 70 if (select_theme.get_name () == Theme.current_theme) { 71 select_theme.set_selected (true); 72 } 73 } 74 75 foreach (Tool t in theme_buttons) { 76 t.set_selected (t.name == Theme.current_theme); 77 } 78 79 Tool add_theme = new Tool ("add_new_theme"); 80 add_theme.select_action.connect((self) => { 81 foreach (Tool t in theme_buttons) { 82 t.set_selected (false); 83 } 84 85 self.set_selected (false); 86 Theme.add_new_theme (this); 87 GlyphCanvas.redraw (); 88 }); 89 tools.add (new SettingsItem (add_theme, t_("Add new theme"))); 90 91 tools.add (new SettingsItem.head_line (t_("Colors"))); 92 93 foreach (string color in Theme.color_list) { 94 SettingsItem s = new SettingsItem.color (color); 95 ColorTool c = (ColorTool) ((!) s.button); 96 97 tools.add (s); 98 99 c.color_updated.connect (() => { 100 create_setting_items (); 101 GlyphCanvas.redraw (); 102 }); 103 } 104 } 105 106 public static string get_label_from_file_name (string theme) { 107 string label; 108 109 if (theme == "dark.theme") { 110 label = t_("Dark"); 111 } else if (theme == "bright.theme") { 112 label = t_("Bright"); 113 } else if (theme == "high_contrast.theme") { 114 label = t_("High contrast"); 115 } else if (theme == "custom.theme") { 116 label = t_("Custom"); 117 } else { 118 label = theme.replace (".theme", ""); 119 } 120 121 return label; 122 } 123 124 public override string get_label () { 125 return t_("Themes"); 126 } 127 128 public override string get_name () { 129 return "Themes"; 130 } 131 } 132 133 } 134