update the raygui examples due to the upgrade of raygui and raylib version (#435)

This commit is contained in:
Yi Jianlong 2024-05-24 08:10:17 +00:00 committed by GitHub
parent 904fe591cb
commit 1092ff970c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 381 additions and 300 deletions

View File

@ -5,7 +5,7 @@
#define RAYGUI_IMPLEMENTATION #define RAYGUI_IMPLEMENTATION
#include <raygui.h> #include <raygui.h>
void updateRadius(int baseL, int outerL, int pointL, int *pBaseR, int *pOuterR, int *pPointR) { void updateRadius(float baseL, float outerL,float pointL, float *pBaseR, float *pOuterR, float *pPointR) {
int totalL=baseL+outerL; int totalL=baseL+outerL;
if (pointL>outerL) if (pointL>outerL)
totalL+=pointL; totalL+=pointL;
@ -27,12 +27,12 @@ void updateRadius(int baseL, int outerL, int pointL, int *pBaseR, int *pOuterR,
int main() { int main() {
int baseL=2; float baseL=2;
int outerL=13; float outerL=13;
int pointL=3; float pointL=3;
int baseR,outerR,pointR; float baseR,outerR,pointR;
int cx=350,cy=350; int cx=350,cy=350;
int speed = 1; float speed = 1;
Color trackColor = BLUE; Color trackColor = BLUE;
updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR); updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR);
InitWindow(1000,700,"Epitrochoid"); InitWindow(1000,700,"Epitrochoid");
@ -53,12 +53,13 @@ int main() {
int frameCount = 0; int frameCount = 0;
while(!WindowShouldClose()) { while(!WindowShouldClose()) {
//GUI //GUI
int newOuterL = GuiSliderBar((Rectangle){ 70, 20, 200, 30 },"Outer",TextFormat("%i", (int)outerL), outerL, 1, 50); float newOuterL = outerL, newBaseL = baseL, newPointL = pointL;
int newBaseL = GuiSliderBar((Rectangle){ 70, 60, 200, 30 },"Base",TextFormat("%i", (int)baseL), baseL, 1, 50); GuiSliderBar((Rectangle){ 70, 20, 200, 30 },"Outer",TextFormat("%i", (int)outerL), &newOuterL, 1, 50);
int newPointL = GuiSliderBar((Rectangle){ 70, 100, 200, 30 },"Point",TextFormat("%i", (int)pointL), pointL, 1, 50); GuiSliderBar((Rectangle){ 70, 60, 200, 30 },"Base",TextFormat("%i", (int)baseL), &newBaseL, 1, 50);
speed = GuiSliderBar((Rectangle){ 70, 150, 200, 30 },"Speed",TextFormat("%i", (int)speed), speed, 1, 50); GuiSliderBar((Rectangle){ 70, 100, 200, 30 },"Point",TextFormat("%i", (int)pointL), &newPointL, 1, 50);
GuiSliderBar((Rectangle){ 70, 150, 200, 30 },"Speed",TextFormat("%i", (int)speed), &speed, 1, 50);
GuiLabel((Rectangle){ 20, 220, 80, 30 },TextFormat("Color: 0x%02X%02X%02X ",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b))); GuiLabel((Rectangle){ 20, 220, 80, 30 },TextFormat("Color: 0x%02X%02X%02X ",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b)));
trackColor= GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, trackColor); GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, &trackColor);
int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"Clear"); int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"Clear");
if (newOuterL!=outerL || newBaseL!=baseL || newPointL!=pointL) { if (newOuterL!=outerL || newBaseL!=baseL || newPointL!=pointL) {
if (newOuterL!=outerL) if (newOuterL!=outerL)

View File

@ -15,7 +15,7 @@
* @param pOuterR * @param pOuterR
* @param pPointR * @param pPointR
*/ */
void updateRadius(int baseL, int outerL, int pointL, int *pBaseR, int *pOuterR, int *pPointR) { void updateRadius(float baseL, float outerL,float pointL, float *pBaseR, float *pOuterR, float *pPointR) {
int totalL=baseL+outerL; int totalL=baseL+outerL;
if (pointL>outerL) if (pointL>outerL)
totalL+=pointL; totalL+=pointL;
@ -37,12 +37,12 @@ void updateRadius(int baseL, int outerL, int pointL, int *pBaseR, int *pOuterR,
int main() { int main() {
int baseL=2; //默认基圆相对半径 float baseL=2; //默认基圆相对半径
int outerL=13; //默认外旋轮相对半径 float outerL=13; //默认外旋轮相对半径
int pointL=3; //默认笔尖在滚动圆中相对位置 float pointL=3; //默认笔尖在滚动圆中相对位置
int baseR,outerR,pointR; float baseR,outerR,pointR;
int cx=350,cy=350; int cx=350,cy=350;
int speed = 1; float speed = 1;
Color trackColor = BLUE; Color trackColor = BLUE;
updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR); updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR);
@ -58,7 +58,8 @@ int main() {
int codepointsCount; int codepointsCount;
int *codepoints=LoadCodepoints(guichars,&codepointsCount); int *codepoints=LoadCodepoints(guichars,&codepointsCount);
// 读取仅含码点表中各字符的字体 // 读取仅含码点表中各字符的字体
Font font = LoadFontEx("c:\\windows\\fonts\\simhei.ttf",20,codepoints,codepointsCount); // 注意:确保字体文件存在
Font font = LoadFontEx("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",20,codepoints,codepointsCount);
// 释放码点表 // 释放码点表
UnloadCodepoints(codepoints); UnloadCodepoints(codepoints);
@ -84,12 +85,13 @@ int main() {
//主绘图循环 //主绘图循环
while(!WindowShouldClose()) { //窗口未被关闭 while(!WindowShouldClose()) { //窗口未被关闭
//使用raygui绘制控制面板 //使用raygui绘制控制面板
int newOuterL = GuiSliderBar((Rectangle){ 90, 20, 180, 30 },"外旋轮半径",TextFormat("%i", (int)outerL), outerL, 1, 50); float newOuterL = outerL, newBaseL = baseL, newPointL = pointL;
int newBaseL = GuiSliderBar((Rectangle){ 90, 60, 180, 30 },"基圆半径",TextFormat("%i", (int)baseL), baseL, 1, 50); GuiSliderBar((Rectangle){ 90, 20, 180, 30 },"外旋轮半径",TextFormat("%i", (int)outerL), &newOuterL, 1, 50);
int newPointL = GuiSliderBar((Rectangle){ 90, 100, 180, 30 },"笔尖半径",TextFormat("%i", (int)pointL), pointL, 1, 50); GuiSliderBar((Rectangle){ 90, 60, 180, 30 },"基圆半径",TextFormat("%i", (int)baseL), &newBaseL, 1, 50);
speed = GuiSliderBar((Rectangle){ 90, 150, 180, 30 },"速度",TextFormat("%i", (int)speed), speed, 1, 50); GuiSliderBar((Rectangle){ 90, 100, 180, 30 },"笔尖半径",TextFormat("%i", (int)pointL), &newPointL, 1, 50);
GuiSliderBar((Rectangle){ 90, 150, 180, 30 },"速度",TextFormat("%i", (int)speed), &speed, 1, 50);
GuiLabel((Rectangle){ 20, 220, 180, 30 },TextFormat("颜色: 0x%02X%02X%02X",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b))); GuiLabel((Rectangle){ 20, 220, 180, 30 },TextFormat("颜色: 0x%02X%02X%02X",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b)));
trackColor= GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, trackColor); GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, &trackColor);
int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"清除"); int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"清除");
if (newOuterL!=outerL || newBaseL!=baseL || newPointL!=pointL) { if (newOuterL!=outerL || newBaseL!=baseL || newPointL!=pointL) {
//圆参数有变化,清除轨迹图层 //圆参数有变化,清除轨迹图层

View File

@ -5,7 +5,7 @@
#define RAYGUI_IMPLEMENTATION #define RAYGUI_IMPLEMENTATION
#include <raygui.h> #include <raygui.h>
void updateRadius(int baseL, int innerL,int pointL, int *pBaseR, int *pInnerR, int *pPointR) { void updateRadius(float baseL, float innerL,float pointL, float *pBaseR, float *pInnerR, float *pPointR) {
int totalL=baseL; int totalL=baseL;
if (innerL>baseL) { if (innerL>baseL) {
if (innerL>pointL) if (innerL>pointL)
@ -33,12 +33,12 @@ void updateRadius(int baseL, int innerL,int pointL, int *pBaseR, int *pInnerR, i
int main() { int main() {
int baseL=6; float baseL=6;
int innerL=3; float innerL=3;
int pointL=6; float pointL=6;
int baseR,innerR,pointR; float baseR,innerR,pointR;
int cx=350,cy=350; int cx=350,cy=350;
int speed = 1; float speed = 1;
Color trackColor = BLUE; Color trackColor = BLUE;
updateRadius(baseL, innerL, pointL, &baseR, &innerR, &pointR); updateRadius(baseL, innerL, pointL, &baseR, &innerR, &pointR);
InitWindow(1100,700,"Hypotrochoid"); InitWindow(1100,700,"Hypotrochoid");
@ -60,12 +60,13 @@ int main() {
int frameCount = 0; int frameCount = 0;
while(!WindowShouldClose()) { while(!WindowShouldClose()) {
//GUI //GUI
int newInnerL = GuiSliderBar((Rectangle){ 70, 20, 200, 30 },"Inner",TextFormat("%i", (int)innerL), innerL, 1, 50); float newInnerL = innerL, newBaseL = baseL, newPointL = pointL;
int newBaseL = GuiSliderBar((Rectangle){ 70, 60, 200, 30 },"Base",TextFormat("%i", (int)baseL), baseL, 1, 50); GuiSliderBar((Rectangle){ 70, 20, 200, 30 },"Inner",TextFormat("%i", (int)innerL), &newInnerL, 1, 50);
int newPointL = GuiSliderBar((Rectangle){ 70, 100, 200, 30 },"Point",TextFormat("%i", (int)pointL), pointL, 1, 50); GuiSliderBar((Rectangle){ 70, 60, 200, 30 },"Base",TextFormat("%i", (int)baseL), &newBaseL, 1, 50);
speed = GuiSliderBar((Rectangle){ 70, 150, 200, 30 },"Speed",TextFormat("%i", (int)speed), speed, 1, 50); GuiSliderBar((Rectangle){ 70, 100, 200, 30 },"Point",TextFormat("%i", (int)pointL), &newPointL, 1, 50);
GuiSliderBar((Rectangle){ 70, 150, 200, 30 },"Speed",TextFormat("%i", (int)speed), &speed, 1, 50);
GuiLabel((Rectangle){ 20, 220, 200, 30 },TextFormat("Color: 0x%02X%02X%02X ",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b))); GuiLabel((Rectangle){ 20, 220, 200, 30 },TextFormat("Color: 0x%02X%02X%02X ",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b)));
trackColor= GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, trackColor); GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, &trackColor);
int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"Clear"); int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"Clear");
if (newInnerL!=innerL || newBaseL!=baseL || newPointL!=pointL) { if (newInnerL!=innerL || newBaseL!=baseL || newPointL!=pointL) {
if (newInnerL!=innerL) if (newInnerL!=innerL)

View File

@ -5,7 +5,7 @@
#define RAYGUI_IMPLEMENTATION #define RAYGUI_IMPLEMENTATION
#include <raygui.h> #include <raygui.h>
void updateRadius(int baseL, int outerL, int pointL, int *pBaseR, int *pOuterR, int *pPointR) { void updateRadius(float baseL, float outerL,float pointL, float *pBaseR, float *pOuterR, float *pPointR) {
int totalL=baseL+outerL; int totalL=baseL+outerL;
if (pointL>outerL) if (pointL>outerL)
totalL+=pointL; totalL+=pointL;
@ -27,12 +27,12 @@ void updateRadius(int baseL, int outerL, int pointL, int *pBaseR, int *pOuterR,
int main() { int main() {
int baseL=2; float baseL=2;
int outerL=13; float outerL=13;
int pointL=3; float pointL=3;
int baseR,outerR,pointR; float baseR,outerR,pointR;
int cx=350,cy=350; int cx=350,cy=350;
int speed = 1; float speed = 1;
Color trackColor = BLUE; Color trackColor = BLUE;
updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR); updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR);
InitWindow(1000,700,"Epitrochoid"); InitWindow(1000,700,"Epitrochoid");
@ -53,12 +53,13 @@ int main() {
int frameCount = 0; int frameCount = 0;
while(!WindowShouldClose()) { while(!WindowShouldClose()) {
//GUI //GUI
int newOuterL = GuiSliderBar((Rectangle){ 70, 20, 200, 30 },"Outer",TextFormat("%i", (int)outerL), outerL, 1, 50); float newOuterL = outerL, newBaseL = baseL, newPointL = pointL;
int newBaseL = GuiSliderBar((Rectangle){ 70, 60, 200, 30 },"Base",TextFormat("%i", (int)baseL), baseL, 1, 50); GuiSliderBar((Rectangle){ 70, 20, 100, 30 },"Outer",TextFormat("%i", (int)outerL), &newOuterL, 1, 50);
int newPointL = GuiSliderBar((Rectangle){ 70, 100, 200, 30 },"Point",TextFormat("%i", (int)pointL), pointL, 1, 50); GuiSliderBar((Rectangle){ 70, 60, 100, 30 },"Base",TextFormat("%i", (int)baseL), &newBaseL, 1, 50);
speed = GuiSliderBar((Rectangle){ 70, 150, 200, 30 },"Speed",TextFormat("%i", (int)speed), speed, 1, 50); GuiSliderBar((Rectangle){ 70, 100, 100, 30 },"Point",TextFormat("%i", (int)pointL), &newPointL, 1, 50);
GuiLabel((Rectangle){ 20, 220, 80, 30 },TextFormat("Color: 0x%02X%02X%02X ",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b))); GuiSliderBar((Rectangle){ 70, 150, 100, 30 },"Speed",TextFormat("%i", (int)speed), &speed, 1, 50);
trackColor= GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, trackColor); GuiLabel((Rectangle){ 20, 220, 180, 30 },TextFormat("Color: 0x%02X%02X%02X",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b)));
GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, &trackColor);
int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"Clear"); int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"Clear");
if (newOuterL!=outerL || newBaseL!=baseL || newPointL!=pointL) { if (newOuterL!=outerL || newBaseL!=baseL || newPointL!=pointL) {
if (newOuterL!=outerL) if (newOuterL!=outerL)

View File

@ -15,7 +15,7 @@
* @param pOuterR * @param pOuterR
* @param pPointR * @param pPointR
*/ */
void updateRadius(int baseL, int outerL, int pointL, int *pBaseR, int *pOuterR, int *pPointR) { void updateRadius(float baseL, float outerL,float pointL, float *pBaseR, float *pOuterR, float *pPointR) {
int totalL=baseL+outerL; int totalL=baseL+outerL;
if (pointL>outerL) if (pointL>outerL)
totalL+=pointL; totalL+=pointL;
@ -37,12 +37,12 @@ void updateRadius(int baseL, int outerL, int pointL, int *pBaseR, int *pOuterR,
int main() { int main() {
int baseL=2; //默认基圆相对半径 float baseL=2; //默认基圆相对半径
int outerL=13; //默认外旋轮相对半径 float outerL=13; //默认外旋轮相对半径
int pointL=3; //默认笔尖在滚动圆中相对位置 float pointL=3; //默认笔尖在滚动圆中相对位置
int baseR,outerR,pointR; float baseR,outerR,pointR;
int cx=350,cy=350; int cx=350,cy=350;
int speed = 1; float speed = 1;
Color trackColor = BLUE; Color trackColor = BLUE;
updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR); updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR);
@ -84,12 +84,13 @@ int main() {
//主绘图循环 //主绘图循环
while(!WindowShouldClose()) { //窗口未被关闭 while(!WindowShouldClose()) { //窗口未被关闭
//使用raygui绘制控制面板 //使用raygui绘制控制面板
int newOuterL = GuiSliderBar((Rectangle){ 90, 20, 180, 30 },"外旋轮半径",TextFormat("%i", (int)outerL), outerL, 1, 50); float newOuterL = outerL, newBaseL = baseL, newPointL = pointL;
int newBaseL = GuiSliderBar((Rectangle){ 90, 60, 180, 30 },"基圆半径",TextFormat("%i", (int)baseL), baseL, 1, 50); GuiSliderBar((Rectangle){ 90, 20, 180, 30 },"外旋轮半径",TextFormat("%i", (int)outerL), &newOuterL, 1, 50);
int newPointL = GuiSliderBar((Rectangle){ 90, 100, 180, 30 },"笔尖半径",TextFormat("%i", (int)pointL), pointL, 1, 50); GuiSliderBar((Rectangle){ 90, 60, 180, 30 },"基圆半径",TextFormat("%i", (int)baseL), &newBaseL, 1, 50);
speed = GuiSliderBar((Rectangle){ 90, 150, 180, 30 },"速度",TextFormat("%i", (int)speed), speed, 1, 50); GuiSliderBar((Rectangle){ 90, 100, 180, 30 },"笔尖半径",TextFormat("%i", (int)pointL), &newPointL, 1, 50);
GuiSliderBar((Rectangle){ 90, 150, 180, 30 },"速度",TextFormat("%i", (int)speed), &speed, 1, 50);
GuiLabel((Rectangle){ 20, 220, 180, 30 },TextFormat("颜色: 0x%02X%02X%02X",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b))); GuiLabel((Rectangle){ 20, 220, 180, 30 },TextFormat("颜色: 0x%02X%02X%02X",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b)));
trackColor= GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, trackColor); GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, &trackColor);
int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"清除"); int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"清除");
if (newOuterL!=outerL || newBaseL!=baseL || newPointL!=pointL) { if (newOuterL!=outerL || newBaseL!=baseL || newPointL!=pointL) {
//圆参数有变化,清除轨迹图层 //圆参数有变化,清除轨迹图层

View File

@ -5,7 +5,7 @@
#define RAYGUI_IMPLEMENTATION #define RAYGUI_IMPLEMENTATION
#include <raygui.h> #include <raygui.h>
void updateRadius(int baseL, int innerL,int pointL, int *pBaseR, int *pInnerR, int *pPointR) { void updateRadius(float baseL, float innerL,float pointL, float *pBaseR, float *pInnerR, float *pPointR){
int totalL=baseL; int totalL=baseL;
if (innerL>baseL) { if (innerL>baseL) {
if (innerL>pointL) if (innerL>pointL)
@ -33,12 +33,12 @@ void updateRadius(int baseL, int innerL,int pointL, int *pBaseR, int *pInnerR, i
int main() { int main() {
int baseL=6; float baseL=6;
int innerL=3; float innerL=3;
int pointL=6; float pointL=6;
int baseR,innerR,pointR; float baseR,innerR,pointR;
int cx=350,cy=350; int cx=350,cy=350;
int speed = 1; float speed = 1;
Color trackColor = BLUE; Color trackColor = BLUE;
updateRadius(baseL, innerL, pointL, &baseR, &innerR, &pointR); updateRadius(baseL, innerL, pointL, &baseR, &innerR, &pointR);
InitWindow(1100,700,"Hypotrochoid"); InitWindow(1100,700,"Hypotrochoid");
@ -60,12 +60,13 @@ int main() {
int frameCount = 0; int frameCount = 0;
while(!WindowShouldClose()) { while(!WindowShouldClose()) {
//GUI //GUI
int newInnerL = GuiSliderBar((Rectangle){ 70, 20, 200, 30 },"Inner",TextFormat("%i", (int)innerL), innerL, 1, 50); float newInnerL = innerL, newBaseL = baseL, newPointL = pointL;
int newBaseL = GuiSliderBar((Rectangle){ 70, 60, 200, 30 },"Base",TextFormat("%i", (int)baseL), baseL, 1, 50); GuiSliderBar((Rectangle){ 70, 20, 200, 30 },"Inner",TextFormat("%i", (int)innerL), &newInnerL, 1, 50);
int newPointL = GuiSliderBar((Rectangle){ 70, 100, 200, 30 },"Point",TextFormat("%i", (int)pointL), pointL, 1, 50); GuiSliderBar((Rectangle){ 70, 60, 200, 30 },"Base",TextFormat("%i", (int)baseL), &newBaseL, 1, 50);
speed = GuiSliderBar((Rectangle){ 70, 150, 200, 30 },"Speed",TextFormat("%i", (int)speed), speed, 1, 50); GuiSliderBar((Rectangle){ 70, 100, 200, 30 },"Point",TextFormat("%i", (int)pointL), &newPointL, 1, 50);
GuiSliderBar((Rectangle){ 70, 150, 200, 30 },"Speed",TextFormat("%i", (int)speed), &speed, 1, 50);
GuiLabel((Rectangle){ 20, 220, 200, 30 },TextFormat("Color: 0x%02X%02X%02X ",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b))); GuiLabel((Rectangle){ 20, 220, 200, 30 },TextFormat("Color: 0x%02X%02X%02X ",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b)));
trackColor= GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, trackColor); GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, &trackColor);
int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"Clear"); int doClear = GuiButton((Rectangle){ 120, 500, 80, 30 },"Clear");
if (newInnerL!=innerL || newBaseL!=baseL || newPointL!=pointL) { if (newInnerL!=innerL || newBaseL!=baseL || newPointL!=pointL) {
if (newInnerL!=innerL) if (newInnerL!=innerL)

View File

@ -1,46 +1,57 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raygui - controls test suite * raygui - controls test suite
* *
* TEST CONTROLS: * TEST CONTROLS:
* - GuiDropdownBox() * - GuiDropdownBox()
* - GuiCheckBox() * - GuiCheckBox()
* - GuiSpinner() * - GuiSpinner()
* - GuiValueBox() * - GuiValueBox()
* - GuiTextBox() * - GuiTextBox()
* - GuiButton() * - GuiButton()
* - GuiComboBox() * - GuiComboBox()
* - GuiListView() * - GuiListView()
* - GuiToggleGroup() * - GuiToggleGroup()
* - GuiColorPicker() * - GuiColorPicker()
* - GuiSlider() * - GuiSlider()
* - GuiSliderBar() * - GuiSliderBar()
* - GuiProgressBar() * - GuiProgressBar()
* - GuiColorBarAlpha() * - GuiColorBarAlpha()
* - GuiScrollPanel() * - GuiScrollPanel()
* *
* *
* DEPENDENCIES: * DEPENDENCIES:
* raylib 4.5 - Windowing/input management and drawing * raylib 5.0 - Windowing/input management and drawing
* raygui 3.5 - Immediate-mode GUI controls with custom styling and icons * raygui 4.0 - Immediate-mode GUI controls with custom styling and icons
* *
* COMPILATION (Windows - MinGW): * COMPILATION (Windows - MinGW):
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99 * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
* *
* LICENSE: zlib/libpng * LICENSE: zlib/libpng
* *
* Copyright (c) 2016-2023 Ramon Santamaria (@raysan5) * Copyright (c) 2016-2024 Ramon Santamaria (@raysan5)
* *
**********************************************************************************************/ **********************************************************************************************/
#include "raylib.h" #include "raylib.h"
//#define RAYGUI_DEBUG_RECS_BOUNDS
//#define RAYGUI_DEBUG_TEXT_BOUNDS
#define RAYGUI_IMPLEMENTATION #define RAYGUI_IMPLEMENTATION
//#define RAYGUI_CUSTOM_ICONS // It requires providing gui_icons.h in the same directory //#define RAYGUI_CUSTOM_ICONS // It requires providing gui_icons.h in the same directory
//#include "gui_icons.h" // External icons data provided, it can be generated with rGuiIcons tool //#include "gui_icons.h" // External icons data provided, it can be generated with rGuiIcons tool
#include "raygui.h" #include <raygui.h>
// raygui style comment out, see https://github.com/raysan5/raygui/tree/master/examples for full examples
// raygui embedded styles
//#include "../styles/style_cyber.h" // raygui style: cyber
//#include "../styles/style_jungle.h" // raygui style: jungle
//#include "../styles/style_lavanda.h" // raygui style: lavanda
//#include "../styles/style_dark.h" // raygui style: dark
//#include "../styles/style_bluish.h" // raygui style: bluish
//#include "../styles/style_terminal.h" // raygui style: terminal
#include <string.h> // Required for: strcpy()
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Program main entry point // Program main entry point
@ -49,7 +60,7 @@ int main()
{ {
// Initialization // Initialization
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
const int screenWidth = 690; const int screenWidth = 960;
const int screenHeight = 560; const int screenHeight = 560;
InitWindow(screenWidth, screenHeight, "raygui - controls test suite"); InitWindow(screenWidth, screenHeight, "raygui - controls test suite");
@ -72,6 +83,9 @@ int main()
char textBoxText[64] = "Text box"; char textBoxText[64] = "Text box";
bool textBoxEditMode = false; bool textBoxEditMode = false;
char textBoxMultiText[1024] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n\nThisisastringlongerthanexpectedwithoutspacestotestcharbreaksforthosecases,checkingifworkingasexpected.\n\nExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
bool textBoxMultiEditMode = false;
int listViewScrollIndex = 0; int listViewScrollIndex = 0;
int listViewActive = -1; int listViewActive = -1;
@ -80,21 +94,22 @@ int main()
int listViewExFocus = -1; int listViewExFocus = -1;
const char *listViewExList[8] = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" }; const char *listViewExList[8] = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" };
char multiTextBoxText[256] = "Multi text box";
bool multiTextBoxEditMode = false;
Color colorPickerValue = RED; Color colorPickerValue = RED;
int sliderValue = 50; float sliderValue = 50.0f;
int sliderBarValue = 60; float sliderBarValue = 60;
float progressValue = 0.4f; float progressValue = 0.1f;
bool forceSquaredChecked = false; bool forceSquaredChecked = false;
float alphaValue = 0.5f; float alphaValue = 0.5f;
int comboBoxActive = 1; //int comboBoxActive = 1;
int visualStyleActive = 0;
int prevVisualStyleActive = 0;
int toggleGroupActive = 0; int toggleGroupActive = 0;
int toggleSliderActive = 0;
Vector2 viewScroll = { 0, 0 }; Vector2 viewScroll = { 0, 0 };
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -107,9 +122,14 @@ int main()
bool showMessageBox = false; bool showMessageBox = false;
char textInput[256] = { 0 }; char textInput[256] = { 0 };
char textInputFileName[256] = { 0 };
bool showTextInputBox = false; bool showTextInputBox = false;
char textInputFileName[256] = { 0 }; float alpha = 1.0f;
// DEBUG: Testing how those two properties affect all controls!
//GuiSetStyle(DEFAULT, TEXT_PADDING, 0);
//GuiSetStyle(DEFAULT, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -133,6 +153,40 @@ int main()
UnloadDroppedFiles(droppedFiles); // Clear internal buffers UnloadDroppedFiles(droppedFiles); // Clear internal buffers
} }
//alpha -= 0.002f;
if (alpha < 0.0f) alpha = 0.0f;
if (IsKeyPressed(KEY_SPACE)) alpha = 1.0f;
GuiSetAlpha(alpha);
//progressValue += 0.002f;
if (IsKeyPressed(KEY_LEFT)) progressValue -= 0.1f;
else if (IsKeyPressed(KEY_RIGHT)) progressValue += 0.1f;
if (progressValue > 1.0f) progressValue = 1.0f;
else if (progressValue < 0.0f) progressValue = 0.0f;
if (visualStyleActive != prevVisualStyleActive)
{
GuiLoadStyleDefault();
// raygui style comment out, see https://github.com/raysan5/raygui/tree/master/examples for full examples
switch (visualStyleActive)
{
case 0: break; // Default style
// case 1: GuiLoadStyleJungle(); break;
// case 2: GuiLoadStyleLavanda(); break;
// case 3: GuiLoadStyleDark(); break;
// case 4: GuiLoadStyleBluish(); break;
// case 5: GuiLoadStyleCyber(); break;
// case 6: GuiLoadStyleTerminal(); break;
default: break;
}
GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
prevVisualStyleActive = visualStyleActive;
}
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
@ -144,12 +198,11 @@ int main()
// raygui: controls drawing // raygui: controls drawing
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Check all possible events that require GuiLock // Check all possible events that require GuiLock
if (dropDown000EditMode || if (dropDown000EditMode || dropDown001EditMode) GuiLock();
dropDown001EditMode) GuiLock();
// First GUI column // First GUI column
//GuiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); //GuiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
forceSquaredChecked = GuiCheckBox((Rectangle){ 25, 108, 15, 15 }, "FORCE CHECK!", forceSquaredChecked); GuiCheckBox((Rectangle){ 25, 108, 15, 15 }, "FORCE CHECK!", &forceSquaredChecked);
GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
//GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); //GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
@ -171,38 +224,59 @@ int main()
GuiSetState(STATE_NORMAL); GuiSetState(STATE_NORMAL);
//GuiUnlock(); //GuiUnlock();
comboBoxActive = GuiComboBox((Rectangle){ 25, 470, 125, 30 }, "ONE;TWO;THREE;FOUR", comboBoxActive); GuiComboBox((Rectangle){ 25, 480, 125, 30 }, "default;Jungle;Lavanda;Dark;Bluish;Cyber;Terminal", &visualStyleActive);
// NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding // NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding
GuiUnlock(); GuiUnlock();
GuiSetStyle(DROPDOWNBOX, TEXT_PADDING, 4);
GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
if (GuiDropdownBox((Rectangle){ 25, 65, 125, 30 }, "#01#ONE;#02#TWO;#03#THREE;#04#FOUR", &dropdownBox001Active, dropDown001EditMode)) dropDown001EditMode = !dropDown001EditMode; if (GuiDropdownBox((Rectangle){ 25, 65, 125, 30 }, "#01#ONE;#02#TWO;#03#THREE;#04#FOUR", &dropdownBox001Active, dropDown001EditMode)) dropDown001EditMode = !dropDown001EditMode;
GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
GuiSetStyle(DROPDOWNBOX, TEXT_PADDING, 0);
if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode; if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode;
// Second GUI column // Second GUI column
listViewActive = GuiListView((Rectangle){ 165, 25, 140, 140 }, "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey", &listViewScrollIndex, listViewActive); GuiListView((Rectangle){ 165, 25, 140, 124 }, "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey", &listViewScrollIndex, &listViewActive);
listViewExActive = GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, 8, &listViewExFocus, &listViewExScrollIndex, listViewExActive); GuiListViewEx((Rectangle){ 165, 162, 140, 184 }, listViewExList, 8, &listViewExScrollIndex, &listViewExActive, &listViewExFocus);
toggleGroupActive = GuiToggleGroup((Rectangle){ 165, 400, 140, 25 }, "#1#ONE\n#3#TWO\n#8#THREE\n#23#", toggleGroupActive); //GuiToggle((Rectangle){ 165, 400, 140, 25 }, "#1#ONE", &toggleGroupActive);
GuiToggleGroup((Rectangle){ 165, 360, 140, 24 }, "#1#ONE\n#3#TWO\n#8#THREE\n#23#", &toggleGroupActive);
//GuiDisable();
GuiSetStyle(SLIDER, SLIDER_PADDING, 2);
GuiToggleSlider((Rectangle){ 165, 480, 140, 30 }, "ON;OFF", &toggleSliderActive);
GuiSetStyle(SLIDER, SLIDER_PADDING, 0);
// Third GUI column // Third GUI column
GuiPanel((Rectangle){ 320, 25, 225, 140 }, "Panel Info"); GuiPanel((Rectangle){ 320, 25, 225, 140 }, "Panel Info");
colorPickerValue = GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, NULL, colorPickerValue); GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, NULL, &colorPickerValue);
sliderValue = GuiSlider((Rectangle){ 355, 400, 165, 20 }, "TEST", TextFormat("%2.2f", (float)sliderValue), sliderValue, -50, 100); //GuiDisable();
sliderBarValue = GuiSliderBar((Rectangle){ 320, 430, 200, 20 }, NULL, TextFormat("%i", (int)sliderBarValue), sliderBarValue, 0, 100); GuiSlider((Rectangle){ 355, 400, 165, 20 }, "TEST", TextFormat("%2.2f", sliderValue), &sliderValue, -50, 100);
progressValue = GuiProgressBar((Rectangle){ 320, 460, 200, 20 }, NULL, NULL, progressValue, 0, 1); GuiSliderBar((Rectangle){ 320, 430, 200, 20 }, NULL, TextFormat("%i", (int)sliderBarValue), &sliderBarValue, 0, 100);
GuiProgressBar((Rectangle){ 320, 460, 200, 20 }, NULL, TextFormat("%i%%", (int)(progressValue*100)), &progressValue, 0.0f, 1.0f);
GuiEnable();
// NOTE: View rectangle could be used to perform some scissor test // NOTE: View rectangle could be used to perform some scissor test
Rectangle view = GuiScrollPanel((Rectangle){ 560, 25, 102, 354 }, NULL, (Rectangle){ 560, 25, 300, 1200 }, &viewScroll); Rectangle view = { 0 };
GuiScrollPanel((Rectangle){ 560, 25, 102, 354 }, NULL, (Rectangle){ 560, 25, 300, 1200 }, &viewScroll, &view);
GuiGrid((Rectangle) { 560, 25 + 180 + 195, 100, 120 }, NULL, 20, 2); Vector2 mouseCell = { 0 };
GuiGrid((Rectangle) { 560, 25 + 180 + 195, 100, 120 }, NULL, 20, 3, &mouseCell);
GuiColorBarAlpha((Rectangle){ 320, 490, 200, 30 }, NULL, &alphaValue);
GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, TEXT_ALIGN_TOP); // WARNING: Word-wrap does not work as expected in case of no-top alignment
GuiSetStyle(DEFAULT, TEXT_WRAP_MODE, TEXT_WRAP_WORD); // WARNING: If wrap mode enabled, text editing is not supported
if (GuiTextBox((Rectangle){ 678, 25, 258, 492 }, textBoxMultiText, 1024, textBoxMultiEditMode)) textBoxMultiEditMode = !textBoxMultiEditMode;
GuiSetStyle(DEFAULT, TEXT_WRAP_MODE, TEXT_WRAP_NONE);
GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, TEXT_ALIGN_MIDDLE);
GuiSetStyle(DEFAULT, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
GuiStatusBar((Rectangle){ 0, (float)GetScreenHeight() - 20, (float)GetScreenWidth(), 20 }, "This is a status bar"); GuiStatusBar((Rectangle){ 0, (float)GetScreenHeight() - 20, (float)GetScreenWidth(), 20 }, "This is a status bar");
GuiSetStyle(DEFAULT, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
alphaValue = GuiColorBarAlpha((Rectangle){ 320, 490, 200, 30 }, NULL, alphaValue); //GuiSetStyle(STATUSBAR, TEXT_INDENTATION, 20);
if (showMessageBox) if (showMessageBox)
{ {
@ -216,19 +290,19 @@ int main()
if (showTextInputBox) if (showTextInputBox)
{ {
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f)); DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f));
int result = GuiTextInputBox((Rectangle){ (float)GetScreenWidth()/2 - 120, (float)GetScreenHeight()/2 - 60, 240, 140 }, "Save", GuiIconText(ICON_FILE_SAVE, "Save file as..."), "Ok;Cancel", textInput, 255, NULL); int result = GuiTextInputBox((Rectangle){ (float)GetScreenWidth()/2 - 120, (float)GetScreenHeight()/2 - 60, 240, 140 }, GuiIconText(ICON_FILE_SAVE, "Save file as..."), "Introduce output file name:", "Ok;Cancel", textInput, 255, NULL);
if (result == 1) if (result == 1)
{ {
// TODO: Validate textInput value and save // TODO: Validate textInput value and save
strcpy(textInputFileName, textInput); TextCopy(textInputFileName, textInput);
} }
if ((result == 0) || (result == 1) || (result == 2)) if ((result == 0) || (result == 1) || (result == 2))
{ {
showTextInputBox = false; showTextInputBox = false;
strcpy(textInput, "\0"); TextCopy(textInput, "\0");
} }
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------