Some code tweaks

This commit is contained in:
Ray
2018-11-26 00:58:48 +01:00
parent 5473b79da1
commit 009913c408
2 changed files with 15 additions and 22 deletions

View File

@ -142,7 +142,7 @@ int main()
if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;
colorPickerValue = GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, colorPickerValue);
sliderValue = GuiSliderEx((Rectangle){ 320, 400, 200, 20 }, sliderValue, 0, 100, "SLIDER", true);
sliderValue = GuiSliderEx((Rectangle){ 320, 400, 200, 20 }, sliderValue, -50, 100, "SLIDER", true);
sliderBarValue = GuiSliderBarEx((Rectangle){ 320, 430, 200, 20 }, sliderBarValue, 0, 100, "SLIDERBAR", true);
progressValue = GuiProgressBarEx((Rectangle){ 320, 460, 200, 20 }, progressValue, 0, 1, true);

View File

@ -1845,22 +1845,20 @@ RAYGUIDEF float GuiSliderPro(Rectangle bounds, float value, float minValue, floa
GuiControlState state = guiState;
int textWidth = (text == NULL) ? 0: GuiTextWidth(text);
int sliderValue = (int)(((value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH)));
Rectangle slider = { 0 };
Rectangle slider = { bounds.x, bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, INNER_PADDING),
0, bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) - 2*GuiGetStyle(SLIDER, INNER_PADDING) };
if (sliderWidth > 0) // Slider
{
slider = (Rectangle){ bounds.x + (int)((value/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))) - GuiGetStyle(SLIDER, SLIDER_WIDTH)/2,
bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH),
sliderWidth,
bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) };
slider.x += (sliderValue - sliderWidth/2);
slider.width = sliderWidth;
}
else if (sliderWidth == 0) // SliderBar
{
slider = (Rectangle){ bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH),
bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, INNER_PADDING),
(int)(((value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))),
bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) - 2*GuiGetStyle(SLIDER, INNER_PADDING) };
slider.x += GuiGetStyle(SLIDER, BORDER_WIDTH);
slider.width = sliderValue;
}
// Update control
@ -1876,16 +1874,10 @@ RAYGUIDEF float GuiSliderPro(Rectangle bounds, float value, float minValue, floa
state = GUI_STATE_PRESSED;
// Get equivalent value and slider position from mousePoint.x
if (sliderWidth > 0) // Slider
{
value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + slider.width/2)))/(float)(bounds.width - slider.width) + minValue;
slider.x = mousePoint.x - slider.width/2;
}
else if (sliderWidth == 0) // SliderBar
{
value = (maxValue - minValue)*((mousePoint.x - (float)bounds.x)/(float)bounds.width) + minValue;
slider.width = (int)(((value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH)));
}
value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue;
if (sliderWidth > 0) slider.x = mousePoint.x - slider.width/2; // Slider
else if (sliderWidth == 0) slider.width = sliderValue; // SliderBar
}
else state = GUI_STATE_FOCUSED;
}
@ -1893,10 +1885,11 @@ RAYGUIDEF float GuiSliderPro(Rectangle bounds, float value, float minValue, floa
if (value > maxValue) value = maxValue;
else if (value < minValue) value = minValue;
// Bar limits check
if (sliderWidth > 0) // Slider
{
if (slider.x <= bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH)) slider.x = bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH);
else if (slider.x + slider.width >= bounds.x + bounds.width) slider.x = bounds.x + bounds.width - slider.width - GuiGetStyle(SLIDER, BORDER_WIDTH);
if (slider.x <= (bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH))) slider.x = bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH);
else if ((slider.x + slider.width) >= (bounds.x + bounds.width)) slider.x = bounds.x + bounds.width - slider.width - GuiGetStyle(SLIDER, BORDER_WIDTH);
}
else if (sliderWidth == 0) // SliderBar
{