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

Revisions

View the latest version of libbirdfont/ColorTool.vala.
Merge stroke parts
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 select_action.connect((self) => { 32 MainWindow.native_window.color_selection (this); 33 }); 34 35 color_updated.connect (() => { 36 MainWindow.get_toolbox ().redraw ((int)x, (int)y, (int)x + 20, (int)y + 20); 37 GlyphCanvas.redraw (); 38 }); 39 } 40 41 public void signal_color_updated () { 42 color_updated (); 43 } 44 45 public override void draw (Context cr) { 46 double scale = Toolbox.get_scale (); 47 double xt = x + w / 2 - 8 * scale; 48 double yt = y + h / 2 - 8 * scale; 49 50 base.draw (cr); 51 52 cr.save (); 53 cr.set_source_rgba (color_r, color_g, color_b, 1); 54 cr.rectangle (xt, yt, 16 * scale, 16 * scale); 55 cr.fill (); 56 cr.restore (); 57 } 58 59 public void set_r (double c) { 60 color_r = c; 61 } 62 63 public void set_g (double c) { 64 color_g = c; 65 } 66 67 public void set_b (double c) { 68 color_b = c; 69 } 70 71 public void set_a (double c) { 72 color_a = c; 73 } 74 75 } 76 77 } 78