fixed dragging GuiColorPanel outside of bounds (#366)
This commit is contained in:
parent
dd36bff888
commit
45e7f967e6
43
src/raygui.h
43
src/raygui.h
@ -3379,15 +3379,54 @@ int GuiColorPanel(Rectangle bounds, const char *text, Color *color)
|
|||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
|
if ((state != STATE_DISABLED) && !guiLocked)
|
||||||
{
|
{
|
||||||
Vector2 mousePoint = GetMousePosition();
|
Vector2 mousePoint = GetMousePosition();
|
||||||
|
|
||||||
if (CheckCollisionPointRec(mousePoint, bounds))
|
if (guiSliderDragging)
|
||||||
|
{
|
||||||
|
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
|
||||||
|
{
|
||||||
|
if (CHECK_BOUNDS_ID(bounds, guiSliderActive))
|
||||||
|
{
|
||||||
|
pickerSelector = mousePoint;
|
||||||
|
|
||||||
|
if (pickerSelector.x < bounds.x) pickerSelector.x = bounds.x;
|
||||||
|
if (pickerSelector.x > bounds.x + bounds.width) pickerSelector.x = bounds.x + bounds.width;
|
||||||
|
if (pickerSelector.y < bounds.y) pickerSelector.y = bounds.y;
|
||||||
|
if (pickerSelector.y > bounds.y + bounds.height) pickerSelector.y = bounds.y + bounds.height;
|
||||||
|
|
||||||
|
// Calculate color from picker
|
||||||
|
Vector2 colorPick = { pickerSelector.x - bounds.x, pickerSelector.y - bounds.y };
|
||||||
|
|
||||||
|
colorPick.x /= (float)bounds.width; // Get normalized value on x
|
||||||
|
colorPick.y /= (float)bounds.height; // Get normalized value on y
|
||||||
|
|
||||||
|
hsv.y = colorPick.x;
|
||||||
|
hsv.z = 1.0f - colorPick.y;
|
||||||
|
|
||||||
|
Vector3 rgb = ConvertHSVtoRGB(hsv);
|
||||||
|
|
||||||
|
// NOTE: Vector3ToColor() only available on raylib 1.8.1
|
||||||
|
*color = RAYGUI_CLITERAL(Color){ (unsigned char)(255.0f*rgb.x),
|
||||||
|
(unsigned char)(255.0f*rgb.y),
|
||||||
|
(unsigned char)(255.0f*rgb.z),
|
||||||
|
(unsigned char)(255.0f*(float)color->a/255.0f) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
guiSliderDragging = false;
|
||||||
|
guiSliderActive = RAYGUI_CLITERAL(Rectangle){ 0, 0, 0, 0 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (CheckCollisionPointRec(mousePoint, bounds))
|
||||||
{
|
{
|
||||||
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
|
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
|
||||||
{
|
{
|
||||||
state = STATE_PRESSED;
|
state = STATE_PRESSED;
|
||||||
|
guiSliderDragging = true;
|
||||||
|
guiSliderActive = bounds;
|
||||||
pickerSelector = mousePoint;
|
pickerSelector = mousePoint;
|
||||||
|
|
||||||
// Calculate color from picker
|
// Calculate color from picker
|
||||||
|
Loading…
x
Reference in New Issue
Block a user