The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

QuestionDialog.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/QuestionDialog.vala.
Fix overwrite dialog
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 QuestionDialog : Dialog { 20 TextArea question; 21 public Gee.ArrayList<Button> buttons; 22 23 double width = 0; 24 double height; 25 26 static const double font_size = 20; 27 static const double margin = 20; 28 29 public QuestionDialog (string message, int height) { 30 question = new TextArea (font_size); 31 question.min_width = 300; 32 question.set_editable (false); 33 question.draw_border = false; 34 question.text_color = Theme.get_color ("Text Tool Box"); 35 question.set_text (message); 36 37 this.height = height; 38 } 39 40 public void add_button (Button button) { 41 buttons.add (button); 42 } 43 44 void layout () { 45 double cx = 0; 46 double cy = (allocation.height - height) / 2.0; 47 double center; 48 double h; 49 50 cx = margin; 51 52 foreach (Button button in buttons) { 53 button.widget_x = cx; 54 cx += margin + button.get_width (); 55 } 56 57 width = question.get_width () + margin; 58 center = (allocation.width - width) / 2.0; 59 60 question.widget_x = margin + center; 61 question.widget_y = cy + margin; 62 question.allocation = new WidgetAllocation.for_area (0, 0, 300, 450); 63 question.layout (); 64 65 h = question.get_height () + margin; 66 67 foreach (Button button in buttons) { 68 button.widget_x += center; 69 button.widget_y = cy + h + margin; 70 } 71 } 72 73 public override void draw (Context cr) { 74 double cx, cy; 75 76 layout (); 77 78 cx = (allocation.width - width) / 2.0; 79 cy = (allocation.height - height) / 2.0; 80 81 cr.save (); 82 Theme.color (cr, "Dialog Shadow"); 83 cr.rectangle (0, 0, allocation.width, allocation.height); 84 cr.fill (); 85 cr.restore (); 86 87 cr.save (); 88 Theme.color (cr, "Dialog Background"); 89 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 90 cr.fill (); 91 cr.restore (); 92 93 cr.save (); 94 Theme.color (cr, "Button Border 4"); 95 cr.set_line_width (1); 96 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 97 cr.stroke (); 98 cr.restore (); 99 100 foreach (Button button in buttons) { 101 button.draw (cr); 102 } 103 104 question.draw (cr); 105 } 106 107 public override void button_press (uint button, double x, double y) { 108 foreach (Button b in buttons) { 109 b.button_press (button, x, y); 110 } 111 } 112 113 public override void button_release (uint button, double x, double y) { 114 foreach (Button b in buttons) { 115 b.button_release (button, x, y); 116 } 117 } 118 } 119 120 } 121