Added keyboard support for zooming.
Added information but to show intro.
This commit is contained in:
parent
a6004a8ab6
commit
5ebd582498
@ -127,6 +127,7 @@ func (c *GameControls) Init(ctx *Context) error {
|
||||
c.game.New()
|
||||
c.updateFlowerControls(ctx)
|
||||
}),
|
||||
NewIconButton("control-information", func(*Context) { c.dialogs.ShowIntro() }),
|
||||
}
|
||||
|
||||
c.shovel = NewIconButtonConfig("control-shovel", func(*Context) { c.game.SelectShovel() }, func(b *IconButton) { b.IconHeight = 32 })
|
||||
|
@ -100,3 +100,26 @@ func (p *projection) visibleTiles(action func(int32, int32, Point)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *projection) ZoomOut(ctx *Context, center PointF) {
|
||||
if p.zoom <= .25 {
|
||||
return
|
||||
}
|
||||
p.SetZoom(ctx, center, .5*p.zoom)
|
||||
}
|
||||
|
||||
func (p *projection) ZoomIn(ctx *Context, center PointF) {
|
||||
if p.zoom >= 2 {
|
||||
return
|
||||
}
|
||||
p.SetZoom(ctx, center, 2*p.zoom)
|
||||
}
|
||||
|
||||
func (p *projection) SetZoom(ctx *Context, center PointF, zoom float32) {
|
||||
if p.zoom == zoom {
|
||||
return
|
||||
}
|
||||
p.center = center.Sub(center.Sub(p.center).Mul(p.zoom / zoom))
|
||||
p.zoom = zoom
|
||||
p.update(ctx.Renderer)
|
||||
}
|
||||
|
@ -78,17 +78,10 @@ func (r *terrainRenderer) Handle(ctx *Context, event sdl.Event) bool {
|
||||
}
|
||||
case *sdl.MouseWheelEvent:
|
||||
if r.hover != nil {
|
||||
zoom := r.project.zoom
|
||||
if e.Y < 0 && r.project.zoom > .25 {
|
||||
zoom *= .5
|
||||
} else if e.Y > 0 && r.project.zoom < 2 {
|
||||
zoom *= 2
|
||||
}
|
||||
if zoom != r.project.zoom {
|
||||
hover := r.hover.ToPtF()
|
||||
r.project.center = hover.Sub(hover.Sub(r.project.center).Mul(r.project.zoom / zoom))
|
||||
r.project.zoom = zoom
|
||||
r.project.update(ctx.Renderer)
|
||||
if e.Y < 0 {
|
||||
r.project.ZoomOut(ctx, r.hover.ToPtF())
|
||||
} else {
|
||||
r.project.ZoomIn(ctx, r.hover.ToPtF())
|
||||
}
|
||||
}
|
||||
case *sdl.WindowEvent:
|
||||
@ -96,6 +89,19 @@ func (r *terrainRenderer) Handle(ctx *Context, event sdl.Event) bool {
|
||||
r.hover = nil
|
||||
r.project.update(ctx.Renderer)
|
||||
}
|
||||
case *sdl.KeyboardEvent:
|
||||
if e.Type == sdl.KEYDOWN {
|
||||
switch e.Keysym.Sym {
|
||||
case sdl.K_PLUS:
|
||||
r.project.ZoomIn(ctx, r.project.center)
|
||||
case sdl.K_KP_PLUS:
|
||||
r.project.ZoomIn(ctx, r.project.center)
|
||||
case sdl.K_MINUS:
|
||||
r.project.ZoomOut(ctx, r.project.center)
|
||||
case sdl.K_KP_MINUS:
|
||||
r.project.ZoomOut(ctx, r.project.center)
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user