reduce redundancy
This commit is contained in:
parent
43396137ec
commit
cc65650499
|
|
@ -144,25 +144,6 @@ int main(void)
|
|||
|
||||
if (sliderClicked && IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) sliderClicked = false;
|
||||
|
||||
// Update the current color based on the handle position
|
||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) && settingColor)
|
||||
{
|
||||
circlePosition = GetMousePosition();
|
||||
|
||||
float distance = Vector2Distance(center, circlePosition) / pointScale;
|
||||
float angle = ((Vector2Angle((Vector2){ 0.0f, -pointScale }, Vector2Subtract(center, circlePosition))/PI + 1.0f)/2.0f);
|
||||
float angle360 = angle*360.0f;
|
||||
|
||||
if (distance > 1.0f)
|
||||
{
|
||||
circlePosition = Vector2Add((Vector2){ sinf(angle*(PI*2.0f))*pointScale, -cosf(angle*(PI* 2.0f))*pointScale }, center);
|
||||
}
|
||||
|
||||
float valueActual = Clamp(distance, 0.0f, 1.0f);
|
||||
|
||||
color = ColorLerp((Color){ (int)(value*255.0f), (int)(value*255.0f), (int)(value*255.0f), 255 }, ColorFromHSV(angle360, Clamp(distance, 0.0f, 1.0f), 1.0f), valueActual);
|
||||
}
|
||||
|
||||
// Update render mode accordingly
|
||||
if (IsKeyPressed(KEY_SPACE)) renderType = RL_LINES;
|
||||
|
||||
|
|
@ -262,11 +243,20 @@ int main(void)
|
|||
// Slider to change color's value
|
||||
GuiSliderBar(sliderRectangle, "value: ", "", &value, 0.0f, 1.0f);
|
||||
|
||||
// If the slider was clicked, update the current color
|
||||
if (sliderClicked)
|
||||
// If the slider or the wheel was clicked, update the current color
|
||||
if (settingColor || sliderClicked)
|
||||
{
|
||||
if (settingColor) {
|
||||
circlePosition = GetMousePosition();
|
||||
}
|
||||
|
||||
float distance = Vector2Distance(center, circlePosition) / pointScale;
|
||||
|
||||
float angle = ((Vector2Angle((Vector2){ 0.0f, -pointScale }, Vector2Subtract(center, circlePosition))/PI + 1.0f)/2.0f);
|
||||
if (settingColor && distance > 1.0f) {
|
||||
circlePosition = Vector2Add((Vector2){ sinf(angle*(PI*2.0f))*pointScale, -cosf(angle*(PI* 2.0f))*pointScale }, center);
|
||||
}
|
||||
|
||||
float angle360 = angle*360.0f;
|
||||
|
||||
float valueActual = Clamp(distance, 0.0f, 1.0f);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user