/
handheld_device.go
74 lines (65 loc) · 1.79 KB
/
handheld_device.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package dev
import (
"github.com/geniot/jigsawpuzzle/internal/ctx"
"github.com/geniot/jigsawpuzzle/internal/glb"
"github.com/veandco/go-sdl2/sdl"
"strconv"
)
type HandheldDeviceImpl struct {
haptic *sdl.Haptic
joystick *sdl.Joystick
isRumbleSupported bool
}
func (handhelpDevice HandheldDeviceImpl) GetJoystickAxis(axis int) int16 {
return handhelpDevice.joystick.Axis(axis)
}
func (handhelpDevice HandheldDeviceImpl) Stop() {
handhelpDevice.joystick.Close()
handhelpDevice.haptic.Close()
closeCommon()
}
func (handhelpDevice HandheldDeviceImpl) ProcessKeyActions() {
_, ok1 := ctx.PressedKeysCodesSetIns[glb.GCW_BUTTON_L1]
_, ok2 := ctx.PressedKeysCodesSetIns[glb.GCW_BUTTON_START]
if ok1 && ok2 {
ctx.LoopIns.Stop()
}
}
func (handhelpDevice HandheldDeviceImpl) GetWindowPosAndSize() (int32, int32, int32, int32) {
return 0, 0, 320, 240
}
func (handhelpDevice HandheldDeviceImpl) GetWindowState() uint32 {
return sdl.WINDOW_SHOWN | sdl.WINDOW_BORDERLESS
}
func NewHandheldDevice() HandheldDeviceImpl {
device := HandheldDeviceImpl{}
device.init()
return device
}
func (handhelpDevice *HandheldDeviceImpl) init() {
initCommon()
numHaptics, err := sdl.NumHaptics()
if err != nil {
panic(err)
}
if numHaptics > 0 {
println("Haptics: " + strconv.Itoa(numHaptics))
println(sdl.HapticName(0))
handhelpDevice.haptic, err = sdl.HapticOpen(0)
if err != nil {
panic(err)
}
err = handhelpDevice.haptic.RumbleInit()
if err != nil {
panic(err)
}
handhelpDevice.isRumbleSupported, _ = handhelpDevice.haptic.RumbleSupported()
}
numJoysticks := sdl.NumJoysticks()
if numJoysticks > 0 {
println("Joysticks: " + strconv.Itoa(numJoysticks))
println(sdl.JoystickNameForIndex(0))
handhelpDevice.joystick = sdl.JoystickOpen(0)
}
sdl.JoystickEventState(sdl.ENABLE)
}