From 4bdfe0bfa083ced19983c47ea9358c2213e78a15 Mon Sep 17 00:00:00 2001 From: Hans Baier Date: Thu, 25 Oct 2012 15:34:52 +0700 Subject: [PATCH] Fix painting of Knob: With Gtk-3.0 widget must be painted at origin, cr is already coordinate transformed --- src/Knob.vala | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Knob.vala b/src/Knob.vala index ce8f9d3..264f5a7 100644 --- a/src/Knob.vala +++ b/src/Knob.vala @@ -24,8 +24,6 @@ namespace Prolooks { public class Knob : Range { private static HashTable images = null; - // turn off debug logging - void debug(string format, ...) {} private Cairo.Surface? cache_surface = null; @@ -83,7 +81,7 @@ public class Knob : Range { construct { Adjustment adj = new Adjustment(0, 0, 1, 0.01, 0.5, 0); set_adjustment (adj); -//XXX set_flags (WidgetFlags.CAN_FOCUS); + set_can_focus(true); add_events (Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK ); draw.connect(on_draw); motion_notify_event.connect(on_motion_notify_event); @@ -137,12 +135,9 @@ public class Knob : Range { get_allocation(out allocation); Adjustment adj = get_adjustment (); - //debug ("adjustment = %p value = %f\n", adj, adj.value); + debug ("adjustment = %p value = %f\n", adj, adj.value); int ox = allocation.x, oy = allocation.y; - - ox += (int)(allocation.width - image_source.get_knob_width ()) / 2; - oy += (int)(allocation.height - image_source.get_knob_height ()) / 2; - + int phase = (int)((adj.value - adj.lower) * 64 / (adj.upper - adj.lower)); // skip middle phase except for true middle value if (knob_mode == KnobMode.BIPOLAR && phase == 32) { @@ -175,15 +170,15 @@ public class Knob : Range { } assert (cache_surface != null); - cr.set_source_surface (cache_surface, ox - phase * image_source.get_knob_width (), oy); - cr.rectangle (ox, oy, image_source.get_knob_width (), image_source.get_knob_height ()); + cr.set_source_surface (cache_surface, - phase * image_source.get_knob_width (), oy); + cr.rectangle (0, 0, image_source.get_knob_width (), image_source.get_knob_height ()); cr.fill (); - // debug ("exposed %p %d+%d", window, allocation.x, allocation.y); + debug ("exposed %p %d+%d", get_window(), allocation.x, allocation.y); if (is_focus) { get_style_context().render_focus ( - cr, - ox, oy, + cr, + 0, 0, (int)image_source.get_knob_width (), (int)image_source.get_knob_height ()); } -- 2.11.4.GIT