Skip to content

Commit

Permalink
cocoa: populate MouseMoveEvent.From field
Browse files Browse the repository at this point in the history
Merge branch 'ricochet2200/From_OSX'.
Fixes #42. Closes #43.
  • Loading branch information
sqweek committed Aug 17, 2015
2 parents 90f9da5 + 0b6f6f3 commit e8d704a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Laurent Le Goff <legoff.laurent@gmail.com>
Amanda Cameron <me@amanda.darkdna.net>
sqweek <sqweek@gmail.com>
Carlos Castillo <cookieo9@gmail.com>
Rick Smith <ricochet2200@yahoo.com>
39 changes: 35 additions & 4 deletions cocoa/events_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import "C"
import (
"fmt"
"github.com/skelterjohn/go.wde"
"image"
// "strings"
)

Expand All @@ -47,6 +48,10 @@ func (w *Window) EventChan() (events <-chan interface{}) {
downKeys := make(map[string]bool)
ec := make(chan interface{})
go func(ec chan<- interface{}) {

noXY := image.Point{-1, -1}
lastXY := noXY

eventloop:
for {
e := C.getNextEvent(w.cw)
Expand All @@ -58,37 +63,63 @@ func (w *Window) EventChan() (events <-chan interface{}) {
mde.Where.X = int(e.data[0])
mde.Where.Y = int(e.data[1])
mde.Which = getButton(int(e.data[2]))
lastXY = mde.Where
ec <- mde
case C.GMDMouseUp:
var mue wde.MouseUpEvent
mue.Where.X = int(e.data[0])
mue.Where.Y = int(e.data[1])
mue.Which = getButton(int(e.data[2]))
lastXY = mue.Where
ec <- mue
case C.GMDMouseDragged:
var mde wde.MouseDraggedEvent
mde.Where.X = int(e.data[0])
mde.Where.Y = int(e.data[1])
mde.Which = getButton(int(e.data[2]))
if lastXY != noXY {
mde.From = lastXY
} else {
mde.From = mde.Where
}
lastXY = mde.Where
ec <- mde
case C.GMDMouseMoved:
var me wde.MouseMovedEvent
me.Where.X = int(e.data[0])
me.Where.Y = int(e.data[1])
ec <- me
var mme wde.MouseMovedEvent
mme.Where.X = int(e.data[0])
mme.Where.Y = int(e.data[1])
if lastXY != noXY {
mme.From = lastXY
} else {
mme.From = mme.Where
}
lastXY = mme.Where
ec <- mme
case C.GMDMouseEntered:
w.hasMouse = true
setCursor(w.cursor)
var me wde.MouseEnteredEvent
me.Where.X = int(e.data[0])
me.Where.Y = int(e.data[1])
if lastXY != noXY {
me.From = lastXY
} else {
me.From = me.Where
}
lastXY = me.Where
ec <- me
case C.GMDMouseExited:
w.hasMouse = false
setCursor(wde.NormalCursor)
var me wde.MouseExitedEvent
me.Where.X = int(e.data[0])
me.Where.Y = int(e.data[1])
if lastXY != noXY {
me.From = lastXY
} else {
me.From = me.Where
}
lastXY = me.Where
ec <- me
case C.GMDMainFocus:
// for some reason Cocoa resets the cursor to normal when the window
Expand Down

0 comments on commit e8d704a

Please sign in to comment.