The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

LabelTool.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/LabelTool.vala.
Sort coverage table for ligatures
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 17 namespace BirdFont { 18 19 public class LabelTool : Tool { 20 21 public string label { get; set; } 22 public string number { get; set; } 23 public bool has_counter { get; set; } 24 public bool has_delete_button { get; set; } 25 public signal void delete_action (LabelTool self); 26 public string data = ""; 27 28 double counter_box_width = 24 * Toolbox.get_scale (); 29 double counter_box_height = 11 * Toolbox.get_scale (); 30 31 Text label_text; 32 33 public LabelTool (string label) { 34 double text_height; 35 36 base (); 37 38 this.label = label; 39 this.number = "-"; 40 41 label_text = new Text (); 42 label_text.set_text (label); 43 text_height = 17 * Toolbox.get_scale (); 44 label_text.set_font_size (text_height); 45 46 has_delete_button = false; 47 has_counter = false; 48 49 panel_press_action.connect ((selected, button, tx, ty) => { 50 if (has_delete_button && y <= ty <= y + h && tx >= w - 30 * Toolbox.get_scale ()) { 51 delete_action (this); 52 } 53 }); 54 } 55 56 public override void draw_tool (Context cr, double px, double py) { 57 Text glyph_count; 58 double bgx, bgy; 59 double center_x, center_y; 60 double x = this.x - px; 61 double y = this.y - py; 62 double text_height; 63 double text_width; 64 65 // background 66 if (is_selected ()) { 67 cr.save (); 68 Theme.color (cr, "Menu Background"); 69 cr.rectangle (0, y - 2 * Toolbox.get_scale (), w, h); // labels overlap with 2 pixels 70 cr.fill (); 71 cr.restore (); 72 } 73 74 // tab label 75 cr.save (); 76 77 if (is_selected ()) { 78 Theme.text_color (label_text, "Text Tool Box"); 79 } else { 80 Theme.text_color (label_text, "Text Tool Box"); 81 } 82 83 text_width = Toolbox.allocation_width; 84 85 if (has_counter) { 86 text_width -= counter_box_width - 15; 87 } 88 89 if (has_delete_button) { 90 text_width -= 30; 91 } 92 93 label_text.truncate (text_width); 94 95 label_text.draw_at_top (cr, x, y); 96 cr.restore (); 97 98 // glyph count 99 if (has_counter) { 100 cr.save (); 101 bgx = Toolbox.allocation_width - counter_box_width - 9; 102 bgy = y + 2; 103 104 if (is_selected ()) { 105 Theme.color (cr, "Glyph Count Background 1"); 106 } else { 107 Theme.color (cr, "Glyph Count Background 2"); 108 } 109 110 draw_rounded_rectangle (cr, bgx, bgy, counter_box_width, counter_box_height, 3); 111 cr.fill (); 112 cr.restore (); 113 114 glyph_count = new Text (); 115 glyph_count.set_text (@"$(this.number)"); 116 text_height = 12; 117 118 glyph_count.set_font_size (text_height); 119 center_x = bgx + (counter_box_width / 2.0 - glyph_count.get_extent () / 2.0); 120 center_y = bgy + (counter_box_height / 2.0 + 5); 121 122 if (is_selected ()) { 123 Theme.text_color (glyph_count, "Text Foreground"); 124 } else { 125 Theme.text_color (glyph_count, "Text Foreground"); 126 } 127 128 glyph_count.set_font_size (text_height); 129 glyph_count.draw_at_baseline (cr, center_x, center_y); 130 } 131 132 if (has_delete_button) { 133 cr.save (); 134 Theme.color (cr, "Text Foreground"); 135 cr.set_line_width (1); 136 cr.move_to (w - 20, y + h / 2 - 2.5 - 2); 137 cr.line_to (w - 25, y + h / 2 + 2.5 - 2); 138 cr.move_to (w - 20, y + h / 2 + 2.5 - 2); 139 cr.line_to (w - 25, y + h / 2 - 2.5 - 2); 140 cr.stroke (); 141 cr.restore (); 142 } 143 } 144 } 145 146 } 147