Reviewed raygui examples

This commit is contained in:
Ray 2018-11-08 10:41:31 +01:00
parent 6e0798fb18
commit 76d5234858
19 changed files with 83 additions and 181 deletions

View File

@ -1,79 +0,0 @@
/*******************************************************************************************
*
* Some new GUI controls testing program
*
* Controls to test:
* - GuiScrollPanel()
* - GuiTextBoxMulti()
*
* Compile this program using:
* gcc -o $(NAME_PART).exe $(NAME_PART).c -I..\..\src -lraylib -lopengl32 -lgdi32 -std=c99 -Wall
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2018 raylib technologies
*
**********************************************************************************************/
#include "raylib.h"
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
//----------------------------------------------------------------------------------
// Controls Functions Declaration
//----------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main()
{
// Initialization
//---------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 600;
InitWindow(screenWidth, screenHeight, "Controls testing suite");
// GuiTextBoxMulti() variables
int textMultiSize = 128;
char textMulti[128] = "";
// GuiScrollPanel() variables
Rectangle scrollBox = { 100, 100, 200, 300 };
Rectangle scrollContent = { 0, 0, 200, 600 };
Vector2 scrollPosition = { 0, 0 };
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Implement required update logic
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(GetColor(style[DEFAULT_BACKGROUND_COLOR]));
GuiTextBoxMulti((Rectangle){ 500, 100, 100, 200 }, textMulti, textMultiSize, true);
scrollPosition = GuiScrollPanel(scrollBox, scrollContent, scrollPosition);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

View File

@ -1,10 +1,25 @@
/*******************************************************************************************
*
* layout_file_name - tool description
* raygui - controls test suite
*
* TEST CONTROLS:
* - GuiDropdownBox()
* - GuiValueBox()
* - GuiSpinner()
* - GuiTextBox()
* - GuiTextBoxMulti()
* - GuiListView()
*
* DEPENDENCIES:
* raylib 2.1-dev - Windowing/input management and drawing.
* raygui 2.1-dev - Immediate-mode GUI controls.
*
* COMPILATION (Windows - MinGW):
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2018 raylib technologies
* Copyright (c) 2018 raylib technologies (@raylibtech)
*
**********************************************************************************************/
@ -13,10 +28,6 @@
#define RAYGUI_IMPLEMENTATION
#include "../../src/raygui.h"
//----------------------------------------------------------------------------------
// Controls Functions Declaration
//----------------------------------------------------------------------------------
static void Button005(); // Button: Button005 logic
//------------------------------------------------------------------------------------
// Program main entry point
@ -28,9 +39,9 @@ int main()
int screenWidth = 800;
int screenHeight = 600;
InitWindow(screenWidth, screenHeight, "layout_file_name");
InitWindow(screenWidth, screenHeight, "raygui - controls test suite");
// layout_file_name: controls initialization
// GUI controls initialization
//----------------------------------------------------------------------------------
int dropdownBox000Active = 0;
const char *dropdownBox000TextList[3] = { "ONE", "TWO", "THREE" };
@ -67,6 +78,7 @@ int main()
bool forceSquaredChecked = false;
//----------------------------------------------------------------------------------
// Custom GUI font loading
//Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0);
//GuiFont(font);
@ -97,7 +109,7 @@ int main()
if (GuiSpinner((Rectangle){ 25, 135, 125, 30 }, &spinner001Value, 0, 100, 25, spinnerEditMode)) spinnerEditMode = !spinnerEditMode;
if (GuiValueBox((Rectangle){ 25, 175, 125, 30 }, &valueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode;
if (GuiTextBox((Rectangle){ 25, 215, 125, 30 }, textBoxText, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode;
if (GuiButton((Rectangle){ 25, 255, 125, 30 }, "SAMPLE TEXT")) Button005();
if (GuiButton((Rectangle){ 25, 255, 125, 30 }, "SAMPLE TEXT")) { }
// NOTE: GuiDropdownBox must draw at the end of the column
if (GuiDropdownBox((Rectangle){ 25, 65, 125, 30 }, dropdownBox001TextList, 5, &dropdownBox001Active, dropDown001EditMode)) dropDown001EditMode = !dropDown001EditMode;
if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, dropdownBox000TextList, 3, &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode;
@ -115,10 +127,10 @@ int main()
// Fourth GUI column
GuiLock();
GuiState(0); if (GuiButton((Rectangle){ 600, 25, 125, 30 }, "DISABLE")) Button005();
GuiState(1); if (GuiButton((Rectangle){ 600, 65, 125, 30 }, "NORMAL")) Button005();
GuiState(2); if (GuiButton((Rectangle){ 600, 105, 125, 30 }, "FOCUSED")) Button005();
GuiState(3); if (GuiButton((Rectangle){ 600, 145, 125, 30 }, "PRESSED")) Button005();
GuiState(0); if (GuiButton((Rectangle){ 600, 25, 125, 30 }, "DISABLE")) { }
GuiState(1); if (GuiButton((Rectangle){ 600, 65, 125, 30 }, "NORMAL")) { }
GuiState(2); if (GuiButton((Rectangle){ 600, 105, 125, 30 }, "FOCUSED")) { }
GuiState(3); if (GuiButton((Rectangle){ 600, 145, 125, 30 }, "PRESSED")) { }
GuiState(1);
GuiUnlock();
//----------------------------------------------------------------------------------
@ -126,7 +138,7 @@ int main()
EndDrawing();
//----------------------------------------------------------------------------------
}
//free(enableElements);
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
@ -134,12 +146,3 @@ int main()
return 0;
}
//------------------------------------------------------------------------------------
// Controls Functions Definitions (local)
//------------------------------------------------------------------------------------
// Button: Button005 logic
static void Button005()
{
// TODO: Implement control logic
}

View File

@ -1,9 +1,13 @@
/*******************************************************************************************
*
* raygui - image exporter example
* raygui - image exporter
*
* This example has been created using raylib v2.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* DEPENDENCIES:
* raylib 2.1-dev - Windowing/input management and drawing.
* raygui 2.1-dev - Immediate-mode GUI controls.
*
* COMPILATION (Windows - MinGW):
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
*
* Copyright (c) 2018 raylib technologies (@raylibtech)
*
@ -14,13 +18,6 @@
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
//#include "untitled.h"
// Static functions
static void ImageToCode(Image image, char *fileName); // Exports image to code (.h)
const char *pixelFormatTextList[7] = { "GRAYSCALE", "GRAY ALPHA", "R5G6B5", "R8G8B8", "R5G5B5A1", "R4G4B4A4", "R8G8B8A8" };
int pixelFormatActive = 0;
//------------------------------------------------------------------------------------
// Program main entry point
@ -32,18 +29,22 @@ int main(int argc, char *argv[0])
const int screenWidth = 800;
const int screenHeight = 450;
//SetConfigFlags();
InitWindow(screenWidth, screenHeight, "image exporter");
InitWindow(screenWidth, screenHeight, "raygui - image exporter");
// Image export window variables
// GUI controls initialization
//----------------------------------------------------------------------------------
Rectangle windowBoxRec = { screenWidth/2 - 110, screenHeight/2 - 100, 220, 190 };
bool windowBoxActive = false;
int fileFormatActive = 0;
const char *fileFormatTextList[3] = { "IMAGE (.png)", "DATA (.raw)", "CODE (.h)" };
char fileName[32] = "untitled";
//Image image = { untitled_data, untitled_width, untitled_height, 1, untitled_format };
//Texture2D texture = LoadTextureFromImage(image);
int pixelFormatActive = 0;
const char *pixelFormatTextList[7] = { "GRAYSCALE", "GRAY ALPHA", "R5G6B5", "R8G8B8", "R5G5B5A1", "R4G4B4A4", "R8G8B8A8" };
char fileName[32] = "untitled";
//--------------------------------------------------------------------------------------
Image image = { 0 };
Texture2D texture = { 0 };
@ -66,7 +67,6 @@ int main(int argc, char *argv[0])
int fileCount = 0;
char **droppedFiles = GetDroppedFiles(&fileCount);
// Check file extensions for drag-and-drop
if (fileCount == 1)
{
Image imTemp = LoadImage(droppedFiles[0]);
@ -99,7 +99,7 @@ int main(int argc, char *argv[0])
if (fileFormatActive == 0) // PNG
{
if ((GetExtension(fileName) == NULL) || (!IsFileExtension(fileName, ".png"))) strcat(fileName, ".png\0"); // No extension provided
ExportImage(fileName, image);
ExportImage(image, fileName);
}
else if (fileFormatActive == 1) // RAW
{
@ -113,7 +113,7 @@ int main(int argc, char *argv[0])
}
else if (fileFormatActive == 2) // CODE
{
ImageToCode(image, fileName);
ExportImageAsCode(image, fileName);
}
}
@ -126,7 +126,9 @@ int main(int argc, char *argv[0])
if (imageScale <= 0.1f) imageScale = 0.1f;
else if (imageScale >= 5) imageScale = 5;
imageRec = (Rectangle){ screenWidth/2 - (float)image.width*imageScale/2, screenHeight/2 - (float)image.height*imageScale/2, (float)image.width*imageScale, (float)image.height*imageScale };
imageRec = (Rectangle){ screenWidth/2 - (float)image.width*imageScale/2,
screenHeight/2 - (float)image.height*imageScale/2,
(float)image.width*imageScale, (float)image.height*imageScale };
}
//----------------------------------------------------------------------------------
@ -187,27 +189,3 @@ int main(int argc, char *argv[0])
return 0;
}
static void ImageToCode(Image image, char *fileName)
{
char outName[32] = "\0";
strcpy(outName, fileName);
if ((GetExtension(fileName) == NULL) || (!IsFileExtension(fileName, ".h"))) strcat(fileName, ".h\0"); // No extension provided
int dataSize = GetPixelDataSize(image.width, image.height, image.format);
FILE *txtFile = fopen(fileName, "wt");
// TODO: Add image information
fprintf(txtFile, "//\n// Image exported using raygui image_exporter example\n//\n// Copyright (c) 2018 raylib technologies (@raylibtech)\n//\n\n");
fprintf(txtFile, "#define %s_width %i\n", outName, image.width);
fprintf(txtFile, "#define %s_height %i\n", outName, image.height);
fprintf(txtFile, "#define %s_format %i // raylib internal pixel format: %s\n\n", outName, pixelFormatActive + 1, pixelFormatTextList[pixelFormatActive]);
fprintf(txtFile, "static unsigned char %s_data[%i] = { ", outName, dataSize);
for (int i = 0; i < dataSize - 1; i++) fprintf(txtFile, "0x%x, ", ((unsigned char *)image.data)[i]);
fprintf(txtFile, "0x%x };\n", ((unsigned char *)image.data)[dataSize - 1]);
fclose(txtFile);
}

View File

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@ -1,9 +1,15 @@
/*******************************************************************************************
*
* raygui - image raw importer example
* raygui - image raw importer
*
* This example has been created using raylib v2.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* DEPENDENCIES:
* raylib 2.1-dev - Windowing/input management and drawing.
* raygui 2.1-dev - Immediate-mode GUI controls.
*
* COMPILATION (Windows - MinGW):
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2018 raylib technologies (@raylibtech)
*
@ -17,10 +23,6 @@
#include <string.h> // Required for: strcpy()
#include <stdlib.h> // Required for: atoi()
//----------------------------------------------------------------------------------
// Controls Functions Declaration
//----------------------------------------------------------------------------------
static void ImportRAW(); // Button: ImportRAW logic
//------------------------------------------------------------------------------------
// Program main entry point
@ -32,17 +34,21 @@ int main()
const int screenWidth = 800;
const int screenHeight = 600;
InitWindow(screenWidth, screenHeight, "Image RAW Importer");
InitWindow(screenWidth, screenHeight, "raygui - image raw importer");
Texture2D texture = { 0 };
// raw_importer: controls initialization
// GUI controls initialization
//----------------------------------------------------------------------------------
Vector2 windowOffset = { screenWidth/2 - 200/2, screenHeight/2 - 465/2 };
bool importWindowActive = false;
int widthValue = 0;
bool widthEditMode = false;
int heightValue = 0;
bool heightEditMode = false;
int pixelFormatActive = 0;
const char *pixelFormatTextList[8] = { "CUSTOM", "GRAYSCALE", "GRAY ALPHA", "R5G6B5", "R8G8B8", "R5G5B5A1", "R4G4B4A4", "R8G8B8A8" };
@ -50,7 +56,9 @@ int main()
const char *channelsTextList[4] = { "1", "2", "3", "4" };
int bitDepthActive = 0;
const char *bitDepthTextList[3] = { "8", "16", "32" };
int headerSizeValue = 0;
bool headerSizeEditMode = false;
//----------------------------------------------------------------------------------
// Image file info
@ -181,10 +189,10 @@ int main()
GuiLabel((Rectangle){ windowOffset.x + 85, windowOffset.y + 50, 75, 20 }, FormatText("%i bytes", dataSize));
GuiGroupBox((Rectangle){ windowOffset.x + 10, windowOffset.y + 85, 180, 80 }, "Resolution");
GuiLabel((Rectangle){ windowOffset.x + 20, windowOffset.y + 100, 33, 25 }, "Width:");
widthValue = GuiValueBox((Rectangle){ windowOffset.x + 60, windowOffset.y + 100, 80, 25 }, widthValue, 100);
if (GuiValueBox((Rectangle){ windowOffset.x + 60, windowOffset.y + 100, 80, 25 }, &widthValue, 0, 8192, widthEditMode)) widthEditMode = !widthEditMode;
GuiLabel((Rectangle){ windowOffset.x + 145, windowOffset.y + 100, 30, 25 }, "pixels");
GuiLabel((Rectangle){ windowOffset.x + 20, windowOffset.y + 130, 33, 25 }, "Height:");
heightValue = GuiValueBox((Rectangle){ windowOffset.x + 60, windowOffset.y + 130, 80, 25 }, heightValue, 100);
if (GuiValueBox((Rectangle){ windowOffset.x + 60, windowOffset.y + 130, 80, 25 }, &heightValue, 0, 8192, heightEditMode)) heightEditMode = !heightEditMode;
GuiLabel((Rectangle){ windowOffset.x + 145, windowOffset.y + 130, 30, 25 }, "pixels");
GuiGroupBox((Rectangle){ windowOffset.x + 10, windowOffset.y + 180, 180, 160 }, "Pixel Format");
pixelFormatActive = GuiComboBox((Rectangle){ windowOffset.x + 20, windowOffset.y + 195, 160, 25 }, pixelFormatTextList, 8, pixelFormatActive);
@ -199,7 +207,7 @@ int main()
GuiGroupBox((Rectangle){ windowOffset.x + 10, windowOffset.y + 355, 180, 50 }, "Header");
GuiLabel((Rectangle){ windowOffset.x + 25, windowOffset.y + 370, 27, 25 }, "Size:");
headerSizeValue = GuiValueBox((Rectangle){ windowOffset.x + 55, windowOffset.y + 370, 85, 25 }, headerSizeValue, 100);
if (GuiValueBox((Rectangle){ windowOffset.x + 55, windowOffset.y + 370, 85, 25 }, &headerSizeValue, 0, 10000, headerSizeEditMode)) headerSizeEditMode = !headerSizeEditMode;
GuiLabel((Rectangle){ windowOffset.x + 145, windowOffset.y + 370, 30, 25 }, "bytes");
btnLoadPressed = GuiButton((Rectangle){ windowOffset.x + 10, windowOffset.y + 420, 180, 30 }, "Import RAW");
@ -213,6 +221,7 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
if (texture.id != 0) UnloadTexture(texture);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------

View File

@ -1,10 +1,17 @@
/*******************************************************************************************
*
* window - tool description
* raygui - standalone window
*
* DEPENDENCIES:
* raylib 2.1-dev - Windowing/input management and drawing.
* raygui 2.1-dev - Immediate-mode GUI controls.
*
* COMPILATION (Windows - MinGW):
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2018 raylib technologies
* Copyright (c) 2018 raylib technologies (@raylibtech)
*
**********************************************************************************************/
@ -13,9 +20,6 @@
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
//----------------------------------------------------------------------------------
// Controls Functions Declaration
//----------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// Program main entry point
@ -28,10 +32,9 @@ int main()
int screenHeight = 600;
SetConfigFlags(FLAG_WINDOW_UNDECORATED);
InitWindow(screenWidth, screenHeight, "raygui - standalone window");
InitWindow(screenWidth, screenHeight, "window");
// window: controls initialization
// GUI controls initialization
//----------------------------------------------------------------------------------
bool exitWindow = false;
//----------------------------------------------------------------------------------
@ -51,8 +54,6 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
// TODO: Implement required update logic
//----------------------------------------------------------------------------------
mousePos = GetMousePosition();
if ((CheckCollisionPointRec(mousePos, (Rectangle){ 0, 0, screenWidth, 20 })) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
@ -68,8 +69,7 @@ int main()
position.x = prevPosition.x + (mousePos.x - panOffset.x),
position.y = prevPosition.y + (mousePos.y - panOffset.y);
}
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
{
prevPosition = position;
dragWindow = false;
@ -77,10 +77,7 @@ int main()
}
SetWindowPosition(position.x, position.y);
// printf("mouse: %f, %f\n", mousePos.x, mousePos.y);
// printf("panOffset: %f, %f\n", panOffset.x, panOffset.y);
// printf("prevPosition: %f, %f\n", prevPosition.x, prevPosition.y);
// printf("position: %f, %f\n\n", position.x, position.y);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
@ -90,9 +87,7 @@ int main()
// raygui: controls drawing
//----------------------------------------------------------------------------------
exitWindow = GuiWindowBox((Rectangle){ 1, 0, screenWidth - 2, screenHeight - 1 }, "EXAMPLE WINDOW");
exitWindow = GuiWindowBox((Rectangle){ 1, 0, screenWidth - 2, screenHeight - 1 }, "STANDALONE WINDOW");
//----------------------------------------------------------------------------------
EndDrawing();
@ -106,7 +101,3 @@ int main()
return 0;
}
//------------------------------------------------------------------------------------
// Controls Functions Definitions (local)
//------------------------------------------------------------------------------------