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
|
using Gtk;
using Cairo;
namespace Lsc.Widgets {
public class RoundBox : EventBox {
private Cairo.Context cr;
private Box container;
private enum Colors {
BACKGROUND,
BORDER
}
public RoundBox (Orientation or, int spacing) {
set_has_window(false);
container = new Box(or, spacing);
add(container);
}
public void pack_start (Widget widget, bool expand, bool fill, int space) {
container.pack_start(widget, expand, fill, space);
}
private void draw_rounded_rectangle (Colors rgb, uint x, uint y, int width, int height, double radius) {
Gdk.RGBA color;
bool res;
if (rgb == Colors.BACKGROUND)
res = get_style_context().lookup_color("base_color", out color);
else
color = { 0.8, 0.8, 0.8, 1 };
res = true;
if (res == false) {
color = { 0, 0, 0, 0 };
}
Gdk.cairo_set_source_rgba (cr, color);
cr.new_path();
cr.move_to (x + radius, y);
cr.arc (width - x - radius, y + radius, radius, Math.PI * 1.5, Math.PI * 2);
cr.arc (width - x - radius, height - y - radius, radius, 0, Math.PI * 0.5);
cr.arc (x + radius, height - y - radius, radius, Math.PI * 0.5, Math.PI);
cr.arc (x + radius, y + radius, radius, Math.PI, Math.PI * 1.5);
cr.close_path ();
cr.fill();
}
public override bool draw (Cairo.Context cr) {
this.cr = cr;
int width = get_allocated_width ();
int height = get_allocated_height ();
double arc_radius = 10.0;
draw_rounded_rectangle(Colors.BORDER, 0, 0, width, height, arc_radius);
draw_rounded_rectangle(Colors.BACKGROUND, 1, 1, width, height, arc_radius-1);
return base.draw(cr);
}
public override void size_allocate (Allocation allocation) {
base.size_allocate (allocation);
}
}
}
|