The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Theme.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
Add *nix as OS tag heads/master
1 /* 2 Copyright (C) 2015 2016 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 B; 16 using Cairo; 17 18 namespace BirdFont { 19 20 public class Theme : GLib.Object { 21 22 static Gee.HashMap<string, Color> colors; 23 public static Gee.ArrayList<string> color_list; 24 public static Gee.ArrayList<string> themes; 25 public static string current_theme; 26 27 public static void text_color (Text text, string name) { 28 Color c; 29 30 if (unlikely (!colors.has_key (name))) { 31 warning (@"Theme does not have a color for $name"); 32 return; 33 } 34 35 c = colors.get (name); 36 text.set_source_rgba (c.r, c.g, c.b, c.a); 37 } 38 39 public static void color (Context cr, string name) { 40 Color c; 41 42 if (unlikely (!colors.has_key (name))) { 43 warning (@"Theme does not have a color for $name"); 44 return; 45 } 46 47 c = colors.get (name); 48 cr.set_source_rgba (c.r, c.g, c.b, c.a); 49 } 50 51 public static void color_opacity (Context cr, string name, double opacity) { 52 Color c; 53 54 if (unlikely (!colors.has_key (name))) { 55 warning (@"Theme does not have a color for $name"); 56 return; 57 } 58 59 c = colors.get (name); 60 cr.set_source_rgba (c.r, c.g, c.b, opacity); 61 } 62 63 public static void gradient (Cairo.Pattern p, string name1, string name2) { 64 Color c1 = get_color (name1); 65 Color c2 = get_color (name2); 66 67 p.add_color_stop_rgba (1, c1.r, c1.g, c1.b, c1.a); 68 p.add_color_stop_rgba (0, c2.r, c2.g, c2.b, c2.a); 69 } 70 71 public static void text_color_opacity (Text text, string name, double opacity) { 72 Color c; 73 74 if (unlikely (!colors.has_key (name))) { 75 warning (@"Theme does not have a color for $name"); 76 return; 77 } 78 79 c = colors.get (name); 80 text.set_source_rgba (c.r, c.g, c.b, opacity); 81 } 82 83 public static Color get_color (string name) { 84 if (unlikely (!colors.has_key (name))) { 85 warning (@"Theme does not have a color for $name"); 86 return new Color (0, 0, 0, 1); 87 } 88 89 return colors.get (name); 90 } 91 92 public static void set_default_colors () { 93 current_theme = "dark.theme"; 94 color_list = new Gee.ArrayList<string> (); 95 colors = new Gee.HashMap<string, Color> (); 96 themes = new Gee.ArrayList<string> (); 97 98 add_theme_files (); 99 100 // Bright theme 101 Theme.set_default_color ("Canvas Background", 1, 1, 1, 1); 102 Theme.set_default_color ("Filled Stroke", 0, 0, 0, 1); 103 Theme.set_default_color ("Stroke Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); 104 Theme.set_default_color ("Handle Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); 105 Theme.set_default_color ("Fill Color", 0.5, 0.5, 0.5, 1); 106 Theme.set_default_color ("Selected Objects", 35 / 255.0, 131 / 255.0, 194 / 255.0, 1); 107 108 Theme.set_default_color ("Background 1", 1, 1, 1, 1); 109 Theme.set_default_color ("Dialog Background", 238 / 255.0, 239 / 255.0, 243 / 255.0, 1); 110 Theme.set_default_color ("Menu Background", 222 / 255.0, 221 / 255.0, 226 / 255.0, 1); 111 Theme.set_default_color ("Default Background", 238 / 255.0, 239 / 255.0, 243 / 255.0, 1); 112 Theme.set_default_color ("Headline Background", 110 / 255.0, 113 / 255.0, 130 / 255.0, 1); 113 114 Theme.set_default_color ("Checkbox Background", 255 / 255.0, 255 / 255.0, 255 / 255.0, 1); 115 Theme.set_default_color ("Foreground 1", 0, 0, 0, 1); 116 117 Theme.set_default_color ("Text Foreground", 3 / 255.0, 16 / 255.0, 24 / 255.0, 1); 118 Theme.set_default_color ("Text Tool Box", 3 / 255.0, 16 / 255.0, 24 / 255.0, 1); 119 Theme.set_default_color ("Text Tab Bar", 3 / 255.0, 16 / 255.0, 24 / 255.0, 1); 120 Theme.set_default_color ("Selected Tab Foreground", 0, 0, 0, 1); 121 Theme.set_default_color ("Menu Foreground", 3 / 255.0, 16 / 255.0, 24 / 255.0, 1); 122 123 Theme.set_default_color ("Table Border", 26 / 255.0, 30 / 255.0, 32 / 255.0, 1); 124 Theme.set_default_color ("Selection Border", 40 / 255.0, 57 / 255.0, 65 / 255.0, 1); 125 Theme.set_default_color ("Overview Glyph", 219 / 255.0, 221 / 255.0, 233 / 255.0, 1); 126 127 Theme.set_default_color ("Table Background 1", 238 / 255.0, 239 / 255.0, 243 / 255.0, 1); 128 Theme.set_default_color ("Table Background 2", 225 / 255.0, 227 / 255.0, 233 / 255.0, 1); 129 130 Theme.set_default_color ("Tab Separator", 207 / 255.0, 210 / 255.0, 215 / 255.0, 1); 131 132 Theme.set_default_color ("Foreground Inverted", 1, 1, 1, 1); 133 134 Theme.set_default_color ("Highlighted 1", 159 / 255.0, 165 / 255.0, 192 / 255.0, 1); 135 136 Theme.set_default_color ("Highlighted Guide", 0, 0, 0.3, 1); 137 Theme.set_default_color ("Guide 1", 0.7, 0.7, 0.8, 1); 138 Theme.set_default_color ("Guide 2", 0.7, 0, 0, 0.5); 139 Theme.set_default_color ("Guide 3", 120 / 255.0, 68 / 255.0, 120 / 255.0, 120 / 255.0); 140 141 Theme.set_default_color ("Grid",0.2, 0.6, 0.2, 0.2); 142 143 Theme.set_default_color ("Background Glyph", 0.2, 0.2, 0.2, 0.5); 144 145 Theme.set_default_color ("Button Border 1", 173 / 255.0, 176 / 255.0, 188 / 255.0, 1); 146 Theme.set_default_color ("Button Background 1", 211 / 255.0, 212 / 255.0, 216 / 255.0, 1); 147 148 Theme.set_default_color ("Button Border 2", 173 / 255.0, 176 / 255.0, 188 / 255.0, 1); 149 Theme.set_default_color ("Button Background 2", 211 / 255.0, 212 / 255.0, 216 / 255.0, 1); 150 151 Theme.set_default_color ("Button Border 3", 173 / 255.0, 176 / 255.0, 188 / 255.0, 1); 152 Theme.set_default_color ("Button Background 3", 242 / 255.0, 246 / 255.0, 246 / 255.0, 1); 153 154 Theme.set_default_color ("Button Border 4", 173 / 255.0, 176 / 255.0, 188 / 255.0, 1); 155 Theme.set_default_color ("Button Background 4", 233 / 255.0, 233 / 255.0, 233 / 255.0, 1); 156 157 Theme.set_default_color ("Button Foreground", 3 / 255.0, 16 / 255.0, 24 / 255.0, 1); 158 Theme.set_default_color ("Selected Button Foreground", 3 / 255.0, 16 / 255.0, 24 / 255.0, 1); 159 160 Theme.set_default_color ("Tool Foreground", 3 / 255.0, 16 / 255.0, 24 / 255.0, 1); 161 Theme.set_default_color ("Selected Tool Foreground", 3 / 255.0, 16 / 255.0, 24 / 255.0, 1); 162 163 Theme.set_default_color ("Text Area Background", 255 / 255.0, 255 / 255.0, 255 / 255.0, 1); 164 165 Theme.set_default_color ("Overview Item Border", 207 / 255.0, 210 / 255.0, 215 / 255.0, 1); 166 167 Theme.set_default_color ("Selected Overview Item", 211 / 255.0, 212 / 255.0, 216 / 255.0, 1); 168 Theme.set_default_color ("Overview Item 1", 236 / 255.0, 236 / 255.0, 236 / 255.0, 1); 169 Theme.set_default_color ("Overview Item 2", 246 / 255.0, 246 / 255.0, 246 / 255.0, 1); 170 171 Theme.set_default_color ("Overview Selected Foreground", 45 / 255.0, 45 / 255.0, 45 / 255.0, 1); 172 Theme.set_default_color ("Overview Foreground", 45 / 255.0, 45 / 255.0, 45 / 255.0, 1); 173 174 Theme.set_default_color ("Glyph Count Background 1", 255 / 255.0, 255 / 255.0, 255 / 255.0, 1); 175 Theme.set_default_color ("Glyph Count Background 2", 255 / 255.0, 255 / 255.0, 255 / 255.0, 1); 176 177 Theme.set_default_color ("Dialog Shadow", 0, 0, 0, 0.3); 178 179 Theme.set_default_color ("Selected Active Cubic Control Point", 0 / 255.0, 112 / 255.0, 244 / 255.0, 1); 180 Theme.set_default_color ("Selected Cubic Control Point", 0 / 255.0, 112 / 255.0, 244 / 255.0, 1); 181 Theme.set_default_color ("Active Cubic Control Point", 70 / 255.0, 70 / 255.0, 70 / 255.0, 1); 182 Theme.set_default_color ("Cubic Control Point", 116 / 255.0, 116 / 255.0, 116 / 255.0, 1); 183 184 Theme.set_default_color ("Selected Active Quadratic Control Point", 0 / 255.0, 112 / 255.0, 244 / 255.0, 1); 185 Theme.set_default_color ("Selected Quadratic Control Point", 0 / 255.0, 112 / 255.0, 244 / 255.0, 1); 186 Theme.set_default_color ("Active Quadratic Control Point", 85 / 255.0, 115 / 255.0, 149 / 255.0, 1); 187 Theme.set_default_color ("Quadratic Control Point", 123 / 255.0, 151 / 255.0, 184 / 255.0, 1); 188 189 Theme.set_default_color ("Selected Control Point Handle", 0 / 255.0, 112 / 255.0, 244 / 255.0, 1); 190 Theme.set_default_color ("Active Handle", 21 / 255.0, 44 / 255.0, 25 / 255.0, 1); 191 192 Theme.set_default_color ("Control Point Handle", 81 / 255.0, 147 / 255.0, 90 / 255.0, 1); 193 194 Theme.set_default_color ("Merge", 167 / 255.0, 170 / 255.0, 178 / 255.0, 0.3); 195 196 Theme.set_default_color ("Spin Button", 164 / 255.0, 167 / 255.0, 175 / 255.0, 1); 197 Theme.set_default_color ("Active Spin Button", 104 / 255.0, 108 / 255.0, 119 / 255.0, 1); 198 Theme.set_default_color ("Zoom Bar Border", 122 / 255.0, 131 / 255.0, 145 / 255.0, 1); 199 Theme.set_default_color ("Font Name", 0 / 255.0, 0 / 255.0, 0 / 255.0, 1); 200 201 if (BirdFont.has_argument ("--test")) { 202 current_theme = "generated_theme.theme"; 203 write_theme (); 204 } 205 206 // Dark theme 207 Theme.set_default_color ("Canvas Background", 1, 1, 1, 1); 208 Theme.set_default_color ("Filled Stroke", 0, 0, 0, 1); 209 Theme.set_default_color ("Stroke Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); 210 Theme.set_default_color ("Handle Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); 211 Theme.set_default_color ("Fill Color", 0.5, 0.5, 0.5, 1); 212 Theme.set_default_color ("Selected Objects", 35 / 255.0, 131 / 255.0, 194 / 255.0, 1); 213 214 Theme.set_default_color ("Background 1", 1, 1, 1, 1); 215 Theme.set_default_color ("Dialog Background", 55 / 255.0, 56 / 255.0, 62 / 255.0, 1); 216 Theme.set_default_color ("Menu Background", 43 / 255.0, 42 / 255.0, 47 / 255.0, 1); 217 Theme.set_default_color ("Default Background", 55 / 255.0, 56 / 255.0, 62 / 255.0, 1); 218 Theme.set_default_color ("Headline Background", 101 / 255.0, 108 / 255.0, 116 / 255.0, 1); 219 220 Theme.set_default_color ("Checkbox Background", 101 / 255.0, 108 / 255.0, 116 / 255.0, 1); 221 222 Theme.set_default_color ("Foreground 1", 0, 0, 0, 1); 223 224 Theme.set_default_color ("Text Foreground", 0 / 255.0, 0 / 255.0, 0 / 255.0, 1); 225 Theme.set_default_color ("Text Tool Box", 128 / 255.0, 130 / 255.0, 136 / 255.0, 1); 226 Theme.set_default_color ("Text Tab Bar", 128 / 255.0, 130 / 255.0, 136 / 255.0, 1); 227 Theme.set_default_color ("Selected Tab Foreground", 38 / 255.0, 36 / 255.0, 39 / 255.0, 1); 228 Theme.set_default_color ("Menu Foreground", 128 / 255.0, 130 / 255.0, 136 / 255.0, 1); 229 230 Theme.set_default_color ("Table Border", 26 / 255.0, 30 / 255.0, 32 / 255.0, 1); 231 Theme.set_default_color ("Selection Border", 40 / 255.0, 57 / 255.0, 65 / 255.0, 1); 232 Theme.set_default_color ("Overview Glyph", 219 / 255.0, 221 / 255.0, 233 / 255.0, 1); 233 234 Theme.set_default_color ("Table Background 1", 238 / 255.0, 239 / 255.0, 243 / 255.0, 1); 235 Theme.set_default_color ("Table Background 2", 225 / 255.0, 227 / 255.0, 233 / 255.0, 1); 236 237 Theme.set_default_color ("Tab Separator", 123 / 255.0, 127 / 255.0, 132 / 255.0, 1); 238 239 Theme.set_default_color ("Foreground Inverted", 1, 1, 1, 1); 240 241 Theme.set_default_color ("Highlighted 1", 234 / 255.0, 77 / 255.0, 26 / 255.0, 1); 242 243 Theme.set_default_color ("Highlighted Guide", 0, 0, 0.3, 1); 244 Theme.set_default_color ("Guide 1", 0.7, 0.7, 0.8, 1); 245 Theme.set_default_color ("Guide 2", 0.7, 0, 0, 0.5); 246 Theme.set_default_color ("Guide 3", 120 / 255.0, 68 / 255.0, 120 / 255.0, 120 / 255.0); 247 248 Theme.set_default_color ("Grid",0.2, 0.6, 0.2, 0.2); 249 250 Theme.set_default_color ("Background Glyph", 0.2, 0.2, 0.2, 0.5); 251 252 Theme.set_default_color ("Button Border 1", 39 / 255.0, 40 / 255.0, 44 / 255.0, 1); 253 Theme.set_default_color ("Button Background 1", 25 / 255.0, 28 / 255.0, 30 / 255.0, 1); 254 255 Theme.set_default_color ("Button Border 2", 39 / 255.0, 40 / 255.0, 44 / 255.0, 1); 256 Theme.set_default_color ("Button Background 2", 25 / 255.0, 28 / 255.0, 30 / 255.0, 1); 257 258 Theme.set_default_color ("Button Border 3", 39 / 255.0, 40 / 255.0, 44 / 255.0, 1); 259 Theme.set_default_color ("Button Background 3", 44 / 255.0, 47 / 255.0, 51 / 255.0, 1); 260 261 Theme.set_default_color ("Button Border 4", 39 / 255.0, 40 / 255.0, 44 / 255.0, 1); 262 Theme.set_default_color ("Button Background 4", 38 / 255.0, 41 / 255.0, 44 / 255.0, 1); 263 264 Theme.set_default_color ("Button Foreground", 255 / 255.0, 255 / 255.0, 255 / 255.0, 1); 265 Theme.set_default_color ("Selected Button Foreground", 107 / 255.0, 112 / 255.0, 122 / 255.0, 1); 266 267 Theme.set_default_color ("Tool Foreground", 123 / 255.0, 127 / 255.0, 132 / 255.0, 1); 268 Theme.set_default_color ("Selected Tool Foreground", 123 / 255.0, 127 / 255.0, 132 / 255.0, 1); 269 270 Theme.set_default_color ("Text Area Background", 101 / 255.0, 108 / 255.0, 116 / 255.0, 1); 271 272 Theme.set_default_color ("Overview Item Border", 207 / 255.0, 210 / 255.0, 215 / 255.0, 1); 273 274 Theme.set_default_color ("Selected Overview Item", 211 / 255.0, 212 / 255.0, 216 / 255.0, 1); 275 Theme.set_default_color ("Overview Item 1", 236 / 255.0, 236 / 255.0, 236 / 255.0, 1); 276 Theme.set_default_color ("Overview Item 2", 246 / 255.0, 246 / 255.0, 246 / 255.0, 1); 277 278 Theme.set_default_color ("Overview Selected Foreground", 45 / 255.0, 45 / 255.0, 45 / 255.0, 1); 279 Theme.set_default_color ("Overview Foreground", 45 / 255.0, 45 / 255.0, 45 / 255.0, 1); 280 281 Theme.set_default_color ("Glyph Count Background 1", 92 / 255.0, 106 / 255.0, 117 / 255.0, 1); 282 Theme.set_default_color ("Glyph Count Background 2", 92 / 255.0, 106 / 255.0, 117 / 255.0, 1); 283 284 Theme.set_default_color ("Dialog Shadow", 0, 0, 0, 0.3); 285 286 Theme.set_default_color ("Selected Active Cubic Control Point", 234 / 255.0, 77 / 255.0, 26 / 255.0, 1); 287 Theme.set_default_color ("Selected Cubic Control Point", 234 / 255.0, 77 / 255.0, 26 / 255.0, 1); 288 Theme.set_default_color ("Active Cubic Control Point", 70 / 255.0, 70 / 255.0, 70 / 255.0, 1); 289 Theme.set_default_color ("Cubic Control Point", 116 / 255.0, 116 / 255.0, 116 / 255.0, 1); 290 291 Theme.set_default_color ("Selected Active Quadratic Control Point", 234 / 255.0, 77 / 255.0, 26 / 255.0, 1); 292 Theme.set_default_color ("Selected Quadratic Control Point", 234 / 255.0, 77 / 255.0, 26 / 255.0, 1); 293 Theme.set_default_color ("Active Quadratic Control Point", 85 / 255.0, 115 / 255.0, 149 / 255.0, 1); 294 Theme.set_default_color ("Quadratic Control Point", 123 / 255.0, 151 / 255.0, 184 / 255.0, 1); 295 296 Theme.set_default_color ("Selected Control Point Handle", 234 / 255.0, 77 / 255.0, 26 / 255.0, 1); 297 Theme.set_default_color ("Active Handle", 21 / 255.0, 44 / 255.0, 25 / 255.0, 1); 298 299 Theme.set_default_color ("Merge", 167 / 255.0, 170 / 255.0, 178 / 255.0, 0.3); 300 301 Theme.set_default_color ("Spin Button", 107 / 255.0, 112 / 255.0, 122 / 255.0, 1); 302 Theme.set_default_color ("Active Spin Button", 107 / 255.0, 112 / 255.0, 122 / 255.0, 1); 303 Theme.set_default_color ("Zoom Bar Border", 38 / 255.0, 39 / 255.0, 43 / 255.0, 1); 304 Theme.set_default_color ("Font Name", 234 / 255.0, 77 / 255.0, 26 / 255.0, 1); 305 306 if (BirdFont.has_argument ("--test")) { 307 current_theme = "generated_dark_theme.theme"; 308 write_theme (); 309 } 310 311 // High contrast theme 312 Theme.set_default_color ("Canvas Background", 1, 1, 1, 1); 313 Theme.set_default_color ("Filled Stroke", 0, 0, 0, 1); 314 Theme.set_default_color ("Stroke Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); 315 Theme.set_default_color ("Handle Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); 316 Theme.set_default_color ("Fill Color", 0, 0, 0, 1); 317 Theme.set_default_color ("Selected Objects", 0, 0, 0, 1); 318 319 Theme.set_default_color ("Background 1", 1, 1, 1, 1); 320 Theme.set_default_color ("Dialog Background", 1, 1, 1, 1); 321 Theme.set_default_color ("Menu Background", 1, 1, 1, 1); 322 Theme.set_default_color ("Default Background", 1, 1, 1, 1); 323 Theme.set_default_color ("Headline Background", 0, 0, 0, 1); 324 325 Theme.set_default_color ("Checkbox Background", 1, 1, 1, 1); 326 Theme.set_default_color ("Foreground 1", 0, 0, 0, 1); 327 328 Theme.set_default_color ("Text Foreground", 0, 0, 0, 1); 329 Theme.set_default_color ("Text Tool Box", 0, 0, 0, 1); 330 Theme.set_default_color ("Text Tab Bar", 0, 0, 0, 1); 331 Theme.set_default_color ("Selected Tab Foreground", 1, 1, 1, 1); 332 Theme.set_default_color ("Menu Foreground", 0, 0, 0, 1); 333 334 Theme.set_default_color ("Table Border", 0, 0, 0, 1); 335 Theme.set_default_color ("Selection Border", 0, 0, 0, 1); 336 Theme.set_default_color ("Overview Glyph", 0, 0, 0, 1); 337 338 Theme.set_default_color ("Table Background 1", 1, 1, 1, 1); 339 Theme.set_default_color ("Table Background 2", 1, 1, 1, 1); 340 341 Theme.set_default_color ("Tab Separator", 0, 0, 0, 1); 342 343 Theme.set_default_color ("Foreground Inverted", 1, 1, 1, 1); 344 345 Theme.set_default_color ("Highlighted 1", 0, 0, 0, 1); 346 347 Theme.set_default_color ("Highlighted Guide", 0, 0, 0, 1); 348 Theme.set_default_color ("Guide 1", 0, 0, 0, 1); 349 Theme.set_default_color ("Guide 2", 0, 0, 0, 1); 350 Theme.set_default_color ("Guide 3", 0, 0, 0, 1); 351 352 Theme.set_default_color ("Grid", 0, 0, 0, 1); 353 354 Theme.set_default_color ("Background Glyph", 0.2, 0.2, 0.2, 0.5); 355 356 Theme.set_default_color ("Button Border 1", 0, 0, 0, 1); 357 Theme.set_default_color ("Button Background 1", 0, 0, 0, 1); 358 359 Theme.set_default_color ("Button Border 2", 0, 0, 0, 1); 360 Theme.set_default_color ("Button Background 2", 0, 0, 0, 1); 361 362 Theme.set_default_color ("Button Border 3", 0, 0, 0, 1); 363 Theme.set_default_color ("Button Background 3", 1, 1, 1, 1); 364 365 Theme.set_default_color ("Button Border 4", 0, 0, 0, 1); 366 Theme.set_default_color ("Button Background 4", 1, 1, 1, 1); 367 368 Theme.set_default_color ("Button Foreground", 0, 0, 0, 1); 369 Theme.set_default_color ("Selected Button Foreground", 1, 1, 1, 1); 370 371 Theme.set_default_color ("Tool Foreground", 0, 0, 0, 1); 372 Theme.set_default_color ("Selected Tool Foreground", 1, 1, 1, 1); 373 374 Theme.set_default_color ("Text Area Background", 1, 1, 1, 1); 375 376 Theme.set_default_color ("Overview Item Border", 0, 0, 0, 1); 377 378 Theme.set_default_color ("Selected Overview Item", 0, 0, 0, 1); 379 Theme.set_default_color ("Overview Item 1", 1, 1, 1, 1); 380 Theme.set_default_color ("Overview Item 2", 1, 1, 1, 1); 381 382 Theme.set_default_color ("Overview Selected Foreground", 1, 1, 1, 1); 383 Theme.set_default_color ("Overview Foreground", 0, 0, 0, 1); 384 385 Theme.set_default_color ("Glyph Count Background 1", 1, 1, 1, 1); 386 Theme.set_default_color ("Glyph Count Background 2", 1, 1, 1, 1); 387 388 Theme.set_default_color ("Dialog Shadow", 0, 0, 0, 1); 389 390 Theme.set_default_color ("Selected Active Cubic Control Point", 0, 0, 0, 1); 391 Theme.set_default_color ("Selected Cubic Control Point", 0, 0, 0, 1); 392 Theme.set_default_color ("Active Cubic Control Point", 0, 0, 0, 1); 393 Theme.set_default_color ("Cubic Control Point", 0, 0, 0, 1); 394 395 Theme.set_default_color ("Selected Active Quadratic Control Point", 0, 0, 0, 1); 396 Theme.set_default_color ("Selected Quadratic Control Point", 0, 0, 0, 1); 397 Theme.set_default_color ("Active Quadratic Control Point", 0, 0, 0, 1); 398 Theme.set_default_color ("Quadratic Control Point", 0, 0, 0, 1); 399 400 Theme.set_default_color ("Selected Control Point Handle", 0, 0, 0, 1); 401 Theme.set_default_color ("Active Handle", 0, 0, 0, 1); 402 Theme.set_default_color ("Control Point Handle", 0, 0, 0, 1); 403 404 Theme.set_default_color ("Merge", 0, 0, 0, 1); 405 406 Theme.set_default_color ("Spin Button", 0, 0, 0, 1); 407 Theme.set_default_color ("Active Spin Button", 0, 0, 0, 1); 408 Theme.set_default_color ("Zoom Bar Border", 0, 0, 0, 1); 409 Theme.set_default_color ("Font Name", 0, 0, 0, 1); 410 411 if (BirdFont.has_argument ("--test")) { 412 current_theme = "generated_high_contrast.theme"; 413 write_theme (); 414 } 415 416 load_theme ("dark.theme"); 417 418 if (BirdFont.has_argument ("--test")) { 419 t_("Canvas Background"); 420 t_("Filled Stroke"); 421 t_("Stroke Color"); 422 t_("Handle Color"); 423 t_("Fill Color"); 424 t_("Selected Objects"); 425 426 t_("Background 1"); 427 t_("Dialog Background"); 428 t_("Menu Background"); 429 t_("Default Background"); 430 431 t_("Checkbox Background"); 432 433 t_("Foreground 1"); 434 t_("Text Foreground"); 435 t_("Table Border"); 436 t_("Selection Border"); 437 t_("Overview Glyph"); 438 t_("Foreground Inverted"); 439 t_("Menu Foreground"); 440 t_("Selected Tab Foreground"); 441 t_("Tab Separator"); 442 443 t_("Highlighted 1"); 444 t_("Highlighted Guide"); 445 446 t_("Grid"); 447 448 t_("Guide 1"); 449 t_("Guide 2"); 450 t_("Guide 3"); 451 452 t_("Button Border 1"); 453 t_("Button Background 1"); 454 t_("Button Border 2"); 455 t_("Button Background 2"); 456 t_("Button Border 3"); 457 t_("Button Background 3"); 458 t_("Button Border 4"); 459 t_("Button Background 4"); 460 461 t_("Button Foreground"); 462 t_("Selected Button Foreground"); 463 464 t_("Tool Foreground"); 465 t_("Selected Tool Foreground"); 466 467 t_("Text Area Background"); 468 469 t_("Overview Item Border"); 470 471 t_("Selected Overview Item"); 472 t_("Overview Item 1"); 473 t_("Overview Item 2"); 474 475 t_("Overview Selected Foreground"); 476 t_("Overview Foreground"); 477 478 t_("Glyph Count Background 1"); 479 t_("Glyph Count Background 2"); 480 481 t_("Dialog Shadow"); 482 483 t_("Selected Active Cubic Control Point"); 484 t_("Selected Cubic Control Point"); 485 t_("Active Cubic Control Point"); 486 t_("Cubic Control Point"); 487 488 t_("Selected Active Quadratic Control Point"); 489 t_("Selected Quadratic Control Point"); 490 t_("Active Quadratic Control Point"); 491 t_("Cubic Quadratic Point"); 492 493 t_("Selected Control Point Handle"); 494 t_("Active Handle"); 495 t_("Control Point Handle"); 496 497 t_("Merge"); 498 t_("Spin Button"); 499 t_("Active Spin Button"); 500 t_("Zoom Bar Border"); 501 t_("Font Name"); 502 } 503 } 504 505 static void add_theme_files () { 506 FileEnumerator enumerator; 507 FileInfo? file_info; 508 string file_name; 509 File dir; 510 511 dir = BirdFont.get_settings_directory (); 512 513 themes.clear (); 514 themes.add ("dark.theme"); 515 themes.add ("bright.theme"); 516 themes.add ("high_contrast.theme"); 517 518 try { 519 enumerator = dir.enumerate_children (FileAttribute.STANDARD_NAME, 0); 520 while ((file_info = enumerator.next_file ()) != null) { 521 file_name = ((!) file_info).get_name (); 522 523 if (file_name.has_suffix (".theme")) { 524 themes.add (file_name); 525 } 526 } 527 } catch (Error e) { 528 warning (e.message); 529 } 530 } 531 532 public static void set_default_color (string name, double r, double g, double b, double a) { 533 color_list.add (name); 534 colors.set (name, new Color (r, g, b, a)); 535 } 536 537 public static void save_color (string name, double r, double g, double b, double a) { 538 colors.set (name, new Color (r, g, b, a)); 539 write_theme (); 540 } 541 542 public static void load_theme (string theme_file) { 543 File default_theme; 544 File user_theme; 545 546 user_theme = get_child (BirdFont.get_settings_directory (), theme_file); 547 if (user_theme.query_exists ()) { 548 current_theme = theme_file; 549 parse_theme (user_theme); 550 return; 551 } 552 553 default_theme = SearchPaths.find_file (null, theme_file); 554 if (default_theme.query_exists ()) { 555 current_theme = theme_file; 556 parse_theme (default_theme); 557 return; 558 } 559 560 warning (@"Theme not found: $theme_file"); 561 } 562 563 public static void write_theme () { 564 DataOutputStream os; 565 File file; 566 int i; 567 string base_name; 568 569 if (current_theme == "") { 570 warning ("No name for theme."); 571 return; 572 } 573 574 if (current_theme == "dark.theme" 575 || current_theme == "bright.theme" 576 || current_theme == "high_contrast.theme") { 577 578 current_theme = "custom.theme"; 579 580 file = get_child (BirdFont.get_settings_directory (), current_theme); 581 i = 2; 582 base_name = "custom"; 583 while (file.query_exists ()) { 584 current_theme = @"$(base_name)_$(i).theme"; 585 file = get_child (BirdFont.get_settings_directory (), current_theme); 586 i++; 587 } 588 } 589 590 file = get_child (BirdFont.get_settings_directory (), current_theme); 591 592 try { 593 if (file.query_exists ()) { 594 file.delete (); 595 } 596 } catch (GLib.Error e) { 597 warning (e.message); 598 } 599 600 try { 601 os = new DataOutputStream (file.create (FileCreateFlags.REPLACE_DESTINATION)); 602 os.put_string ("""<?xml version="1.0" encoding="utf-8" standalone="yes"?>"""); 603 os.put_string ("\n"); 604 605 os.put_string ("<theme>\n"); 606 foreach (string name in colors.keys) { 607 Color color = colors.get (name); 608 609 os.put_string ("\t<color "); 610 611 os.put_string (@"name=\"$(Markup.escape_text (name))\" "); 612 os.put_string (@"red=\"$(color.r)\" "); 613 os.put_string (@"green=\"$(color.g)\" "); 614 os.put_string (@"blue=\"$(color.b)\" "); 615 os.put_string (@"alpha=\"$(color.a)\""); 616 617 os.put_string ("/>\n"); 618 } 619 os.put_string ("</theme>\n"); 620 621 os.close (); 622 } catch (GLib.Error e) { 623 warning (e.message); 624 } 625 626 add_theme_files (); 627 } 628 629 static void parse_theme (File f) { 630 string xml_data; 631 XmlParser parser; 632 633 try { 634 FileUtils.get_contents ((!) f.get_path (), out xml_data); 635 parser = new XmlParser (xml_data); 636 parse_colors (parser.get_root_tag ()); 637 } catch (GLib.Error e) { 638 warning (e.message); 639 } 640 } 641 642 static void parse_colors (Tag tag) { 643 foreach (Tag t in tag) { 644 if (t.get_name () == "color") { 645 parse_color (t.get_attributes ()); 646 } 647 } 648 } 649 650 static void parse_color (Attributes attributes) { 651 string name = ""; 652 double r = 0; 653 double g = 0; 654 double b = 0; 655 double a = 1; 656 657 foreach (Attribute attr in attributes) { 658 if (attr.get_name () == "name") { 659 name = attr.get_content (); 660 } 661 662 if (attr.get_name () == "red") { 663 r = double.parse (attr.get_content ()); 664 } 665 666 if (attr.get_name () == "green") { 667 g = double.parse (attr.get_content ()); 668 } 669 670 if (attr.get_name () == "blue") { 671 b = double.parse (attr.get_content ()); 672 } 673 674 if (attr.get_name () == "alpha") { 675 a = double.parse (attr.get_content ()); 676 } 677 } 678 679 colors.set (name, new Color (r, g, b, a)); 680 } 681 682 internal static void add_new_theme (SettingsDisplay d) { 683 TextListener listener; 684 685 listener = new TextListener (t_("New theme"), "", t_("Set")); 686 687 listener.signal_text_input.connect ((text) => { 688 if (text != "") { 689 current_theme = text + ".theme"; 690 themes.add (current_theme); 691 } 692 }); 693 694 listener.signal_submit.connect (() => { 695 TabContent.hide_text_input (); 696 write_theme (); 697 d.create_setting_items (); 698 }); 699 700 TabContent.show_text_input (listener); 701 } 702 703 public static string get_icon_file () { 704 return "icons.birdfont".dup (); 705 } 706 } 707 708 } 709