From ea7bc5aff96dc09c0bef73415ece97d95fa277a1 Mon Sep 17 00:00:00 2001 From: Ousmane Traore Date: Sun, 30 Apr 2017 17:19:51 -0400 Subject: [PATCH] Add Icons paramter to window config --- pixelgl/window.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pixelgl/window.go b/pixelgl/window.go index 65c95f9..d703e45 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -4,6 +4,8 @@ import ( "image/color" "runtime" + "image" + "github.com/faiface/glhf" "github.com/faiface/mainthread" "github.com/faiface/pixel" @@ -20,6 +22,16 @@ type WindowConfig struct { // Title at the top of the Window. Title string + // Icons specifies the icon images used by the window. This is usually displayed + // in the top bar of the window or in the task bar of the desktop environment. + // If passed one image, it will use that image, if passed an array of images + // those of or closest to the sizes desired by the system are selected. + // The desired image sizes varies depending on platform and system settings. The selected + // images will be rescaled as needed. Good sizes include 16x16, 32x32 and 48x48. + // NOTE: Setting this value doesn't have an effect on OSX. You'll need to set the icon + // when bundling your application for release. + Icons []pixel.Picture + // Bounds specify the bounds of the Window in pixels. Bounds pixel.Rect @@ -118,7 +130,16 @@ func NewWindow(cfg WindowConfig) (*Window, error) { w.Update() runtime.SetFinalizer(w, (*Window).Destroy) - + if len(cfg.Icons) > 0 { + var imgs []image.Image + for _, v := range cfg.Icons { + pic := pixel.PictureDataFromPicture(v) + imgs = append(imgs, pic.Image()) + } + mainthread.Call(func() { + w.window.SetIcon(imgs) + }) + } return w, nil }