Implemented default colors styling

This commit is contained in:
Ray San
2018-02-15 14:08:16 +01:00
parent 503aa4bef9
commit b9f017f8cb

View File

@ -36,6 +36,7 @@
#define RAYGUI_IMPLEMENTATION #define RAYGUI_IMPLEMENTATION
#define RAYGUI_STYLE_SAVE_LOAD #define RAYGUI_STYLE_SAVE_LOAD
#define RAYGUI_STYLE_DEFAULT_DARK
#include "raygui.h" #include "raygui.h"
#include "external/tinyfiledialogs.h" // Open/Save file dialogs #include "external/tinyfiledialogs.h" // Open/Save file dialogs
@ -64,12 +65,13 @@
#define NUM_STYLES_A 4 #define NUM_STYLES_A 4
#define NUM_STYLES_B 8 #define NUM_STYLES_B 8
#define NUM_STYLES_C 12 #define NUM_STYLES_C 12
#define NUM_STYLES_D 14
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
typedef enum { typedef enum {
LABEL = 0, DEFAULT = 0,
LABELBUTTON, LABELBUTTON,
BUTTON, BUTTON,
//IMAGEBUTTON, //IMAGEBUTTON,
@ -107,7 +109,7 @@ typedef enum {
static char currentPath[256]; // Path to current working folder static char currentPath[256]; // Path to current working folder
const char *guiControlText[NUM_CONTROLS] = { const char *guiControlText[NUM_CONTROLS] = {
"LABEL", "DEFAULT",
"LABELBUTTON", "LABELBUTTON",
"BUTTON", "BUTTON",
//"IMAGEBUTTON", //"IMAGEBUTTON",
@ -157,6 +159,23 @@ const char *guiStylesTextC[NUM_STYLES_C] = {
"TEXT_COLOR_DISABLED" "TEXT_COLOR_DISABLED"
}; };
const char *guiStylesTextD[NUM_STYLES_D] = {
"BORDER_COLOR_NORMAL",
"BASE_COLOR_NORMAL",
"TEXT_COLOR_NORMAL",
"BORDER_COLOR_FOCUSED",
"BASE_COLOR_FOCUSED",
"TEXT_COLOR_FOCUSED",
"BORDER_COLOR_PRESSED",
"BASE_COLOR_PRESSED",
"TEXT_COLOR_PRESSED",
"BORDER_COLOR_DISABLED",
"BASE_COLOR_DISABLED",
"TEXT_COLOR_DISABLED",
"BACKGROUND_COLOR",
"LINES_COLOR"
};
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module Functions Declaration // Module Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -189,10 +208,10 @@ int main(int argc, char *argv[])
// Define gui controls rectangles // Define gui controls rectangles
Rectangle bounds[NUM_CONTROLS] = { Rectangle bounds[NUM_CONTROLS] = {
(Rectangle){ guiPosX + 23, guiPosY + 18, 50, 10 }, // LABEL (Rectangle){ 0 }, // DEFAULT
(Rectangle){ guiPosX + 98, guiPosY + 18, 140, 10 }, // LABELBUTTON (Rectangle){ guiPosX + 98, guiPosY + 18, 140, 10 }, // LABELBUTTON
(Rectangle){ guiPosX + 184, guiPosY + 250, 180, 30 }, // BUTTON (Rectangle){ guiPosX + 184, guiPosY + 250, 180, 30 }, // BUTTON
//(Rectangle){ guiPosX + 251, guiPosY + 5, 113, 32 }, // IMAGEBUTTON //(Rectangle){ guiPosX + 251, guiPosY + 5, 113, 32 }, // IMAGEBUTTON
(Rectangle){ guiPosX + 20, guiPosY + 54, 60, 30 }, // TOGGLE (Rectangle){ guiPosX + 20, guiPosY + 54, 60, 30 }, // TOGGLE
(Rectangle){ guiPosX + 98, guiPosY + 54, 65, 30 }, // TOGGLEGROUP (Rectangle){ guiPosX + 98, guiPosY + 54, 65, 30 }, // TOGGLEGROUP
(Rectangle){ guiPosX + 20, guiPosY + 104, 344, 20 }, // SLIDER (Rectangle){ guiPosX + 20, guiPosY + 104, 344, 20 }, // SLIDER
@ -212,7 +231,7 @@ int main(int argc, char *argv[])
currentPath[strlen(currentPath)] = '\\'; currentPath[strlen(currentPath)] = '\\';
currentPath[strlen(currentPath) + 1] = '\0'; // Not really required currentPath[strlen(currentPath) + 1] = '\0'; // Not really required
GuiLoadStyleImage("resources/rguistyle_default_light.png"); //GuiLoadStyleImage("resources/rguistyle_default_dark.png");
Texture2D texIcons = LoadTexture("resources/icons.png"); Texture2D texIcons = LoadTexture("resources/icons.png");
@ -248,18 +267,10 @@ int main(int argc, char *argv[])
Color colorBoxValue[12]; Color colorBoxValue[12];
for (int i = 0; i < 12; i++) colorBoxValue[i] = WHITE; for (int i = 0; i < 12; i++) colorBoxValue[i] = GuiBackgroundColor();
char colorHex[9] = "00000000"; char colorHex[9] = "00000000";
bool toggleBackgroundColor = false;
bool toggleLinesColor = false;
bool toggleDefaultColor = false;
bool toggleBackgroundColorPressed = false;
bool toggleLinesColorPressed = false;
bool toggleDefaultColorPressed = false;
Vector3 colorHSV = { 0.0f, 0.0f, 0.0f }; Vector3 colorHSV = { 0.0f, 0.0f, 0.0f };
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -275,34 +286,22 @@ int main(int argc, char *argv[])
ClearDroppedFiles(); ClearDroppedFiles();
} }
if (toggleBackgroundColorPressed != toggleBackgroundColor) if ((previousSelectedControl != currentSelectedControl)) currentSelectedProperty = -1;
{
colorPickerValue = GetColor(styleGeneric[DEFAULT_BACKGROUND_COLOR]);
}
if (toggleBackgroundColor)
{
toggleBackgroundColorPressed = true;
currentSelectedControl = -1;
currentSelectedProperty = -1;
styleGeneric[DEFAULT_BACKGROUND_COLOR] = ColorToInt(colorPickerValue);
}
else toggleBackgroundColorPressed = false;
if (toggleLinesColorPressed != toggleLinesColor) if ((currentSelectedControl == 0) && (currentSelectedProperty != -1))
{ {
colorPickerValue = GetColor(styleGeneric[DEFAULT_LINES_COLOR]); if ((previousSelectedProperty != currentSelectedProperty) || (previousSelectedControl != currentSelectedControl)) saveColor = false;
}
if (toggleLinesColor)
{
toggleLinesColorPressed = true;
currentSelectedControl = -1;
currentSelectedProperty = -1;
styleGeneric[DEFAULT_LINES_COLOR] = ColorToInt(colorPickerValue);
}
else toggleLinesColorPressed = false;
if (!saveColor)
{
colorPickerValue = GetColor(styleGeneric[GetGuiStylePropertyIndex(currentSelectedControl, currentSelectedProperty)]);
saveColor = true;
}
if ((currentSelectedControl != -1) && (currentSelectedProperty != -1)) styleGeneric[GetGuiStylePropertyIndex(currentSelectedControl, currentSelectedProperty)] = ColorToInt(colorPickerValue);
GuiUpdateStyleComplete();
}
else if ((currentSelectedControl != -1) && (currentSelectedProperty != -1))
{ {
if ((previousSelectedProperty != currentSelectedProperty) || (previousSelectedControl != currentSelectedControl)) saveColor = false; if ((previousSelectedProperty != currentSelectedProperty) || (previousSelectedControl != currentSelectedControl)) saveColor = false;
@ -341,12 +340,14 @@ int main(int argc, char *argv[])
// Draw info bar top // Draw info bar top
DrawRectangle(0, 0, GetScreenWidth(), 24, GetColor(styleGeneric[DEFAULT_BASE_COLOR_NORMAL])); DrawRectangle(0, 0, GetScreenWidth(), 24, GetColor(styleGeneric[DEFAULT_BASE_COLOR_NORMAL]));
DrawRectangle(0, 24, GetScreenWidth(), 1, GuiLinesColor());
DrawText("CHOOSE CONTROL", 35, 8, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_NORMAL])); DrawText("CHOOSE CONTROL", 35, 8, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_NORMAL]));
DrawText("> CHOOSE PROPERTY STYLE", 152, 8, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_NORMAL])); DrawText("> CHOOSE PROPERTY STYLE", 152, 8, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_NORMAL]));
DrawText("> STYLE VIEWER", guiPosX + 10, 8, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_NORMAL])); DrawText("> STYLE VIEWER", guiPosX + 10, 8, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_NORMAL]));
// Draw status bar bottom // Draw status bar bottom
DrawRectangle(0, GetScreenHeight() - 24, GetScreenWidth(), 24, GetColor(styleGeneric[DEFAULT_BASE_COLOR_NORMAL])); DrawRectangle(0, GetScreenHeight() - 24, GetScreenWidth(), 24, GetColor(styleGeneric[DEFAULT_BASE_COLOR_NORMAL]));
DrawRectangle(0, GetScreenHeight() - 24, GetScreenWidth(), 1, GuiLinesColor());
DrawText(FormatText("CURRENT SELECTION: %s_%s", guiControlText[currentSelectedControl], guiStylesTextC[currentSelectedProperty]), 20, GetScreenHeight() - 16, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_NORMAL])); DrawText(FormatText("CURRENT SELECTION: %s_%s", guiControlText[currentSelectedControl], guiStylesTextC[currentSelectedProperty]), 20, GetScreenHeight() - 16, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_NORMAL]));
DrawText(FormatText("SAVE STATUS: %s", guiText), guiPosX + 100, GetScreenHeight() - 16, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_NORMAL])); DrawText(FormatText("SAVE STATUS: %s", guiText), guiPosX + 100, GetScreenHeight() - 16, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_NORMAL]));
@ -357,13 +358,13 @@ int main(int argc, char *argv[])
switch (currentSelectedControl) switch (currentSelectedControl)
{ {
case LABEL: case DEFAULT: currentSelectedProperty = GuiListView((Rectangle){ 156, guiPosY + 3, 180, 563 }, guiStylesTextD, NUM_STYLES_D, currentSelectedProperty); break;
case LABELBUTTON: currentSelectedProperty = GuiListView((Rectangle){ 156, guiPosY + 3, 180, 485 }, guiStylesTextA, NUM_STYLES_A, currentSelectedProperty); break; case LABELBUTTON: currentSelectedProperty = GuiListView((Rectangle){ 156, guiPosY + 3, 180, 563 }, guiStylesTextA, NUM_STYLES_A, currentSelectedProperty); break;
case SLIDER: case SLIDER:
case SLIDERBAR: case SLIDERBAR:
case PROGRESSBAR: case PROGRESSBAR:
case CHECKBOX: case CHECKBOX:
case COLORPICKER: currentSelectedProperty = GuiListView((Rectangle){ 156, guiPosY + 3, 180, 485 }, guiStylesTextB, NUM_STYLES_B, currentSelectedProperty); break; case COLORPICKER: currentSelectedProperty = GuiListView((Rectangle){ 156, guiPosY + 3, 180, 563 }, guiStylesTextB, NUM_STYLES_B, currentSelectedProperty); break;
case BUTTON: case BUTTON:
//case IMAGEBUTTON: //case IMAGEBUTTON:
case TOGGLE: case TOGGLE:
@ -372,7 +373,7 @@ int main(int argc, char *argv[])
case TEXTBOX: case TEXTBOX:
case SPINNER: case SPINNER:
case LISTVIEW: case LISTVIEW:
default: currentSelectedProperty = GuiListView((Rectangle){ 156, guiPosY + 3, 180, 485 }, guiStylesTextC, NUM_STYLES_C, currentSelectedProperty); break; default: currentSelectedProperty = GuiListView((Rectangle){ 156, guiPosY + 3, 180, 563 }, guiStylesTextC, NUM_STYLES_C, currentSelectedProperty); break;
} }
GuiEnable(); GuiEnable();
@ -381,7 +382,7 @@ int main(int argc, char *argv[])
if (checked) GuiDisable(); if (checked) GuiDisable();
GuiLabel(bounds[LABEL], "rGuiStyler"); GuiLabel((Rectangle){ guiPosX + 23, guiPosY + 18, 50, 10 }, "rGuiStyler");
if (GuiLabelButton(bounds[LABELBUTTON], "github.com/raysan5/raygui")) {} if (GuiLabelButton(bounds[LABELBUTTON], "github.com/raysan5/raygui")) {}
@ -405,11 +406,6 @@ int main(int argc, char *argv[])
colorPickerValue = GuiColorPicker(bounds[COLORPICKER], colorPickerValue); colorPickerValue = GuiColorPicker(bounds[COLORPICKER], colorPickerValue);
// Draw default styles toggles
toggleBackgroundColor = GuiToggleButton((Rectangle){ 156, guiPosY + 496, 180, 20 }, "BACKGROUND_COLOR", toggleBackgroundColor);
toggleLinesColor = GuiToggleButton((Rectangle){ 156, guiPosY + 521, 180, 20 }, "LINES_COLOR", toggleLinesColor);
toggleDefaultColor = GuiToggleButton((Rectangle){ 156, guiPosY + 546, 180, 20 }, "DEFAULT_STYLE_MODE", toggleDefaultColor);
// Draw labels for GuiColorPicker information (RGBA) // Draw labels for GuiColorPicker information (RGBA)
GuiGroupBox((Rectangle){ guiPosX + 303, guiPosY + 299, 60, 74 }, "RGBA"); GuiGroupBox((Rectangle){ guiPosX + 303, guiPosY + 299, 60, 74 }, "RGBA");
GuiLabel((Rectangle){ guiPosX + 313, guiPosY + 310, 60, 70 }, FormatText("R: %03i", colorPickerValue.r)); GuiLabel((Rectangle){ guiPosX + 313, guiPosY + 310, 60, 70 }, FormatText("R: %03i", colorPickerValue.r));
@ -497,7 +493,13 @@ static int GetGuiStylePropertyIndex(int control, int property)
switch (control) switch (control)
{ {
case LABEL: guiProp = LABEL_TEXT_COLOR_NORMAL + property; break; case DEFAULT:
{
if (property == 12) guiProp = 0;
else if (property == 13) guiProp = 1;
else guiProp = DEFAULT_BORDER_COLOR_NORMAL + property;
}break;
case LABELBUTTON: guiProp = LABEL_TEXT_COLOR_NORMAL + property; break; case LABELBUTTON: guiProp = LABEL_TEXT_COLOR_NORMAL + property; break;
case BUTTON: guiProp = BUTTON_BORDER_COLOR_NORMAL + property; break; case BUTTON: guiProp = BUTTON_BORDER_COLOR_NORMAL + property; break;
//case IMAGEBUTTON: guiProp = BUTTON_BORDER_COLOR_NORMAL + property; break; //case IMAGEBUTTON: guiProp = BUTTON_BORDER_COLOR_NORMAL + property; break;