The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

License dialog

These changes was commited to the Birdfont repository Sat, 24 Oct 2015 13:11:31 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 24 Oct 2015 13:11:31 +0000 (15:11 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 24 Oct 2015 13:11:31 +0000 (15:11 +0200)
commit da0cf4b6a540baefe8d69fd5169ac67aff6a6209
tree b0d0e83085a633d9c4cd75095ed6e9b8a1752d28
parent 21e86d2ecc4d540df96ba3763be26e0c2778f082
License dialog

birdfont/Main.vala
libbirdfont/LicenseDialog.vala [new ]
libbirdfont/MainWindow.vala
libbirdfont/MessageDialog.vala
libbirdfont/Toolbox.vala
--- a/birdfont/Main.vala +++ b/birdfont/Main.vala @@ -33,9 +33,10 @@ native_window.init (); birdfont.load_font_from_command_line (); + Gtk.main (); return 0; }
--- /dev/null +++ b/libbirdfont/LicenseDialog.vala @@ -1,1 +1,136 @@ + /* + Copyright (C) 2015 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 LicenseDialog : Dialog { + TextArea agreement; + Button accept; + Button decline; + + double width = 0; + double height; + + static const double font_size = 20; + static const double margin = 20; + + public LicenseDialog () { + agreement = new TextArea (font_size); + agreement.min_width = 300; + agreement.set_editable (false); + agreement.draw_border = false; + agreement.text_color = Theme.get_color ("Text Tool Box"); + agreement.set_text ("This is the freeware version of BirdFont. You may use it for creating fonts under the SIL Open Font License.\n\nWhich license do you want to use for your font?"); + + decline = new Button ("Commercial"); + decline.action.connect (() => { + commercial (); + }); + + accept = new Button ("SIL Open Font License"); + accept.action.connect (() => { + MainWindow.hide_dialog (); + MainWindow.get_toolbox ().set_suppress_event (false); + }); + + height = 190 * MainWindow.units; + + MainWindow.get_toolbox ().set_suppress_event (true); + } + + void layout () { + double cx = 0; + double cy = (allocation.height - height) / 2.0; + double center; + double h; + + cx = margin; + decline.widget_x = cx; + + cx += margin + decline.get_width (); + accept.widget_x = cx; + + width = agreement.get_width () + margin; + center = (allocation.width - width) / 2.0; + + agreement.widget_x = margin + center; + agreement.widget_y = cy + margin; + agreement.allocation = new WidgetAllocation.for_area (0, 0, 300, 300); + + h = agreement.get_height () + margin; + + decline.widget_x += center; + decline.widget_y = cy + h + margin; + + accept.widget_x += center; + accept.widget_y = cy + h + margin; + } + + public override void draw (Context cr) { + double cx, cy; + + layout (); + + cx = (allocation.width - width) / 2.0; + cy = (allocation.height - height) / 2.0; + + cr.save (); + Theme.color (cr, "Dialog Shadow"); + cr.rectangle (0, 0, allocation.width, allocation.height); + cr.fill (); + cr.restore (); + + cr.save (); + Theme.color (cr, "Dialog Background"); + draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); + cr.fill (); + cr.restore (); + + cr.save (); + Theme.color (cr, "Button Border 4"); + cr.set_line_width (1); + draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); + cr.stroke (); + cr.restore (); + + decline.draw (cr); + accept.draw (cr); + agreement.draw (cr); + } + + public override void button_press (uint button, double x, double y) { + decline.button_press (button, x, y); + accept.button_press (button, x, y); + } + + public override void button_release (uint button, double x, double y) { + decline.button_release (button, x, y); + accept.button_release (button, x, y); + } + + void commercial () { + MessageDialog md = new MessageDialog ("You need to get a commercial copy of BirdFont. Visit to birdfont.org"); + md.close.connect (exit); + MainWindow.show_dialog (md); + } + + static void exit () { + MainWindow.native_window.quit (); + } + } + + }
--- a/libbirdfont/MainWindow.vala +++ b/libbirdfont/MainWindow.vala @@ -77,6 +77,10 @@ GlyphCanvas.redraw (); set_cursor (NativeWindow.VISIBLE); + } + + public static void show_license_dialog () { + show_dialog (new LicenseDialog ()); } public static void set_cursor (int flags) { @@ -89,8 +93,9 @@ } } - public static void show_message (string text) { - show_dialog (new MessageDialog (text)); + public static void show_message (string text) { + MessageDialog md = new MessageDialog (text); + show_dialog (md); } public static void hide_dialog () {
--- a/libbirdfont/MessageDialog.vala +++ b/libbirdfont/MessageDialog.vala @@ -18,8 +18,9 @@ public class MessageDialog : Dialog { - Button ok_button; + public Button ok_button; TextArea message; + public signal void close (); public MessageDialog (string message) { Color c = Theme.get_color ("Text Tool Box"); @@ -34,9 +35,12 @@ this.message.height = this.message.min_height; ok_button = new Button (t_("Close")); - ok_button.action.connect (() => { - MainWindow.hide_dialog (); - }); + ok_button.action.connect (close_action); + } + + public void close_action () { + close (); + MainWindow.hide_dialog (); } public override void draw (Context cr) {
--- a/libbirdfont/Toolbox.vala +++ b/libbirdfont/Toolbox.vala @@ -53,6 +53,7 @@ double tool_tip_y = 0; public signal void new_tool_set (Tab? tab); + bool suppress_event = false; public Toolbox (GlyphCanvas glyph_canvas, TabBar tab_bar) { tool_sets = new Gee.ArrayList<ToolCollection> (); @@ -90,6 +91,10 @@ }); update_expanders (); + } + + public void set_suppress_event (bool e) { + suppress_event = e; } public static DrawingTools get_drawing_tools () { @@ -144,7 +149,7 @@ } public void press (uint button, double x, double y) { - if (MenuTab.has_suppress_event ()) { + if (MenuTab.has_suppress_event () || suppress_event) { warn_if_test ("Event suppressed"); return; } @@ -171,7 +176,7 @@ y -= current_set.scroll; - if (MenuTab.has_suppress_event ()) { + if (MenuTab.has_suppress_event () || suppress_event) { warn_if_test ("Event suppressed"); return; } @@ -198,7 +203,7 @@ } public void double_click (uint button, double x, double y) { - if (MenuTab.has_suppress_event ()) { + if (MenuTab.has_suppress_event () || suppress_event) { warn_if_test ("Event suppressed"); return; } @@ -219,7 +224,7 @@ y -= current_set.scroll; - if (MenuTab.has_suppress_event ()) { + if (MenuTab.has_suppress_event () || suppress_event) { warn_if_test ("Event suppressed"); return; }