Clone in a terminal:
Commit da0cf4b
Johan Mattsson - 2015-10-24T13:11:31+00:00
da0cf4b6a540baefe8d69fd5169ac67aff6a6209johan.mattsson.m@gmail.com

License dialog

Changed files (5)

Diff

diff --git a/birdfont/Main.vala b/birdfont/Main.valaindex 104ea8d..8554fd7 100644--- a/birdfont/Main.vala+++ b/birdfont/Main.vala@@ -33,6 +33,7 @@ public static int main (string[] arg) { 	native_window.init ();  	birdfont.load_font_from_command_line ();+	 	Gtk.main (); 	return 0; }diff --git a/libbirdfont/LicenseDialog.vala b/libbirdfont/LicenseDialog.valanew file mode 100644index 0000000..3d7ac52--- /dev/null+++ b/libbirdfont/LicenseDialog.vala@@ -0,0 +1,135 @@+/*+    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 ();+	}+}++}diff --git a/libbirdfont/MainWindow.vala b/libbirdfont/MainWindow.valaindex dca9ba0..b727651 100644--- a/libbirdfont/MainWindow.vala+++ b/libbirdfont/MainWindow.vala@@ -79,6 +79,10 @@ public class MainWindow : GLib.Object { 		set_cursor (NativeWindow.VISIBLE);
 	}
 
+	public static void show_license_dialog () {
+		show_dialog (new LicenseDialog ());
+	}
+
 	public static void set_cursor (int flags) {
 		if (BirdFont.has_argument ("--test")) {
 			if (dialog.visible) {
@@ -89,8 +93,9 @@ public class MainWindow : GLib.Object { 		}
 	}
 
-	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 () {
diff --git a/libbirdfont/MessageDialog.vala b/libbirdfont/MessageDialog.valaindex 9ceb385..23e4d88 100644--- a/libbirdfont/MessageDialog.vala+++ b/libbirdfont/MessageDialog.vala@@ -18,8 +18,9 @@ namespace BirdFont {  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 @@ public class MessageDialog : Dialog { 		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) {	diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex 899da2f..58eeda7 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -53,6 +53,7 @@ public class Toolbox : GLib.Object  { 	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> ();@@ -92,6 +93,10 @@ public class Toolbox : GLib.Object  { 		update_expanders (); 	} +	public void set_suppress_event (bool e) {+		suppress_event = e;+	}+ 	public static DrawingTools get_drawing_tools () { 		return drawing_tools; 	}@@ -144,7 +149,7 @@ public class Toolbox : GLib.Object  { 	} 	 	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 @@ public class Toolbox : GLib.Object  { 		 		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 class Toolbox : GLib.Object  { 	}  	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 @@ public class Toolbox : GLib.Object  { 		 		y -= current_set.scroll; 		-		if (MenuTab.has_suppress_event ()) {+		if (MenuTab.has_suppress_event () || suppress_event) { 			warn_if_test ("Event suppressed"); 			return; 		}

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112