Fix typo: Similar Artist -> Similar Artists
[gmpc.git] / src / Widgets / gmpc-sidebar-view.vala
blob3af430065acd1a0634aeb4da104fd37f4810a31a
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;
65 private bool _show_text = true;
66 public bool show_text
68 set {
69 _show_text = value;
71 get{
72 return _show_text;
75 public int image_width
77 set;
78 get;
79 default = 16;
81 public new float xalign
83 set{
84 cr_pb.xalign = value;
87 /* dumb constructor */
88 public MyCellRenderer () {}
90 public override Gtk.SizeRequestMode get_request_mode()
92 return Gtk.SizeRequestMode.CONSTANT_SIZE;
95 public override void get_preferred_width(Gtk.Widget widget,
96 out int min_size,
97 out int nat_size)
100 int ms = 0, ns = 0;
101 cr_pb.get_preferred_width(widget, out ms, out ns);
102 if(_show_text)
104 int tms = 0, tns =0;
105 cr_text.get_preferred_width(widget, out tms, out tns);
106 ms+= tms+6;
107 ns+= tns+6;
109 if(&min_size != null) min_size = ms;
110 if(&nat_size != null) nat_size = ns;
111 stdout.printf("get preferred width: %d %d\n", ms, ns);
114 /* get_size method, always request a 50x50 area */
115 public override void get_size (Gtk.Widget widget,
116 Gdk.Rectangle? cell_area,
117 out int x_offset,
118 out int y_offset,
119 out int width,
120 out int height)
122 int x_o=0;
123 int y_o =0;
124 int w=0;
125 int h=0;
126 int tx_o=0;
127 int ty_o =0;
128 int tw=0;
129 int th=0;
130 stdout.printf("get size\n");
132 cr_pb.get_size(widget, null, out x_o, out y_o, out w, out h);
133 if(show_text)
134 cr_text.get_size(widget, null, out tx_o, out ty_o, out tw, out th);
135 /* The bindings miss the nullable property, so we need to check if the
136 * values are null.
138 if (&x_offset != null) x_offset = 0;
139 if (&y_offset != null) y_offset = 0;
140 if (&width != null) width = image_width+6+tw;
141 if (&height != null) height = int.max(h, th);
142 return;
145 /* render method */
146 public override void render (Cairo.Context ct,
147 Gtk.Widget widget,
148 Gdk.Rectangle background_area,
149 Gdk.Rectangle cell_area,
150 Gtk.CellRendererState flags)
152 int x_o=0;
153 int y_o =0;
154 int w=0;
155 int h=0;
156 cr_pb.get_size(widget, null, out x_o, out y_o, out w, out h);
157 Gdk.Rectangle ca = Gdk.Rectangle();
158 ca.x = cell_area.x;
159 ca.y = cell_area.y;
160 ca.width = w+6;//cell_area.height;
161 ca.height = cell_area.height;
163 if(cr_pb.icon_name != null || cr_pb.stock_id != null )
165 cr_pb.render(ct, widget, background_area, ca, flags);
167 ca.x+=6+image_width;
168 ca.width = cell_area.width-ca.width;
170 else
172 ca.width = cell_area.width;
174 if(_show_text)
175 cr_text.render(ct, widget, background_area, ca, flags);
177 // Draw arrow.
179 if((flags&Gtk.CellRendererState.SELECTED) == Gtk.CellRendererState.SELECTED)
181 double cax = background_area.width*0.9;
182 double bld = background_area.width*0.1;
183 if(!show_text) cax = background_area.x+image_width+3;
185 ct.move_to(background_area.x+cax, background_area.y);
186 ct.line_to(background_area.x+cax+bld, background_area.y+background_area.height/2);
187 ct.line_to(background_area.x+cax, background_area.y+background_area.height);
188 ct.line_to(background_area.x+cax+bld, background_area.y+background_area.height);
189 ct.line_to(background_area.x+cax+bld, background_area.y);
190 ct.line_to(background_area.x+cax, background_area.y);
191 Gdk.cairo_set_source_color(ct, widget.style.bg[Gtk.StateType.NORMAL]);
192 ct.fill();
194 return;