From 8dd47c5ec20009c6486a5edcfc8cd9329dd1a277 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sat, 9 May 2020 14:02:00 +0200 Subject: [PATCH] Added storing of window size. --- cmd/tins2020/tins2020.go | 15 +++++++++++++-- settings.go | 1 + terrainrenderer.go | 7 ++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/tins2020/tins2020.go b/cmd/tins2020/tins2020.go index 49d77f9..d1518fe 100644 --- a/cmd/tins2020/tins2020.go +++ b/cmd/tins2020/tins2020.go @@ -47,10 +47,18 @@ func run() error { Y: sdl.WINDOWPOS_UNDEFINED, } } + if ctx.Settings.Window.Size == nil { + ctx.Settings.Window.Size = &tins2020.Point{ + X: 800, + Y: 600, + } + } sdl.SetHint(sdl.HINT_RENDER_SCALE_QUALITY, "1") - window, err := sdl.CreateWindow("TINS 2020", ctx.Settings.Window.Location.X, ctx.Settings.Window.Location.Y, - 800, 600, sdl.WINDOW_SHOWN|sdl.WINDOW_RESIZABLE) + window, err := sdl.CreateWindow("TINS 2020", + ctx.Settings.Window.Location.X, ctx.Settings.Window.Location.Y, + ctx.Settings.Window.Size.X, ctx.Settings.Window.Size.Y, + sdl.WINDOW_SHOWN|sdl.WINDOW_RESIZABLE) if err != nil { return err } @@ -135,6 +143,9 @@ func run() error { case sdl.WINDOWEVENT_MOVED: x, y := window.GetPosition() ctx.Settings.Window.Location = &tins2020.Point{X: x, Y: y} + case sdl.WINDOWEVENT_SIZE_CHANGED: + w, h := window.GetSize() + ctx.Settings.Window.Size = &tins2020.Point{X: w, Y: h} } case *sdl.KeyboardEvent: switch e.Keysym.Sym { diff --git a/settings.go b/settings.go index 3db65e7..2b58fff 100644 --- a/settings.go +++ b/settings.go @@ -31,4 +31,5 @@ func (s *Settings) Store() error { type WindowSettings struct { Location *Point + Size *Point } diff --git a/terrainrenderer.go b/terrainrenderer.go index 2971e67..583c894 100644 --- a/terrainrenderer.go +++ b/terrainrenderer.go @@ -92,25 +92,22 @@ func (r *terrainRenderer) Handle(ctx *Context, event sdl.Event) { r.interact.mouseLeftDown = e.Type == sdl.MOUSEBUTTONDOWN if r.interact.mouseLeftDown && r.interact.mouseDrag == nil { r.interact.mouseDrag = &Point{e.X, e.Y} - fmt.Println("Drag start", r.interact.mouseDrag) } else if !r.interact.mouseLeftDown && r.interact.mouseDrag != nil { - fmt.Println("Drag end", r.interact.mouseDrag) r.interact.mouseDrag = nil } } case *sdl.MouseMotionEvent: r.hover = r.project.screenToMap(e.X, e.Y) if r.interact.mouseDrag != nil { - fmt.Println("Dragging...", r.project.center) r.project.center = r.project.center.Sub(r.project.screenToMapRel(e.X-r.interact.mouseDrag.X, e.Y-r.interact.mouseDrag.Y)) r.project.update(ctx.Renderer) r.interact.mouseDrag = &Point{e.X, e.Y} } case *sdl.MouseWheelEvent: - if e.Y > 0 { + if e.Y > 0 && r.project.zoom > .5 { r.project.zoom *= .5 r.project.update(ctx.Renderer) - } else if e.Y < 0 { + } else if e.Y < 0 && r.project.zoom < 4 { r.project.zoom *= 2 r.project.update(ctx.Renderer) }