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