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
Circle boundaries 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 ("Objects", 0, 0, 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 ("Objects", 0, 0, 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 ("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 t_("Objects"); 426 427 t_("Background 1"); 428 t_("Dialog Background"); 429 t_("Menu Background"); 430 t_("Default Background"); 431 432 t_("Checkbox Background"); 433 434 t_("Foreground 1"); 435 t_("Text Foreground"); 436 t_("Table Border"); 437 t_("Selection Border"); 438 t_("Overview Glyph"); 439 t_("Foreground Inverted"); 440 t_("Menu Foreground"); 441 t_("Selected Tab Foreground"); 442 t_("Tab Separator"); 443 444 t_("Highlighted 1"); 445 t_("Highlighted Guide"); 446 447 t_("Grid"); 448 449 t_("Guide 1"); 450 t_("Guide 2"); 451 t_("Guide 3"); 452 453 t_("Button Border 1"); 454 t_("Button Background 1"); 455 t_("Button Border 2"); 456 t_("Button Background 2"); 457 t_("Button Border 3"); 458 t_("Button Background 3"); 459 t_("Button Border 4"); 460 t_("Button Background 4"); 461 462 t_("Button Foreground"); 463 t_("Selected Button Foreground"); 464 465 t_("Tool Foreground"); 466 t_("Selected Tool Foreground"); 467 468 t_("Text Area Background"); 469 470 t_("Overview Item Border"); 471 472 t_("Selected Overview Item"); 473 t_("Overview Item 1"); 474 t_("Overview Item 2"); 475 476 t_("Overview Selected Foreground"); 477 t_("Overview Foreground"); 478 479 t_("Glyph Count Background 1"); 480 t_("Glyph Count Background 2"); 481 482 t_("Dialog Shadow"); 483 484 t_("Selected Active Cubic Control Point"); 485 t_("Selected Cubic Control Point"); 486 t_("Active Cubic Control Point"); 487 t_("Cubic Control Point"); 488 489 t_("Selected Active Quadratic Control Point"); 490 t_("Selected Quadratic Control Point"); 491 t_("Active Quadratic Control Point"); 492 t_("Cubic Quadratic Point"); 493 494 t_("Selected Control Point Handle"); 495 t_("Active Handle"); 496 t_("Control Point Handle"); 497 498 t_("Merge"); 499 t_("Spin Button"); 500 t_("Active Spin Button"); 501 t_("Zoom Bar Border"); 502 t_("Font Name"); 503 } 504 } 505 506 static void add_theme_files () { 507 FileEnumerator enumerator; 508 FileInfo? file_info; 509 string file_name; 510 File dir; 511 512 dir = BirdFont.get_settings_directory (); 513 514 themes.clear (); 515 themes.add ("dark.theme"); 516 themes.add ("bright.theme"); 517 themes.add ("high_contrast.theme"); 518 519 try { 520 enumerator = dir.enumerate_children (FileAttribute.STANDARD_NAME, 0); 521 while ((file_info = enumerator.next_file ()) != null) { 522 file_name = ((!) file_info).get_name (); 523 524 if (file_name.has_suffix (".theme")) { 525 themes.add (file_name); 526 } 527 } 528 } catch (Error e) { 529 warning (e.message); 530 } 531 } 532 533 public static void set_default_color (string name, double r, double g, double b, double a) { 534 color_list.add (name); 535 colors.set (name, new Color (r, g, b, a)); 536 } 537 538 public static void save_color (string name, double r, double g, double b, double a) { 539 colors.set (name, new Color (r, g, b, a)); 540 write_theme (); 541 } 542 543 public static void load_theme (string theme_file) { 544 File default_theme; 545 File user_theme; 546 547 user_theme = get_child (BirdFont.get_settings_directory (), theme_file); 548 if (user_theme.query_exists ()) { 549 current_theme = theme_file; 550 parse_theme (user_theme); 551 return; 552 } 553 554 default_theme = SearchPaths.find_file (null, theme_file); 555 if (default_theme.query_exists ()) { 556 current_theme = theme_file; 557 parse_theme (default_theme); 558 return; 559 } 560 561 warning (@"Theme not found: $theme_file"); 562 } 563 564 public static void write_theme () { 565 DataOutputStream os; 566 File file; 567 int i; 568 string base_name; 569 570 if (current_theme == "") { 571 warning ("No name for theme."); 572 return; 573 } 574 575 if (current_theme == "dark.theme" 576 || current_theme == "bright.theme" 577 || current_theme == "high_contrast.theme") { 578 579 current_theme = "custom.theme"; 580 581 file = get_child (BirdFont.get_settings_directory (), current_theme); 582 i = 2; 583 base_name = "custom"; 584 while (file.query_exists ()) { 585 current_theme = @"$(base_name)_$(i).theme"; 586 file = get_child (BirdFont.get_settings_directory (), current_theme); 587 i++; 588 } 589 } 590 591 file = get_child (BirdFont.get_settings_directory (), current_theme); 592 593 try { 594 if (file.query_exists ()) { 595 file.delete (); 596 } 597 } catch (GLib.Error e) { 598 warning (e.message); 599 } 600 601 try { 602 os = new DataOutputStream (file.create (FileCreateFlags.REPLACE_DESTINATION)); 603 os.put_string ("""<?xml version="1.0" encoding="utf-8" standalone="yes"?>"""); 604 os.put_string ("\n"); 605 606 os.put_string ("<theme>\n"); 607 foreach (string name in colors.keys) { 608 Color color = colors.get (name); 609 610 os.put_string ("\t<color "); 611 612 os.put_string (@"name=\"$(Markup.escape_text (name))\" "); 613 os.put_string (@"red=\"$(color.r)\" "); 614 os.put_string (@"green=\"$(color.g)\" "); 615 os.put_string (@"blue=\"$(color.b)\" "); 616 os.put_string (@"alpha=\"$(color.a)\""); 617 618 os.put_string ("/>\n"); 619 } 620 os.put_string ("</theme>\n"); 621 622 os.close (); 623 } catch (GLib.Error e) { 624 warning (e.message); 625 } 626 627 add_theme_files (); 628 } 629 630 static void parse_theme (File f) { 631 string xml_data; 632 XmlParser parser; 633 634 try { 635 FileUtils.get_contents ((!) f.get_path (), out xml_data); 636 parser = new XmlParser (xml_data); 637 parse_colors (parser.get_root_tag ()); 638 } catch (GLib.Error e) { 639 warning (e.message); 640 } 641 } 642 643 static void parse_colors (Tag tag) { 644 foreach (Tag t in tag) { 645 if (t.get_name () == "color") { 646 parse_color (t.get_attributes ()); 647 } 648 } 649 } 650 651 static void parse_color (Attributes attributes) { 652 string name = ""; 653 double r = 0; 654 double g = 0; 655 double b = 0; 656 double a = 1; 657 658 foreach (Attribute attr in attributes) { 659 if (attr.get_name () == "name") { 660 name = attr.get_content (); 661 } 662 663 if (attr.get_name () == "red") { 664 r = double.parse (attr.get_content ()); 665 } 666 667 if (attr.get_name () == "green") { 668 g = double.parse (attr.get_content ()); 669 } 670 671 if (attr.get_name () == "blue") { 672 b = double.parse (attr.get_content ()); 673 } 674 675 if (attr.get_name () == "alpha") { 676 a = double.parse (attr.get_content ()); 677 } 678 } 679 680 colors.set (name, new Color (r, g, b, a)); 681 } 682 683 public static void add_new_theme (SettingsDisplay d) { 684 TextListener listener; 685 686 listener = new TextListener (t_("New theme"), "", t_("Set")); 687 688 listener.signal_text_input.connect ((text) => { 689 if (text != "") { 690 current_theme = text + ".theme"; 691 themes.add (current_theme); 692 } 693 }); 694 695 listener.signal_submit.connect (() => { 696 TabContent.hide_text_input (); 697 write_theme (); 698 d.create_setting_items (); 699 }); 700 701 TabContent.show_text_input (listener); 702 } 703 704 public static string get_icon_file () { 705 string icons; 706 File f; 707 708 return_val_if_fail (!is_null (current_theme), "icons.bf".dup ()); 709 return_val_if_fail (current_theme != "", "icons.bf".dup ()); 710 711 if (current_theme == "dark.theme" 712 || current_theme == "bright.theme" 713 || current_theme == "high_contrast.theme") { 714 return "icons.bf".dup (); 715 } 716 717 icons = current_theme.replace (".theme", ".bf"); 718 f = SearchPaths.search_file (null, icons); 719 720 if (f.query_exists ()) { 721 return icons; 722 } 723 724 return "icons.bf".dup (); 725 } 726 } 727 728 } 729