/
mouse.go
87 lines (70 loc) · 1.96 KB
/
mouse.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
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mouse
import (
"fmt"
"github.com/as/shiny/event/key"
)
// Event is a mouse event.
type Event struct {
// X and Y are the mouse location, in pixels.
X, Y float32
// Button is the mouse button being pressed or released. Its value may be
// zero, for a mouse move or drag without any button change.
Button Button
// TODO: have a field to hold what other buttons are down, for detecting
// drags or button-chords.
// Modifiers is a bitmask representing a set of modifier keys:
// key.ModShift, key.ModAlt, etc.
Modifiers key.Modifiers
// Direction is the direction of the mouse event: DirPress, DirRelease,
// or DirNone (for mouse moves or drags).
Direction Direction
// TODO: add a Device ID, for multiple input devices?
// TODO: add a time.Time?
}
// Button is a mouse button.
type Button int32
// IsWheel returns whether the button is for a scroll wheel.
func (b Button) IsWheel() bool {
return b < 0
}
// TODO: have a separate axis concept for wheel up/down? How does that relate
// to joystick events?
const (
ButtonNone Button = +0
ButtonLeft Button = +1
ButtonMiddle Button = +2
ButtonRight Button = +3
ButtonWheelUp Button = -1
ButtonWheelDown Button = -2
ButtonWheelLeft Button = -3
ButtonWheelRight Button = -4
)
// Direction is the direction of the mouse event.
type Direction uint8
const (
DirNone Direction = 0
DirPress Direction = 1
DirRelease Direction = 2
// DirStep is a simultaneous press and release, such as a single step of a
// mouse wheel.
//
// Its value equals DirPress | DirRelease.
DirStep Direction = 3
)
func (d Direction) String() string {
switch d {
case DirNone:
return "None"
case DirPress:
return "Press"
case DirRelease:
return "Release"
case DirStep:
return "Step"
default:
return fmt.Sprintf("mouse.Direction(%d)", d)
}
}