The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

ColorTool.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
Circle boundaries heads/master
1 /* 2 Copyright (C) 2012 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 ColorTool : Tool { 20 21 public double color_r = 0; 22 public double color_g = 0; 23 public double color_b = 0; 24 public double color_a = 0; 25 26 public signal void color_updated (); 27 28 public ColorTool (string tooltip = "") { 29 base (null, tooltip); 30 31 color_updated.connect (() => { 32 redraw (); 33 GlyphCanvas.redraw (); 34 }); 35 } 36 37 public Color get_color () { 38 return new Color (color_r, color_g, color_b, color_a); 39 } 40 41 public void set_color (Color c) { 42 color_r = c.r; 43 color_g = c.g; 44 color_b = c.b; 45 color_a = c.a; 46 color_updated (); 47 } 48 49 public void signal_color_updated () { 50 color_updated (); 51 } 52 53 public override void draw_tool (Context cr, double px, double py) { 54 double scale = Toolbox.get_scale (); 55 double x = this.x - px; 56 double y = this.y - py; 57 double xt = x + w / 2 - 8 * scale; 58 double yt = y + h / 2 - 8 * scale; 59 60 base.draw_tool (cr, px, py); 61 62 cr.save (); 63 cr.set_source_rgba (color_r, color_g, color_b, 1); 64 cr.rectangle (xt, yt, 16 * scale, 16 * scale); 65 cr.fill (); 66 cr.restore (); 67 } 68 69 public void set_r (double c) { 70 color_r = c; 71 } 72 73 public void set_g (double c) { 74 color_g = c; 75 } 76 77 public void set_b (double c) { 78 color_b = c; 79 } 80 81 public void set_a (double c) { 82 color_a = c; 83 } 84 85 } 86 87 } 88