.
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 DropMenu.Selected action;
22 public DropMenu? parent = null;
23 public int index = -1;
24 public bool has_delete_button = true;
25
26 bool selected = false;
27 static ImageSurface? delete_button = null;
28
29 public MenuAction (string label) {
30 this.label = label;
31
32 if (delete_button == null) {
33 delete_button = Icons.get_icon ("delete_menu_item.png");
34 }
35 }
36
37 public void set_selected (bool s) {
38 selected = s;
39 }
40
41 public virtual void draw (double x, double y, Context cr) {
42 ImageSurface img;
43
44 if (selected) {
45 cr.save ();
46 Theme.color (cr, "Selected Menu Item");
47 cr.rectangle (x - 2, y - 12, 93, 15);
48 cr.fill_preserve ();
49 cr.stroke ();
50 cr.restore ();
51 }
52
53 if (has_delete_button && delete_button != null) {
54 img = (!) delete_button;
55 cr.save ();
56 cr.set_source_surface (img, x - img.get_width () / 2 + 82, y - img.get_height () / 2 - 5);
57 cr.paint ();
58 cr.restore ();
59 }
60
61 cr.save ();
62
63 Theme.color (cr, "Foreground 1");
64
65 cr.set_font_size (12);
66 cr.select_font_face ("Cantarell", FontSlant.NORMAL, FontWeight.NORMAL);
67
68 cr.move_to (x, y);
69
70 cr.show_text (label);
71 cr.restore ();
72 }
73 }
74
75 }
76