Multiple improvements

- Text Edit: Support text delete while pressing backspace.
- Support PNG styles drag&drop
- Support layout Reset -> CTRL+N (new layout)
This commit is contained in:
Ray 2018-05-16 13:01:13 +02:00
parent 83c04e8723
commit d2553a1403

View File

@ -289,6 +289,9 @@ int main()
bool tracemapEditMode = false; bool tracemapEditMode = false;
float tracemapFade = 0.5f; float tracemapFade = 0.5f;
// loadedTexture for checking if texture is a tracemap or a style
Texture2D loadedTexture = { 0 };
// Very basic undo system // Very basic undo system
// Undo last-selected rectangle changes // Undo last-selected rectangle changes
// Undo text/name editing on cancel (KEY_ESC) // Undo text/name editing on cancel (KEY_ESC)
@ -325,6 +328,11 @@ int main()
config.fullComments = false; config.fullComments = false;
config.defineTexts = false; config.defineTexts = false;
// Delete current layout and reset variables
bool resetWindowActive = false;
bool resetLayout = false;
SetTargetFPS(120); SetTargetFPS(120);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -343,6 +351,7 @@ int main()
if (IsKeyPressed(KEY_ESCAPE) && !textEditMode && !nameEditMode) if (IsKeyPressed(KEY_ESCAPE) && !textEditMode && !nameEditMode)
{ {
if (generateWindowActive) generateWindowActive = false; if (generateWindowActive) generateWindowActive = false;
else if (resetWindowActive) resetWindowActive = false;
else else
{ {
closingWindowActive = !closingWindowActive; closingWindowActive = !closingWindowActive;
@ -428,7 +437,7 @@ int main()
} }
// Create new control // Create new control
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && (selectedControl == -1) && !anchorMode && !tracemapEditMode && !closingWindowActive && !paletteMode && !generateWindowActive) if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && (selectedControl == -1) && !anchorMode && !tracemapEditMode && !closingWindowActive && !paletteMode && !generateWindowActive && (!resetWindowActive))
{ {
// Add new control (button) // Add new control (button)
layout.controls[layout.controlsCount].id = layout.controlsCount; layout.controls[layout.controlsCount].id = layout.controlsCount;
@ -503,7 +512,7 @@ int main()
} }
} }
if (!(controlDrag || controlLockMode || tracemapEditMode || anchorLockMode || closingWindowActive || paletteMode || generateWindowActive)) if (!(controlDrag || controlLockMode || tracemapEditMode || anchorLockMode || closingWindowActive || paletteMode || generateWindowActive || resetWindowActive))
{ {
// Check selected control (on mouse hover) // Check selected control (on mouse hover)
for (int i = layout.controlsCount; i >= 0; i--) for (int i = layout.controlsCount; i >= 0; i--)
@ -746,7 +755,7 @@ int main()
// Replaces characters with pressed keys or '\0' in case of backspace // Replaces characters with pressed keys or '\0' in case of backspace
// NOTE: Only allow keys in range [32..125] // NOTE: Only allow keys in range [32..125]
if ((key >= 32) && (key <= 125) && (keyCount < 31)) if (((key >= 32) && (key <= 125)) && (keyCount < 31))
{ {
layout.controls[selectedControl].text[keyCount] = (unsigned char)key; layout.controls[selectedControl].text[keyCount] = (unsigned char)key;
} }
@ -828,7 +837,7 @@ int main()
} }
// Turns on NameEditMode // Turns on NameEditMode
if (IsKeyPressed(KEY_N) && !textEditMode && (selectedControl != -1) && (!generateWindowActive)) if (IsKeyPressed(KEY_N) && (!IsKeyDown(KEY_LEFT_CONTROL)) && (!resetWindowActive) && !textEditMode && (selectedControl != -1) && (!generateWindowActive))
{ {
nameEditMode = true; nameEditMode = true;
strcpy(prevControlName, layout.controls[selectedControl].name); strcpy(prevControlName, layout.controls[selectedControl].name);
@ -911,7 +920,7 @@ int main()
} }
// Create and edit anchor points // Create and edit anchor points
if (anchorMode) if (anchorMode && (!generateWindowActive) && (!resetWindowActive) && (!closingWindowActive))
{ {
// On mouse click anchor is created // On mouse click anchor is created
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && (selectedAnchor == -1) && (selectedControl == -1)) if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && (selectedAnchor == -1) && (selectedControl == -1))
@ -1091,9 +1100,18 @@ int main()
} }
else if (IsFileExtension(droppedFileName, ".rgs")) GuiLoadStyle(droppedFileName); else if (IsFileExtension(droppedFileName, ".rgs")) GuiLoadStyle(droppedFileName);
else if (IsFileExtension(droppedFileName, ".png")) else if (IsFileExtension(droppedFileName, ".png"))
{
if (loadedTexture.id > 0) UnloadTexture(loadedTexture);
loadedTexture = LoadTexture(droppedFileName);
if (loadedTexture.width == 64 && loadedTexture.height == 16) GuiLoadStyleImage(droppedFileName);
else
{ {
if (tracemap.id > 0) UnloadTexture(tracemap); if (tracemap.id > 0) UnloadTexture(tracemap);
tracemap = LoadTexture(droppedFileName); tracemap = LoadTexture(droppedFileName);
}
UnloadTexture(loadedTexture);
SetTextureFilter(tracemap, FILTER_BILINEAR); SetTextureFilter(tracemap, FILTER_BILINEAR);
@ -1241,6 +1259,39 @@ int main()
} }
if ((IsKeyDown(KEY_LEFT_CONTROL)) && (IsKeyPressed(KEY_Z))) layout.controls[undoSelectedControl].rec = undoLastRec; if ((IsKeyDown(KEY_LEFT_CONTROL)) && (IsKeyPressed(KEY_Z))) layout.controls[undoSelectedControl].rec = undoLastRec;
if ((IsKeyDown(KEY_LEFT_CONTROL)) && (IsKeyPressed(KEY_N)) && (!generateWindowActive) && (!closingWindowActive))
{
resetWindowActive = true;
resetLayout = false;
}
if (resetWindowActive && resetLayout)
{
// Resets all controls to default values
for (int i = selectedControl; i < layout.controlsCount; i++)
{
layout.controls[i].id = 0;
layout.controls[i].type = 0;
layout.controls[i].rec = (Rectangle){ 0, 0, 0, 0 };
memset(layout.controls[i].text, 0, 32);
memset(layout.controls[i].name, 0, 32);
layout.controls[i].ap = &layout.anchors[0]; // By default, set parent anchor
}
// Resets anchor points to default values
for (int i = 0; i < MAX_ANCHOR_POINTS; i++)
{
layout.anchors[i].x = 0;
layout.anchors[i].y = 0;
layout.anchors[i].enabled = false;
layout.anchors[i].hidding = false;
}
SetWindowTitle("rGuiLayout v1.0");
layout.controlsCount = 0;
resetWindowActive = false;
}
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
@ -1441,7 +1492,7 @@ int main()
if (((framesCounter/20)%2) == 0) DrawText("|", layout.controls[selectedControl].rec.x + layout.controls[selectedControl].rec.width/2 + layout.controls[selectedControl].ap->x + MeasureText(layout.controls[selectedControl].name, style[DEFAULT_TEXT_SIZE]*2)/2 + 2, layout.controls[selectedControl].rec.y + layout.controls[selectedControl].ap->y + layout.controls[selectedControl].rec.height/2 - 10, style[DEFAULT_TEXT_SIZE]*2 + 2, BLACK); if (((framesCounter/20)%2) == 0) DrawText("|", layout.controls[selectedControl].rec.x + layout.controls[selectedControl].rec.width/2 + layout.controls[selectedControl].ap->x + MeasureText(layout.controls[selectedControl].name, style[DEFAULT_TEXT_SIZE]*2)/2 + 2, layout.controls[selectedControl].rec.y + layout.controls[selectedControl].ap->y + layout.controls[selectedControl].rec.height/2 - 10, style[DEFAULT_TEXT_SIZE]*2 + 2, BLACK);
} }
else if ((IsKeyDown(KEY_N)) && (!textEditMode) && (!generateWindowActive)) else if ((IsKeyDown(KEY_N)) && (!textEditMode) && (!generateWindowActive) && (!resetWindowActive))
{ {
if (layout.controlsCount > 0) DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(WHITE, 0.7f)); if (layout.controlsCount > 0) DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(WHITE, 0.7f));
@ -1607,6 +1658,23 @@ int main()
else if (GuiButton((Rectangle){ GetScreenWidth()/2 + 10, GetScreenHeight()/2 + 10, 85, 25 }, "No")) { exitWindow = true; } else if (GuiButton((Rectangle){ GetScreenWidth()/2 + 10, GetScreenHeight()/2 + 10, 85, 25 }, "No")) { exitWindow = true; }
} }
// Draw reset message window (save)
if (resetWindowActive)
{
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(WHITE, 0.7f));
resetWindowActive = !GuiWindowBox((Rectangle){ GetScreenWidth()/2 - 125, GetScreenHeight()/2 - 50, 250, 100 }, "Creating new layout");
GuiLabel((Rectangle){ GetScreenWidth()/2 - 95, GetScreenHeight()/2 - 60, 200, 100 }, "Do you want to save the current layout?");
if (GuiButton((Rectangle){ GetScreenWidth()/2 - 94, GetScreenHeight()/2 + 10, 85, 25 }, "Yes"))
{
cancelSave = false;
ShowSaveLayoutDialog();
if (cancelSave) resetLayout = true;
}
else if (GuiButton((Rectangle){ GetScreenWidth()/2 + 10, GetScreenHeight()/2 + 10, 85, 25 }, "No")) { resetLayout = true; }
}
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }