Set window icon.

This commit is contained in:
Josh Holtrop 2020-12-19 10:39:04 -05:00
parent 14b448d8fb
commit 42d1711bfb
4 changed files with 33 additions and 14 deletions

View File

@ -1,8 +0,0 @@
#ifndef JES_ICON_32X32_H
#define JES_ICON_32X32_H
#include <stdint.h>
extern const uint8_t jes_icon_32x32[];
#endif

View File

@ -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";

View File

@ -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);
}
}

View File

@ -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());