diff --git a/internal/app/canvas.go b/internal/app/canvas.go index fca0234..5820e34 100644 --- a/internal/app/canvas.go +++ b/internal/app/canvas.go @@ -21,6 +21,15 @@ func cut(img canvas, bounds math.Rect) canvas { return §ion{img: img, frame: bounds} } +func fill(img canvas, style tcell.Style) { + bounds := img.bounds() + for x := 0; x < bounds.Width; x++ { + for y := 0; y < bounds.Height; y++ { + img.setTile(x, y, tile{r: ' ', style: style}) + } + } +} + type section struct { img canvas frame math.Rect diff --git a/internal/app/chat_view.go b/internal/app/chat_view.go index b6b9988..4d76d81 100644 --- a/internal/app/chat_view.go +++ b/internal/app/chat_view.go @@ -51,6 +51,7 @@ func (c *chatView) handleEvent(e tcell.Event) change { func (c *chatView) draw(img canvas, st *state) { bounds := img.bounds() + fill(img, tcell.StyleDefault.Background(tcell.NewRGBColor(32, 32, 32))) chatHeight := bounds.Height - 1 for i := 0; i < math.Min(chatHeight, len(c.history)); i++ { msg := c.history[len(c.history)-1-i] diff --git a/internal/app/container_view.go b/internal/app/container_view.go index 3417361..f40e38b 100644 --- a/internal/app/container_view.go +++ b/internal/app/container_view.go @@ -6,8 +6,10 @@ import ( ) type containerView struct { - children []*node - focussed int + refWidth int + refHeight int + children []*node + focussed int } func (c *containerView) handleEvent(e tcell.Event) change { @@ -23,8 +25,20 @@ func (c *containerView) handleEvent(e tcell.Event) change { } func (c *containerView) draw(img canvas, st *state) { + bounds := img.bounds() + for _, n := range c.children { - n.draw(cut(img, n.frame), st) + n.draw(cut(img, c.scaleFrame(n.frame, bounds)), st) + } +} + +func (c *containerView) scaleFrame(frame math.Rect, bounds math.Rect) math.Rect { + xscale := bounds.Width / c.refWidth + yscale := bounds.Height / c.refHeight + return math.Rect{ + Origin: math.Vec{xscale * frame.Origin.X, yscale * frame.Origin.Y}, + Width: xscale * frame.Width, + Height: yscale * frame.Height, } } diff --git a/internal/app/login.go b/internal/app/login.go index aba51a1..56e8e89 100644 --- a/internal/app/login.go +++ b/internal/app/login.go @@ -1,7 +1,6 @@ package app import ( - "github.com/jordanorelli/astro-domu/internal/math" "github.com/jordanorelli/astro-domu/internal/wire" ) @@ -38,19 +37,5 @@ func (l login) exec(ui *UI) { // e := room.Entities[p.Avatar] ui.state.room = &room - ui.root = &containerView{ - children: []*node{ - { - frame: math.Rect{math.Vec{0, 0}, 20, 20}, - view: &gameView{ - Log: ui.Child("game-view"), - }, - }, - { - frame: math.Rect{math.Vec{0, 20}, 40, 20}, - view: &chatView{}, - }, - }, - } - ui.Info("done logging in, we replaced the root view whaduheck") + ui.root = inGameView } diff --git a/internal/app/ui.go b/internal/app/ui.go index 47fa6c6..d437b28 100644 --- a/internal/app/ui.go +++ b/internal/app/ui.go @@ -191,3 +191,18 @@ var joinForm = &form{ }, }, } + +var inGameView = &containerView{ + refWidth: 8, + refHeight: 8, + children: []*node{ + { + frame: math.Rect{math.Vec{0, 0}, 4, 4}, + view: &gameView{}, + }, + { + frame: math.Rect{math.Vec{0, 4}, 8, 4}, + view: &chatView{}, + }, + }, +} diff --git a/main.go b/main.go index e27b615..15e44c4 100644 --- a/main.go +++ b/main.go @@ -30,7 +30,7 @@ func newLog(path string) *blammo.Log { func main() { if len(os.Args) < 2 { - exit.WithMessage(1, "client or server?") + runClient() } switch os.Args[1] {