A new slider : TextVerticalDrag


#1

Hi Jules,

in my app I need a new kind of slider. Just a label displaying the value with the possibility to change the value by clicking on it (like LinearBar) or dragging up and down with the mouse (like RotaryVerticalDrag)
If you like to add this kind of slider to the list there are just few changes in the juce_slider.ccp and header.

Best regards,
Andrea

juce_slider.h
add this as last enum SliderStyle

TextVerticalDrag,	/**< A text label shown the value that can be changed by draggin the mouse up-and-down.
							@see setRotaryParameters*/

juce_slider.cpp

void Slider::lookAndFeelChanged()
{
	[...] (line 356)
if ((style == LinearBar) || (style == TextVerticalDrag))
	valueBox->addMouseListener (this, false);
	[...]
}

(line 827)
void Slider::paint (Graphics& g)
{
	if ((style != IncDecButtons) && (style != TextVerticalDrag))
	[...]
}

void Slider::resized()
{
	[...] (line 880)
	if ((style == LinearBar) || (style == TextVerticalDrag))
	{
		if (valueBox != 0)
			valueBox->setBounds (getLocalBounds());
	}
	[...] (line 915)
	if ((style == LinearBar) || (style == TextVerticalDrag))
	{
		const int barIndent = 1;
		sliderRegionStart = barIndent;
	[...]
}

void Slider::restoreMouseIfHidden()
{
	[...] (line 1154)
		Point<int> mousePos;

		if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag || style == TextVerticalDrag)
		{
						mousePos = Desktop::getLastMouseDownPosition();
	[...]
}

void Slider::mouseDrag (const MouseEvent& e)
{
	[...] (line 1276)
				double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;

				if (style == RotaryHorizontalDrag
					|| style == RotaryVerticalDrag || style == TextVerticalDrag
					|| style == IncDecButtons
	[...] (line 1330)
						if (isVertical() || style == RotaryVerticalDrag || style == TextVerticalDrag
						 || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
						speed = -speed;
	[...]
}

#2

Very cool! The latest plugins from Audio Damage use this idea of “numbers as sliders.” It makes for a very tidy GUI, that is easy to read and use.

Sean Costello


#3

Thanks Sean, I hope Jules like it too so he can add to the library.

Andrea


#4

+1!


#5

I’ve been revisiting this today. Ideally, a TextVerticalDrag slider would have the ability to use a larger or smaller font size than the default value for the sliders. Would this be best handled by a LookAndFeel modification, or by creating a new TextSlider class that has the ability to change text size, font, etc?

Sean Costello


#6

Another relevant thread on this topic: http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=3809

I’ve also thought about using a rotary slider, making it invisible, and having a Label behind it that is tied into the slider via my code (in my case, via the actual plugin parameter computation code). In general, I have been thinking about using separate Label components for my sliders, instead of using the labels that are associated with the Slider class, so I can move coefficient range warping into the plugin code instead of within the control. But that is probably a subject for a different thread.

Sean Costello