mouse cursor will be hidden in playmode window if mouse if not being used

cursor will reappear when mouse is moved, unless the window has been
"captured"
This commit is contained in:
JetSetIlly 2022-09-07 14:57:31 +01:00
parent e825ceeae0
commit 6895b373a3
3 changed files with 49 additions and 19 deletions

View file

@ -409,14 +409,26 @@ func (img *SdlImgui) setCapture(set bool) {
}
img.plt.window.SetGrab(set)
img.hideCursor(set)
}
if set {
_, err = sdl.ShowCursor(sdl.DISABLE)
// smartly hide cursor based on playmode and capture state. only called from
// gui thread
func (img *SdlImgui) smartHideCursor(set bool) {
if img.isPlaymode() && !img.isCaptured() {
img.hideCursor(set)
}
}
// hide mouse cursor. only called from gui thread
func (img *SdlImgui) hideCursor(hide bool) {
if hide {
_, err := sdl.ShowCursor(sdl.DISABLE)
if err != nil {
logger.Log("sdlimgui", err.Error())
}
} else {
_, err = sdl.ShowCursor(sdl.ENABLE)
_, err := sdl.ShowCursor(sdl.ENABLE)
if err != nil {
logger.Log("sdlimgui", err.Error())
}

View file

@ -72,9 +72,15 @@ func (img *SdlImgui) Service() {
}
case *sdl.KeyboardEvent:
img.smartHideCursor(true)
img.serviceKeyboard(ev)
case *sdl.MouseMotionEvent:
img.smartHideCursor(false)
case *sdl.MouseButtonEvent:
img.smartHideCursor(false)
// the button event to send
var button userinput.MouseButton
@ -151,6 +157,8 @@ func (img *SdlImgui) Service() {
}
case *sdl.JoyButtonEvent:
img.smartHideCursor(true)
button := userinput.GamepadButtonNone
switch ev.Button {
case 0:
@ -182,6 +190,8 @@ func (img *SdlImgui) Service() {
}
case *sdl.JoyHatEvent:
img.smartHideCursor(true)
dir := userinput.DPadNone
switch ev.Value {
case sdl.HAT_CENTERED:
@ -217,6 +227,14 @@ func (img *SdlImgui) Service() {
case *sdl.JoyAxisEvent:
pad := sdl.GameControllerFromInstanceID(ev.Which)
if pad.Axis(0) > userinput.StickDeadzone || pad.Axis(0) < -userinput.StickDeadzone ||
pad.Axis(1) > userinput.StickDeadzone || pad.Axis(1) < -userinput.StickDeadzone ||
pad.Axis(3) > userinput.StickDeadzone || pad.Axis(3) < -userinput.StickDeadzone ||
pad.Axis(4) > userinput.StickDeadzone || pad.Axis(4) < -userinput.StickDeadzone {
img.smartHideCursor(true)
}
switch ev.Axis {
case 0:
fallthrough

View file

@ -20,6 +20,12 @@ import (
"github.com/jetsetilly/gopher2600/hardware/riot/ports/plugging"
)
// small deadzone for the triggers
const TriggerDeadzone = 10
// quite a large deadzone for the thumbstick
const StickDeadzone = 10000
// Controllers keeps track of hardware userinput options.
type Controllers struct {
inputHandlers []HandleInput
@ -342,26 +348,23 @@ func (c *Controllers) gamepadThumbstick(ev EventGamepadThumbstick) (bool, error)
return false, nil
}
// quite a large deadzone for the thumbstick
const deadzone = 10000
if ev.Horiz > deadzone {
if ev.Vert > deadzone {
if ev.Horiz > StickDeadzone {
if ev.Vert > StickDeadzone {
return c.handleEvents(ev.ID, ports.RightDown, ports.DataStickSet)
} else if ev.Vert < -deadzone {
} else if ev.Vert < -StickDeadzone {
return c.handleEvents(ev.ID, ports.RightUp, ports.DataStickSet)
}
return c.handleEvents(ev.ID, ports.Right, ports.DataStickSet)
} else if ev.Horiz < -deadzone {
if ev.Vert > deadzone {
} else if ev.Horiz < -StickDeadzone {
if ev.Vert > StickDeadzone {
return c.handleEvents(ev.ID, ports.LeftDown, ports.DataStickSet)
} else if ev.Vert < -deadzone {
} else if ev.Vert < -StickDeadzone {
return c.handleEvents(ev.ID, ports.LeftUp, ports.DataStickSet)
}
return c.handleEvents(ev.ID, ports.Left, ports.DataStickSet)
} else if ev.Vert > deadzone {
} else if ev.Vert > StickDeadzone {
return c.handleEvents(ev.ID, ports.Down, ports.DataStickSet)
} else if ev.Vert < -deadzone {
} else if ev.Vert < -StickDeadzone {
return c.handleEvents(ev.ID, ports.Up, ports.DataStickSet)
}
@ -380,9 +383,6 @@ func (c *Controllers) gamepadTriggers(ev EventGamepadTrigger) (bool, error) {
return false, nil
}
// small deadzone for the triggers
const deadzone = 10
const min = 0.0
const max = 65535.0
const mid = 32768.0
@ -394,7 +394,7 @@ func (c *Controllers) gamepadTriggers(ev EventGamepadTrigger) (bool, error) {
case GamepadTriggerLeft:
// check deadzone
if n >= -deadzone && n <= deadzone {
if n >= -TriggerDeadzone && n <= TriggerDeadzone {
c.trigger = GamepadTriggerNone
n = min
} else {
@ -409,7 +409,7 @@ func (c *Controllers) gamepadTriggers(ev EventGamepadTrigger) (bool, error) {
}
case GamepadTriggerRight:
// check deadzone
if n >= -deadzone && n <= deadzone {
if n >= -TriggerDeadzone && n <= TriggerDeadzone {
c.trigger = GamepadTriggerNone
n = min
} else {