Commit 3c201ab
Check boxes for bold and italic styles
Changed files (5)
addedlibbirdfont/CheckBox.valamodifiedlibbirdfont/DescriptionDisplay.valamodifiedlibbirdfont/Renderer/Text.valamodifiedlibbirdfont/Renderer/TextArea.valamodifiedlibbirdfont/Widget.vala
Diff
new file mode 100644@@ -0,0 +1,91 @@+/*+ Copyright (C) 2014 Johan Mattsson++ This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version.++ This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details.+*/++using Cairo;+using Math;++namespace BirdFont {++public class CheckBox : Widget {+ + public bool checked = false;+ public signal void updated (bool checked);+ public double padding = 3.333 * MainWindow.units;+ + public double w = 12 * MainWindow.units;+ public double h = 12 * MainWindow.units;+ + public Text label;+ + public CheckBox (string text = "", double font_size = -1) {+ if (font_size < 0) {+ font_size = h;+ }+ + label = new Text (text, font_size);+ }+ + public void set_checked (bool c) {+ checked = c;+ updated (c);+ }+ + public override double get_height () {+ return label.font_size;+ }+ + public override double get_width () {+ return w + 2 * padding + label.get_sidebearing_extent ();+ }+ + public override void draw (Context cr) {+ double d = w * 0.25;+ double center_y = (get_height () - (h + 2 * padding)) / 2.0 + padding;++ cr.save ();+ cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1); + draw_rounded_rectangle (cr, widget_x, widget_y + center_y, w, h - padding, padding);+ cr.fill ();+ cr.restore ();+ + cr.save ();+ cr.set_line_width (1);+ draw_rounded_rectangle (cr, widget_x, widget_y + center_y, w, h - padding, padding);+ cr.stroke ();+ cr.restore ();+ + if (checked) {+ cr.save ();+ + cr.set_line_width (1);+ + cr.move_to (widget_x + d, widget_y + d + center_y);+ cr.line_to (widget_x + w - d, widget_y + h - d + center_y);+ cr.stroke ();+ + cr.move_to (widget_x + w - d, widget_y + d + center_y);+ cr.line_to (widget_x + d, widget_y + h - d + center_y);+ cr.stroke ();+ + cr.restore ();+ }+ + label.widget_x = widget_x + 1.5 * w;+ label.widget_y = widget_y;+ label.draw (cr);+ }+ +}++}@@ -28,6 +28,8 @@ public class DescriptionDisplay : FontDisplay { TextArea postscript_name; TextArea name; TextArea style;+ CheckBox bold;+ CheckBox italic; TextArea weight; TextArea full_name; TextArea unique_id;@@ -79,13 +81,28 @@ public class DescriptionDisplay : FontDisplay { widgets.add (name); widgets.add (new Text (t_("Style"), label_size, label_margin));- style.margin_bottom = margin;+ style.margin_bottom = 1.5 * margin; style.set_text (font.subfamily); style.text_changed.connect ((t) => { font.subfamily = t; }); widgets.add (style); + bold = new CheckBox (t_("Bold"), label_size);+ bold.updated.connect ((c) => {+ font.bold = c;+ });+ bold.checked = font.bold;+ widgets.add (bold);+ + italic = new CheckBox (t_("Italic"), label_size);+ italic.updated.connect ((c) => {+ font.italic = c;+ });+ italic.checked = font.italic;+ italic.margin_bottom = margin;+ widgets.add (italic);+ widgets.add (new Text (t_("Weight"), label_size, label_margin)); weight.margin_bottom = margin; weight.set_text (font.get_weight ());@@ -216,6 +233,7 @@ public class DescriptionDisplay : FontDisplay { public override void button_press (uint button, double x, double y) { TextArea t;+ CheckBox c; if (keyboard_focus != null) { t = (!) keyboard_focus;@@ -231,6 +249,9 @@ public class DescriptionDisplay : FontDisplay { t = (TextArea) w; t.draw_carret = true; keyboard_focus = t;+ } else if (w is CheckBox) {+ c = (CheckBox) w;+ c.set_checked (!c.checked); } } }@@ -42,7 +42,7 @@ public class Text : Widget { public string text; GlyphSequence glyph_sequence; public delegate void Iterator (Glyph glyph, double kerning, bool last);- double font_size;+ public double font_size; public Text (string text = "", double size = 17, double margin_bottom = 0) { current_font = null;@@ -197,14 +197,14 @@ public class TextArea : Widget { cr.save (); cr.set_line_width (1); cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1);- create_border (cr, x, y);+ draw_rounded_rectangle (cr, x, y, this.width, this.height, padding); cr.fill (); cr.restore (); // border cr.save (); cr.set_line_width (1);- create_border (cr, x, y);+ draw_rounded_rectangle (cr, x, y, this.width, this.height, padding); cr.stroke (); cr.restore (); }@@ -319,23 +319,6 @@ public class TextArea : Widget { return n; }-- void create_border (Context cr, double x, double y) {- double radius = padding; - double w = width;- double h = height;- - cr.move_to (x, y + radius);- cr.arc (x + radius, y + radius, radius, 2 * (PI / 2), 3 * (PI / 2));- cr.line_to (x + w - radius, y);- cr.arc (x + w - radius, y + radius, radius, 3 * (PI / 2), 4 * (PI / 2));- cr.line_to (x + w, y + h); - cr.arc (x + w - radius, y + h, radius, 4 * (PI / 2), 5 * (PI / 2));- cr.line_to (x + radius, y + h + radius);- cr.arc (x + radius, y + h, radius, 5 * (PI / 2), 6 * (PI / 2));- cr.line_to (x, y + radius);- cr.close_path (); - } } }@@ -28,6 +28,20 @@ public abstract class Widget : GLib.Object { public abstract void draw (Context cr); public WidgetAllocation allocation = new WidgetAllocation ();++ public void draw_rounded_rectangle (Context cr, double x, double y, double w, double h, double radius) { + // fixme radius is padding not margin+ cr.move_to (x, y + radius);+ cr.arc (x + radius, y + radius, radius, 2 * (PI / 2), 3 * (PI / 2));+ cr.line_to (x + w - radius, y);+ cr.arc (x + w - radius, y + radius, radius, 3 * (PI / 2), 4 * (PI / 2));+ cr.line_to (x + w, y + h); + cr.arc (x + w - radius, y + h, radius, 4 * (PI / 2), 5 * (PI / 2));+ cr.line_to (x + radius, y + h + radius);+ cr.arc (x + radius, y + h, radius, 5 * (PI / 2), 6 * (PI / 2));+ cr.line_to (x, y + radius);+ cr.close_path (); + } } }