.
1 /*
2 Copyright (C) 2014 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 MessageDialog : Dialog {
20
21 public Button ok_button;
22 TextArea message;
23 public signal void close ();
24
25 public MessageDialog (string message) {
26 Color c = Theme.get_color ("Text Tool Box");
27 this.message = new TextArea (20 * MainWindow.units, c);
28 this.message.set_text (message);
29 this.message.draw_border = false;
30 this.message.editable = false;
31 this.message.carret_is_visible = false;
32 this.message.min_width = 300 * MainWindow.units;
33 this.message.width = this.message.min_width;
34 this.message.min_height = 20 * MainWindow.units;
35 this.message.height = this.message.min_height;
36
37 ok_button = new Button (t_("Close"));
38 ok_button.action.connect (close_action);
39 }
40
41 public void close_action () {
42 close ();
43 MainWindow.hide_dialog ();
44 }
45
46 public override void draw (Context cr) {
47 double cx, cy;
48 double width, height;
49
50 message.layout ();
51
52 width = message.get_width ();
53 height = message.get_height ();
54 height += ok_button.get_height ();
55 height += 5 * MainWindow.units;
56
57 cx = (allocation.width - width) / 2.0;
58 cy = (allocation.height - height) / 2.0;
59
60 cr.save ();
61 Theme.color_opacity (cr, "Foreground 1", 0.3);
62 cr.rectangle (0, 0, allocation.width, allocation.height);
63 cr.fill ();
64 cr.restore ();
65
66 cr.save ();
67 Theme.color (cr, "Dialog Background");
68 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units);
69 cr.fill ();
70 cr.restore ();
71
72 cr.save ();
73 Theme.color (cr, "Foreground 1");
74 cr.set_line_width (1);
75 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units);
76 cr.stroke ();
77 cr.restore ();
78
79 cy += 5 * MainWindow.units;
80 message.widget_x = cx + 10 * MainWindow.units;
81 message.widget_y = cy;
82 message.allocation = allocation;
83 message.layout ();
84 message.draw (cr);
85
86 ok_button.widget_x = cx + 10 * MainWindow.units;
87 ok_button.widget_y = cy + message.get_height ();
88 ok_button.draw (cr);
89 }
90
91 public override void button_press (uint button, double x, double y) {
92 ok_button.button_press (button, x, y);
93 }
94
95 public override void button_release (uint button, double x, double y) {
96 ok_button.button_release (button, x, y);
97 }
98 }
99
100 }
101