Slider Request: RotaryHorizontalVerticalDrag SliderStyle


#1

Hi Jules, I’ve had a few people ask me that rotary sliders respond to both horizontal and vertical mouse drags. Rather than taking a copy of all the Slider code I thought this might be a feature that a lot of people may want and so would make a good addition to the library.

A simple example of how this should work is the “Panner” slider in AU Lab, moving the slider to the right or up increments the value and vice versa. I’m not sure if this uses the largest of the x/y distance or resolves the drags but I think it feels like the second option, this would also make more sense as you wouldn’t have to favor linear or horizontal.

If you’re happy to include it but don’t have time to look at it now I’ll be happy to have a go and post the changes required.

Cheers, Dave.


#2

Well, I’ve not got time to think about it myself, but sure, I’d be happy to have a look at your suggested changes!


#3

Ok, I think this does what I need and would expect. There’s not many changes really, just the new style and some additional conditional options when setting/resetting the values. You probably have your own methods for integrating code but I like to use the Xcode Developer Tool “FileMerge” for comparing largely similar code as you can see it side by side.

The only thing I was a bit unsure of is how to restore the mouse position when it had been hidden (restoreMouseIfHidden) so I made the assumption that the drag was from 50% horizontal and 50% vertical. I’m not sure what you’ll see best here.

Thanks for taking a look,
Dave.

[attachment=0]Slider with horizvert style.zip[/attachment]


#4

Dave, I haven’t taken the time to grok your code yet - but does it handle velocity drag for this new hybrid mode too? This has been on my ToDo list for a while, so it’s great to see!


#5

Yes I think so, I did add some code to the handleVelocityDrag method so it certainly responds to velocity mode, the only thing I couldn’t figure out is why the speed is multiplied by -1 if the slider is vertical so I left that bit alone. It seems to work fine anyway though.

Here’s a really simple Introjucer project with the sources so it should build straight off the download. It just displays one slider in this new mode but will be a quick way for you to grab it and see if it responds how you would expect. I rarely use velocity mode so it would be good to have another opinion on it.


#6

Thanks, but ouch in VS2010! I can fix a couple of errors by qualifying with SliderExt::, but I don’t have time to track the rest of them down right now.

[code]Error 1 error C2664: ‘void juce::ListenerList::callCheckedjuce::Component::BailOutChecker,SliderExt*(const BailOutCheckerType &,void (__thiscall juce::Slider::Listener::* )(P1),SliderExt )’ : cannot convert parameter 2 from 'void (__thiscall SliderExt::Listener:: )(SliderExt )’ to 'void (__thiscall juce::Slider::Listener:: )(P1)’ d:\temp\slidertest\slidertest\source\sliderext.cpp 321

Error 2 error C2664: ‘void juce::ListenerList::callCheckedjuce::Component::BailOutChecker,SliderExt*(const BailOutCheckerType &,void (__thiscall juce::Slider::Listener::* )(P1),SliderExt )’ : cannot convert parameter 2 from 'void (__thiscall SliderExt::Listener:: )(SliderExt )’ to 'void (__thiscall juce::Slider::Listener:: )(P1)’ d:\temp\slidertest\slidertest\source\sliderext.cpp 330

Error 3 error C2664: ‘void juce::ListenerList::callCheckedjuce::Component::BailOutChecker,SliderExt*(const BailOutCheckerType &,void (__thiscall juce::Slider::Listener::* )(P1),SliderExt )’ : cannot convert parameter 2 from 'void (__thiscall SliderExt::Listener:: )(SliderExt )’ to 'void (__thiscall juce::Slider::Listener:: )(P1)’ d:\temp\slidertest\slidertest\source\sliderext.cpp 341

Error 4 error C2664: ‘juce::LookAndFeel::createSliderTextBox’ : cannot convert parameter 1 from ‘SliderExt’ to ‘juce::Slider &’ d:\temp\slidertest\slidertest\source\sliderext.cpp 549

Error 5 error C2664: ‘juce::LookAndFeel::drawRotarySlider’ : cannot convert parameter 9 from ‘SliderExt’ to ‘juce::Slider &’ d:\temp\slidertest\slidertest\source\sliderext.cpp 1030

Error 6 error C2664: ‘juce::LookAndFeel::drawLinearSlider’ : cannot convert parameter 9 from ‘SliderExt::SliderStyle’ to ‘const juce::Slider::SliderStyle’ d:\temp\slidertest\slidertest\source\sliderext.cpp 1040

Error 7 error C2664: ‘juce::LookAndFeel::getSliderThumbRadius’ : cannot convert parameter 1 from ‘SliderExt’ to ‘juce::Slider &’ d:\temp\slidertest\slidertest\source\sliderext.cpp 1097

Error 8 error C2523: ‘SliderExt::~Slider’ : destructor tag mismatch d:\temp\slidertest\slidertest\source\sliderext.cpp 1305

Error 9 error C2511: ‘void SliderExt::addListener(juce::SliderListener *const )’ : overloaded member function not found in ‘SliderExt’ d:\temp\slidertest\slidertest\source\sliderext.cpp 1308

Error 10 error C2511: ‘void SliderExt::removeListener(juce::SliderListener *const )’ : overloaded member function not found in ‘SliderExt’ d:\temp\slidertest\slidertest\source\sliderext.cpp 1309

Error 11 error C2511: ‘void juce::Slider::Listener::sliderDragStarted(SliderExt *)’ : overloaded member function not found in ‘juce::Slider::Listener’ d:\temp\slidertest\slidertest\source\sliderext.cpp 1554

Error 12 error C2511: ‘void juce::Slider::Listener::sliderDragEnded(SliderExt *)’ : overloaded member function not found in ‘juce::Slider::Listener’ d:\temp\slidertest\slidertest\source\sliderext.cpp 1555

13	IntelliSense: identifier "SliderStyle" is undefined	d:\temp\slidertest\slidertest\source\sliderext.cpp	19
14	IntelliSense: identifier "TextEntryBoxPosition" is undefined	d:\temp\slidertest\slidertest\source\sliderext.cpp	19
15	IntelliSense: identifier "SliderStyle" is undefined	d:\temp\slidertest\slidertest\source\sliderext.cpp	436
16	IntelliSense: identifier "IncDecButtonMode" is undefined	d:\temp\slidertest\slidertest\source\sliderext.cpp	476
17	IntelliSense: identifier "TextEntryBoxPosition" is undefined	d:\temp\slidertest\slidertest\source\sliderext.cpp	485
18	IntelliSense: identifier "SliderStyle" is undefined	d:\temp\slidertest\slidertest\source\sliderext.cpp	1163
19	IntelliSense: identifier "TextEntryBoxPosition" is undefined	d:\temp\slidertest\slidertest\source\sliderext.cpp	1179
20	IntelliSense: identifier "IncDecButtonMode" is undefined	d:\temp\slidertest\slidertest\source\sliderext.cpp	1183
21	IntelliSense: explicit type is missing ('int' assumed)	d:\temp\slidertest\slidertest\source\sliderext.cpp	1305
22	IntelliSense: invalid destructor name for type "SliderExt"	d:\temp\slidertest\slidertest\source\sliderext.cpp	1305
23	IntelliSense: declaration is incompatible with "void SliderExt::addListener(SliderExt::Listener *listener)" (declared at line 528 of "d:\temp\slidertest\slidertest\source\SliderExt.h")	d:\temp\slidertest\slidertest\source\sliderext.cpp	1308
24	IntelliSense: declaration is incompatible with "void SliderExt::removeListener(SliderExt::Listener *listener)" (declared at line 531 of "d:\temp\slidertest\slidertest\source\SliderExt.h")	d:\temp\slidertest\slidertest\source\sliderext.cpp	1309
25	IntelliSense: declaration is incompatible with "void juce::Slider::Listener::sliderDragStarted(juce::Slider *slider)" (declared at line 536 of "d:\temp\slidertest\slidertest\source\../JuceLibraryCode/modules/juce_gui_basics/../../../Source/modules/juce_gui_basics/lookandfeel/../widgets/juce_Slider.h")	d:\temp\slidertest\slidertest\source\sliderext.cpp	1554
26	IntelliSense: declaration is incompatible with "void juce::Slider::Listener::sliderDragEnded(juce::Slider *slider)" (declared at line 542 of "d:\temp\slidertest\slidertest\source\../JuceLibraryCode/modules/juce_gui_basics/../../../Source/modules/juce_gui_basics/lookandfeel/../widgets/juce_Slider.h")	d:\temp\slidertest\slidertest\source\sliderext.cpp	1555

[/code]


#7

Oops, sorry, that SliderExt stuff shouldn’t be included, I guess I removed it from the Xcode project but not the Introjucer. I started making this as that separate class but it all got a bit complicated with the look and feel parameters so I just modified the Slider class. Try the link again now, it should work.


#8

Yeah that looks good to me, the velocity drag works nicely!

This overcomes an issue for me where horizontal only or vertical only knobs don’t have much travel if they’re placed near the edge of the screen. Previously the best solution for this was rotary mode, except for the fact that you lose velocity mode. So this’ll be great if Jules can suffer a little more bloat in the slider class :smiley:


#9

Jules - thanks for adding RotaryHorizontalVerticalDrag to the slider class, but I note that this hasn’t flowed through to the Jucer. Is it as easy as adding it to SliderTypeProperty in jucer_SliderHandler.h?


#10

Can’t remember, TBH. Probably. But as noted elsewhere, the old jucer isn’t a priority for me.


#11

OK there was another spot for changes too, if anyone else wants the Jucer to handle the new slider style, here’s the diff:

[code]diff --git a/extras/the jucer/src/model/components/jucer_SliderHandler.h b/extras/the jucer/src/model/components/jucer_SliderHandler.h
index abc68db…d00943c 100644
— a/extras/the jucer/src/model/components/jucer_SliderHandler.h
+++ b/extras/the jucer/src/model/components/jucer_SliderHandler.h
@@ -192,6 +192,7 @@ private:
choices.add (“Rotary”);
choices.add (“Rotary HorizontalDrag”);
choices.add (“Rotary VerticalDrag”);

  •   	choices.add ("Rotary HorizontalVerticalDrag"); //***
           choices.add ("Inc/Dec Buttons");
           choices.add ("Two Value Horizontal");
           choices.add ("Two Value Vertical");
    

@@ -207,6 +208,7 @@ private:
Slider::Rotary,
Slider::RotaryHorizontalDrag,
Slider::RotaryVerticalDrag,

  •   										  Slider::RotaryHorizontalVerticalDrag, //***
                                                 Slider::IncDecButtons,
                                                 Slider::TwoValueHorizontal,
                                                 Slider::TwoValueVertical,
    

@@ -228,6 +230,7 @@ private:
Slider::Rotary,
Slider::RotaryHorizontalDrag,
Slider::RotaryVerticalDrag,

  •   										  Slider::RotaryHorizontalVerticalDrag, //***
                                                 Slider::IncDecButtons,
                                                 Slider::TwoValueHorizontal,
                                                 Slider::TwoValueVertical,
    

@@ -642,6 +645,8 @@ private:
return “RotaryHorizontalDrag”;
case Slider::RotaryVerticalDrag:
return “RotaryVerticalDrag”;

  •    case Slider::RotaryHorizontalVerticalDrag: //***
    
  •        return "RotaryHorizontalVerticalDrag"; //***
       case Slider::IncDecButtons:
           return "IncDecButtons";
       case Slider::TwoValueHorizontal:
    

@@ -675,6 +680,8 @@ private:
return Slider::RotaryHorizontalDrag;
else if (s == “RotaryVerticalDrag”)
return Slider::RotaryVerticalDrag;

  •    else if (s == "RotaryHorizontalVerticalDrag") //***
    
  •        return Slider::RotaryHorizontalVerticalDrag; //***
       else if (s == "IncDecButtons")
           return Slider::IncDecButtons;
       else if (s.startsWithIgnoreCase ("TwoValueHoriz"))
    

[/code]


#12

Ta, I’ll merge that in.


#13

Beaut, one less branch for me to manage!