Small 'bug' in Slider class?


#1

Hello all,
I’m pretty new to juce, so maybe I’m wrong, but I think there’s a small bug in the Slider class:
I made an image based linear slider using the lookAndFeel class. Everything works fine, except when a horizontal slider is used in combination with a textBox on left or a vertical slider with textBox below. In these cases the slider image is scaled correctly but the slider thumb image isn’t placed correctly, but has an offset the size of the textBox. All other slider / textBox combinations are working fine.
Here is the code:

[code]void XYLookAndFeel::drawLinearSlider (Graphics& g,
int x, int y,
int w, int h,
float sliderPos,
float minSliderPos,
float maxSliderPos,
const Slider::SliderStyle style,
Slider& slider)
{

if(slider.isHorizontal() || slider.isVertical())
{
    if (slider.isHorizontal())
    {
        g.setOpacity(1.f);
		g.drawImage(faderLineImgH, x, y + (h - faderLineImgH->getHeight())/2, w, faderLineImgH->getHeight(),
								  0, 0, faderLineImgH->getWidth(), faderLineImgH->getHeight(),0);
    }
    else
    {
		g.setOpacity(1.f);
		g.drawImage(faderLineImgV, x + (w - faderLineImgV->getWidth())/2, y, faderLineImgV->getWidth(), h,
								  0, 0, faderLineImgV->getWidth(), faderLineImgV->getHeight(),0);
    }

    
    if (style == Slider::LinearHorizontal)
    {
		
		
		g.setOpacity(1.f);
		g.drawImageAt(faderButtonImgH, x + int(sliderPos) - faderButtonImgH->getWidth(),
									   y + (h - faderLineImgH->getHeight())/2 - faderButtonImgH->getHeight()/2 +1, 0);
	}
    else if (style == Slider::LinearVertical)
    {	
		g.setOpacity(1.f);
		g.drawImageAt(faderButtonImgV, x + (w - faderLineImgV->getWidth())/2 - faderButtonImgV->getWidth()/2 +1,
									   y + int(sliderPos) - faderButtonImgV->getHeight(), 0);
    }
}

}

int XYLookAndFeel::getSliderThumbRadius (Slider& slider)
{
if(slider.isHorizontal())
return faderButtonImgH->getWidth()/2;
else
return faderButtonImgV->getHeight()/2;
}[/code]

I did a workaround by switching slider.getTextBoxPosition():

switch (slider.getTextBoxPosition()) { case Slider::NoTextBox: tbOffsetL = 0; tbOffsetR = 0; tbOffsetA = 0; tbOffsetB = 0; break; case Slider::TextBoxLeft: tbOffsetL = slider.getTextBoxWidth(); tbOffsetR = 0; tbOffsetA = 0; tbOffsetB = 0; break; case Slider::TextBoxAbove: tbOffsetL = 0; tbOffsetR = 0; tbOffsetA = slider.getTextBoxHeight(); tbOffsetB = 0; break; case Slider::TextBoxRight: tbOffsetL = 0; tbOffsetR = slider.getTextBoxWidth(); tbOffsetA = 0; tbOffsetB = 0; break; case Slider::TextBoxBelow: tbOffsetL = 0; tbOffsetR = 0; tbOffsetA = 0; tbOffsetB = slider.getTextBoxHeight(); break; }

and used that offset to place the thumb image:

[code]if (style == Slider::LinearHorizontal)
{

		g.setOpacity(1.f);
		g.drawImageAt(faderButtonImgH, x - tbOffsetL + int(sliderPos) - faderButtonImgH->getWidth(),
									   y + (h - faderLineImgH->getHeight())/2 - faderButtonImgH->getHeight()/2 +1, 0);
	}
    else if (style == Slider::LinearVertical)
    {	
		g.setOpacity(1.f);
		g.drawImageAt(faderButtonImgV, x + (w - faderLineImgV->getWidth())/2 - faderButtonImgV->getWidth()/2 +1,
									   y - tbOffsetA + int(sliderPos) - faderButtonImgV->getHeight(), 0);
    }[/code]

But I think that’s not the way things should work.
Maybe I missed something or went completely the wrong way, so please correct me if I’m wrong.

And by the way, juce is a great piece of work, I really enjoyed it from the beginning, go on Jules.

Thanks in advance


#2