Spacing and code tweaks

This commit is contained in:
Ray
2018-11-06 15:50:31 +01:00
parent 1052e6a4cb
commit da19c6305a

View File

@ -4,7 +4,8 @@
* *
* DESCRIPTION: * DESCRIPTION:
* *
* raygui is a library for creating simple IMGUI interfaces using raylib, intended for tools dev. * raygui is a tools-dev-focused immediate-mode-gui library based on raylib but also possible
* to be used as a standalone library, as long as input and drawing functions are provided.
* *
* Basic controls provided: * Basic controls provided:
* *
@ -60,7 +61,7 @@
* *
* *
* VERSIONS HISTORY: * VERSIONS HISTORY:
* 2.0 (01-May-2018) Lot of rework and redesign! Lots of new controls! * 2.0 (01-Nov-2018) Lot of rework and redesign! Lots of new controls!
* 1.5 (21-Jun-2017) Working in an improved styles system * 1.5 (21-Jun-2017) Working in an improved styles system
* 1.4 (15-Jun-2017) Rewritten all GUI functions (removed useless ones) * 1.4 (15-Jun-2017) Rewritten all GUI functions (removed useless ones)
* 1.3 (12-Jun-2017) Redesigned styles system * 1.3 (12-Jun-2017) Redesigned styles system
@ -71,13 +72,13 @@
* *
* CONTRIBUTORS: * CONTRIBUTORS:
* Ramon Santamaria: Supervision, review, redesign, update and maintenance... * Ramon Santamaria: Supervision, review, redesign, update and maintenance...
* Kevin Gato: Initial implementation of basic components (2014) * Sergio Martinez: Review, testing (2015) and redesign of multiple controls (2018)
* Daniel Nicolas: Initial implementation of basic components (2014)
* Albert Martos: Review and testing of the library (2015)
* Ian Eito: Review and testing of the library (2015)
* Sergio Martinez: Review and testing of the library (2015)
* Adria Arranz: Testing and Implementation of additional controls (2018) * Adria Arranz: Testing and Implementation of additional controls (2018)
* Jordi Jorba: Testing and Implementation of additional controls (2018) * Jordi Jorba: Testing and Implementation of additional controls (2018)
* Albert Martos: Review and testing of the library (2015)
* Ian Eito: Review and testing of the library (2015)
* Kevin Gato: Initial implementation of basic components (2014)
* Daniel Nicolas: Initial implementation of basic components (2014)
* *
* *
* LICENSE: zlib/libpng * LICENSE: zlib/libpng
@ -367,8 +368,8 @@ RAYGUIDEF void GuiEnable(void); // Enabl
RAYGUIDEF void GuiDisable(void); // Disable gui controls (global state) RAYGUIDEF void GuiDisable(void); // Disable gui controls (global state)
RAYGUIDEF void GuiLock(void); // Lock gui controls (global state) RAYGUIDEF void GuiLock(void); // Lock gui controls (global state)
RAYGUIDEF void GuiUnlock(void); // Unlock gui controls (global state) RAYGUIDEF void GuiUnlock(void); // Unlock gui controls (global state)
RAYGUIDEF void GuiState(int state); // Set gui state (global state) RAYGUIDEF void GuiState(int state); // Set gui state (global state)
RAYGUIDEF void GuiFont(Font font); // Define custom gui font (global state) RAYGUIDEF void GuiFont(Font font); // Set gui custom font (global state)
RAYGUIDEF void GuiFade(float alpha); // Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f RAYGUIDEF void GuiFade(float alpha); // Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f
// Style set/get functions // Style set/get functions
@ -387,13 +388,13 @@ RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text);
RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked
RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text); // Label button control, show true when clicked RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text); // Label button control, show true when clicked
RAYGUIDEF bool GuiImageButton(Rectangle bounds, Texture2D texture); // Image button control, returns true when clicked RAYGUIDEF bool GuiImageButton(Rectangle bounds, Texture2D texture); // Image button control, returns true when clicked
RAYGUIDEF bool GuiImageButtonEx(Rectangle bounds, Texture2D texture, Rectangle texSource, const char *text); // Image button extended control, returns true when clicked RAYGUIDEF bool GuiImageButtonEx(Rectangle bounds, Texture2D texture, Rectangle texSource, const char *text); // Image button extended control, returns true when clicked
RAYGUIDEF bool GuiToggleButton(Rectangle bounds, const char *text, bool toggle); // Toggle Button control, returns true when active RAYGUIDEF bool GuiToggleButton(Rectangle bounds, const char *text, bool toggle); // Toggle Button control, returns true when active
RAYGUIDEF int GuiToggleGroup(Rectangle bounds, const char **text, int count, int active); // Toggle Group control, returns toggled button index RAYGUIDEF int GuiToggleGroup(Rectangle bounds, const char **text, int count, int active); // Toggle Group control, returns toggled button index
RAYGUIDEF bool GuiCheckBox(Rectangle bounds, bool checked); // Check Box control, returns true when active RAYGUIDEF bool GuiCheckBox(Rectangle bounds, bool checked); // Check Box control, returns true when active
RAYGUIDEF bool GuiCheckBoxEx(Rectangle bounds, bool checked, const char *text); // Check Box control with text, returns true when active RAYGUIDEF bool GuiCheckBoxEx(Rectangle bounds, bool checked, const char *text); // Check Box control with text, returns true when active
RAYGUIDEF int GuiComboBox(Rectangle bounds, const char **text, int count, int active); // Combo Box control, returns selected item index RAYGUIDEF int GuiComboBox(Rectangle bounds, const char **text, int count, int active); // Combo Box control, returns selected item index
RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char **text, int count, int *active, bool editMode); // Dropdown Box control, returns selected item RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char **text, int count, int *active, bool editMode); // Dropdown Box control, returns selected item
RAYGUIDEF bool GuiSpinner(Rectangle bounds, int *value, int minValue, int maxValue, int btnWidth, bool editMode); // Spinner control, returns selected value RAYGUIDEF bool GuiSpinner(Rectangle bounds, int *value, int minValue, int maxValue, int btnWidth, bool editMode); // Spinner control, returns selected value
RAYGUIDEF bool GuiValueBox(Rectangle bounds, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers RAYGUIDEF bool GuiValueBox(Rectangle bounds, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers
RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool freeEdit); // Text Box control, updates input text RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool freeEdit); // Text Box control, updates input text
@ -403,13 +404,13 @@ RAYGUIDEF float GuiSliderEx(Rectangle bounds, float value, float minValue, float
RAYGUIDEF float GuiSliderBar(Rectangle bounds, float value, float minValue, float maxValue); // Slider Bar control, returns selected value RAYGUIDEF float GuiSliderBar(Rectangle bounds, float value, float minValue, float maxValue); // Slider Bar control, returns selected value
RAYGUIDEF float GuiSliderBarEx(Rectangle bounds, float value, float minValue, float maxValue, const char *text, bool showValue); // Slider Bar control, returns selected value RAYGUIDEF float GuiSliderBarEx(Rectangle bounds, float value, float minValue, float maxValue, const char *text, bool showValue); // Slider Bar control, returns selected value
RAYGUIDEF float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue); // Progress Bar control, shows current progress value RAYGUIDEF float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue); // Progress Bar control, shows current progress value
RAYGUIDEF float GuiProgressBarEx(Rectangle bounds, float value, float minValue, float maxValue, bool showValue); // Progress Bar control, shows current progress value RAYGUIDEF float GuiProgressBarEx(Rectangle bounds, float value, float minValue, float maxValue, bool showValue); // Progress Bar control, shows current progress value
RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text, int offsetX); // Status Bar control, shows info text RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text, int offsetX); // Status Bar control, shows info text
RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text); // Dummy control for placeholders RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text); // Dummy control for placeholders
// Advance controls set // Advance controls set
RAYGUIDEF bool GuiListView(Rectangle bounds, const char **text, int count, int*scrollIndex, int *active, bool editMode); // List View control, returns selected list element index RAYGUIDEF bool GuiListView(Rectangle bounds, const char **text, int count, int *scrollIndex, int *active, bool editMode); // List View control, returns selected list element index
RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, int*focus, bool editMode); RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, int *focus, bool editMode); // with List View extended parameters
RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color); // Color Picker control RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color); // Color Picker control
RAYGUIDEF bool GuiMessageBox(Rectangle bounds, const char *windowTitle, const char *message); // Message Box control, displays a message RAYGUIDEF bool GuiMessageBox(Rectangle bounds, const char *windowTitle, const char *message); // Message Box control, displays a message
@ -458,7 +459,6 @@ typedef enum GuiControlState {
NORMAL, NORMAL,
FOCUSED, FOCUSED,
PRESSED, PRESSED,
WASPRESSED
} GuiControlState; } GuiControlState;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -834,16 +834,15 @@ static Vector2 GetMousePosition(void) { return (Vector2){ 0, 0 }; }
static bool IsMouseButtonDown(int button); static bool IsMouseButtonDown(int button);
static bool IsMouseButtonReleased(int button); static bool IsMouseButtonReleased(int button);
static bool IsMouseButtonUp(int button); // -- GuiSpinner(), GuiColorPicker()
static int GetKeyPressed(void); // -- GuiTextBox() static int GetKeyPressed(void); // -- GuiTextBox()
static bool IsKeyPressed(int key); // -- GuiTextBox() static bool IsKeyPressed(int key); // -- GuiTextBox()
static bool IsKeyDown(int key); // -- GuiColorPicker() static bool IsKeyDown(int key); // -- GuiColorPicker()
// Control specific functions // Control specific functions
static void DrawRectangleLines(int x, int y, int width, int height, Color color) { /* TODO */ } // -- GuiColorPicker() * static void DrawRectangleLines(int x, int y, int width, int height, Color color) { /* TODO */ } // -- GuiColorPicker()
static void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2);// -- GuiColorPicker() * static void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2); // -- GuiColorPicker()
static void DrawRectangleGradientH(int posX, int posY, int width, int height, Color color1, Color color2);// -- GuiColorPicker() * static void DrawRectangleGradientH(int posX, int posY, int width, int height, Color color1, Color color2); // -- GuiColorPicker()
static void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4); // -- GuiColorPicker() static void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4); // -- GuiColorPicker()
static void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // -- GuiTexture() static void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // -- GuiTexture()
@ -855,7 +854,6 @@ static void UnloadImage(Image image); // -- GuiLoadStylePaletteIma
#endif // RAYGUI_STANDALONE #endif // RAYGUI_STANDALONE
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module specific Functions Declaration // Module specific Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -865,7 +863,6 @@ static bool GuiListElement(Rectangle bounds, const char *text, bool active, bool
static Vector3 ConvertHSVtoRGB(Vector3 hsv); // Convert color data from HSV to RGB static Vector3 ConvertHSVtoRGB(Vector3 hsv); // Convert color data from HSV to RGB
static Vector3 ConvertRGBtoHSV(Vector3 rgb); // Convert color data from RGB to HSV static Vector3 ConvertRGBtoHSV(Vector3 rgb); // Convert color data from RGB to HSV
static void GuiDrawText(const char *text, int posX, int posY, Color tint) static void GuiDrawText(const char *text, int posX, int posY, Color tint)
{ {
if (guiFont.texture.id == 0) guiFont = GetFontDefault(); if (guiFont.texture.id == 0) guiFont = GetFontDefault();
@ -930,8 +927,8 @@ RAYGUIDEF int GuiGetStyleProperty(int guiProperty) { return style[guiProperty];
// Window Box control // Window Box control
RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *text) RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *text)
{ {
#define WINDOWBOX_PADDING 2 #define WINDOWBOX_PADDING 2
#define WINDOWBOX_BORDER_WIDTH 1 #define WINDOWBOX_BORDER_WIDTH 1
bool clicked = false; bool clicked = false;
GuiControlState state = guiState; GuiControlState state = guiState;
@ -1006,9 +1003,9 @@ RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *text)
// Group Box control with title name // Group Box control with title name
RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text) RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text)
{ {
#define GROUPBOX_LINE_THICK 1 #define GROUPBOX_LINE_THICK 1
#define GROUPBOX_TEXT_PADDING 10 #define GROUPBOX_TEXT_PADDING 10
#define GROUPBOX_PADDING 2 #define GROUPBOX_PADDING 2
GuiControlState state = guiState; GuiControlState state = guiState;
@ -1047,8 +1044,6 @@ RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text)
default: break; default: break;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
} }
// Line control // Line control
@ -1064,17 +1059,17 @@ RAYGUIDEF void GuiLine(Rectangle bounds, int thick)
{ {
case NORMAL: case NORMAL:
case FOCUSED: case FOCUSED:
case PRESSED: DrawRectangleLinesEx(line, thick, Fade(GetColor(style[DEFAULT_LINES_COLOR]), guiAlpha));break; case PRESSED: DrawRectangleLinesEx(line, thick, Fade(GetColor(style[DEFAULT_LINES_COLOR]), guiAlpha)); break;
case DISABLED: DrawRectangleLinesEx(line, thick, Fade(GetColor(style[DEFAULT_BORDER_COLOR_DISABLED]), guiAlpha));break; case DISABLED: DrawRectangleLinesEx(line, thick, Fade(GetColor(style[DEFAULT_BORDER_COLOR_DISABLED]), guiAlpha)); break;
default: break;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
} }
// Panel control // Panel control
RAYGUIDEF void GuiPanel(Rectangle bounds) RAYGUIDEF void GuiPanel(Rectangle bounds)
{ {
#define GUIPANEL_BORDER_WIDTH 1 #define GUIPANEL_BORDER_WIDTH 1
GuiControlState state = guiState; GuiControlState state = guiState;
@ -1088,12 +1083,13 @@ RAYGUIDEF void GuiPanel(Rectangle bounds)
{ {
DrawRectangleRec(bounds, Fade(GetColor(style[DEFAULT_BACKGROUND_COLOR]), guiAlpha)); DrawRectangleRec(bounds, Fade(GetColor(style[DEFAULT_BACKGROUND_COLOR]), guiAlpha));
DrawRectangleLinesEx(bounds, GUIPANEL_BORDER_WIDTH, Fade(GetColor(style[DEFAULT_LINES_COLOR]), guiAlpha)); DrawRectangleLinesEx(bounds, GUIPANEL_BORDER_WIDTH, Fade(GetColor(style[DEFAULT_LINES_COLOR]), guiAlpha));
}break; } break;
case DISABLED: case DISABLED:
{ {
DrawRectangleRec(bounds, Fade(GetColor(style[DEFAULT_BASE_COLOR_DISABLED]), guiAlpha)); DrawRectangleRec(bounds, Fade(GetColor(style[DEFAULT_BASE_COLOR_DISABLED]), guiAlpha));
DrawRectangleLinesEx(bounds, GUIPANEL_BORDER_WIDTH, Fade(GetColor(style[DEFAULT_BORDER_COLOR_DISABLED]), guiAlpha)); DrawRectangleLinesEx(bounds, GUIPANEL_BORDER_WIDTH, Fade(GetColor(style[DEFAULT_BORDER_COLOR_DISABLED]), guiAlpha));
}break; } break;
default: break;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
} }
@ -1102,7 +1098,7 @@ RAYGUIDEF void GuiPanel(Rectangle bounds)
// NOTE: bounds define the view area, content defines size of internal data // NOTE: bounds define the view area, content defines size of internal data
RAYGUIDEF Vector2 GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 viewScroll) RAYGUIDEF Vector2 GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 viewScroll)
{ {
// TODO: Implement // TODO: Implement scroll panel control
return viewScroll; return viewScroll;
} }
@ -1245,17 +1241,15 @@ RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text)
} }
// Image button control, returns true when clicked // Image button control, returns true when clicked
// TODO: Just provide textureId instead of full Texture2D
RAYGUIDEF bool GuiImageButton(Rectangle bounds, Texture2D texture) RAYGUIDEF bool GuiImageButton(Rectangle bounds, Texture2D texture)
{ {
return GuiImageButtonEx(bounds, texture, (Rectangle){ 0, 0, texture.width, texture.height }, NULL); return GuiImageButtonEx(bounds, texture, (Rectangle){ 0, 0, texture.width, texture.height }, NULL);
} }
// Image button control, returns true when clicked // Image button control, returns true when clicked
// TODO: Just provide textureId instead of full Texture2D
RAYGUIDEF bool GuiImageButtonEx(Rectangle bounds, Texture2D texture, Rectangle texSource, const char *text) RAYGUIDEF bool GuiImageButtonEx(Rectangle bounds, Texture2D texture, Rectangle texSource, const char *text)
{ {
#define IMAGEBUTTON_PADDING 4 #define IMAGEBUTTON_PADDING 4
GuiControlState state = guiState; GuiControlState state = guiState;
bool clicked = false; bool clicked = false;
@ -1487,8 +1481,8 @@ RAYGUIDEF bool GuiCheckBox(Rectangle bounds, bool checked)
// Check Box extended control, returns true when active // Check Box extended control, returns true when active
RAYGUIDEF bool GuiCheckBoxEx(Rectangle bounds, bool checked, const char *text) RAYGUIDEF bool GuiCheckBoxEx(Rectangle bounds, bool checked, const char *text)
{ {
#define GUICHECKBOXEX_WIDTH_PADDING 5 #define GUICHECKBOXEX_WIDTH_PADDING 5
#define GUICHECKBOXEX_HEIGHT_PADDING 1 #define GUICHECKBOXEX_HEIGHT_PADDING 1
GuiControlState state = guiState; GuiControlState state = guiState;
int textWidth = GuiTextWidth(text); int textWidth = GuiTextWidth(text);
@ -1685,23 +1679,8 @@ RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char **text, int count, in
{ {
Vector2 mousePoint = GetMousePosition(); Vector2 mousePoint = GetMousePosition();
if (editMode) if (editMode) state = PRESSED;
{
state = PRESSED;
// if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
// {
// for (int i = 1; i < (count + 1); i++)
// {
// if (CheckCollisionPointRec(mousePoint, (Rectangle){ bounds.x, bounds.y + i*bounds.height, bounds.width, bounds.height }))
// {
// auxActive = i - 1;
// }
// }
// }
}
// Note: Changing editMode
if (!editMode) if (!editMode)
{ {
if (CheckCollisionPointRec(mousePoint, closeBounds)) if (CheckCollisionPointRec(mousePoint, closeBounds))
@ -1718,7 +1697,6 @@ RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char **text, int count, in
{ {
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true; if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true;
} }
else if (!CheckCollisionPointRec(mousePoint, openBounds)) else if (!CheckCollisionPointRec(mousePoint, openBounds))
{ {
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) pressed = true; if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) pressed = true;
@ -1794,7 +1772,6 @@ RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char **text, int count, in
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
*active = auxActive; *active = auxActive;
return pressed; return pressed;
} }
@ -1804,6 +1781,7 @@ RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char **text, int count, in
RAYGUIDEF bool GuiSpinner(Rectangle bounds, int *value, int minValue, int maxValue, int btnWidth, bool editMode) RAYGUIDEF bool GuiSpinner(Rectangle bounds, int *value, int minValue, int maxValue, int btnWidth, bool editMode)
{ {
#define GUIVALUEBOX_BUTTON_BORDER_WIDTH 1 #define GUIVALUEBOX_BUTTON_BORDER_WIDTH 1
bool pressed = false; bool pressed = false;
int buttonBorderWidth = style[BUTTON_BORDER_WIDTH]; int buttonBorderWidth = style[BUTTON_BORDER_WIDTH];
@ -1848,18 +1826,16 @@ RAYGUIDEF bool GuiSpinner(Rectangle bounds, int *value, int minValue, int maxVal
// NOTE: Requires static variables: framesCounter // NOTE: Requires static variables: framesCounter
RAYGUIDEF bool GuiValueBox(Rectangle bounds, int *value, int minValue, int maxValue, bool editMode) RAYGUIDEF bool GuiValueBox(Rectangle bounds, int *value, int minValue, int maxValue, bool editMode)
{ {
#define GUIVALUEBOX_CHAR_COUNT 32 #define GUIVALUEBOX_CHAR_COUNT 32
#define KEY_BACKSPACE_TEXT 259 // GLFW BACKSPACE: 3 + 256 #define KEY_BACKSPACE_TEXT 259 // GLFW BACKSPACE: 3 + 256
bool pressed = false; static int framesCounter = 0; // Required for blinking cursor
GuiControlState state = guiState; GuiControlState state = guiState;
static int framesCounter = 0; bool pressed = false;
// Required for blinking cursor
char text[GUIVALUEBOX_CHAR_COUNT + 1] = "\0"; char text[GUIVALUEBOX_CHAR_COUNT + 1] = "\0";
sprintf(text, "%i", *value); sprintf(text, "%i", *value);
int textWidth = GuiTextWidth(text); int textWidth = GuiTextWidth(text);
// Update control // Update control
@ -1913,6 +1889,7 @@ RAYGUIDEF bool GuiValueBox(Rectangle bounds, int *value, int minValue, int maxVa
valueHasChanged = true; valueHasChanged = true;
} }
} }
if (valueHasChanged) *value = atoi(text); if (valueHasChanged) *value = atoi(text);
} }
else else
@ -1921,7 +1898,6 @@ RAYGUIDEF bool GuiValueBox(Rectangle bounds, int *value, int minValue, int maxVa
else if (*value < minValue) *value = minValue; else if (*value < minValue) *value = minValue;
} }
// Note: Changing editMode
if (!editMode) if (!editMode)
{ {
if (CheckCollisionPointRec(mousePoint, bounds)) if (CheckCollisionPointRec(mousePoint, bounds))
@ -1981,8 +1957,11 @@ RAYGUIDEF bool GuiValueBox(Rectangle bounds, int *value, int minValue, int maxVa
// NOTE 2: Returns if KEY_ENTER pressed (useful for data validation) // NOTE 2: Returns if KEY_ENTER pressed (useful for data validation)
RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode) RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
{ {
#define KEY_BACKSPACE_TEXT 259 // GLFW BACKSPACE: 3 + 256
static int framesCounter = 0; // Required for blinking cursor
GuiControlState state = guiState; GuiControlState state = guiState;
static int framesCounter = 0; // Required for blinking cursor
bool pressed = false; bool pressed = false;
// Update control // Update control
@ -1991,8 +1970,6 @@ RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editM
{ {
Vector2 mousePoint = GetMousePosition(); Vector2 mousePoint = GetMousePosition();
#define KEY_BACKSPACE_TEXT 259 // GLFW BACKSPACE: 3 + 256
if (editMode) if (editMode)
{ {
state = PRESSED; state = PRESSED;
@ -2035,7 +2012,6 @@ RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editM
} }
} }
// Note: Changing editMode
if (!editMode) if (!editMode)
{ {
if (CheckCollisionPointRec(mousePoint, bounds)) if (CheckCollisionPointRec(mousePoint, bounds))
@ -2094,15 +2070,16 @@ RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editM
RAYGUIDEF bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode) RAYGUIDEF bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode)
{ {
#define GUITEXTBOXMULTI_PADDING 4 #define GUITEXTBOXMULTI_PADDING 4
#define GUITEXTBOXMULTI_LINE_PADDING 5 // Internal from raylib line-break space (height + height/2)*scale #define GUITEXTBOXMULTI_LINE_PADDING 5
#define GUITEXTBOXMULTI_LINE_HEIGHT 10 #define GUITEXTBOXMULTI_LINE_HEIGHT 10
GuiControlState state = guiState;
static int framesCounter = 0; // Required for blinking cursor static int framesCounter = 0; // Required for blinking cursor
GuiControlState state = guiState;
bool pressed = false; bool pressed = false;
bool textHasChange = false; bool textHasChange = false;
int currentLine = 0; int currentLine = 0;
const char *numChars = ""; const char *numChars = "";
// Security check because font is used directly in this control // Security check because font is used directly in this control
@ -2215,6 +2192,7 @@ RAYGUIDEF bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool
if (GuiTextWidth(text) > maxWidth) if (GuiTextWidth(text) > maxWidth)
{ {
char *lastSpace = strrchr(text, 32); char *lastSpace = strrchr(text, 32);
if (lastSpace != NULL) if (lastSpace != NULL)
{ {
int index = lastSpace - text; int index = lastSpace - text;
@ -2240,7 +2218,7 @@ RAYGUIDEF bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool
} }
} }
// Changing editMode // Changing edit mode
if (!editMode) if (!editMode)
{ {
if (CheckCollisionPointRec(mousePoint, bounds)) if (CheckCollisionPointRec(mousePoint, bounds))
@ -2386,9 +2364,9 @@ RAYGUIDEF float GuiSlider(Rectangle bounds, float value, float minValue, float m
// Slider control extended, returns selected value and has text // Slider control extended, returns selected value and has text
RAYGUIDEF float GuiSliderEx(Rectangle bounds, float value, float minValue, float maxValue, const char *text, bool showValue) RAYGUIDEF float GuiSliderEx(Rectangle bounds, float value, float minValue, float maxValue, const char *text, bool showValue)
{ {
#define SLIDER_SLIDER_LINE_THICK 1 #define SLIDER_SLIDER_LINE_THICK 1
#define SLIDEREX_WIDTH_PADDING 5 #define SLIDEREX_WIDTH_PADDING 5
#define SLIDEREX_HEIGHT_PADDING 1 #define SLIDEREX_HEIGHT_PADDING 1
GuiControlState state = guiState; GuiControlState state = guiState;
@ -2628,19 +2606,12 @@ RAYGUIDEF float GuiProgressBar(Rectangle bounds, float value, float minValue, fl
GuiControlState state = guiState; GuiControlState state = guiState;
Rectangle progress = { bounds.x + style[PROGRESSBAR_BORDER_WIDTH], Rectangle progress = { bounds.x + style[PROGRESSBAR_BORDER_WIDTH],
bounds.y + style[PROGRESSBAR_BORDER_WIDTH] + style[PROGRESSBAR_INNER_PADDING], bounds.y + style[PROGRESSBAR_BORDER_WIDTH] + style[PROGRESSBAR_INNER_PADDING], 0,
0, // TODO
bounds.height - 2*style[PROGRESSBAR_BORDER_WIDTH] - 2*style[PROGRESSBAR_INNER_PADDING] }; bounds.height - 2*style[PROGRESSBAR_BORDER_WIDTH] - 2*style[PROGRESSBAR_INNER_PADDING] };
// Update control // Update control
//-------------------------------------------------------------------- //--------------------------------------------------------------------
if (state != DISABLED) if (state != DISABLED) progress.width = (int)(value/(maxValue - minValue)*(float)(bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH]));
{
//Vector2 mousePoint = GetMousePosition();
//if (CheckCollisionPointRec(mousePoint, bounds)) state = FOCUSED; // State not required on ProgressBar
progress.width = (int)(value/(maxValue - minValue)*(float)(bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH]));
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Draw control // Draw control
@ -2677,19 +2648,12 @@ RAYGUIDEF float GuiProgressBarEx(Rectangle bounds, float value, float minValue,
GuiControlState state = guiState; GuiControlState state = guiState;
Rectangle progress = { bounds.x + style[PROGRESSBAR_BORDER_WIDTH], Rectangle progress = { bounds.x + style[PROGRESSBAR_BORDER_WIDTH],
bounds.y + style[PROGRESSBAR_BORDER_WIDTH] + style[PROGRESSBAR_INNER_PADDING], bounds.y + style[PROGRESSBAR_BORDER_WIDTH] + style[PROGRESSBAR_INNER_PADDING], 0,
0, // TODO
bounds.height - 2*style[PROGRESSBAR_BORDER_WIDTH] - 2*style[PROGRESSBAR_INNER_PADDING] }; bounds.height - 2*style[PROGRESSBAR_BORDER_WIDTH] - 2*style[PROGRESSBAR_INNER_PADDING] };
// Update control // Update control
//-------------------------------------------------------------------- //--------------------------------------------------------------------
if (state != DISABLED) if (state != DISABLED) progress.width = (int)(value/(maxValue - minValue)*(float)(bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH]));
{
//Vector2 mousePoint = GetMousePosition();
//if (CheckCollisionPointRec(mousePoint, bounds)) state = FOCUSED; // State not required on ProgressBar
progress.width = (int)(value/(maxValue - minValue)*(float)(bounds.width - 2*style[PROGRESSBAR_BORDER_WIDTH]));
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Draw control // Draw control
@ -2722,7 +2686,7 @@ RAYGUIDEF float GuiProgressBarEx(Rectangle bounds, float value, float minValue,
// Status Bar control // Status Bar control
RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text, int offsetX) RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text, int offsetX)
{ {
#define STATUSBAR_BORDER_WIDTH 1 #define STATUSBAR_BORDER_WIDTH 1
GuiControlState state = guiState; GuiControlState state = guiState;
@ -2755,6 +2719,7 @@ RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text, int offsetX)
//-------------------------------------------------------------------- //--------------------------------------------------------------------
} }
// Dummy rectangle control, intended for placeholding
RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text) RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text)
{ {
GuiControlState state = guiState; GuiControlState state = guiState;
@ -2789,14 +2754,12 @@ RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text)
case PRESSED: case PRESSED:
{ {
DrawRectangleRec(bounds, Fade(GetColor(style[DEFAULT_BASE_COLOR_NORMAL]), guiAlpha)); DrawRectangleRec(bounds, Fade(GetColor(style[DEFAULT_BASE_COLOR_NORMAL]), guiAlpha));
//DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[DEFAULT_BORDER_COLOR_NORMAL]), guiAlpha));
GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(style[BUTTON_TEXT_COLOR_NORMAL]), guiAlpha)); GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(style[BUTTON_TEXT_COLOR_NORMAL]), guiAlpha));
} break; } break;
case DISABLED: case DISABLED:
{ {
DrawRectangleRec(bounds, Fade(GetColor(style[DEFAULT_BASE_COLOR_DISABLED]), guiAlpha)); DrawRectangleRec(bounds, Fade(GetColor(style[DEFAULT_BASE_COLOR_DISABLED]), guiAlpha));
//DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[DEFAULT_BORDER_COLOR_DISABLED]), guiAlpha));
GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(style[BUTTON_TEXT_COLOR_DISABLED]), guiAlpha)); GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(style[BUTTON_TEXT_COLOR_DISABLED]), guiAlpha));
} break; } break;
default: break; default: break;
@ -2826,10 +2789,6 @@ static bool GuiListElement(Rectangle bounds, const char *text, bool active, bool
// TODO: Remove character if they dont fit inside bounds. We have the same problem with others GUIs. // TODO: Remove character if they dont fit inside bounds. We have the same problem with others GUIs.
} }
//if (bounds.width < textWidth) bounds.width = textWidth + LISTELEMENT_PADDING*2;
// if (bounds.height < textHeight) bounds.height = textHeight;
Vector2 mousePoint = GetMousePosition(); Vector2 mousePoint = GetMousePosition();
if (CheckCollisionPointRec(mousePoint, bounds)) if (CheckCollisionPointRec(mousePoint, bounds))
@ -2892,13 +2851,14 @@ static bool GuiListElement(Rectangle bounds, const char *text, bool active, bool
return active; return active;
} }
// List View control, returns selected list element index // int *startIndex) // List View control
RAYGUIDEF bool GuiListView(Rectangle bounds, const char **text, int count, int*scrollIndex, int *active, bool editMode) RAYGUIDEF bool GuiListView(Rectangle bounds, const char **text, int count, int*scrollIndex, int *active, bool editMode)
{ {
int focusDefault = 0; int focusDefault = 0;
return GuiListViewEx(bounds, text, NULL, count, scrollIndex, active, &focusDefault, editMode); return GuiListViewEx(bounds, text, NULL, count, scrollIndex, active, &focusDefault, editMode);
} }
// List View control extended parameters
RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, int*focus, bool editMode) RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, int*focus, bool editMode)
{ {
#define LISTVIEW_LINE_THICK 1 #define LISTVIEW_LINE_THICK 1
@ -2940,6 +2900,7 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
// Calculate position X and width to draw each element. // Calculate position X and width to draw each element.
int posX = bounds.x + style[LISTVIEW_BAR_WIDTH] + style[LISTVIEW_ELEMENTS_PADDING]; int posX = bounds.x + style[LISTVIEW_BAR_WIDTH] + style[LISTVIEW_ELEMENTS_PADDING];
int elementWidth = bounds.width - style[LISTVIEW_BAR_WIDTH] - 2*style[LISTVIEW_ELEMENTS_PADDING] - LISTVIEW_LINE_THICK; int elementWidth = bounds.width - style[LISTVIEW_BAR_WIDTH] - 2*style[LISTVIEW_ELEMENTS_PADDING] - LISTVIEW_LINE_THICK;
if (!useScrollBar) if (!useScrollBar)
{ {
posX = bounds.x + style[LISTVIEW_ELEMENTS_PADDING]; posX = bounds.x + style[LISTVIEW_ELEMENTS_PADDING];
@ -2998,9 +2959,7 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
if (endIndex > count) endIndex = count; if (endIndex > count) endIndex = count;
} }
} }
// ------------------------------------------------------------------------------------
// Note: Changing editMode
if (!editMode) if (!editMode)
{ {
if (CheckCollisionPointRec(mousePoint, bounds)) if (CheckCollisionPointRec(mousePoint, bounds))
@ -3039,8 +2998,7 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
} }
} }
// Calculamos el porcentaje de elementos visibles, y aplicamos el mismo porcentaje al tamaño de la barra original. // Calculate percentage of visible elements and apply same percentage to scrollbar
// Hay que tener en cuenta un valor mínimo para que la barra no sea de 1 px nunca y también que no sea mayor que la altura máxima.
if (useScrollBar) if (useScrollBar)
{ {
float percentVisible = (endIndex - startIndex)*100/count; float percentVisible = (endIndex - startIndex)*100/count;
@ -3049,16 +3007,13 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
if (barHeight < minBarHeight) barHeight = minBarHeight; if (barHeight < minBarHeight) barHeight = minBarHeight;
else if (barHeight > bounds.height) barHeight = bounds.height; else if (barHeight > bounds.height) barHeight = bounds.height;
// Posición Y a la que dibujamos la barra.
barPosY = bounds.y + startIndex*((bounds.height - barHeight)/(count - (endIndex - startIndex))); barPosY = bounds.y + startIndex*((bounds.height - barHeight)/(count - (endIndex - startIndex)));
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Draw control // Draw control
//-------------------------------------------------------------------- //--------------------------------------------------------------------
DrawRectangleRec(bounds, GetColor(style[DEFAULT_BACKGROUND_COLOR])); // Draw background
// Draw background
DrawRectangleRec(bounds, GetColor(style[DEFAULT_BACKGROUND_COLOR]));
// Draw scrollBar background // Draw scrollBar background
if (useScrollBar) DrawRectangle(bounds.x, bounds.y, style[LISTVIEW_BAR_WIDTH], bounds.height, Fade(GetColor(style[DEFAULT_BORDER_COLOR_DISABLED]), guiAlpha)); if (useScrollBar) DrawRectangle(bounds.x, bounds.y, style[LISTVIEW_BAR_WIDTH], bounds.height, Fade(GetColor(style[DEFAULT_BORDER_COLOR_DISABLED]), guiAlpha));
@ -3110,7 +3065,6 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
if (useScrollBar) DrawRectangle(bounds.x, barPosY, style[LISTVIEW_BAR_WIDTH], barHeight, Fade(GetColor(style[SLIDERBAR_BASE_COLOR_PRESSED]), guiAlpha)); if (useScrollBar) DrawRectangle(bounds.x, barPosY, style[LISTVIEW_BAR_WIDTH], barHeight, Fade(GetColor(style[SLIDERBAR_BASE_COLOR_PRESSED]), guiAlpha));
DrawRectangleLinesEx(bounds, LISTVIEW_LINE_THICK, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_PRESSED]), guiAlpha)); DrawRectangleLinesEx(bounds, LISTVIEW_LINE_THICK, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_PRESSED]), guiAlpha));
// Draw GuiListElements
for (int i = startIndex; i < endIndex; i++) for (int i = startIndex; i < endIndex; i++)
{ {
if (usingEnableList && enabledElements[i] == 0) if (usingEnableList && enabledElements[i] == 0)
@ -3135,7 +3089,6 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
DrawRectangleLinesEx(bounds, LISTVIEW_LINE_THICK, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_DISABLED]), guiAlpha)); DrawRectangleLinesEx(bounds, LISTVIEW_LINE_THICK, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_DISABLED]), guiAlpha));
// Draw GuiListElements
for (int i = startIndex; i < endIndex; i++) for (int i = startIndex; i < endIndex; i++)
{ {
if (i == auxActive) GuiListElement((Rectangle){ posX, bounds.y + style[LISTVIEW_ELEMENTS_PADDING] + LISTVIEW_LINE_THICK + (i - startIndex)*(style[LISTVIEW_ELEMENTS_HEIGHT] + style[LISTVIEW_ELEMENTS_PADDING]), elementWidth, style[LISTVIEW_ELEMENTS_HEIGHT] }, text[i], true, false); if (i == auxActive) GuiListElement((Rectangle){ posX, bounds.y + style[LISTVIEW_ELEMENTS_PADDING] + LISTVIEW_LINE_THICK + (i - startIndex)*(style[LISTVIEW_ELEMENTS_HEIGHT] + style[LISTVIEW_ELEMENTS_PADDING]), elementWidth, style[LISTVIEW_ELEMENTS_HEIGHT] }, text[i], true, false);
@ -3145,6 +3098,7 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
default: break; default: break;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
*scrollIndex = startIndex; *scrollIndex = startIndex;
*focus = focusElement; *focus = focusElement;
*active = auxActive; *active = auxActive;
@ -3220,7 +3174,6 @@ RAYGUIDEF Color GuiColorPanel(Rectangle bounds, Color color)
else else
{ {
DrawRectangleGradientEx(bounds, Fade(Fade(GetColor(style[COLORPICKER_BASE_COLOR_DISABLED]), 0.1f), guiAlpha), Fade(Fade(BLACK, 0.6f), guiAlpha), Fade(Fade(BLACK, 0.6f), guiAlpha), Fade(Fade(GetColor(style[COLORPICKER_BORDER_COLOR_DISABLED]), 0.6f), guiAlpha)); DrawRectangleGradientEx(bounds, Fade(Fade(GetColor(style[COLORPICKER_BASE_COLOR_DISABLED]), 0.1f), guiAlpha), Fade(Fade(BLACK, 0.6f), guiAlpha), Fade(Fade(BLACK, 0.6f), guiAlpha), Fade(Fade(GetColor(style[COLORPICKER_BORDER_COLOR_DISABLED]), 0.6f), guiAlpha));
//DrawRectangleGradientEx(bounds, Fade(BLACK, 0), BLACK, BLACK, Fade(BLACK, 0));
} }
switch (state) switch (state)
@ -3244,8 +3197,6 @@ RAYGUIDEF float GuiColorBarAlpha(Rectangle bounds, float alpha)
#define GUICOLORBARALPHA_SELECTOR_PADDING 2 #define GUICOLORBARALPHA_SELECTOR_PADDING 2
#define CHECKER_SIZE 10 #define CHECKER_SIZE 10
//#define GUICOLORBAR_SELECTOR_THICK 6
GuiControlState state = guiState; GuiControlState state = guiState;
Rectangle selector = { bounds.x + alpha*bounds.width - GUICOLORBARALPHA_SELECTOR_PADDING, bounds.y - GUICOLORBARALPHA_SELECTOR_PADDING, GUICOLORBARALPHA_SELECTOR_WIDTH, bounds.height + GUICOLORBARALPHA_SELECTOR_PADDING*2 }; Rectangle selector = { bounds.x + alpha*bounds.width - GUICOLORBARALPHA_SELECTOR_PADDING, bounds.y - GUICOLORBARALPHA_SELECTOR_PADDING, GUICOLORBARALPHA_SELECTOR_WIDTH, bounds.height + GUICOLORBARALPHA_SELECTOR_PADDING*2 };
@ -3268,7 +3219,7 @@ RAYGUIDEF float GuiColorBarAlpha(Rectangle bounds, float alpha)
if (alpha >= 1.0f) alpha = 1.0f; if (alpha >= 1.0f) alpha = 1.0f;
//selector.x = bounds.x + (int)(((alpha - 0)/(100 - 0))*(bounds.width - 2*style[SLIDER_BORDER_WIDTH])) - selector.width/2; //selector.x = bounds.x + (int)(((alpha - 0)/(100 - 0))*(bounds.width - 2*style[SLIDER_BORDER_WIDTH])) - selector.width/2;
} }
else state = FOCUSED; //state = FOCUSED; else state = FOCUSED;
} }
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -3284,7 +3235,6 @@ RAYGUIDEF float GuiColorBarAlpha(Rectangle bounds, float alpha)
} }
else DrawRectangleGradientH(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[COLORPICKER_BASE_COLOR_DISABLED]), 0.1f), Fade(GetColor(style[COLORPICKER_BORDER_COLOR_DISABLED]), guiAlpha)); else DrawRectangleGradientH(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[COLORPICKER_BASE_COLOR_DISABLED]), 0.1f), Fade(GetColor(style[COLORPICKER_BORDER_COLOR_DISABLED]), guiAlpha));
switch (state) switch (state)
{ {
case NORMAL: case NORMAL:
@ -3358,11 +3308,12 @@ RAYGUIDEF float GuiColorBarHue(Rectangle bounds, float hue)
} }
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Draw control // Draw control
//-------------------------------------------------------------------- //--------------------------------------------------------------------
if (state != DISABLED) if (state != DISABLED)
{ {
//Draw hue bar:color bars // Draw hue bar:color bars
DrawRectangleGradientV(bounds.x + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.y + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.width - GUICOLORBARHUE_SELECTOR_PADDING, (int)bounds.height/6, Fade((Color){ 255,0,0,255 }, guiAlpha), Fade((Color){ 255,255,0,255 }, guiAlpha)); DrawRectangleGradientV(bounds.x + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.y + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.width - GUICOLORBARHUE_SELECTOR_PADDING, (int)bounds.height/6, Fade((Color){ 255,0,0,255 }, guiAlpha), Fade((Color){ 255,255,0,255 }, guiAlpha));
DrawRectangleGradientV(bounds.x + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.y + (int)bounds.height/6 + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.width - GUICOLORBARHUE_SELECTOR_PADDING, (int)bounds.height/6, Fade((Color){ 255,255,0,255 }, guiAlpha), Fade((Color){ 0,255,0,255 }, guiAlpha)); DrawRectangleGradientV(bounds.x + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.y + (int)bounds.height/6 + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.width - GUICOLORBARHUE_SELECTOR_PADDING, (int)bounds.height/6, Fade((Color){ 255,255,0,255 }, guiAlpha), Fade((Color){ 0,255,0,255 }, guiAlpha));
DrawRectangleGradientV(bounds.x + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.y + 2*((int)bounds.height/6) + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.width - GUICOLORBARHUE_SELECTOR_PADDING, (int)bounds.height/6, Fade((Color){ 0,255,0,255 }, guiAlpha), Fade((Color){ 0,255,255,255 }, guiAlpha)); DrawRectangleGradientV(bounds.x + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.y + 2*((int)bounds.height/6) + GUICOLORBARHUE_SELECTOR_PADDING/2, bounds.width - GUICOLORBARHUE_SELECTOR_PADDING, (int)bounds.height/6, Fade((Color){ 0,255,0,255 }, guiAlpha), Fade((Color){ 0,255,255,255 }, guiAlpha));
@ -3409,7 +3360,6 @@ RAYGUIDEF float GuiColorBarHue(Rectangle bounds, float hue)
// TODO: Color GuiColorBarValue() [BLACK->color]), HSV / HSL // TODO: Color GuiColorBarValue() [BLACK->color]), HSV / HSL
// TODO: float GuiColorBarLuminance() [BLACK->WHITE] // TODO: float GuiColorBarLuminance() [BLACK->WHITE]
// Color Picker control // Color Picker control
// NOTE: It's divided in multiple controls: // NOTE: It's divided in multiple controls:
// Color GuiColorPanel() - Color select panel // Color GuiColorPanel() - Color select panel
@ -3466,7 +3416,7 @@ RAYGUIDEF bool GuiMessageBox(Rectangle bounds, const char *windowTitle, const ch
} }
// Grid control // Grid control
// NOTE: Returns mouse position on grid, selected cell // NOTE: Returns grid mouse-hover selected cell
RAYGUIDEF Vector2 GuiGrid(Rectangle bounds, int spacing, int subdivs) RAYGUIDEF Vector2 GuiGrid(Rectangle bounds, int spacing, int subdivs)
{ {
#define GRID_COLOR_ALPHA 0.15f // Grid lines alpha amount #define GRID_COLOR_ALPHA 0.15f // Grid lines alpha amount
@ -3479,7 +3429,6 @@ RAYGUIDEF Vector2 GuiGrid(Rectangle bounds, int spacing, int subdivs)
//-------------------------------------------------------------------- //--------------------------------------------------------------------
if ((state != DISABLED) && !guiLocked) if ((state != DISABLED) && !guiLocked)
{ {
// Check mouse position if snap
if (CheckCollisionPointRec(mousePoint, bounds)) if (CheckCollisionPointRec(mousePoint, bounds))
{ {
currentCell.x = (int)((mousePoint.x - bounds.x)/spacing); currentCell.x = (int)((mousePoint.x - bounds.x)/spacing);