Beispiel #1
0
func (i *input) update(window *glfw.Window, scale int) error {
	for g, e := range glfwKeyCodeToKey {
		i.keyPressed[e] = window.GetKey(g) == glfw.Press
	}
	for g, e := range glfwMouseButtonToMouseButton {
		i.mouseButtonPressed[e] = window.GetMouseButton(g) == glfw.Press
	}
	x, y := window.GetCursorPos()
	i.cursorX = int(math.Floor(x)) / scale
	i.cursorY = int(math.Floor(y)) / scale
	for id := glfw.Joystick(0); id < glfw.Joystick(len(i.gamepads)); id++ {
		if !glfw.JoystickPresent(id) {
			continue
		}
		axes32 := glfw.GetJoystickAxes(id)
		i.gamepads[id].axisNum = len(axes32)
		for a := 0; a < len(i.gamepads[id].axes); a++ {
			if len(axes32) <= a {
				i.gamepads[id].axes[a] = 0
				continue
			}
			i.gamepads[id].axes[a] = float64(axes32[a])
		}
		buttons := glfw.GetJoystickButtons(id)
		i.gamepads[id].buttonNum = len(buttons)
		for b := 0; b < len(i.gamepads[id].buttonPressed); b++ {
			if len(buttons) <= b {
				i.gamepads[id].buttonPressed[b] = false
				continue
			}
			i.gamepads[id].buttonPressed[b] = glfw.Action(buttons[b]) == glfw.Press
		}
	}
	return nil
}
Beispiel #2
0
func (state *State) UpdateInput(window *glfw.Window) {
	state.Input.Update()

	x, y := window.GetCursorPos()
	state.Input.Mouse.Position.X = float32(x)
	state.Input.Mouse.Position.Y = float32(y)
	state.Input.Mouse.Down = window.GetMouseButton(glfw.MouseButtonLeft) == glfw.Press
}
Beispiel #3
0
func onMouseClick(w *glfw.Window, button glfw.MouseButton, action glfw.Action, mod glfw.ModifierKey) {
	if currentScreen != nil {
		if button != glfw.MouseButtonLeft || action == glfw.Repeat {
			return
		}
		width, height := w.GetSize()
		xpos, ypos := w.GetCursorPos()
		fw, fh := w.GetFramebufferSize()
		currentScreen.click(action == glfw.Press, xpos*(float64(fw)/float64(width)), ypos*(float64(fh)/float64(height)), fw, fh)
		return
	}
	if !Client.chat.enteringText && lockMouse && action != glfw.Repeat {
		Client.MouseAction(button, action == glfw.Press)
	}
	if button == glfw.MouseButtonLeft && action == glfw.Press && !Client.chat.enteringText {
		lockMouse = true
		w.SetInputMode(glfw.CursorMode, glfw.CursorDisabled)
	}
}