Review and clean code

This commit is contained in:
Ray San
2018-04-06 12:24:10 +02:00
parent d463be524c
commit 09f72d741f

View File

@ -1,24 +1,19 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raygui - raw image file importer * raygui - image exporter window box test
* *
* This example has been created using raylib v1.7 (www.raylib.com) * This example has been created using raylib v1.9 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* *
* Copyright (c) 2017 Ramon Santamaria (@raysan5) * Copyright (c) 2018 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
#include "raylib.h" #include "raylib.h"
#define RAYGUI_IMPLEMENTATION #define RAYGUI_IMPLEMENTATION
#define RAYGUI_STYLE_SAVE_LOAD
#include "raygui.h" #include "raygui.h"
#include <string.h> // Required for: strcpy()
#include <stdlib.h> // Required for: atoi()
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Program main entry point // Program main entry point
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
@ -29,35 +24,33 @@ int main(int argc, char *argv[0])
const int SCREEN_WIDTH = 800; const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 450; const int SCREEN_HEIGHT = 450;
int guiHeight = 30; // Window box
int guiWidth = 150; Rectangle windowBoxRec = { SCREEN_WIDTH/2 - 130, SCREEN_HEIGHT/2 - 110, 260, 230 };
bool windowBoxActive = false;
Rectangle panel = { SCREEN_WIDTH/2 - 130, SCREEN_HEIGHT/2 - 110, 260, 230 }; // File format combo box
int formatCount = 3;
int formatSelected = 0;
const char *formatText[3] = { "PNG", "RAW", "CODE"};
int guiPosX = panel.x + 10; // Pixel format combo box
int guiPosY = panel.y + 20; int pixelFormatCount = 6;
int pixelActiveSelected = 0;
const char *pixelFormatText[6] = { "R8G8B8A8", "R8", "R5G5B5A1" ,"R5G6B5", "R8A8", "R4G4B4A4" };
// Toggle buttons
int formatNum = 3;
int formatActive = 0;
int pixelNum = 8;
int pixelActive = 0;
//int channelsNum = 4;
//int channelsActive = 0;
int dropdownTest = 0;
bool toggleRed = true; bool toggleRed = true;
bool toggleGreen = true; bool toggleGreen = true;
bool toggleBlue = true; bool toggleBlue = true;
bool toggleAlpha = true; bool toggleAlpha = true;
const char *formatText[3] = { "PNG", "RAW", "CODE (.c/.h)"};
const char *formatPixel[8] = { "R8G8B8A8", "R8", "R5G5B5A1" ,"R5G6B5", "R8A8", "R16G16B16", "R4G4B4A4", "R2D2C3P0" }; // Text box
char fileNameText[32] = "Untitled"; char fileNameText[32] = "Untitled";
//const char *formatChannels[4] = { "R", "G", "B" ,"A" };
//int dropdownSelected = 0;
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "image exporter"); InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "image exporter");
Texture2D texture = { 0 };
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -66,6 +59,8 @@ int main(int argc, char *argv[0])
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// ...
//----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -73,33 +68,43 @@ int main(int argc, char *argv[0])
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
GuiDisable(); // Draw message box (testing)
GuiWindowBox(panel, "Image export options"); //GuiMessageBox((Rectangle){600, 100, 150, 100}, "Image export options", "Hello World!\nHello World!");
GuiEnable();
//Draw file format options
GuiLabel((Rectangle){ guiPosX, guiPosY + 20, 0, 0 }, FormatText("File format"));
formatActive = GuiComboBox((Rectangle){ guiPosX + 90, guiPosY + 10, guiWidth, guiHeight },formatText,formatNum,formatActive);
//Draw pixel format options if (GuiButton((Rectangle){ 20, 20, 150, 30 }, "Show Export Window")) windowBoxActive = true;
GuiLabel((Rectangle){ guiPosX, guiPosY + 60, 0, 0 }, FormatText("Pixel format"));
pixelActive = GuiComboBox((Rectangle){ guiPosX + 90, guiPosY + 50, guiWidth, guiHeight },formatPixel,pixelNum,pixelActive);
//Draw active channels options // Draw window box
GuiLabel((Rectangle){ guiPosX, guiPosY + 100, 0, 0 }, FormatText("Active channels")); //-----------------------------------------------------------------------------
toggleRed = GuiToggleButton((Rectangle){ guiPosX + 100, guiPosY + 90, guiWidth/5, guiHeight}, "R", toggleRed); if (windowBoxActive)
toggleGreen = GuiToggleButton((Rectangle){ guiPosX + 132, guiPosY + 90, guiWidth/5, guiHeight}, "G", toggleGreen); {
toggleBlue = GuiToggleButton((Rectangle){ guiPosX + 164, guiPosY + 90, guiWidth/5, guiHeight}, "B", toggleBlue); windowBoxActive = !GuiWindowBox(windowBoxRec, "Image export options");
toggleAlpha = GuiToggleButton((Rectangle){ guiPosX + 196, guiPosY + 90, guiWidth/5, guiHeight}, "A", toggleAlpha);
//channelsActive = GuiToggleGroup((Rectangle){ guiPosX + 100, guiPosY + 90, guiWidth/5, guiHeight },formatChannels,channelsNum,channelsActive);
//Draw file name options // Draw file format options
GuiLabel((Rectangle){ guiPosX, guiPosY + 140, 0, 0 }, FormatText("File name")); GuiLabel((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 20 + 20, 0, 0 }, FormatText("File format"));
GuiTextBox((Rectangle){ guiPosX + 90, guiPosY + 130, guiWidth, guiHeight }, fileNameText, 32); formatSelected = GuiComboBox((Rectangle){ windowBoxRec.x + 10 + 90, windowBoxRec.y + 20 + 10, 150, 30 }, formatText, formatCount, formatSelected);
//Draw export image button // Draw pixel format options
if(GuiButton((Rectangle){ guiPosX, guiPosY + 170, guiWidth + 90, guiHeight }, "Export Image")){} // Call function GuiLabel((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 20 + 60, 0, 0 }, FormatText("Pixel format"));
pixelActiveSelected = GuiComboBox((Rectangle){ windowBoxRec.x + 10 + 90, windowBoxRec.y + 20 + 50, 150, 30 }, pixelFormatText, pixelFormatCount, pixelActiveSelected);
dropdownTest = GuiDropdownBox((Rectangle){ 10, 10, 200, 20 }, formatText, formatNum, dropdownTest); // Draw active channels options
GuiLabel((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 20 + 100, 0, 0 }, FormatText("Active channels"));
toggleRed = GuiToggleButton((Rectangle){ windowBoxRec.x + 10 + 90, windowBoxRec.y + 20 + 90, 36, 30}, "R", toggleRed);
toggleGreen = GuiToggleButton((Rectangle){ windowBoxRec.x + 10 + 128, windowBoxRec.y + 20 + 90, 36, 30}, "G", toggleGreen);
toggleBlue = GuiToggleButton((Rectangle){ windowBoxRec.x + 10 + 166, windowBoxRec.y + 20 + 90, 36, 30}, "B", toggleBlue);
toggleAlpha = GuiToggleButton((Rectangle){ windowBoxRec.x + 10 + 204, windowBoxRec.y + 20 + 90, 36, 30}, "A", toggleAlpha);
//Draw file name options
GuiLabel((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 20 + 140, 0, 0 }, FormatText("File name"));
GuiTextBox((Rectangle){ windowBoxRec.x + 10 + 90, windowBoxRec.y + 20 + 130, 150, 30 }, fileNameText, 32);
// Draw export image button
if (GuiButton((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 20 + 170, 150 + 90, 30 }, "Export Image")) { /* Call function */ }
}
//-----------------------------------------------------------------------------
// Draw dropdown box (testing)
//dropdownSelected = GuiDropdownBox((Rectangle){ 10, 10, 150, 30 }, formatText, formatCount, dropdownSelected);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -107,8 +112,6 @@ int main(int argc, char *argv[0])
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
if (texture.id != 0) UnloadTexture(texture);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------