-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for manipulating cursors (#114)
Adding support for manipulating cursors
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package opengl | ||
|
||
import ( | ||
"image" | ||
"runtime" | ||
|
||
"github.com/go-gl/glfw/v3.3/glfw" | ||
"github.com/gopxl/mainthread/v2" | ||
"github.com/gopxl/pixel/v2" | ||
) | ||
|
||
type StandardCursor int | ||
|
||
const ( | ||
ArrowCursor = StandardCursor(glfw.ArrowCursor) | ||
IBeamCursor = StandardCursor(glfw.IBeamCursor) | ||
CrosshairCursor = StandardCursor(glfw.CrosshairCursor) | ||
HandCursor = StandardCursor(glfw.HandCursor) | ||
HResizeCursor = StandardCursor(glfw.HResizeCursor) | ||
VResizeCursor = StandardCursor(glfw.VResizeCursor) | ||
) | ||
|
||
type Cursor = glfw.Cursor | ||
|
||
// CreateStandardCursor creates a new standard cursor. | ||
func CreateStandardCursor(cursorId StandardCursor) *Cursor { | ||
c := mainthread.CallVal(func() *Cursor { | ||
return glfw.CreateStandardCursor(glfw.StandardCursor(cursorId)) | ||
}) | ||
runtime.SetFinalizer(c, (*Cursor).Destroy) | ||
return c | ||
} | ||
|
||
// CreateCursorImage creates a new cursor from an image with the specified hotspot (where the click is registered). | ||
func CreateCursorImage(img image.Image, hot pixel.Vec) *Cursor { | ||
c := mainthread.CallVal(func() *Cursor { | ||
return glfw.CreateCursor(img, int(hot.X), int(hot.Y)) | ||
}) | ||
runtime.SetFinalizer(c, (*Cursor).Destroy) | ||
return c | ||
} | ||
|
||
// SetCursor sets the cursor for the window. | ||
func (w *Window) SetCursor(cursor *Cursor) { | ||
mainthread.Call(func() { | ||
w.window.SetCursor(cursor) | ||
w.cursor = cursor | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters