implemented basic window and letterboxing
This commit is contained in:
parent
fb039cc370
commit
39d211ac0f
5 changed files with 129 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
FileVersion = 1
|
||||
Dependencies = {corlib = "*", raylib-beef = "*"}
|
||||
|
||||
[Project]
|
||||
Name = "TheaterGui"
|
||||
TargetType = "BeefLib"
|
||||
StartupObject = "TheaterGui.Program"
|
||||
|
|
|
@ -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"}}
|
||||
|
|
BIN
assets/64.png
Normal file
BIN
assets/64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 925 B |
111
src/Application.bf
Normal file
111
src/Application.bf
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
8
src/Assets.bf
Normal file
8
src/Assets.bf
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace TheaterGui;
|
||||
|
||||
using System;
|
||||
|
||||
class Assets
|
||||
{
|
||||
public static uint8[?] WindowIcon = Compiler.ReadBinary("assets/64.png");
|
||||
}
|
Loading…
Add table
Reference in a new issue