-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcellrendererstar.vala
49 lines (40 loc) · 1.76 KB
/
cellrendererstar.vala
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
/* vim: set cin et sw=4 : */
class CellRendererStar : Gtk.CellRenderer {
public bool starred { get; set; }
public RGB? color { get; set; }
public signal void toggled(string path);
public CellRendererStar(int width, int height) {
GLib.Object(width: width, height: height, mode: Gtk.CellRendererMode.ACTIVATABLE);
}
public override void get_size(Gtk.Widget widget, Gdk.Rectangle? cell_area, out int x_offset, out int y_offset, out int width, out int height) {
x_offset = 0;
y_offset = 0;
width = this.width;
height = this.height;
}
public override void render(Cairo.Context ctx, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
ctx.translate(cell_area.x+cell_area.width/2.0, cell_area.y+cell_area.height/2.0);
ctx.scale(cell_area.width/3.5, cell_area.height/3.5);
for (int i = 0; i < 5; i++) {
ctx.line_to(Math.sin(i*0.4*Math.PI), -Math.cos(i*0.4*Math.PI));
ctx.line_to(Math.sin((i*0.4+0.2)*Math.PI)/2.5, -Math.cos((i*0.4+0.2)*Math.PI)/2.5);
}
ctx.close_path();
if (starred) {
var path = ctx.copy_path();
if (color == null)
ctx.set_source_rgba(1.0,1.0,0.0,1.0);
else
ctx.set_source_rgba(color.red, color.green, color.blue, 1.0);
ctx.fill();
ctx.append_path(path);
}
ctx.set_line_width(0.1);
ctx.set_source_rgba(0.0,0.0,0.0,0.8);
ctx.stroke();
}
public override bool activate(Gdk.Event event, Gtk.Widget widget, string path, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
toggled(path);
return true;
}
}