From fb6c44162652c0366a4987ba7662fe62e25c983d Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 16 May 2018 13:07:37 +0200 Subject: [PATCH] Fixed ColorPicker bounds collision - Mouse can't get out of colorPicker bounds when pressing - Mouse hides so user can see better the selector --- tools/rGuiStyler/src/rguistyler.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tools/rGuiStyler/src/rguistyler.c b/tools/rGuiStyler/src/rguistyler.c index 0466864..e8186ef 100644 --- a/tools/rGuiStyler/src/rguistyler.c +++ b/tools/rGuiStyler/src/rguistyler.c @@ -397,7 +397,11 @@ int main(int argc, char *argv[]) bool checked = false; + bool selectingColor = false; + int spinnerValue = 28; + + Vector2 mousePos = { 0 }; int comboNum = 2; const char *comboText[2] = { "Style Text (.rgs)", "Style Binary (.rgs)" }; @@ -431,6 +435,9 @@ int main(int argc, char *argv[]) //---------------------------------------------------------------------------------- framesCounter++; + // Get mouse position each frame + mousePos = GetMousePosition(); + // Check for changed controls if ((framesCounter%120) == 0) { @@ -494,6 +501,28 @@ int main(int argc, char *argv[]) colorHSV = ColorToHSV(colorPickerValue); + if (CheckCollisionPointRec(mousePos, bounds[COLORPICKER])) + { + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selectingColor = true; + } + + if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) + { + selectingColor = false; + ShowCursor(); + } + + if (selectingColor) + { + HideCursor(); + if (mousePos.x < bounds[COLORPICKER].x) SetMousePosition((Vector2){ bounds[COLORPICKER].x, mousePos.y }); + else if (mousePos.x > bounds[COLORPICKER].x + bounds[COLORPICKER].width) SetMousePosition((Vector2){ bounds[COLORPICKER].x + bounds[COLORPICKER].width, mousePos.y }); + + if (mousePos.y < bounds[COLORPICKER].y) SetMousePosition((Vector2){ mousePos.x, bounds[COLORPICKER].y }); + else if (mousePos.y > bounds[COLORPICKER].y + bounds[COLORPICKER].height) SetMousePosition((Vector2){ mousePos.x, bounds[COLORPICKER].y + bounds[COLORPICKER].height }); + + } + // Control TextBox edit mode if (CheckCollisionPointRec(GetMousePosition(), bounds[TEXTBOX]) && (IsKeyPressed(KEY_ENTER) || IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) editFilenameText = !editFilenameText; if (CheckCollisionPointRec(GetMousePosition(), (Rectangle){ anchor02.x + 290, anchor02.y + 530, 65, 20 }) && (IsKeyPressed(KEY_ENTER) || IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) editHexColorText = !editHexColorText;