The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

SettingsItem.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) 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 using Math; 17 18 namespace BirdFont { 19 20 public class SettingsItem : GLib.Object { 21 public bool handle_events; 22 public bool key_bindings = false; 23 public double y = 0; 24 public Tool? button = null; 25 public bool headline = false; 26 public MenuItem menu_item = new MenuItem (""); 27 public bool active = false; 28 29 Text label; 30 31 public SettingsItem (Tool tool, string description) { 32 button = tool; 33 label = new Text (); 34 label.set_text (description); 35 handle_events = true; 36 } 37 38 public SettingsItem.key_binding (MenuItem item) { 39 if (item is ToolItem) { 40 button = ((ToolItem) item).tool; 41 } 42 43 label = item.label; 44 handle_events = false; 45 key_bindings = true; 46 menu_item = item; 47 } 48 49 public SettingsItem.head_line (string label) { 50 this.label = new Text (); 51 this.label.set_text (label); 52 53 handle_events = false; 54 headline = true; 55 } 56 57 public SettingsItem.color (string color) { 58 ColorTool cb; 59 Color c; 60 61 c = Theme.get_color (color); 62 63 label = new Text (); 64 label.set_text (color); 65 handle_events = true; 66 67 cb = new ColorTool (color); 68 cb.set_r (c.r); 69 cb.set_g (c.g); 70 cb.set_b (c.b); 71 cb.set_a (c.a); 72 73 cb.color_updated.connect (() => { 74 TabBar tab_bar; 75 76 Theme.save_color (color, cb.color_r, cb.color_g, cb.color_b, cb.color_a); 77 78 tab_bar = MainWindow.get_tab_bar (); 79 tab_bar.redraw (0, 0, tab_bar.width, tab_bar.height); 80 GlyphCanvas.redraw (); 81 Toolbox.redraw_tool_box (); 82 }); 83 84 button = cb; 85 } 86 87 public void draw (WidgetAllocation allocation, Context cr) { 88 Tool t; 89 double label_x; 90 91 if (headline) { 92 cr.save (); 93 Theme.color (cr, "Headline Background"); 94 cr.rectangle (0, y, allocation.width, 40 * MainWindow.units); 95 cr.fill (); 96 cr.restore (); 97 98 cr.save (); 99 Theme.text_color (label, "Foreground Inverted"); 100 label.set_font_size (20 * MainWindow.units); 101 label.draw_at_baseline (cr, 21 * MainWindow.units, y + 25 * MainWindow.units); 102 cr.restore (); 103 } else { 104 if (active) { 105 cr.save (); 106 Theme.color (cr, "Menu Background"); 107 cr.rectangle (0, y - 5 * MainWindow.units, allocation.width, 40 * MainWindow.units); 108 cr.fill (); 109 cr.restore (); 110 } 111 112 label_x = button != null ? 70 : 20; 113 label_x *= MainWindow.units; 114 115 if (button != null) { 116 t = (!) button; 117 t.draw (cr); 118 } 119 120 cr.save (); 121 Theme.text_color (label, "Text Tool Box"); 122 label.set_font_size (17 * MainWindow.units); 123 label.draw_at_baseline (cr, label_x, y + 20 * MainWindow.units); 124 cr.restore (); 125 126 if (key_bindings) { 127 Text key_binding_text = new Text (); 128 key_binding_text.set_text (menu_item.get_key_bindings ()); 129 cr.save (); 130 131 if (active) { 132 Theme.text_color (key_binding_text, "Foreground Inverted"); 133 } else { 134 Theme.text_color (key_binding_text, "Text Tool Box"); 135 } 136 137 key_binding_text.set_font_size (17 * MainWindow.units); 138 label_x += label.get_extent () + 20 * MainWindow.units; 139 key_binding_text.draw_at_baseline (cr, label_x, y + 20 * MainWindow.units); 140 cr.restore (); 141 } 142 } 143 } 144 } 145 146 } 147