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