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