diff --git a/terrainrenderer.go b/terrainrenderer.go index ca68a3a..3be78df 100644 --- a/terrainrenderer.go +++ b/terrainrenderer.go @@ -51,25 +51,34 @@ func (r *terrainRenderer) Init(ctx *Context) error { 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) { switch e := event.(type) { case *sdl.MouseButtonEvent: if r.project.windowInteractRect.IsPointInside(e.X, e.Y) { - switch e.Button { - case sdl.BUTTON_LEFT: - down := e.Type == sdl.MOUSEBUTTONDOWN - if down && !r.drag.IsDragging() { - r.drag.Start(Pt(e.X, e.Y)) - } else if !down && r.drag.IsDragging() { - r.drag.Cancel() + if e.Type == sdl.MOUSEBUTTONDOWN { + if e.Button == sdl.BUTTON_MIDDLE || (e.Button == sdl.BUTTON_LEFT && isControlKeyDown()) { + if !r.drag.IsDragging() { + r.drag.Start(Pt(e.X, e.Y)) + } } - if e.Type == sdl.MOUSEBUTTONUP && !r.drag.HasDragged() { + if e.Button == sdl.BUTTON_LEFT { pos := r.project.screenToMapInt(e.X, e.Y) r.game.UserClickedTile(pos) } - case sdl.BUTTON_RIGHT: - if e.Type == sdl.MOUSEBUTTONDOWN { - r.game.CancelTool() + if e.Button == sdl.BUTTON_RIGHT { + if e.Type == sdl.MOUSEBUTTONDOWN { + r.game.CancelTool() + } + } + } + if e.Type == sdl.MOUSEBUTTONUP { + if r.drag.IsDragging() { + r.drag.Cancel() } } }