From 4c817d7c20f95a89a22f15566e9b8c8009bb0133 Mon Sep 17 00:00:00 2001
From: Stephen Michaelis <stephen.michaelis@hotmail.com>
Date: Sat, 19 Jan 2019 10:24:01 -0500
Subject: [PATCH] adding mouse operations

---
 pixelgl/input.go  | 30 ++++++++++++++++++++++++++++++
 pixelgl/window.go |  1 +
 2 files changed, 31 insertions(+)

diff --git a/pixelgl/input.go b/pixelgl/input.go
index a2ef808..01eeb62 100644
--- a/pixelgl/input.go
+++ b/pixelgl/input.go
@@ -33,6 +33,32 @@ func (w *Window) MousePosition() pixel.Vec {
 	return w.currInp.mouse
 }
 
+// MousePreviousPosition returns the previous mouse position in the Window's Bounds.
+func (w *Window) MousePreviousPosition() pixel.Vec {
+	return w.prevInp.mouse
+}
+
+// SetMousePosition positions the mouse cursor anywhere within the Window's Bounds.
+func (w *Window) SetMousePosition(v pixel.Vec) {
+	mainthread.Call(func() {
+		if (v.X >= 0 && v.X <= w.bounds.W()) &&
+			(v.Y >= 0 && v.Y <= w.bounds.H()) {
+			w.window.SetCursorPos(
+				v.X+w.bounds.Min.X,
+				(w.bounds.H()-v.Y)+w.bounds.Min.Y,
+			)
+			w.prevInp.mouse = v
+			w.currInp.mouse = v
+			w.tempInp.mouse = v
+		}
+	})
+}
+
+// MouseEntered returns true if the mouse position is within the Window's Bounds.
+func (w *Window) MouseEntered() bool {
+	return w.cursorEntered
+}
+
 // MouseScroll returns the mouse scroll amount (in both axes) since the last call to Window.Update.
 func (w *Window) MouseScroll() pixel.Vec {
 	return w.currInp.scroll
@@ -354,6 +380,10 @@ func (w *Window) initInput() {
 			}
 		})
 
+		w.window.SetCursorEnterCallback(func(_ *glfw.Window, entered bool) {
+			w.cursorEntered = entered
+		})
+
 		w.window.SetCursorPosCallback(func(_ *glfw.Window, x, y float64) {
 			w.tempInp.mouse = pixel.V(
 				x+w.bounds.Min.X,
diff --git a/pixelgl/window.go b/pixelgl/window.go
index c124152..7fb4dda 100644
--- a/pixelgl/window.go
+++ b/pixelgl/window.go
@@ -59,6 +59,7 @@ type Window struct {
 	canvas        *Canvas
 	vsync         bool
 	cursorVisible bool
+	cursorEntered bool
 
 	// need to save these to correctly restore a fullscreen window
 	restore struct {
-- 
GitLab