mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 20:42:07 +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.
|
// 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.
|
// 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) {
|
func CreateCursor(img image.Image, xhot, yhot int) (*Cursor, error) {
|
||||||
var imgC C.GLFWimage
|
|
||||||
var pixels []uint8
|
|
||||||
b := img.Bounds()
|
b := img.Bounds()
|
||||||
|
|
||||||
switch img := img.(type) {
|
m := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
|
||||||
case *image.NRGBA:
|
draw.Draw(m, m.Bounds(), img, b.Min, draw.Src)
|
||||||
pixels = img.Pix
|
pixels := m.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
|
|
||||||
}
|
|
||||||
|
|
||||||
pix, free := bytes(pixels)
|
pix, free := bytes(pixels)
|
||||||
|
|
||||||
imgC.width = C.int(b.Dx())
|
imgC := C.GLFWimage{
|
||||||
imgC.height = C.int(b.Dy())
|
width: C.int(b.Dx()),
|
||||||
imgC.pixels = (*C.uchar)(pix)
|
height: C.int(b.Dy()),
|
||||||
|
pixels: (*C.uchar)(pix),
|
||||||
|
}
|
||||||
|
|
||||||
c := C.glfwCreateCursor(&imgC, C.int(xhot), C.int(yhot))
|
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)
|
freePixels := make([]func(), count)
|
||||||
|
|
||||||
for i, img := range images {
|
for i, img := range images {
|
||||||
var pixels []uint8
|
|
||||||
b := img.Bounds()
|
b := img.Bounds()
|
||||||
|
|
||||||
switch img := img.(type) {
|
m := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
|
||||||
case *image.NRGBA:
|
draw.Draw(m, m.Bounds(), img, b.Min, draw.Src)
|
||||||
pixels = img.Pix
|
pixels := m.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
|
|
||||||
}
|
|
||||||
|
|
||||||
pix, free := bytes(pixels)
|
pix, free := bytes(pixels)
|
||||||
freePixels[i] = free
|
freePixels[i] = free
|
||||||
|
Loading…
Reference in New Issue
Block a user