The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

LicenseDialog.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
Circle boundaries heads/master
1 /* 2 Copyright (C) 2015 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 LicenseDialog : Dialog { 20 TextArea agreement; 21 Button accept; 22 Button decline; 23 24 double width = 0; 25 double height; 26 27 static const double font_size = 20; 28 static const double margin = 20; 29 30 public LicenseDialog () { 31 Color color = Theme.get_color ("Text Tool Box"); 32 agreement = new TextArea (font_size, color); 33 agreement.min_width = 300; 34 agreement.set_editable (false); 35 agreement.draw_border = false; 36 agreement.set_text ("BirdFont is developed with donations, please consider donating to the project.\n\nThis 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?"); 37 38 decline = new Button ("Commercial License"); 39 decline.action.connect (() => { 40 commercial (); 41 }); 42 43 accept = new Button ("SIL Open Font License"); 44 accept.action.connect (() => { 45 MainWindow.hide_dialog (); 46 MainWindow.get_toolbox ().set_suppress_event (false); 47 }); 48 49 MainWindow.get_toolbox ().set_suppress_event (true); 50 height = 240; 51 } 52 53 public override void layout () { 54 double cx = 0; 55 double cy = (allocation.height - height) / 2.0; 56 double center; 57 double h; 58 59 cx = margin; 60 decline.widget_x = cx; 61 62 cx += margin + decline.get_width (); 63 accept.widget_x = cx; 64 65 width = agreement.get_width () + margin; 66 center = (allocation.width - width) / 2.0; 67 68 agreement.widget_x = margin + center; 69 agreement.widget_y = cy + margin; 70 agreement.allocation = new WidgetAllocation.for_area (0, 0, 300, 450); 71 agreement.layout (); 72 73 h = agreement.get_height () + margin; 74 75 decline.widget_x += center; 76 decline.widget_y = cy + h + margin; 77 78 accept.widget_x += center; 79 accept.widget_y = cy + h + margin; 80 } 81 82 public override void draw (Context cr) { 83 double cx, cy; 84 85 layout (); 86 87 cx = (allocation.width - width) / 2.0; 88 cy = (allocation.height - height) / 2.0; 89 90 cr.save (); 91 Theme.color (cr, "Dialog Shadow"); 92 cr.rectangle (0, 0, allocation.width, allocation.height); 93 cr.fill (); 94 cr.restore (); 95 96 cr.save (); 97 Theme.color (cr, "Dialog Background"); 98 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 99 cr.fill (); 100 cr.restore (); 101 102 cr.save (); 103 Theme.color (cr, "Button Border 4"); 104 cr.set_line_width (1); 105 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 106 cr.stroke (); 107 cr.restore (); 108 109 decline.draw (cr); 110 accept.draw (cr); 111 agreement.draw (cr); 112 } 113 114 public override void button_press (uint button, double x, double y) { 115 decline.button_press (button, x, y); 116 accept.button_press (button, x, y); 117 } 118 119 public override void button_release (uint button, double x, double y) { 120 decline.button_release (button, x, y); 121 accept.button_release (button, x, y); 122 } 123 124 void commercial () { 125 MessageDialog md = new MessageDialog ("You need to get a commercial copy of BirdFont. Visit to birdfont.org"); 126 md.close.connect (exit); 127 MainWindow.show_dialog (md); 128 } 129 130 static void exit () { 131 MainWindow.native_window.quit (); 132 } 133 } 134 135 } 136