2 Copyright 2009 by Krzysztof Foltman
10 public class LED
: DrawingArea
{
12 private bool _led_state
= false;
18 public bool led_state
{
30 // Set favored widget size
31 set_size_request (12, 12);
34 public void set_rgb(float _r
, float _g
, float _b
)
42 public void get_rgb(ref float _r
, ref float _g
, ref float _b
)
49 /* Widget is asked to draw itself */
50 public override bool expose_event (Gdk
.EventExpose event
) {
52 // Create a Cairo context
53 var cr
= Gdk
.cairo_create (this
.window
);
55 // Set clipping area in order to avoid unnecessary drawing
56 cr
.rectangle (event
.area
.x
, event
.area
.y
,
57 event
.area
.width
, event
.area
.height
);
60 set_source_from_color(cr
, style
.bg
[Gtk
.StateType
.NORMAL
]);
61 cr
.rectangle(0, 0, allocation
.width
, allocation
.height
);
64 int xc
= allocation
.width
/ 2;
65 int yc
= allocation
.height
/ 2;
67 int diameter
= (allocation
.width
< allocation
.height ? allocation
.width
: allocation
.height
) - 1;
69 Cairo
.Pattern pt
= new Cairo
.Pattern
.radial(xc
, yc
+ diameter
/ 4, 0, xc
, yc
, diameter
/ 2);
70 double m1
= _led_state ?
1.0 : 0.25;
71 double m2
= _led_state ?
0.75 : 0.2;
72 double m3
= _led_state ?
0.25 : 0.1;
74 pt
.add_color_stop_rgb(0.0, r
* m1
, g
* m1
, b
* m1
);
75 pt
.add_color_stop_rgb(0.5, r
* m2
, g
* m2
, b
* m2
);
76 pt
.add_color_stop_rgb(1.0, r
* m3
, g
* m3
, b
* m3
);
78 cr
.arc(xc
, yc
, diameter
/ 2, 0, 2 * Math
.PI
);
79 cr
.set_line_join(Cairo
.LineJoin
.BEVEL
);
83 cr
.arc(xc
, yc
, diameter
/ 2, 0, 2 * Math
.PI
);
84 cr
.set_line_width(0.5);
85 cr
.set_source_rgba (r
* m4
, g
* m4
, b
* m4
, 0.5);
92 } // namespace Prolooks