From 947fbe0a2e63660c99adfb3bce9fef7daf7ea12b Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 31 Dec 2018 04:59:06 +0900 Subject: [PATCH] glwf: Implement SetIcon --- internal/glfw/glfw_windows.go | 41 +++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/internal/glfw/glfw_windows.go b/internal/glfw/glfw_windows.go index aab716ea5..dae189b9e 100644 --- a/internal/glfw/glfw_windows.go +++ b/internal/glfw/glfw_windows.go @@ -16,6 +16,7 @@ package glfw import ( "image" + "image/draw" "runtime" "sync" "unsafe" @@ -23,6 +24,21 @@ import ( "golang.org/x/sys/windows" ) +type glfwVidMode struct { + width int32 + height int32 + redBits int32 + greenBits int32 + blueBits int32 + refreshRate int32 +} + +type glfwImage struct { + width int32 + height int32 + pixels uintptr +} + type glfwWindows map[uintptr]*Window var ( @@ -57,15 +73,6 @@ func (w glfwWindows) get(win uintptr) *Window { return ww } -type glfwVidMode struct { - width int32 - height int32 - redBits int32 - greenBits int32 - blueBits int32 - refreshRate int32 -} - type Monitor struct { m uintptr } @@ -197,10 +204,20 @@ func (w *Window) SetScrollCallback(cbfun ScrollCallback) (previous ScrollCallbac } func (w *Window) SetIcon(images []image.Image) { - // TODO: Implement this + gimgs := make([]glfwImage, len(images)) + defer runtime.KeepAlive(gimgs) - // glfwDLL.call("glfwSetWindowIcon", w.w, l, p) - // panicError() + for i, img := range images { + b := img.Bounds() + m := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) + draw.Draw(m, m.Bounds(), img, b.Min, draw.Src) + gimgs[i].width = int32(b.Dx()) + gimgs[i].height = int32(b.Dy()) + gimgs[i].pixels = uintptr(unsafe.Pointer(&m.Pix[0])) + } + + glfwDLL.call("glfwSetWindowIcon", w.w, uintptr(len(gimgs)), uintptr(unsafe.Pointer(&gimgs[0]))) + panicError() } func (w *Window) SetInputMode(mode InputMode, value int) {