Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix asymmetric values in sliderpack not drawing correctly #327

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions hi_tools/hi_standalone_components/SliderPack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,7 @@ void SliderPack::paintOverChildren(Graphics &g)
{
if (displayAlphas[i] > 0.0f)
{
const bool biPolar = sliders[i]->getMinimum() < 0;


const bool biPolar = sliders[i]->getMinimum() < 0 && sliders[i]->getMaximum() > 0;

auto v = (int)sliders[i]->getPositionOfValue(sliders[i]->getValue());

Expand All @@ -575,10 +573,15 @@ void SliderPack::paintOverChildren(Graphics &g)

if (biPolar)
{
int h_half = sliders[i]->getHeight() / 2;
float max = (float)sliders[i]->getMaximum();
float min = (float)sliders[i]->getMinimum();

float value = 1.0f - (sliders[i]->getValue() - min) / (max - min);
float origin = 1.0f - (-1.0f * min) / (max - min);

y = value < origin ? value * sliders[i]->getHeight() : origin * sliders[i]->getHeight();

y = v < h_half ? v : h_half;
h = v < h_half ? (h_half - y) : (v - h_half);
h = fabs(origin - value) * sliders[i]->getHeight();
}
else
{
Expand Down Expand Up @@ -879,10 +882,11 @@ void SliderPack::SliderLookAndFeel::drawLinearSlider(Graphics &g, int /*x*/, int

if (isBiPolar)
{
const float value = (-1.0f * (float)s.getValue() - min) / (max - min);
const float value = 1.0f - ((float)s.getValue() - min) / (max - min);
float origin = 1.0f - (-1.0f * min) / (max - min);

leftY = (value < 0.5f ? value * (float)(height) : 0.5f * (float)(height));
actualHeight = fabs(0.5f - value) * (float)(height);
leftY = value < origin ? value * (float)(height) : origin * (float)(height);
actualHeight = fabs(origin - value) * (float)(height);
}
else
{
Expand Down