Remove the overlay numbers as they caused theme drawing issues.
[gmpc.git] / src / Widgets / gmpc-sidebar-view.vala
blob401693a9288f7be7ae0e33d83071ab3675e3b920
2 /* Gnome Music Player Client (GMPC)
3 * Copyright (C) 2004-2012 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 private CellRendererPixbuf cr_pb = new Gtk.CellRendererPixbuf();
32 private CellRendererText cr_text = new Gtk.CellRendererText();
33 public string icon_name
35 set{
36 cr_pb.icon_name = value;
39 public string stock_id
41 set{
42 cr_pb.stock_id = value;
46 public int weight { set { cr_text.weight = value;}}
47 public bool weight_set { set { cr_text.weight_set = value;}}
49 public uint stock_size
51 get {
52 return cr_pb.stock_size;
54 set {
55 cr_pb.stock_size = value;
58 public string text
60 set {
61 cr_text.text = value;
64 public bool show_text
66 set;
67 get;
68 default = true;
70 public int image_width
72 set;
73 get;
74 default = 16;
76 public new float xalign
78 set{
79 cr_pb.xalign = value;
82 /* dumb constructor */
83 public MyCellRenderer () {}
85 public override Gtk.SizeRequestMode get_request_mode()
87 return Gtk.SizeRequestMode.CONSTANT_SIZE;
90 /* get_size method, always request a 50x50 area */
91 public override void get_size (Gtk.Widget widget,
92 Gdk.Rectangle? cell_area,
93 out int x_offset,
94 out int y_offset,
95 out int width,
96 out int height)
98 int x_o=0;
99 int y_o =0;
100 int w=0;
101 int h=0;
102 int tx_o=0;
103 int ty_o =0;
104 int tw=0;
105 int th=0;
107 cr_pb.get_size(widget, null, out x_o, out y_o, out w, out h);
108 if(show_text)
109 cr_text.get_size(widget, null, out tx_o, out ty_o, out tw, out th);
110 /* The bindings miss the nullable property, so we need to check if the
111 * values are null.
113 if (&x_offset != null) x_offset = 0;
114 if (&y_offset != null) y_offset = 0;
115 if (&width != null) width = image_width+6+tw;
116 if (&height != null) height = int.max(h, th);
117 return;
120 /* render method */
121 public override void render (Cairo.Context ct,
122 Gtk.Widget widget,
123 Gdk.Rectangle background_area,
124 Gdk.Rectangle cell_area,
125 Gtk.CellRendererState flags)
127 int x_o=0;
128 int y_o =0;
129 int w=0;
130 int h=0;
131 cr_pb.get_size(widget, null, out x_o, out y_o, out w, out h);
132 Gdk.Rectangle ca = Gdk.Rectangle();
133 ca.x = cell_area.x;
134 ca.y = cell_area.y;
135 ca.width = w+6;//cell_area.height;
136 ca.height = cell_area.height;
138 if(cr_pb.icon_name != null || cr_pb.stock_id != null )
140 cr_pb.render(ct, widget, background_area, ca, flags);
142 ca.x+=6+image_width;
143 ca.width = cell_area.width-ca.width;
145 else
147 ca.width = cell_area.width;
149 if(show_text)
150 cr_text.render(ct, widget, background_area, ca, flags);
152 // Draw arrow.
154 if((flags&Gtk.CellRendererState.SELECTED) == Gtk.CellRendererState.SELECTED)
156 double cax = background_area.width*0.9;
157 double bld = background_area.width*0.1;
158 if(!show_text) cax = background_area.x+image_width+3;
160 ct.move_to(background_area.x+cax, background_area.y);
161 ct.line_to(background_area.x+cax+bld, background_area.y+background_area.height/2);
162 ct.line_to(background_area.x+cax, background_area.y+background_area.height);
163 ct.line_to(background_area.x+cax+bld, background_area.y+background_area.height);
164 ct.line_to(background_area.x+cax+bld, background_area.y);
165 ct.line_to(background_area.x+cax, background_area.y);
166 Gdk.cairo_set_source_color(ct, widget.style.bg[Gtk.StateType.NORMAL]);
167 ct.fill();
169 return;