The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

MessageDialog.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
Install renamed icons file heads/master
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 width += 10 * MainWindow.units; 54 55 height = message.get_height (); 56 height += ok_button.get_height (); 57 height += 5 * MainWindow.units; 58 59 cx = (allocation.width - width) / 2.0; 60 cy = (allocation.height - height) / 2.0; 61 62 cr.save (); 63 Theme.color_opacity (cr, "Foreground 1", 0.3); 64 cr.rectangle (0, 0, allocation.width, allocation.height); 65 cr.fill (); 66 cr.restore (); 67 68 cr.save (); 69 Theme.color (cr, "Dialog Background"); 70 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 71 cr.fill (); 72 cr.restore (); 73 74 cr.save (); 75 Theme.color (cr, "Foreground 1"); 76 cr.set_line_width (1); 77 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 78 cr.stroke (); 79 cr.restore (); 80 81 cy += 5 * MainWindow.units; 82 message.widget_x = cx + 10 * MainWindow.units; 83 message.widget_y = cy; 84 message.allocation = allocation; 85 message.layout (); 86 message.draw (cr); 87 88 ok_button.widget_x = cx + 10 * MainWindow.units; 89 ok_button.widget_y = cy + message.get_height (); 90 ok_button.draw (cr); 91 } 92 93 public override void button_press (uint button, double x, double y) { 94 ok_button.button_press (button, x, y); 95 } 96 97 public override void button_release (uint button, double x, double y) { 98 ok_button.button_release (button, x, y); 99 } 100 } 101 102 } 103