From a9681dc83634eed0483ad5d73ee6159d68884882 Mon Sep 17 00:00:00 2001 From: Hans Baier Date: Thu, 26 Mar 2009 03:16:52 +0700 Subject: [PATCH] Knob: Glade-enabled --- prolooks/IKnobImageSource.vala | 2 +- prolooks/Knob.vala | 93 ++++++++++++++++++++++++++---------------- prolooks/KnobDemo.vala | 10 ++--- 3 files changed, 64 insertions(+), 41 deletions(-) diff --git a/prolooks/IKnobImageSource.vala b/prolooks/IKnobImageSource.vala index 6fce6cb..cbd1de7 100644 --- a/prolooks/IKnobImageSource.vala +++ b/prolooks/IKnobImageSource.vala @@ -10,7 +10,7 @@ namespace Prolooks { public interface IKnobImageSource : GLib.Object { public int variants { get { - return KnobMode.NUM_MODES; + return (int)KnobMode.ENDLESS + 1; } } diff --git a/prolooks/Knob.vala b/prolooks/Knob.vala index 81be589..f4c9dca 100644 --- a/prolooks/Knob.vala +++ b/prolooks/Knob.vala @@ -7,38 +7,82 @@ using Gtk; namespace Prolooks { - static const uint16 GDK_Home = 0xff50; - static const uint16 GDK_End = 0xff57; - static const uint16 GDK_Up = 0xff52; - static const uint16 GDK_Down = 0xff54; - static const uint16 GDK_Shift_L = 0xffe1; - static const uint16 GDK_Shift_R = 0xffe2; + static const uint16 GDK_Home = 0xff50; + static const uint16 GDK_End = 0xff57; + static const uint16 GDK_Up = 0xff52; + static const uint16 GDK_Down = 0xff54; + static const uint16 GDK_Shift_L = 0xffe1; + static const uint16 GDK_Shift_R = 0xffe2; public enum KnobMode { POSITIVE, BIPOLAR, NEGATIVE, - ENDLESS, - NUM_MODES + ENDLESS } public class Knob : Range { private Cairo.Surface? cache_surface = null; - public IKnobImageSource image_source { get; set; } + private IKnobImageSource _image_source; + public IKnobImageSource image_source { + get { + if (_image_source == null) { + image_source = new SimpleKnobImageSource (); + } + return _image_source; + } + + set { + if (value != null && value != _image_source) { + _image_source = value; + cache_surface = null; + queue_draw (); + } + } + } - public KnobMode knob_mode { get; set; } + private KnobMode _knob_mode; + public KnobMode knob_mode { + get { + return _knob_mode; + } + set { + if (value != _knob_mode) { + _knob_mode = value; + cache_surface = null; + queue_draw (); + } + } + } + double start_value; int start_x; int start_y; int last_y; + public Knob () { + Adjustment adj = new Adjustment(0, 0, 1, 0.01, 0.5, 0); + init (adj); + } + + private void init (Adjustment an_adjustment) { + requisition.width = (int)image_source.get_knob_width (); + requisition.height = (int)image_source.get_knob_height (); + set_flags (WidgetFlags.CAN_FOCUS); + set_adjustment (an_adjustment); + this.value_changed += () => { + queue_draw (); + }; + add_events (Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK ); + } + + public Knob.with_adjustment (Adjustment an_adjustment) { + init (an_adjustment); + } + public override bool expose_event (Gdk.EventExpose event) { - if (image_source == null) { - return false; - } - // Create a Cairo context var cr = Gdk.cairo_create (this.window); @@ -250,27 +294,6 @@ public class Knob : Range { calf_knob_incr (event.direction); return true; } - - public Knob () { - Adjustment adj = new Adjustment(0, 0, 1, 0.01, 0.5, 0); - init (adj); - } - - private void init (Adjustment an_adjustment) { - image_source = new SimpleKnobImageSource (); - requisition.width = 40; - requisition.height = 40; - set_flags (WidgetFlags.CAN_FOCUS); - set_adjustment (an_adjustment); - this.value_changed += () => { - queue_draw (); - }; - add_events (Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK ); - } - - public Knob.with_adjustment (Adjustment an_adjustment) { - init (an_adjustment); - } } // class Knob diff --git a/prolooks/KnobDemo.vala b/prolooks/KnobDemo.vala index 160d4b1..fbaf8ff 100644 --- a/prolooks/KnobDemo.vala +++ b/prolooks/KnobDemo.vala @@ -13,11 +13,11 @@ namespace Prolooks { var hbox = new HBox (false, 0); var isource = new SimpleKnobImageSource (); isource.led_color = color_from_string ("#9fc717"); - for (int i = 0; i < (int)KnobMode.NUM_MODES; i++) { - Knob knob = new Knob (); - knob.image_source = isource; - knob.knob_mode = (KnobMode)i; - hbox.add (knob); + for (int i = 0; i <= (int)KnobMode.ENDLESS; i++) { + Knob knob = new Knob (); + knob.image_source = isource; + knob.knob_mode = (KnobMode)i; + hbox.add (knob); } window.add (hbox); window.destroy += Gtk.main_quit; -- 2.11.4.GIT