The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Button.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/Button.vala.
Parse more style attributes in SVG files
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 Button : Widget { 20 21 Text label; 22 double padding; 23 double font_size; 24 25 public signal void action (); 26 27 public Button (string label, double margin_bottom = 0) { 28 this.margin_bottom = margin_bottom; 29 font_size = 17 * MainWindow.units; 30 this.label = new Text (label, font_size); 31 padding = 15 * MainWindow.units; 32 } 33 34 public override void draw (Context cr) { 35 cr.save (); 36 Theme.color (cr, "Button Background 3"); 37 draw_rounded_rectangle (cr, widget_x, widget_y, get_width (), padding, padding); 38 cr.fill (); 39 cr.restore (); 40 41 cr.save (); 42 Theme.color (cr, "Button Border 3"); 43 cr.set_line_width (1); 44 draw_rounded_rectangle (cr, widget_x, widget_y, get_width (), padding, padding); 45 cr.stroke (); 46 cr.restore (); 47 48 cr.save (); 49 Theme.text_color (label, "Button Foreground"); 50 label.draw_at_top (cr, widget_x + padding, widget_y + (2 * padding - font_size - 3 * MainWindow.units) / 2.0); 51 cr.restore (); 52 } 53 54 public override double get_height () { 55 return 2 * padding; 56 } 57 58 public override double get_width () { 59 return label.get_width () + 2 * padding; 60 } 61 62 public override void button_release (uint button, double x, double y) { 63 if (is_over (x, y)) { 64 action (); 65 } 66 } 67 } 68 69 } 70