summaryrefslogtreecommitdiff
path: root/plugingui/knob.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-03-09 20:12:23 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-03-09 20:12:23 +0100
commit08e96c97f7524190c40a1c5482076874f394a6a7 (patch)
tree93df09c80f05b884dd969c938a8f7665c9e23ef6 /plugingui/knob.cc
parent221f7216d1b6fda90f1aba36b2509aa62e158bee (diff)
Make knob controllable using the arrow keys.
Diffstat (limited to 'plugingui/knob.cc')
-rw-r--r--plugingui/knob.cc35
1 files changed, 27 insertions, 8 deletions
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;