.
1 /*
2 Copyright (C) 2012 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 MenuAction : GLib.Object {
20 public string label;
21 public signal void action (MenuAction a);
22 public int index = -1;
23 public bool has_delete_button = true;
24 public double width = 100;
25 public Text text;
26
27 bool selected = false;
28
29 public MenuAction (string label) {
30 this.label = label;
31 }
32
33 public void set_selected (bool s) {
34 selected = s;
35 }
36
37 public virtual void draw (double x, double y, Context cr) {
38 if (selected) {
39 cr.save ();
40 Theme.color (cr, "Highlighted 1");
41 cr.rectangle (x - 2, y - 12, width, 15);
42 cr.fill_preserve ();
43 cr.stroke ();
44 cr.restore ();
45 }
46
47 if (has_delete_button) {
48 cr.save ();
49 Theme.color (cr, "Foreground 1");
50 cr.move_to (x + width - 10, y - 2);
51 cr.line_to (x + width - 10 - 5, y - 2 - 5);
52 cr.move_to (x + width - 10 - 5, y - 2);
53 cr.line_to (x + width - 10, y - 2 - 5);
54 cr.set_line_width (1);
55 cr.stroke ();
56 cr.restore ();
57 }
58
59 text = new Text (label);
60 Theme.text_color (text, "Foreground 1");
61 text.draw_at_baseline (cr, x, y);
62 }
63 }
64
65 }
66