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

Revisions

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