Skip to content

Commit

Permalink
Mouse support (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
kivutar authored Oct 25, 2021
1 parent f7a97a6 commit 038765b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
23 changes: 23 additions & 0 deletions input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ var (
NewAnalogState AnalogStates // analog input state for the current frame
)

var oldMouseX float64
var oldMouseY float64

// Hot keys
const (
// ActionMenuToggle toggles the menu UI
Expand Down Expand Up @@ -190,5 +193,25 @@ func State(port uint, device uint32, index uint, id uint) int16 {
return NewAnalogState[port][index][id]
}

if device == lr.DeviceMouse {
x, y := vid.Window.GetCursorPos()
if id == uint(lr.DeviceIDMouseX) {
d := x - oldMouseX
oldMouseX = x
return int16(d)
}
if id == uint(lr.DeviceIDMouseY) {
d := y - oldMouseY
oldMouseY = y
return int16(d)
}
if id == uint(lr.DeviceIDMouseLeft) && vid.Window.GetMouseButton(glfw.MouseButton1) == glfw.Press {
return 1
}
if id == uint(lr.DeviceIDMouseRight) && vid.Window.GetMouseButton(glfw.MouseButton2) == glfw.Press {
return 1
}
}

return 0
}
17 changes: 16 additions & 1 deletion libretro/libretro.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ const (
DeviceIDJoypadMask = uint32(C.RETRO_DEVICE_ID_JOYPAD_MASK)
)

// Index / Id values for ANALOG device.
// Index / Id values for analog device
const (
DeviceIndexAnalogLeft = uint32(C.RETRO_DEVICE_INDEX_ANALOG_LEFT)
DeviceIndexAnalogRight = uint32(C.RETRO_DEVICE_INDEX_ANALOG_RIGHT)
Expand All @@ -304,6 +304,21 @@ const (
DeviceIDAnalogY = uint32(C.RETRO_DEVICE_ID_ANALOG_Y)
)

// ID values for the mouse device
const (
DeviceIDMouseX = uint32(C.RETRO_DEVICE_ID_MOUSE_X)
DeviceIDMouseY = uint32(C.RETRO_DEVICE_ID_MOUSE_Y)
DeviceIDMouseLeft = uint32(C.RETRO_DEVICE_ID_MOUSE_LEFT)
DeviceIDMouseRight = uint32(C.RETRO_DEVICE_ID_MOUSE_RIGHT)
DeviceIDMouseWheelUp = uint32(C.RETRO_DEVICE_ID_MOUSE_WHEELUP)
DeviceIDMouseWheelDown = uint32(C.RETRO_DEVICE_ID_MOUSE_WHEELDOWN)
DeviceIDMouseMiddle = uint32(C.RETRO_DEVICE_ID_MOUSE_MIDDLE)
DeviceIDMouseHorizWheelUp = uint32(C.RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP)
DeviceIDMouseHorizWheelDown = uint32(C.RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN)
DeviceIDMouseButton4 = uint32(C.RETRO_DEVICE_ID_MOUSE_BUTTON_4)
DeviceIDMouseButton5 = uint32(C.RETRO_DEVICE_ID_MOUSE_BUTTON_5)
)

// Environment callback API. See libretro.h for details
const (
EnvironmentSetRotation = uint32(C.RETRO_ENVIRONMENT_SET_ROTATION)
Expand Down

0 comments on commit 038765b

Please sign in to comment.