diff --git a/linux/templates/epitrochoid.ico b/linux/templates/epitrochoid.ico new file mode 100644 index 00000000..34a221ab Binary files /dev/null and b/linux/templates/epitrochoid.ico differ diff --git a/linux/templates/epitrochoid.template b/linux/templates/epitrochoid.template new file mode 100644 index 00000000..43a2b337 --- /dev/null +++ b/linux/templates/epitrochoid.template @@ -0,0 +1,20 @@ +[Template] +ver=2 +Name=Epitrochoid +Name[zh_CN]=外旋轮线 +Icon=Epitrochoid.ico +Description=A simple epitrochoid drawing app +Description[zh_CN]=外旋轮线绘制程序 +Category=Game +Category[zh_CN]=游戏 + +[Unit0] +CName=main.c +C=epitrochoid_c.txt + +[Project] +UnitCount=1 +Type=1 +IsCpp=0 +linker=-lrdrawing -lraylib -lopengl32 -lgdi32 -lwinmm +ExecEncoding=UTF-8 diff --git a/linux/templates/epitrochoid_c.txt b/linux/templates/epitrochoid_c.txt new file mode 100644 index 00000000..608ce42e --- /dev/null +++ b/linux/templates/epitrochoid_c.txt @@ -0,0 +1,112 @@ +#include +#include +#include + +#define RAYGUI_IMPLEMENTATION +#include + +void updateRadius(int baseL, int outerL, int *pBaseR, int *pOuterR) { + int totalL=baseL+outerL+outerL; + int totalR = 420; + int remainder = totalR % totalL; + if (remainder!=0) { + if (remainder < totalL / 2) { + totalR -= remainder; + } else { + totalR += ( totalL - remainder); + } + } + *pBaseR = (totalR) / totalL * baseL; + *pOuterR = (totalR) / totalL * outerL; +} + + +int main() { + int baseL=2; + int outerL=13; + int baseR,outerR; + int cx=450,cy=450; + int speed = 1; + Color trackColor = BLUE; + updateRadius(baseL, outerL, &baseR, &outerR); + InitWindow(1300,900,"Epitrochoid"); + SetTraceLogLevel(LOG_WARNING); + SetTargetFPS(60); + GuiSetStyle(DEFAULT,TEXT_SIZE,20); + + Image trackImage=GenImageColor(900,900,WHITE); + //border + ImageFillRectangleEx(&trackImage,0,0,900,900,LIGHTGRAY); + ImageFillRectangleEx(&trackImage,5,5,890,890,WHITE); + + Image circlesImage = GenImageColor(900,900,BLANK); + float r=0; + int lastx,lasty; + lasty=cy; + lastx=cx+(baseR+outerR+outerR); + int frameCount = 0; + while(!WindowShouldClose()) { + //GUI + int newOuterL = GuiSliderBar((Rectangle){ 70, 20, 200, 30 },"Outer",TextFormat("%i", (int)outerL), outerL, 1, 50); + int newBaseL = GuiSliderBar((Rectangle){ 70, 60, 200, 30 },"Base",TextFormat("%i", (int)baseL), baseL, 1, 50); + speed = GuiSliderBar((Rectangle){ 70, 120, 200, 30 },"Speed",TextFormat("%i", (int)speed), speed, 1, 50); + GuiLabel((Rectangle){ 20, 220, 80, 30 },TextFormat("Color: 0x%X%X%X ",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b))); + trackColor= GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, trackColor); + int doClear = GuiButton((Rectangle){ 120, 700, 80, 30 },"Clear"); + if (newOuterL!=outerL || newBaseL!=baseL) { + outerL=newOuterL; + baseL=newBaseL; + updateRadius(baseL, outerL, &baseR, &outerR); + lasty=cy; + lastx=cx+(baseR+outerR+outerR); + r=0; + ImageClearBackground(&trackImage,WHITE); + ImageFillRectangleEx(&trackImage,0,0,900,900,LIGHTGRAY); + ImageFillRectangleEx(&trackImage,5,5,890,890,WHITE); + } else if (doClear) { + ImageClearBackground(&trackImage,WHITE); + ImageFillRectangleEx(&trackImage,0,0,900,900,LIGHTGRAY); + ImageFillRectangleEx(&trackImage,5,5,890,890,WHITE); + } + //update datas + r+=0.01; + float outerCX=cx+ (baseR+outerR)*cos(r); + float outerCY=cy+ (baseR+outerR)*sin(r); + float theta = r * baseL / outerL; + int x=round(outerCX + outerR * cos(theta)); + int y=round(outerCY + outerR * sin(theta)); + + //update image (in CPU) + //ImageClearBackground(&trackImage,WHITE); + ImageDrawLineEx(&trackImage,lastx,lasty,x,y,3,trackColor); + + frameCount++; + if (frameCount>=speed) { + ImageClearBackground(&circlesImage,BLANK); + //base circle + ImageDrawCircleEx(&circlesImage,cx,cy,baseR,1,LIGHTRED); + ImageDrawCircleEx(&circlesImage,outerCX,outerCY,outerR,1,LIGHTSLATEGRAY); + ImageDrawPointEx(&circlesImage,x,y,7,RED); + + //Drawing in GPU + Texture trackTexture = LoadTextureFromImage(trackImage); + Texture circlesTexture = LoadTextureFromImage(circlesImage); + BeginDrawing(); + ClearBackground(WHITE); + DrawTexture(trackTexture,300,0,WHITE); + DrawTexture(circlesTexture,300,0,WHITE); + EndDrawing(); + UnloadTexture(circlesTexture); + UnloadTexture(trackTexture); + frameCount=0; + } + + lastx=x; + lasty=y; + } + + //Clean up + UnloadImage(circlesImage); + UnloadImage(trackImage); + CloseWindow(); +} diff --git a/linux/templates/hypotrochoid.ico b/linux/templates/hypotrochoid.ico new file mode 100644 index 00000000..bff8482f Binary files /dev/null and b/linux/templates/hypotrochoid.ico differ diff --git a/linux/templates/hypotrochoid.template b/linux/templates/hypotrochoid.template new file mode 100644 index 00000000..5fb9227e --- /dev/null +++ b/linux/templates/hypotrochoid.template @@ -0,0 +1,20 @@ +[Template] +ver=2 +Name=Hypotrochoid +Name[zh_CN]=内旋轮线 +Icon=hypotrochoid.ico +Description=A simple hypotrochoid drawing app +Description[zh_CN]=内旋轮线绘制程序 +Category=Game +Category[zh_CN]=游戏 + +[Unit0] +CName=main.c +C=hypotrochoid_c.txt + +[Project] +UnitCount=1 +Type=1 +IsCpp=0 +linker=-lrdrawing -lraylib -lopengl32 -lgdi32 -lwinmm +ExecEncoding=UTF-8 diff --git a/linux/templates/hypotrochoid_c.txt b/linux/templates/hypotrochoid_c.txt new file mode 100644 index 00000000..b847ea2c --- /dev/null +++ b/linux/templates/hypotrochoid_c.txt @@ -0,0 +1,119 @@ +#include +#include +#include + +#define RAYGUI_IMPLEMENTATION +#include + +void updateRadius(int baseL, int innerL, int *pBaseR, int *pInnerR) { + int totalL=baseL; + if (innerL>baseL) + totalL = (2*innerL-baseL); + int totalR = 420; + int remainder = totalR % totalL; + if (remainder!=0) { + if (remainder < totalL / 2) { + totalR -= remainder; + } else { + totalR += ( totalL - remainder); + } + } + if (innerL=speed) { + ImageClearBackground(&circlesImage,BLANK); + //base circle + ImageDrawCircleEx(&circlesImage,cx,cy,baseR,1,LIGHTRED); + ImageDrawCircleEx(&circlesImage,innerCX,innerCY,innerR,1,LIGHTSLATEGRAY); + ImageDrawPointEx(&circlesImage,x,y,7,RED); + + //Drawing in GPU + Texture trackTexture = LoadTextureFromImage(trackImage); + Texture circlesTexture = LoadTextureFromImage(circlesImage); + BeginDrawing(); + ClearBackground(WHITE); + DrawTexture(trackTexture,300,0,WHITE); + DrawTexture(circlesTexture,300,0,WHITE); + EndDrawing(); + UnloadTexture(circlesTexture); + UnloadTexture(trackTexture); + frameCount=0; + } + + lastx=x; + lasty=y; + } + + //Clean up + UnloadImage(circlesImage); + UnloadImage(trackImage); + CloseWindow(); +} diff --git a/linux/templates/raygui.ico b/linux/templates/raygui.ico new file mode 100644 index 00000000..b8668114 Binary files /dev/null and b/linux/templates/raygui.ico differ diff --git a/linux/templates/raygui.template b/linux/templates/raygui.template new file mode 100644 index 00000000..86a7cd62 --- /dev/null +++ b/linux/templates/raygui.template @@ -0,0 +1,21 @@ +[Template] +ver=2 +Name=raygui +Name[zh_CN]=raygui +Icon=raygui.ico +Description=raygui demo +Description[zh_CN]=Raygui演示 +Category=Multimedia +Category[zh_CN]=多媒体 + +[Unit0] +CName=main.c +C=raygui_c.txt + +[Project] +UnitCount=1 +Type=1 +IsCpp=0 +linker=-lraylib -lopengl32 -lgdi32 -lwinmm +ExecEncoding=UTF-8 + diff --git a/linux/templates/raygui_c.txt b/linux/templates/raygui_c.txt new file mode 100644 index 00000000..e5be517e --- /dev/null +++ b/linux/templates/raygui_c.txt @@ -0,0 +1,251 @@ +/******************************************************************************************* +* +* raygui - controls test suite +* +* TEST CONTROLS: +* - GuiDropdownBox() +* - GuiCheckBox() +* - GuiSpinner() +* - GuiValueBox() +* - GuiTextBox() +* - GuiButton() +* - GuiComboBox() +* - GuiListView() +* - GuiToggleGroup() +* - GuiTextBoxMulti() +* - GuiColorPicker() +* - GuiSlider() +* - GuiSliderBar() +* - GuiProgressBar() +* - GuiColorBarAlpha() +* - GuiScrollPanel() +* +* +* DEPENDENCIES: +* raylib 4.0 - Windowing/input management and drawing. +* raygui 3.2 - 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) 2016-2022 Ramon Santamaria (@raysan5) +* +**********************************************************************************************/ + +#include "raylib.h" + +#define RAYGUI_IMPLEMENTATION +//#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 "raygui/raygui.h" + +#include // Required for: strcpy() + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //--------------------------------------------------------------------------------------- + const int screenWidth = 690; + const int screenHeight = 560; + + InitWindow(screenWidth, screenHeight, "raygui - controls test suite"); + SetExitKey(0); + + // GUI controls initialization + //---------------------------------------------------------------------------------- + //GuiSetStyle(DEFAULT,TEXT_SIZE,16); + int dropdownBox000Active = 0; + bool dropDown000EditMode = false; + + int dropdownBox001Active = 0; + bool dropDown001EditMode = false; + + int spinner001Value = 0; + bool spinnerEditMode = false; + + int valueBox002Value = 0; + bool valueBoxEditMode = false; + + char textBoxText[64] = "Text box"; + bool textBoxEditMode = false; + + int listViewScrollIndex = 0; + int listViewActive = -1; + + int listViewExScrollIndex = 0; + int listViewExActive = 2; + int listViewExFocus = -1; + 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; + + int sliderValue = 50; + int sliderBarValue = 60; + float progressValue = 0.4f; + + bool forceSquaredChecked = false; + + float alphaValue = 0.5f; + + int comboBoxActive = 1; + + int toggleGroupActive = 0; + + Vector2 viewScroll = { 0, 0 }; + //---------------------------------------------------------------------------------- + + // Custom GUI font loading + //Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0); + //GuiSetFont(font); + + bool exitWindow = false; + bool showMessageBox = false; + + char textInput[256] = { 0 }; + bool showTextInputBox = false; + + char textInputFileName[256] = { 0 }; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!exitWindow) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + exitWindow = WindowShouldClose(); + + if (IsKeyPressed(KEY_ESCAPE)) showMessageBox = !showMessageBox; + + if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_S)) showTextInputBox = true; + +// incompatible with raylib 4.0 +// if (IsFileDropped()) +// { +// int dropFileCount = 0; +// char **droppedFiles = LoadDroppedFiles(&dropFileCount); +// +// if ((dropFileCount > 0) && IsFileExtension(droppedFiles[0], ".rgs")) GuiLoadStyle(droppedFiles[0]); +// +// UnloadDroppedFiles(); // Clear internal buffers +// } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); + + // raygui: controls drawing + //---------------------------------------------------------------------------------- + if (dropDown000EditMode || dropDown001EditMode) GuiLock(); + else if (!dropDown000EditMode && !dropDown001EditMode) GuiUnlock(); + //GuiDisable(); + + // First GUI column + //GuiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); + forceSquaredChecked = GuiCheckBox((Rectangle){ 25, 108, 15, 15 }, "FORCE CHECK!", forceSquaredChecked); + + GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); + //GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); + if (GuiSpinner((Rectangle){ 25, 135, 125, 30 }, NULL, &spinner001Value, 0, 100, spinnerEditMode)) spinnerEditMode = !spinnerEditMode; + if (GuiValueBox((Rectangle){ 25, 175, 125, 30 }, NULL, &valueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode; + GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); + if (GuiTextBox((Rectangle){ 25, 215, 125, 30 }, textBoxText, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode; + + GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); + + if (GuiButton((Rectangle){ 25, 255, 125, 30 }, GuiIconText(ICON_FILE_SAVE, "Save File"))) showTextInputBox = true; + + GuiGroupBox((Rectangle){ 25, 310, 125, 150 }, "STATES"); + //GuiLock(); + GuiSetState(STATE_NORMAL); if (GuiButton((Rectangle){ 30, 320, 115, 30 }, "NORMAL")) { } + GuiSetState(STATE_FOCUSED); if (GuiButton((Rectangle){ 30, 355, 115, 30 }, "FOCUSED")) { } + GuiSetState(STATE_PRESSED); if (GuiButton((Rectangle){ 30, 390, 115, 30 }, "#15#PRESSED")) { } + GuiSetState(STATE_DISABLED); if (GuiButton((Rectangle){ 30, 425, 115, 30 }, "DISABLED")) { } + GuiSetState(STATE_NORMAL); + //GuiUnlock(); + + comboBoxActive = GuiComboBox((Rectangle){ 25, 470, 125, 30 }, "ONE;TWO;THREE;FOUR", comboBoxActive); + + // NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding + 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; + + GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); + if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode; + + // Second GUI column + listViewActive = GuiListView((Rectangle){ 165, 25, 140, 140 }, "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey", &listViewScrollIndex, listViewActive); + listViewExActive = GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, 8, &listViewExFocus, &listViewExScrollIndex, listViewExActive); + + toggleGroupActive = GuiToggleGroup((Rectangle){ 165, 400, 140, 25 }, "#1#ONE\n#3#TWO\n#8#THREE\n#23#", toggleGroupActive); + + // Third GUI column + if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 256, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode; + 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); + sliderBarValue = GuiSliderBar((Rectangle){ 320, 430, 200, 20 }, NULL, TextFormat("%i", (int)sliderBarValue), sliderBarValue, 0, 100); + progressValue = GuiProgressBar((Rectangle){ 320, 460, 200, 20 }, NULL, NULL, progressValue, 0, 1); + + // NOTE: View rectangle could be used to perform some scissor test + Rectangle view = GuiScrollPanel((Rectangle){ 560, 25, 100, 160 }, NULL, (Rectangle){ 560, 25, 200, 400 }, &viewScroll); + + GuiPanel((Rectangle){ 560, 25 + 180, 100, 160 }, "Panel Info"); + + GuiGrid((Rectangle) { 560, 25 + 180 + 180, 100, 120 }, NULL, 20, 2); + + GuiStatusBar((Rectangle){ 0, (float)GetScreenHeight() - 20, (float)GetScreenWidth(), 20 }, "This is a status bar"); + + alphaValue = GuiColorBarAlpha((Rectangle){ 320, 490, 200, 30 }, NULL, alphaValue); + + if (showMessageBox) + { + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f)); + int result = GuiMessageBox((Rectangle){ (float)GetScreenWidth()/2 - 125, (float)GetScreenHeight()/2 - 50, 250, 100 }, GuiIconText(ICON_EXIT, "Close Window"), "Do you really want to exit?", "Yes;No"); + + if ((result == 0) || (result == 2)) showMessageBox = false; + else if (result == 1) exitWindow = true; + } + + if (showTextInputBox) + { + 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); + + if (result == 1) + { + // TODO: Validate textInput value and save + + strcpy(textInputFileName, textInput); + } + + if ((result == 0) || (result == 1) || (result == 2)) + { + showTextInputBox = false; + strcpy(textInput, "\0"); + } + } + //---------------------------------------------------------------------------------- + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/windows/templates/epitrochoid.ico b/windows/templates/epitrochoid.ico new file mode 100644 index 00000000..34a221ab Binary files /dev/null and b/windows/templates/epitrochoid.ico differ diff --git a/windows/templates/epitrochoid.template b/windows/templates/epitrochoid.template new file mode 100644 index 00000000..43a2b337 --- /dev/null +++ b/windows/templates/epitrochoid.template @@ -0,0 +1,20 @@ +[Template] +ver=2 +Name=Epitrochoid +Name[zh_CN]=外旋轮线 +Icon=Epitrochoid.ico +Description=A simple epitrochoid drawing app +Description[zh_CN]=外旋轮线绘制程序 +Category=Game +Category[zh_CN]=游戏 + +[Unit0] +CName=main.c +C=epitrochoid_c.txt + +[Project] +UnitCount=1 +Type=1 +IsCpp=0 +linker=-lrdrawing -lraylib -lopengl32 -lgdi32 -lwinmm +ExecEncoding=UTF-8 diff --git a/windows/templates/epitrochoid_c.txt b/windows/templates/epitrochoid_c.txt new file mode 100644 index 00000000..608ce42e --- /dev/null +++ b/windows/templates/epitrochoid_c.txt @@ -0,0 +1,112 @@ +#include +#include +#include + +#define RAYGUI_IMPLEMENTATION +#include + +void updateRadius(int baseL, int outerL, int *pBaseR, int *pOuterR) { + int totalL=baseL+outerL+outerL; + int totalR = 420; + int remainder = totalR % totalL; + if (remainder!=0) { + if (remainder < totalL / 2) { + totalR -= remainder; + } else { + totalR += ( totalL - remainder); + } + } + *pBaseR = (totalR) / totalL * baseL; + *pOuterR = (totalR) / totalL * outerL; +} + + +int main() { + int baseL=2; + int outerL=13; + int baseR,outerR; + int cx=450,cy=450; + int speed = 1; + Color trackColor = BLUE; + updateRadius(baseL, outerL, &baseR, &outerR); + InitWindow(1300,900,"Epitrochoid"); + SetTraceLogLevel(LOG_WARNING); + SetTargetFPS(60); + GuiSetStyle(DEFAULT,TEXT_SIZE,20); + + Image trackImage=GenImageColor(900,900,WHITE); + //border + ImageFillRectangleEx(&trackImage,0,0,900,900,LIGHTGRAY); + ImageFillRectangleEx(&trackImage,5,5,890,890,WHITE); + + Image circlesImage = GenImageColor(900,900,BLANK); + float r=0; + int lastx,lasty; + lasty=cy; + lastx=cx+(baseR+outerR+outerR); + int frameCount = 0; + while(!WindowShouldClose()) { + //GUI + int newOuterL = GuiSliderBar((Rectangle){ 70, 20, 200, 30 },"Outer",TextFormat("%i", (int)outerL), outerL, 1, 50); + int newBaseL = GuiSliderBar((Rectangle){ 70, 60, 200, 30 },"Base",TextFormat("%i", (int)baseL), baseL, 1, 50); + speed = GuiSliderBar((Rectangle){ 70, 120, 200, 30 },"Speed",TextFormat("%i", (int)speed), speed, 1, 50); + GuiLabel((Rectangle){ 20, 220, 80, 30 },TextFormat("Color: 0x%X%X%X ",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b))); + trackColor= GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, trackColor); + int doClear = GuiButton((Rectangle){ 120, 700, 80, 30 },"Clear"); + if (newOuterL!=outerL || newBaseL!=baseL) { + outerL=newOuterL; + baseL=newBaseL; + updateRadius(baseL, outerL, &baseR, &outerR); + lasty=cy; + lastx=cx+(baseR+outerR+outerR); + r=0; + ImageClearBackground(&trackImage,WHITE); + ImageFillRectangleEx(&trackImage,0,0,900,900,LIGHTGRAY); + ImageFillRectangleEx(&trackImage,5,5,890,890,WHITE); + } else if (doClear) { + ImageClearBackground(&trackImage,WHITE); + ImageFillRectangleEx(&trackImage,0,0,900,900,LIGHTGRAY); + ImageFillRectangleEx(&trackImage,5,5,890,890,WHITE); + } + //update datas + r+=0.01; + float outerCX=cx+ (baseR+outerR)*cos(r); + float outerCY=cy+ (baseR+outerR)*sin(r); + float theta = r * baseL / outerL; + int x=round(outerCX + outerR * cos(theta)); + int y=round(outerCY + outerR * sin(theta)); + + //update image (in CPU) + //ImageClearBackground(&trackImage,WHITE); + ImageDrawLineEx(&trackImage,lastx,lasty,x,y,3,trackColor); + + frameCount++; + if (frameCount>=speed) { + ImageClearBackground(&circlesImage,BLANK); + //base circle + ImageDrawCircleEx(&circlesImage,cx,cy,baseR,1,LIGHTRED); + ImageDrawCircleEx(&circlesImage,outerCX,outerCY,outerR,1,LIGHTSLATEGRAY); + ImageDrawPointEx(&circlesImage,x,y,7,RED); + + //Drawing in GPU + Texture trackTexture = LoadTextureFromImage(trackImage); + Texture circlesTexture = LoadTextureFromImage(circlesImage); + BeginDrawing(); + ClearBackground(WHITE); + DrawTexture(trackTexture,300,0,WHITE); + DrawTexture(circlesTexture,300,0,WHITE); + EndDrawing(); + UnloadTexture(circlesTexture); + UnloadTexture(trackTexture); + frameCount=0; + } + + lastx=x; + lasty=y; + } + + //Clean up + UnloadImage(circlesImage); + UnloadImage(trackImage); + CloseWindow(); +} diff --git a/windows/templates/hypotrochoid.ico b/windows/templates/hypotrochoid.ico new file mode 100644 index 00000000..bff8482f Binary files /dev/null and b/windows/templates/hypotrochoid.ico differ diff --git a/windows/templates/hypotrochoid.template b/windows/templates/hypotrochoid.template new file mode 100644 index 00000000..5fb9227e --- /dev/null +++ b/windows/templates/hypotrochoid.template @@ -0,0 +1,20 @@ +[Template] +ver=2 +Name=Hypotrochoid +Name[zh_CN]=内旋轮线 +Icon=hypotrochoid.ico +Description=A simple hypotrochoid drawing app +Description[zh_CN]=内旋轮线绘制程序 +Category=Game +Category[zh_CN]=游戏 + +[Unit0] +CName=main.c +C=hypotrochoid_c.txt + +[Project] +UnitCount=1 +Type=1 +IsCpp=0 +linker=-lrdrawing -lraylib -lopengl32 -lgdi32 -lwinmm +ExecEncoding=UTF-8 diff --git a/windows/templates/hypotrochoid_c.txt b/windows/templates/hypotrochoid_c.txt new file mode 100644 index 00000000..b847ea2c --- /dev/null +++ b/windows/templates/hypotrochoid_c.txt @@ -0,0 +1,119 @@ +#include +#include +#include + +#define RAYGUI_IMPLEMENTATION +#include + +void updateRadius(int baseL, int innerL, int *pBaseR, int *pInnerR) { + int totalL=baseL; + if (innerL>baseL) + totalL = (2*innerL-baseL); + int totalR = 420; + int remainder = totalR % totalL; + if (remainder!=0) { + if (remainder < totalL / 2) { + totalR -= remainder; + } else { + totalR += ( totalL - remainder); + } + } + if (innerL=speed) { + ImageClearBackground(&circlesImage,BLANK); + //base circle + ImageDrawCircleEx(&circlesImage,cx,cy,baseR,1,LIGHTRED); + ImageDrawCircleEx(&circlesImage,innerCX,innerCY,innerR,1,LIGHTSLATEGRAY); + ImageDrawPointEx(&circlesImage,x,y,7,RED); + + //Drawing in GPU + Texture trackTexture = LoadTextureFromImage(trackImage); + Texture circlesTexture = LoadTextureFromImage(circlesImage); + BeginDrawing(); + ClearBackground(WHITE); + DrawTexture(trackTexture,300,0,WHITE); + DrawTexture(circlesTexture,300,0,WHITE); + EndDrawing(); + UnloadTexture(circlesTexture); + UnloadTexture(trackTexture); + frameCount=0; + } + + lastx=x; + lasty=y; + } + + //Clean up + UnloadImage(circlesImage); + UnloadImage(trackImage); + CloseWindow(); +} diff --git a/windows/templates/raygui.ico b/windows/templates/raygui.ico new file mode 100644 index 00000000..b8668114 Binary files /dev/null and b/windows/templates/raygui.ico differ diff --git a/windows/templates/raygui.template b/windows/templates/raygui.template new file mode 100644 index 00000000..86a7cd62 --- /dev/null +++ b/windows/templates/raygui.template @@ -0,0 +1,21 @@ +[Template] +ver=2 +Name=raygui +Name[zh_CN]=raygui +Icon=raygui.ico +Description=raygui demo +Description[zh_CN]=Raygui演示 +Category=Multimedia +Category[zh_CN]=多媒体 + +[Unit0] +CName=main.c +C=raygui_c.txt + +[Project] +UnitCount=1 +Type=1 +IsCpp=0 +linker=-lraylib -lopengl32 -lgdi32 -lwinmm +ExecEncoding=UTF-8 + diff --git a/windows/templates/raygui_c.txt b/windows/templates/raygui_c.txt new file mode 100644 index 00000000..e5be517e --- /dev/null +++ b/windows/templates/raygui_c.txt @@ -0,0 +1,251 @@ +/******************************************************************************************* +* +* raygui - controls test suite +* +* TEST CONTROLS: +* - GuiDropdownBox() +* - GuiCheckBox() +* - GuiSpinner() +* - GuiValueBox() +* - GuiTextBox() +* - GuiButton() +* - GuiComboBox() +* - GuiListView() +* - GuiToggleGroup() +* - GuiTextBoxMulti() +* - GuiColorPicker() +* - GuiSlider() +* - GuiSliderBar() +* - GuiProgressBar() +* - GuiColorBarAlpha() +* - GuiScrollPanel() +* +* +* DEPENDENCIES: +* raylib 4.0 - Windowing/input management and drawing. +* raygui 3.2 - 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) 2016-2022 Ramon Santamaria (@raysan5) +* +**********************************************************************************************/ + +#include "raylib.h" + +#define RAYGUI_IMPLEMENTATION +//#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 "raygui/raygui.h" + +#include // Required for: strcpy() + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //--------------------------------------------------------------------------------------- + const int screenWidth = 690; + const int screenHeight = 560; + + InitWindow(screenWidth, screenHeight, "raygui - controls test suite"); + SetExitKey(0); + + // GUI controls initialization + //---------------------------------------------------------------------------------- + //GuiSetStyle(DEFAULT,TEXT_SIZE,16); + int dropdownBox000Active = 0; + bool dropDown000EditMode = false; + + int dropdownBox001Active = 0; + bool dropDown001EditMode = false; + + int spinner001Value = 0; + bool spinnerEditMode = false; + + int valueBox002Value = 0; + bool valueBoxEditMode = false; + + char textBoxText[64] = "Text box"; + bool textBoxEditMode = false; + + int listViewScrollIndex = 0; + int listViewActive = -1; + + int listViewExScrollIndex = 0; + int listViewExActive = 2; + int listViewExFocus = -1; + 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; + + int sliderValue = 50; + int sliderBarValue = 60; + float progressValue = 0.4f; + + bool forceSquaredChecked = false; + + float alphaValue = 0.5f; + + int comboBoxActive = 1; + + int toggleGroupActive = 0; + + Vector2 viewScroll = { 0, 0 }; + //---------------------------------------------------------------------------------- + + // Custom GUI font loading + //Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0); + //GuiSetFont(font); + + bool exitWindow = false; + bool showMessageBox = false; + + char textInput[256] = { 0 }; + bool showTextInputBox = false; + + char textInputFileName[256] = { 0 }; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!exitWindow) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + exitWindow = WindowShouldClose(); + + if (IsKeyPressed(KEY_ESCAPE)) showMessageBox = !showMessageBox; + + if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_S)) showTextInputBox = true; + +// incompatible with raylib 4.0 +// if (IsFileDropped()) +// { +// int dropFileCount = 0; +// char **droppedFiles = LoadDroppedFiles(&dropFileCount); +// +// if ((dropFileCount > 0) && IsFileExtension(droppedFiles[0], ".rgs")) GuiLoadStyle(droppedFiles[0]); +// +// UnloadDroppedFiles(); // Clear internal buffers +// } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); + + // raygui: controls drawing + //---------------------------------------------------------------------------------- + if (dropDown000EditMode || dropDown001EditMode) GuiLock(); + else if (!dropDown000EditMode && !dropDown001EditMode) GuiUnlock(); + //GuiDisable(); + + // First GUI column + //GuiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); + forceSquaredChecked = GuiCheckBox((Rectangle){ 25, 108, 15, 15 }, "FORCE CHECK!", forceSquaredChecked); + + GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); + //GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); + if (GuiSpinner((Rectangle){ 25, 135, 125, 30 }, NULL, &spinner001Value, 0, 100, spinnerEditMode)) spinnerEditMode = !spinnerEditMode; + if (GuiValueBox((Rectangle){ 25, 175, 125, 30 }, NULL, &valueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode; + GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); + if (GuiTextBox((Rectangle){ 25, 215, 125, 30 }, textBoxText, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode; + + GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); + + if (GuiButton((Rectangle){ 25, 255, 125, 30 }, GuiIconText(ICON_FILE_SAVE, "Save File"))) showTextInputBox = true; + + GuiGroupBox((Rectangle){ 25, 310, 125, 150 }, "STATES"); + //GuiLock(); + GuiSetState(STATE_NORMAL); if (GuiButton((Rectangle){ 30, 320, 115, 30 }, "NORMAL")) { } + GuiSetState(STATE_FOCUSED); if (GuiButton((Rectangle){ 30, 355, 115, 30 }, "FOCUSED")) { } + GuiSetState(STATE_PRESSED); if (GuiButton((Rectangle){ 30, 390, 115, 30 }, "#15#PRESSED")) { } + GuiSetState(STATE_DISABLED); if (GuiButton((Rectangle){ 30, 425, 115, 30 }, "DISABLED")) { } + GuiSetState(STATE_NORMAL); + //GuiUnlock(); + + comboBoxActive = GuiComboBox((Rectangle){ 25, 470, 125, 30 }, "ONE;TWO;THREE;FOUR", comboBoxActive); + + // NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding + 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; + + GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); + if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode; + + // Second GUI column + listViewActive = GuiListView((Rectangle){ 165, 25, 140, 140 }, "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey", &listViewScrollIndex, listViewActive); + listViewExActive = GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, 8, &listViewExFocus, &listViewExScrollIndex, listViewExActive); + + toggleGroupActive = GuiToggleGroup((Rectangle){ 165, 400, 140, 25 }, "#1#ONE\n#3#TWO\n#8#THREE\n#23#", toggleGroupActive); + + // Third GUI column + if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 256, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode; + 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); + sliderBarValue = GuiSliderBar((Rectangle){ 320, 430, 200, 20 }, NULL, TextFormat("%i", (int)sliderBarValue), sliderBarValue, 0, 100); + progressValue = GuiProgressBar((Rectangle){ 320, 460, 200, 20 }, NULL, NULL, progressValue, 0, 1); + + // NOTE: View rectangle could be used to perform some scissor test + Rectangle view = GuiScrollPanel((Rectangle){ 560, 25, 100, 160 }, NULL, (Rectangle){ 560, 25, 200, 400 }, &viewScroll); + + GuiPanel((Rectangle){ 560, 25 + 180, 100, 160 }, "Panel Info"); + + GuiGrid((Rectangle) { 560, 25 + 180 + 180, 100, 120 }, NULL, 20, 2); + + GuiStatusBar((Rectangle){ 0, (float)GetScreenHeight() - 20, (float)GetScreenWidth(), 20 }, "This is a status bar"); + + alphaValue = GuiColorBarAlpha((Rectangle){ 320, 490, 200, 30 }, NULL, alphaValue); + + if (showMessageBox) + { + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f)); + int result = GuiMessageBox((Rectangle){ (float)GetScreenWidth()/2 - 125, (float)GetScreenHeight()/2 - 50, 250, 100 }, GuiIconText(ICON_EXIT, "Close Window"), "Do you really want to exit?", "Yes;No"); + + if ((result == 0) || (result == 2)) showMessageBox = false; + else if (result == 1) exitWindow = true; + } + + if (showTextInputBox) + { + 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); + + if (result == 1) + { + // TODO: Validate textInput value and save + + strcpy(textInputFileName, textInput); + } + + if ((result == 0) || (result == 1) || (result == 2)) + { + showTextInputBox = false; + strcpy(textInput, "\0"); + } + } + //---------------------------------------------------------------------------------- + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}