2
* Copyright (c) 2011 Lucas Baudin <xapantu@gmail.com>
4
* Marlin is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or (at your option) any later version.
9
* Marlin is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public
15
* License along with this program; see the file COPYING. If not,
16
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
21
public class Marlin.View.Chrome.BreadcrumbsElement : Object {
23
private static const int ICON_MARGIN = 3;
25
public double offset = 0;
26
public double last_height = 0;
27
public double text_width = -1;
28
public double text_height = -1;
29
public double max_width = -1;
33
return text_width + padding.left + padding.right + last_height / 2;
36
public double real_width {
38
return (max_width > 0 ? max_width : text_width) +
39
padding.left + padding.right + last_height / 2;
42
public bool hidden = false;
43
public bool display = true;
44
public bool display_text = true;
45
public string? text_displayed = null;
47
public bool pressed = false;
48
private Gtk.Border padding = Gtk.Border ();
49
private Gdk.Pixbuf icon = null;
51
public BreadcrumbsElement (string text_) {
53
text_displayed = Uri.unescape_string (text);
56
public void set_icon (Gdk.Pixbuf icon_) {
60
public double draw (Cairo.Context cr, double x, double y, double height, Gtk.StyleContext button_context, Gtk.Widget widget) {
61
var state = button_context.get_state ();
63
state |= Gtk.StateFlags.ACTIVE;
65
padding = button_context.get_padding (state);
66
double line_width = cr.get_line_width ();
71
cr.set_source_rgb (0,0,0);
72
string? text = text_displayed ?? this.text;
73
Pango.Layout layout = widget.create_pango_layout (text ?? "");
76
computetext_width (layout);
77
} else if (!display_text) {
78
text_width = icon.get_width () + ICON_MARGIN;
80
computetext_width (layout);
81
text_width += icon.get_width () + 2 * ICON_MARGIN;
85
layout.set_width (Pango.units_from_double (max_width));
86
layout.set_ellipsize (Pango.EllipsizeMode.MIDDLE);
90
cr.move_to (x - height/2, y);
91
cr.line_to (x, y + height/2);
92
cr.line_to (x - height/2, y + height);
93
cr.line_to (x + text_width + padding.left, y + height);
94
cr.line_to (x + text_width + height/2 + padding.left, y + height/2);
95
cr.line_to (x + text_width + padding.left, y);
102
double text_width = max_width > 0 ? max_width : this.text_width;
104
var left_x = base_x - height / 2 + line_width;
105
var right_x = base_x + text_width + padding.left + padding.right;
106
var arrow_right_x = right_x + height / 2;
107
var top_y = y + padding.top - line_width;
108
var bottom_y = y + height - padding.bottom + line_width;
109
var arrow_y = y + height / 2;
110
cr.move_to (left_x, top_y);
111
cr.line_to (base_x, arrow_y);
112
cr.line_to (left_x, bottom_y);
113
cr.line_to (right_x, bottom_y);
114
cr.line_to (arrow_right_x, arrow_y);
115
cr.line_to (right_x, top_y);
119
button_context.save ();
120
button_context.set_state (Gtk.StateFlags.ACTIVE);
121
button_context.render_background (cr, left_x, y, text_width + height + padding.left + padding.right + 2 * line_width, height);
122
button_context.render_frame (cr, 0, padding.top - line_width, widget.get_allocated_width (), height - line_width);
123
button_context.restore ();
128
x -= Math.sin (offset*Math.PI_2) * width;
130
button_context.render_layout (cr, x,
131
y + height/2 - text_height/2, layout);
132
} else if (!display_text) {
133
button_context.render_icon (cr, icon, x + ICON_MARGIN,
134
y + height/2 - icon.get_height ()/2);
136
button_context.render_icon (cr, icon, x + ICON_MARGIN,
137
y + height/2 - icon.get_height ()/2);
138
button_context.render_layout (cr, x + icon.get_width () + 2 * ICON_MARGIN,
139
y + height/2 - text_height/2, layout);
142
x += padding.right + (max_width > 0 ? max_width : text_width);
144
/* Draw the separator */
146
cr.translate (x - height / 4, y + height / 2);
147
cr.rectangle (0, -height / 2 + line_width, height, height - 2 * line_width);
149
cr.rotate (Math.PI_4);
150
button_context.save ();
151
button_context.add_class ("noradius-button");
153
button_context.set_state (Gtk.StateFlags.ACTIVE);
155
button_context.render_frame (cr, -height / 2, -height / 2, height, height);
156
button_context.restore ();
164
private void computetext_width (Pango.Layout pango) {
165
int text_width, text_height;
166
pango.get_size (out text_width, out text_height);
167
this.text_width = Pango.units_to_double (text_width);
168
this.text_height = Pango.units_to_double (text_height);