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);
36 if (value
!= null & value
!= "") {
37 gdk_color_to_cairo_color (color_from_string (value
), ref r
, ref g
, ref b
);
45 public void set_rgb(double _r
, double _g
, double _b
)
53 public void get_rgb(ref double _r
, ref double _g
, ref double _b
)
60 /* Widget is asked to draw itself */
61 public override bool expose_event (Gdk
.EventExpose event
) {
63 // Create a Cairo context
64 var cr
= Gdk
.cairo_create (this
.window
);
66 // Set clipping area in order to avoid unnecessary drawing
67 cr
.rectangle (event
.area
.x
, event
.area
.y
,
68 event
.area
.width
, event
.area
.height
);
71 set_source_color(cr
, style
.bg
[Gtk
.StateType
.NORMAL
]);
72 cr
.rectangle(0, 0, allocation
.width
, allocation
.height
);
75 int xc
= allocation
.width
/ 2;
76 int yc
= allocation
.height
/ 2;
78 int diameter
= (allocation
.width
< allocation
.height ? allocation
.width
: allocation
.height
) - 1;
80 Cairo
.Pattern pt
= new Cairo
.Pattern
.radial(xc
, yc
+ diameter
/ 4, 0, xc
, yc
, diameter
/ 2);
81 double m1
= _led_state ?
1.0 : 0.25;
82 double m2
= _led_state ?
0.75 : 0.2;
83 double m3
= _led_state ?
0.25 : 0.1;
85 pt
.add_color_stop_rgb(0.0, r
* m1
, g
* m1
, b
* m1
);
86 pt
.add_color_stop_rgb(0.5, r
* m2
, g
* m2
, b
* m2
);
87 pt
.add_color_stop_rgb(1.0, r
* m3
, g
* m3
, b
* m3
);
89 cr
.arc(xc
, yc
, diameter
/ 2, 0, 2 * Math
.PI
);
90 cr
.set_line_join(Cairo
.LineJoin
.BEVEL
);
94 cr
.arc(xc
, yc
, diameter
/ 2, 0, 2 * Math
.PI
);
95 cr
.set_line_width(0.5);
96 cr
.set_source_rgba (r
* m4
, g
* m4
, b
* m4
, 0.5);
103 } // namespace Prolooks