Added storing of window size.

This commit is contained in:
Sander Schobers 2020-05-09 14:02:00 +02:00
parent 27afe594fe
commit 8dd47c5ec2
3 changed files with 16 additions and 7 deletions

View File

@ -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 {

View File

@ -31,4 +31,5 @@ func (s *Settings) Store() error {
type WindowSettings struct {
Location *Point
Size *Point
}

View File

@ -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)
}