From d1defc60f9f8160788900788919631dd1e00869f Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 15 Jun 2017 01:00:39 +0200 Subject: [PATCH] Complete rewrite of all functions --- src/raygui.h | 1019 +++++++++++++++++---------------- tools/rGuiStyler/rguistyler.c | 31 +- 2 files changed, 556 insertions(+), 494 deletions(-) diff --git a/src/raygui.h b/src/raygui.h index 1e182f9..ef5d581 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raygui v1.1 - IMGUI (Immedite Mode GUI) library for raylib (www.raylib.com) +* raygui v1.5 - A simple and easy-to-use IMGUI (Immedite Mode GUI) library for raylib (www.raylib.com) * * DESCRIPTION: * @@ -50,6 +50,8 @@ * Some controls missing, like panels. * * VERSIONS HISTORY: +* 1.5 (15-Jun-2017) Rewrite of all GUI functions (removed useless ones) +* 1.3 (12-Jun-2017) Redesigned styles system * 1.1 (01-Jun-2017) Complete review of the library * 1.0 (07-Jun-2016) Converted to header-only by Ramon Santamaria. * 0.9 (07-Mar-2016) Reviewed and tested by Albert Martos, Ian Eito, Sergio Martinez and Ramon Santamaria. @@ -167,9 +169,9 @@ typedef enum GuiProperty { DEFAULT_TEXT_FONT, DEFAULT_TEXT_SIZE, // Label - LABEL_BORDER_COLOR_NORMAL, - LABEL_BASE_COLOR_NORMAL, LABEL_TEXT_COLOR_NORMAL, + LABEL_TEXT_COLOR_FOCUSED, + LABEL_TEXT_COLOR_PRESSED, // Button BUTTON_BORDER_WIDTH, BUTTON_BORDER_COLOR_NORMAL, @@ -214,6 +216,9 @@ typedef enum GuiProperty { SPINNER_BORDER_COLOR_FOCUSED, SPINNER_BASE_COLOR_FOCUSED, SPINNER_TEXT_COLOR_FOCUSED, + SPINNER_BORDER_COLOR_PRESSED, + SPINNER_BASE_COLOR_PRESSED, + SPINNER_TEXT_COLOR_PRESSED, // ComboBox COMBOBOX_BORDER_WIDTH, COMBOBOX_BUTTON_PADDING, @@ -228,6 +233,7 @@ typedef enum GuiProperty { COMBOBOX_TEXT_COLOR_PRESSED, // CheckBox CHECKBOX_BORDER_WIDTH, + CHECKBOX_INNER_PADDING, CHECKBOX_BORDER_COLOR_NORMAL, CHECKBOX_BASE_COLOR_NORMAL, CHECKBOX_BORDER_COLOR_FOCUSED, @@ -258,8 +264,8 @@ typedef enum GuiProperty { //---------------------------------------------------------------------------------- RAYGUIDEF Color GuiBackgroundColor(void); // Get background color RAYGUIDEF Color GuiLinesColor(void); // Get lines color +RAYGUIDEF Color GuiTextColor(void); // Get text color for normal state RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text); // Label element, show text -RAYGUIDEF void GuiLabelEx(Rectangle bounds, const char *text, Color textColor, Color border, Color inner); // Label element extended, configurable colors RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text); // Button element, returns true when clicked RAYGUIDEF bool GuiToggleButton(Rectangle bounds, const char *text, bool toggle); // Toggle Button element, returns true when active RAYGUIDEF int GuiToggleGroup(Rectangle bounds, int toggleNum, char **toggleText, int toggleActive); // Toggle Group element, returns toggled button index @@ -267,9 +273,9 @@ RAYGUIDEF int GuiComboBox(Rectangle bounds, int comboNum, char **comboText, int RAYGUIDEF bool GuiCheckBox(Rectangle bounds, const char *text, bool checked); // Check Box element, returns true when active RAYGUIDEF float GuiSlider(Rectangle bounds, float value, float minValue, float maxValue); // Slider element, returns selected value RAYGUIDEF float GuiSliderBar(Rectangle bounds, float value, float minValue, float maxValue); // Slider Bar element, returns selected value -RAYGUIDEF void GuiProgressBar(Rectangle bounds, float value); // Progress Bar element, shows current progress value +RAYGUIDEF float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue); // Progress Bar element, shows current progress value RAYGUIDEF int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue); // Spinner element, returns selected value -RAYGUIDEF char *GuiTextBox(Rectangle bounds, char *text); // Text Box element, returns input text +RAYGUIDEF char *GuiTextBox(Rectangle bounds, char *text, int textSize); // Text Box element, returns input text //RAYGUIDEF void UpdateMouse(bool isMouseDown, bool isMouseUp, Vector2 mousePosition); //RAYGUIDEF void UpdateKeys(int keyPressed); @@ -346,9 +352,9 @@ static int style[NUM_PROPERTIES] = { DEFAULT_TEXT_COLOR_NORMAL, // DEFAULT_TEXT_COLOR, 0, // DEFAULT_TEXT_FONT, 10, // DEFAULT_TEXT_SIZE, - DEFAULT_BORDER_COLOR_NORMAL, // LABEL_BORDER_COLOR_NORMAL, - DEFAULT_BASE_COLOR_NORMAL, // LABEL_BASE_COLOR_NORMAL, DEFAULT_TEXT_COLOR_NORMAL, // LABEL_TEXT_COLOR_NORMAL, + DEFAULT_TEXT_COLOR_FOCUSED, // LABEL_TEXT_COLOR_FOCUSED, + DEFAULT_TEXT_COLOR_PRESSED, // LABEL_TEXT_COLOR_PRESSED, 2, // BUTTON_BORDER_WIDTH, DEFAULT_BORDER_COLOR_NORMAL, // BUTTON_BORDER_COLOR_NORMAL, DEFAULT_BASE_COLOR_NORMAL, // BUTTON_BASE_COLOR_NORMAL, @@ -372,11 +378,11 @@ static int style[NUM_PROPERTIES] = { 2, // TOGGLEGROUP_PADDING, 1, // SLIDERBAR_BORDER_WIDTH, DEFAULT_BORDER_COLOR_NORMAL, // SLIDERBAR_BORDER_COLOR_NORMAL, - DEFAULT_BASE_COLOR_PRESSED, // SLIDERBAR_BASE_COLOR_NORMAL, + DEFAULT_BASE_COLOR_NORMAL, // SLIDERBAR_BASE_COLOR_NORMAL, DEFAULT_BORDER_COLOR_FOCUSED, // SLIDERBAR_BORDER_COLOR_FOCUSED, - DEFAULT_BASE_COLOR_FOCUSED, // SLIDERBAR_BASE_COLOR_FOCUSED, + DEFAULT_BASE_COLOR_NORMAL, // SLIDERBAR_BASE_COLOR_FOCUSED, DEFAULT_BORDER_COLOR_PRESSED, // SLIDERBAR_BORDER_COLOR_PRESSED, - DEFAULT_BASE_COLOR_PRESSED, // SLIDERBAR_BASE_COLOR_PRESSED, + DEFAULT_BASE_COLOR_NORMAL, // SLIDERBAR_BASE_COLOR_PRESSED, 1, // PROGRESSBAR_BORDER_WIDTH, DEFAULT_BORDER_COLOR_NORMAL, // PROGRESSBAR_BORDER_COLOR_NORMAL, DEFAULT_BASE_COLOR_NORMAL, // PROGRESSBAR_BASE_COLOR_NORMAL, @@ -388,6 +394,9 @@ static int style[NUM_PROPERTIES] = { DEFAULT_BORDER_COLOR_FOCUSED, // SPINNER_BORDER_COLOR_FOCUSED, DEFAULT_BASE_COLOR_FOCUSED, // SPINNER_BASE_COLOR_FOCUSED, DEFAULT_TEXT_COLOR_FOCUSED, // SPINNER_TEXT_COLOR_FOCUSED, + DEFAULT_BORDER_COLOR_PRESSED, // SPINNER_BORDER_COLOR_PRESSED, + DEFAULT_BASE_COLOR_PRESSED, // SPINNER_BASE_COLOR_PRESSED, + DEFAULT_TEXT_COLOR_PRESSED, // SPINNER_TEXT_COLOR_PRESSED, 1, // COMBOBOX_BORDER_WIDTH, 2, // COMBOBOX_BUTTON_PADDING, DEFAULT_BORDER_COLOR_NORMAL, // COMBOBOX_BORDER_COLOR_NORMAL, @@ -400,8 +409,9 @@ static int style[NUM_PROPERTIES] = { DEFAULT_BASE_COLOR_PRESSED, // COMBOBOX_BASE_COLOR_PRESSED, DEFAULT_TEXT_COLOR_PRESSED, // COMBOBOX_TEXT_COLOR_PRESSED, 1, // CHECKBOX_BORDER_WIDTH, + 1, // CHECKBOX_INNER_PADDING, DEFAULT_BORDER_COLOR_NORMAL, // CHECKBOX_BORDER_COLOR_NORMAL, - DEFAULT_BASE_COLOR_NORMAL, // CHECKBOX_BASE_COLOR_NORMAL, + 0xf5f5f5ff, // CHECKBOX_BASE_COLOR_NORMAL, DEFAULT_BORDER_COLOR_FOCUSED, // CHECKBOX_BORDER_COLOR_FOCUSED, DEFAULT_BASE_COLOR_FOCUSED, // CHECKBOX_BASE_COLOR_FOCUSED, DEFAULT_BORDER_COLOR_PRESSED, // CHECKBOX_BORDER_COLOR_PRESSED, @@ -427,18 +437,18 @@ static int style[NUM_PROPERTIES] = { #if !defined(RAYGUI_NO_STYLE_SAVE_LOAD) // GUI property names (to read/write style text files) static const char *guiPropertyName[] = { - "GLOBAL_BASE_COLOR", - "GLOBAL_BORDER_COLOR", - "GLOBAL_TEXT_COLOR", - "DEFAULT_TEXT_SIZE", - "GLOBAL_BORDER_WIDTH", "DEFAULT_BACKGROUND_COLOR", "DEFAULT_LINES_COLOR", - "LABEL_BORDER_WIDTH", - "LABEL_TEXT_COLOR", - "LABEL_TEXT_PADDING", + "DEFAULT_BORDER_COLOR", + "DEFAULT_BORDER_WIDTH", + "DEFAULT_BASE_COLOR", + "DEFAULT_TEXT_COLOR", + "DEFAULT_TEXT_FONT", + "DEFAULT_TEXT_SIZE", + "LABEL_BORDER_COLOR_NORMAL", + "LABEL_BASE_COLOR_NORMAL", + "LABEL_TEXT_COLOR_NORMAL", "BUTTON_BORDER_WIDTH", - "BUTTON_TEXT_PADDING", "BUTTON_BORDER_COLOR_NORMAL", "BUTTON_BASE_COLOR_NORMAL", "BUTTON_TEXT_COLOR_NORMAL", @@ -448,7 +458,6 @@ static const char *guiPropertyName[] = { "BUTTON_BORDER_COLOR_PRESSED", "BUTTON_BASE_COLOR_PRESSED", "BUTTON_TEXT_COLOR_PRESSED", - "TOGGLE_TEXT_PADDING", "TOGGLE_BORDER_WIDTH", "TOGGLE_BORDER_COLOR_NORMAL", "TOGGLE_BASE_COLOR_NORMAL", @@ -459,73 +468,53 @@ static const char *guiPropertyName[] = { "TOGGLE_BORDER_COLOR_PRESSED", "TOGGLE_BASE_COLOR_PRESSED", "TOGGLE_TEXT_COLOR_PRESSED", - "TOGGLE_BORDER_COLOR_PRESSED", - "TOGGLE_BASE_COLOR_PRESSED", - "TOGGLE_TEXT_COLOR_PRESSED", "TOGGLEGROUP_PADDING", "SLIDERBAR_BORDER_WIDTH", - "SLIDER_BUTTON_BORDER_WIDTH", "SLIDERBAR_BORDER_COLOR_NORMAL", "SLIDERBAR_BASE_COLOR_NORMAL", - "SLIDERBAR_BASE_COLOR_NORMAL", + "SLIDERBAR_BORDER_COLOR_FOCUSED", "SLIDERBAR_BASE_COLOR_FOCUSED", + "SLIDERBAR_BORDER_COLOR_PRESSED", "SLIDERBAR_BASE_COLOR_PRESSED", - "SLIDERBAR_BORDER_COLOR", - "SLIDERBAR_INSIDE_COLOR", - "SLIDERBAR_DEFAULT_COLOR", - "SLIDERBAR_HOVER_COLOR", - "SLIDERBAR_ACTIVE_COLOR", - "SLIDERBAR_ZERO_LINE_COLOR", + "PROGRESSBAR_BORDER_WIDTH", "PROGRESSBAR_BORDER_COLOR_NORMAL", "PROGRESSBAR_BASE_COLOR_NORMAL", "PROGRESSBAR_FRONT_COLOR_NORMAL", - "PROGRESSBAR_BORDER_WIDTH", + "SPINNER_BUTTON_PADDING", "SPINNER_BORDER_COLOR_NORMAL", "SPINNER_BASE_COLOR_NORMAL", - "SPINNER_DEFAULT_BUTTON_BORDER_COLOR", - "SPINNER_DEFAULT_BUTTON_INSIDE_COLOR", - "SPINNER_DEFAULT_SYMBOL_COLOR", "SPINNER_TEXT_COLOR_NORMAL", - "SPINNER_HOVER_BUTTON_BORDER_COLOR", - "SPINNER_HOVER_BUTTON_INSIDE_COLOR", - "SPINNER_HOVER_SYMBOL_COLOR", + "SPINNER_BORDER_COLOR_FOCUSED", + "SPINNER_BASE_COLOR_FOCUSED", "SPINNER_TEXT_COLOR_FOCUSED", - "SPINNER_PRESSED_BUTTON_BORDER_COLOR", - "SPINNER_PRESSED_BUTTON_INSIDE_COLOR", - "SPINNER_PRESSED_SYMBOL_COLOR", - "SPINNER_PRESSED_TEXT_COLOR", - "COMBOBOX_PADDING", - "COMBOBOX_BUTTON_WIDTH", - "COMBOBOX_BUTTON_HEIGHT", "COMBOBOX_BORDER_WIDTH", + "COMBOBOX_BUTTON_PADDING", "COMBOBOX_BORDER_COLOR_NORMAL", "COMBOBOX_BASE_COLOR_NORMAL", "COMBOBOX_TEXT_COLOR_NORMAL", - "BUTTON_TEXT_COLOR_NORMAL", "COMBOBOX_BORDER_COLOR_FOCUSED", "COMBOBOX_BASE_COLOR_FOCUSED", "COMBOBOX_TEXT_COLOR_FOCUSED", - "BUTTON_TEXT_COLOR_FOCUSED", "COMBOBOX_BORDER_COLOR_PRESSED", "COMBOBOX_BASE_COLOR_PRESSED", "COMBOBOX_TEXT_COLOR_PRESSED", - "COMBOBOX_PRESSED_LIST_BORDER_COLOR", - "COMBOBOX_PRESSED_LIST_INSIDE_COLOR", - "COMBOBOX_PRESSED_LIST_TEXT_COLOR", + "CHECKBOX_BORDER_WIDTH", "CHECKBOX_BORDER_COLOR_NORMAL", "CHECKBOX_BASE_COLOR_NORMAL", "CHECKBOX_BORDER_COLOR_FOCUSED", "CHECKBOX_BASE_COLOR_FOCUSED", "CHECKBOX_BORDER_COLOR_PRESSED", "CHECKBOX_BASE_COLOR_PRESSED", - "CHECKBOX_BASE_COLOR_PRESSED", - "CHECKBOX_BORDER_WIDTH", "TEXTBOX_BORDER_WIDTH", "TEXTBOX_BORDER_COLOR_NORMAL", "TEXTBOX_BASE_COLOR_NORMAL", "TEXTBOX_TEXT_COLOR_NORMAL", - "TEXTBOX_LINE_COLOR", - "TEXTBOX_TEXT_FONTSIZE" + "TEXTBOX_BORDER_COLOR_FOCUSED", + "TEXTBOX_BASE_COLOR_FOCUSED", + "TEXTBOX_TEXT_COLOR_FOCUSED", + "TEXTBOX_BORDER_COLOR_PRESSED", + "TEXTBOX_BASE_COLOR_PRESSED", + "TEXTBOX_TEXT_COLOR_PRESSED", }; #endif @@ -568,15 +557,16 @@ RAYGUIDEF Color GuiBackgroundColor(void) { return GetColor(style[DEFAULT_BACKGRO // Get lines color RAYGUIDEF Color GuiLinesColor(void) { return GetColor(style[DEFAULT_LINES_COLOR]); } -// Label element, show text +// Get text color for normal state +RAYGUIDEF Color GuiTextColor(void) { return GetColor(style[DEFAULT_TEXT_COLOR]); } + +// Label element RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text) { - GuiLabelEx(bounds, text, GetColor(style[LABEL_TEXT_COLOR_NORMAL]), (Color){ 0, 0, 0, 0 }, (Color){ 0, 0, 0, 0 }); -} - -// Label element extended, configurable colors -RAYGUIDEF void GuiLabelEx(Rectangle bounds, const char *text, Color textColor, Color border, Color inner) -{ + ControlState state = NORMAL; + + Vector2 mousePoint = GetMousePosition(); + // Update control //-------------------------------------------------------------------- int textWidth = MeasureText(text, style[DEFAULT_TEXT_SIZE]); @@ -584,13 +574,24 @@ RAYGUIDEF void GuiLabelEx(Rectangle bounds, const char *text, Color textColor, C if (bounds.width < textWidth) bounds.width = textWidth; if (bounds.height < textHeight) bounds.height = textHeight; + + // Check label state + if (CheckCollisionPointRec(mousePoint, bounds)) + { + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED; + else state = FOCUSED; + } //-------------------------------------------------------------------- // Draw control //-------------------------------------------------------------------- - DrawRectangleRec(bounds, border); - DrawRectangle(bounds.x + style[DEFAULT_BORDER_WIDTH], bounds.y + style[DEFAULT_BORDER_WIDTH], bounds.width - (2*style[DEFAULT_BORDER_WIDTH]), bounds.height - (2*style[DEFAULT_BORDER_WIDTH]), inner); - DrawText(text, bounds.x + ((bounds.width/2) - (textWidth/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], textColor); + switch (state) + { + case NORMAL: DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[LABEL_TEXT_COLOR_NORMAL])); break; + case FOCUSED: DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[LABEL_TEXT_COLOR_FOCUSED])); break; + case PRESSED: DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[LABEL_TEXT_COLOR_PRESSED])); break; + default: break; + } //-------------------------------------------------------------------- } @@ -602,14 +603,15 @@ RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text) Vector2 mousePoint = GetMousePosition(); bool clicked = false; - int textWidth = MeasureText(text, style[DEFAULT_TEXT_SIZE]); - int textHeight = style[DEFAULT_TEXT_SIZE]; - // Update control //-------------------------------------------------------------------- + int textWidth = MeasureText(text, style[DEFAULT_TEXT_SIZE]); + int textHeight = style[DEFAULT_TEXT_SIZE]; + if (bounds.width < textWidth) bounds.width = textWidth; if (bounds.height < textHeight) bounds.height = textHeight; + // Check button state if (CheckCollisionPointRec(mousePoint, bounds)) { if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED; @@ -625,20 +627,26 @@ RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text) case NORMAL: { DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_NORMAL])); - DrawRectangle((int)(bounds.x + style[BUTTON_BORDER_WIDTH]), (int)(bounds.y + style[BUTTON_BORDER_WIDTH]) , (int)(bounds.width - (2*style[BUTTON_BORDER_WIDTH])), (int)(bounds.height - (2*style[BUTTON_BORDER_WIDTH])), GetColor(style[BUTTON_BASE_COLOR_NORMAL])); - DrawText(text, bounds.x + ((bounds.width/2) - (MeasureText(text, style[DEFAULT_TEXT_SIZE])/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_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])); + DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_NORMAL])); } break; case FOCUSED: { DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_FOCUSED])); - DrawRectangle((int)(bounds.x + style[BUTTON_BORDER_WIDTH]), (int)(bounds.y + style[BUTTON_BORDER_WIDTH]) , (int)(bounds.width - (2*style[BUTTON_BORDER_WIDTH])), (int)(bounds.height - (2*style[BUTTON_BORDER_WIDTH])), GetColor(style[BUTTON_BASE_COLOR_FOCUSED])); - DrawText(text, bounds.x + ((bounds.width/2) - (MeasureText(text, style[DEFAULT_TEXT_SIZE])/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_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])); + DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_FOCUSED])); } break; case PRESSED: { DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_PRESSED])); - DrawRectangle((int)(bounds.x + style[BUTTON_BORDER_WIDTH]), (int)(bounds.y + style[BUTTON_BORDER_WIDTH]) , (int)(bounds.width - (2*style[BUTTON_BORDER_WIDTH])), (int)(bounds.height - (2*style[BUTTON_BORDER_WIDTH])), GetColor(style[BUTTON_BASE_COLOR_PRESSED])); - DrawText(text, bounds.x + ((bounds.width/2) - (MeasureText(text, style[DEFAULT_TEXT_SIZE])/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_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])); + DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_PRESSED])); } break; default: break; } @@ -655,14 +663,15 @@ RAYGUIDEF bool GuiToggleButton(Rectangle bounds, const char *text, bool active) Vector2 mousePoint = GetMousePosition(); - int textWidth = MeasureText(text, style[DEFAULT_TEXT_SIZE]); - int textHeight = style[DEFAULT_TEXT_SIZE]; - // Update control //-------------------------------------------------------------------- + int textWidth = MeasureText(text, style[DEFAULT_TEXT_SIZE]); + int textHeight = style[DEFAULT_TEXT_SIZE]; + if (bounds.width < textWidth) bounds.width = textWidth; if (bounds.height < textHeight) bounds.height = textHeight; + // Check toggle button state if (CheckCollisionPointRec(mousePoint, bounds)) { if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED; @@ -684,27 +693,35 @@ RAYGUIDEF bool GuiToggleButton(Rectangle bounds, const char *text, bool active) if (active) { DrawRectangleRec(bounds, GetColor(style[TOGGLE_BORDER_COLOR_PRESSED])); - DrawRectangle((int)(bounds.x + style[TOGGLE_BORDER_WIDTH]), (int)(bounds.y + style[TOGGLE_BORDER_WIDTH]) , (int)(bounds.width - (2*style[TOGGLE_BORDER_WIDTH])), (int)(bounds.height - (2*style[TOGGLE_BORDER_WIDTH])), GetColor(style[TOGGLE_BASE_COLOR_PRESSED])); - DrawText(text, bounds.x + ((bounds.width/2) - (MeasureText(text, style[DEFAULT_TEXT_SIZE])/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[TOGGLE_TEXT_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])); + DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[TOGGLE_TEXT_COLOR_PRESSED])); } else { DrawRectangleRec(bounds, GetColor(style[TOGGLE_BORDER_COLOR_NORMAL])); - DrawRectangle((int)(bounds.x + style[TOGGLE_BORDER_WIDTH]), (int)(bounds.y + style[TOGGLE_BORDER_WIDTH]) , (int)(bounds.width - (2*style[TOGGLE_BORDER_WIDTH])), (int)(bounds.height - (2*style[TOGGLE_BORDER_WIDTH])), GetColor(style[TOGGLE_BASE_COLOR_NORMAL])); - DrawText(text, bounds.x + ((bounds.width/2) - (MeasureText(text, style[DEFAULT_TEXT_SIZE])/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[TOGGLE_TEXT_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])); + DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[TOGGLE_TEXT_COLOR_NORMAL])); } } break; case FOCUSED: { DrawRectangleRec(bounds, GetColor(style[TOGGLE_BORDER_COLOR_FOCUSED])); - DrawRectangle((int)(bounds.x + style[TOGGLE_BORDER_WIDTH]), (int)(bounds.y + style[TOGGLE_BORDER_WIDTH]) , (int)(bounds.width - (2*style[TOGGLE_BORDER_WIDTH])), (int)(bounds.height - (2*style[TOGGLE_BORDER_WIDTH])), GetColor(style[TOGGLE_BASE_COLOR_FOCUSED])); - DrawText(text, bounds.x + ((bounds.width/2) - (MeasureText(text, style[DEFAULT_TEXT_SIZE])/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[TOGGLE_TEXT_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])); + DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[TOGGLE_TEXT_COLOR_FOCUSED])); } break; case PRESSED: { DrawRectangleRec(bounds, GetColor(style[TOGGLE_BORDER_COLOR_PRESSED])); - DrawRectangle((int)(bounds.x + style[TOGGLE_BORDER_WIDTH]), (int)(bounds.y + style[TOGGLE_BORDER_WIDTH]) , (int)(bounds.width - (2*style[TOGGLE_BORDER_WIDTH])), (int)(bounds.height - (2*style[TOGGLE_BORDER_WIDTH])), GetColor(style[TOGGLE_BASE_COLOR_PRESSED])); - DrawText(text, bounds.x + ((bounds.width/2) - (MeasureText(text, style[DEFAULT_TEXT_SIZE])/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[TOGGLE_TEXT_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])); + DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], GetColor(style[TOGGLE_TEXT_COLOR_PRESSED])); } break; default: break; } @@ -725,103 +742,6 @@ RAYGUIDEF int GuiToggleGroup(Rectangle bounds, int toggleCount, char **toggleTex return active; } -// Combo Box element, returns selected item index -RAYGUIDEF int GuiComboBox(Rectangle bounds, int comboCount, char **comboText, int active) -{ - ControlState state = NORMAL; - - Rectangle click = { bounds.x + bounds.width + style[COMBOBOX_BUTTON_PADDING], bounds.y, bounds.width/comboCount, bounds.height }; - Vector2 mousePoint = GetMousePosition(); - - int textHeight = style[DEFAULT_TEXT_SIZE]; - - bool clicked = false; - - for (int i = 0; i < comboCount; i++) - { - if (i == active) - { - // Update control - //-------------------------------------------------------------------- - int textWidth = MeasureText(comboText[i], style[DEFAULT_TEXT_SIZE]); - - if (bounds.width < textWidth) bounds.width = textWidth; - if (bounds.height < textHeight) bounds.height = textHeight; - - if (CheckCollisionPointRec(mousePoint, bounds) || CheckCollisionPointRec(mousePoint, click)) - { - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED; - else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) clicked = true; - else state = FOCUSED; - } - //-------------------------------------------------------------------- - - // Draw control - //-------------------------------------------------------------------- - switch (state) - { - case NORMAL: - { - DrawRectangleRec(bounds, GetColor(style[COMBOBOX_BORDER_COLOR_NORMAL])); - DrawRectangle((int)(bounds.x + style[COMBOBOX_BORDER_WIDTH]), (int)(bounds.y + style[COMBOBOX_BORDER_WIDTH]), (int)(bounds.width - (2*style[COMBOBOX_BORDER_WIDTH])), (int)(bounds.height - (2*style[COMBOBOX_BORDER_WIDTH])), GetColor(style[COMBOBOX_BASE_COLOR_NORMAL])); - - DrawRectangleRec(click, GetColor(style[COMBOBOX_BORDER_COLOR_NORMAL])); - DrawRectangle((int)(click.x + style[COMBOBOX_BORDER_WIDTH]), (int)(click.y + style[COMBOBOX_BORDER_WIDTH]) , (int)(click.width - (2*style[COMBOBOX_BORDER_WIDTH])), (int)(click.height - (2*style[COMBOBOX_BORDER_WIDTH])), GetColor(style[COMBOBOX_BASE_COLOR_NORMAL])); - DrawText(FormatText("%i/%i", active + 1, comboCount), click.x + ((click.width/2) - (MeasureText(FormatText("%i/%i", active + 1, comboCount), style[DEFAULT_TEXT_SIZE])/2)), click.y + ((click.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_NORMAL])); - DrawText(comboText[i], bounds.x + ((bounds.width/2) - (MeasureText(comboText[i], style[DEFAULT_TEXT_SIZE])/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[COMBOBOX_TEXT_COLOR_NORMAL])); - } break; - case FOCUSED: - { - DrawRectangleRec(bounds, GetColor(style[COMBOBOX_BORDER_COLOR_FOCUSED])); - DrawRectangle((int)(bounds.x + style[COMBOBOX_BORDER_WIDTH]), (int)(bounds.y + style[COMBOBOX_BORDER_WIDTH]), (int)(bounds.width - (2*style[COMBOBOX_BORDER_WIDTH])), (int)(bounds.height - (2*style[COMBOBOX_BORDER_WIDTH])), GetColor(style[COMBOBOX_BASE_COLOR_FOCUSED])); - - DrawRectangleRec(click, GetColor(style[COMBOBOX_BORDER_COLOR_FOCUSED])); - DrawRectangle((int)(click.x + style[COMBOBOX_BORDER_WIDTH]), (int)(click.y + style[COMBOBOX_BORDER_WIDTH]) , (int)(click.width - (2*style[COMBOBOX_BORDER_WIDTH])), (int)(click.height - (2*style[COMBOBOX_BORDER_WIDTH])), GetColor(style[COMBOBOX_BASE_COLOR_FOCUSED])); - DrawText(FormatText("%i/%i", active + 1, comboCount), click.x + ((click.width/2) - (MeasureText(FormatText("%i/%i", active + 1, comboCount), style[DEFAULT_TEXT_SIZE])/2)), click.y + ((click.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_FOCUSED])); - DrawText(comboText[i], bounds.x + ((bounds.width/2) - (MeasureText(comboText[i], style[DEFAULT_TEXT_SIZE])/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[COMBOBOX_TEXT_COLOR_FOCUSED])); - } break; - case PRESSED: - { - DrawRectangleRec(bounds, GetColor(style[COMBOBOX_BORDER_COLOR_PRESSED])); - DrawRectangle((int)(bounds.x + style[COMBOBOX_BORDER_WIDTH]), (int)(bounds.y + style[COMBOBOX_BORDER_WIDTH]), (int)(bounds.width - (2*style[COMBOBOX_BORDER_WIDTH])), (int)(bounds.height - (2*style[COMBOBOX_BORDER_WIDTH])), GetColor(style[COMBOBOX_BASE_COLOR_PRESSED])); - - DrawRectangleRec(click, GetColor(style[COMBOBOX_BORDER_COLOR_PRESSED])); - DrawRectangle((int)(click.x + style[COMBOBOX_BORDER_WIDTH]), (int)(click.y + style[COMBOBOX_BORDER_WIDTH]) , (int)(click.width - (2*style[COMBOBOX_BORDER_WIDTH])), (int)(click.height - (2*style[COMBOBOX_BORDER_WIDTH])), GetColor(style[COMBOBOX_BASE_COLOR_PRESSED])); - DrawText(FormatText("%i/%i", active + 1, comboCount), click.x + ((click.width/2) - (MeasureText(FormatText("%i/%i", active + 1, comboCount), style[DEFAULT_TEXT_SIZE])/2)), click.y + ((click.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[COMBOBOX_TEXT_COLOR_PRESSED])); - DrawText(comboText[i], bounds.x + ((bounds.width/2) - (MeasureText(comboText[i], style[DEFAULT_TEXT_SIZE])/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[COMBOBOX_TEXT_COLOR_PRESSED])); - } break; - default: break; - } - - if (clicked) - { - DrawRectangleRec(bounds, GetColor(style[COMBOBOX_BORDER_COLOR_PRESSED])); - DrawRectangle((int)(bounds.x + style[COMBOBOX_BORDER_WIDTH]), (int)(bounds.y + style[COMBOBOX_BORDER_WIDTH]), (int)(bounds.width - (2 * style[COMBOBOX_BORDER_WIDTH])), (int)(bounds.height - (2*style[COMBOBOX_BORDER_WIDTH])), GetColor(style[COMBOBOX_BASE_COLOR_PRESSED])); - - DrawRectangleRec(click, GetColor(style[COMBOBOX_BORDER_COLOR_PRESSED])); - DrawRectangle((int)(click.x + style[COMBOBOX_BORDER_WIDTH]), (int)(click.y + style[COMBOBOX_BORDER_WIDTH]) , (int)(click.width - (2*style[COMBOBOX_BORDER_WIDTH])), (int)(click.height - (2*style[COMBOBOX_BORDER_WIDTH])), GetColor(style[COMBOBOX_BASE_COLOR_PRESSED])); - DrawText(FormatText("%i/%i", active + 1, comboCount), click.x + ((click.width/2) - (MeasureText(FormatText("%i/%i", active + 1, comboCount), style[DEFAULT_TEXT_SIZE])/2)), click.y + ((click.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[COMBOBOX_TEXT_COLOR_PRESSED])); - DrawText(comboText[i], bounds.x + ((bounds.width/2) - (MeasureText(comboText[i], style[DEFAULT_TEXT_SIZE])/2)), bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[COMBOBOX_TEXT_COLOR_PRESSED])); - } - - //DrawText(comboText[i], bounds.x + ((bounds.width/2) - (MeasureText(comboText[i], style[]globalTextFontSize)/2)), bounds.y + ((bounds.height/2) - (style[]globalTextFontSize/2)), style[]globalTextFontSize, COMBOBOX_TEXT_COLOR_PRESSED); - //-------------------------------------------------------------------- - } - } - - if (CheckCollisionPointRec(mousePoint, bounds) || - CheckCollisionPointRec(mousePoint, click)) - { - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - { - active += 1; - if (active >= comboCount) active = 0; - } - } - - return active; -} - // Check Box element, returns true when active RAYGUIDEF bool GuiCheckBox(Rectangle bounds, const char *text, bool checked) { @@ -831,14 +751,12 @@ RAYGUIDEF bool GuiCheckBox(Rectangle bounds, const char *text, bool checked) // Update control //-------------------------------------------------------------------- + + // Check checkbox state if (CheckCollisionPointRec(mousePoint, bounds)) { if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED; - else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) - { - state = NORMAL; - checked = !checked; - } + else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) checked = !checked; else state = FOCUSED; } //-------------------------------------------------------------------- @@ -850,27 +768,47 @@ RAYGUIDEF bool GuiCheckBox(Rectangle bounds, const char *text, bool checked) case NORMAL: { DrawRectangleRec(bounds, GetColor(style[CHECKBOX_BORDER_COLOR_NORMAL])); - DrawRectangle((int)(bounds.x + style[TOGGLE_BORDER_WIDTH]), (int)(bounds.y + style[TOGGLE_BORDER_WIDTH]), (int)(bounds.width - (2*style[TOGGLE_BORDER_WIDTH])), (int)(bounds.height - (2*style[TOGGLE_BORDER_WIDTH])), GetColor(style[CHECKBOX_BASE_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], + 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])); + if (text != NULL) DrawText(text, bounds.x + bounds.width + 2, bounds.y + bounds.height/2 - style[DEFAULT_TEXT_SIZE]/2, style[DEFAULT_TEXT_SIZE], GetColor(style[DEFAULT_TEXT_COLOR])); + } break; case FOCUSED: { DrawRectangleRec(bounds, GetColor(style[CHECKBOX_BORDER_COLOR_FOCUSED])); - DrawRectangle((int)(bounds.x + style[TOGGLE_BORDER_WIDTH]), (int)(bounds.y + style[TOGGLE_BORDER_WIDTH]), (int)(bounds.width - (2*style[TOGGLE_BORDER_WIDTH])), (int)(bounds.height - (2*style[TOGGLE_BORDER_WIDTH])), GetColor(style[CHECKBOX_BASE_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], + 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[DEFAULT_TEXT_COLOR])); + if (text != NULL) DrawText(text, bounds.x + bounds.width + 2, bounds.y + bounds.height/2 - style[DEFAULT_TEXT_SIZE]/2, style[DEFAULT_TEXT_SIZE], GetColor(style[DEFAULT_TEXT_COLOR_PRESSED])); + } break; case PRESSED: { DrawRectangleRec(bounds, GetColor(style[CHECKBOX_BORDER_COLOR_PRESSED])); - DrawRectangle((int)(bounds.x + style[TOGGLE_BORDER_WIDTH]), (int)(bounds.y + style[TOGGLE_BORDER_WIDTH]), (int)(bounds.width - (2*style[TOGGLE_BORDER_WIDTH])), (int)(bounds.height - (2*style[TOGGLE_BORDER_WIDTH])), GetColor(style[CHECKBOX_BASE_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], + 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])); + if (text != NULL) DrawText(text, bounds.x + bounds.width + 2, bounds.y + bounds.height/2 - style[DEFAULT_TEXT_SIZE]/2, style[DEFAULT_TEXT_SIZE], GetColor(style[DEFAULT_TEXT_COLOR])); + } break; default: break; } - - if (text != NULL) DrawText(text, bounds.x + bounds.width + 2, bounds.y + ((bounds.height/2) - (style[DEFAULT_TEXT_SIZE]/2) + 1), style[DEFAULT_TEXT_SIZE], GetColor(style[DEFAULT_TEXT_COLOR])); - - if (checked) - { - DrawRectangle((int)(bounds.x + style[CHECKBOX_BORDER_WIDTH]), (int)(bounds.y + style[CHECKBOX_BORDER_WIDTH]), (int)(bounds.width - (2*style[CHECKBOX_BORDER_WIDTH])), (int)(bounds.height - (2*style[CHECKBOX_BORDER_WIDTH])), GetColor(style[CHECKBOX_BASE_COLOR_PRESSED])); - } //-------------------------------------------------------------------- return checked; @@ -882,106 +820,103 @@ RAYGUIDEF float GuiSlider(Rectangle bounds, float value, float minValue, float m ControlState state = NORMAL; Vector2 mousePoint = GetMousePosition(); - float buttonTravelDistance = 0; - float sliderPos = 0; // Update control //-------------------------------------------------------------------- if (value < minValue) value = minValue; - else if (value >= maxValue) value = maxValue; + else if (value > maxValue) value = maxValue; - sliderPos = (value - minValue)/(maxValue - minValue); - - Rectangle sliderButton; - sliderButton.width = ((int)(bounds.width - (2*style[SLIDERBAR_BORDER_WIDTH]))/10 - 8); - sliderButton.height = ((int)(bounds.height - (2*style[SLIDERBAR_BORDER_WIDTH] + 2*style[SLIDERBAR_BORDER_WIDTH]))); - - float sliderButtonMinPos = bounds.x + style[SLIDERBAR_BORDER_WIDTH] + style[SLIDERBAR_BORDER_WIDTH]; - float sliderButtonMaxPos = bounds.x + bounds.width - (style[SLIDERBAR_BORDER_WIDTH] + style[SLIDERBAR_BORDER_WIDTH] + sliderButton.width); - - buttonTravelDistance = sliderButtonMaxPos - sliderButtonMinPos; - - sliderButton.x = ((int)(bounds.x + style[SLIDERBAR_BORDER_WIDTH] + style[SLIDERBAR_BORDER_WIDTH]) + (sliderPos * buttonTravelDistance)); - sliderButton.y = ((int)(bounds.y + style[SLIDERBAR_BORDER_WIDTH] + style[SLIDERBAR_BORDER_WIDTH])); + Rectangle slider = { bounds.x + (int)((value/(maxValue - minValue))*(bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH])) - 10, + bounds.y + style[SLIDERBAR_BORDER_WIDTH], // + style[SLIDER_INNER_PADDING]; + 20, bounds.height - 2*style[SLIDERBAR_BORDER_WIDTH] };// - 2*style[SLIDER_INNER_PADDING]; if (CheckCollisionPointRec(mousePoint, bounds)) { - state = FOCUSED; - - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED; - - if ((state == PRESSED) && (IsMouseButtonDown(MOUSE_LEFT_BUTTON))) + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) { - sliderButton.x = mousePoint.x - sliderButton.width/2; + state = PRESSED; + + // Get equivalent value from mousePoint.x + value = (((maxValue - minValue)*(mousePoint.x - (float)bounds.x))/(float)bounds.width) + minValue; + + if (value > maxValue) value = maxValue; + else if (value < minValue) value = minValue; - if (sliderButton.x <= sliderButtonMinPos) sliderButton.x = sliderButtonMinPos; - else if (sliderButton.x >= sliderButtonMaxPos) sliderButton.x = sliderButtonMaxPos; - - sliderPos = (sliderButton.x - sliderButtonMinPos)/buttonTravelDistance; + slider.x = bounds.x + (int)((value/(maxValue - minValue))*(bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH])) - slider.width/2; + + //if (slider.x < (bounds.x + style[PROGRESSBAR_BORDER_WIDTH])) slider.x = bounds.x + style[PROGRESSBAR_BORDER_WIDTH]; + //else if ((slider.x + slider.width) > (bounds.x + bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH])) slider.x = (bounds.x + bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH]) - slider.width; } + else state = FOCUSED; } - else state = NORMAL; //-------------------------------------------------------------------- // Draw control //-------------------------------------------------------------------- - DrawRectangleRec(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_NORMAL])); - DrawRectangle((int)(bounds.x + style[SLIDERBAR_BORDER_WIDTH]), (int)(bounds.y + style[SLIDERBAR_BORDER_WIDTH]), (int)(bounds.width - (2*style[SLIDERBAR_BORDER_WIDTH])), (int)(bounds.height - (2*style[SLIDERBAR_BORDER_WIDTH])), GetColor(style[SLIDERBAR_BASE_COLOR_NORMAL])); - switch (state) { - case NORMAL: DrawRectangleRec(sliderButton, GetColor(style[SLIDERBAR_BASE_COLOR_NORMAL])); break; - case FOCUSED: DrawRectangleRec(sliderButton, GetColor(style[SLIDERBAR_BASE_COLOR_FOCUSED])); break; - case PRESSED: DrawRectangleRec(sliderButton, GetColor(style[SLIDERBAR_BASE_COLOR_PRESSED])); break; + 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])); + } break; + case FOCUSED: + { + 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])); + } break; + case PRESSED: + { + 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])); + } break; default: break; } //-------------------------------------------------------------------- - return minValue + (maxValue - minValue)*sliderPos; + return value; } // Slider Bar element, returns selected value +// NOTE: If minimum value is <0 support multidirection RAYGUIDEF float GuiSliderBar(Rectangle bounds, float value, float minValue, float maxValue) { ControlState state = NORMAL; Vector2 mousePoint = GetMousePosition(); - float fixedValue; - float fixedMinValue; - - fixedValue = value - minValue; - maxValue = maxValue - minValue; - fixedMinValue = 0; + + Rectangle slider = { bounds.x + style[PROGRESSBAR_BORDER_WIDTH], + bounds.y + style[PROGRESSBAR_BORDER_WIDTH], // + style[PROGRESSBAR_INNER_PADDING] + (int)((value/(maxValue - minValue))*(bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH])), + bounds.height - 2*style[PROGRESSBAR_BORDER_WIDTH] }; // - 2*style[PROGRESSBAR_INNER_PADDING] // Update control //-------------------------------------------------------------------- - if (fixedValue <= fixedMinValue) fixedValue = fixedMinValue; - else if (fixedValue >= maxValue) fixedValue = maxValue; - - Rectangle sliderBar; - - sliderBar.x = bounds.x + style[SLIDERBAR_BORDER_WIDTH]; - sliderBar.y = bounds.y + style[SLIDERBAR_BORDER_WIDTH]; - sliderBar.width = ((fixedValue*((float)bounds.width - 2*style[SLIDERBAR_BORDER_WIDTH]))/(maxValue - fixedMinValue)); - sliderBar.height = bounds.height - 2*style[SLIDERBAR_BORDER_WIDTH]; - if (CheckCollisionPointRec(mousePoint, bounds)) { - state = FOCUSED; - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) { state = PRESSED; + + // Get equivalent value from mousePoint.x + value = (((maxValue - minValue)*(mousePoint.x - (float)bounds.x))/(float)bounds.width) + minValue; + + if (value > maxValue) value = maxValue; + else if (value < minValue) value = minValue; - sliderBar.width = (mousePoint.x - bounds.x - style[SLIDERBAR_BORDER_WIDTH]); - - if (mousePoint.x <= (bounds.x + style[SLIDERBAR_BORDER_WIDTH])) sliderBar.width = 0; - else if (mousePoint.x >= (bounds.x + bounds.width - style[SLIDERBAR_BORDER_WIDTH])) sliderBar.width = bounds.width - 2*style[SLIDERBAR_BORDER_WIDTH]; + slider.width = (int)((value/(maxValue - minValue))*(bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH])); } + state = FOCUSED; } - else state = NORMAL; - - fixedValue = ((float)sliderBar.width*(maxValue - fixedMinValue))/((float)bounds.width - 2*style[SLIDERBAR_BORDER_WIDTH]); //-------------------------------------------------------------------- // Draw control @@ -991,75 +926,365 @@ RAYGUIDEF float GuiSliderBar(Rectangle bounds, float value, float minValue, floa case NORMAL: { DrawRectangleRec(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_NORMAL])); - DrawRectangle((int)(bounds.x + style[SLIDERBAR_BORDER_WIDTH]), (int)(bounds.y + style[SLIDERBAR_BORDER_WIDTH]) , (int)(bounds.width - (2*style[SLIDERBAR_BORDER_WIDTH])), (int)(bounds.height - (2*style[SLIDERBAR_BORDER_WIDTH])), GetColor(style[SLIDERBAR_BASE_COLOR_NORMAL])); - DrawRectangleRec(sliderBar, GetColor(style[SLIDERBAR_BASE_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])); } break; case FOCUSED: { DrawRectangleRec(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_FOCUSED])); - DrawRectangle((int)(bounds.x + style[SLIDERBAR_BORDER_WIDTH]), (int)(bounds.y + style[SLIDERBAR_BORDER_WIDTH]) , (int)(bounds.width - (2*style[SLIDERBAR_BORDER_WIDTH])), (int)(bounds.height - (2*style[SLIDERBAR_BORDER_WIDTH])), GetColor(style[SLIDERBAR_BASE_COLOR_FOCUSED])); - DrawRectangleRec(sliderBar, GetColor(style[SLIDERBAR_BASE_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_PRESSED])); } break; case PRESSED: { DrawRectangleRec(bounds, GetColor(style[SLIDERBAR_BORDER_COLOR_PRESSED])); - DrawRectangle((int)(bounds.x + style[SLIDERBAR_BORDER_WIDTH]), (int)(bounds.y + style[SLIDERBAR_BORDER_WIDTH]) , (int)(bounds.width - (2*style[SLIDERBAR_BORDER_WIDTH])), (int)(bounds.height - (2*style[SLIDERBAR_BORDER_WIDTH])), GetColor(style[SLIDERBAR_BASE_COLOR_PRESSED])); - DrawRectangleRec(sliderBar, GetColor(style[SLIDERBAR_BASE_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])); } break; default: break; - } - - if (minValue < 0 && maxValue > 0) DrawRectangle((bounds.x + style[SLIDERBAR_BORDER_WIDTH]) - (minValue*((bounds.width - (style[SLIDERBAR_BORDER_WIDTH]*2))/maxValue)), sliderBar.y, 1, sliderBar.height, GetColor(style[SLIDERBAR_BORDER_COLOR_NORMAL])); + } //-------------------------------------------------------------------- - return fixedValue + minValue; + return value; } // Progress Bar element, shows current progress value -RAYGUIDEF void GuiProgressBar(Rectangle bounds, float value) +RAYGUIDEF float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue) { - if (value > 1.0f) value = 1.0f; - else if (value < 0.0f) value = 0.0f; + ControlState state = NORMAL; + + Vector2 mousePoint = GetMousePosition(); + + Rectangle progress = { bounds.x + style[PROGRESSBAR_BORDER_WIDTH], + bounds.y + style[PROGRESSBAR_BORDER_WIDTH], // + style[PROGRESSBAR_INNER_PADDING] + 0, // TODO + bounds.height - 2*style[PROGRESSBAR_BORDER_WIDTH] }; // - 2*style[PROGRESSBAR_INNER_PADDING] - Rectangle progressBar = { bounds.x + style[PROGRESSBAR_BORDER_WIDTH], bounds.y + style[PROGRESSBAR_BORDER_WIDTH], bounds.width - (style[PROGRESSBAR_BORDER_WIDTH]*2), bounds.height - (style[PROGRESSBAR_BORDER_WIDTH] * 2)}; - Rectangle progressValue = { bounds.x + style[PROGRESSBAR_BORDER_WIDTH], bounds.y + style[PROGRESSBAR_BORDER_WIDTH], value * (bounds.width - (style[PROGRESSBAR_BORDER_WIDTH]*2)), bounds.height - (style[PROGRESSBAR_BORDER_WIDTH] * 2)}; + // Update control + //-------------------------------------------------------------------- + if (value > maxValue) value = maxValue; + else if (value < minValue) value = minValue; + + if (CheckCollisionPointRec(mousePoint, bounds)) + { + state = FOCUSED; + + progress.width = (int)(value/(maxValue - minValue)*(float)(bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH])); + } + //-------------------------------------------------------------------- // Draw control //-------------------------------------------------------------------- - DrawRectangleRec(bounds, GetColor(style[PROGRESSBAR_BORDER_COLOR_NORMAL])); - DrawRectangleRec(progressBar, GetColor(style[PROGRESSBAR_BASE_COLOR_NORMAL])); - DrawRectangleRec(progressValue, GetColor(style[PROGRESSBAR_FRONT_COLOR_NORMAL])); + switch (state) + { + 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(style[PROGRESSBAR_BASE_COLOR_NORMAL])); + DrawRectangleRec(progress, GetColor(style[SLIDERBAR_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(style[SLIDERBAR_BASE_COLOR_FOCUSED])); + DrawRectangleRec(progress, GetColor(style[SLIDERBAR_BASE_COLOR_FOCUSED])); + } break; + case PRESSED: break; + default: break; + } //-------------------------------------------------------------------- + + return value; +} + +// Combo Box element, returns selected item index +RAYGUIDEF int GuiComboBox(Rectangle bounds, int comboCount, char **comboText, int active) +{ + ControlState state = NORMAL; + + Vector2 mousePoint = GetMousePosition(); + bool clicked = false; + + #define COMBOBOX_SELECTOR_WIDTH 35 + + bounds.width -= (COMBOBOX_SELECTOR_WIDTH + style[COMBOBOX_BUTTON_PADDING]); + + Rectangle selector = { bounds.x + bounds.width + style[COMBOBOX_BUTTON_PADDING], + bounds.y, COMBOBOX_SELECTOR_WIDTH, bounds.height }; + + // Update control + //-------------------------------------------------------------------- + if (active < 0) active = 0; + else if (active > comboCount - 1) active = comboCount - 1; + + int textWidth = MeasureText(comboText[active], style[DEFAULT_TEXT_SIZE]); + int textHeight = style[DEFAULT_TEXT_SIZE]; + + if (bounds.width < textWidth) bounds.width = textWidth; + if (bounds.height < textHeight) bounds.height = textHeight; + + if (CheckCollisionPointRec(mousePoint, bounds) || + CheckCollisionPointRec(mousePoint, selector)) + { + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED; + else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) + { + clicked = true; + + active += 1; + if (active >= comboCount) active = 0; + } + else state = FOCUSED; + } + //-------------------------------------------------------------------- + + // Draw control + //-------------------------------------------------------------------- + switch (state) + { + 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])); + + 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])); + + DrawText(comboText[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - style[DEFAULT_TEXT_SIZE]/2, + style[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), + style[DEFAULT_TEXT_SIZE])/2), selector.y + selector.height/2 - style[DEFAULT_TEXT_SIZE]/2, + style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_NORMAL])); + } 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])); + + 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])); + + DrawText(comboText[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - style[DEFAULT_TEXT_SIZE]/2, + style[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), + style[DEFAULT_TEXT_SIZE])/2), selector.y + selector.height/2 - style[DEFAULT_TEXT_SIZE]/2, + style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_FOCUSED])); + } 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])); + + 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])); + + DrawText(comboText[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - style[DEFAULT_TEXT_SIZE]/2, + style[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), + style[DEFAULT_TEXT_SIZE])/2), selector.y + selector.height/2 - style[DEFAULT_TEXT_SIZE]/2, + style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_PRESSED])); + } break; + default: break; + } + //-------------------------------------------------------------------- + + return active; +} + +// Text Box element, returns input text +// NOTE: Requires static variables: framesCounter +RAYGUIDEF char *GuiTextBox(Rectangle bounds, char *text, int textSize) +{ + static int framesCounter = 0; // Required for blinking cursor + + #define KEY_BACKSPACE_TEXT 259 // GLFW BACKSPACE: 3 + 256 + + ControlState state = NORMAL; + + Vector2 mousePoint = GetMousePosition(); + + // Update control + //-------------------------------------------------------------------- + if (CheckCollisionPointRec(mousePoint, bounds)) + { + state = FOCUSED; // NOTE: PRESSED state is not used on this control + + framesCounter++; + + int letter = -1; + letter = GetKeyPressed(); + + if (letter != -1) + { + if (letter == KEY_BACKSPACE_TEXT) + { + for (int i = 0; i < textSize; i++) + { + if ((text[i] == '\0') && (i > 0)) + { + text[i - 1] = '\0'; + break; + } + } + + text[textSize - 1] = '\0'; + } + else + { + if ((letter >= 32) && (letter < 127)) + { + for (int i = 0; i < textSize; i++) + { + if (text[i] == '\0') + { + text[i] = (char)letter; + break; + } + } + } + } + } + } + //-------------------------------------------------------------------- + + // Draw control + //-------------------------------------------------------------------- + switch (state) + { + 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])); + DrawText(text, bounds.x + 4, bounds.y + style[DEFAULT_TEXT_SIZE], style[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])); + DrawText(text, bounds.x + 4, bounds.y + style[DEFAULT_TEXT_SIZE], style[DEFAULT_TEXT_SIZE], GetColor(style[TEXTBOX_TEXT_COLOR_PRESSED])); + + if ((framesCounter/20)%2 == 0) DrawRectangle(bounds.x + 4 + MeasureText(text, style[DEFAULT_TEXT_SIZE]) + 2, bounds.y + 5, 1, 20, GetColor(style[TEXTBOX_BORDER_COLOR_FOCUSED])); + + } break; + case PRESSED: break; // NOTE: PRESSED state is not used on this control + default: break; + } + //-------------------------------------------------------------------- + + return text; } // Spinner element, returns selected value // NOTE: Requires static variables: framesCounter, valueSpeed - ERROR! RAYGUIDEF int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue) -{ +{ ControlState state = NORMAL; + #define SPINNER_LEFT_BUTTON 1 + #define SPINNER_RIGHT_BUTTON 2 + + #define SPINNER_BUTTON_WIDTH 35 + Vector2 mousePoint = GetMousePosition(); - Rectangle labelBoxBound = { bounds.x + bounds.width/4 + 1, bounds.y, bounds.width/2, bounds.height }; - Rectangle leftButtonBound = { bounds.x, bounds.y, bounds.width/4, bounds.height }; - Rectangle rightButtonBound = { bounds.x + bounds.width - bounds.width/4 + 1, bounds.y, bounds.width/4, bounds.height }; - - int textWidth = MeasureText(FormatText("%i", value), style[DEFAULT_TEXT_SIZE]); - //int textHeight = style[DEFAULT_TEXT_SIZE]; // Unused variable - - int buttonSide = 0; - + static int framesCounter = 0; static bool valueSpeed = false;; + + Rectangle spinnerBounds = { bounds.x + SPINNER_BUTTON_WIDTH + style[SPINNER_BUTTON_PADDING], bounds.y, bounds.width - 2*(SPINNER_BUTTON_WIDTH + style[SPINNER_BUTTON_PADDING]), bounds.height }; + Rectangle leftButtonBound = { bounds.x, bounds.y, SPINNER_BUTTON_WIDTH, bounds.height }; + Rectangle rightButtonBound = { bounds.x + bounds.width - SPINNER_BUTTON_WIDTH, bounds.y, SPINNER_BUTTON_WIDTH, bounds.height }; - //if (bounds.width < textWidth) bounds.width = textWidth; - //if (bounds.height < textHeight) bounds.height = textHeight; + int textWidth = MeasureText(FormatText("%i", value), style[DEFAULT_TEXT_SIZE]); + int textHeight = style[DEFAULT_TEXT_SIZE]; + + if (bounds.width < textWidth) bounds.width = textWidth; + if (bounds.height < textHeight) bounds.height = textHeight; // Update control - //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + if (CheckCollisionPointRec(mousePoint, leftButtonBound)) + { + state = FOCUSED; + + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + { + state = PRESSED; + + if (!valueSpeed) + { + if (value > minValue) value--; + valueSpeed = true; + } + else framesCounter++; + + if (value > minValue) + { + if (framesCounter >= 30) value -= 1; + } + } + } + else if (CheckCollisionPointRec(mousePoint, rightButtonBound)) + { + state = FOCUSED; + + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + { + state = PRESSED; + + if (!valueSpeed) + { + if (value < maxValue) value++; + valueSpeed = true; + } + else framesCounter++; + + if (value < maxValue) + { + if (framesCounter >= 30) value += 1; + } + } + } + + if (IsMouseButtonUp(MOUSE_LEFT_BUTTON)) + { + valueSpeed = false; + framesCounter = 0; + } + /* if (CheckCollisionPointRec(mousePoint, leftButtonBound) || CheckCollisionPointRec(mousePoint, rightButtonBound) || - CheckCollisionPointRec(mousePoint, labelBoxBound)) + CheckCollisionPointRec(mousePoint, spinnerBounds)) { if (IsKeyDown(KEY_LEFT)) { @@ -1077,143 +1302,50 @@ RAYGUIDEF int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue } } */ - - if (CheckCollisionPointRec(mousePoint, leftButtonBound)) - { - buttonSide = 1; - state = FOCUSED; - - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) - { - if (!valueSpeed) - { - if (value > minValue) value--; - valueSpeed = true; - } - else framesCounter++; - - state = PRESSED; - - if (value > minValue) - { - if (framesCounter >= 30) value -= 1; - } - } - } - else if (CheckCollisionPointRec(mousePoint, rightButtonBound)) - { - buttonSide = 2; - state = FOCUSED; - - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) - { - if (!valueSpeed) - { - if (value < maxValue) value++; - valueSpeed = true; - } - else framesCounter++; - - state = PRESSED; - - if (value < maxValue) - { - if (framesCounter >= 30) value += 1; - } - } - } - else if (!CheckCollisionPointRec(mousePoint, labelBoxBound)) buttonSide = 0; - - if (IsMouseButtonUp(MOUSE_LEFT_BUTTON)) - { - valueSpeed = false; - framesCounter = 0; - } //-------------------------------------------------------------------- // Draw control //-------------------------------------------------------------------- + if (GuiButton(leftButtonBound, "-")) + { + /* + if (!valueSpeed) + { + if (value > minValue) value--; + valueSpeed = true; + } + else framesCounter++; + + if (value > minValue) + { + if (framesCounter >= 30) value -= 1; + } + */ + } + else if (GuiButton(rightButtonBound, "+")) { } + switch (state) { case NORMAL: { - DrawRectangleRec(leftButtonBound, GetColor(style[BUTTON_BORDER_COLOR_NORMAL])); - DrawRectangle(leftButtonBound.x + 2, leftButtonBound.y + 2, leftButtonBound.width - 4, leftButtonBound.height - 4, GetColor(style[BUTTON_BASE_COLOR_NORMAL])); + DrawRectangleRec(spinnerBounds, GetColor(style[SPINNER_BORDER_COLOR_NORMAL])); + DrawRectangle(spinnerBounds.x + 1, spinnerBounds.y + 1, spinnerBounds.width - 2, spinnerBounds.height - 2, GetColor(style[SPINNER_BASE_COLOR_NORMAL])); - DrawRectangleRec(rightButtonBound, GetColor(style[BUTTON_BORDER_COLOR_NORMAL])); - DrawRectangle(rightButtonBound.x + 2, rightButtonBound.y + 2, rightButtonBound.width - 4, rightButtonBound.height - 4, GetColor(style[BUTTON_BASE_COLOR_NORMAL])); - - DrawText("-", leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText("+", style[DEFAULT_TEXT_SIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_NORMAL])); - DrawText("+", rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText("-", style[DEFAULT_TEXT_SIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_NORMAL])); - - DrawRectangleRec(labelBoxBound, GetColor(style[SPINNER_BORDER_COLOR_NORMAL])); - DrawRectangle(labelBoxBound.x + 1, labelBoxBound.y + 1, labelBoxBound.width - 2, labelBoxBound.height - 2, GetColor(style[SPINNER_BASE_COLOR_NORMAL])); - - DrawText(FormatText("%i", value), labelBoxBound.x + (labelBoxBound.width/2 - textWidth/2), labelBoxBound.y + (labelBoxBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_TEXT_COLOR_NORMAL])); + DrawText(FormatText("%i", value), spinnerBounds.x + (spinnerBounds.width/2 - textWidth/2), spinnerBounds.y + (spinnerBounds.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_TEXT_COLOR_NORMAL])); } break; case FOCUSED: { - /* - if (buttonSide == 1) - { - DrawRectangleRec(leftButtonBound, GetColor(style[BUTTON_BORDER_COLOR_FOCUSED])); - DrawRectangle(leftButtonBound.x + 2, leftButtonBound.y + 2, leftButtonBound.width - 4, leftButtonBound.height - 4, GetColor(style[BUTTON_BASE_COLOR_FOCUSED])); + DrawRectangleRec(spinnerBounds, GetColor(style[SPINNER_BORDER_COLOR_FOCUSED])); + DrawRectangle(spinnerBounds.x + 1, spinnerBounds.y + 1, spinnerBounds.width - 2, spinnerBounds.height - 2, GetColor(style[SPINNER_BASE_COLOR_FOCUSED])); - DrawRectangleRec(rightButtonBound, GetColor(style[BUTTON_BORDER_COLOR_NORMAL])); - DrawRectangle(rightButtonBound.x + 2, rightButtonBound.y + 2, rightButtonBound.width - 4, rightButtonBound.height - 4, GetColor(style[BUTTON_BORDER_COLOR_NORMAL])); - - DrawText("-", leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText("+", style[DEFAULT_TEXT_SIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_HOVER_SYMBOL_COLOR])); - DrawText("+", rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText("-", style[DEFAULT_TEXT_SIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR])); - } - else if (buttonSide == 2) - { - DrawRectangleRec(leftButtonBound, GetColor(style[BUTTON_BORDER_COLOR_FOCUSED])); - DrawRectangle(leftButtonBound.x + 2, leftButtonBound.y + 2, leftButtonBound.width - 4, leftButtonBound.height - 4, GetColor(style[SPINNER_DEFAULT_BUTTON_INSIDE_COLOR])); - - DrawRectangleRec(rightButtonBound, GetColor(style[SPINNER_HOVER_BUTTON_BORDER_COLOR])); - DrawRectangle(rightButtonBound.x + 2, rightButtonBound.y + 2, rightButtonBound.width - 4, rightButtonBound.height - 4, GetColor(style[SPINNER_HOVER_BUTTON_INSIDE_COLOR])); - - DrawText("-", leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText("+", style[DEFAULT_TEXT_SIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR])); - DrawText("+", rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText("-", style[DEFAULT_TEXT_SIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_HOVER_SYMBOL_COLOR])); - } - */ - - DrawRectangleRec(labelBoxBound, GetColor(style[SPINNER_BORDER_COLOR_NORMAL])); - DrawRectangle(labelBoxBound.x + 1, labelBoxBound.y + 1, labelBoxBound.width - 2, labelBoxBound.height - 2, GetColor(style[SPINNER_BASE_COLOR_NORMAL])); - - DrawText(FormatText("%i", value), labelBoxBound.x + (labelBoxBound.width/2 - textWidth/2), labelBoxBound.y + (labelBoxBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_TEXT_COLOR_FOCUSED])); + DrawText(FormatText("%i", value), spinnerBounds.x + (spinnerBounds.width/2 - textWidth/2), spinnerBounds.y + (spinnerBounds.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_TEXT_COLOR_FOCUSED])); } break; case PRESSED: { - /* - if (buttonSide == 1) - { - DrawRectangleRec(leftButtonBound, GetColor(style[SPINNER_PRESSED_BUTTON_BORDER_COLOR])); - DrawRectangle(leftButtonBound.x + 2, leftButtonBound.y + 2, leftButtonBound.width - 4, leftButtonBound.height - 4, GetColor(style[SPINNER_PRESSED_BUTTON_INSIDE_COLOR])); + DrawRectangleRec(spinnerBounds, GetColor(style[SPINNER_BORDER_COLOR_PRESSED])); + DrawRectangle(spinnerBounds.x + 1, spinnerBounds.y + 1, spinnerBounds.width - 2, spinnerBounds.height - 2, GetColor(style[SPINNER_BASE_COLOR_PRESSED])); - DrawRectangleRec(rightButtonBound, GetColor(style[SPINNER_DEFAULT_BUTTON_BORDER_COLOR])); - DrawRectangle(rightButtonBound.x + 2, rightButtonBound.y + 2, rightButtonBound.width - 4, rightButtonBound.height - 4, GetColor(style[SPINNER_DEFAULT_BUTTON_INSIDE_COLOR])); - - DrawText("-", leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText("+", style[DEFAULT_TEXT_SIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_PRESSED_SYMBOL_COLOR])); - DrawText("+", rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText("-", style[DEFAULT_TEXT_SIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR])); - } - else if (buttonSide == 2) - { - DrawRectangleRec(leftButtonBound, GetColor(style[SPINNER_DEFAULT_BUTTON_BORDER_COLOR])); - DrawRectangle(leftButtonBound.x + 2, leftButtonBound.y + 2, leftButtonBound.width - 4, leftButtonBound.height - 4, GetColor(style[SPINNER_DEFAULT_BUTTON_INSIDE_COLOR])); - - DrawRectangleRec(rightButtonBound, GetColor(style[SPINNER_PRESSED_BUTTON_BORDER_COLOR])); - DrawRectangle(rightButtonBound.x + 2, rightButtonBound.y + 2, rightButtonBound.width - 4, rightButtonBound.height - 4, GetColor(style[SPINNER_PRESSED_BUTTON_INSIDE_COLOR])); - - DrawText("-", leftButtonBound.x + (leftButtonBound.width/2 - (MeasureText("+", style[DEFAULT_TEXT_SIZE]))/2), leftButtonBound.y + (leftButtonBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_DEFAULT_SYMBOL_COLOR])); - DrawText("+", rightButtonBound.x + (rightButtonBound.width/2 - (MeasureText("-", style[DEFAULT_TEXT_SIZE]))/2), rightButtonBound.y + (rightButtonBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_PRESSED_SYMBOL_COLOR])); - } - */ - - DrawRectangleRec(labelBoxBound, GetColor(style[SPINNER_BORDER_COLOR_NORMAL])); - DrawRectangle(labelBoxBound.x + 1, labelBoxBound.y + 1, labelBoxBound.width - 2, labelBoxBound.height - 2, GetColor(style[SPINNER_BASE_COLOR_NORMAL])); - - //DrawText(FormatText("%i", value), labelBoxBound.x + (labelBoxBound.width/2 - textWidth/2), labelBoxBound.y + (labelBoxBound.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_TEXT_COLOR_PRESSED])); + DrawText(FormatText("%i", value), spinnerBounds.x + (spinnerBounds.width/2 - textWidth/2), spinnerBounds.y + (spinnerBounds.height/2 - (style[DEFAULT_TEXT_SIZE]/2)), style[DEFAULT_TEXT_SIZE], GetColor(style[SPINNER_TEXT_COLOR_PRESSED])); } break; default: break; } @@ -1221,75 +1353,6 @@ RAYGUIDEF int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue return value; } -// Text Box element, returns input text -// NOTE: Requires static variables: framesCounter -RAYGUIDEF char *GuiTextBox(Rectangle bounds, char *text) -{ - static int framesCounter = 0; // Required for blinking cursor - - #define MAX_CHARS_LENGTH 20 - #define KEY_BACKSPACE_TEXT 259 // GLFW BACKSPACE: 3 + 256 - - Vector2 mousePoint = GetMousePosition(); - int initPos = bounds.x + 4; - int letter = -1; - - // Update control - //-------------------------------------------------------------------- - framesCounter++; - - letter = GetKeyPressed(); - - if (CheckCollisionPointRec(mousePoint, bounds)) - { - if (letter != -1) - { - if (letter == KEY_BACKSPACE_TEXT) - { - for (int i = 0; i < MAX_CHARS_LENGTH; i++) - { - if ((text[i] == '\0') && (i > 0)) - { - text[i - 1] = '\0'; - break; - } - } - - text[MAX_CHARS_LENGTH - 1] = '\0'; - } - else - { - if ((letter >= 32) && (letter < 127)) - { - for (int i = 0; i < MAX_CHARS_LENGTH; i++) - { - if (text[i] == '\0') - { - text[i] = (char)letter; - break; - } - } - } - } - } - } - //-------------------------------------------------------------------- - - // Draw control - //-------------------------------------------------------------------- - if (CheckCollisionPointRec(mousePoint, bounds)) DrawRectangleRec(bounds, GetColor(style[TOGGLE_BORDER_COLOR_PRESSED])); - else DrawRectangleRec(bounds, GetColor(style[TEXTBOX_BORDER_COLOR_NORMAL])); - - DrawRectangle(bounds.x + style[TEXTBOX_BORDER_WIDTH], bounds.y + style[TEXTBOX_BORDER_WIDTH], bounds.width - (style[TEXTBOX_BORDER_WIDTH]*2), bounds.height - (style[TEXTBOX_BORDER_WIDTH]*2), GetColor(style[TEXTBOX_BASE_COLOR_NORMAL])); - - DrawText(text, initPos, bounds.y + style[DEFAULT_TEXT_SIZE], style[DEFAULT_TEXT_SIZE], GetColor(style[TEXTBOX_TEXT_COLOR_NORMAL])); - - if ((framesCounter/20)%2 && CheckCollisionPointRec(mousePoint, bounds)) DrawRectangle(initPos + MeasureText(text, style[DEFAULT_TEXT_SIZE]) + 2, bounds.y + 5, 1, 20, GetColor(style[TEXTBOX_BORDER_COLOR_NORMAL])); - //-------------------------------------------------------------------- - - return text; -} - RAYGUIDEF void GuiBeginPanel(Rectangle rec) { //offset = (Vector2){ rec.x, rec.y }; diff --git a/tools/rGuiStyler/rguistyler.c b/tools/rGuiStyler/rguistyler.c index 7cfbd6f..1586ffe 100644 --- a/tools/rGuiStyler/rguistyler.c +++ b/tools/rGuiStyler/rguistyler.c @@ -273,10 +273,9 @@ int main() int toggleNum = 3; char *toggleGuiText[3] = { "toggle", "group", "selection" }; - float sliderValue = 50; - float sliderBarValue = 50; - - float progressValue = 0; + float sliderValue = 50.0f; + float sliderBarValue = 50.0f; + float progressValue = 0.0f; int spinnerValue = 20; @@ -284,7 +283,7 @@ int main() char *comboText[5] = { "this", "is", "a" ,"combo", "box" }; int comboActive = 0; - char *guiText = (char *)malloc(20); + char *guiText = (char *)malloc(32); guiText[0] = '\0'; bool isModified = false; @@ -484,10 +483,10 @@ int main() } // Update style color value - if (guiPropertySelected == BACKGROUND_COLOR) bgColor = colorPickerValue; + if (guiPropertySelected == DEFAULT_BACKGROUND_COLOR) bgColor = colorPickerValue; else if ((guiPropertySelected >= 0) && (guiPropertyType[guiPropertySelected] == 0)) { - bgColor = GetColor(GetStyleProperty(BACKGROUND_COLOR)); + bgColor = GetColor(GetStyleProperty(DEFAULT_BACKGROUND_COLOR)); SetStyleProperty(guiPropertySelected, GetHexValue(colorPickerValue)); } } @@ -518,7 +517,7 @@ int main() DrawRectangle(400,0, screenWidth - 320 - 400, GetScreenHeight() - STATUS_BAR_HEIGHT, bgColor); GuiLabel((Rectangle){guiPosX, guiPosY, guiWidth, guiHeight}, "Label"); - GuiLabelEx((Rectangle){guiPosX + deltaX, guiPosY, guiWidth, guiHeight}, "LabelEx", BLACK, BLACK, WHITE); + //GuiLabelEx((Rectangle){guiPosX + deltaX, guiPosY, guiWidth, guiHeight}, "LabelEx", BLACK, BLACK, WHITE); if (GuiButton((Rectangle){guiPosX, guiPosY + deltaY, guiWidth, guiHeight}, "Button")) { } @@ -529,18 +528,18 @@ int main() sliderValue = GuiSlider((Rectangle){guiPosX, guiPosY + 4*deltaY, 3*guiWidth, guiHeight}, sliderValue, 0, 100); - sliderBarValue = GuiSliderBar((Rectangle){guiPosX, guiPosY + 5*deltaY, 3*guiWidth, guiHeight}, sliderBarValue, -50, 50); + sliderBarValue = GuiSliderBar((Rectangle){guiPosX, guiPosY + 5*deltaY, 3*guiWidth, guiHeight}, sliderBarValue, 0, 100); - GuiProgressBar((Rectangle){guiPosX, guiPosY + 6*deltaY, 3*guiWidth, guiHeight}, progressValue); + GuiProgressBar((Rectangle){guiPosX, guiPosY + 6*deltaY, 3*guiWidth, guiHeight}, progressValue, 0.0f, 1.0f); spinnerValue = GuiSpinner((Rectangle){guiPosX, guiPosY + 7*deltaY, guiWidth, guiHeight}, spinnerValue, 0, 100); comboActive = GuiComboBox((Rectangle){guiPosX, guiPosY + 8*deltaY, guiWidth, guiHeight}, comboNum, comboText, comboActive); - GuiCheckBox((Rectangle){guiPosX, guiPosY + 9*deltaY, guiWidth/5, guiHeight}, "", false); - GuiCheckBox((Rectangle){guiPosX + deltaX/4, guiPosY + 9*deltaY, guiWidth/5, guiHeight}, "", true); + GuiCheckBox((Rectangle){guiPosX, guiPosY + 9*deltaY, guiWidth/5, guiHeight}, NULL, false); + GuiCheckBox((Rectangle){guiPosX + deltaX/4, guiPosY + 9*deltaY, guiWidth/5, guiHeight}, NULL, true); - guiText = GuiTextBox((Rectangle){guiPosX, guiPosY + 10*deltaY, guiWidth, guiHeight}, guiText); + guiText = GuiTextBox((Rectangle){guiPosX, guiPosY + 10*deltaY, guiWidth, guiHeight}, guiText, 32); if (guiElementSelected >= 0) DrawRectangleRec(guiElementRec[guiElementSelected], COLOR_REC); if (guiElementHover >= 0) DrawRectangleRec(guiElementRec[guiElementHover], Fade(COLOR_REC, 0.5f)); @@ -613,13 +612,13 @@ int main() } // -- RGBA sliders - GuiLabelEx((Rectangle){colorPickerPos.x, colorPickerPos.y + texColorPicker.height + 14*rgbDelta, rgbWidthLabel, rgbHeightLabel}, FormatText("%d", redValue), BLACK, COLOR_REC, RED); + //GuiLabelEx((Rectangle){colorPickerPos.x, colorPickerPos.y + texColorPicker.height + 14*rgbDelta, rgbWidthLabel, rgbHeightLabel}, FormatText("%d", redValue), BLACK, COLOR_REC, RED); redValue = GuiSlider((Rectangle){colorPickerPos.x + rgbWidthLabel + rgbDelta, colorPickerPos.y + texColorPicker.height + 14*rgbDelta, texColorPicker.height - rgbWidthLabel - rgbDelta, rgbHeightLabel}, redValue, 0, 255); - GuiLabelEx((Rectangle){colorPickerPos.x, colorPickerPos.y + texColorPicker.height + 15*rgbDelta + rgbHeightLabel, rgbWidthLabel, rgbHeightLabel}, FormatText("%d", greenValue), BLACK, COLOR_REC, GREEN); + //GuiLabelEx((Rectangle){colorPickerPos.x, colorPickerPos.y + texColorPicker.height + 15*rgbDelta + rgbHeightLabel, rgbWidthLabel, rgbHeightLabel}, FormatText("%d", greenValue), BLACK, COLOR_REC, GREEN); greenValue = GuiSlider((Rectangle){colorPickerPos.x + rgbWidthLabel + rgbDelta, colorPickerPos.y + texColorPicker.height + 15*rgbDelta + rgbHeightLabel, texColorPicker.height - rgbWidthLabel - rgbDelta, rgbHeightLabel}, greenValue, 0, 255); - GuiLabelEx((Rectangle){colorPickerPos.x, colorPickerPos.y + texColorPicker.height + 16*rgbDelta + 2*rgbHeightLabel, rgbWidthLabel, rgbHeightLabel}, FormatText("%d", blueValue), BLACK, COLOR_REC, BLUE); + //GuiLabelEx((Rectangle){colorPickerPos.x, colorPickerPos.y + texColorPicker.height + 16*rgbDelta + 2*rgbHeightLabel, rgbWidthLabel, rgbHeightLabel}, FormatText("%d", blueValue), BLACK, COLOR_REC, BLUE); blueValue = GuiSlider((Rectangle){colorPickerPos.x + rgbWidthLabel + rgbDelta, colorPickerPos.y + texColorPicker.height + 16*rgbDelta + 2*rgbHeightLabel, texColorPicker.height - rgbWidthLabel - rgbDelta, rgbHeightLabel}, blueValue, 0, 255); DrawTextureRec(texChecked, (Rectangle){0,0,rgbWidthLabel, rgbHeightLabel}, (Vector2){colorPickerPos.x, colorPickerPos.y + texColorPicker.height + 17*rgbDelta + 3*rgbHeightLabel}, WHITE);