From 08e96c97f7524190c40a1c5482076874f394a6a7 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 9 Mar 2013 20:12:23 +0100 Subject: Make knob controllable using the arrow keys. --- plugingui/knob.cc | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'plugingui/knob.cc') diff --git a/plugingui/knob.cc b/plugingui/knob.cc index d60ecc4..43bc3e8 100644 --- a/plugingui/knob.cc +++ b/plugingui/knob.cc @@ -78,10 +78,6 @@ void GUI::Knob::scrollEvent(ScrollEvent *e) void GUI::Knob::mouseMoveEvent(MouseMoveEvent *e) { if(state == down) { - /* - DEBUG(slider, "Knob::mouseMoveEvent(mouse_offset_x: %d, e->x: %d)\n", - mouse_offset_x, e->x); - */ if(mouse_offset_x == (e->x + -1*e->y)) return; float dval = mouse_offset_x - (e->x + -1*e->y); @@ -97,19 +93,44 @@ void GUI::Knob::mouseMoveEvent(MouseMoveEvent *e) } } +void GUI::Knob::keyEvent(KeyEvent *e) +{ + if(e->direction != -1) return; + + switch(e->keycode) { + case GUI::KeyEvent::KEY_UP: + val += 0.01; + break; + case GUI::KeyEvent::KEY_DOWN: + val -= 0.01; + break; + case GUI::KeyEvent::KEY_HOME: + val = 0; + break; + case GUI::KeyEvent::KEY_END: + val = 1; + break; + default: + break; + } + + if(val < 0) val = 0; + if(val > 1) val = 1; + + repaintEvent(NULL); +} + void GUI::Knob::buttonEvent(ButtonEvent *e) { if(e->direction == 1) { state = down; mouse_offset_x = e->x + -1*e->y; - //val = maximum / (float)width() * (float)e->x; if(handler) handler(ptr); repaintEvent(NULL); } if(e->direction == -1) { state = up; mouse_offset_x = e->x + -1*e->y; - //val = maximum / (float)width() * (float)e->x; repaintEvent(NULL); clicked(); if(handler) handler(ptr); @@ -118,8 +139,6 @@ void GUI::Knob::buttonEvent(ButtonEvent *e) void GUI::Knob::repaintEvent(GUI::RepaintEvent *e) { - // DEBUG(slider, "Knob::repaintEvent (%f)\n", val); - Painter p(this); float alpha = 0.8; -- cgit v1.2.3