aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoşku Baş <cosku.bas@gmail.com>2015-01-19 09:21:58 +0100
committerDmitri Shuralyov <shurcooL@gmail.com>2015-02-21 18:51:43 -0800
commit2fdda4bd50688f74173abf590cd775cdf9fd7ed6 (patch)
tree5e9c1aa02499df1fe640cdf8dafac395d97096d1
parent9672e0b6bc9e3eb903f8fab1591d7984c45f2116 (diff)
downloadglfw-2fdda4bd50688f74173abf590cd775cdf9fd7ed6.tar.gz
Implement cursor stuff
-rw-r--r--input.go66
1 files changed, 64 insertions, 2 deletions
diff --git a/input.go b/input.go
index 658ef2f..2460467 100644
--- a/input.go
+++ b/input.go
@@ -202,6 +202,19 @@ const (
MouseButtonMiddle MouseButton = C.GLFW_MOUSE_BUTTON_MIDDLE
)
+// StandardCursor corresponds to a standard cursor icon.
+type StandardCursor int
+
+// Standard cursors
+const (
+ ArrowCursor StandardCursor = C.GLFW_ARROW_CURSOR
+ IBeamCursor StandardCursor = C.GLFW_IBEAM_CURSOR
+ CrosshairCursor StandardCursor = C.GLFW_CROSSHAIR_CURSOR
+ HandCursor StandardCursor = C.GLFW_HAND_CURSOR
+ HResizeCursor StandardCursor = C.GLFW_HRESIZE_CURSOR
+ VResizeCursor StandardCursor = C.GLFW_VRESIZE_CURSOR
+)
+
// Action corresponds to a key or button action.
type Action int
@@ -228,6 +241,14 @@ const (
CursorDisabled int = C.GLFW_CURSOR_DISABLED
)
+type Cursor struct {
+ data *C.GLFWcursor
+}
+
+type Image struct {
+ data *C.GLFWimage
+}
+
//export goMouseButtonCB
func goMouseButtonCB(window unsafe.Pointer, button, action, mods C.int) {
w := windows.get((*C.GLFWwindow)(window))
@@ -274,8 +295,8 @@ func goCharModsCB(window unsafe.Pointer, character C.uint, mods C.int) {
//export goDropCB
func goDropCB(window unsafe.Pointer, count C.int, names **C.char) { // TODO: The types of name can be `**C.char` or `unsafe.Pointer`, use whichever is better.
w := windows.get((*C.GLFWwindow)(window))
- namesSlice := make([]string, int(count)) // // TODO: Make this better. This part is unfinished, hacky, probably not correct, and not idiomatic.
- for i := 0; i < int(count); i++ { // // TODO: Make this better. It should be cleaned up and vetted.
+ namesSlice := make([]string, int(count)) // TODO: Make this better. This part is unfinished, hacky, probably not correct, and not idiomatic.
+ for i := 0; i < int(count); i++ { // TODO: Make this better. It should be cleaned up and vetted.
var x *C.char // TODO: Make this better.
p := (**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(names)) + uintptr(i)*unsafe.Sizeof(x))) // TODO: Make this better.
namesSlice[i] = C.GoString(*p) // TODO: Make this better.
@@ -343,6 +364,47 @@ func (w *Window) SetCursorPosition(xpos, ypos float64) error {
return fetchError()
}
+// Creates a new custom cursor image that can be set for a window with SetCursor.
+// The cursor can be destroyed with Destroy. Any remaining cursors are destroyed by Terminate.
+//
+// The pixels are 32-bit little-endian RGBA, i.e. eight bits per channel. They are arranged
+// canonically as packed sequential rows, starting from the top-left corner.
+//
+// The cursor hotspot is specified in pixels, relative to the upper-left corner of the cursor image.
+// Like all other coordinate systems in GLFW, the X-axis points to the right and the Y-axis points down.
+func CreateCursor(image *Image, xhot, yhot int) (*Cursor, error) {
+ c := C.glfwCreateCursor(image.data, C.int(xhot), C.int(yhot))
+ return &Cursor{c}, fetchError()
+}
+
+// Returns a cursor with a standard shape, that can be set for a window with SetCursor.
+func CreateStandardCursor(shape int) (*Cursor, error) {
+ c := C.glfwCreateStandardCursor(C.int(shape))
+ return &Cursor{c}, fetchError()
+}
+
+// This function destroys a cursor previously created with CreateCursor.
+// Any remaining cursors will be destroyed by Terminate.
+func (c *Cursor) Destroy() error {
+ C.glfwDestroyCursor(c.data)
+ return fetchError()
+}
+
+// This function sets the cursor image to be used when the cursor is over the client area
+// of the specified window. The set cursor will only be visible when the cursor mode of the
+// window is CursorNormal.
+//
+// On some platforms, the set cursor may not be visible unless the window also has input focus.
+func (w *Window) SetCursor(c *Cursor) error {
+ if c == nil {
+ C.glfwSetCursor(w.data, nil)
+ } else {
+ C.glfwSetCursor(w.data, c.data)
+ }
+
+ return fetchError()
+}
+
type KeyCallback func(w *Window, key Key, scancode int, action Action, mods ModifierKey)
// SetKeyCallback sets the key callback which is called when a key is pressed,