github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/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 defines an event for mouse input.
     6  //
     7  // See the github.com/c-darwin/mobile/app package for details on the event model.
     8  package mouse // import "github.com/c-darwin/mobile/event/mouse"
     9  
    10  import (
    11  	"fmt"
    12  
    13  	"github.com/c-darwin/mobile/event/key"
    14  )
    15  
    16  // Event is a mouse event.
    17  type Event struct {
    18  	// X and Y are the mouse location, in pixels.
    19  	X, Y float32
    20  
    21  	// Button is the mouse button being pressed or released. Its value may be
    22  	// zero, for a mouse move or drag without any button change.
    23  	Button Button
    24  
    25  	// TODO: have a field to hold what other buttons are down, for detecting
    26  	// drags or button-chords.
    27  
    28  	// Modifiers is a bitmask representing a set of modifier keys:
    29  	// key.ModShift, key.ModAlt, etc.
    30  	Modifiers key.Modifiers
    31  
    32  	// Direction is the direction of the mouse event: DirPress, DirRelease,
    33  	// or DirNone (for mouse moves or drags).
    34  	Direction Direction
    35  
    36  	// TODO: add a Device ID, for multiple input devices?
    37  	// TODO: add a time.Time?
    38  }
    39  
    40  // Button is a mouse button.
    41  type Button int32
    42  
    43  // TODO: have a separate axis concept for wheel up/down? How does that relate
    44  // to joystick events?
    45  
    46  const (
    47  	ButtonNone      Button = +0
    48  	ButtonLeft      Button = +1
    49  	ButtonMiddle    Button = +2
    50  	ButtonRight     Button = +3
    51  	ButtonWheelUp   Button = -1
    52  	ButtonWheelDown Button = -2
    53  )
    54  
    55  // Direction is the direction of the mouse event.
    56  type Direction uint8
    57  
    58  const (
    59  	DirNone    Direction = 0
    60  	DirPress   Direction = 1
    61  	DirRelease Direction = 2
    62  )
    63  
    64  func (d Direction) String() string {
    65  	switch d {
    66  	case DirNone:
    67  		return "None"
    68  	case DirPress:
    69  		return "Press"
    70  	case DirRelease:
    71  		return "Release"
    72  	default:
    73  		return fmt.Sprintf("mouse.Direction(%d)", d)
    74  	}
    75  }