ValueDisplay: new widget for displaying values, something like a fancy label
[libprolooks.git] / prolooks / ValueDisplay.vala
blob63c06edd25a92e6c38476a82a73e786ba80d30a8
1 /*
2 Copyright 2009 by Hans Baier
3 License: LGPLv2+
4 */
6 using Gtk;
8 namespace Prolooks {
10 public class ValueDisplay : DrawingArea {
12 private string _text = "";
13 public string text {
14 set {
15 if (_text != value) {
16 _text = value;
17 queue_draw ();
20 get {
21 return _text;
25 public bool show_matrix {get; set;}
27 private int width = 36;
28 private int height = 16;
30 construct {
31 set_size_request (width, height);
32 show_matrix = true;
35 /* Widget is asked to draw itself */
36 public override bool expose_event (Gdk.EventExpose event) {
37 //Gdk.Color test_color = color_from_string ("#ff0000");
39 width = allocation.width;
40 height = allocation.height;
42 // Create a Cairo context
43 var cr = Gdk.cairo_create (this.window);
45 // Set clipping area in order to avoid unnecessary drawing
46 cr.rectangle (event.area.x, event.area.y,
47 event.area.width, event.area.height);
48 cr.clip ();
50 DisplayBase.outer_rim_for_display (cr, 0, 0, width, height, style.bg[Gtk.StateType.SELECTED]);
52 cr.translate (3, 3);
54 var inner_width = width - 6;
55 var inner_height = height - 6;
57 if (show_matrix) {
58 DisplayBase.dot_matrix (cr, 0.5, 0.5, inner_width, inner_height, DisplayBase.matrix_dot_color ());
61 DisplayBase.lcd(cr, inner_width, inner_height, 3.0);
63 // draw text
64 double font_size = inner_height;
66 cr.select_font_face ("FreeSans", Cairo.FontSlant.NORMAL, Cairo.FontWeight.NORMAL);
67 cr.set_font_size (font_size);
68 Cairo.TextExtents ext = Cairo.TextExtents();
69 cr.text_extents (text, ref ext);
70 double x = (inner_width - ext.x_advance) / 2.0;
71 double y = inner_height * 0.85;
73 DisplayBase.text (cr, text, x, y, font_size);
75 DisplayBase.reflection(cr, inner_width, inner_height);
77 return false;
81 } // namespace Prolooks