Changed panning of map (Ctrl+LMB or MMB instead of LMB).

This commit is contained in:
Sander Schobers 2020-05-11 01:15:48 +02:00
parent 14454cfd5e
commit a07d3c1c82

View File

@ -51,28 +51,37 @@ func (r *terrainRenderer) Init(ctx *Context) error {
return nil return nil
} }
func isControlKeyDown() bool {
state := sdl.GetKeyboardState()
return state[sdl.SCANCODE_LCTRL] == 1 || state[sdl.SCANCODE_RCTRL] == 1
}
func (r *terrainRenderer) Handle(ctx *Context, event sdl.Event) { func (r *terrainRenderer) Handle(ctx *Context, event sdl.Event) {
switch e := event.(type) { switch e := event.(type) {
case *sdl.MouseButtonEvent: case *sdl.MouseButtonEvent:
if r.project.windowInteractRect.IsPointInside(e.X, e.Y) { if r.project.windowInteractRect.IsPointInside(e.X, e.Y) {
switch e.Button { if e.Type == sdl.MOUSEBUTTONDOWN {
case sdl.BUTTON_LEFT: if e.Button == sdl.BUTTON_MIDDLE || (e.Button == sdl.BUTTON_LEFT && isControlKeyDown()) {
down := e.Type == sdl.MOUSEBUTTONDOWN if !r.drag.IsDragging() {
if down && !r.drag.IsDragging() {
r.drag.Start(Pt(e.X, e.Y)) r.drag.Start(Pt(e.X, e.Y))
} else if !down && r.drag.IsDragging() {
r.drag.Cancel()
} }
if e.Type == sdl.MOUSEBUTTONUP && !r.drag.HasDragged() { }
if e.Button == sdl.BUTTON_LEFT {
pos := r.project.screenToMapInt(e.X, e.Y) pos := r.project.screenToMapInt(e.X, e.Y)
r.game.UserClickedTile(pos) r.game.UserClickedTile(pos)
} }
case sdl.BUTTON_RIGHT: if e.Button == sdl.BUTTON_RIGHT {
if e.Type == sdl.MOUSEBUTTONDOWN { if e.Type == sdl.MOUSEBUTTONDOWN {
r.game.CancelTool() r.game.CancelTool()
} }
} }
} }
if e.Type == sdl.MOUSEBUTTONUP {
if r.drag.IsDragging() {
r.drag.Cancel()
}
}
}
case *sdl.MouseMotionEvent: case *sdl.MouseMotionEvent:
if r.project.windowInteractRect.IsPointInside(e.X, e.Y) { if r.project.windowInteractRect.IsPointInside(e.X, e.Y) {
hover := r.project.screenToMapInt(e.X, e.Y) hover := r.project.screenToMapInt(e.X, e.Y)