Review some code

This commit is contained in:
Ray
2018-02-20 23:05:06 +01:00
parent 285b8dc4a5
commit d01a8b49b4

View File

@ -85,19 +85,24 @@ int main()
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
SetConfigFlags(FLAG_WINDOW_RESIZABLE); SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(screenWidth, screenHeight, "raylib tool - raygui layout editor"); InitWindow(screenWidth, screenHeight, "rGuiLayout - raygui layout editor");
int selectedControl = -1; int selectedControl = -1;
const char *list[3] = { "ONE", "TWO", "THREE" };
bool snapMode = false;
int selectedType = BUTTON; int selectedType = BUTTON;
int mouseX, mouseY;
int selectedTypeDraw = LABEL; int selectedTypeDraw = LABEL;
bool controlCollision = false;
Rectangle recDraw = { 0, 0, 100, 30 }; int mouseX, mouseY;
bool snapMode = false;
bool showGrid = true;
bool controlCollision = false; // TODO: What's that?
bool controlDrag = false; // TODO: What's that?
bool textEditMode = false;
int saveControlSelected = -1;
Rectangle recDraw = { 0, 0, 100, 30 }; // TODO: What's that?
// List view required variables
Rectangle listViewControls = { -200, 0, 140, 500 }; Rectangle listViewControls = { -200, 0, 140, 500 };
int counterListViewControls = 0; int counterListViewControls = 0;
int startPosXListViewControls = -200; int startPosXListViewControls = -200;
@ -106,10 +111,8 @@ int main()
int counterListViewControlsCounter = 0; int counterListViewControlsCounter = 0;
int startPosXListViewControlsCounter = GetScreenWidth() + 140; int startPosXListViewControlsCounter = GetScreenWidth() + 140;
int deltaPosXListViewControlsCounter = 0; int deltaPosXListViewControlsCounter = 0;
bool controlDrag = false;
bool textEditMode = false; const char *list[3] = { "ONE", "TWO", "THREE" };
int saveControlSelected = -1;
const char *guiControls[14] = { const char *guiControls[14] = {
"LABEL", "LABEL",
@ -128,7 +131,7 @@ int main()
"COLORPICKER" "COLORPICKER"
}; };
const char *guiControlsCounter[64] = { const char *guiControlsCounter[12] = {
"00", "00",
"01", "01",
"02", "02",
@ -140,64 +143,13 @@ int main()
"08", "08",
"09", "09",
"10", "10",
"11", "11"
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
"33",
"34",
"35",
"36",
"37",
"38",
"39",
"40",
"41",
"42",
"43",
"44",
"45",
"46",
"47",
"48",
"49",
"50",
"51",
"52",
"53",
"54",
"55",
"56",
"57",
"58",
"59",
"60",
"61",
"62",
"63"
}; };
GuiLoadStyleImage("default_light.png"); GuiLoadStyleImage("default_light.png");
Texture2D texture = LoadTexture("default_light.png"); Texture2D texture = LoadTexture("default_light.png");
SetTargetFPS(120); SetTargetFPS(120);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -208,9 +160,11 @@ int main()
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
mouseX = GetMouseX(); mouseX = GetMouseX();
mouseY = GetMouseY(); mouseY = GetMouseY();
// Updates the recDraw position // Updates the recDraw position
recDraw.x = mouseX - recDraw.width/2; recDraw.x = mouseX - recDraw.width/2;
recDraw.y = mouseY - recDraw.height/2; recDraw.y = mouseY - recDraw.height/2;
// Checks if the recDraw is colliding with the list of the controls // Checks if the recDraw is colliding with the list of the controls
if (CheckCollisionPointRec(GetMousePosition(), listViewControls))controlCollision = true; if (CheckCollisionPointRec(GetMousePosition(), listViewControls))controlCollision = true;
@ -221,6 +175,7 @@ int main()
deltaPosXListViewControls = 0 - startPosXListViewControls; deltaPosXListViewControls = 0 - startPosXListViewControls;
counterListViewControls = 0; counterListViewControls = 0;
} }
if (IsKeyDown(KEY_TAB)) if (IsKeyDown(KEY_TAB))
{ {
counterListViewControls++; counterListViewControls++;
@ -247,6 +202,7 @@ int main()
deltaPosXListViewControlsCounter = GetScreenWidth() -listViewControlsCounter.width - startPosXListViewControlsCounter; deltaPosXListViewControlsCounter = GetScreenWidth() -listViewControlsCounter.width - startPosXListViewControlsCounter;
counterListViewControlsCounter = 0; counterListViewControlsCounter = 0;
} }
if (IsKeyDown(KEY_LEFT_SHIFT)) if (IsKeyDown(KEY_LEFT_SHIFT))
{ {
counterListViewControlsCounter++; counterListViewControlsCounter++;
@ -289,20 +245,20 @@ int main()
if (selectedControl != -1 && !textEditMode) if (selectedControl != -1 && !textEditMode)
{ {
//Disables the recDraw // Disables the recDraw
controlCollision = true; controlCollision = true;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{ {
controlDrag = true; controlDrag = true;
} }
else if(IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
{ {
controlDrag = false; controlDrag = false;
selectedControl = -1; selectedControl = -1;
} }
if(controlDrag) if (controlDrag)
{ {
layout[selectedControl].rec.x = mouseX - layout[selectedControl].rec.width/2; layout[selectedControl].rec.x = mouseX - layout[selectedControl].rec.width/2;
layout[selectedControl].rec.y = mouseY - layout[selectedControl].rec.height/2; layout[selectedControl].rec.y = mouseY - layout[selectedControl].rec.height/2;
@ -432,7 +388,7 @@ int main()
// TODO: Check if control has text to editor // TODO: Check if control has text to editor
// TODO: Lock selectedControl for text editing // TODO: Lock selectedControl for text editing
//Turns on textEditMode // Turns on textEditMode
if (IsKeyPressed(KEY_T) && selectedControl != -1 && ((selectedType == LABEL) || (selectedType == BUTTON) || (selectedType == TOGGLE))) if (IsKeyPressed(KEY_T) && selectedControl != -1 && ((selectedType == LABEL) || (selectedType == BUTTON) || (selectedType == TOGGLE)))
{ {
textEditMode = true; textEditMode = true;
@ -483,6 +439,8 @@ int main()
// TODO: Draw global app screen limits (black rectangle with black default anchor) // TODO: Draw global app screen limits (black rectangle with black default anchor)
if (IsKeyPressed(KEY_G)) showGrid = !showGrid;
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_S)) SaveGuiLayout("test_layout.rlyt"); if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_S)) SaveGuiLayout("test_layout.rlyt");
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_O)) LoadGuiLayout("test_layout.rlyt"); if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_O)) LoadGuiLayout("test_layout.rlyt");
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_ENTER)) GenerateGuiLayoutCode("test_layout.c"); if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_ENTER)) GenerateGuiLayoutCode("test_layout.c");
@ -494,7 +452,8 @@ int main()
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawGrid2D(77, 40); // TODO: Review grid lines to draw depending on screen size
if (showGrid) DrawGrid2D(77, 40);
if (selectedControl == -1) if (selectedControl == -1)
{ {
@ -503,7 +462,6 @@ int main()
} }
// Draws the recDraw of the control selected // Draws the recDraw of the control selected
if(!controlCollision)
switch (selectedTypeDraw) switch (selectedTypeDraw)
{ {
case LABEL: GuiLabel(recDraw, "TEXT SAMPLE"); break; case LABEL: GuiLabel(recDraw, "TEXT SAMPLE"); break;
@ -598,9 +556,7 @@ int main()
static void DrawGrid2D(int divsX, int divsY) static void DrawGrid2D(int divsX, int divsY)
{ {
int spacing = 0; int spacing = 0;
/*divsX = GetScreenHeight()/13;
divsY = GetScreenWidth()/13;
*/
// Draw vertical grid lines // Draw vertical grid lines
for (int i = 0; i < divsX; i++) for (int i = 0; i < divsX; i++)
{ {