From 94d00c93b021aa611f32e10553a078c33360f67e Mon Sep 17 00:00:00 2001 From: Hans Baier Date: Sat, 28 Mar 2009 08:29:01 +0700 Subject: [PATCH] KnobWithDisplay: added --- prolooks/KnobWithDisplay | 82 +++++++++++++++++++++++++++++++++++++++++++ prolooks/KnobWithDisplay.vala | 37 +++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 prolooks/KnobWithDisplay create mode 100644 prolooks/KnobWithDisplay.vala diff --git a/prolooks/KnobWithDisplay b/prolooks/KnobWithDisplay new file mode 100644 index 0000000..63c06ed --- /dev/null +++ b/prolooks/KnobWithDisplay @@ -0,0 +1,82 @@ +/* + Copyright 2009 by Hans Baier + License: LGPLv2+ +*/ + +using Gtk; + +namespace Prolooks { + +public class ValueDisplay : DrawingArea { + + private string _text = ""; + public string text { + set { + if (_text != value) { + _text = value; + queue_draw (); + } + } + get { + return _text; + } + } + + public bool show_matrix {get; set;} + + private int width = 36; + private int height = 16; + + construct { + set_size_request (width, height); + show_matrix = true; + } + + /* Widget is asked to draw itself */ + public override bool expose_event (Gdk.EventExpose event) { + //Gdk.Color test_color = color_from_string ("#ff0000"); + + width = allocation.width; + height = allocation.height; + + // Create a Cairo context + var cr = Gdk.cairo_create (this.window); + + // Set clipping area in order to avoid unnecessary drawing + cr.rectangle (event.area.x, event.area.y, + event.area.width, event.area.height); + cr.clip (); + + DisplayBase.outer_rim_for_display (cr, 0, 0, width, height, style.bg[Gtk.StateType.SELECTED]); + + cr.translate (3, 3); + + var inner_width = width - 6; + var inner_height = height - 6; + + if (show_matrix) { + DisplayBase.dot_matrix (cr, 0.5, 0.5, inner_width, inner_height, DisplayBase.matrix_dot_color ()); + } + + DisplayBase.lcd(cr, inner_width, inner_height, 3.0); + + // draw text + double font_size = inner_height; + + cr.select_font_face ("FreeSans", Cairo.FontSlant.NORMAL, Cairo.FontWeight.NORMAL); + cr.set_font_size (font_size); + Cairo.TextExtents ext = Cairo.TextExtents(); + cr.text_extents (text, ref ext); + double x = (inner_width - ext.x_advance) / 2.0; + double y = inner_height * 0.85; + + DisplayBase.text (cr, text, x, y, font_size); + + DisplayBase.reflection(cr, inner_width, inner_height); + + return false; + } +} + +} // namespace Prolooks + diff --git a/prolooks/KnobWithDisplay.vala b/prolooks/KnobWithDisplay.vala new file mode 100644 index 0000000..4d98550 --- /dev/null +++ b/prolooks/KnobWithDisplay.vala @@ -0,0 +1,37 @@ +/* + Copyright 2009 by Hans Baier + License: LGPLv2+ +*/ + +using Gtk; + +namespace Prolooks { + +public class KnobWithDisplay : EventBox { + private VBox vbox; + private Knob knob; + private ValueDisplay display; + + // delegating properties + public bool show_matrix { get { return display.show_matrix; } set { display.show_matrix = value; } } + public Adjustment adjustment { get { return knob.get_adjustment (); } set { knob.set_adjustment (value); } } + public KnobMode knob_mode { get { return knob.knob_mode; } set { knob.knob_mode = value; } } + + construct { + vbox = new VBox (false, 0); + knob = new Knob (); + vbox.add (knob); + display = new ValueDisplay (); + vbox.add (display); + knob.user_data = display; + knob.value_changed += (knob) => { + ValueDisplay disp = knob.user_data as ValueDisplay; + disp.text = knob.get_value ().to_string (); + }; + add (vbox); + show_matrix = true; + } +} + +} // namespace Prolooks + -- 2.11.4.GIT