internal/glfw: bug fix: always use draw.Draw for any images

Closes #2807
This commit is contained in:
Hajime Hoshi 2023-10-11 01:02:38 +09:00
parent 1e5086fd5a
commit 54c6c6b728
2 changed files with 11 additions and 22 deletions

View File

@ -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))

View File

@ -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