Merge branch 'master' into patch-2

This commit is contained in:
Ray
2018-09-26 16:39:40 +02:00
committed by GitHub

View File

@ -1615,9 +1615,7 @@ RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int
#define DROPDOWNBOX_ARROW_RIGHT_PADDING 16 #define DROPDOWNBOX_ARROW_RIGHT_PADDING 16
GuiControlState state = guiState; GuiControlState state = guiState;
bool dropActive = false;
static bool dropOpen = false; static bool dropOpen = false;
static bool clicked = false;
int textWidth = MeasureText(text[active], style[DEFAULT_TEXT_SIZE]); int textWidth = MeasureText(text[active], style[DEFAULT_TEXT_SIZE]);
int textHeight = style[DEFAULT_TEXT_SIZE]; int textHeight = style[DEFAULT_TEXT_SIZE];
@ -1633,17 +1631,21 @@ RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int
{ {
Vector2 mousePoint = GetMousePosition(); Vector2 mousePoint = GetMousePosition();
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && CheckCollisionPointRec(mousePoint, bounds)) if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && CheckCollisionPointRec(mousePoint, bounds)) dropOpen = true;
{
clicked = true;
}
else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) clicked = false;
if (clicked) if (dropOpen)
{ {
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
{
for (int i = 1; i < (count + 1); i++)
{
if (CheckCollisionPointRec(mousePoint, (Rectangle){ bounds.x, bounds.y + i*bounds.height, bounds.width, bounds.height })) active = i - 1;
}
dropOpen = false;
}
bounds.height *= (count + 1); bounds.height *= (count + 1);
dropActive = true;
dropOpen = true;
} }
if (CheckCollisionPointRec(mousePoint, bounds)) if (CheckCollisionPointRec(mousePoint, bounds))
@ -1652,15 +1654,6 @@ RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int
else state = FOCUSED; else state = FOCUSED;
} }
else state = NORMAL; else state = NORMAL;
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON) && dropOpen)
{
for (int i = 1; i < (count + 1); i++)
{
if (CheckCollisionPointRec(mousePoint, (Rectangle){ bounds.x, bounds.y + i*bounds.height, bounds.width, bounds.height })) active = i - 1;
}
dropOpen = false;
}
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -1670,7 +1663,7 @@ RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int
{ {
case NORMAL: case NORMAL:
{ {
if (dropActive) GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height/(count + 1) }, text[active], true); if (dropOpen) GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height/(count + 1) }, text[active], true);
else else
{ {
DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[DEFAULT_BASE_COLOR_NORMAL]), guiAlpha)); DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[DEFAULT_BASE_COLOR_NORMAL]), guiAlpha));
@ -1684,7 +1677,7 @@ RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int
} break; } break;
case FOCUSED: case FOCUSED:
{ {
if (dropActive) GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height/(count + 1) }, text[active], true); if (dropOpen) GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height/(count + 1) }, text[active], true);
else GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[active], true); else GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[active], true);
DrawTriangle((Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING, bounds.y + boundsHeight0/2 - 2 }, DrawTriangle((Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING, bounds.y + boundsHeight0/2 - 2 },
@ -1694,10 +1687,10 @@ RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int
case PRESSED: case PRESSED:
{ {
GuiPanel(bounds); GuiPanel(bounds);
if (dropActive) GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height/(count + 1) }, text[active], true); if (dropOpen) GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height/(count + 1) }, text[active], true);
else GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[active], true); else GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[active], true);
if (clicked) if (dropOpen)
{ {
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++)
{ {
@ -1705,7 +1698,6 @@ RAYGUIDEF int GuiDropdownBox(Rectangle bounds, const char **text, int count, int
} }
} }
DrawTriangle((Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING, bounds.y + boundsHeight0/2 - 2 }, DrawTriangle((Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING, bounds.y + boundsHeight0/2 - 2 },
(Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 5, bounds.y + boundsHeight0/2 - 2 + 5 }, (Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 5, bounds.y + boundsHeight0/2 - 2 + 5 },
(Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 10, bounds.y + boundsHeight0/2 - 2 }, Fade(GetColor(style[DEFAULT_TEXT_COLOR_PRESSED]), guiAlpha)); (Vector2){ bounds.x + bounds.width - DROPDOWNBOX_ARROW_RIGHT_PADDING + 10, bounds.y + boundsHeight0/2 - 2 }, Fade(GetColor(style[DEFAULT_TEXT_COLOR_PRESSED]), guiAlpha));
@ -3624,6 +3616,6 @@ static const char *FormatText(const char *text, ...)
return buffer; return buffer;
} }
#endif #endif // RAYGUI_STANDALONE
#endif // RAYGUI_IMPLEMENTATION #endif // RAYGUI_IMPLEMENTATION