From 42d1711bfb7538720615315293501788125ee8e4 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 19 Dec 2020 10:39:04 -0500 Subject: [PATCH] Set window icon. --- src-c/gui/jes_icon-32x32.h | 8 ------ .../jes_icon-32x32.c => src/jes/gui/icon.d | 7 +++-- src/jes/gui/window.d | 27 +++++++++++++++++-- src/jtk/window.d | 5 ++++ 4 files changed, 33 insertions(+), 14 deletions(-) delete mode 100644 src-c/gui/jes_icon-32x32.h rename src-c/gui/jes_icon-32x32.c => src/jes/gui/icon.d (99%) diff --git a/src-c/gui/jes_icon-32x32.h b/src-c/gui/jes_icon-32x32.h deleted file mode 100644 index c007213..0000000 --- a/src-c/gui/jes_icon-32x32.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef JES_ICON_32X32_H -#define JES_ICON_32X32_H - -#include - -extern const uint8_t jes_icon_32x32[]; - -#endif diff --git a/src-c/gui/jes_icon-32x32.c b/src/jes/gui/icon.d similarity index 99% rename from src-c/gui/jes_icon-32x32.c rename to src/jes/gui/icon.d index 1e1be75..1363083 100644 --- a/src-c/gui/jes_icon-32x32.c +++ b/src/jes/gui/icon.d @@ -1,8 +1,8 @@ -#include "jes_icon-32x32.h" +module jes.gui.icon; /* GIMP RGB C-Source image dump (jes_icon-32x32.c) */ -const uint8_t jes_icon_32x32[] = { +const string jes_icon_32x32 = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" @@ -95,5 +95,4 @@ const uint8_t jes_icon_32x32[] = { "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" - "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", -}; + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"; diff --git a/src/jes/gui/window.d b/src/jes/gui/window.d index 950a30b..1518a64 100644 --- a/src/jes/gui/window.d +++ b/src/jes/gui/window.d @@ -1,5 +1,6 @@ module jes.gui.window; +static import jes.gui.icon; static import jtk; import jes.gui.font; import jes.gui.gl; @@ -28,7 +29,7 @@ class Window void resize(int width, int height) { - load_gl(); + map_window(); m_gl.resize(width, height); draw(); } @@ -42,11 +43,12 @@ class Window m_window.swap_buffers(); } - private void load_gl() + private void map_window() { if (m_gl is null) { m_gl = new Gl(); + set_window_icon(); } } @@ -54,4 +56,25 @@ class Window { return jtk_windows[jtk_window]; } + + private void set_window_icon() + { + const(ubyte) * in_icon = cast(const(ubyte) *)jes.gui.icon.jes_icon_32x32.ptr; + ubyte[] icon_bgra = new ubyte[32u * 32u * 4u]; + ubyte * out_icon = icon_bgra.ptr; + for (uint row = 0u; row < 32u; row++) + { + for (uint col = 0u; col < 32u; col++) + { + ubyte r = *in_icon++; + ubyte g = *in_icon++; + ubyte b = *in_icon++; + *out_icon++ = b; + *out_icon++ = g; + *out_icon++ = r; + *out_icon++ = 0xFFu; + } + } + m_window.set_icon(icon_bgra.ptr, 32u, 32u); + } } diff --git a/src/jtk/window.d b/src/jtk/window.d index d689ec8..6cb0766 100644 --- a/src/jtk/window.d +++ b/src/jtk/window.d @@ -45,6 +45,11 @@ class Window } } + void set_icon(const ubyte * data, size_t width, size_t height) + { + jtk_window_set_icon(m_window, data, width, height); + } + void set_title(string title) { jtk_window_set_title(m_window, title.toStringz());