package ui import ( coreobjects "github.com/DegustatorPonos/RuinesOfRafdolon/CoreObjects" settings "github.com/DegustatorPonos/RuinesOfRafdolon/Settings" rl "github.com/gen2brain/raylib-go/raylib" ) // Scene implimetation that contains aligned UI elements type Menu struct { manager *coreobjects.SceneManager // The space between the window border and the grid. Measured in fractions of a screen. [0; 1] PaddingX float32 // The space between the window border and the grid. Measured in fractions of a screen. [0; 1] PaddingY float32 // Base element Contents UIElement cache *layoutCache } func (base *Menu) Create(manager *coreobjects.SceneManager) { base.manager = manager base.cache = &layoutCache{} base.Contents.Init(base) } func (base *Menu) Destroy() { } func (base *Menu) Update() { } func (base *Menu) Draw() { if !base.cache.IsValid() { base.RecalculateCache() } rl.ClearBackground(rl.Black) if settings.State.DrawColliders { base.drawPaddings() } var span = rl.Rectangle { X: base.cache.OffsetX, Y: base.cache.OffsetY, Width: base.cache.Width, Height: base.cache.Height, } base.Contents.Draw(&span) } func (base *Menu) drawPaddings() { // Horizontal rl.DrawRectangle(0, 0, int32(base.cache.ScreenResolution.X), int32(base.cache.OffsetY), rl.Red) rl.DrawRectangle(0, int32(base.cache.ScreenResolution.Y) - int32(base.cache.OffsetY), int32(base.cache.ScreenResolution.X), int32(base.cache.OffsetY), rl.Red) // Vertical rl.DrawRectangle(0, int32(base.cache.OffsetY), int32(base.cache.OffsetX), int32(base.cache.ScreenResolution.Y - base.cache.OffsetY * 2), rl.Blue) rl.DrawRectangle( int32(base.cache.ScreenResolution.X - base.cache.OffsetX), int32(base.cache.OffsetY), int32(base.cache.OffsetX), int32(base.cache.ScreenResolution.Y - base.cache.OffsetY * 2), rl.Blue) } func (base *Menu) GetMousePosition() rl.Vector2 { return rl.GetMousePosition() } func (base *Menu) RecalculateCache() { base.cache.ScreenResolution = rl.Vector2 { X: float32(rl.GetScreenWidth()), Y: float32(rl.GetScreenHeight()), } base.cache.SpanResolution = rl.Vector2 { X: float32(rl.GetScreenWidth()), Y: float32(rl.GetScreenHeight()), } base.cache.CalculateOffsets( base.cache.SpanResolution.X, base.cache.SpanResolution.Y, base.PaddingX, base.PaddingY) }