mirror of
https://github.com/raysan5/raygui.git
synced 2025-12-25 10:22:33 -05:00
Changed save/load system, created layouts
Corrected delete bug, creating text bug, resize control
This commit is contained in:
23
tools/rGuiLayout/layouts/image_exporter.rgl
Normal file
23
tools/rGuiLayout/layouts/image_exporter.rgl
Normal file
@ -0,0 +1,23 @@
|
||||
#
|
||||
# rgl text file (v1.0) - raygui layout text file generated using rGuiLayout
|
||||
#
|
||||
# Total number of controls: 8
|
||||
# Anchor info: a <id> <posx> <posy> <enabled>
|
||||
# Control info: c <id> <type> <rectangle> <anchor_id> <text>
|
||||
#
|
||||
a 000 0 0 1
|
||||
a 001 0 0 0
|
||||
a 002 0 0 0
|
||||
a 003 0 0 0
|
||||
a 004 0 0 0
|
||||
a 005 0 0 0
|
||||
a 006 0 0 0
|
||||
a 007 0 0 0
|
||||
c 000 13 24 15 220 161 0 Image Export Options
|
||||
c 001 9 102 47 130 20 0
|
||||
c 002 9 102 77 130 20 0 SAMPLE TEXT
|
||||
c 003 11 102 107 131 22 0 Untitled
|
||||
c 004 1 35 139 200 30 0 Export Image
|
||||
c 005 0 35 53 60 20 0 File format
|
||||
c 006 0 35 83 61 20 0 Pixel format
|
||||
c 007 0 35 113 50 20 0 File name
|
||||
38
tools/rGuiLayout/layouts/raw_importer.rgl
Normal file
38
tools/rGuiLayout/layouts/raw_importer.rgl
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# rgl text file (v1.0) - raygui layout text file generated using rGuiLayout
|
||||
#
|
||||
# Total number of controls: 23
|
||||
# Anchor info: a <id> <posx> <posy> <enabled>
|
||||
# Control info: c <id> <type> <rectangle> <anchor_id> <text>
|
||||
#
|
||||
a 000 0 0 1
|
||||
a 001 0 0 0
|
||||
a 002 0 0 0
|
||||
a 003 0 0 0
|
||||
a 004 0 0 0
|
||||
a 005 0 0 0
|
||||
a 006 0 0 0
|
||||
a 007 0 0 0
|
||||
c 000 13 116 65 200 452 0 RAW Import Options
|
||||
c 001 0 126 96 56 20 0
|
||||
c 002 0 126 116 80 20 0 File size:
|
||||
c 004 0 136 166 30 20 0 Width:
|
||||
c 005 0 136 191 33 20 0 Height:
|
||||
c 006 0 266 166 30 20 0 pixels
|
||||
c 007 0 266 191 30 20 0 pixels
|
||||
c 008 11 176 161 80 20 0
|
||||
c 009 11 176 186 80 20 0
|
||||
c 011 0 138 254 63 20 0 Pixel format:
|
||||
c 012 9 137 268 158 21 0 SAMPLE TEXT
|
||||
c 013 0 137 304 50 20 0 Channels:
|
||||
c 012 4 137 317 156 20 0 Bit Depth:
|
||||
c 013 4 137 358 156 20 0 Bit Depth:
|
||||
c 014 0 137 345 50 20 0 Bit Depth:
|
||||
c 015 0 136 432 22 20 0 Size:
|
||||
c 016 0 266 432 30 20 0 bytes
|
||||
c 017 11 176 427 80 20 0
|
||||
c 018 1 126 477 180 24 0 SAMPLE TEXT
|
||||
c 019 12 126 412 179 49 0 Header
|
||||
c 020 12 126 241 179 150 0 Pixels Data
|
||||
c 021 12 126 141 179 79 0 Resolution
|
||||
c 022 0 126 96 54 20 0 Import file:
|
||||
113
tools/rGuiLayout/layouts/rfxgen.rgl
Normal file
113
tools/rGuiLayout/layouts/rfxgen.rgl
Normal file
@ -0,0 +1,113 @@
|
||||
#
|
||||
# rgl text file (v1.0) - raygui layout text file generated using rGuiLayout
|
||||
#
|
||||
# Total number of controls: 98
|
||||
# Anchor info: a <id> <posx> <posy> <enabled>
|
||||
# Control info: c <id> <type> <rectangle> <anchor_id> <text>
|
||||
#
|
||||
a 000 0 0 1
|
||||
a 001 0 0 0
|
||||
a 002 0 0 0
|
||||
a 003 0 0 0
|
||||
a 004 0 0 0
|
||||
a 005 0 0 0
|
||||
a 006 0 0 0
|
||||
a 007 0 0 0
|
||||
c 000 1 113 98 92 20 0 Pickup/Coin
|
||||
c 001 1 113 123 92 20 0 Laser/Shoot
|
||||
c 002 1 113 148 92 20 0 Explosion
|
||||
c 003 1 113 173 92 20 0 Powerup
|
||||
c 004 1 113 198 92 20 0 Hit/Hurt
|
||||
c 005 1 113 223 92 20 0 Jump
|
||||
c 006 1 113 248 92 20 0 Blip/Select
|
||||
c 007 1 113 414 92 20 0 Mutate
|
||||
c 008 1 113 439 92 20 0 Randomize
|
||||
c 009 1 494 65 92 20 0 Screen Size x2
|
||||
c 010 1 494 333 92 20 0 Load Sound
|
||||
c 011 1 494 357 92 20 0 Save Sound
|
||||
c 012 1 494 439 92 20 0 Export Wav
|
||||
c 013 1 494 131 92 20 0 Play Sound
|
||||
c 014 10 494 165 10 10 0 SAMPLE TEXT
|
||||
c 015 0 510 165 80 20 0 Play on change
|
||||
c 016 0 494 190 80 20 0 powered by
|
||||
c 017 0 505 300 70 20 0 www.raylib.com
|
||||
c 018 0 494 99 92 20 0 VOLUME: 60 %
|
||||
c 019 6 494 115 92 10 0 SAMPLE TEXT
|
||||
c 020 9 494 390 92 20 0 SAMPLE TEXT
|
||||
c 021 9 494 414 92 20 0 SAMPLE TEXT
|
||||
c 022 4 217 65 264 20 0 SAMPLE TEXT
|
||||
c 023 0 116 285 90 20 0 based on sfxr by
|
||||
c 024 0 113 298 98 20 0 Tomas Pettersson
|
||||
c 025 0 118 370 100 20 0 www.github.com/
|
||||
c 026 0 118 385 81 20 0 raysan5/raylib
|
||||
c 027 6 344 98 100 10 0 SAMPLE TEXT
|
||||
c 028 6 344 113 100 10 0 SAMPLE TEXT
|
||||
c 029 6 344 128 100 10 0 SAMPLE TEXT
|
||||
c 030 6 344 143 100 10 0 SAMPLE TEXT
|
||||
c 031 6 344 164 100 10 0 SAMPLE TEXT
|
||||
c 032 6 344 179 100 10 0 SAMPLE TEXT
|
||||
c 033 6 344 194 100 10 0 SAMPLE TEXT
|
||||
c 034 6 344 209 100 10 0 SAMPLE TEXT
|
||||
c 035 6 344 224 100 10 0 SAMPLE TEXT
|
||||
c 036 6 344 239 100 10 0 SAMPLE TEXT
|
||||
c 037 6 344 260 100 10 0 SAMPLE TEXT
|
||||
c 038 6 344 275 100 10 0 SAMPLE TEXT
|
||||
c 039 6 344 296 100 10 0 SAMPLE TEXT
|
||||
c 040 6 344 311 100 10 0 SAMPLE TEXT
|
||||
c 041 6 344 332 100 10 0 SAMPLE TEXT
|
||||
c 042 6 344 353 100 10 0 SAMPLE TEXT
|
||||
c 043 6 344 368 100 10 0 SAMPLE TEXT
|
||||
c 044 6 344 389 100 10 0 SAMPLE TEXT
|
||||
c 045 6 344 404 100 10 0 SAMPLE TEXT
|
||||
c 046 6 344 419 100 10 0 SAMPLE TEXT
|
||||
c 047 6 344 434 100 10 0 SAMPLE TEXT
|
||||
c 048 6 344 449 100 10 0 SAMPLE TEXT
|
||||
c 049 14 427 530 173 20 0 Wave size:
|
||||
c 050 14 100 530 201 20 0 SOUND INFO: Num samples:
|
||||
c 051 14 300 530 128 20 0 Duration:
|
||||
c 052 0 451 450 20 20 0 0.00
|
||||
c 053 0 451 99 20 20 0 0.00
|
||||
c 054 0 451 129 20 20 0 0.00
|
||||
c 055 0 451 180 20 20 0 0.00
|
||||
c 056 0 451 195 20 20 0 0.00
|
||||
c 057 0 451 210 20 20 0 0.00
|
||||
c 058 0 451 225 20 20 0 0.00
|
||||
c 059 0 451 240 20 20 0 0.00
|
||||
c 060 0 451 261 20 20 0 0.00
|
||||
c 061 0 451 276 20 20 0 0.00
|
||||
c 062 0 451 297 20 20 0 0.00
|
||||
c 063 0 451 312 19 20 0 0.00
|
||||
c 064 0 451 333 19 20 0 0.00
|
||||
c 065 0 451 354 19 20 0 0.00
|
||||
c 066 0 451 390 20 20 0 1.00
|
||||
c 067 0 451 405 20 20 0 0.00
|
||||
c 068 0 451 420 20 20 0 0.00
|
||||
c 069 0 451 435 20 20 0 0.00
|
||||
c 070 0 451 165 20 20 0 0.30
|
||||
c 071 0 451 114 20 20 0 0.30
|
||||
c 072 0 451 144 20 20 0 0.40
|
||||
c 073 0 451 369 19 20 0 0.00
|
||||
c 074 0 258 98 80 20 0 ATTACK TIME
|
||||
c 075 0 255 113 81 20 0 SUSTAIN TIME
|
||||
c 076 0 247 128 90 20 0 SUSTAIN PUNCH
|
||||
c 077 0 267 143 70 20 0 DECAY TIME
|
||||
c 078 0 229 164 103 20 0 START FREQUENCY
|
||||
c 079 0 247 179 90 20 0 MIN FREQUENCY
|
||||
c 080 0 302 194 30 20 0 SLIDE
|
||||
c 081 0 263 209 70 20 0 DELTA SLIDE
|
||||
c 082 0 246 239 90 20 0 VIBRATO SPEED
|
||||
c 083 0 245 224 90 20 0 VIBRATO DEPTH
|
||||
c 084 0 243 260 90 20 0 CHANGE AMOUNT
|
||||
c 085 0 252 275 80 20 0 CHANGE SPEED
|
||||
c 086 0 258 296 80 20 0 SQUARE DUTY
|
||||
c 087 0 264 311 68 20 0 DUTY SWEEP
|
||||
c 088 0 251 332 81 20 0 REPEAT SPEED
|
||||
c 089 0 251 368 81 20 0 PHASER SWEEP
|
||||
c 090 0 244 353 88 20 0 PHASER OFFSET
|
||||
c 091 0 226 404 106 20 0 LPF CUTOFF SWEEP
|
||||
c 092 0 266 389 66 20 0 LPF CUTOFF
|
||||
c 093 0 246 419 86 20 0 LPF RESONANCE
|
||||
c 094 0 225 449 107 20 0 HPF CUTOFF SWEEP
|
||||
c 095 0 265 434 67 20 0 HPF CUTOFF
|
||||
c 096 0 118 330 100 20 0 www.github.com/
|
||||
c 097 0 118 345 81 20 0 raysan5/raygui
|
||||
42
tools/rGuiLayout/layouts/rtexpacker_right_panel.rgl
Normal file
42
tools/rGuiLayout/layouts/rtexpacker_right_panel.rgl
Normal file
@ -0,0 +1,42 @@
|
||||
#
|
||||
# rgl text file (v1.0) - raygui layout text file generated using rGuiLayout
|
||||
#
|
||||
# Total number of controls: 27
|
||||
# Anchor info: a <id> <posx> <posy> <enabled>
|
||||
# Control info: c <id> <type> <rectangle> <anchor_id> <text>
|
||||
#
|
||||
a 000 0 0 1
|
||||
a 001 0 0 0
|
||||
a 002 0 0 0
|
||||
a 003 0 0 0
|
||||
a 004 0 0 0
|
||||
a 005 0 0 0
|
||||
a 006 0 0 0
|
||||
a 007 0 0 0
|
||||
c 000 14 285 25 226 30 0 ATLAS SETTINGS
|
||||
c 001 0 300 90 50 20 0 Algorythm
|
||||
c 002 0 300 120 51 20 0 Heuristics
|
||||
c 003 0 300 150 38 20 0 Padding
|
||||
c 004 10 300 180 20 20 0 SAMPLE TEXT
|
||||
c 005 10 300 210 20 20 0 SAMPLE TEXT
|
||||
c 006 10 300 240 20 20 0 SAMPLE TEXT
|
||||
c 007 0 340 185 62 20 0 Trim sprites
|
||||
c 008 0 340 215 111 20 0 Allow sprites rotation
|
||||
c 009 0 340 245 92 20 0 Remove duplicates
|
||||
c 010 9 365 85 130 20 0 SAMPLE TEXT
|
||||
c 011 9 365 115 130 20 0 SAMPLE TEXT
|
||||
c 012 8 365 145 130 20 0 SAMPLE TEXT
|
||||
c 013 12 290 70 215 200 0 Size
|
||||
c 014 0 300 310 20 20 0 Size
|
||||
c 015 11 340 305 70 20 0
|
||||
c 016 11 425 305 70 20 0
|
||||
c 017 10 300 340 20 20 0 SAMPLE TEXT
|
||||
c 018 10 300 370 20 20 0 SAMPLE TEXT
|
||||
c 019 0 335 345 56 20 0 Force POT
|
||||
c 020 0 335 375 76 20 0 Force squared
|
||||
c 021 0 300 408 61 20 0 Pixel format
|
||||
c 022 9 375 403 120 20 0 SAMPLE TEXT
|
||||
c 023 10 300 430 20 20 0 SAMPLE TEXT
|
||||
c 024 0 335 435 58 20 0 Clear alpha
|
||||
c 025 1 300 460 195 25 0 Export
|
||||
c 026 12 290 290 215 205 0 Texture
|
||||
@ -26,7 +26,9 @@
|
||||
#define MAX_ANCHOR_POINTS 8 // Maximum number of anchor points
|
||||
|
||||
#define GRID_LINE_SPACING 10 // Grid line spacing in pixels
|
||||
#define GRID_ALPHA 0.1f // Grid lines alpha amount
|
||||
#define GRID_ALPHA 0.1f // Grid lines alpha amount
|
||||
|
||||
#define ANCHOR_RADIUS 20 // Default anchor radius
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
@ -56,7 +58,6 @@ typedef struct {
|
||||
int id;
|
||||
int x;
|
||||
int y;
|
||||
float radius;
|
||||
bool enabled;
|
||||
} AnchorPoint;
|
||||
|
||||
@ -73,7 +74,6 @@ typedef struct {
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
static char currentPath[256]; // Path to current working folder
|
||||
static int screenWidth = 800;
|
||||
static int screenHeight = 600;
|
||||
|
||||
@ -207,7 +207,6 @@ int main()
|
||||
anchors[i].id = i;
|
||||
anchors[i].x = 0;
|
||||
anchors[i].y = 0;
|
||||
anchors[i].radius = 20;
|
||||
anchors[i].enabled = false;
|
||||
}
|
||||
|
||||
@ -219,8 +218,8 @@ int main()
|
||||
layout[i].id = 0;
|
||||
layout[i].type = 0;
|
||||
layout[i].rec = (Rectangle){ 0, 0, 0, 0 };
|
||||
layout[i].text = (unsigned char *)malloc(32);
|
||||
strcpy(layout[i].text, "SAMPLE TEXT\0");
|
||||
layout[i].text = (unsigned char *)calloc(1, 32);
|
||||
strcpy(layout[i].text, "SAMPLE TEXT");
|
||||
layout[i].ap = &anchors[0]; // By default, set parent anchor
|
||||
}
|
||||
|
||||
@ -304,7 +303,7 @@ int main()
|
||||
layout[controlsCounter].id = controlsCounter;
|
||||
layout[controlsCounter].type = selectedType;
|
||||
layout[controlsCounter].rec = (Rectangle){ mouseX - defaultRec[selectedType].width/2, mouseY - defaultRec[selectedType].height/2, defaultRec[selectedType].width, defaultRec[selectedType].height };
|
||||
strcpy(layout[controlsCounter].text, "SAMPLE TEXT\0");
|
||||
strcpy(layout[controlsCounter].text, "SAMPLE TEXT");
|
||||
layout[controlsCounter].ap = &anchors[0]; // Default anchor point (0, 0)
|
||||
|
||||
controlsCounter++;
|
||||
@ -358,17 +357,7 @@ int main()
|
||||
else layout[selectedControl].rec.x -= offsetX;
|
||||
|
||||
if (offsetY >= GRID_LINE_SPACING/2) layout[selectedControl].rec.y += (GRID_LINE_SPACING - offsetY);
|
||||
else layout[selectedControl].rec.y -= offsetY;
|
||||
|
||||
// Snap rectangle size to closer snap point sizes
|
||||
offsetX = layout[selectedControl].rec.width%GRID_LINE_SPACING;
|
||||
offsetY = layout[selectedControl].rec.height%GRID_LINE_SPACING;
|
||||
|
||||
if (offsetX >= GRID_LINE_SPACING/2) layout[selectedControl].rec.width += (GRID_LINE_SPACING - offsetX);
|
||||
else layout[selectedControl].rec.width -= offsetX;
|
||||
|
||||
if (offsetY >= GRID_LINE_SPACING/2) layout[selectedControl].rec.height += (GRID_LINE_SPACING - offsetY);
|
||||
else layout[selectedControl].rec.height -= offsetY;
|
||||
else layout[selectedControl].rec.y -= offsetY;
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,7 +382,7 @@ int main()
|
||||
else if (IsKeyPressed(KEY_DOWN)) layout[selectedControl].rec.height += GRID_LINE_SPACING;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int offsetX = layout[selectedControl].rec.width%GRID_LINE_SPACING;
|
||||
int offsetY = layout[selectedControl].rec.height%GRID_LINE_SPACING;
|
||||
|
||||
@ -402,6 +391,7 @@ int main()
|
||||
|
||||
if (offsetY >= GRID_LINE_SPACING/2) layout[selectedControl].rec.height += (GRID_LINE_SPACING - offsetY);
|
||||
else layout[selectedControl].rec.height -= offsetY;
|
||||
*/
|
||||
}
|
||||
|
||||
else
|
||||
@ -437,14 +427,21 @@ int main()
|
||||
// Delete selected control and shift array position
|
||||
if (IsKeyPressed(KEY_DELETE))
|
||||
{
|
||||
for (int i = selectedControl; i < controlsCounter; i++) layout[i] = layout[i + 1];
|
||||
for (int i = selectedControl; i < controlsCounter; i++)
|
||||
{
|
||||
layout[i].id = layout[i + 1].id;
|
||||
layout[i].type = layout[i + 1].type;
|
||||
layout[i].rec = layout[i + 1].rec;
|
||||
strcpy(layout[i].text, layout[i + 1].text);
|
||||
layout[i].ap = layout[i + 1].ap;
|
||||
}
|
||||
|
||||
controlsCounter--;
|
||||
selectedControl = -1;
|
||||
}
|
||||
|
||||
// Unlinks the control selected from its current anchor
|
||||
if(IsKeyPressed(KEY_R))
|
||||
if(IsKeyPressed(KEY_U))
|
||||
{
|
||||
layout[selectedControl].rec.x += layout[selectedControl].ap->x;
|
||||
layout[selectedControl].rec.y += layout[selectedControl].ap->y;
|
||||
@ -494,6 +491,7 @@ int main()
|
||||
if (offsetY >= GRID_LINE_SPACING/2) defaultRec[selectedType].y += (GRID_LINE_SPACING - offsetY);
|
||||
else defaultRec[selectedType].y -= offsetY;
|
||||
// Snap rectangle size to closer snap point sizes
|
||||
/*
|
||||
offsetX = defaultRec[selectedType].width%GRID_LINE_SPACING;
|
||||
offsetY = defaultRec[selectedType].height%GRID_LINE_SPACING;
|
||||
|
||||
@ -502,6 +500,22 @@ int main()
|
||||
|
||||
if (offsetY >= GRID_LINE_SPACING/2) defaultRec[selectedType].height += (GRID_LINE_SPACING - offsetY);
|
||||
else defaultRec[selectedType].height -= offsetY;
|
||||
*/
|
||||
}
|
||||
|
||||
// Resize the controller aplying the snap
|
||||
if (!textEditMode && IsKeyPressed(KEY_R) && selectedControl != -1)
|
||||
{
|
||||
|
||||
int offsetX = layout[selectedControl].rec.width%GRID_LINE_SPACING;
|
||||
int offsetY = layout[selectedControl].rec.height%GRID_LINE_SPACING;
|
||||
|
||||
if (offsetX >= GRID_LINE_SPACING/2) layout[selectedControl].rec.width += (GRID_LINE_SPACING - offsetX);
|
||||
else layout[selectedControl].rec.width -= offsetX;
|
||||
|
||||
if (offsetY >= GRID_LINE_SPACING/2) layout[selectedControl].rec.height += (GRID_LINE_SPACING - offsetY);
|
||||
else layout[selectedControl].rec.height -= offsetY;
|
||||
|
||||
}
|
||||
|
||||
// Check if control has text to edit
|
||||
@ -514,9 +528,9 @@ int main()
|
||||
|
||||
// Replaces characters with pressed keys or '\0' in case of backspace
|
||||
// NOTE: Only allow keys in range [32..125]
|
||||
if ((key >= 32) && (key <= 125) && (keyCount < 32))
|
||||
if ((key >= 32) && (key <= 125) && (keyCount < 31))
|
||||
{
|
||||
layout[selectedControl].text[keyCount] = (char)key;
|
||||
layout[selectedControl].text[keyCount] = (unsigned char)key;
|
||||
}
|
||||
|
||||
if (IsKeyPressed(KEY_BACKSPACE_TEXT))
|
||||
@ -568,7 +582,7 @@ int main()
|
||||
{
|
||||
if (anchorLinkMode || controlDrag) break;
|
||||
|
||||
if (CheckCollisionPointCircle(GetMousePosition(), (Vector2){ anchors[i].x, anchors[i].y }, anchors[i].radius))
|
||||
if (CheckCollisionPointCircle(GetMousePosition(), (Vector2){ anchors[i].x, anchors[i].y }, ANCHOR_RADIUS))
|
||||
{
|
||||
selectedAnchor = i;
|
||||
anchorMode = true;
|
||||
@ -585,7 +599,7 @@ int main()
|
||||
if (anchorMode)
|
||||
{
|
||||
// On mouse click anchor is created
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !controlCollision && selectedAnchor == -1 && selectedControl == -1)
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !controlCollision && (selectedAnchor == -1) && (selectedControl == -1))
|
||||
{
|
||||
for (int i = 1; i < MAX_ANCHOR_POINTS; i++)
|
||||
{
|
||||
@ -726,29 +740,19 @@ int main()
|
||||
|
||||
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_S))
|
||||
{
|
||||
char currrentPathFile[256];
|
||||
|
||||
// Add sample file name to currentPath
|
||||
strcpy(currrentPathFile, currentPath);
|
||||
//strcat(currrentPathFile, defaultName);
|
||||
|
||||
// Save file dialog
|
||||
const char *filters[] = { "*.rgl" };
|
||||
const char *fileName = tinyfd_saveFileDialog("Save raygui layout text file", currrentPathFile, 1, filters, "raygui Layout Files (*.rgl)");
|
||||
const char *fileName = tinyfd_saveFileDialog("Save raygui layout text file", "", 1, filters, "raygui Layout Files (*.rgl)");
|
||||
|
||||
if (fileName != NULL)
|
||||
{
|
||||
// Save layout file (text or binary)
|
||||
SaveLayoutRGL("test_layout.rgl", true);
|
||||
fileName = "";
|
||||
}
|
||||
// Save layout file (text or binary)
|
||||
if (fileName != NULL) SaveLayoutRGL(fileName, false);
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_O))
|
||||
{
|
||||
// Open file dialog
|
||||
const char *filters[] = { "*.rgl" };
|
||||
const char *fileName = tinyfd_openFileDialog("Load raygui layout file", currentPath, 1, filters, "raygui Layout Files (*.rgl)", 0);
|
||||
const char *fileName = tinyfd_openFileDialog("Load raygui layout file", "", 1, filters, "raygui Layout Files (*.rgl)", 0);
|
||||
|
||||
if (fileName != NULL)
|
||||
{
|
||||
@ -756,7 +760,7 @@ int main()
|
||||
|
||||
// Setup by default some anchor value because logic is always trying to access layout[i].ap->id
|
||||
// if layout[i].ap == NULL, program crashes
|
||||
for (int i = 0; i < controlsCounter; i++) layout[i].ap = &anchors[0];
|
||||
//for (int i = 0; i < controlsCounter; i++) layout[i].ap = &anchors[0];
|
||||
}
|
||||
}
|
||||
|
||||
@ -842,10 +846,10 @@ int main()
|
||||
// Draw the anchorPoints
|
||||
for (int i = 1; i < MAX_ANCHOR_POINTS; i++)
|
||||
{
|
||||
if (anchors[i].id == selectedAnchor) DrawCircle(anchors[i].x, anchors[i].y, anchors[i].radius, Fade(RED, 0.5f));
|
||||
else DrawCircleLines(anchors[i].x, anchors[i].y, anchors[i].radius, Fade(RED, 0.5f));
|
||||
DrawRectangle(anchors[i].x - anchors[i].radius - 5, anchors[i].y, anchors[i].radius*2 + 10, 1, RED);
|
||||
DrawRectangle(anchors[i].x, anchors[i].y - anchors[i].radius - 5, 1, anchors[i].radius*2 + 10, RED);
|
||||
if (anchors[i].id == selectedAnchor) DrawCircle(anchors[i].x, anchors[i].y, ANCHOR_RADIUS, Fade(RED, 0.5f));
|
||||
else DrawCircleLines(anchors[i].x, anchors[i].y, ANCHOR_RADIUS, Fade(RED, 0.5f));
|
||||
DrawRectangle(anchors[i].x - ANCHOR_RADIUS - 5, anchors[i].y, ANCHOR_RADIUS*2 + 10, 1, RED);
|
||||
DrawRectangle(anchors[i].x, anchors[i].y - ANCHOR_RADIUS - 5, 1, ANCHOR_RADIUS*2 + 10, RED);
|
||||
}
|
||||
|
||||
if ((selectedControl != -1) && (selectedControl < controlsCounter))
|
||||
@ -858,9 +862,9 @@ int main()
|
||||
{
|
||||
if (anchorMode)
|
||||
{
|
||||
DrawCircleLines(mouseX, mouseY, anchors[0].radius, Fade(RED, 0.5f));
|
||||
DrawRectangle(mouseX - anchors[0].radius - 5, mouseY, anchors[0].radius*2 + 10, 1, RED);
|
||||
DrawRectangle(mouseX, mouseY - anchors[0].radius - 5, 1, anchors[0].radius*2 + 10, RED);
|
||||
DrawCircleLines(mouseX, mouseY, ANCHOR_RADIUS, Fade(RED, 0.5f));
|
||||
DrawRectangle(mouseX - ANCHOR_RADIUS - 5, mouseY, ANCHOR_RADIUS*2 + 10, 1, RED);
|
||||
DrawRectangle(mouseX, mouseY - ANCHOR_RADIUS - 5, 1, ANCHOR_RADIUS*2 + 10, RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -887,22 +891,24 @@ int main()
|
||||
|
||||
if (helpMode)
|
||||
{
|
||||
DrawRectangleRec((Rectangle){ 20, 20, 260, 290 }, GetColor(style[DEFAULT_BACKGROUND_COLOR]));
|
||||
GuiGroupBox((Rectangle){ 20, 20, 260, 290 }, "Shortcuts");
|
||||
DrawRectangleRec((Rectangle){ 20, 20, 260, 330 }, GetColor(style[DEFAULT_BACKGROUND_COLOR]));
|
||||
GuiGroupBox((Rectangle){ 20, 20, 260, 330 }, "Shortcuts");
|
||||
GuiLabel((Rectangle){ 30, 30, 0, 0 }, "G - Show/hide grid");
|
||||
GuiLabel((Rectangle){ 30, 50, 0, 0 }, "S - Toggle snap");
|
||||
GuiLabel((Rectangle){ 30, 70, 0, 0 }, "A - Anchor mode");
|
||||
GuiLabel((Rectangle){ 30, 90, 0, 0 }, "Space - Lock/unlock control");
|
||||
GuiLabel((Rectangle){ 30, 110, 0, 0 }, "T - Enter text mode(if possible)");
|
||||
GuiLabel((Rectangle){ 30, 130, 0, 0 }, "Enter - Exit text mode");
|
||||
GuiLabel((Rectangle){ 30, 150, 0, 0 }, "Delete - Delete a control");
|
||||
GuiLabel((Rectangle){ 30, 170, 0, 0 }, "Arrows - Modify width/height");
|
||||
GuiLabel((Rectangle){ 30, 190, 0, 0 }, "L. Ctrl + Arrows - Modify width/height(smooth)");
|
||||
GuiLabel((Rectangle){ 30, 210, 0, 0 }, "L. Alt + Arrows - Modify position");
|
||||
GuiLabel((Rectangle){ 30, 230, 0, 0 }, "L. Ctrl + Enter - Export layout to code");
|
||||
GuiLabel((Rectangle){ 30, 250, 0, 0 }, "L. Ctrl + S - Save layout(.rgl)");
|
||||
GuiLabel((Rectangle){ 30, 270, 0, 0 }, "L. Ctrl + O - Open layout(.rgl)");
|
||||
GuiLabel((Rectangle){ 30, 290, 0, 0 }, "L. Ctrl + D - Duplicate selected control");
|
||||
GuiLabel((Rectangle){ 30, 70, 0, 0 }, "R - Resize to grid");
|
||||
GuiLabel((Rectangle){ 30, 90, 0, 0 }, "A - Anchor mode");
|
||||
GuiLabel((Rectangle){ 30, 110, 0, 0 }, "U - Unlink anchor");
|
||||
GuiLabel((Rectangle){ 30, 130, 0, 0 }, "Space - Lock/unlock control");
|
||||
GuiLabel((Rectangle){ 30, 150, 0, 0 }, "T - Enter text mode(if possible)");
|
||||
GuiLabel((Rectangle){ 30, 170, 0, 0 }, "Enter - Exit text mode");
|
||||
GuiLabel((Rectangle){ 30, 190, 0, 0 }, "Delete - Delete a control");
|
||||
GuiLabel((Rectangle){ 30, 210, 0, 0 }, "Arrows - Modify width/height");
|
||||
GuiLabel((Rectangle){ 30, 230, 0, 0 }, "L. Ctrl + Arrows - Modify width/height(smooth)");
|
||||
GuiLabel((Rectangle){ 30, 250, 0, 0 }, "L. Alt + Arrows - Modify position");
|
||||
GuiLabel((Rectangle){ 30, 270, 0, 0 }, "L. Ctrl + Enter - Export layout to code");
|
||||
GuiLabel((Rectangle){ 30, 290, 0, 0 }, "L. Ctrl + S - Save layout(.rgl)");
|
||||
GuiLabel((Rectangle){ 30, 310, 0, 0 }, "L. Ctrl + O - Open layout(.rgl)");
|
||||
GuiLabel((Rectangle){ 30, 330, 0, 0 }, "L. Ctrl + D - Duplicate selected control");
|
||||
}
|
||||
|
||||
// Draw status bar bottom with debug information
|
||||
@ -988,6 +994,14 @@ static void SaveLayoutRGL(const char *fileName, bool binary)
|
||||
fwrite(&version, 1, sizeof(short), rglFile);
|
||||
fwrite(&numControls, 1, sizeof(short), rglFile);
|
||||
fwrite(&reserved, 1, sizeof(int), rglFile);
|
||||
|
||||
for (int i = 0; i < MAX_ANCHOR_POINTS; i++)
|
||||
{
|
||||
fwrite(&anchors[i].id, 1, sizeof(int), rglFile);
|
||||
fwrite(&anchors[i].x, 1, sizeof(int), rglFile);
|
||||
fwrite(&anchors[i].y, 1, sizeof(int), rglFile);
|
||||
fwrite(&anchors[i].enabled, 1, sizeof(bool), rglFile);
|
||||
}
|
||||
|
||||
for (int i = 0; i < controlsCounter; i++)
|
||||
{
|
||||
@ -996,9 +1010,7 @@ static void SaveLayoutRGL(const char *fileName, bool binary)
|
||||
fwrite(&layout[i].type, 1, sizeof(int), rglFile);
|
||||
fwrite(&layout[i].rec, 1, sizeof(Rectangle), rglFile);
|
||||
fwrite(layout[i].text, 1, 32, rglFile);
|
||||
|
||||
|
||||
// TODO: Export anchors data
|
||||
fwrite(&layout[i].ap->id, 1, sizeof(int), rglFile);
|
||||
}
|
||||
|
||||
fclose(rglFile);
|
||||
@ -1015,11 +1027,17 @@ static void SaveLayoutRGL(const char *fileName, bool binary)
|
||||
// Write some description comments
|
||||
fprintf(rglFile, "#\n# rgl text file (v%s) - raygui layout text file generated using rGuiLayout\n#\n", RGL_FILE_VERSION_TEXT);
|
||||
fprintf(rglFile, "# Total number of controls: %i\n", controlsCounter);
|
||||
fprintf(rglFile, "# Control info: c <id> <type> <rectangle> <text> <anchor_id> <anchor_pos>\n#\n");
|
||||
fprintf(rglFile, "# Anchor info: a <id> <posx> <posy> <enabled>\n");
|
||||
fprintf(rglFile, "# Control info: c <id> <type> <rectangle> <anchor_id> <text>\n#\n");
|
||||
|
||||
for (int i = 0; i < MAX_ANCHOR_POINTS; i++)
|
||||
{
|
||||
fprintf(rglFile, "a %03i %i %i %i\n", anchors[i].id, anchors[i].x, anchors[i].y, anchors[i].enabled);
|
||||
}
|
||||
|
||||
for (int i = 0; i < controlsCounter; i++)
|
||||
{
|
||||
fprintf(rglFile, "c %03i %i %i %i %i %i %i %i %i %s\n", layout[i].id, layout[i].type, layout[i].rec.x, layout[i].rec.y, layout[i].rec.width, layout[i].rec.height, layout[i].ap->id, layout[i].ap->x, layout[i].ap->y, layout[i].text);
|
||||
fprintf(rglFile, "c %03i %i %i %i %i %i %i %s\n", layout[i].id, layout[i].type, layout[i].rec.x, layout[i].rec.y, layout[i].rec.width, layout[i].rec.height, layout[i].ap->id, layout[i].text);
|
||||
}
|
||||
|
||||
fclose(rglFile);
|
||||
@ -1088,21 +1106,29 @@ static void LoadLayoutRGL(const char *fileName)
|
||||
(signature[2] == 'L') &&
|
||||
(signature[3] == ' '))
|
||||
{
|
||||
|
||||
for (int i = 0; i < MAX_ANCHOR_POINTS; i++)
|
||||
{
|
||||
fread(&anchors[i].id, 1, sizeof(int), rglFile);
|
||||
fread(&anchors[i].x, 1, sizeof(int), rglFile);
|
||||
fread(&anchors[i].y, 1, sizeof(int), rglFile);
|
||||
fread(&anchors[i].enabled, 1, sizeof(bool), rglFile);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < controlsCounter; i++)
|
||||
{
|
||||
int anchorId = 0;
|
||||
|
||||
// Import data in independent way
|
||||
fread(&layout[i].id, 1, sizeof(int), rglFile);
|
||||
fread(&layout[i].type, 1, sizeof(int), rglFile);
|
||||
fread(&layout[i].rec, 1, sizeof(Rectangle), rglFile);
|
||||
fread(layout[i].text, 1, 32, rglFile);
|
||||
/*
|
||||
// Import anchor id and position
|
||||
// fread(&layout[i].ap->id, 1, sizeof(int), rglFile);
|
||||
// fread(&layout[i].ap->x, 1, sizeof(int), rglFile);
|
||||
// fread(&layout[i].ap->y, 1, sizeof(int), rglFile);
|
||||
*/
|
||||
fread(&anchorId, 1, sizeof(int), rglFile);
|
||||
layout[i].ap = &anchors[anchorId];
|
||||
|
||||
printf("[READ] Controls info: id-%i type-%i rec-%i,%i,%i,%i text-%s\n", layout[i].id, layout[i].type, layout[i].rec.x, layout[i].rec.y, layout[i].rec.width, layout[i].rec.height, layout[i].text);
|
||||
printf("[READ] Control info> id: %i, type: %i, rec: %i,%i,%i,%i, text: %s, anchorId: %i\n", layout[i].id, layout[i].type, layout[i].rec.x, layout[i].rec.y, layout[i].rec.width, layout[i].rec.height, layout[i].text, anchorId);
|
||||
}
|
||||
}
|
||||
else TraceLog(LOG_WARNING, "[raygui] Invalid layout file");
|
||||
@ -1294,6 +1320,7 @@ static void GenerateLayoutCode(const char *fileName)
|
||||
case TEXTBOX: fprintf(ftool, "\t\t\tGuiTextBox(layoutRecs[%i], %s%03i, %sSize%03i);\n\n", i, controlTypeNameShort[layout[i].type], i, controlTypeNameShort[layout[i].type], i); break;
|
||||
case GROUPBOX: fprintf(ftool, "\t\t\tGuiGroupBox(layoutRecs[%i], \"%s\");\n\n", i, layout[i].text); break;
|
||||
case WINDOWBOX: fprintf(ftool, "\t\t\tGuiWindowBox(layoutRecs[%i], \"%s\");\n\n", i, layout[i].text); break;
|
||||
case STATUSBAR: fprintf(ftool, "\t\t\tGuiStatusBar(layoutRecs[%i], \"%s\", 10);\n\n", i, layout[i].text); break;
|
||||
case COLORPICKER: fprintf(ftool, "\t\t\t%sColor%03i = GuiColorPicker(layoutRecs[%i], %sColor%03i);\n\n", controlTypeNameShort[layout[i].type], i, i, controlTypeNameShort[layout[i].type], i); break;
|
||||
|
||||
default: break;
|
||||
|
||||
Reference in New Issue
Block a user