forked from zeozeozeo/microui-go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
input.go
67 lines (56 loc) · 1.32 KB
/
input.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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024 The Ebitengine Authors
package debugui
import (
"image"
"github.com/hajimehoshi/ebiten/v2"
)
func (c *Context) inputMouseMove(x, y int) {
c.mousePos = image.Pt(x, y)
}
func mouseButtonToInt(btn ebiten.MouseButton) int {
switch btn {
case ebiten.MouseButtonLeft:
return mouseLeft
case ebiten.MouseButtonRight:
return mouseRight
case ebiten.MouseButtonMiddle:
return mouseMiddle
}
return 0
}
func (c *Context) inputMouseDown(x, y int, btn ebiten.MouseButton) {
c.inputMouseMove(x, y)
c.mouseDown |= mouseButtonToInt(btn)
c.mousePressed |= mouseButtonToInt(btn)
}
func (c *Context) inputMouseUp(x, y int, btn ebiten.MouseButton) {
c.inputMouseMove(x, y)
c.mouseDown &= ^mouseButtonToInt(btn)
}
func (c *Context) inputScroll(x, y int) {
c.scrollDelta.X += x
c.scrollDelta.Y += y
}
func keyToInt(key ebiten.Key) int {
switch key {
case ebiten.KeyShift:
return keyShift
case ebiten.KeyControl:
return keyControl
case ebiten.KeyAlt:
return keyAlt
case ebiten.KeyBackspace:
return keyBackspace
case ebiten.KeyEnter:
return keyReturn
}
return 0
}
func (c *Context) inputKeyDown(key ebiten.Key) {
c.keyPressed |= keyToInt(key)
c.keyDown |= keyToInt(key)
}
func (c *Context) inputKeyUp(key ebiten.Key) {
c.keyDown &= ^keyToInt(key)
}