Skip to content

Commit

Permalink
implement @chrisplatorres's STB-based idea for decoding/setting the a…
Browse files Browse the repository at this point in the history
…pp icon
  • Loading branch information
humbletim committed Sep 1, 2019
1 parent cd3b34d commit 126da6b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions deps/exokit-bindings/glfw/src/glfw.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <glfw/include/glfw.h>
#include <windowsystem.h>
#include <webgl.h>
#include "canvas/src/stb_image.h"

#include <exout>

Expand Down Expand Up @@ -969,6 +970,18 @@ NAN_METHOD(SetCurrentWindowContext) {
SetCurrentWindowContext(window);
}

bool SetNativeWindowIcon(NATIVEwindow* window, const char* filename) {
GLFWimage icon;
int components;
icon.pixels = stbi_load(filename, &icon.width, &icon.height, &components, STBI_rgb_alpha);
if (icon.pixels != nullptr) {
glfwSetWindowIcon(window, 1, &icon);
stbi_image_free(icon.pixels);
return true;
}
return false;
}

NATIVEwindow *CreateNativeWindow(unsigned int width, unsigned int height, bool visible) {
glfwWindowHint(GLFW_VISIBLE, visible);

Expand All @@ -989,6 +1002,7 @@ NATIVEwindow *CreateNativeWindow(unsigned int width, unsigned int height, bool v
NATIVEwindow *window = glfwCreateWindow(width, height, "Exokit", nullptr, sharedWindow);
if (window) {
glfwSetWindowUserPointer(window, new WindowState());
SetNativeWindowIcon(window, "assets/icon.png");
return window;
} else {
exerr << "Can't create GLFW window" << std::endl;
Expand Down

0 comments on commit 126da6b

Please sign in to comment.