The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

OverwriteDialog.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 OverwriteDialog : Dialog { 20 21 OverWriteDialogListener listener; 22 23 Text question; 24 Button overwrite_button; 25 Button cancel_button; 26 Button dont_ask_again_button; 27 28 double width = 0; 29 double height; 30 31 static const double question_font_size = 23; 32 33 public OverwriteDialog (OverWriteDialogListener callbacks) { 34 double font_size = question_font_size * MainWindow.units; 35 36 listener = callbacks; 37 38 question = new Text (callbacks.message, font_size); 39 40 overwrite_button = new Button (callbacks.message); 41 overwrite_button.action.connect (() => { 42 MainWindow.hide_dialog (); 43 callbacks.overwrite (); 44 }); 45 46 cancel_button = new Button (callbacks.cancel_message); 47 cancel_button.action.connect (() => { 48 MainWindow.hide_dialog (); 49 callbacks.cancel (); 50 }); 51 52 dont_ask_again_button = new Button (callbacks.dont_ask_again_message); 53 dont_ask_again_button.action.connect (() => { 54 MainWindow.hide_dialog (); 55 callbacks.overwrite_dont_ask_again (); 56 }); 57 58 height = 90 * MainWindow.units; 59 } 60 61 public override void layout () { 62 double cx = 0; 63 double cy = (allocation.height - height) / 2.0; 64 double center; 65 double qh; 66 67 cx = 20 * MainWindow.units; 68 overwrite_button.widget_x = cx; 69 70 cx += 10 * MainWindow.units + overwrite_button.get_width (); 71 cancel_button.widget_x = cx; 72 73 cx += 10 * MainWindow.units + cancel_button.get_width (); 74 dont_ask_again_button.widget_x = cx; 75 76 width = cx + 20 * MainWindow.units + dont_ask_again_button.get_width (); 77 78 center = (allocation.width - width) / 2.0; 79 80 question.widget_x = overwrite_button.widget_x + center; 81 question.widget_y = cy + 15 * MainWindow.units; 82 Theme.text_color (question, "Text Tool Box"); 83 84 qh = (question_font_size + 1) * MainWindow.units; 85 86 overwrite_button.widget_x += center; 87 overwrite_button.widget_y = cy + qh + 25 * MainWindow.units; 88 89 cancel_button.widget_x += center; 90 cancel_button.widget_y = cy + qh + 25 * MainWindow.units; 91 92 dont_ask_again_button.widget_x += center; 93 dont_ask_again_button.widget_y = cy + qh + 25 * MainWindow.units; 94 } 95 96 public override void draw (Context cr) { 97 double cx, cy; 98 99 layout (); 100 101 cx = (allocation.width - width) / 2.0; 102 cy = (allocation.height - height) / 2.0; 103 104 cr.save (); 105 Theme.color (cr, "Dialog Shadow"); 106 cr.rectangle (0, 0, allocation.width, allocation.height); 107 cr.fill (); 108 cr.restore (); 109 110 cr.save (); 111 Theme.color (cr, "Dialog Background"); 112 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 113 cr.fill (); 114 cr.restore (); 115 116 cr.save (); 117 Theme.color (cr, "Button Border 4"); 118 cr.set_line_width (1); 119 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 120 cr.stroke (); 121 cr.restore (); 122 123 question.draw (cr); 124 overwrite_button.draw (cr); 125 cancel_button.draw (cr); 126 dont_ask_again_button.draw (cr); 127 } 128 129 public override void button_press (uint button, double x, double y) { 130 overwrite_button.button_press (button, x, y); 131 cancel_button.button_press (button, x, y); 132 dont_ask_again_button.button_press (button, x, y); 133 } 134 135 public override void button_release (uint button, double x, double y) { 136 overwrite_button.button_release (button, x, y); 137 cancel_button.button_release (button, x, y); 138 dont_ask_again_button.button_release (button, x, y); 139 } 140 } 141 142 } 143