From 609ee0c3680092d1411d55d21e7462b12e63f1f4 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 2 Jan 2018 02:24:44 +0100 Subject: [PATCH] Rewritting tool for new raygui --- tools/rGuiStyler/rguistyler.c | 351 +++++------------- tools/rGuiStyler/rguistyler_dark_REV8.png | Bin 0 -> 66098 bytes ...tyler.old.png => rguistyler_light.old.png} | Bin ...ler_REV1.png => rguistyler_light_REV1.png} | Bin tools/rGuiStyler/rguistyler_light_REV9.png | Bin 0 -> 67821 bytes 5 files changed, 100 insertions(+), 251 deletions(-) create mode 100644 tools/rGuiStyler/rguistyler_dark_REV8.png rename tools/rGuiStyler/{rguistyler.old.png => rguistyler_light.old.png} (100%) rename tools/rGuiStyler/{rguistyler_REV1.png => rguistyler_light_REV1.png} (100%) create mode 100644 tools/rGuiStyler/rguistyler_light_REV9.png diff --git a/tools/rGuiStyler/rguistyler.c b/tools/rGuiStyler/rguistyler.c index 41acb59..625a5ef 100644 --- a/tools/rGuiStyler/rguistyler.c +++ b/tools/rGuiStyler/rguistyler.c @@ -53,13 +53,12 @@ //---------------------------------------------------------------------------------- #define FONT_SIZE 10 #define COLOR_REC GuiLinesColor() -#define NUM_COLOR_SAMPLES 10 -#define ELEMENT_HEIGHT 38 +#define CONTROL_LIST_HEIGHT 38 #define STATUS_BAR_HEIGHT 25 -#define NUM_ELEMENTS 11 +#define NUM_CONTROLS 11 -// NOTE: Be extremely careful when defining: NUM_ELEMENTS, GuiElement, guiElementText, guiPropertyNum, guiPropertyType and guiPropertyPos +// NOTE: Be extremely careful when defining: NUM_CONTROLS, GuiElement, guiControlText, guiPropertyNum, guiPropertyType and guiPropertyPos // All those variables must be coherent, one small mistake breaks the program (and it could take hours to find the error!) //---------------------------------------------------------------------------------- @@ -77,14 +76,14 @@ typedef enum { COMBOBOX, CHECKBOX, TEXTBOX -} GuiElement; +} GuiControlType; //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- static char currentPath[256]; // Path to current working folder -const char *guiElementText[NUM_ELEMENTS] = { +const char *guiControlText[NUM_CONTROLS] = { "LABEL", "BUTTON", "TOGGLE", @@ -113,8 +112,16 @@ int main() //-------------------------------------------------------------------------------------- const int screenWidth = 1280; const int screenHeight = 720; - - const int guiPropertyNum[NUM_ELEMENTS] = { 3, 11, 14, 1, 7, 6, 4, 14, 18, 8, 6 }; + + SetConfigFlags(FLAG_WINDOW_RESIZABLE); + InitWindow(screenWidth, screenHeight, "rGuiStyler - raygui style editor"); + + int dropsCount = 0; + char **droppedFiles; + + + + const int guiPropertyNum[NUM_CONTROLS] = { 3, 11, 14, 1, 7, 6, 4, 14, 18, 8, 6 }; // Defines if the property to change is a Color or a value to update it accordingly // NOTE: 0 - Color, 1 - value @@ -126,37 +133,30 @@ int main() 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 }; int aux = 0; - int guiPropertyPos[NUM_ELEMENTS]; + int guiPropertyPos[NUM_CONTROLS]; - for (int i = 0; i < NUM_ELEMENTS; i++) + for (int i = 0; i < NUM_CONTROLS; i++) { guiPropertyPos[i] = aux; aux += guiPropertyNum[i]; } - //SetConfigFlags(FLAG_FULLSCREEN_MODE); - InitWindow(screenWidth, screenHeight, "rGuiStyler - raygui style editor"); + Rectangle guiControlListRec[NUM_CONTROLS]; + + for (int i = 0; i < NUM_CONTROLS; i++) guiControlListRec[i] = (Rectangle){ 0, 0 + i*CONTROL_LIST_HEIGHT, 140, CONTROL_LIST_HEIGHT }; + + int guiControlSelected = -1; + int guiControlHover = -1; - int dropsCount = 0; - char **droppedFiles; - - Rectangle guiElementRec[NUM_ELEMENTS]; - for (int i = 0; i < NUM_ELEMENTS; i++) guiElementRec[i] = (Rectangle){ 0, 0 + i*ELEMENT_HEIGHT, 140, ELEMENT_HEIGHT }; + Rectangle guiPropertyListRec[NUM_PROPERTIES]; - int guiElementSelected = -1; - int guiElementHover = -1; - - // Generate properties rectangles depending on guiPropertyNum[] and guiPropertyPos[] - //----------------------------------------------------------------------------------- - Rectangle propertyRec[NUM_PROPERTIES]; - - for (int j = 0; j < NUM_ELEMENTS; j++) + for (int j = 0; j < NUM_CONTROLS; j++) { for (int i = 0; i < guiPropertyNum[j]; i++) { - if ((j + guiPropertyNum[j]) > 18) propertyRec[guiPropertyPos[j] + i] = (Rectangle){ guiElementRec[0].width, guiElementRec[18 - guiPropertyNum[j]].y + i*ELEMENT_HEIGHT, 260, ELEMENT_HEIGHT }; - else propertyRec[guiPropertyPos[j] + i] = (Rectangle){ guiElementRec[0].width, guiElementRec[j].y + i*ELEMENT_HEIGHT, 260, ELEMENT_HEIGHT }; + if ((j + guiPropertyNum[j]) > 18) guiPropertyListRec[guiPropertyPos[j] + i] = (Rectangle){ guiControlListRec[0].width, guiControlListRec[18 - guiPropertyNum[j]].y + i*CONTROL_LIST_HEIGHT, 260, CONTROL_LIST_HEIGHT }; + else guiPropertyListRec[guiPropertyPos[j] + i] = (Rectangle){ guiControlListRec[0].width, guiControlListRec[j].y + i*CONTROL_LIST_HEIGHT, 260, CONTROL_LIST_HEIGHT }; } } @@ -164,7 +164,7 @@ int main() int guiPropertyHover = -1; //------------------------------------------------------------ - // GUI + // Gui area variables //----------------------------------------------------------- int guiPosX = 455; int guiPosY = 35; @@ -175,50 +175,17 @@ int main() int deltaY = 60; int selectPosX = 401; - //int selectPosY = 0; int selectWidth = screenWidth - 723; - //int selectHeight = screenHeight; //------------------------------------------------------------ - - // Color picker - //----------------------------------------------------------- - Vector2 colorPickerPos = { (float)screenWidth - 287, 20.0f }; - Vector2 cursorPickerPos = colorPickerPos; - Color colorPickerValue = RED; - Color colorSample[NUM_COLOR_SAMPLES]; - - for (int i = 0; i < NUM_COLOR_SAMPLES; i++) colorSample[i] = RAYWHITE; - - int rgbWidthLabel = 30; - int rgbHeightLabel = 20; - int rgbDelta = 6; - int redValue = 0; - int greenValue = 0; - int blueValue = 0; - int alphaValue = 255; - - // Color samples - Rectangle sampleBoundsRec[NUM_COLOR_SAMPLES]; - int sampleHover = -1; - int sampleSelected = 0; - - for (int i = 0; i < NUM_COLOR_SAMPLES/2; i++) sampleBoundsRec[i] = (Rectangle) {colorPickerPos.x + 2*rgbWidthLabel + i*rgbWidthLabel + 3*rgbDelta + i*rgbDelta, colorPickerPos.y + 300 + 2*rgbDelta, rgbWidthLabel, rgbWidthLabel - 2}; - for (int i = NUM_COLOR_SAMPLES/2; i < NUM_COLOR_SAMPLES; i++) sampleBoundsRec[i] = (Rectangle) {colorPickerPos.x + 2*rgbWidthLabel + (i-5)*rgbWidthLabel + 3*rgbDelta + (i-5)*rgbDelta, colorPickerPos.y + 300 + 2*rgbDelta + rgbWidthLabel + 2, rgbWidthLabel, rgbWidthLabel - 2}; - //------------------------------------------------------------ - - // Value size selection - //----------------------------------------------------------- - int sizeValueSelected = 10; - //----------------------------------------------------------- - Color bgColor = RAYWHITE; - + // Gui controls data + //----------------------------------------------------------- bool toggle = false; bool toggleValue = false; char *toggleGuiText[3] = { "toggle", "group", "selection" }; float sliderValue = 50.0f; - float sliderBarValue = 50.0f; + float sliderBarValue = 20.0f; float progressValue = 0.0f; bool checked = false; @@ -229,9 +196,10 @@ int main() char *comboText[5] = { "this", "is", "a" ,"combo", "box" }; int comboActive = 0; - char guiText[16] = "\0"; + char guiText[17] = { '\0' }; - bool isModified = false; + Vector2 colorPickerPos = { (float)screenWidth - 287, 20.0f }; + Color colorPickerValue = RED; //----------------------------------------------------------- // Get current directory @@ -240,7 +208,7 @@ int main() currentPath[strlen(currentPath)] = '\\'; currentPath[strlen(currentPath) + 1] = '\0'; // Not really required - LoadGuiStyleImage("rguistyle_default_dark.png"); + GuiLoadStyleImage("rguistyle_default_dark.png"); SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -253,33 +221,33 @@ int main() if (IsFileDropped()) { droppedFiles = GetDroppedFiles(&dropsCount); - LoadGuiStyle(droppedFiles[0]); + GuiLoadStyle(droppedFiles[0]); ClearDroppedFiles(); } - // NOTE: We must verify that guiElementSelected and guiPropertySelected are valid + // NOTE: We must verify that guiControlSelected and guiPropertySelected are valid - // Check gui element selected - for (int i = 0; i < NUM_ELEMENTS; i++) + // Check gui control selected + for (int i = 0; i < NUM_CONTROLS; i++) { - if (CheckCollisionPointRec(GetMousePosition(), guiElementRec[i])) + if (CheckCollisionPointRec(GetMousePosition(), guiControlListRec[i])) { - guiElementSelected = i; - guiElementHover = i; + guiControlSelected = i; + guiControlHover = i; guiPropertySelected = -1; guiPropertyHover = -1; break; } - else guiElementHover = -1; + else guiControlHover = -1; } // Check gui property selected - if (guiElementSelected != -1) + if (guiControlSelected != -1) { - for (int i = guiPropertyPos[guiElementSelected]; i < guiPropertyPos[guiElementSelected] + guiPropertyNum[guiElementSelected]; i++) + for (int i = guiPropertyPos[guiControlSelected]; i < guiPropertyPos[guiControlSelected] + guiPropertyNum[guiControlSelected]; i++) { - if (CheckCollisionPointRec(GetMousePosition(), propertyRec[i])) + if (CheckCollisionPointRec(GetMousePosition(), guiPropertyListRec[i])) { guiPropertyHover = i; @@ -289,14 +257,9 @@ int main() if (guiPropertyType[guiPropertyHover] == 0) // Color type { // Update color picker color value - colorPickerValue = GetColor(GetStyleProperty(guiPropertyHover)); - redValue = colorPickerValue.r; - greenValue = colorPickerValue.g; - blueValue = colorPickerValue.b; - cursorPickerPos = (Vector2){screenWidth, screenHeight}; + colorPickerValue = GetColor(GuiGetStyleProperty(guiPropertyHover)); } - // Value Type - else if (guiPropertyType[guiPropertyHover] == 1) sizeValueSelected = GetStyleProperty(guiPropertyHover); + //else if (guiPropertyType[guiPropertyHover] == 1) sizeValueSelected = GuiGetStyleProperty(guiPropertyHover); } // Check if gui property is clicked @@ -309,13 +272,9 @@ int main() if ((guiPropertyHover > -1) && (guiPropertyType[guiPropertyHover] == 0)) { - if (guiPropertySelected > -1) colorPickerValue = GetColor(GetStyleProperty(guiPropertySelected)); - - redValue = colorPickerValue.r; - greenValue = colorPickerValue.g; - blueValue = colorPickerValue.b; + if (guiPropertySelected > -1) colorPickerValue = GetColor(GuiGetStyleProperty(guiPropertySelected)); } - else if (guiPropertySelected > -1) sizeValueSelected = GetStyleProperty(guiPropertySelected); + //else if (guiPropertySelected > -1) sizeValueSelected = GuiGetStyleProperty(guiPropertySelected); } } break; @@ -324,137 +283,33 @@ int main() } } - //if (guiElementSelected == PROGRESSBAR) - { - if (progressValue > 1.0f) progressValue = 0.0f; - progressValue += 0.0005f; - } - - if (guiPropertySelected != -1) - { - // Update style size value - if (guiPropertyType[guiPropertySelected] == 1) - { - if (GetStyleProperty(guiPropertySelected) != sizeValueSelected) - { - isModified = true; - SetStyleProperty(guiPropertySelected, sizeValueSelected); - } - } - - // Color samples - /* - if (CheckCollisionPointRec(GetMousePosition(), colorSelectedBoundsRec)) - { - colorSelectedHover = true; - - if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) colorSample[sampleSelected] = colorPickerValue; - } - else colorSelectedHover = false; - - for (int i = 0; i < NUM_COLOR_SAMPLES; i++) - { - if (CheckCollisionPointRec(GetMousePosition(), sampleBoundsRec[i])) - { - sampleHover = i; - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) - { - sampleSelected = i; - } - if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) - { - sampleSelected = i; - colorPickerValue = colorSample[sampleSelected]; - redValue = colorPickerValue.r; - greenValue = colorPickerValue.g; - blueValue = colorPickerValue.b; - alphaValue = colorPickerValue.a; - } - } - } - */ - - // Update style color value - if (guiPropertySelected == DEFAULT_BACKGROUND_COLOR) bgColor = colorPickerValue; - else if ((guiPropertySelected >= 0) && (guiPropertyType[guiPropertySelected] == 0)) - { - bgColor = GetColor(GetStyleProperty(DEFAULT_BACKGROUND_COLOR)); - SetStyleProperty(guiPropertySelected, GetHexValue(colorPickerValue)); - } - } + // Update progress bar automatically + progressValue += 0.0005f; + if (progressValue > 1.0f) progressValue = 0.0f; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); - ClearBackground(RAYWHITE); + ClearBackground(RAYWHITE); - // Show selected properties - //if (guiPropertySelected >= 0) DrawText(FormatText("SELECTED PROPERTY: <%s>", guiPropertyName[guiPropertySelected]), 5, screenHeight - STATUS_BAR_HEIGHT + 8, FONT_SIZE , BLACK); - //else DrawText("SELECTED PROPERTY: