mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/glfw: bug fix: always use draw.Draw for any images
Closes #2807
This commit is contained in:
parent
1e5086fd5a
commit
54c6c6b728
@ -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))
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user