diff --git a/internal/glfw/input_unix.go b/internal/glfw/input_unix.go index ab34a8008..46cb8ba24 100644 --- a/internal/glfw/input_unix.go +++ b/internal/glfw/input_unix.go @@ -247,24 +247,19 @@ 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(img image.Image, xhot, yhot int) (*Cursor, error) { - var imgC C.GLFWimage - var pixels []uint8 b := img.Bounds() - switch img := img.(type) { - case *image.NRGBA: - pixels = img.Pix - default: - m := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) - draw.Draw(m, m.Bounds(), img, b.Min, draw.Src) - pixels = m.Pix - } + m := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) + draw.Draw(m, m.Bounds(), img, b.Min, draw.Src) + pixels := m.Pix pix, free := bytes(pixels) - imgC.width = C.int(b.Dx()) - imgC.height = C.int(b.Dy()) - imgC.pixels = (*C.uchar)(pix) + imgC := C.GLFWimage{ + width: C.int(b.Dx()), + height: C.int(b.Dy()), + pixels: (*C.uchar)(pix), + } c := C.glfwCreateCursor(&imgC, C.int(xhot), C.int(yhot)) diff --git a/internal/glfw/window_unix.go b/internal/glfw/window_unix.go index fd4cf15ac..8398be522 100644 --- a/internal/glfw/window_unix.go +++ b/internal/glfw/window_unix.go @@ -361,17 +361,11 @@ func (w *Window) SetIcon(images []image.Image) error { freePixels := make([]func(), count) for i, img := range images { - var pixels []uint8 b := img.Bounds() - switch img := img.(type) { - case *image.NRGBA: - pixels = img.Pix - default: - m := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) - draw.Draw(m, m.Bounds(), img, b.Min, draw.Src) - pixels = m.Pix - } + m := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) + draw.Draw(m, m.Bounds(), img, b.Min, draw.Src) + pixels := m.Pix pix, free := bytes(pixels) freePixels[i] = free