From 39d211ac0f783500c9c6c630384a8340edf33bc0 Mon Sep 17 00:00:00 2001 From: Booklordofthedings Date: Sun, 12 May 2024 13:06:45 +0200 Subject: [PATCH] implemented basic window and letterboxing --- BeefProj.toml | 2 + BeefSpace.toml | 10 +++- assets/64.png | Bin 0 -> 925 bytes src/Application.bf | 111 +++++++++++++++++++++++++++++++++++++++++++++ src/Assets.bf | 8 ++++ 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 assets/64.png create mode 100644 src/Application.bf create mode 100644 src/Assets.bf diff --git a/BeefProj.toml b/BeefProj.toml index e169987..2bb6413 100644 --- a/BeefProj.toml +++ b/BeefProj.toml @@ -1,5 +1,7 @@ FileVersion = 1 +Dependencies = {corlib = "*", raylib-beef = "*"} [Project] Name = "TheaterGui" +TargetType = "BeefLib" StartupObject = "TheaterGui.Program" diff --git a/BeefSpace.toml b/BeefSpace.toml index 1cbd8d8..4f08523 100644 --- a/BeefSpace.toml +++ b/BeefSpace.toml @@ -1,5 +1,11 @@ FileVersion = 1 -Projects = {TheaterGui = {Path = "."}, raylib-beef = {Path = "../../Libs/External/raylib-beef/raylib-beef"}} +Projects = {TheaterGui = {Path = "."}, raylib-beef = {Path = "../../External/raylib-beef/raylib-beef"}, ExampleGui = {Path = "../../../Projects/ExampleGui"}} [Workspace] -StartupProject = "TheaterGui" +StartupProject = "ExampleGui" + +[Configs.Debug.Win64] +ConfigSelections = {raylib-beef = {Config = "StaticDebug"}} + +[Configs.Release.Win64] +ConfigSelections = {raylib-beef = {Config = "StaticRelease"}} diff --git a/assets/64.png b/assets/64.png new file mode 100644 index 0000000000000000000000000000000000000000..37a44cef72b48d1d47572f5306248604cff16f61 GIT binary patch literal 925 zcmV;O17iG%P)+O?M6Uc}@soT;V_c#kQ6o`6 zh!SuKL=7%6G0`8?eq<_Rr|nGJ+if_>7(#Gn+H=pn=iUy!bnya190&hI2Fu`CRQ!Mw zygZJ$X}E0zLccr|+tAOYI57jMH;lO4(B?8>nVm#KHXZyqP7x4;fgLo__!|~EpO6?# ztMHPuFK~;UkIuY!RwDvpG4P>cKXoM`DYW;BO*MWuih_`A>()q9Fz^l?&!&=)Sb8(D zFEG$V0R+>!i^gVP+kyR%9)g5qUcS#7n{53*H)|CkB=c4g0L8#2IswkOuU{ddv#hvQ z4ceEnU=anrRg1>z&NeNzj{~ueRS^(cZyO!7FJs;i1sK8k6&j;cTkoiS)j~t}BqS8; zhuWWXe(AXm?$Eblwax>48F=H!ek^B7Alb$N7T+}rvY7|e@3-O+{_?wEVCGp{1o&!i z6=?CQD1h`TG?ex>fVKaJKViJ$4YFzx$eQYEdb(hsnH~C8EegT5jAaYkYlB~0u~TS2 z?|Hy_z_K@F=fM36fxh7iVDeL8j|VN}poT!!)GeSvrwRAj8PMKOn;HGZNo7$f9@#|90? z#4K-=T=SUoM^f7fwXbTGUGtc88GMph`!Z$>qcf+Gn5o75n1S}8+IOdqq#kCXeHk|# z4pyn{5mfH%+a9bETkrfJQ}zX}TOO<`BS7b-cF?inH7~EvY94Tpoi1VnuC+vgQ#ZI< z2>bFP!Mee_g|IJhwTc3ep=fFBgLZ?X>rP?p*Q3BY0zUPaePsm57#7ODz?GJRRcflC zpW)6u*x%!K=o$M0Gm0o^Y{1u^vM=z1XM%d-Z*0JPPuUlkt(_w@B=F61#$F2QbB+HtU`{$^ z=__v6-0i;&_WLRv00000NkvXXu0mjfCZ4h} literal 0 HcmV?d00001 diff --git a/src/Application.bf b/src/Application.bf new file mode 100644 index 0000000..8cc859c --- /dev/null +++ b/src/Application.bf @@ -0,0 +1,111 @@ +namespace TheaterGui; + +using System; +using RaylibBeef; + +class Application +{ + //Letterboxing + private RenderTexture2D _RenderTexture; + private int32[2] _RTPosition = .(0,0); + private int32[2] _RTSize = .(0,0); + private int32[2] _RTOldSize = .(0,0); //How large was the window last time we checked + + public this(StringView pAppTitle, int32 pWidth, int32 pHeight) + { + Raylib.SetConfigFlags((.)(ConfigFlags.FLAG_WINDOW_RESIZABLE | ConfigFlags.FLAG_WINDOW_HIGHDPI)); + Raylib.InitWindow(pWidth, pHeight, scope String(pAppTitle)); + Raylib.SetExitKey(0); + Raylib.SetTargetFPS(40); + + var icon = Raylib.LoadImageFromMemory(".png", (.)&Assets.WindowIcon, Assets.WindowIcon.Count); + Raylib.SetWindowIcon(icon); + Raylib.UnloadImage(icon); + + _RenderTexture = Raylib.LoadRenderTexture(1920, 1080); + } + + ///Window width + public int32 Width + { + get => Raylib.GetRenderWidth(); + set => Raylib.SetWindowSize(value, Raylib.GetRenderHeight()); + } + ///Window height + public int32 Height + { + get => Raylib.GetRenderHeight(); + set => Raylib.SetWindowSize(Raylib.GetRenderWidth(), value); + } + + public Vector2 MousePosition + { + get + { + var mouse = Raylib.GetMousePosition(); + mouse.x -= _RTPosition[0]; + mouse.y -= _RTPosition[1]; + mouse.x = mouse.x / _RTSize[0] * 1920; + mouse.y = mouse.y / _RTSize[1] * 1080; + return mouse; + } + } + + ///Start the application displaying the input screen + public void Start() + { + while(!Raylib.WindowShouldClose()) + { + Raylib.BeginDrawing(); + Raylib.ClearBackground(Raylib.BLACK); + + Raylib.BeginTextureMode(_RenderTexture); //Our render code goes here + Raylib.ClearBackground(Raylib.WHITE); + var mouse = MousePosition; + Raylib.DrawRectangle((.)mouse.x-16,(.)mouse.y-16,32,32,Raylib.PINK); + Raylib.EndTextureMode(); + + Raylib.DrawTexturePro( + _RenderTexture.texture, + .(0, 0, 1920, -1080), + .(_RTPosition[0], _RTPosition[1], _RTSize[0], _RTSize[1]), //Black bars + .(0,0), + 0, + Raylib.WHITE + ); + + Raylib.EndDrawing(); + UpdateLetterboxing(); + } + } + + ///Letterboxing algo from TheaterEngine + private void UpdateLetterboxing() + { + var width = Raylib.GetRenderWidth(); + var height = Raylib.GetRenderHeight(); + + if(!(width == _RTOldSize[0] && height == _RTOldSize[1])) + { //We dont need to update if the window size hasnt changed + float maxWidth = width/16; + float maxHeight = height/9; + + if(maxWidth < maxHeight) + { + _RTPosition[0] = 0; + _RTSize[0] = width; + _RTPosition[1] = (.)((height - maxHeight * 9) / 2); + _RTSize[1] = (.)(height - (height - maxWidth * 9)); + } + else + { + _RTPosition[0] = (.)((width - maxHeight * 16) / 2); + _RTSize[0] = (.)(width - (width - maxHeight * 16)); + _RTPosition[1] = 0; + _RTSize[1] = height; + } + _RTOldSize[0] = width; + _RTOldSize[1] = height; + } + } +} \ No newline at end of file diff --git a/src/Assets.bf b/src/Assets.bf new file mode 100644 index 0000000..4e3ef2a --- /dev/null +++ b/src/Assets.bf @@ -0,0 +1,8 @@ +namespace TheaterGui; + +using System; + +class Assets +{ + public static uint8[?] WindowIcon = Compiler.ReadBinary("assets/64.png"); +} \ No newline at end of file