示例#1
0
文件: glfw.go 项目: andrebq/glfw
// JoystickButtons queries the current state of one or more buttons of a joystick.
// The button states are returned in an array, where the first element
// represents the first button of the joystick. Each state can be either
// glfw.Pressed or glfw.Released.
//
// Note: If len(buttons) exceeds the number of buttons supported by the joystick,
// or if the joystick is not available, the unused elements in the buttons array
// will be set to glfw.Released.
//
// Note: The function returns the number of actually returned buttons. This is
// the minimum of len(buttons) and the number of buttons supported by the
// joystick. If the joystick is not supported or connected, the function will
// return 0 (zero).
func JoystickButtons(joy int, buttons []byte) int {
	if len(buttons) == 0 {
		return 0
	}

	return int(C.glfwGetJoystickButtons(C.int(joy),
		(*C.uchar)(unsafe.Pointer(&buttons[0])), C.int(len(buttons))))
}
示例#2
0
文件: glfw.go 项目: skelterjohn/glfw
func JoystickButtons(joy, numbuttons int) []byte {
	ptr := (*_Ctype_unsignedchar)(C.malloc(C.size_t(C.int(numbuttons))))
	defer C.free(unsafe.Pointer(ptr))

	var count C.int
	if count = C.glfwGetJoystickButtons(C.int(joy), ptr, C.int(numbuttons)); count == 0 {
		return nil
	}

	b := make([]byte, count)
	copy(b, (*(*[1<<31 - 1]byte)(unsafe.Pointer(ptr)))[:count])
	return b
}
示例#3
0
文件: input.go 项目: godispy/glfw
// GetJoystickButtons returns a slice of button values.
func GetJoystickButtons(joy Joystick) []byte {
	var length int

	buttons := C.glfwGetJoystickButtons(C.int(joy), (*C.int)(unsafe.Pointer(&length)))
	panicError()
	if buttons == nil {
		return nil
	}

	b := make([]byte, length)
	for i := 0; i < length; i++ {
		b[i] = byte(C.GetButtonsAtIndex(buttons, C.int(i)))
	}
	return b
}
示例#4
0
//GetJoystickButtons returns a slice of button values.
func GetJoystickButtons(joy Joystick) ([]byte, error) {
	var length int

	buttons := C.glfwGetJoystickButtons(C.int(joy), (*C.int)(unsafe.Pointer(&length)))
	if buttons == nil {
		return nil, errors.New("Joystick is not present.")
	}

	b := make([]byte, length)
	for i := 0; i < length; i++ {
		b[i] = byte(C.GetButtonsAtIndex(buttons, C.int(i)))
	}

	return b, nil
}