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.
New color theme
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 27 double counter_box_width = 24; 28 double counter_box_height = 11; 29 30 public LabelTool (string label) { 31 base (); 32 33 this.label = label; 34 this.number = "-"; 35 36 has_delete_button = false; 37 has_counter = false; 38 39 panel_press_action.connect ((selected, button, tx, ty) => { 40 if (has_delete_button && y <= ty <= y + h && tx >= w - 30) { 41 delete_action (this); 42 } 43 }); 44 45 panel_move_action.connect ((selected, button, tx, ty) => { 46 return false; 47 }); 48 } 49 50 public override void draw (Context cr) { 51 Text label_text, glyph_count; 52 double text_height; 53 double bgx, bgy; 54 double center_x, center_y; 55 56 // background 57 if (is_selected ()) { 58 cr.save (); 59 Theme.color (cr, "Menu Background"); 60 cr.rectangle (0, y - 2, w, h + 7); 61 cr.fill (); 62 cr.restore (); 63 } 64 65 // tab label 66 cr.save (); 67 label_text = new Text (); 68 label_text.set_text (label); 69 text_height = 18; 70 71 if (is_selected ()) { 72 Theme.text_color (label_text, "Text Foreground"); 73 } else { 74 Theme.text_color (label_text, "Text Foreground"); 75 } 76 77 label_text.set_font_size (text_height); 78 label_text.draw_at_baseline (cr, x + 14, y + h - 1.5); 79 cr.restore (); 80 81 // glyph count 82 if (has_counter) { 83 cr.save (); 84 bgx = Toolbox.allocation_width - counter_box_width - 9; 85 bgy = y + 2; 86 87 if (is_selected ()) { 88 Theme.color (cr, "Glyph Count Background"); 89 } else { 90 Theme.color (cr, "Menu Background"); 91 } 92 93 draw_rounded_rectangle (cr, bgx, bgy, counter_box_width, counter_box_height, 3); 94 cr.fill (); 95 cr.restore (); 96 97 glyph_count = new Text (); 98 glyph_count.set_text (@"$(this.number)"); 99 text_height = 12; 100 101 glyph_count.set_font_size (text_height); 102 center_x = bgx + (counter_box_width / 2.0 - glyph_count.get_extent () / 2.0); 103 center_y = bgy + (counter_box_height / 2.0 + 5); 104 105 if (is_selected ()) { 106 Theme.text_color (glyph_count, "Text Foreground"); 107 } else { 108 Theme.text_color (glyph_count, "Text Foreground"); 109 } 110 111 glyph_count.set_font_size (text_height); 112 glyph_count.draw_at_baseline (cr, center_x, center_y); 113 } 114 115 if (has_delete_button) { 116 cr.save (); 117 Theme.color (cr, "Foreground Inverted"); 118 cr.set_line_width (1); 119 cr.move_to (w - 20, y + h / 2 - 2.5 + 2); 120 cr.line_to (w - 25, y + h / 2 + 2.5 + 2); 121 cr.move_to (w - 20, y + h / 2 + 2.5 + 2); 122 cr.line_to (w - 25, y + h / 2 - 2.5 + 2); 123 cr.stroke (); 124 cr.restore (); 125 } 126 } 127 } 128 129 } 130