added some layouting and basic controls
This commit is contained in:
parent
39d211ac0f
commit
9d20ae7cb0
11 changed files with 273 additions and 7 deletions
BIN
assets/DIN.ttf
Normal file
BIN
assets/DIN.ttf
Normal file
Binary file not shown.
BIN
assets/npatch.png
Normal file
BIN
assets/npatch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 170 B |
BIN
assets/npatch.png~
Normal file
BIN
assets/npatch.png~
Normal file
Binary file not shown.
After Width: | Height: | Size: 189 B |
|
@ -23,6 +23,8 @@ class Application
|
|||
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
|
||||
|
@ -37,7 +39,6 @@ class Application
|
|||
get => Raylib.GetRenderHeight();
|
||||
set => Raylib.SetWindowSize(Raylib.GetRenderWidth(), value);
|
||||
}
|
||||
|
||||
public Vector2 MousePosition
|
||||
{
|
||||
get
|
||||
|
@ -51,18 +52,23 @@ class Application
|
|||
}
|
||||
}
|
||||
|
||||
public Textures Textures ~ delete _;
|
||||
public Screen CurrentScreen;
|
||||
|
||||
///Start the application displaying the input screen
|
||||
public void Start()
|
||||
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(Raylib.WHITE);
|
||||
var mouse = MousePosition;
|
||||
Raylib.DrawRectangle((.)mouse.x-16,(.)mouse.y-16,32,32,Raylib.PINK);
|
||||
Raylib.ClearBackground(Theme.BackgroundDark);
|
||||
CurrentScreen.Render();
|
||||
Raylib.EndTextureMode();
|
||||
|
||||
Raylib.DrawTexturePro(
|
||||
|
@ -73,7 +79,6 @@ class Application
|
|||
0,
|
||||
Raylib.WHITE
|
||||
);
|
||||
|
||||
Raylib.EndDrawing();
|
||||
UpdateLetterboxing();
|
||||
}
|
||||
|
@ -94,7 +99,7 @@ class Application
|
|||
{
|
||||
_RTPosition[0] = 0;
|
||||
_RTSize[0] = width;
|
||||
_RTPosition[1] = (.)((height - maxHeight * 9) / 2);
|
||||
_RTPosition[1] = (.)((height - maxWidth * 9) / 2);
|
||||
_RTSize[1] = (.)(height - (height - maxWidth * 9));
|
||||
}
|
||||
else
|
||||
|
|
|
@ -5,4 +5,7 @@ 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");
|
||||
|
||||
}
|
19
src/Controls/Button.bf
Normal file
19
src/Controls/Button.bf
Normal file
|
@ -0,0 +1,19 @@
|
|||
namespace TheaterGui.Controls;
|
||||
|
||||
using RaylibBeef;
|
||||
|
||||
class Button : Control
|
||||
{
|
||||
public this()
|
||||
{
|
||||
BoundingBox = .(0, 0, 400, 200);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
18
src/Controls/Control.bf
Normal file
18
src/Controls/Control.bf
Normal file
|
@ -0,0 +1,18 @@
|
|||
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
|
||||
*/
|
||||
}
|
19
src/Controls/Toolbar.bf
Normal file
19
src/Controls/Toolbar.bf
Normal file
|
@ -0,0 +1,19 @@
|
|||
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);
|
||||
}
|
||||
}
|
44
src/Screen.bf
Normal file
44
src/Screen.bf
Normal file
|
@ -0,0 +1,44 @@
|
|||
namespace TheaterGui;
|
||||
using TheaterGui.Controls;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using RaylibBeef;
|
||||
|
||||
class Screen
|
||||
{
|
||||
private List<Control> _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;
|
||||
}
|
||||
}
|
144
src/Textures.bf
Normal file
144
src/Textures.bf
Normal file
|
@ -0,0 +1,144 @@
|
|||
namespace TheaterGui;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using RaylibBeef;
|
||||
|
||||
class Textures
|
||||
{
|
||||
private List<Node> _Containers = new .() ~ DeleteContainerAndItems!(_);
|
||||
private List<RenderTexture> _Textures = new .() ~ delete _;
|
||||
private Dictionary<String, sprite> _Map = new .() ~ DeleteDictionaryAndKeys!(_); //Mapped Textures
|
||||
|
||||
public this()
|
||||
{
|
||||
LoadAsset(Assets.NPatch, "npatch");
|
||||
}
|
||||
|
||||
public Result<sprite> GetAsset(StringView acess)
|
||||
{
|
||||
if (!_Map.ContainsKeyAlt<StringView>(acess))
|
||||
return .Err;
|
||||
return .Ok(_Map[scope .(acess)]);
|
||||
}
|
||||
|
||||
private void LoadAsset(Span<uint8> data, StringView name)
|
||||
{
|
||||
var img = Raylib.LoadImageFromMemory(".png", (.)data.Ptr, (.)data.Length);
|
||||
defer Raylib.UnloadImage(img);
|
||||
var s = Insert(img);
|
||||
_Map.Add(new .(name), s);
|
||||
}
|
||||
|
||||
private sprite Insert(Image toInsert)
|
||||
{
|
||||
for (var i in _Containers)
|
||||
{
|
||||
var res = i.Insert(toInsert);
|
||||
if (res != null)
|
||||
{
|
||||
Raylib.BeginDrawing();
|
||||
Raylib.BeginTextureMode(_Textures[@i.Index]);
|
||||
var img = Raylib.LoadTextureFromImage((.)res.id);
|
||||
Raylib.DrawTexturePro(img, .(0, 0, img.width, -img.height), .((.)res.rc[0], 2048 - res.rc[1] - (.)res.rc[3], img.width, img.height), .(0, 0), 0, Raylib.WHITE);
|
||||
Raylib.EndTextureMode();
|
||||
Raylib.EndDrawing();
|
||||
Raylib.UnloadTexture(img);
|
||||
|
||||
sprite toReturn = .();
|
||||
toReturn.Source = &_Textures[@i.Index].texture;
|
||||
toReturn.Height = (.)res.rc[3];
|
||||
toReturn.Width = (.)res.rc[2];
|
||||
toReturn.SourceRect = .(res.rc[0], res.rc[1], res.rc[2], res.rc[3]);
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
_Containers.Add(new .());
|
||||
_Textures.Add(Raylib.LoadRenderTexture(2048, 2048));
|
||||
Raylib.BeginDrawing();
|
||||
Raylib.BeginTextureMode(_Textures[_Textures.Count - 1]);
|
||||
Raylib.ClearBackground(Raylib.BLANK);
|
||||
Raylib.EndTextureMode();
|
||||
Raylib.EndDrawing();
|
||||
return Insert(toInsert);
|
||||
}
|
||||
|
||||
class Node
|
||||
{
|
||||
public Node[2] childs = .(null, null);
|
||||
public uint64[4] rc = .(0, 0, 2048, 2048); //x,y, width, height
|
||||
public Image? id = null;
|
||||
|
||||
public Node Insert(Image toInsert)
|
||||
{
|
||||
if (!(childs[0] == null && childs[1] == null))
|
||||
{
|
||||
var newNode = childs[0].Insert(toInsert);
|
||||
if (newNode != null) return newNode;
|
||||
|
||||
newNode = childs[1].Insert(toInsert);
|
||||
if (newNode != null) return newNode;
|
||||
}
|
||||
else //Insert
|
||||
{
|
||||
if (id != null)
|
||||
return null;
|
||||
|
||||
if (toInsert.width > (.)rc[2] || toInsert.height > (.)rc[3])
|
||||
return null;
|
||||
|
||||
if (toInsert.width == (.)rc[2] && toInsert.height == (.)rc[3])
|
||||
{
|
||||
id = toInsert;
|
||||
return this;
|
||||
}
|
||||
|
||||
childs[0] = new .();
|
||||
childs[1] = new .();
|
||||
|
||||
var dw = rc[2] - (.)toInsert.width;
|
||||
var dh = rc[3] - (.)toInsert.height;
|
||||
|
||||
if (dw > dh)
|
||||
{
|
||||
childs[0].rc = .(rc[0], rc[1], (.)toInsert.width, rc[3]);
|
||||
childs[1].rc = .(rc[0] + (.)toInsert.width, rc[1],
|
||||
rc[2] - (.)toInsert.width, rc[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
childs[0].rc = .(rc[0], rc[1],
|
||||
rc[2], (.)toInsert.height);
|
||||
childs[1].rc = .(rc[0], rc[1] + (.)toInsert.height,
|
||||
rc[2], rc[3] - (.)toInsert.height);
|
||||
}
|
||||
|
||||
return childs[0].Insert(toInsert);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ~this()
|
||||
{
|
||||
if (childs[0] != null)
|
||||
delete childs[0];
|
||||
if (childs[1] != null)
|
||||
delete childs[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct sprite
|
||||
{
|
||||
public Texture2D* Source;
|
||||
public Rectangle SourceRect;
|
||||
|
||||
public int32 Width = 0;
|
||||
public int32 Height = 0;
|
||||
public float Rotation = 0;
|
||||
|
||||
public void Render(float x, float y)
|
||||
{
|
||||
Raylib.DrawTexturePro(*Source, SourceRect, .(x + Width / 2, y + Height / 2, Width, Height), .(Width / 2, Height / 2), Rotation, Raylib.WHITE);
|
||||
}
|
||||
}
|
14
src/Theme.bf
Normal file
14
src/Theme.bf
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace TheaterGui;
|
||||
|
||||
using RaylibBeef;
|
||||
|
||||
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 Text = .(216, 197, 215, 255);
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue