X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fgtkmm2ext%2Fauto_spin.cc;h=5ab8852adfff03286f9764bf0b561aea83c20ec3;hb=8ee52628fc18ebf86a6bac6d7176faf98b73ed3d;hp=0830eca77e6a61232fd426d43fdb63dc87122f67;hpb=d09f6b3016bacbc2871a8946cbb24ad705076509;p=ardour.git diff --git a/libs/gtkmm2ext/auto_spin.cc b/libs/gtkmm2ext/auto_spin.cc index 0830eca77e..5ab8852adf 100644 --- a/libs/gtkmm2ext/auto_spin.cc +++ b/libs/gtkmm2ext/auto_spin.cc @@ -18,8 +18,9 @@ $Id$ */ -#include #include +#include "gtkmm2ext/auto_spin.h" +#include "gtkmm2ext/keyboard.h" using namespace Gtkmm2ext; using namespace std; @@ -33,7 +34,7 @@ const unsigned int AutoSpin::initial_timer_interval = 500; /* msecs */ const unsigned int AutoSpin::timer_interval = 20; /* msecs */ const unsigned int AutoSpin::climb_timer_calls = 5; /* between climbing */ -AutoSpin::AutoSpin (Gtk::Adjustment &adjr, gfloat cr) +AutoSpin::AutoSpin (Gtk::Adjustment &adjr, gfloat cr, bool round_to_steps_yn) : adjustment (adjr), climb_rate (cr) @@ -44,19 +45,20 @@ AutoSpin::AutoSpin (Gtk::Adjustment &adjr, gfloat cr) have_timer = false; need_timer = false; timer_calls = 0; + round_to_steps = round_to_steps_yn; } void AutoSpin::stop_timer () { if (have_timer) { - gtk_timeout_remove (timeout_tag); + g_source_remove (timeout_tag); have_timer = false; } } gint -AutoSpin::stop_spinning (GdkEventButton *ev) +AutoSpin::stop_spinning (GdkEventButton */*ev*/) { need_timer = false; stop_timer (); @@ -72,13 +74,13 @@ AutoSpin::button_press (GdkEventButton *ev) stop_spinning (0); - if (ev->state & GDK_SHIFT_MASK) { + if (ev->state & Keyboard::TertiaryModifier) { /* use page shift */ shifted = true; } - if (ev->state & GDK_CONTROL_MASK) { + if (ev->state & Keyboard::PrimaryModifier) { /* go to upper/lower bound on button1/button2 */ control = true; @@ -150,7 +152,7 @@ AutoSpin::start_spinning (bool decrement, bool page) have_timer = true; timer_calls = 0; - timeout_tag = gtk_timeout_add (initial_timer_interval, + timeout_tag = g_timeout_add (initial_timer_interval, AutoSpin::_timer, this); } @@ -164,7 +166,10 @@ AutoSpin::_timer (void *arg) void AutoSpin::set_value (gfloat value) { - adjustment.set_value (value); + if (round_to_steps) + adjustment.set_value (floor((value / step_increment) + 0.5f) * step_increment); + else + adjustment.set_value (value); } bool @@ -193,7 +198,7 @@ AutoSpin::adjust_value (gfloat increment) } } - adjustment.set_value (val); + set_value(val); return done; } @@ -212,7 +217,7 @@ AutoSpin::timer () request a much more frequent update. */ - timeout_tag = gtk_timeout_add (timer_interval, + timeout_tag = g_timeout_add (timer_interval, _timer, this); have_timer = true; @@ -253,6 +258,8 @@ AutoSpin::set_bounds (gfloat init, gfloat up, gfloat down, bool with_reset) { adjustment.set_upper(up); adjustment.set_lower(down); + + initial = init; adjustment.changed ();