1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
/***
BEGIN LICENSE
Copyright (C) 2013 Tom Beckmann
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License version 3, as published
by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranties of
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>
END LICENSE
***/
using Clutter;
public class ShadowedLabel : Actor {
Granite.Drawing.BufferSurface buffer;
Gdk.RGBA text_color;
Gdk.RGBA shadow_color;
string _label = "";
public string label {
get {
return _label;
} set {
if (value == _label)
return;
_label = value;
var l = new Pango.Layout (Pango.cairo_font_map_get_default ().create_context ());
l.set_markup (label, -1);
Pango.Rectangle ink, log;
l.get_extents (out ink, out log);
width = (log.width / Pango.SCALE + 20);
height = (log.height / Pango.SCALE) + 6;
}
}
public ShadowedLabel (string _label, string text_color = "white", string shadow_color = "black") {
this.text_color.parse (text_color);
this.shadow_color.parse (shadow_color);
content = new Canvas ();
(content as Canvas).draw.connect (draw);
notify["width"].connect (() => {(content as Canvas).set_size ((int) width, (int) height); });
notify["height"].connect (() => {(content as Canvas).set_size ((int) width, (int) height); });
label = _label;
}
bool draw (Cairo.Context cr) {
cr.set_operator (Cairo.Operator.CLEAR);
cr.paint ();
cr.set_operator (Cairo.Operator.OVER);
buffer = new Granite.Drawing.BufferSurface ((int) width, (int) height);
var layout = Pango.cairo_create_layout (buffer.context);
layout.set_markup (label, -1);
buffer.context.move_to (0, 1);
buffer.context.set_source_rgba (shadow_color.red, shadow_color.green,
shadow_color.blue, shadow_color.alpha);
Pango.cairo_show_layout (buffer.context, layout);
buffer.exponential_blur (3);
buffer.context.move_to (0, 0);
buffer.context.set_source_rgba (text_color.red, text_color.green,
text_color.blue, text_color.alpha);
Pango.cairo_show_layout (buffer.context, layout);
cr.set_source_surface (buffer.surface, 0, 0);
cr.paint ();
return true;
}
}
public class ShadowedLink : ShadowedLabel {
string uri;
public ShadowedLink (string label, string uri, string text_color = "white", string shadow_color = "black") {
base (label, text_color, shadow_color);
this.uri = uri;
reactive = true;
button_release_event.connect (on_click);
}
private bool on_click () {
try {
AppInfo.launch_default_for_uri(this.uri, null);
} catch (Error e) {
warning("Could not open uri: " + this.uri);
}
return true;
}
}
|