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.
Draw filled open paths
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 question = new TextArea (font_size); 32 question.min_width = 300; 33 question.min_height = font_size; 34 question.set_editable (false); 35 question.draw_border = false; 36 question.text_color = Theme.get_color ("Text Tool Box"); 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 print (@"question.get_height (): $(question.get_height ())\n"); 67 68 foreach (Button button in buttons) { 69 button.widget_x += center; 70 } 71 72 height = h + margin + margin_small; 73 74 if (buttons.size > 0) { 75 height += buttons.get (0).get_height (); 76 } 77 78 cy = (allocation.height - height) / 2.0; 79 80 foreach (Button button in buttons) { 81 button.widget_y = cy + h + margin_small; 82 } 83 84 question.widget_y = cy + margin; 85 } 86 87 public override void draw (Context cr) { 88 double cx, cy; 89 90 cx = (allocation.width - width) / 2.0; 91 cy = (allocation.height - height) / 2.0; 92 93 cr.save (); 94 Theme.color (cr, "Dialog Shadow"); 95 cr.rectangle (0, 0, allocation.width, allocation.height); 96 cr.fill (); 97 cr.restore (); 98 99 cr.save (); 100 Theme.color (cr, "Dialog Background"); 101 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 102 cr.fill (); 103 cr.restore (); 104 105 cr.save (); 106 Theme.color (cr, "Button Border 4"); 107 cr.set_line_width (1); 108 draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 109 cr.stroke (); 110 cr.restore (); 111 112 foreach (Button button in buttons) { 113 button.draw (cr); 114 } 115 116 question.draw (cr); 117 } 118 119 public override void button_press (uint button, double x, double y) { 120 foreach (Button b in buttons) { 121 b.button_press (button, x, y); 122 } 123 } 124 125 public override void button_release (uint button, double x, double y) { 126 foreach (Button b in buttons) { 127 b.button_release (button, x, y); 128 } 129 } 130 } 131 132 } 133