mirror of
https://github.com/raysan5/raygui.git
synced 2026-02-06 14:19:19 -05:00
Reorganize properties and review GuiImageButtonEx()
This commit is contained in:
40
src/raygui.h
40
src/raygui.h
@ -116,7 +116,7 @@
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#define NUM_PROPERTIES 150
|
#define NUM_PROPERTIES 152
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
@ -247,7 +247,8 @@ typedef enum GuiProperty {
|
|||||||
PROGRESSBAR_BASE_COLOR_NORMAL,
|
PROGRESSBAR_BASE_COLOR_NORMAL,
|
||||||
PROGRESSBAR_BORDER_COLOR_FOCUSED,
|
PROGRESSBAR_BORDER_COLOR_FOCUSED,
|
||||||
PROGRESSBAR_BASE_COLOR_FOCUSED,
|
PROGRESSBAR_BASE_COLOR_FOCUSED,
|
||||||
/*Add PRESSED */
|
PROGRESSBAR_BORDER_COLOR_PRESSED,
|
||||||
|
PROGRESSBAR_BASE_COLOR_PRESSED,
|
||||||
PROGRESSBAR_BORDER_COLOR_DISABLED,
|
PROGRESSBAR_BORDER_COLOR_DISABLED,
|
||||||
PROGRESSBAR_BASE_COLOR_DISABLED,
|
PROGRESSBAR_BASE_COLOR_DISABLED,
|
||||||
// Spinner
|
// Spinner
|
||||||
@ -533,6 +534,8 @@ static int style[NUM_PROPERTIES] = {
|
|||||||
0xc9effeff, // PROGRESSBAR_BASE_COLOR_NORMAL ----> DEFAULT_BASE_COLOR_PRESSED
|
0xc9effeff, // PROGRESSBAR_BASE_COLOR_NORMAL ----> DEFAULT_BASE_COLOR_PRESSED
|
||||||
0x7bb0d6ff, // PROGRESSBAR_BORDER_COLOR_FOCUSED ----> DEFAULT_BORDER_COLOR_FOCUSED
|
0x7bb0d6ff, // PROGRESSBAR_BORDER_COLOR_FOCUSED ----> DEFAULT_BORDER_COLOR_FOCUSED
|
||||||
0x97e8ffff, // PROGRESSBAR_BASE_COLOR_FOCUSED ----> DEFAULT_BASE_COLOR_FOCUSED
|
0x97e8ffff, // PROGRESSBAR_BASE_COLOR_FOCUSED ----> DEFAULT_BASE_COLOR_FOCUSED
|
||||||
|
0x48cc7ff, // PROGRESSBAR_BORDER_COLOR_PRESSED ----> DEFAULT_BORDER_COLOR_PRESSED
|
||||||
|
0x97e8ffff, // PROGRESSBAR_BASE_COLOR_PRESSED ----> DEFAULT_BASE_COLOR_PRESSED
|
||||||
0x72817eff, // PROGRESSBAR_BORDER_COLOR_DISABLED ----> DEFAULT_BORDER_COLOR_DISABLED
|
0x72817eff, // PROGRESSBAR_BORDER_COLOR_DISABLED ----> DEFAULT_BORDER_COLOR_DISABLED
|
||||||
0x344041ff, // PROGRESSBAR_BASE_COLOR_DISABLED ----> DEFAULT_BASE_COLOR_DISABLED
|
0x344041ff, // PROGRESSBAR_BASE_COLOR_DISABLED ----> DEFAULT_BASE_COLOR_DISABLED
|
||||||
0x2, // SPINNER_BUTTON_PADDING
|
0x2, // SPINNER_BUTTON_PADDING
|
||||||
@ -612,7 +615,6 @@ static int style[NUM_PROPERTIES] = {
|
|||||||
0x72817eff, // LISTVIEW_BORDER_COLOR_DISABLED ----> DEFAULT_BORDER_COLOR_DISABLED
|
0x72817eff, // LISTVIEW_BORDER_COLOR_DISABLED ----> DEFAULT_BORDER_COLOR_DISABLED
|
||||||
0x344041ff, // LISTVIEW_BASE_COLOR_DISABLED ----> DEFAULT_BASE_COLOR_DISABLED
|
0x344041ff, // LISTVIEW_BASE_COLOR_DISABLED ----> DEFAULT_BASE_COLOR_DISABLED
|
||||||
0x606666ff, // LISTVIEW_TEXT_COLOR_DISABLED ----> DEFAULT_TEXT_COLOR_DISABLED
|
0x606666ff, // LISTVIEW_TEXT_COLOR_DISABLED ----> DEFAULT_TEXT_COLOR_DISABLED
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -842,18 +844,24 @@ RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text)
|
|||||||
// TODO: Just provide textureId instead of full Texture2D
|
// 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
|
||||||
|
|
||||||
GuiControlState state = guiState;
|
GuiControlState state = guiState;
|
||||||
bool clicked = false;
|
bool clicked = false;
|
||||||
|
int textWidth = 0;
|
||||||
|
int textHeight = 0;
|
||||||
|
|
||||||
if (bounds.width < texSource.width) bounds.width = texSource.width;
|
if (bounds.width < texSource.width) bounds.width = texSource.width;
|
||||||
if (bounds.height < texSource.height) bounds.height = texSource.height;
|
if (bounds.height < texSource.height) bounds.height = texSource.height;
|
||||||
|
|
||||||
int textWidth = MeasureText(text, styleGeneric[DEFAULT_TEXT_SIZE]);
|
if (text != NULL)
|
||||||
int textHeight = styleGeneric[DEFAULT_TEXT_SIZE];
|
{
|
||||||
|
textWidth = MeasureText(text, styleGeneric[DEFAULT_TEXT_SIZE]);
|
||||||
|
textHeight = styleGeneric[DEFAULT_TEXT_SIZE];
|
||||||
|
|
||||||
if (bounds.width < textWidth) bounds.width = textWidth;
|
if (bounds.width < textWidth + texSource.width) bounds.width = textWidth + texSource.width + IMAGEBUTTON_PADDING;
|
||||||
if (bounds.height < textHeight) bounds.height = textHeight;
|
if (bounds.height < textHeight) bounds.height = textHeight;
|
||||||
|
}
|
||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
@ -879,27 +887,33 @@ RAYGUIDEF bool GuiImageButtonEx(Rectangle bounds, Texture2D texture, Rectangle t
|
|||||||
{
|
{
|
||||||
DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_NORMAL]));
|
DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_NORMAL]));
|
||||||
DrawRectangle(bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH], GetColor(style[BUTTON_BASE_COLOR_NORMAL]));
|
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]));
|
||||||
DrawTextureRec(texture, texSource, (Vector2){ bounds.x, bounds.y }, GetColor(style[BUTTON_TEXT_COLOR_NORMAL]));
|
DrawTextureRec(texture, texSource, (Vector2){ bounds.x + bounds.width/2 - (texSource.width + IMAGEBUTTON_PADDING/2 + textWidth)/2, bounds.y + bounds.height/2 - texSource.height/2 }, GetColor(style[BUTTON_TEXT_COLOR_NORMAL]));
|
||||||
|
|
||||||
//if (text != NULL) DrawText();
|
if (text != NULL) DrawText(text, (bounds.x + bounds.width/2 - (texSource.width + IMAGEBUTTON_PADDING + textWidth)/2) + texSource.width, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_NORMAL]));
|
||||||
} break;
|
} break;
|
||||||
case FOCUSED:
|
case FOCUSED:
|
||||||
{
|
{
|
||||||
DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_FOCUSED]));
|
DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_FOCUSED]));
|
||||||
DrawRectangle(bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH], GetColor(style[BUTTON_BASE_COLOR_FOCUSED]));
|
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]));
|
||||||
DrawTextureRec(texture, texSource, (Vector2){ bounds.x, bounds.y }, GetColor(style[BUTTON_TEXT_COLOR_FOCUSED]));
|
DrawTextureRec(texture, texSource, (Vector2){ bounds.x + bounds.width/2 - (texSource.width + IMAGEBUTTON_PADDING/2 + textWidth)/2, bounds.y + bounds.height/2 - texSource.height/2 }, GetColor(style[BUTTON_TEXT_COLOR_FOCUSED]));
|
||||||
|
|
||||||
|
if (text != NULL) DrawText(text, (bounds.x + bounds.width/2 - (texSource.width + IMAGEBUTTON_PADDING + textWidth)/2) + texSource.width, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_FOCUSED]));
|
||||||
} break;
|
} break;
|
||||||
case PRESSED:
|
case PRESSED:
|
||||||
{
|
{
|
||||||
DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_PRESSED]));
|
DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_PRESSED]));
|
||||||
DrawRectangle(bounds.x + style[BUTTON_BORDER_WIDTH], bounds.y + style[BUTTON_BORDER_WIDTH], bounds.width - 2*style[BUTTON_BORDER_WIDTH], bounds.height - 2*style[BUTTON_BORDER_WIDTH], GetColor(style[BUTTON_BASE_COLOR_PRESSED]));
|
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]));
|
||||||
DrawTextureRec(texture, texSource, (Vector2){ bounds.x, bounds.y }, GetColor(style[BUTTON_TEXT_COLOR_PRESSED]));
|
DrawTextureRec(texture, texSource, (Vector2){ bounds.x + bounds.width/2 - (texSource.width + IMAGEBUTTON_PADDING/2 + textWidth)/2, bounds.y + bounds.height/2 - texSource.height/2 }, GetColor(style[BUTTON_TEXT_COLOR_PRESSED]));
|
||||||
|
|
||||||
|
if (text != NULL) DrawText(text, (bounds.x + bounds.width/2 - (texSource.width + IMAGEBUTTON_PADDING + textWidth)/2) + texSource.width, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_PRESSED]));
|
||||||
} break;
|
} break;
|
||||||
case DISABLED:
|
case DISABLED:
|
||||||
{
|
{
|
||||||
DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_DISABLED]));
|
DrawRectangleRec(bounds, GetColor(style[BUTTON_BORDER_COLOR_DISABLED]));
|
||||||
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_DISABLED]));
|
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_DISABLED]));
|
||||||
DrawTextureRec(texture, texSource, (Vector2){ bounds.x, bounds.y }, GetColor(style[BUTTON_TEXT_COLOR_DISABLED]));
|
DrawTextureRec(texture, texSource, (Vector2){ bounds.x + bounds.width/2 - (texSource.width + IMAGEBUTTON_PADDING/2 + textWidth)/2, bounds.y + bounds.height/2 - texSource.height/2 }, GetColor(style[BUTTON_TEXT_COLOR_DISABLED]));
|
||||||
|
|
||||||
|
if (text != NULL) DrawText(text, (bounds.x + bounds.width/2 - (texSource.width + IMAGEBUTTON_PADDING + textWidth)/2) + texSource.width, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(style[BUTTON_TEXT_COLOR_DISABLED]));
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@ -2225,6 +2239,8 @@ RAYGUIDEF void GuiUpdateStyleComplete(void)
|
|||||||
style[PROGRESSBAR_BASE_COLOR_NORMAL] = styleGeneric[DEFAULT_BASE_COLOR_PRESSED];
|
style[PROGRESSBAR_BASE_COLOR_NORMAL] = styleGeneric[DEFAULT_BASE_COLOR_PRESSED];
|
||||||
style[PROGRESSBAR_BORDER_COLOR_FOCUSED] = styleGeneric[DEFAULT_BORDER_COLOR_FOCUSED];
|
style[PROGRESSBAR_BORDER_COLOR_FOCUSED] = styleGeneric[DEFAULT_BORDER_COLOR_FOCUSED];
|
||||||
style[PROGRESSBAR_BASE_COLOR_FOCUSED] = styleGeneric[DEFAULT_BASE_COLOR_FOCUSED];
|
style[PROGRESSBAR_BASE_COLOR_FOCUSED] = styleGeneric[DEFAULT_BASE_COLOR_FOCUSED];
|
||||||
|
style[PROGRESSBAR_BORDER_COLOR_PRESSED] = styleGeneric[DEFAULT_BORDER_COLOR_PRESSED];
|
||||||
|
style[PROGRESSBAR_BASE_COLOR_PRESSED] = styleGeneric[DEFAULT_BASE_COLOR_PRESSED];
|
||||||
style[PROGRESSBAR_BORDER_COLOR_DISABLED] = styleGeneric[DEFAULT_BORDER_COLOR_DISABLED];
|
style[PROGRESSBAR_BORDER_COLOR_DISABLED] = styleGeneric[DEFAULT_BORDER_COLOR_DISABLED];
|
||||||
style[PROGRESSBAR_BASE_COLOR_DISABLED] = styleGeneric[DEFAULT_BASE_COLOR_DISABLED];
|
style[PROGRESSBAR_BASE_COLOR_DISABLED] = styleGeneric[DEFAULT_BASE_COLOR_DISABLED];
|
||||||
// Spinner
|
// Spinner
|
||||||
|
|||||||
Reference in New Issue
Block a user