From 012f86413fbcb85d4b94c1b93fc067752ab7c6d0 Mon Sep 17 00:00:00 2001 From: Booklordofthedings Date: Sun, 2 Jun 2024 17:57:52 +0200 Subject: [PATCH] added most buttons --- assets/32.png~ | Bin 0 -> 559 bytes assets/button.png | Bin 0 -> 534 bytes assets/icon_folder.png | Bin 0 -> 349 bytes assets/icon_theater.png | Bin 0 -> 596 bytes assets/large_button.png | Bin 0 -> 1180 bytes assets/n_button.png | Bin 0 -> 1466 bytes assets/n_button.png~ | Bin 0 -> 1875 bytes assets/npatch.png | Bin 170 -> 0 bytes assets/npatch.png~ | Bin 189 -> 0 bytes assets/square_button.png | Bin 0 -> 673 bytes assets/square_button_hover.png | Bin 0 -> 717 bytes src/App.bf | 168 +++++++++++++++++++++++++ src/Application.bf | 116 ----------------- src/Assets.bf | 11 -- src/Controls/Button.bf | 52 ++++++-- src/Controls/Container.bf | 147 ++++++++++++++++++++++ src/Controls/Control.bf | 18 --- src/Controls/GuiObject.bf | 95 ++++++++++++++ src/Controls/IconButton.bf | 30 +++++ src/Controls/Label.bf | 17 +++ src/Controls/LargeButton.bf | 24 ++++ src/Controls/NButton.bf | 56 +++++++++ src/Controls/Placeholder.bf | 12 ++ src/Controls/Screen.bf | 18 +++ src/Controls/Toolbar.bf | 19 --- src/Extensions.bf | 15 +++ src/Generators/ButtonGenerator.bf | 48 +++++++ src/Generators/ContainerGenerator.bf | 36 ++++++ src/Generators/IconButtonGenerator.bf | 49 ++++++++ src/Generators/LargeButtonGenerator.bf | 48 +++++++ src/Generators/NButtonGenerator.bf | 48 +++++++ src/Generators/ScreenGenerator.bf | 37 ++++++ src/Screen.bf | 44 ------- src/Textures.bf | 31 +++-- src/Theme.bf | 28 ++++- 35 files changed, 941 insertions(+), 226 deletions(-) create mode 100644 assets/32.png~ create mode 100644 assets/button.png create mode 100644 assets/icon_folder.png create mode 100644 assets/icon_theater.png create mode 100644 assets/large_button.png create mode 100644 assets/n_button.png create mode 100644 assets/n_button.png~ delete mode 100644 assets/npatch.png delete mode 100644 assets/npatch.png~ create mode 100644 assets/square_button.png create mode 100644 assets/square_button_hover.png create mode 100644 src/App.bf delete mode 100644 src/Application.bf delete mode 100644 src/Assets.bf create mode 100644 src/Controls/Container.bf delete mode 100644 src/Controls/Control.bf create mode 100644 src/Controls/GuiObject.bf create mode 100644 src/Controls/IconButton.bf create mode 100644 src/Controls/Label.bf create mode 100644 src/Controls/LargeButton.bf create mode 100644 src/Controls/NButton.bf create mode 100644 src/Controls/Placeholder.bf create mode 100644 src/Controls/Screen.bf delete mode 100644 src/Controls/Toolbar.bf create mode 100644 src/Extensions.bf create mode 100644 src/Generators/ButtonGenerator.bf create mode 100644 src/Generators/ContainerGenerator.bf create mode 100644 src/Generators/IconButtonGenerator.bf create mode 100644 src/Generators/LargeButtonGenerator.bf create mode 100644 src/Generators/NButtonGenerator.bf create mode 100644 src/Generators/ScreenGenerator.bf delete mode 100644 src/Screen.bf diff --git a/assets/32.png~ b/assets/32.png~ new file mode 100644 index 0000000000000000000000000000000000000000..cf80bc89f052836ac49858f64bdec13c5bf0159e GIT binary patch literal 559 zcmV+~0?_@5P)>-~c0FC;$r1OATxpw{B=D58iL6hXlk zUj*?%&?;(LC=@|NAN&EwM6!@DTh>;Y%sHy%-pTFNtI6bLp6 z=HOx0h4KIU=eS6+Ce~tBfuP}Fj-Db(@QBl7m7!;yJxxQ8tj*DZiQK=P#VUYsZLS8k zQudrRvS?cDrRy9DqgH)n-L}{poH}ZOtE*bCnKyAt-f;v@(o)t25lng$I3XNC)_@W| zuVmg6!`^0yg4)m$*5>+^VQ+AhIzr?ECG21?!r;9+LK8i^kZDsWzrmrv5s+2D*S#Xb zc4bsB@wB9S-4l(6!-1uOOJUXp?R3NG`vrhenC%01@s?W#`-~&J3Uo@chcbO2!A(i_ z274Yy6cjMs>m9~mkWkV-V9u{`cAyFD5_^PpS>ppnp$fRH=&XS&oU0^(9fu0K@zx5n z1D_SKCmLSyo$#U}_6FOQ3P}R3daA-#?lYk}q~8+CZqdPVxDvr|pjOp)!3C}7=r$Zi x@Z{$QM)JGi5R%9#evI>Mn;ys`i3xc(+&{=zbju$YdN}|9002ovPDHLkV1l`k{T~1T literal 0 HcmV?d00001 diff --git a/assets/button.png b/assets/button.png new file mode 100644 index 0000000000000000000000000000000000000000..df52cd4a251f893bf56252332cfdc2364eb3e986 GIT binary patch literal 534 zcmV+x0_pvUP)6DmUs?m@+la5N#BcfWYrX z5(^rE{{3u|$g*P-87u~4rVa1FkK>pL@vnj9^Lo5}SG8~Z>iAt9W7}@q?`*!*zUZt| zXaDZ_yQX_}lZobuBZ*EhuHLQp1xyXr^Hv8t+F%sCZ&5(&gfmDdeL->ZIi z&tYReCU$jPoAaU8+4ueKvMvii%=7GQf+m4C30f$EvbheEcx^?%<={UdTWx36-EnQN z`3c1Ay6#T|+-D{M|L*XwGA^SZ_>UX^vbAmd?#7>rH{f45nGg4sNx;8<{O<$+{QDQU zYe8|~KOLG;eL3)-CjQrU{sjEHteSy;VO|5c%vRvv?X4#V{?o-jSp)+A>EK_h1_1u! z#lP|r0Q{$cf9)Co_>U9+r!@fZA2e|QKP7(%v&i2uVH0Qip||A*fM z0{`*je-!}B^Bnk34F65jEN_ha#vAbO_ityb04`Gi_zw^NYxZwz09F(Q@Ey_k%FJG~V@ zkuco@>Lq>*>isZ`YHSVl#m7)X zz1BDfj>>PYdbkB+Ons^luAyG@flAJRYT5zni=}uh!GVXcgnIPj6^g0Wf#93~)Mrn@ v7}QtkKn%Q!p+HQy1sb`{QU5dl1G7B=->TJ?JKQp-00000NkvXXu0mjfXRMYg literal 0 HcmV?d00001 diff --git a/assets/icon_theater.png b/assets/icon_theater.png new file mode 100644 index 0000000000000000000000000000000000000000..f597c9c708bf13d9b642750dde123d55a37211c6 GIT binary patch literal 596 zcmV-a0;~OrP)sLI%>wJZ_uD1A%5TlY7tUJ$Et;^vJBt&lbP} z1QM8T4O0bPwFD*xRVE^@<#O;fCphynQ(Yk4pJNJ4^CgBTKT8CI=QPZ9l9h23ew`6! zQHvRdgaVm$4RbIsdxb&o`6;HgtTk&fs6ZyKV2*|&adC$u+A2fCI(Zt04q1z<4nu8k zJ8@J1;@Y+v*znogtPw;-VozPCP#8JuBI}yOUf@_!3%0sSbeeeuhv^-M;3Q6EEl`D| zF@YnEBeXTZi2s*6@7}^*W{8B^;1t&4{>j2#;J|kT$pwtq!5)dhJ9Pxt^z2Zk6{7qC z`vgZoPyti-s%mT(MFkO$Q@Yo!rt#RYC#j%P*y@6szu|QK0bo(s+6PL`mKz1T7DpHr zs7GWEQTl+3>xk?Hb_|XPDImI60|ua%VAMV!eqZ5OPZQYI>=9gLjW_6rIH0nkvIZ`3 zJeCBu6e{ri^Gh~3@E#L;O~VU+6Q0GyUSLyF!A+o;^HpfJ9TVb%f0kfw%szjtbn)40 zex+uX|097iB-tYShF}6-5+AKbb22>@cM_f%rrD44g@K{7Vez4Qla0ClJRIVLwM}Oh i=9UUkqdJ6)8}1(~c6@R~R+wD?0000g2E literal 0 HcmV?d00001 diff --git a/assets/large_button.png b/assets/large_button.png new file mode 100644 index 0000000000000000000000000000000000000000..71f13a7b73cd7b67f0aaa238c69f136301ddc07a GIT binary patch literal 1180 zcmV;N1Y`S&P)XPd(0l3sWq_oAe zAs&y%AIwu9{Ex?DoDWSjXz8((x>L@}y?#zRQwDuan{s}$rvB9aNsf6=NvV72H`nX+ zht|^+_@%+bH2~6vC^bn|okQ+?ap52r;3>!YM$j3+>-l`L4@l|Ga`r>AogSi}b~`y8 zWWQW4myZz;rzeyKcur?IL7^S$Ym9!HG_*5-xA&LkdR&94ZHQ99)i63P8mjFaGz_te z0#sYlr5UnIM?cWe`D0{(lX_4;5dC7(P%7a~pnmv@evxS?X(nAzKcM|vqoHIW(S`b9 zkA_M{KT9-}kaYP=enCU|>L*J{7qovHG_-W|(=xK0EZ;Ol>3|7)DKN*R5JQ`p`o)fDAW($`YkN`w&olx(9kaf@Sy!mgTk}+ z4;soKgJR{Q-{@zBb9V~j!|iVTT?&A zfLhab?=?MuL)-%Z^#jk^dZD3T1`vIpO-%sQru|!`p()rTsR@uA5YOs|rgN~W{cF-t zvDKhh`RFUumvj!6Z^DrUfJak5BzZY#D6b)sgg1fuVZ%9aa_&epbWsj~m5=;f)}tXt zeE^3_SaW3c!)x@5MnhBUCM{6Zu71>}{adA>St^i4^}|}yh3(#bK7d194c1ma#?HaZ z?tE(h+&EYi0ib^PihdrXQ7?u_9szDq{m_hlprL$*NI8=iN&A-uMf6v_dZD3X^@wkc z2<_i*^z%eRbB~c0z$2?4h<-L`XwDdrBq;E*ySnz-v`Ry#Xc}=;VqN{vqCebp05nwo zE;FqiY!B)OwEy@tG#7VbTO&qSKk%$=jGJ)Ti{YSt_=tYdY3N!*Yz?5T9E+9COzhK(pKJpne#Sejc`aFKvh^^>*IBp96f1 zpa%8BqS4`Hck&P5{009|65QifY>W_4W09 zD_Q|>B|ZdyHtU_fQ-Bxvr9&r#KqK>zcRlFVcS!F%TLV7I_&hQX+0)iV51RpVm&89vh$E0y|8G5k2)_b_LTIl8ZA5GWc0i5pr8$En(48QN*;l*#l%2 zWO@WNL)vt=ghlWMWL@B5a~Q}<-FQBR+6UU)5*96>nSBh49w4(I(=(t*ZQXkBl{Rc1AJEM#xRBy&jhkkH?N7M%Njuuz>iX_X+6r3y-zywJa;7U zz1mc)1&rnm7y7&8C39*(`M5|Py~f5Vx_LDC5)?hk85Iqw}e@= zY2*biAT42*0UdpT3m8k72M-y2=aZsgAetcK1%5OiLn#k&vxIpDlslg|S;7#^7FkU! zt=BTMgdq%jviTVHg1_hiGALa1F@RXYkOImDE{wK~iva#8K8DisyQ~q!V$GOovsw#? zTB*x54mxid#Y){A;8$q@tklhE4B4Csj1o{TaG|_u6f1Rg1Q{4hSagwttD7hrLRhJr zlZQz3fM%-H^+=m=max$T8E+mUXaVJlt>uw37AcMn0N*+Sd3Md5`-&9n3{%$RR zf=pcS7dHSab>s7p+ViDnKq<)h@{pDXSx~y8(YK=aigVMZQ50nQrcE#KUycH}t!gYD zviJP1yN6SdvE?B>&KGp>$wTzWXR#d2Ie9D|(sL3_Py2^4YyGWOPAB6MT(c|NQ)XV*XnUnm#^0D9AX^&0B)M zPy-(yoX=+pGESAc*5EJR{5=2h<9fY@5oFL)k>@1XKf?DC@9FUVm=8QM9IH700SICP U-=1=<3IG5A07*qoM6N<$g2!O4LI3~& literal 0 HcmV?d00001 diff --git a/assets/n_button.png~ b/assets/n_button.png~ new file mode 100644 index 0000000000000000000000000000000000000000..46d1105384f095a8bfd24a593c6d37c686a72785 GIT binary patch literal 1875 zcmV-Z2dwysP)058&~uW~Xur_5zwW=5dfeRH zM0tm1a)#_%Z{I5pi+!{@j$j_nZZ^?JYQIEH<0 z_!83%2YjmQF0o%?$M@~(LjE=99n1xva=Nhw|Cn=6Zh#u|8YO&cYnjT{;b>Ee(Xd~4 z9KEY0_%&h&62|vn1gHf+bZ#p6r@Bg(;pdz?I0Z<|Gj^aIe(E(>5(u#jUm{Oo1%A>Eq;_XohfnR_OWR+rmQj-f zpVLp)5ICv{e_{k`gkRfL;tU)~dIH5pAmH=H4kW|Lv2#X^K+W(qdzQ0KJ~>4nYNf)(8ZAeI0@dKD#^|dOiK{gCjsou97vq z9yR=8H?SpF$$Akg1^k@rCY6UnuV)K>mK$gpzSTNJF8HD2NaW$r>)C+MA`gdNkG?}l zz|VFATY_&Pb`UGy<{EL5ZlD%FnKPWM9X|JT<1D*Mt?Bh@*cy)0Rf1lR9zLb55uE}o z`N>OzUrinky`GF-PZIuQ3gC8?px2{^f2ytHa!&%io=*6u+FwozKJyd168sAxgAWrz4 zxdf@$fkybH9U?jcaKndWt4@JyG7uyY#RB|#1+JleopbRU0D3+9@N+uEAQD&$KJp7^_B(S z|DMjj8z9-zq1Th>5NBs+>0AKd+sIR#dTr+ZF@(cf)}+^yf*@6*t}QtNP`WeF>*@F- zjo9`3H$ZoNeXTkbx)i;h zOd^U!3HFqTU%{`6lZ})WHAE+e$8iM;|78k~2)aXv2w^wP*=gTy8I<_8pJUqiXK|H6f=d9<9tKZW KKbLh*2~7ZL6*hGM diff --git a/assets/npatch.png~ b/assets/npatch.png~ deleted file mode 100644 index 1cff33eb0218e3c5c44194c4d73a1a5748b2d5a0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 189 zcmeAS@N?(olHy`uVBq!ia0vp^>Od^U!3HFqTU%{`6lZ})WHAE+eZt1gO7oxa)ZQQ}Y6m_m^aZK0H|2-!)-M!{on9x0)?> zOe^!5-`>e_=+H8Dy@>abXEujwM$0>^%ce-@dI_ETe<8ZJH(%A&m}_^4MZkZADC@b74D% zDWU`*HrrjE?Gym4&S4uJw50KKlbBEh zxHLhkY)7dBe6T$>?u_aH4s3@EvqJ!U8eIxvwI&#A-X4#q;&vy++EfIcfj3c z9dI`SoQA+1#LD_7?o0rqI)IBtO^a`DOd|758LL(aU{=nlV^8b_tt*eIQe?Lk|h8}pg+aS0?4yDc?RCLIm{*B}d00000NkvXX Hu0mjfDVZi1 literal 0 HcmV?d00001 diff --git a/assets/square_button_hover.png b/assets/square_button_hover.png new file mode 100644 index 0000000000000000000000000000000000000000..8a585b5faa0666df52166d046724a337133edf66 GIT binary patch literal 717 zcmV;;0y6!HP){{-g z)9Li1xvNEdiZLnAJD<;Ay1NqMr9CSxb@X|c%jKiJvlcJuSxK+Y^*(C!^?DujlV$WS zEqNs9QjPAcdLQjst)N4Ux!rCnsR&nL;^&E;rkeOrer&w=x=@47J8~Y2`%?$T5krSP4cmCHN6&f$fMfq}>zRL1&Fo zYK`qk<%vSjBioTS5I0Kl%66oEq+RkgupKdmQX6Bz_S~7mhM-rrBkhZ3K&eLM$dvc- zd_Kb&P#fDV2=Epk#GrS!bN7ygi^c(^Co!4?7>f^vU`uT0dVO{rkb~{knIaL-t_OH$ zd#vQ6@>2n=upQnc6}utVW<~3u<37IB8rv6bk}9!T(K_h3c1AP6 zJKH6s60Hf=9&{-sKmA|S8ru=07mWjIWqZ<^V6M%Invpt00000NkvXXu0mjfQRP{! literal 0 HcmV?d00001 diff --git a/src/App.bf b/src/App.bf new file mode 100644 index 0000000..e47a6b9 --- /dev/null +++ b/src/App.bf @@ -0,0 +1,168 @@ +namespace TheaterGui; +using TheaterGui.Controls; + +using System; +using RaylibBeef; + +class App +{ + ///Initialize the TheaterGui app + public static void Initialize(StringView pAppTitle = "TheaterApp") + { + Raylib.SetConfigFlags((.)(ConfigFlags.FLAG_WINDOW_RESIZABLE | ConfigFlags.FLAG_WINDOW_HIGHDPI)); + Raylib.InitWindow(1280, 720, scope String(pAppTitle)); + Raylib.SetExitKey(0); + Raylib.SetTargetFPS(40); + Raylib.SetWindowMinSize(640,360); + + ///Set the default window icon + var icon = Raylib.LoadImageFromMemory(".png", (.)&Theme.Texture_WindowIcon, Theme.Texture_WindowIcon.Count); + Raylib.SetWindowIcon(icon); + Raylib.UnloadImage(icon); + + //Load textures + Textures = new .(); + Theme.Font = Raylib.LoadFontFromMemory(".ttf", (.)&Theme.Din, Theme.Din.Count, 16, null, 256); + } + + ///Deinitialize the TheaterGui app + public static void Deinitialize() + { + + } + + ///Start the application on the input stream + public static void Start(Screen pScreen) + { + Vector2 oldSize = .(0,0); + //For hover items + Vector2 oldPos = .(0,0); + double movTime = 0; + String hoverText = scope .(); + + CurrentScreen = pScreen; + while(!Raylib.WindowShouldClose()) + { + if(oldSize != .(Width,Height)) + { + CurrentScreen.Reorder(Width); + oldSize = .(Width,Height); + } + + //This could probably be solved better + + if(CurrentScreen.Height - Height > 0) + { + Wheel = -Wheel; + Wheel += 7 * Raylib.GetMouseWheelMove(); + Wheel = Math.Clamp(Wheel, -1*(CurrentScreen.Height - Height), 0); + Wheel = -Wheel; + } + + if(Raylib.IsMouseButtonPressed(0)) + { + CurrentScreen.OnClick(Raylib.GetMouseX(), (.)(Raylib.GetMouseY()+App.Wheel)); + + } + else + { + var hov = CurrentScreen.OnHover(Raylib.GetMouseX(), (.)(Raylib.GetMouseY()+App.Wheel)); + if(hov != null) + { + if(hov.Enabled) + Raylib.SetMouseCursor((.)MouseCursor.MOUSE_CURSOR_POINTING_HAND); + //TODO: If we go offscreen with the mouse it doesnt work anymore + if(oldPos != Mouse) + movTime = Raylib.GetTime(); + if(Raylib.GetTime() - movTime >= 0.5) + hoverText.Append(hov.Description); + oldPos = Mouse; + } + else + Raylib.SetMouseCursor((.)MouseCursor.MOUSE_CURSOR_DEFAULT); + } + + //Drawing logic + Raylib.BeginDrawing(); + Raylib.ClearBackground(Theme.Background); + CurrentScreen.Render(); + + if(hoverText != String.Empty) + { + int32 yOffset = 0; + int32 xOffset = 0; + //TODO: Curently just goes offscreen when it doesnt work + var measure = Raylib.MeasureTextEx(Theme.Font, hoverText, Theme.FontSize, 0); + if(Raylib.GetMouseX() < Width/2) + xOffset = 15; + else + xOffset = (.)(-1 * measure.x)-15; + if(Raylib.GetMouseY() < Height/2) + yOffset = 0; + else + yOffset = (.)(-1 * measure.y); + Raylib.DrawRectangle((.)Mouse.x-3+xOffset+3, (.)Mouse.y-3+yOffset+3, (.)measure.x+6, (.)measure.y+3, .(0, 0, 0, 70)); + Raylib.DrawRectangle((.)Mouse.x-3+xOffset, (.)Mouse.y-3+yOffset, (.)measure.x+6, (.)measure.y+3, .(218, 211, 176, 255)); + Raylib.DrawRectangleLines((.)Mouse.x-3+xOffset, (.)Mouse.y-3+yOffset, (.)measure.x+6, (.)measure.y+3, Raylib.BLACK); + Raylib.DrawTextEx(Theme.Font, hoverText, Raymath.Vector2Add(Mouse, .(xOffset,yOffset)), Theme.FontSize, 0, Raylib.BLACK); + } + + Raylib.EndDrawing(); + + if(hoverText != String.Empty) + hoverText.Clear(); + } + } + + // + ///Platform + // + + //All loaded textures + public static Textures Textures ~ delete _; + + private static Screen _CurrentScreen = null; + public static Screen CurrentScreen + { + get => _CurrentScreen; + set + { + if(_CurrentScreen != null) + delete _CurrentScreen; + _CurrentScreen = value; + } + }; + ///Window width + public static int32 Width + { + get => Raylib.GetRenderWidth(); + set => Raylib.SetWindowSize(value, Raylib.GetRenderHeight()); + } + ///Window height + public static int32 Height + { + get => Raylib.GetRenderHeight(); + set => Raylib.SetWindowSize(Raylib.GetRenderWidth(), value); + } + ///Mouse position + public static Vector2 Mouse + { + get => Raylib.GetMousePosition(); + } + //Mouse wheel offset + public static float Wheel + { + get; + set; + } + public static GuiObject Selected + { + get; + set; + } + + public static void ForceReorder() + { + CurrentScreen.Reorder(Width); + } +} \ No newline at end of file diff --git a/src/Application.bf b/src/Application.bf deleted file mode 100644 index 96b37ef..0000000 --- a/src/Application.bf +++ /dev/null @@ -1,116 +0,0 @@ -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); - Textures = new .(); - Theme.Font = Raylib.LoadFontFromMemory(".ttf", (.)&Assets.Din, Assets.Din.Count, 16, null, 256); - } - - ///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; - } - } - - public Textures Textures ~ delete _; - public Screen CurrentScreen; - - ///Start the application displaying the input screen - public void Start(Screen pScreen) - { - pScreen.Parent = this; - CurrentScreen = pScreen; - - while(!Raylib.WindowShouldClose()) - { - Raylib.BeginDrawing(); - Raylib.ClearBackground(Raylib.BLACK); - - Raylib.BeginTextureMode(_RenderTexture); //Our render code goes here - Raylib.ClearBackground(Theme.BackgroundDark); - CurrentScreen.Render(); - 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 - maxWidth * 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 deleted file mode 100644 index 54dd5cc..0000000 --- a/src/Assets.bf +++ /dev/null @@ -1,11 +0,0 @@ -namespace TheaterGui; - -using System; - -class Assets -{ - public static uint8[?] WindowIcon = Compiler.ReadBinary("assets/64.png"); - public static uint8[?] NPatch = Compiler.ReadBinary("assets/npatch.png"); - public static uint8[?] Din = Compiler.ReadBinary("assets/din.ttf"); - -} \ No newline at end of file diff --git a/src/Controls/Button.bf b/src/Controls/Button.bf index d6339a3..d43a7c5 100644 --- a/src/Controls/Button.bf +++ b/src/Controls/Button.bf @@ -1,19 +1,57 @@ namespace TheaterGui.Controls; +using System; using RaylibBeef; -class Button : Control +abstract class Button : GuiObject { - public this() + public sprite Sprite; + + public this(StringView pName, StringView pComponentName = "Button") : base(pComponentName, pName) { - BoundingBox = .(0, 0, 400, 200); + Sprite = App.Textures.GetAsset("button"); + Label.Append(pName); + Width = Sprite.Width; + Height = Sprite.Height; + } + + protected bool _IsHovered = false; + public override GuiObject OnHover(int32 x, int32 y) + { + _IsHovered = true; + return this; + } + + public override bool OnClick(int32 x, int32 y) + { + if(Rectangle(X, Y, Width, Height).Overlaps(x, y)) + { + if(Enabled) + { + ClickAction(); + return true; + } + return false; + } + return false; } public override void Render() { - var s = Parent.Parent.Textures.GetAsset("npatch").Value; - NPatchInfo patchInfo = .(s.SourceRect,3,3,3,3,(.)NPatchLayout.NPATCH_NINE_PATCH); - Raylib.DrawTextureNPatch(*s.Source, patchInfo,.(BoundingBox.x,BoundingBox.y,400,200),.(0,0),0,Theme.Main); - Raylib.DrawTextEx(Theme.Font, "Button", .(BoundingBox.x + 3, BoundingBox.y + 4), 16, 0, Theme.Text); + Sprite.Render(X,Y, Tint); + var measure = Raylib.MeasureTextEx(Theme.Font, Label, Theme.FontSize, 0); + Raylib.DrawTextEx(Theme.Font, Label, .(X+Width/2-measure.x/2,Y+Height/2-measure.y/2), Theme.FontSize, 0, Theme.Text); + if(!Enabled) + { + Sprite.Render(X,Y, Theme.DisabledTint); + } + else + { + if(_IsHovered) + Sprite.Render(X,Y, HoverTint); + } + _IsHovered = false; } + + public abstract void ClickAction(); } \ No newline at end of file diff --git a/src/Controls/Container.bf b/src/Controls/Container.bf new file mode 100644 index 0000000..b33a03a --- /dev/null +++ b/src/Controls/Container.bf @@ -0,0 +1,147 @@ +namespace TheaterGui.Controls; + +using System; +using System.Collections; + +class Container : GuiObject +{ + private List _LayoutData = new .() ~ delete _; + public List Children = new .() ~ DeleteContainerAndItems!(_); //Entries => LayoutData without nulls + + public this(StringView pName, StringView pComponentName = "Container") : base(pName, pComponentName) + { + + } + + ///Reorder all entries + /// @params w The Maximum width that the container should take + public virtual void Reorder(int32 w) + { + /* + List {Entry, Entry, Entry, RB, Entry, Entry, RB, Entry, RB} + null is a rowbreak while non null isnt a rowbreak + + Algorithm + if the current entry is a rowbreak, reset the cursor to x = 0, y = y + height + + try to fit the current entry after the cursor + if it fits add it, + if it doesnt fit break + */ + + int32 maxWidth = 0; //The highest width line + int32 rowHeight = 0; //How high the current row is + int32 x = 0; + int32 y = 0; + + for(var e in _LayoutData) + { + if(e == null) + { //Manual row break + x = 0; + y = y + rowHeight; + rowHeight = 0; + continue; + } + + if(e is Container) + { + ((Container)e).Reorder(w); + for(var i in ((Container)e).Children) + { + i.X += x + Padding + e.Padding; + i.Y += y + Padding + e.Padding; + } + } + + if(x+e.Width+e.Padding > w-Padding) //Change both instances of padding to 2*Padding to ensure proper padding on the leftmost side of the screen + { //Automatic row break + x = 0; + y = y + rowHeight; + rowHeight = 0; + } + + e.X = x + e.Padding; + x = x + e.Width + 2*e.Padding; + e.Y = y + e.Padding; + if(x > maxWidth) + maxWidth = x; + + if(rowHeight < e.Height+2*e.Padding) + rowHeight = e.Height+2*e.Padding; + } + + Width = maxWidth + 2*Padding; + Height = y + rowHeight + 2*Padding; + } + + ///Add a new item to the list of items + public void AddChild(GuiObject pToAdd) + { + _LayoutData.Add(pToAdd); + Children.Add(pToAdd); + pToAdd.Parent = this; + } + + public virtual void InsertBefore(GuiObject pToAdd, GuiObject Position, bool pReorder = true) + { + var idx = _LayoutData.IndexOf(Position); + if(idx < 0) + { + delete pToAdd; //Avoid memory leaks + return; + } + _LayoutData.Insert(idx, pToAdd); + Children.Add(pToAdd); + pToAdd.Parent = this; + + if(pReorder) + App.ForceReorder(); + } + + public virtual void InsertAfter(GuiObject pToAdd, GuiObject Position, bool pReorder = true) + { + var idx = _LayoutData.IndexOf(Position); + idx++; + if(idx < 0) + { + delete pToAdd; //Avoid memory leaks + return; + } + _LayoutData.Insert(idx, pToAdd); + Children.Add(pToAdd); + pToAdd.Parent = this; + + if(pReorder) + App.ForceReorder(); + } + + ///Forcefully terminates the current row + public void EndRow() => _LayoutData.Add(null); + + public override void Render() + { + for(var i in Children) + i.Render(); + } + + public override bool OnClick(int32 x, int32 y) + { + for(var e in Children) + { + if(RaylibBeef.Rectangle(e.X, e.Y, e.Width, e.Height).Overlaps(x, y)) + return e.OnClick(x, y); + } + return false; + } + + public override GuiObject OnHover(int32 x, int32 y) + { + for(var e in Children) + { + if(RaylibBeef.Rectangle(e.X, e.Y, e.Width, e.Height).Overlaps(x, y)) + return e.OnHover(x, y); + } + return null; + } +} \ No newline at end of file diff --git a/src/Controls/Control.bf b/src/Controls/Control.bf deleted file mode 100644 index 8e29101..0000000 --- a/src/Controls/Control.bf +++ /dev/null @@ -1,18 +0,0 @@ -namespace TheaterGui.Controls; - -using RaylibBeef; - -//The base class for every control object -abstract class Control -{ - public Rectangle BoundingBox = .(0,0,0,0); - public Screen Parent; - - public abstract void Render(); - - /* - Reacting to clicks - Reacting to hover - While selected - */ -} \ No newline at end of file diff --git a/src/Controls/GuiObject.bf b/src/Controls/GuiObject.bf new file mode 100644 index 0000000..c86ae71 --- /dev/null +++ b/src/Controls/GuiObject.bf @@ -0,0 +1,95 @@ +namespace TheaterGui.Controls; + +using System; +using System.Collections; +using RaylibBeef; + +abstract class GuiObject +{ + public String ComponentName = new .() ~ delete _; + public String Name = new .() ~ delete _; + public String Label = new .() ~ delete _; + public String Description = new .() ~ delete _; + public Color Tint = Theme.Tint; + public Color HoverTint = Theme.HoverTint; + public bool Enabled = true; + + public this(StringView pComponentName, StringView pName) + { + ComponentName.Append(pComponentName); + Name.Append(pName); + } + + private Container _Parent = null; + public Container Parent + { + get => _Parent; + set + { + OnParentChange(value); + _Parent = value; + } + }; + public int32 Padding + { + get; + set; + } = 0; + public int32 X + { + get; + set; + } = 0; + public int32 Y + { + get; + set; + } = 0; + public int32 Width + { + public get; + protected set; + }; + public int32 Height + { + public get; + protected set; + }; + public bool Selected + { + get; + set + { + Selected = value; + App.Selected = this; + } + } + public Vector2 SizeOf() + { + return .(Width + 2*Padding, Height + 2*Padding); + } + + ///Returns true if the onclick has been handled + public virtual bool OnClick(int32 x, int32 y) + { + return false; + } + + public abstract GuiObject OnHover(int32 x, int32 y); + + //Called every frame if the object is selected + public virtual void WhileSelected() + { + + } + + public virtual void OnParentChange(Container pNewParent) + { + + } + + public virtual void Render() + { + + } +} \ No newline at end of file diff --git a/src/Controls/IconButton.bf b/src/Controls/IconButton.bf new file mode 100644 index 0000000..161b6a9 --- /dev/null +++ b/src/Controls/IconButton.bf @@ -0,0 +1,30 @@ +namespace TheaterGui.Controls; + +using System; + +abstract class IconButton : Button +{ + public sprite Icon = App.Textures.GetAsset("folder_icon"); + + + public this(StringView pName) : base(pName, "SquareButton") + { + Sprite = App.Textures.GetAsset("square_button"); + Width = Sprite.Width; + Height = Sprite.Height; + } + + + + public override void Render() + { + + Sprite.Render(X,Y, Tint); + Icon.Render(X+Width/2-Icon.Width/2+2,Y+Height/2-Icon.Height/2+2, .(0,0,0,125)); + Icon.Render(X+Width/2-Icon.Width/2,Y+Height/2-Icon.Height/2); + if(_IsHovered) + Sprite.Render(X,Y, HoverTint); + _IsHovered = false; + + } +} \ No newline at end of file diff --git a/src/Controls/Label.bf b/src/Controls/Label.bf new file mode 100644 index 0000000..5070586 --- /dev/null +++ b/src/Controls/Label.bf @@ -0,0 +1,17 @@ +namespace TheaterGui.Controls; + +using System; +using RaylibBeef; + +class Label : GuiObject +{ + public this(StringView pName) : base(Label, pName) + { + Label.Append(pName); + } + + public override GuiObject OnHover(int32 x, int32 y) + { + return this; + } +} \ No newline at end of file diff --git a/src/Controls/LargeButton.bf b/src/Controls/LargeButton.bf new file mode 100644 index 0000000..0180936 --- /dev/null +++ b/src/Controls/LargeButton.bf @@ -0,0 +1,24 @@ +namespace TheaterGui.Controls; + +using System; +using RaylibBeef; + +abstract class LargeButton : Button +{ + public this(StringView pName) : base(pName, "LargeButton") + { + Sprite = App.Textures.GetAsset("large_button"); + Width = Sprite.Width; + Height = Sprite.Height; + } + + public override void Render() + { + Sprite.Render(X,Y, Tint); + var measure = Raylib.MeasureTextEx(Theme.Font, Label, Theme.FontSize, 0); + Raylib.DrawTextEx(Theme.Font, Label, .(X+Width/2-measure.x/2,Y+Height/2-measure.y/2), Theme.FontSize, 0, Theme.Text); + if(_IsHovered) + Sprite.Render(X,Y, HoverTint); + _IsHovered = false; + } +} \ No newline at end of file diff --git a/src/Controls/NButton.bf b/src/Controls/NButton.bf new file mode 100644 index 0000000..d838cc0 --- /dev/null +++ b/src/Controls/NButton.bf @@ -0,0 +1,56 @@ +namespace TheaterGui.Controls; + +using System; +using RaylibBeef; + +abstract class NButton : Button +{ + public NPatchInfo PatchInfo; + + public this(int32 w, int32 h, StringView pName) : base(pName, "NButton") + { + Sprite = App.Textures.GetAsset("n_button"); + Width = w; + Height = h; + + PatchInfo =.(Sprite.SourceRect, 7,7,7,7,(.)NPatchLayout.NPATCH_NINE_PATCH); + + } + + public override void Render() + { + Raylib.DrawTextureNPatch( + *Sprite.Source, + PatchInfo, + .(X, Y, Width, Height), + .(0,0), + 0, + Tint); + + var measure = Raylib.MeasureTextEx(Theme.Font, Label, Theme.FontSize, 0); + Raylib.DrawTextEx(Theme.Font, Label, .(X+Width/2-measure.x/2,Y+Height/2-measure.y/2), Theme.FontSize, 0, Theme.Text); + + if(!Enabled) + { + Raylib.DrawTextureNPatch( + *Sprite.Source, + PatchInfo, + .(X, Y, Width, Height), + .(0,0), + 0, + Theme.DisabledTint); + } + else + { + if(_IsHovered) + Raylib.DrawTextureNPatch( + *Sprite.Source, + PatchInfo, + .(X, Y, Width, Height), + .(0,0), + 0, + HoverTint); + } + _IsHovered = false; + } +} \ No newline at end of file diff --git a/src/Controls/Placeholder.bf b/src/Controls/Placeholder.bf new file mode 100644 index 0000000..4d1525d --- /dev/null +++ b/src/Controls/Placeholder.bf @@ -0,0 +1,12 @@ +namespace TheaterGui.Controls; + +class Placeholder : GuiObject +{ + public this(int32 w, int32 h) : base("Placeholder", "Placeholder") + { + Width = w; + Height = h; + } + + public override GuiObject OnHover(int32 x, int32 y) => null; +} \ No newline at end of file diff --git a/src/Controls/Screen.bf b/src/Controls/Screen.bf new file mode 100644 index 0000000..a28442e --- /dev/null +++ b/src/Controls/Screen.bf @@ -0,0 +1,18 @@ +namespace TheaterGui.Controls; +using TheaterGui; + +using System; +using System.Collections; +using RaylibBeef; + +/* + While containers are sized depending on their parent, screens are sized depending on the user +*/ +class Screen : Container +{ + public this(StringView pName) : base(pName, "Screen") + { + this.Width = Raylib.GetRenderWidth(); + this.Height = Raylib.GetRenderHeight(); + } +} \ No newline at end of file diff --git a/src/Controls/Toolbar.bf b/src/Controls/Toolbar.bf deleted file mode 100644 index 484ed93..0000000 --- a/src/Controls/Toolbar.bf +++ /dev/null @@ -1,19 +0,0 @@ -namespace TheaterGui.Controls; - -using RaylibBeef; - -class Toolbar : Control -{ - public this() - { - BoundingBox = .(0,0, 1920, 20); - } - - public override void Render() - { - var s = Parent.Parent.Textures.GetAsset("npatch").Value; - NPatchInfo patchInfo = .(s.SourceRect,3,3,3,3,(.)NPatchLayout.NPATCH_NINE_PATCH); - Raylib.DrawTextureNPatch(*s.Source, patchInfo,.(BoundingBox.x,BoundingBox.y,1920,20),.(0,0),0,Theme.Main); - Raylib.DrawTextEx(Theme.Font, "File", .(BoundingBox.x + 3, BoundingBox.y + 4), 16, 0, Theme.Text); - } -} \ No newline at end of file diff --git a/src/Extensions.bf b/src/Extensions.bf new file mode 100644 index 0000000..eae7eea --- /dev/null +++ b/src/Extensions.bf @@ -0,0 +1,15 @@ +namespace TheaterGui; + +namespace RaylibBeef +{ + extension Rectangle + { + public bool Overlaps(int32 x, int32 y) + { + if(x >= this.x && x <= this.x + this.width) + if(y >= this.y && y <= this.y + this.height) + return true; + return false; + } + } +} \ No newline at end of file diff --git a/src/Generators/ButtonGenerator.bf b/src/Generators/ButtonGenerator.bf new file mode 100644 index 0000000..61562e1 --- /dev/null +++ b/src/Generators/ButtonGenerator.bf @@ -0,0 +1,48 @@ +namespace TheaterGui.Generators; + +using System; + +class ButtonGenerator : Compiler.Generator +{ + public override String Name => "TheaterGui -> Generate Button" + + public override void InitUI() + { + AddEdit("name", "Button Name", ""); + AddCheckbox("enabled", "Enabled", true); + AddEdit("description", "Description", ""); + } + + public override void Generate(String outFileName, String outText, ref Flags generateFlags) + { + var name = mParams["name"]; + if (name.EndsWith(".bf", .OrdinalIgnoreCase)) + name.RemoveFromEnd(3); + + var enabled = bool.Parse(mParams["enabled"]); + var description = mParams["description"]; + + outFileName.Append(scope $"TG{name}"); + + outText.Append(scope $""" + namespace {Namespace}; + + using TheaterGui.Controls; + + class TG{name} : Button + {{ + public this() : base("{name}") + {{ + {!enabled ? "Enabled = false;" : ""} + Description.Append("{description}"); + }} + + //What happens when the button is clicked + public override void ClickAction() + {{ + + }} + }} + """); + } +} \ No newline at end of file diff --git a/src/Generators/ContainerGenerator.bf b/src/Generators/ContainerGenerator.bf new file mode 100644 index 0000000..00b24b2 --- /dev/null +++ b/src/Generators/ContainerGenerator.bf @@ -0,0 +1,36 @@ +namespace TheaterGui.Generators; + +using System; + +class ContainerGenerator : Compiler.Generator +{ + public override String Name => "TheaterGui -> Generate Container" + + public override void InitUI() + { + AddEdit("name", "Container Name", ""); + } + + public override void Generate(String outFileName, String outText, ref Flags generateFlags) + { + var name = mParams["name"]; + if (name.EndsWith(".bf", .OrdinalIgnoreCase)) + name.RemoveFromEnd(3); + + outFileName.Append(scope $"TG{name}"); + + outText.Append(scope $""" + namespace {Namespace}; + + using TheaterGui.Controls; + + class TG{name} : Screen + {{ + public this() : base("{name}") + {{ + //Add ui items here via AddChild() and terminate the row via EndRow() + }} + }} + """); + } +} \ No newline at end of file diff --git a/src/Generators/IconButtonGenerator.bf b/src/Generators/IconButtonGenerator.bf new file mode 100644 index 0000000..924a9bb --- /dev/null +++ b/src/Generators/IconButtonGenerator.bf @@ -0,0 +1,49 @@ +namespace TheaterGui.Generators; + +using System; + +class IconButtonGenerator : Compiler.Generator +{ + public override String Name => "TheaterGui -> Generate Icon Button" + + public override void InitUI() + { + AddEdit("name", "Button Name", ""); + AddCheckbox("enabled", "Enabled", true); + AddEdit("description", "Description", ""); + } + + public override void Generate(String outFileName, String outText, ref Flags generateFlags) + { + var name = mParams["name"]; + if (name.EndsWith(".bf", .OrdinalIgnoreCase)) + name.RemoveFromEnd(3); + + var enabled = bool.Parse(mParams["enabled"]); + var description = mParams["description"]; + + outFileName.Append(scope $"TG{name}"); + + outText.Append(scope $""" + namespace {Namespace}; + + using TheaterGui.Controls; + + class TG{name} : IconButton + {{ + public this() : base("{name}") + {{ + Icon = .Icon_Folder; //Use this to set the icon sprite + {!enabled ? "Enabled = false;" : ""} + Description.Append("{description}"); + }} + + //What happens when the button is clicked + public override void ClickAction() + {{ + + }} + }} + """); + } +} \ No newline at end of file diff --git a/src/Generators/LargeButtonGenerator.bf b/src/Generators/LargeButtonGenerator.bf new file mode 100644 index 0000000..02c4736 --- /dev/null +++ b/src/Generators/LargeButtonGenerator.bf @@ -0,0 +1,48 @@ +namespace TheaterGui.Generators; + +using System; + +class LargeButtonGenerator : Compiler.Generator +{ + public override String Name => "TheaterGui -> Generate Large Button" + + public override void InitUI() + { + AddEdit("name", "Button Name", ""); + AddCheckbox("enabled", "Enabled", true); + AddEdit("description", "Description", ""); + } + + public override void Generate(String outFileName, String outText, ref Flags generateFlags) + { + var name = mParams["name"]; + if (name.EndsWith(".bf", .OrdinalIgnoreCase)) + name.RemoveFromEnd(3); + + var enabled = bool.Parse(mParams["enabled"]); + var description = mParams["description"]; + + outFileName.Append(scope $"TG{name}"); + + outText.Append(scope $""" + namespace {Namespace}; + + using TheaterGui.Controls; + + class TG{name} : LargeButton + {{ + public this() : base("{name}") + {{ + {!enabled ? "Enabled = false;" : ""} + Description.Append("{description}"); + }} + + //What happens when the button is clicked + public override void ClickAction() + {{ + + }} + }} + """); + } +} \ No newline at end of file diff --git a/src/Generators/NButtonGenerator.bf b/src/Generators/NButtonGenerator.bf new file mode 100644 index 0000000..392b573 --- /dev/null +++ b/src/Generators/NButtonGenerator.bf @@ -0,0 +1,48 @@ +namespace TheaterGui.Generators; + +using System; + +class NButtonGenerator : Compiler.Generator +{ + public override String Name => "TheaterGui -> Generate NButton" + + public override void InitUI() + { + AddEdit("name", "Button Name", ""); + AddCheckbox("enabled", "Enabled", true); + AddEdit("description", "Description", ""); + } + + public override void Generate(String outFileName, String outText, ref Flags generateFlags) + { + var name = mParams["name"]; + if (name.EndsWith(".bf", .OrdinalIgnoreCase)) + name.RemoveFromEnd(3); + + var enabled = bool.Parse(mParams["enabled"]); + var description = mParams["description"]; + + outFileName.Append(scope $"TG{name}"); + + outText.Append(scope $""" + namespace {Namespace}; + + using TheaterGui.Controls; + + class TG{name} : NButton + {{ + public this() : base("{name}") + {{ + {!enabled ? "Enabled = false;" : ""} + Description.Append("{description}"); + }} + + //What happens when the button is clicked + public override void ClickAction() + {{ + + }} + }} + """); + } +} \ No newline at end of file diff --git a/src/Generators/ScreenGenerator.bf b/src/Generators/ScreenGenerator.bf new file mode 100644 index 0000000..f628f61 --- /dev/null +++ b/src/Generators/ScreenGenerator.bf @@ -0,0 +1,37 @@ +namespace TheaterGui.Generators; + +using System; + +class ScreenGenerator : Compiler.Generator +{ + public override String Name => "TheaterGui -> Generate Screen" + + public override void InitUI() + { + AddEdit("name", "Screen Name", ""); + } + + public override void Generate(String outFileName, String outText, ref Flags generateFlags) + { + var name = mParams["name"]; + if (name.EndsWith(".bf", .OrdinalIgnoreCase)) + name.RemoveFromEnd(3); + + outFileName.Append(scope $"TG{name}"); + + outText.Append(scope $""" + namespace {Namespace}; + + using TheaterGui.Controls; + + class TG{name} : Screen + {{ + public this() : base("{name}") + {{ + //Add ui items here via AddChild() and terminate the row via EndRow() + //The padding object can be used to add padding to every ui object + }} + }} + """); + } +} \ No newline at end of file diff --git a/src/Screen.bf b/src/Screen.bf deleted file mode 100644 index 6423779..0000000 --- a/src/Screen.bf +++ /dev/null @@ -1,44 +0,0 @@ -namespace TheaterGui; -using TheaterGui.Controls; - -using System; -using System.Collections; -using RaylibBeef; - -class Screen -{ - private List _Controls = new .() ~ DeleteContainerAndItems!(_); - //Used for layouting - private int32 _HighestY = 0; //"Highest" y value - private int32 _LowestY = 0; //"Lowest" y value - private int32 _X = 0; //Current X value - - - public Application Parent = null; - - public void Render() - { - for(var i in _Controls) - i.Render(); - } - - ///Add a control to the current screen - public void AddControl(Control pToAdd) - { - if(_X + pToAdd.BoundingBox.width >= 1920) - ForceNewRow(); - pToAdd.BoundingBox.x = _X; - pToAdd.BoundingBox.y = _HighestY; - _X = _X + (.)pToAdd.BoundingBox.width; //Update to new x value - if(_HighestY + pToAdd.BoundingBox.height > _LowestY) - _LowestY = _HighestY + (.)pToAdd.BoundingBox.height; - _Controls.Add(pToAdd); - pToAdd.Parent = this; - } - ///Force the next controls onto a newline - public void ForceNewRow() - { - _X = 0; - _HighestY = _LowestY; - } -} \ No newline at end of file diff --git a/src/Textures.bf b/src/Textures.bf index 68a8485..87ccbd5 100644 --- a/src/Textures.bf +++ b/src/Textures.bf @@ -8,18 +8,31 @@ class Textures { private List _Containers = new .() ~ DeleteContainerAndItems!(_); private List _Textures = new .() ~ delete _; - private Dictionary _Map = new .() ~ DeleteDictionaryAndKeys!(_); //Mapped Textures public this() { - LoadAsset(Assets.NPatch, "npatch"); + LoadAsset(Theme.Texture_Button, "button"); + LoadAsset(Theme.Texture_NButton, "n_button"); + LoadAsset(Theme.Texture_SquareButton, "square_button"); + LoadAsset(Theme.Texture_LargeButton, "large_button"); + + LoadAsset(Theme.Texture_TheaterIcon, "theater_icon"); + LoadAsset(Theme.Texture_FolderIcon, "folder_icon"); + sprite.Icon_Folder = GetAsset("folder_icon"); + sprite.Icon_Theater = GetAsset("theater_icon"); + + + } + private Dictionary _TileMap = new .() ~ DeleteDictionaryAndKeys!(_); + + ///Attempt to get a existing asset by StringView public Result GetAsset(StringView acess) { - if (!_Map.ContainsKeyAlt(acess)) + if (!_TileMap.ContainsKeyAlt(acess)) return .Err; - return .Ok(_Map[scope .(acess)]); + return .Ok(_TileMap[scope .(acess)]); } private void LoadAsset(Span data, StringView name) @@ -27,7 +40,7 @@ class Textures var img = Raylib.LoadImageFromMemory(".png", (.)data.Ptr, (.)data.Length); defer Raylib.UnloadImage(img); var s = Insert(img); - _Map.Add(new .(name), s); + _TileMap.Add(new .(name), s); } private sprite Insert(Image toInsert) @@ -137,8 +150,12 @@ struct sprite public int32 Height = 0; public float Rotation = 0; - public void Render(float x, float y) + public static sprite Icon_Folder; + public static sprite Icon_Theater; + + + public void Render(float x, float y, Color color = Raylib.WHITE) { - Raylib.DrawTexturePro(*Source, SourceRect, .(x + Width / 2, y + Height / 2, Width, Height), .(Width / 2, Height / 2), Rotation, Raylib.WHITE); + Raylib.DrawTexturePro(*Source, SourceRect, .(x + Width / 2, y + Height / 2, Width, Height), .(Width / 2, Height / 2), Rotation, color); } } \ No newline at end of file diff --git a/src/Theme.bf b/src/Theme.bf index 0cd4d70..291586b 100644 --- a/src/Theme.bf +++ b/src/Theme.bf @@ -1,14 +1,34 @@ namespace TheaterGui; +using System; using RaylibBeef; -class Theme +public class Theme { public static Font Font ~ Raylib.UnloadFont(_); public static int32 FontSize = 16; - public static Color BackgroundDark = .(45, 45, 49, 255); - public static Color Main = .(153, 36, 72 ,255); + public static Color Background = .(45, 45, 49, 255); + public static Color Tint = .(153, 36, 72, 255); + public static Color HoverTint = .(255,255,255,50); //Color overlay when an object is hovered over + public static Color DisabledTint = .(90,90,90,125); public static Color Text = .(216, 197, 215, 255); -} \ No newline at end of file + //Font data + public static uint8[?] Din = Compiler.ReadBinary("assets/Din.ttf"); + + public static uint8[?] Texture_WindowIcon = Compiler.ReadBinary("assets/64.png"); + //Icons + public static uint8[?] Texture_TheaterIcon = Compiler.ReadBinary("assets/icon_theater.png"); + public static uint8[?] Texture_FolderIcon = Compiler.ReadBinary("assets/icon_folder.png"); + + //Controls + public static uint8[?] Texture_SquareButton = Compiler.ReadBinary("assets/square_button.png"); + public static uint8[?] Texture_LargeButton = Compiler.ReadBinary("assets/large_button.png"); + public static uint8[?] Texture_NButton = Compiler.ReadBinary("assets/n_button.png"); + public static uint8[?] Texture_Button = Compiler.ReadBinary("assets/button.png"); + + + +} +