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