From 65d42936653ba8519abd0224d14285548be58848 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sat, 26 Dec 2009 00:58:28 -0600 Subject: [PATCH] Mixer: Improve the mousewheel behavior of Fl_Arc_Dial and add Fl_Value_SliderX. You can now hold down the ctrl key for more precision. --- FL/Fl_Arc_Dial.C | 30 ++++++++--- FL/Fl_Value_SliderX.H | 88 +++++++++++++++++++++++++++++++++ Mixer/Controller_Module.C | 6 +-- Mixer/Controller_Module.H | 4 +- Mixer/Module_Parameter_Editor.C | 7 ++- 5 files changed, 121 insertions(+), 14 deletions(-) create mode 100644 FL/Fl_Value_SliderX.H diff --git a/FL/Fl_Arc_Dial.C b/FL/Fl_Arc_Dial.C index fbe0c48..cf6d8f5 100644 --- a/FL/Fl_Arc_Dial.C +++ b/FL/Fl_Arc_Dial.C @@ -24,6 +24,7 @@ #include #include #include +#include int Fl_Arc_Dial::handle ( int m ) @@ -37,14 +38,31 @@ Fl_Arc_Dial::handle ( int m ) if ( this != Fl::belowmouse() ) return 0; - int d = Fl::event_dy(); + int steps = 16; - double v = increment( value(), d ); + if ( Fl::event_ctrl() ) + steps = 128; - if ( v < minimum() ) - v = minimum(); - else if ( v > maximum() ) - v = maximum(); + float step = fabs( maximum() - minimum() ) / (float)steps; + + float d = ((float)Fl::event_dy()) * step; + + double v = value() + d; + + if ( maximum() > minimum() ) + { + if ( v < minimum() ) + v = minimum(); + else if ( v > maximum() ) + v = maximum(); + } + else + { + if ( v > minimum() ) + v = minimum(); + else if ( v < maximum() ) + v = maximum(); + } value( v ); do_callback(); diff --git a/FL/Fl_Value_SliderX.H b/FL/Fl_Value_SliderX.H new file mode 100644 index 0000000..043e3db --- /dev/null +++ b/FL/Fl_Value_SliderX.H @@ -0,0 +1,88 @@ + +/*******************************************************************************/ +/* Copyright (C) 2009 Jonathan Moore Liles */ +/* */ +/* This program is free software; you can redistribute it and/or modify it */ +/* under the terms of the GNU General Public License as published by the */ +/* Free Software Foundation; either version 2 of the License, or (at your */ +/* option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, but WITHOUT */ +/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ +/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */ +/* more details. */ +/* */ +/* You should have received a copy of the GNU General Public License along */ +/* with This program; see the file COPYING. If not,write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*******************************************************************************/ + +/* just like an Fl_Value_Slider, except that it responds to mousewheel events */ + +#pragma once + +#include +#include +#include + +class Fl_Value_SliderX : public Fl_Value_Slider +{ + +public: + + Fl_Value_SliderX ( int X, int Y, int W, int H, const char *L = 0 ) + : Fl_Value_Slider( X, Y, W, H, L ) + { + } + + virtual ~Fl_Value_SliderX() { } + + virtual int handle ( int m ) + { + + /* Fl_Value_Slider and friends should really handle mousewheel, but they don't in FTLK1 */ + + + switch ( m ) + { + case FL_MOUSEWHEEL: + { + if ( this != Fl::belowmouse() ) + return 0; + + int steps = 16; + + if ( Fl::event_ctrl() ) + steps = 128; + + float step = fabs( maximum() - minimum() ) / (float)steps; + + float d = ((float)Fl::event_dy()) * step; + + double v = value() + d; + + if ( maximum() > minimum() ) + { + if ( v < minimum() ) + v = minimum(); + else if ( v > maximum() ) + v = maximum(); + } + else + { + if ( v > minimum() ) + v = minimum(); + else if ( v < maximum() ) + v = maximum(); + } + + value( v ); + do_callback(); + + return 1; + } + } + + return Fl_Value_Slider::handle( m ); + } +}; diff --git a/Mixer/Controller_Module.C b/Mixer/Controller_Module.C index ae196b3..37f99ab 100644 --- a/Mixer/Controller_Module.C +++ b/Mixer/Controller_Module.C @@ -20,7 +20,7 @@ #include "Controller_Module.H" #include -#include +#include "FL/Fl_Value_SliderX.H" #include #include #include "FL/Fl_Arc_Dial.H" @@ -151,7 +151,7 @@ Controller_Module::connect_to ( Port *p ) } else if ( p->hints.type == Module::Port::Hints::LOGARITHMIC ) { - Fl_Value_Slider *o = new Fl_Value_Slider(0, 0, 30, 250, p->name() ); + Fl_Value_SliderX *o = new Fl_Value_SliderX(0, 0, 30, 250, p->name() ); control = o; w = o; @@ -160,7 +160,6 @@ Controller_Module::connect_to ( Port *p ) o->selection_color((Fl_Color)1); o->minimum(1.5); o->maximum(0); - o->step(0.01); o->value(1); o->textsize(14); @@ -192,7 +191,6 @@ Controller_Module::connect_to ( Port *p ) o->color( fl_darker( fl_darker( FL_GRAY ) ) ); o->selection_color( FL_WHITE ); o->value( p->control_value() ); - } } diff --git a/Mixer/Controller_Module.H b/Mixer/Controller_Module.H index 2b18d23..7ca2a97 100644 --- a/Mixer/Controller_Module.H +++ b/Mixer/Controller_Module.H @@ -47,8 +47,8 @@ public: const char *name ( void ) const { return "Controller"; } - int can_support_inputs ( int n ) { return 0; } - bool configure_inputs ( int n ) { return false; } + int can_support_inputs ( int ) { return 0; } + bool configure_inputs ( int ) { return false; } void pad ( bool v ) { _pad = v; } diff --git a/Mixer/Module_Parameter_Editor.C b/Mixer/Module_Parameter_Editor.C index 4e12278..22d270f 100644 --- a/Mixer/Module_Parameter_Editor.C +++ b/Mixer/Module_Parameter_Editor.C @@ -19,7 +19,7 @@ #include #include -#include +#include "FL/Fl_Value_SliderX.H" #include #include #include "FL/Fl_Arc_Dial.H" @@ -35,6 +35,7 @@ #include #include #include +#include @@ -172,10 +173,11 @@ Module_Parameter_Editor::make_controls ( void ) o->selection_color( FL_WHITE ); o->value( p->control_value() ); +// o->step( fabs( ( o->maximum() - o->minimum() ) ) / 32.0f ); } else { - Fl_Value_Slider *o = new Fl_Value_Slider( 0, 0, 120, 24, p->name() ); + Fl_Value_SliderX *o = new Fl_Value_SliderX( 0, 0, 120, 24, p->name() ); w = o; if ( mode_choice->value() == 1 ) @@ -198,6 +200,7 @@ Module_Parameter_Editor::make_controls ( void ) o->minimum( p->hints.maximum ); } +// o->step( fabs( ( o->maximum() - o->minimum() ) ) / 32.0f ); o->slider( FL_THIN_UP_BOX ); o->color( fl_darker( fl_darker( FL_GRAY ) ) ); o->selection_color( FL_WHITE );