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

Revisions

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