2 Copyright 2009 by Hans Baier
10 public class ValueDisplay
: DrawingArea
{
11 private Cairo
.Surface? cache_surface
= null;
13 private string _text
= "";
26 private bool _show_matrix
= true;
27 public bool show_matrix
{
28 get { return _show_matrix
; }
36 private int width
= 36;
37 private int height
= 16;
40 set_size_request (width
, height
);
43 /* Widget is asked to draw itself */
44 public override bool expose_event (Gdk
.EventExpose event
) {
45 //Gdk.Color test_color = color_from_string ("#ff0000");
47 if (width
!= allocation
.width
|| height
!= allocation
.height
) {
48 width
= allocation
.width
;
49 height
= allocation
.height
;
52 var inner_width
= width
- 6;
53 var inner_height
= height
- 6;
55 // Create a Cairo context
56 var cr
= Gdk
.cairo_create (this
.window
);
58 if (cache_surface
== null) {
59 cache_surface
= new Cairo
.Surface
.similar (cr
.get_target (),
60 Cairo
.Content
.COLOR_ALPHA
,
64 Cairo
.Context cache_cr
= new Cairo
.Context ( cache_surface
);
66 DisplayBase
.outer_rim_for_display (cache_cr
, 0, 0, width
, height
, style
.bg
[Gtk
.StateType
.SELECTED
]);
68 cache_cr
.translate (3, 3);
70 DisplayBase
.lcd(cache_cr
, inner_width
, inner_height
, 3.0);
73 //especially the matrix is expensive for large displays
74 DisplayBase
.dot_matrix (cache_cr
, 0.5, 0.5, inner_width
, inner_height
, DisplayBase
.matrix_dot_color ());
78 // Set clipping area in order to avoid unnecessary drawing
79 cr
.rectangle (event
.area
.x
, event
.area
.y
,
80 event
.area
.width
, event
.area
.height
);
83 cr
.set_source_surface (cache_surface
, 0, 0);
89 double font_size
= inner_height
;
91 cr
.select_font_face ("FreeSans", Cairo
.FontSlant
.NORMAL
, Cairo
.FontWeight
.NORMAL
);
92 cr
.set_font_size (font_size
);
93 Cairo
.TextExtents ext
= Cairo
.TextExtents();
94 cr
.text_extents (text
, ref ext
);
95 double x
= (inner_width
- ext
.x_advance
) / 2.0;
96 double y
= inner_height
* 0.85;
98 DisplayBase
.text (cr
, text
, x
, y
, font_size
);
100 DisplayBase
.reflection(cr
, inner_width
, inner_height
);
106 } // namespace Prolooks