diff --git a/src/raygui.h b/src/raygui.h index 67d9357..6bcd67f 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -560,10 +560,11 @@ static const char *FormatText(const char *text, ...); // Formatting of text wi // Drawing related functions static int MeasureText(const char *text, int fontSize) { /* TODO */ return 0; } static void DrawText(const char *text, int posX, int posY, int fontSize, Color color) { /* TODO */ } -static void DrawRectangleRec(Rectangle rec, Color color) { /* TODO */ } -static void DrawRectangle(int posX, int posY, int width, int height, Color color) { DrawRectangleRec((Rectangle){ posX, posY, width, height }, color); } +static void DrawRectangleRecT(Rectangle rec, Color color) { /* TODO */ } #endif +static void DrawRectangleRecT(Rectangle rec, Color color); + //---------------------------------------------------------------------------------- // Module Functions Definition //---------------------------------------------------------------------------------- @@ -643,26 +644,20 @@ RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text) { case NORMAL: { - DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_NORMAL])); - DrawRectangle(bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], - bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH], - GetColor(style[BUTTON_BASE_COLOR_NORMAL])); + DrawRectangleRecT(bounds, GetColor(style[BUTTON_BORDER_COLOR_NORMAL])); + DrawRectangleRecT((Rectangle){ bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH] }, GetColor(style[BUTTON_BASE_COLOR_NORMAL])); DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, DEFAULT_TEXT_SIZE, GetColor(style[BUTTON_TEXT_COLOR_NORMAL])); } break; case FOCUSED: { - DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_FOCUSED])); - DrawRectangle(bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], - bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH], - GetColor(style[BUTTON_BASE_COLOR_FOCUSED])); + DrawRectangleRecT(bounds, GetColor(style[BUTTON_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH] }, GetColor(style[BUTTON_BASE_COLOR_FOCUSED])); DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, DEFAULT_TEXT_SIZE, GetColor(style[BUTTON_TEXT_COLOR_FOCUSED])); } break; case PRESSED: { - DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_PRESSED])); - DrawRectangle(bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], - bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH], - GetColor(style[BUTTON_BASE_COLOR_PRESSED])); + DrawRectangleRecT(bounds, GetColor(style[BUTTON_BORDER_COLOR_PRESSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH] }, GetColor(style[BUTTON_BASE_COLOR_PRESSED])); DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, DEFAULT_TEXT_SIZE, GetColor(style[BUTTON_TEXT_COLOR_PRESSED])); } break; default: break; @@ -709,35 +704,27 @@ RAYGUIDEF bool GuiToggleButton(Rectangle bounds, const char *text, bool active) { if (active) { - DrawRectangleRec(bounds, GetColor(style[TOGGLE_BORDER_COLOR_PRESSED])); - DrawRectangle(bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], - bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH], - GetColor(style[TOGGLE_BASE_COLOR_PRESSED])); + DrawRectangleRecT(bounds, GetColor(style[TOGGLE_BORDER_COLOR_PRESSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH] }, GetColor(style[TOGGLE_BASE_COLOR_PRESSED])); DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, DEFAULT_TEXT_SIZE, GetColor(style[TOGGLE_TEXT_COLOR_PRESSED])); } else { - DrawRectangleRec(bounds, GetColor(style[TOGGLE_BORDER_COLOR_NORMAL])); - DrawRectangle(bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], - bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH], - GetColor(style[TOGGLE_BASE_COLOR_NORMAL])); + DrawRectangleRecT(bounds, GetColor(style[TOGGLE_BORDER_COLOR_NORMAL])); + DrawRectangleRecT((Rectangle){ bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH] }, GetColor(style[TOGGLE_BASE_COLOR_NORMAL])); DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, DEFAULT_TEXT_SIZE, GetColor(style[TOGGLE_TEXT_COLOR_NORMAL])); } } break; case FOCUSED: { - DrawRectangleRec(bounds, GetColor(style[TOGGLE_BORDER_COLOR_FOCUSED])); - DrawRectangle(bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], - bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH], - GetColor(style[TOGGLE_BASE_COLOR_FOCUSED])); + DrawRectangleRecT(bounds, GetColor(style[TOGGLE_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH] }, GetColor(style[TOGGLE_BASE_COLOR_FOCUSED])); DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, DEFAULT_TEXT_SIZE, GetColor(style[TOGGLE_TEXT_COLOR_FOCUSED])); } break; case PRESSED: { - DrawRectangleRec(bounds, GetColor(style[TOGGLE_BORDER_COLOR_PRESSED])); - DrawRectangle(bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], - bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH], - GetColor(style[TOGGLE_BASE_COLOR_PRESSED])); + DrawRectangleRecT(bounds, GetColor(style[TOGGLE_BORDER_COLOR_PRESSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH] }, GetColor(style[TOGGLE_BASE_COLOR_PRESSED])); DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, DEFAULT_TEXT_SIZE, GetColor(style[TOGGLE_TEXT_COLOR_PRESSED])); } break; default: break; @@ -784,39 +771,30 @@ RAYGUIDEF bool GuiCheckBox(Rectangle bounds, bool checked) { case NORMAL: { - DrawRectangleRec(bounds, GetColor(style[CHECKBOX_BORDER_COLOR_NORMAL])); - DrawRectangle(bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], - bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH], - GetColor(style[CHECKBOX_BASE_COLOR_NORMAL])); - if (checked) DrawRectangle(bounds.x + style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING], + DrawRectangleRecT(bounds, GetColor(style[CHECKBOX_BORDER_COLOR_NORMAL])); + DrawRectangleRecT((Rectangle){ bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH] }, GetColor(style[CHECKBOX_BASE_COLOR_NORMAL])); + if (checked) DrawRectangleRecT((Rectangle){ bounds.x + style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING], bounds.y + style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING], bounds.width - 2*(style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING]), - bounds.height - 2*(style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING]), - GetColor(style[CHECKBOX_BASE_COLOR_PRESSED])); + bounds.height - 2*(style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING]) }, GetColor(style[CHECKBOX_BASE_COLOR_PRESSED])); } break; case FOCUSED: { - DrawRectangleRec(bounds, GetColor(style[CHECKBOX_BORDER_COLOR_FOCUSED])); - DrawRectangle(bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], - bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH], - GetColor(style[CHECKBOX_BASE_COLOR_NORMAL])); - if (checked) DrawRectangle(bounds.x + style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING], + DrawRectangleRecT(bounds, GetColor(style[CHECKBOX_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH] }, GetColor(style[CHECKBOX_BASE_COLOR_NORMAL])); + if (checked) DrawRectangleRecT((Rectangle){ bounds.x + style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING], bounds.y + style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING], bounds.width - 2*(style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING]), - bounds.height - 2*(style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING]), - GetColor(style[CHECKBOX_BASE_COLOR_FOCUSED])); + bounds.height - 2*(style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING]) }, GetColor(style[CHECKBOX_BASE_COLOR_FOCUSED])); } break; case PRESSED: { - DrawRectangleRec(bounds, GetColor(style[CHECKBOX_BORDER_COLOR_PRESSED])); - DrawRectangle(bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], - bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH], - GetColor(style[CHECKBOX_BASE_COLOR_NORMAL])); - if (checked) DrawRectangle(bounds.x + style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING], + DrawRectangleRecT(bounds, GetColor(style[CHECKBOX_BORDER_COLOR_PRESSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[TOGGLE_BORDER_WIDTH], bounds.y + style[TOGGLE_BORDER_WIDTH], bounds.width - 2*style[TOGGLE_BORDER_WIDTH], bounds.height - 2*style[TOGGLE_BORDER_WIDTH] }, GetColor(style[CHECKBOX_BASE_COLOR_NORMAL])); + if (checked) DrawRectangleRecT((Rectangle){ bounds.x + style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING], bounds.y + style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING], bounds.width - 2*(style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING]), - bounds.height - 2*(style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING]), - GetColor(style[CHECKBOX_BASE_COLOR_PRESSED])); + bounds.height - 2*(style[CHECKBOX_BORDER_WIDTH] + style[CHECKBOX_INNER_PADDING]) }, GetColor(style[CHECKBOX_BASE_COLOR_PRESSED])); } break; default: break; } @@ -831,9 +809,8 @@ RAYGUIDEF int GuiComboBox(Rectangle bounds, int comboCount, char **comboText, in { ControlState state = NORMAL; - Vector2 mousePoint = GetMousePosition(); - bool clicked = false; - + Vector2 mousePoint = GetMousePosition(); + #define COMBOBOX_SELECTOR_WIDTH 35 bounds.width -= (COMBOBOX_SELECTOR_WIDTH + style[COMBOBOX_BUTTON_PADDING]); @@ -858,8 +835,6 @@ RAYGUIDEF int GuiComboBox(Rectangle bounds, int comboCount, char **comboText, in if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED; else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) { - clicked = true; - active += 1; if (active >= comboCount) active = 0; } @@ -873,18 +848,13 @@ RAYGUIDEF int GuiComboBox(Rectangle bounds, int comboCount, char **comboText, in { case NORMAL: { - DrawRectangleRec(bounds, GetColor(style[COMBOBOX_BORDER_COLOR_NORMAL])); - DrawRectangle(bounds.x + style[COMBOBOX_BORDER_WIDTH], bounds.y + style[COMBOBOX_BORDER_WIDTH], - bounds.width - 2*style[COMBOBOX_BORDER_WIDTH], bounds.height - 2*style[COMBOBOX_BORDER_WIDTH], - GetColor(style[COMBOBOX_BASE_COLOR_NORMAL])); + DrawRectangleRecT(bounds, GetColor(style[COMBOBOX_BORDER_COLOR_NORMAL])); + DrawRectangleRecT((Rectangle){ bounds.x + style[COMBOBOX_BORDER_WIDTH], bounds.y + style[COMBOBOX_BORDER_WIDTH], bounds.width - 2*style[COMBOBOX_BORDER_WIDTH], bounds.height - 2*style[COMBOBOX_BORDER_WIDTH] }, GetColor(style[COMBOBOX_BASE_COLOR_NORMAL])); - DrawRectangleRec(selector, GetColor(style[COMBOBOX_BORDER_COLOR_NORMAL])); - DrawRectangle(selector.x + style[COMBOBOX_BORDER_WIDTH], selector.y + style[COMBOBOX_BORDER_WIDTH], - selector.width - 2*style[COMBOBOX_BORDER_WIDTH], selector.height - 2*style[COMBOBOX_BORDER_WIDTH], - GetColor(style[COMBOBOX_BASE_COLOR_NORMAL])); + DrawRectangleRecT(selector, GetColor(style[COMBOBOX_BORDER_COLOR_NORMAL])); + DrawRectangleRecT((Rectangle){ selector.x + style[COMBOBOX_BORDER_WIDTH], selector.y + style[COMBOBOX_BORDER_WIDTH], selector.width - 2*style[COMBOBOX_BORDER_WIDTH], selector.height - 2*style[COMBOBOX_BORDER_WIDTH] }, GetColor(style[COMBOBOX_BASE_COLOR_NORMAL])); - DrawText(comboText[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - DEFAULT_TEXT_SIZE/2, - DEFAULT_TEXT_SIZE, GetColor(style[COMBOBOX_TEXT_COLOR_NORMAL])); + DrawText(comboText[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - DEFAULT_TEXT_SIZE/2, DEFAULT_TEXT_SIZE, GetColor(style[COMBOBOX_TEXT_COLOR_NORMAL])); DrawText(FormatText("%i/%i", active + 1, comboCount), selector.x + selector.width/2 - (MeasureText(FormatText("%i/%i", active + 1, comboCount), DEFAULT_TEXT_SIZE)/2), selector.y + selector.height/2 - DEFAULT_TEXT_SIZE/2, @@ -892,18 +862,13 @@ RAYGUIDEF int GuiComboBox(Rectangle bounds, int comboCount, char **comboText, in } break; case FOCUSED: { - DrawRectangleRec(bounds, GetColor(style[COMBOBOX_BORDER_COLOR_FOCUSED])); - DrawRectangle(bounds.x + style[COMBOBOX_BORDER_WIDTH], bounds.y + style[COMBOBOX_BORDER_WIDTH], - bounds.width - 2*style[COMBOBOX_BORDER_WIDTH], bounds.height - 2*style[COMBOBOX_BORDER_WIDTH], - GetColor(style[COMBOBOX_BASE_COLOR_FOCUSED])); + DrawRectangleRecT(bounds, GetColor(style[COMBOBOX_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[COMBOBOX_BORDER_WIDTH], bounds.y + style[COMBOBOX_BORDER_WIDTH], bounds.width - 2*style[COMBOBOX_BORDER_WIDTH], bounds.height - 2*style[COMBOBOX_BORDER_WIDTH] }, GetColor(style[COMBOBOX_BASE_COLOR_FOCUSED])); - DrawRectangleRec(selector, GetColor(style[COMBOBOX_BORDER_COLOR_FOCUSED])); - DrawRectangle(selector.x + style[COMBOBOX_BORDER_WIDTH], selector.y + style[COMBOBOX_BORDER_WIDTH], - selector.width - 2*style[COMBOBOX_BORDER_WIDTH], selector.height - 2*style[COMBOBOX_BORDER_WIDTH], - GetColor(style[COMBOBOX_BASE_COLOR_FOCUSED])); + DrawRectangleRecT(selector, GetColor(style[COMBOBOX_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT((Rectangle){ selector.x + style[COMBOBOX_BORDER_WIDTH], selector.y + style[COMBOBOX_BORDER_WIDTH], selector.width - 2*style[COMBOBOX_BORDER_WIDTH], selector.height - 2*style[COMBOBOX_BORDER_WIDTH] }, GetColor(style[COMBOBOX_BASE_COLOR_FOCUSED])); - DrawText(comboText[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - DEFAULT_TEXT_SIZE/2, - DEFAULT_TEXT_SIZE, GetColor(style[COMBOBOX_TEXT_COLOR_FOCUSED])); + DrawText(comboText[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - DEFAULT_TEXT_SIZE/2, DEFAULT_TEXT_SIZE, GetColor(style[COMBOBOX_TEXT_COLOR_FOCUSED])); DrawText(FormatText("%i/%i", active + 1, comboCount), selector.x + selector.width/2 - (MeasureText(FormatText("%i/%i", active + 1, comboCount), DEFAULT_TEXT_SIZE)/2), selector.y + selector.height/2 - DEFAULT_TEXT_SIZE/2, @@ -911,18 +876,13 @@ RAYGUIDEF int GuiComboBox(Rectangle bounds, int comboCount, char **comboText, in } break; case PRESSED: { - DrawRectangleRec(bounds, GetColor(style[COMBOBOX_BORDER_COLOR_PRESSED])); - DrawRectangle(bounds.x + style[COMBOBOX_BORDER_WIDTH], bounds.y + style[COMBOBOX_BORDER_WIDTH], - bounds.width - 2*style[COMBOBOX_BORDER_WIDTH], bounds.height - 2*style[COMBOBOX_BORDER_WIDTH], - GetColor(style[COMBOBOX_BASE_COLOR_PRESSED])); + DrawRectangleRecT(bounds, GetColor(style[COMBOBOX_BORDER_COLOR_PRESSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[COMBOBOX_BORDER_WIDTH], bounds.y + style[COMBOBOX_BORDER_WIDTH], bounds.width - 2*style[COMBOBOX_BORDER_WIDTH], bounds.height - 2*style[COMBOBOX_BORDER_WIDTH] }, GetColor(style[COMBOBOX_BASE_COLOR_PRESSED])); - DrawRectangleRec(selector, GetColor(style[COMBOBOX_BORDER_COLOR_PRESSED])); - DrawRectangle(selector.x + style[COMBOBOX_BORDER_WIDTH], selector.y + style[COMBOBOX_BORDER_WIDTH], - selector.width - 2*style[COMBOBOX_BORDER_WIDTH], selector.height - 2*style[COMBOBOX_BORDER_WIDTH], - GetColor(style[COMBOBOX_BASE_COLOR_PRESSED])); + DrawRectangleRecT(selector, GetColor(style[COMBOBOX_BORDER_COLOR_PRESSED])); + DrawRectangleRecT((Rectangle){ selector.x + style[COMBOBOX_BORDER_WIDTH], selector.y + style[COMBOBOX_BORDER_WIDTH], selector.width - 2*style[COMBOBOX_BORDER_WIDTH], selector.height - 2*style[COMBOBOX_BORDER_WIDTH] }, GetColor(style[COMBOBOX_BASE_COLOR_PRESSED])); - DrawText(comboText[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - DEFAULT_TEXT_SIZE/2, - DEFAULT_TEXT_SIZE, GetColor(style[COMBOBOX_TEXT_COLOR_PRESSED])); + DrawText(comboText[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - DEFAULT_TEXT_SIZE/2, DEFAULT_TEXT_SIZE, GetColor(style[COMBOBOX_TEXT_COLOR_PRESSED])); DrawText(FormatText("%i/%i", active + 1, comboCount), selector.x + selector.width/2 - (MeasureText(FormatText("%i/%i", active + 1, comboCount), DEFAULT_TEXT_SIZE)/2), selector.y + selector.height/2 - DEFAULT_TEXT_SIZE/2, @@ -978,27 +938,21 @@ RAYGUIDEF float GuiSlider(Rectangle bounds, float value, float minValue, float m { case NORMAL: { - DrawRectangleRec(bounds, GetColor(style[SLIDER_BORDER_COLOR_NORMAL])); - DrawRectangle(bounds.x + style[SLIDER_BORDER_WIDTH], bounds.y + style[SLIDER_BORDER_WIDTH], - bounds.width - 2*style[SLIDER_BORDER_WIDTH], bounds.height - 2*style[SLIDER_BORDER_WIDTH], - GetColor(DEFAULT_BACKGROUND_COLOR)); - DrawRectangleRec(slider, GetColor(style[SLIDER_BASE_COLOR_NORMAL])); + DrawRectangleRecT(bounds, GetColor(style[SLIDER_BORDER_COLOR_NORMAL])); + DrawRectangleRecT((Rectangle){ bounds.x + style[SLIDER_BORDER_WIDTH], bounds.y + style[SLIDER_BORDER_WIDTH], bounds.width - 2*style[SLIDER_BORDER_WIDTH], bounds.height - 2*style[SLIDER_BORDER_WIDTH] }, GetColor(DEFAULT_BACKGROUND_COLOR)); + DrawRectangleRecT(slider, GetColor(style[SLIDER_BASE_COLOR_NORMAL])); } break; case FOCUSED: { - DrawRectangleRec(bounds, GetColor(style[SLIDER_BORDER_COLOR_FOCUSED])); - DrawRectangle(bounds.x + style[SLIDER_BORDER_WIDTH], bounds.y + style[SLIDER_BORDER_WIDTH], - bounds.width - 2*style[SLIDER_BORDER_WIDTH], bounds.height - 2*style[SLIDER_BORDER_WIDTH], - GetColor(DEFAULT_BACKGROUND_COLOR)); - DrawRectangleRec(slider, GetColor(style[SLIDER_BASE_COLOR_FOCUSED])); + DrawRectangleRecT(bounds, GetColor(style[SLIDER_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[SLIDER_BORDER_WIDTH], bounds.y + style[SLIDER_BORDER_WIDTH], bounds.width - 2*style[SLIDER_BORDER_WIDTH], bounds.height - 2*style[SLIDER_BORDER_WIDTH] }, GetColor(DEFAULT_BACKGROUND_COLOR)); + DrawRectangleRecT(slider, GetColor(style[SLIDER_BASE_COLOR_FOCUSED])); } break; case PRESSED: { - DrawRectangleRec(bounds, GetColor(style[SLIDER_BORDER_COLOR_PRESSED])); - DrawRectangle(bounds.x + style[SLIDER_BORDER_WIDTH], bounds.y + style[SLIDER_BORDER_WIDTH], - bounds.width - 2*style[SLIDER_BORDER_WIDTH], bounds.height - 2*style[SLIDER_BORDER_WIDTH], - GetColor(DEFAULT_BACKGROUND_COLOR)); - DrawRectangleRec(slider, GetColor(style[SLIDER_BASE_COLOR_PRESSED])); + DrawRectangleRecT(bounds, GetColor(style[SLIDER_BORDER_COLOR_PRESSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[SLIDER_BORDER_WIDTH], bounds.y + style[SLIDER_BORDER_WIDTH], bounds.width - 2*style[SLIDER_BORDER_WIDTH], bounds.height - 2*style[SLIDER_BORDER_WIDTH] }, GetColor(DEFAULT_BACKGROUND_COLOR)); + DrawRectangleRecT(slider, GetColor(style[SLIDER_BASE_COLOR_PRESSED])); } break; default: break; } @@ -1046,27 +1000,21 @@ RAYGUIDEF float GuiSliderBar(Rectangle bounds, float value, float minValue, floa { case NORMAL: { - DrawRectangleRec(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_NORMAL])); - DrawRectangle(bounds.x + style[SLIDERBAR_BORDER_WIDTH], bounds.y + style[SLIDERBAR_BORDER_WIDTH], - bounds.width - 2*style[SLIDERBAR_BORDER_WIDTH], bounds.height - 2*style[SLIDERBAR_BORDER_WIDTH], - GetColor(style[SLIDERBAR_BASE_COLOR_NORMAL])); - DrawRectangleRec(slider, GetColor(style[SLIDERBAR_BORDER_COLOR_PRESSED])); + DrawRectangleRecT(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_NORMAL])); + DrawRectangleRecT((Rectangle){ bounds.x + style[SLIDERBAR_BORDER_WIDTH], bounds.y + style[SLIDERBAR_BORDER_WIDTH], bounds.width - 2*style[SLIDERBAR_BORDER_WIDTH], bounds.height - 2*style[SLIDERBAR_BORDER_WIDTH] }, GetColor(style[SLIDERBAR_BASE_COLOR_NORMAL])); + DrawRectangleRecT(slider, GetColor(style[SLIDERBAR_BORDER_COLOR_PRESSED])); } break; case FOCUSED: { - DrawRectangleRec(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_FOCUSED])); - DrawRectangle(bounds.x + style[SLIDERBAR_BORDER_WIDTH], bounds.y + style[SLIDERBAR_BORDER_WIDTH], - bounds.width - 2*style[SLIDERBAR_BORDER_WIDTH], bounds.height - 2*style[SLIDERBAR_BORDER_WIDTH], - GetColor(style[SLIDERBAR_BASE_COLOR_FOCUSED])); - DrawRectangleRec(slider, GetColor(style[SLIDERBAR_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[SLIDERBAR_BORDER_WIDTH], bounds.y + style[SLIDERBAR_BORDER_WIDTH], bounds.width - 2*style[SLIDERBAR_BORDER_WIDTH], bounds.height - 2*style[SLIDERBAR_BORDER_WIDTH] }, GetColor(style[SLIDERBAR_BASE_COLOR_FOCUSED])); + DrawRectangleRecT(slider, GetColor(style[SLIDERBAR_BORDER_COLOR_FOCUSED])); } break; case PRESSED: { - DrawRectangleRec(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_PRESSED])); - DrawRectangle(bounds.x + style[SLIDERBAR_BORDER_WIDTH], bounds.y + style[SLIDERBAR_BORDER_WIDTH], - bounds.width - 2*style[SLIDERBAR_BORDER_WIDTH], bounds.height - 2*style[SLIDERBAR_BORDER_WIDTH], - GetColor(style[SLIDERBAR_BASE_COLOR_PRESSED])); - DrawRectangleRec(slider, GetColor(style[SLIDERBAR_BORDER_COLOR_PRESSED])); + DrawRectangleRecT(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_PRESSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[SLIDERBAR_BORDER_WIDTH], bounds.y + style[SLIDERBAR_BORDER_WIDTH], bounds.width - 2*style[SLIDERBAR_BORDER_WIDTH], bounds.height - 2*style[SLIDERBAR_BORDER_WIDTH] }, GetColor(style[SLIDERBAR_BASE_COLOR_PRESSED])); + DrawRectangleRecT(slider, GetColor(style[SLIDERBAR_BORDER_COLOR_PRESSED])); } break; default: break; } @@ -1103,19 +1051,15 @@ RAYGUIDEF float GuiProgressBar(Rectangle bounds, float value, float minValue, fl { case NORMAL: { - DrawRectangleRec(bounds, GetColor(style[PROGRESSBAR_BORDER_COLOR_NORMAL])); - DrawRectangle(bounds.x + style[PROGRESSBAR_BORDER_WIDTH], bounds.y + style[PROGRESSBAR_BORDER_WIDTH], - bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH], bounds.height - 2*style[PROGRESSBAR_BORDER_WIDTH], - GetColor(DEFAULT_BACKGROUND_COLOR)); - DrawRectangleRec(progress, GetColor(style[PROGRESSBAR_BASE_COLOR_NORMAL])); + DrawRectangleRecT(bounds, GetColor(style[PROGRESSBAR_BORDER_COLOR_NORMAL])); + DrawRectangleRecT((Rectangle){ bounds.x + style[PROGRESSBAR_BORDER_WIDTH], bounds.y + style[PROGRESSBAR_BORDER_WIDTH], bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH], bounds.height - 2*style[PROGRESSBAR_BORDER_WIDTH] }, GetColor(DEFAULT_BACKGROUND_COLOR)); + DrawRectangleRecT(progress, GetColor(style[PROGRESSBAR_BASE_COLOR_NORMAL])); } break; case FOCUSED: { - DrawRectangleRec(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_FOCUSED])); - DrawRectangle(bounds.x + style[SLIDERBAR_BORDER_WIDTH], bounds.y + style[SLIDERBAR_BORDER_WIDTH], - bounds.width - 2*style[SLIDERBAR_BORDER_WIDTH], bounds.height - 2*style[SLIDERBAR_BORDER_WIDTH], - GetColor(DEFAULT_BACKGROUND_COLOR)); - DrawRectangleRec(progress, GetColor(style[PROGRESSBAR_BASE_COLOR_FOCUSED])); + DrawRectangleRecT(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[SLIDERBAR_BORDER_WIDTH], bounds.y + style[SLIDERBAR_BORDER_WIDTH], bounds.width - 2*style[SLIDERBAR_BORDER_WIDTH], bounds.height - 2*style[SLIDERBAR_BORDER_WIDTH] }, GetColor(DEFAULT_BACKGROUND_COLOR)); + DrawRectangleRecT(progress, GetColor(style[PROGRESSBAR_BASE_COLOR_FOCUSED])); } break; case PRESSED: break; default: break; @@ -1249,22 +1193,22 @@ RAYGUIDEF int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue { case NORMAL: { - DrawRectangleRec(spinner, GetColor(style[SPINNER_BORDER_COLOR_NORMAL])); - DrawRectangle(spinner.x + 1, spinner.y + 1, spinner.width - 2, spinner.height - 2, GetColor(style[SPINNER_BASE_COLOR_NORMAL])); + DrawRectangleRecT(spinner, GetColor(style[SPINNER_BORDER_COLOR_NORMAL])); + DrawRectangleRecT((Rectangle){ spinner.x + 1, spinner.y + 1, spinner.width - 2, spinner.height - 2 }, GetColor(style[SPINNER_BASE_COLOR_NORMAL])); DrawText(FormatText("%i", value), spinner.x + (spinner.width/2 - textWidth/2), spinner.y + (spinner.height/2 - (DEFAULT_TEXT_SIZE/2)), DEFAULT_TEXT_SIZE, GetColor(style[SPINNER_TEXT_COLOR_NORMAL])); } break; case FOCUSED: { - DrawRectangleRec(spinner, GetColor(style[SPINNER_BORDER_COLOR_FOCUSED])); - DrawRectangle(spinner.x + 1, spinner.y + 1, spinner.width - 2, spinner.height - 2, GetColor(style[SPINNER_BASE_COLOR_FOCUSED])); + DrawRectangleRecT(spinner, GetColor(style[SPINNER_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT((Rectangle){ spinner.x + 1, spinner.y + 1, spinner.width - 2, spinner.height - 2 }, GetColor(style[SPINNER_BASE_COLOR_FOCUSED])); DrawText(FormatText("%i", value), spinner.x + (spinner.width/2 - textWidth/2), spinner.y + (spinner.height/2 - (DEFAULT_TEXT_SIZE/2)), DEFAULT_TEXT_SIZE, GetColor(style[SPINNER_TEXT_COLOR_FOCUSED])); } break; case PRESSED: { - DrawRectangleRec(spinner, GetColor(style[SPINNER_BORDER_COLOR_PRESSED])); - DrawRectangle(spinner.x + 1, spinner.y + 1, spinner.width - 2, spinner.height - 2, GetColor(style[SPINNER_BASE_COLOR_PRESSED])); + DrawRectangleRecT(spinner, GetColor(style[SPINNER_BORDER_COLOR_PRESSED])); + DrawRectangleRecT((Rectangle){ spinner.x + 1, spinner.y + 1, spinner.width - 2, spinner.height - 2 }, GetColor(style[SPINNER_BASE_COLOR_PRESSED])); DrawText(FormatText("%i", value), spinner.x + (spinner.width/2 - textWidth/2), spinner.y + (spinner.height/2 - (DEFAULT_TEXT_SIZE/2)), DEFAULT_TEXT_SIZE, GetColor(style[SPINNER_TEXT_COLOR_PRESSED])); } break; @@ -1336,22 +1280,18 @@ RAYGUIDEF void GuiTextBox(Rectangle bounds, char *text, int textSize) { case NORMAL: { - DrawRectangleRec(bounds, GetColor(style[TEXTBOX_BORDER_COLOR_NORMAL])); - DrawRectangle(bounds.x + style[TEXTBOX_BORDER_WIDTH], bounds.y + style[TEXTBOX_BORDER_WIDTH], - bounds.width - 2*style[TEXTBOX_BORDER_WIDTH], bounds.height - 2*style[TEXTBOX_BORDER_WIDTH], - GetColor(style[TEXTBOX_BASE_COLOR_NORMAL])); + DrawRectangleRecT(bounds, GetColor(style[TEXTBOX_BORDER_COLOR_NORMAL])); + DrawRectangleRecT((Rectangle){ bounds.x + style[TEXTBOX_BORDER_WIDTH], bounds.y + style[TEXTBOX_BORDER_WIDTH], bounds.width - 2*style[TEXTBOX_BORDER_WIDTH], bounds.height - 2*style[TEXTBOX_BORDER_WIDTH] }, GetColor(style[TEXTBOX_BASE_COLOR_NORMAL])); DrawText(text, bounds.x + 4, bounds.y + style[TEXTBOX_BORDER_WIDTH] + bounds.height/2 - DEFAULT_TEXT_SIZE/2, DEFAULT_TEXT_SIZE, GetColor(style[TEXTBOX_TEXT_COLOR_NORMAL])); } break; case FOCUSED: { - DrawRectangleRec(bounds, GetColor(style[TOGGLE_BORDER_COLOR_FOCUSED])); - DrawRectangle(bounds.x + style[TEXTBOX_BORDER_WIDTH], bounds.y + style[TEXTBOX_BORDER_WIDTH], - bounds.width - 2*style[TEXTBOX_BORDER_WIDTH], bounds.height - 2*style[TEXTBOX_BORDER_WIDTH], - GetColor(style[TEXTBOX_BASE_COLOR_FOCUSED])); + DrawRectangleRecT(bounds, GetColor(style[TOGGLE_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[TEXTBOX_BORDER_WIDTH], bounds.y + style[TEXTBOX_BORDER_WIDTH], bounds.width - 2*style[TEXTBOX_BORDER_WIDTH], bounds.height - 2*style[TEXTBOX_BORDER_WIDTH] }, GetColor(style[TEXTBOX_BASE_COLOR_FOCUSED])); DrawText(text, bounds.x + 4, bounds.y + style[TEXTBOX_BORDER_WIDTH] + bounds.height/2 - DEFAULT_TEXT_SIZE/2, DEFAULT_TEXT_SIZE, GetColor(style[TEXTBOX_TEXT_COLOR_PRESSED])); - if ((framesCounter/20)%2 == 0) DrawRectangle(bounds.x + 4 + MeasureText(text, DEFAULT_TEXT_SIZE), bounds.y + 2, 1, bounds.height - 4, GetColor(style[TEXTBOX_BORDER_COLOR_FOCUSED])); + if ((framesCounter/20)%2 == 0) DrawRectangleRecT((Rectangle){ bounds.x + 4 + MeasureText(text, DEFAULT_TEXT_SIZE), bounds.y + 2, 1, bounds.height - 4 }, GetColor(style[TEXTBOX_BORDER_COLOR_FOCUSED])); } break; case PRESSED: break; // NOTE: PRESSED state is not used on this control @@ -1386,26 +1326,20 @@ RAYGUIDEF bool GuiTexture(Rectangle bounds, Texture2D texture) { case NORMAL: { - DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_NORMAL])); - DrawRectangle(bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], - bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH], - GetColor(style[BUTTON_BASE_COLOR_NORMAL])); + DrawRectangleRecT(bounds, GetColor(style[BUTTON_BORDER_COLOR_NORMAL])); + DrawRectangleRecT((Rectangle){ bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH] }, GetColor(style[BUTTON_BASE_COLOR_NORMAL])); DrawTexture(texture, bounds.x, bounds.y, WHITE); } break; case FOCUSED: { - DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_FOCUSED])); - DrawRectangle(bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], - bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH], - GetColor(style[BUTTON_BASE_COLOR_FOCUSED])); + DrawRectangleRecT(bounds, GetColor(style[BUTTON_BORDER_COLOR_FOCUSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH] }, GetColor(style[BUTTON_BASE_COLOR_FOCUSED])); DrawTexture(texture, bounds.x, bounds.y, GetColor(style[BUTTON_BASE_COLOR_FOCUSED])); } break; case PRESSED: { - DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_PRESSED])); - DrawRectangle(bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], - bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH], - GetColor(style[BUTTON_BASE_COLOR_PRESSED])); + DrawRectangleRecT(bounds, GetColor(style[BUTTON_BORDER_COLOR_PRESSED])); + DrawRectangleRecT((Rectangle){ bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH] }, GetColor(style[BUTTON_BASE_COLOR_PRESSED])); DrawTexture(texture, bounds.x, bounds.y, GetColor(style[BUTTON_BASE_COLOR_PRESSED])); } break; default: break; @@ -1537,6 +1471,20 @@ static const char *FormatText(const char *text, ...) return buffer; } + +static void DrawRectangleRecT(Rectangle rec, Color color) +{ + DrawTexturePro(GetDefaultFont().texture, GetDefaultFont().chars[127].rec, + (Rectangle){ x, y, width, height }, (Vector2){ 0, 0 }, 0.0f, color); +} +/* +void SetDrawRectangleFunc(void (* DrawRectangle)(Rectangle rec, Color color)) +{ + DrawRectangleRecT(rec, color); +} + +SetDrawRectangleFunc(DrawRectangleT); +*/ #endif #endif // RAYGUI_IMPLEMENTATION