diff options
author | Coşku Baş <cosku.bas@gmail.com> | 2015-01-19 22:36:17 +0200 |
---|---|---|
committer | Dmitri Shuralyov <shurcooL@gmail.com> | 2015-02-21 18:51:44 -0800 |
commit | 93e9a1d71456aba8b2ed774bfd48478e0be9b612 (patch) | |
tree | 30049adeb640fe7e02f57c15ecdfca061f91eb13 | |
parent | 50283a5bea2135e5f4a6eface65e4984a67a313b (diff) | |
download | glfw-93e9a1d71456aba8b2ed774bfd48478e0be9b612.tar.gz |
Convert non RGBA images to RGBA, use Image interface
-rw-r--r-- | input.go | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -15,6 +15,7 @@ import "C" import ( "image" + "image/draw" "unsafe" ) @@ -246,8 +247,6 @@ type Cursor struct { data *C.GLFWcursor } -type Image *image.NRGBA - //export goMouseButtonCB func goMouseButtonCB(window unsafe.Pointer, button, action, mods C.int) { w := windows.get((*C.GLFWwindow)(window)) @@ -371,12 +370,25 @@ func (w *Window) SetCursorPos(xpos, ypos float64) error { // // 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) { - var img C.GLFWimage - img.width = C.int(image.Rect.Max.X) - img.height = C.int(image.Rect.Max.Y) - img.pixels = (*C.uchar)(&image.Pix[0]) - c := C.glfwCreateCursor(&img, C.int(xhot), C.int(yhot)) +func CreateCursor(img image.Image, xhot, yhot int) (*Cursor, error) { + var img_c C.GLFWimage + var pixPointer *uint8 + b := img.Bounds() + + switch img := img.(type) { + case *image.RGBA: + pixPointer = &img.Pix[0] + default: + m := image.NewRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) + draw.Draw(m, m.Bounds(), img, b.Min, draw.Src) + pixPointer = &m.Pix[0] + } + + img_c.width = C.int(b.Dx()) + img_c.height = C.int(b.Dy()) + img_c.pixels = (*C.uchar)(pixPointer) + c := C.glfwCreateCursor(&img_c, C.int(xhot), C.int(yhot)) + return &Cursor{c}, fetchError() } |