Highlight keybinding number when hitting the alt key
[gmpc.git] / src / Widgets / gmpc-sidebar-view.vala
blob2526c6616f477b132412d02ff4c20cea4123502c
2 /* Gnome Music Player Client (GMPC)
3 * Copyright (C) 2004-2011 Qball Cow <qball@gmpclient.org>
4 * Project homepage: http://gmpclient.org/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 using Config;
22 using Gtk;
23 using Gmpc;
24 using Cairo;
26 private const bool use_transition_sbv = Gmpc.use_transition;
27 private const string some_unique_name_sbv = Config.VERSION;
29 public class MyCellRenderer : Gtk.CellRenderer
31 public bool show_number { set; get; default=false;}
32 public int number { set; get; default=0;}
33 private CellRendererPixbuf cr_pb = new Gtk.CellRendererPixbuf();
34 private CellRendererText cr_text = new Gtk.CellRendererText();
35 public string icon_name {
36 set{
37 cr_pb.icon_name = value;
41 public int weight { set { cr_text.weight = value;}}
42 public bool weight_set { set { cr_text.weight_set = value;}}
44 public uint stock_size {
45 get {
46 return cr_pb.stock_size;
48 set {
49 cr_pb.stock_size = value;
52 public string text {
53 set {
54 cr_text.text = value;
57 public bool show_text
59 set;
60 get;
61 default = true;
63 public int image_width {
64 set;
65 get;
66 default = 16;
68 public new float xalign {
69 set{
70 cr_pb.xalign = value;
73 /* dumb constructor */
74 public MyCellRenderer () {}
76 /* get_size method, always request a 50x50 area */
77 public override void get_size (Gtk.Widget widget,
78 Gdk.Rectangle? cell_area,
79 out int x_offset,
80 out int y_offset,
81 out int width,
82 out int height)
84 int x_o=0;
85 int y_o =0;
86 int w=0;
87 int h=0;
88 int tx_o=0;
89 int ty_o =0;
90 int tw=0;
91 int th=0;
93 cr_pb.get_size(widget, null, out x_o, out y_o, out w, out h);
94 if(show_text)
95 cr_text.get_size(widget, null, out tx_o, out ty_o, out tw, out th);
96 /* The bindings miss the nullable property, so we need to check if the
97 * values are null.
99 if (&x_offset != null) x_offset = 0;
100 if (&y_offset != null) y_offset = 0;
101 if (&width != null) width = image_width+6+tw;
102 if (&height != null) height = int.max(h, th);
103 return;
106 /* render method */
107 public override void render (Gdk.Window window,
108 Gtk.Widget widget,
109 Gdk.Rectangle background_area,
110 Gdk.Rectangle cell_area,
111 Gdk.Rectangle expose_area,
112 Gtk.CellRendererState flags)
114 int x_o=0;
115 int y_o =0;
116 int w=0;
117 int h=0;
118 cr_pb.get_size(widget, null, out x_o, out y_o, out w, out h);
119 Gdk.Rectangle ca = Gdk.Rectangle();
120 ca.x = cell_area.x;
121 ca.y = cell_area.y;
122 ca.width = image_width+6;//cell_area.height;
123 ca.height = cell_area.height;
125 if(cr_pb.icon_name != null )
127 cr_pb.render(window, widget, background_area, ca, expose_area, flags);
129 ca.x+=6+image_width;
130 ca.width-=6+image_width;
132 if(show_text)
133 cr_text.render(window, widget, background_area, ca, expose_area, flags);
135 if(show_number)
137 int pw,ph;
138 var l = widget.create_pango_layout("%0i".printf(number));
139 var ct = Gdk.cairo_create(window);
140 l.get_pixel_size(out pw, out ph);
142 ct.set_source_rgb(0.8,0.2,0.2);
143 ct.rectangle(cell_area.x+3, cell_area.y+cell_area.height/2-ph/2, pw+4, ph);
144 ct.fill();
146 ct.move_to(cell_area.x+2+3, cell_area.y+cell_area.height/2-ph/2);
147 ct.set_source_rgb(1,1,1);
148 Pango.cairo_show_layout(ct, l);
149 ct.stroke();
151 return;