github.com/as/shiny@v0.8.2/event/mouse/mouse.go (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package mouse
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/as/shiny/event/key"
    11  )
    12  
    13  // Event is a mouse event.
    14  type Event struct {
    15  	// X and Y are the mouse location, in pixels.
    16  	X, Y float32
    17  
    18  	// Button is the mouse button being pressed or released. Its value may be
    19  	// zero, for a mouse move or drag without any button change.
    20  	Button Button
    21  
    22  	// TODO: have a field to hold what other buttons are down, for detecting
    23  	// drags or button-chords.
    24  
    25  	// Modifiers is a bitmask representing a set of modifier keys:
    26  	// key.ModShift, key.ModAlt, etc.
    27  	Modifiers key.Modifiers
    28  
    29  	// Direction is the direction of the mouse event: DirPress, DirRelease,
    30  	// or DirNone (for mouse moves or drags).
    31  	Direction Direction
    32  
    33  	// TODO: add a Device ID, for multiple input devices?
    34  	// TODO: add a time.Time?
    35  }
    36  
    37  // Button is a mouse button.
    38  type Button int32
    39  
    40  // IsWheel returns whether the button is for a scroll wheel.
    41  func (b Button) IsWheel() bool {
    42  	return b < 0
    43  }
    44  
    45  // TODO: have a separate axis concept for wheel up/down? How does that relate
    46  // to joystick events?
    47  
    48  const (
    49  	ButtonNone   Button = +0
    50  	ButtonLeft   Button = +1
    51  	ButtonMiddle Button = +2
    52  	ButtonRight  Button = +3
    53  
    54  	ButtonWheelUp    Button = -1
    55  	ButtonWheelDown  Button = -2
    56  	ButtonWheelLeft  Button = -3
    57  	ButtonWheelRight Button = -4
    58  )
    59  
    60  // Direction is the direction of the mouse event.
    61  type Direction uint8
    62  
    63  const (
    64  	DirNone    Direction = 0
    65  	DirPress   Direction = 1
    66  	DirRelease Direction = 2
    67  	// DirStep is a simultaneous press and release, such as a single step of a
    68  	// mouse wheel.
    69  	//
    70  	// Its value equals DirPress | DirRelease.
    71  	DirStep Direction = 3
    72  )
    73  
    74  func (d Direction) String() string {
    75  	switch d {
    76  	case DirNone:
    77  		return "None"
    78  	case DirPress:
    79  		return "Press"
    80  	case DirRelease:
    81  		return "Release"
    82  	case DirStep:
    83  		return "Step"
    84  	default:
    85  		return fmt.Sprintf("mouse.Direction(%d)", d)
    86  	}
    87  }