Commit 75ab1a7
Dialog box
Changed files (7)
addedlibbirdfont/Button.valamodifiedlibbirdfont/KerningDisplay.valamodifiedlibbirdfont/KerningRange.valamodifiedlibbirdfont/MainWindow.valaaddedlibbirdfont/MessageDialog.valamodifiedlibbirdfont/Renderer/TextArea.valamodifiedlibbirdfont/SaveDialog.vala
Diff
new file mode 100644@@ -0,0 +1,68 @@+/*+ 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;++namespace BirdFont {++public class Button : Widget {++ Text label;+ double padding;+ double font_size;++ public signal void action ();++ public Button (string label) {+ font_size = 17 * MainWindow.units;+ this.label = new Text (label, font_size);+ this.label.set_source_rgba (1, 1, 1, 1);+ padding = 15 * MainWindow.units;+ }++ public override void draw (Context cr) { + cr.save ();+ cr.set_source_rgba (51 / 255.0, 54 / 255.0, 59 / 255.0, 1);+ draw_rounded_rectangle (cr, widget_x, widget_y, get_width (), padding, padding);+ cr.fill ();+ cr.restore ();+ + cr.save ();+ cr.set_source_rgba (0, 0, 0, 1);+ cr.set_line_width (1);+ draw_rounded_rectangle (cr, widget_x, widget_y, get_width (), padding, padding);+ cr.stroke ();+ cr.restore ();++ cr.save ();+ label.draw_at_top (cr, widget_x + padding, widget_y + (2 * padding - font_size - 3 * MainWindow.units) / 2.0);+ cr.restore ();+ }++ public override double get_height () {+ return 2 * padding; + }++ public override double get_width () {+ return label.get_width () + 2 * padding;+ }+ + public void button_press (uint button, double x, double y) {+ if (is_over (x, y)) {+ action ();+ }+ }+}++}@@ -31,8 +31,7 @@ public class KerningDisplay : FontDisplay { double begin_handle_y = 0; double last_handle_x = 0;-- bool parse_error = false;+ bool text_input = false; Gee.ArrayList<UndoItem> undo_items;@@ -59,40 +58,15 @@ public class KerningDisplay : FontDisplay { } public void show_parse_error () {- parse_error = true;- }- - public override void draw (WidgetAllocation allocation, Context cr) {- if (parse_error) {- draw_error_message (allocation, cr);- } else {- draw_kerning_pairs (allocation, cr);- }- }- - public void draw_error_message (WidgetAllocation allocation, Context cr) { string line1 = t_("The current kerning class is malformed."); string line2 = t_("Add single characters separated by space and ranges on the form A-Z."); string line3 = t_("Type “space” to kern the space character and “divis” to kern -.");- - cr.save ();- cr.set_source_rgba (1, 1, 1, 1);- cr.rectangle (0, 0, allocation.width, allocation.height);- cr.fill ();- - cr.set_font_size (18);- cr.set_source_rgba (0.3, 0.3, 0.3, 1);- cr.move_to (30, 40);- cr.show_text (line1);- - cr.set_font_size (14);- cr.move_to (30, 60);- cr.show_text (line2);-- cr.set_font_size (14);- cr.move_to (30, 80);- cr.show_text (line3); - cr.restore ();+ + MainWindow.show_dialog (new MessageDialog (line1 + " " + line2 + " " + line3));+ }+ + public override void draw (WidgetAllocation allocation, Context cr) {+ draw_kerning_pairs (allocation, cr); } public double get_row_height () {@@ -558,8 +532,7 @@ public class KerningDisplay : FontDisplay { } c = (unichar) keyval;- parse_error = false;- + if (suppress_input) { return; }@@ -782,7 +755,6 @@ public class KerningDisplay : FontDisplay { } public override void button_release (int button, double ex, double ey) {- parse_error = false; set_active_handle (ex, ey); moving = false; first_update = true;@@ -63,31 +63,31 @@ public class KerningRange : Tool { public void set_ranges (string r) { GlyphRange glyph_range = new GlyphRange ();- SpacingData spacing = BirdFont.get_current_font ().get_spacing ();+ Font font = BirdFont.get_current_font ();+ SpacingData spacing = font.get_spacing (); string new_range; string ch; - try { - glyph_range.parse_ranges (r);- new_range = glyph_range.get_all_ranges ();+ glyph_range.parse_ranges (r);+ new_range = glyph_range.get_all_ranges ();+ + malformed = false;+ + for (int i = 0; i < glyph_range.get_length (); i++) {+ ch = glyph_range.get_char (i); - for (int i = 0; i < glyph_range.get_length (); i++) {- ch = glyph_range.get_char (i);- - foreach (string c in spacing.get_all_connections (ch)) {- if (!glyph_range.has_character (c) && c != "" && c != "?") {- new_range += " " + GlyphRange.serialize (c);- }+ foreach (string c in spacing.get_all_connections (ch)) {+ if (!glyph_range.has_character (c) && c != "" && c != "?") {+ new_range += " " + GlyphRange.serialize (c); } } - set_one_range (new_range);- malformed = false;- } catch (MarkupError e) {- warning (@"Failed to add range \"$r\"");- warning (e.message);- malformed = true;+ if (!font.has_glyph (ch)) {+ malformed = true;+ } }+ + set_one_range (new_range); } private void set_one_range (string r) throws MarkupError {@@ -132,7 +132,7 @@ public class KerningRange : Tool { cr.save (); if (malformed) { - cr.set_source_rgba (108/255.0, 0/255.0, 0/255.0, 1);+ cr.set_source_rgba (0, 0, 0, 1); } else if (!active) { cr.set_source_rgba (99/255.0, 99/255.0, 99/255.0, 1); } else {@@ -50,6 +50,7 @@ public class MainWindow : GLib.Object { ligature_display = new LigatureList (); spacing_class_tab = new SpacingClassTab (); menu = new Menu (); + dialog = new Dialog (); } @@ -66,6 +67,7 @@ public class MainWindow : GLib.Object { public static void hide_dialog () { dialog = new Dialog (); dialog.visible = false; + GlyphCanvas.redraw (); } public static Menu get_menu () { new file mode 100644@@ -0,0 +1,89 @@+/*+ 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;++namespace BirdFont {++public class MessageDialog : Dialog {++ Button ok_button;+ TextArea message;+ + public MessageDialog (string message) {+ this.message = new TextArea (20 * MainWindow.units);+ this.message.set_text (message);+ this.message.draw_border = false;+ this.message.editable = false;+ this.message.carret_is_visible = false;+ this.message.min_width = 300 * MainWindow.units;+ this.message.width = this.message.min_width;+ this.message.min_height = 20 * MainWindow.units;+ this.message.height = this.message.min_height;++ ok_button = new Button (t_("Close"));+ ok_button.action.connect (() => {+ MainWindow.hide_dialog ();+ });+ }++ public override void draw (Context cr) { + Text headline;+ double cx, cy;+ double width, height;++ message.layout ();++ width = message.get_width ();+ height = message.get_height () + ok_button.get_height ();+ + cx = (allocation.width - width) / 2.0;+ cy = (allocation.height - height) / 2.0;+ + cr.save ();+ cr.set_source_rgba (0, 0, 0, 0.3);+ cr.rectangle (0, 0, allocation.width, allocation.height);+ cr.fill ();+ cr.restore ();+ + cr.save ();+ cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1);+ draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units);+ cr.fill ();+ cr.restore ();+ + cr.save ();+ cr.set_source_rgba (0, 0, 0, 1);+ cr.set_line_width (1);+ draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units);+ cr.stroke ();+ cr.restore ();++ message.widget_x = cx + 10 * MainWindow.units;+ message.widget_y = cy;+ message.allocation = allocation;+ message.layout ();+ message.draw (cr);+ + ok_button.widget_x = cx + 10 * MainWindow.units;+ ok_button.widget_y = cy + message.get_height ();+ ok_button.draw (cr);+ }++ public override void button_press (uint button, double x, double y) {+ ok_button.button_press (button, x, y);+ }+}++}@@ -40,7 +40,7 @@ public class TextArea : Widget { public double width; public double height;-+ Carret carret = new Carret (); Carret selection_end = new Carret (); bool update_selection = false;@@ -62,7 +62,7 @@ public class TextArea : Widget { Gee.ArrayList<TextUndoItem> redo_items = new Gee.ArrayList<TextUndoItem> (); bool store_undo_state_at_next_event = false;- bool editable;+ public bool editable; public TextArea (double font_size = 20) { this.font_size = font_size;@@ -825,6 +825,10 @@ public class TextArea : Widget { tx = 0; ty = font_size; + if (unlikely (allocation.height == 0)) {+ warning ("Allocation is not set.");+ }+ for (i = paragraphs.size - 1; i >= 0 && paragraphs.size > 1; i--) { if (unlikely (paragraphs.get (i).is_empty ())) { warning ("Empty paragraph.");@@ -32,16 +32,19 @@ public class SaveDialog : Dialog { save_button = new Button (t_("Save")); save_button.action.connect (() => {+ MainWindow.hide_dialog (); callbacks.signal_save (); }); discard_button = new Button (t_("Discard")); discard_button.action.connect (() => {+ MainWindow.hide_dialog (); callbacks.signal_discard (); }); cancel_button = new Button (t_("Cancel")); cancel_button.action.connect (() => {+ MainWindow.hide_dialog (); callbacks.signal_cancel (); });