embed fonts

main
Brett 2023-12-26 21:14:01 -05:00
parent e4676f46ce
commit ee053255ae
11 changed files with 21143 additions and 5 deletions

View File

@ -1,12 +1,18 @@
#pragma once
#include "IconsFontAwesome5.h" // from https://github.com/juliettef/IconFontCppHeaders
#include "imgui_spectrum.h"
#include <imgui.h>
#include <cmath>
extern const char fontAwesomeRegular_compressed_data_base85[];
extern const unsigned int fontAwesomeSolid_compressed_data[];
extern const unsigned int fontAwesomeSolid_compressed_size;
extern const unsigned int fontAwesomeBrands_compressed_size;
extern const unsigned int fontAwesomeBrands_compressed_data[];
namespace ImGui
{
inline void SetupImGuiStyle( bool bStyleDark_, float alpha_ )
{
ImGuiStyle& style = ImGui::GetStyle();
@ -178,7 +184,7 @@ namespace ImGui
int GetBin( float time_ )
{
int bin = (int)floor( time_ / dT );
int bin = (int)std::floor( time_ / dT );
if( bin >= NUM )
{
bin = NUM - 1;

View File

@ -0,0 +1,212 @@
#pragma once
/*
Color definitions in ImGui are a good starting point,
but do not cover all the intricacies of Spectrum's possible colors
in controls and widgets.
One big difference is that ImGui communicates widget activity
(hover, pressed) with their background, while spectrum uses a mix
of background and border, with border being the most common choice.
Because of this, we reference extra colors in spectrum from
imgui.cpp and imgui_widgets.cpp directly, and to make that work,
we need to have them defined at here at compile time.
*/
/// Pick one, or have one defined already.
#if !defined(SPECTRUM_USE_LIGHT_THEME) && !defined(SPECTRUM_USE_DARK_THEME)
#define SPECTRUM_USE_DARK_THEME
//#define SPECTRUM_USE_DARK_THEME
#endif
namespace ImGui {
namespace Spectrum {
// a list of changes introduced to change the look of the widgets.
// Collected here as const rather than being magic numbers spread
// around imgui.cpp and imgui_widgets.cpp.
const float CHECKBOX_BORDER_SIZE = 2.0f;
const float CHECKBOX_ROUNDING = 2.0f;
// Load SourceSansProRegular and sets it as a default font.
// You may want to call ImGui::GetIO().Fonts->Clear() before this
void LoadFont(float size = 16.0f);
// Sets the ImGui style to Spectrum
void StyleColorsSpectrum();
namespace { // Unnamed namespace, since we only use this here.
unsigned int Color(unsigned int c) {
// add alpha.
// also swap red and blue channel for some reason.
// todo: figure out why, and fix it.
const short a = 0xFF;
const short r = (c >> 16) & 0xFF;
const short g = (c >> 8) & 0xFF;
const short b = (c >> 0) & 0xFF;
return(a << 24)
| (r << 0)
| (g << 8)
| (b << 16);
}
}
// all colors are from http://spectrum.corp.adobe.com/color.html
inline unsigned int color_alpha(unsigned int alpha, unsigned int c) {
return ((alpha & 0xFF) << 24) | (c & 0x00FFFFFF);
}
namespace Static { // static colors
const unsigned int NONE = 0x00000000; // transparent
const unsigned int WHITE = Color(0xFFFFFF);
const unsigned int BLACK = Color(0x000000);
const unsigned int GRAY200 = Color(0xF4F4F4);
const unsigned int GRAY300 = Color(0xEAEAEA);
const unsigned int GRAY400 = Color(0xD3D3D3);
const unsigned int GRAY500 = Color(0xBCBCBC);
const unsigned int GRAY600 = Color(0x959595);
const unsigned int GRAY700 = Color(0x767676);
const unsigned int GRAY800 = Color(0x505050);
const unsigned int GRAY900 = Color(0x323232);
const unsigned int BLUE400 = Color(0x378EF0);
const unsigned int BLUE500 = Color(0x2680EB);
const unsigned int BLUE600 = Color(0x1473E6);
const unsigned int BLUE700 = Color(0x0D66D0);
const unsigned int RED400 = Color(0xEC5B62);
const unsigned int RED500 = Color(0xE34850);
const unsigned int RED600 = Color(0xD7373F);
const unsigned int RED700 = Color(0xC9252D);
const unsigned int ORANGE400 = Color(0xF29423);
const unsigned int ORANGE500 = Color(0xE68619);
const unsigned int ORANGE600 = Color(0xDA7B11);
const unsigned int ORANGE700 = Color(0xCB6F10);
const unsigned int GREEN400 = Color(0x33AB84);
const unsigned int GREEN500 = Color(0x2D9D78);
const unsigned int GREEN600 = Color(0x268E6C);
const unsigned int GREEN700 = Color(0x12805C);
}
#ifdef SPECTRUM_USE_LIGHT_THEME
const unsigned int GRAY50 = Color(0xFFFFFF);
const unsigned int GRAY75 = Color(0xFAFAFA);
const unsigned int GRAY100 = Color(0xF5F5F5);
const unsigned int GRAY200 = Color(0xEAEAEA);
const unsigned int GRAY300 = Color(0xE1E1E1);
const unsigned int GRAY400 = Color(0xCACACA);
const unsigned int GRAY500 = Color(0xB3B3B3);
const unsigned int GRAY600 = Color(0x8E8E8E);
const unsigned int GRAY700 = Color(0x707070);
const unsigned int GRAY800 = Color(0x4B4B4B);
const unsigned int GRAY900 = Color(0x2C2C2C);
const unsigned int BLUE400 = Color(0x2680EB);
const unsigned int BLUE500 = Color(0x1473E6);
const unsigned int BLUE600 = Color(0x0D66D0);
const unsigned int BLUE700 = Color(0x095ABA);
const unsigned int RED400 = Color(0xE34850);
const unsigned int RED500 = Color(0xD7373F);
const unsigned int RED600 = Color(0xC9252D);
const unsigned int RED700 = Color(0xBB121A);
const unsigned int ORANGE400 = Color(0xE68619);
const unsigned int ORANGE500 = Color(0xDA7B11);
const unsigned int ORANGE600 = Color(0xCB6F10);
const unsigned int ORANGE700 = Color(0xBD640D);
const unsigned int GREEN400 = Color(0x2D9D78);
const unsigned int GREEN500 = Color(0x268E6C);
const unsigned int GREEN600 = Color(0x12805C);
const unsigned int GREEN700 = Color(0x107154);
const unsigned int INDIGO400 = Color(0x6767EC);
const unsigned int INDIGO500 = Color(0x5C5CE0);
const unsigned int INDIGO600 = Color(0x5151D3);
const unsigned int INDIGO700 = Color(0x4646C6);
const unsigned int CELERY400 = Color(0x44B556);
const unsigned int CELERY500 = Color(0x3DA74E);
const unsigned int CELERY600 = Color(0x379947);
const unsigned int CELERY700 = Color(0x318B40);
const unsigned int MAGENTA400 = Color(0xD83790);
const unsigned int MAGENTA500 = Color(0xCE2783);
const unsigned int MAGENTA600 = Color(0xBC1C74);
const unsigned int MAGENTA700 = Color(0xAE0E66);
const unsigned int YELLOW400 = Color(0xDFBF00);
const unsigned int YELLOW500 = Color(0xD2B200);
const unsigned int YELLOW600 = Color(0xC4A600);
const unsigned int YELLOW700 = Color(0xB79900);
const unsigned int FUCHSIA400 = Color(0xC038CC);
const unsigned int FUCHSIA500 = Color(0xB130BD);
const unsigned int FUCHSIA600 = Color(0xA228AD);
const unsigned int FUCHSIA700 = Color(0x93219E);
const unsigned int SEAFOAM400 = Color(0x1B959A);
const unsigned int SEAFOAM500 = Color(0x16878C);
const unsigned int SEAFOAM600 = Color(0x0F797D);
const unsigned int SEAFOAM700 = Color(0x096C6F);
const unsigned int CHARTREUSE400 = Color(0x85D044);
const unsigned int CHARTREUSE500 = Color(0x7CC33F);
const unsigned int CHARTREUSE600 = Color(0x73B53A);
const unsigned int CHARTREUSE700 = Color(0x6AA834);
const unsigned int PURPLE400 = Color(0x9256D9);
const unsigned int PURPLE500 = Color(0x864CCC);
const unsigned int PURPLE600 = Color(0x7A42BF);
const unsigned int PURPLE700 = Color(0x6F38B1);
#endif
#ifdef SPECTRUM_USE_DARK_THEME
const unsigned int GRAY50 = Color(0x252525);
const unsigned int GRAY75 = Color(0x2F2F2F);
const unsigned int GRAY100 = Color(0x323232);
const unsigned int GRAY200 = Color(0x393939);
const unsigned int GRAY300 = Color(0x3E3E3E);
const unsigned int GRAY400 = Color(0x4D4D4D);
const unsigned int GRAY500 = Color(0x5C5C5C);
const unsigned int GRAY600 = Color(0x7B7B7B);
const unsigned int GRAY700 = Color(0x999999);
const unsigned int GRAY800 = Color(0xCDCDCD);
const unsigned int GRAY900 = Color(0xFFFFFF);
const unsigned int BLUE400 = Color(0x2680EB);
const unsigned int BLUE500 = Color(0x378EF0);
const unsigned int BLUE600 = Color(0x4B9CF5);
const unsigned int BLUE700 = Color(0x5AA9FA);
const unsigned int RED400 = Color(0xE34850);
const unsigned int RED500 = Color(0xEC5B62);
const unsigned int RED600 = Color(0xF76D74);
const unsigned int RED700 = Color(0xFF7B82);
const unsigned int ORANGE400 = Color(0xE68619);
const unsigned int ORANGE500 = Color(0xF29423);
const unsigned int ORANGE600 = Color(0xF9A43F);
const unsigned int ORANGE700 = Color(0xFFB55B);
const unsigned int GREEN400 = Color(0x2D9D78);
const unsigned int GREEN500 = Color(0x33AB84);
const unsigned int GREEN600 = Color(0x39B990);
const unsigned int GREEN700 = Color(0x3FC89C);
const unsigned int INDIGO400 = Color(0x6767EC);
const unsigned int INDIGO500 = Color(0x7575F1);
const unsigned int INDIGO600 = Color(0x8282F6);
const unsigned int INDIGO700 = Color(0x9090FA);
const unsigned int CELERY400 = Color(0x44B556);
const unsigned int CELERY500 = Color(0x4BC35F);
const unsigned int CELERY600 = Color(0x51D267);
const unsigned int CELERY700 = Color(0x58E06F);
const unsigned int MAGENTA400 = Color(0xD83790);
const unsigned int MAGENTA500 = Color(0xE2499D);
const unsigned int MAGENTA600 = Color(0xEC5AAA);
const unsigned int MAGENTA700 = Color(0xF56BB7);
const unsigned int YELLOW400 = Color(0xDFBF00);
const unsigned int YELLOW500 = Color(0xEDCC00);
const unsigned int YELLOW600 = Color(0xFAD900);
const unsigned int YELLOW700 = Color(0xFFE22E);
const unsigned int FUCHSIA400 = Color(0xC038CC);
const unsigned int FUCHSIA500 = Color(0xCF3EDC);
const unsigned int FUCHSIA600 = Color(0xD951E5);
const unsigned int FUCHSIA700 = Color(0xE366EF);
const unsigned int SEAFOAM400 = Color(0x1B959A);
const unsigned int SEAFOAM500 = Color(0x20A3A8);
const unsigned int SEAFOAM600 = Color(0x23B2B8);
const unsigned int SEAFOAM700 = Color(0x26C0C7);
const unsigned int CHARTREUSE400 = Color(0x85D044);
const unsigned int CHARTREUSE500 = Color(0x8EDE49);
const unsigned int CHARTREUSE600 = Color(0x9BEC54);
const unsigned int CHARTREUSE700 = Color(0xA3F858);
const unsigned int PURPLE400 = Color(0x9256D9);
const unsigned int PURPLE500 = Color(0x9D64E1);
const unsigned int PURPLE600 = Color(0xA873E9);
const unsigned int PURPLE700 = Color(0xB483F0);
#endif
}
}

BIN
resources/fonts/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,388 @@
// dear imgui
// (binary_to_compressed_c.cpp)
// Helper tool to turn a file into a C array, if you want to embed font data in your source code.
// The data is first compressed with stb_compress() to reduce source code size,
// then encoded in Base85 to fit in a string so we can fit roughly 4 bytes of compressed data into 5 bytes of source code (suggested by @mmalex)
// (If we used 32-bit constants it would require take 11 bytes of source code to encode 4 bytes, and be endianness dependent)
// Note that even with compression, the output array is likely to be bigger than the binary file..
// Load compressed TTF fonts with ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF()
// Build with, e.g:
// # cl.exe binary_to_compressed_c.cpp
// # g++ binary_to_compressed_c.cpp
// # clang++ binary_to_compressed_c.cpp
// You can also find a precompiled Windows binary in the binary/demo package available from https://github.com/ocornut/imgui
// Usage:
// binary_to_compressed_c.exe [-base85] [-nocompress] [-nostatic] <inputfile> <symbolname>
// Usage example:
// # binary_to_compressed_c.exe myfont.ttf MyFont > myfont.cpp
// # binary_to_compressed_c.exe -base85 myfont.ttf MyFont > myfont.cpp
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
// stb_compress* from stb.h - declaration
typedef unsigned int stb_uint;
typedef unsigned char stb_uchar;
stb_uint stb_compress(stb_uchar* out, stb_uchar* in, stb_uint len);
static bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_base85_encoding, bool use_compression, bool use_static);
int main(int argc, char** argv)
{
if (argc < 3)
{
printf("Syntax: %s [-base85] [-nocompress] [-nostatic] <inputfile> <symbolname>\n", argv[0]);
return 0;
}
int argn = 1;
bool use_base85_encoding = false;
bool use_compression = true;
bool use_static = true;
while (argn < (argc - 2) && argv[argn][0] == '-')
{
if (strcmp(argv[argn], "-base85") == 0) { use_base85_encoding = true; argn++; }
else if (strcmp(argv[argn], "-nocompress") == 0) { use_compression = false; argn++; }
else if (strcmp(argv[argn], "-nostatic") == 0) { use_static = false; argn++; }
else
{
fprintf(stderr, "Unknown argument: '%s'\n", argv[argn]);
return 1;
}
}
bool ret = binary_to_compressed_c(argv[argn], argv[argn + 1], use_base85_encoding, use_compression, use_static);
if (!ret)
fprintf(stderr, "Error opening or reading file: '%s'\n", argv[argn]);
return ret ? 0 : 1;
}
char Encode85Byte(unsigned int x)
{
x = (x % 85) + 35;
return (char)((x >= '\\') ? x + 1 : x);
}
bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_base85_encoding, bool use_compression, bool use_static)
{
// Read file
FILE* f = fopen(filename, "rb");
if (!f) return false;
int data_sz;
if (fseek(f, 0, SEEK_END) || (data_sz = (int)ftell(f)) == -1 || fseek(f, 0, SEEK_SET)) { fclose(f); return false; }
char* data = new char[data_sz + 4];
if (fread(data, 1, data_sz, f) != (size_t)data_sz) { fclose(f); delete[] data; return false; }
memset((void*)(((char*)data) + data_sz), 0, 4);
fclose(f);
// Compress
int maxlen = data_sz + 512 + (data_sz >> 2) + sizeof(int); // total guess
char* compressed = use_compression ? new char[maxlen] : data;
int compressed_sz = use_compression ? stb_compress((stb_uchar*)compressed, (stb_uchar*)data, data_sz) : data_sz;
if (use_compression)
memset(compressed + compressed_sz, 0, maxlen - compressed_sz);
// Output as Base85 encoded
FILE* out = stdout;
fprintf(out, "// File: '%s' (%d bytes)\n", filename, (int)data_sz);
fprintf(out, "// Exported using binary_to_compressed_c.cpp\n");
const char* static_str = use_static ? "static " : "";
const char* compressed_str = use_compression ? "compressed_" : "";
if (use_base85_encoding)
{
fprintf(out, "%sconst char %s_%sdata_base85[%d+1] =\n \"", static_str, symbol, compressed_str, (int)((compressed_sz + 3) / 4)*5);
char prev_c = 0;
for (int src_i = 0; src_i < compressed_sz; src_i += 4)
{
// This is made a little more complicated by the fact that ??X sequences are interpreted as trigraphs by old C/C++ compilers. So we need to escape pairs of ??.
unsigned int d = *(unsigned int*)(compressed + src_i);
for (unsigned int n5 = 0; n5 < 5; n5++, d /= 85)
{
char c = Encode85Byte(d);
fprintf(out, (c == '?' && prev_c == '?') ? "\\%c" : "%c", c);
prev_c = c;
}
if ((src_i % 112) == 112 - 4)
fprintf(out, "\"\n \"");
}
fprintf(out, "\";\n\n");
}
else
{
fprintf(out, "%sconst unsigned int %s_%ssize = %d;\n", static_str, symbol, compressed_str, (int)compressed_sz);
fprintf(out, "%sconst unsigned int %s_%sdata[%d/4] =\n{", static_str, symbol, compressed_str, (int)((compressed_sz + 3) / 4)*4);
int column = 0;
for (int i = 0; i < compressed_sz; i += 4)
{
unsigned int d = *(unsigned int*)(compressed + i);
if ((column++ % 12) == 0)
fprintf(out, "\n 0x%08x, ", d);
else
fprintf(out, "0x%08x, ", d);
}
fprintf(out, "\n};\n\n");
}
// Cleanup
delete[] data;
if (use_compression)
delete[] compressed;
return true;
}
// stb_compress* from stb.h - definition
//////////////////// compressor ///////////////////////
static stb_uint stb_adler32(stb_uint adler32, stb_uchar *buffer, stb_uint buflen)
{
const unsigned long ADLER_MOD = 65521;
unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16;
unsigned long blocklen, i;
blocklen = buflen % 5552;
while (buflen) {
for (i=0; i + 7 < blocklen; i += 8) {
s1 += buffer[0], s2 += s1;
s1 += buffer[1], s2 += s1;
s1 += buffer[2], s2 += s1;
s1 += buffer[3], s2 += s1;
s1 += buffer[4], s2 += s1;
s1 += buffer[5], s2 += s1;
s1 += buffer[6], s2 += s1;
s1 += buffer[7], s2 += s1;
buffer += 8;
}
for (; i < blocklen; ++i)
s1 += *buffer++, s2 += s1;
s1 %= ADLER_MOD, s2 %= ADLER_MOD;
buflen -= blocklen;
blocklen = 5552;
}
return (s2 << 16) + s1;
}
static unsigned int stb_matchlen(stb_uchar *m1, stb_uchar *m2, stb_uint maxlen)
{
stb_uint i;
for (i=0; i < maxlen; ++i)
if (m1[i] != m2[i]) return i;
return i;
}
// simple implementation that just takes the source data in a big block
static stb_uchar *stb__out;
static FILE *stb__outfile;
static stb_uint stb__outbytes;
static void stb__write(unsigned char v)
{
fputc(v, stb__outfile);
++stb__outbytes;
}
//#define stb_out(v) (stb__out ? *stb__out++ = (stb_uchar) (v) : stb__write((stb_uchar) (v)))
#define stb_out(v) do { if (stb__out) *stb__out++ = (stb_uchar) (v); else stb__write((stb_uchar) (v)); } while (0)
static void stb_out2(stb_uint v) { stb_out(v >> 8); stb_out(v); }
static void stb_out3(stb_uint v) { stb_out(v >> 16); stb_out(v >> 8); stb_out(v); }
static void stb_out4(stb_uint v) { stb_out(v >> 24); stb_out(v >> 16); stb_out(v >> 8 ); stb_out(v); }
static void outliterals(stb_uchar *in, int numlit)
{
while (numlit > 65536) {
outliterals(in,65536);
in += 65536;
numlit -= 65536;
}
if (numlit == 0) ;
else if (numlit <= 32) stb_out (0x000020 + numlit-1);
else if (numlit <= 2048) stb_out2(0x000800 + numlit-1);
else /* numlit <= 65536) */ stb_out3(0x070000 + numlit-1);
if (stb__out) {
memcpy(stb__out,in,numlit);
stb__out += numlit;
} else
fwrite(in, 1, numlit, stb__outfile);
}
static int stb__window = 0x40000; // 256K
static int stb_not_crap(int best, int dist)
{
return ((best > 2 && dist <= 0x00100)
|| (best > 5 && dist <= 0x04000)
|| (best > 7 && dist <= 0x80000));
}
static stb_uint stb__hashsize = 32768;
// note that you can play with the hashing functions all you
// want without needing to change the decompressor
#define stb__hc(q,h,c) (((h) << 7) + ((h) >> 25) + q[c])
#define stb__hc2(q,h,c,d) (((h) << 14) + ((h) >> 18) + (q[c] << 7) + q[d])
#define stb__hc3(q,c,d,e) ((q[c] << 14) + (q[d] << 7) + q[e])
static unsigned int stb__running_adler;
static int stb_compress_chunk(stb_uchar *history,
stb_uchar *start,
stb_uchar *end,
int length,
int *pending_literals,
stb_uchar **chash,
stb_uint mask)
{
(void)history;
int window = stb__window;
stb_uint match_max;
stb_uchar *lit_start = start - *pending_literals;
stb_uchar *q = start;
#define STB__SCRAMBLE(h) (((h) + ((h) >> 16)) & mask)
// stop short of the end so we don't scan off the end doing
// the hashing; this means we won't compress the last few bytes
// unless they were part of something longer
while (q < start+length && q+12 < end) {
int m;
stb_uint h1,h2,h3,h4, h;
stb_uchar *t;
int best = 2, dist=0;
if (q+65536 > end)
match_max = (stb_uint)(end-q);
else
match_max = 65536;
#define stb__nc(b,d) ((d) <= window && ((b) > 9 || stb_not_crap((int)(b),(int)(d))))
#define STB__TRY(t,p) /* avoid retrying a match we already tried */ \
if (p ? dist != (int)(q-t) : 1) \
if ((m = stb_matchlen(t, q, match_max)) > best) \
if (stb__nc(m,q-(t))) \
best = m, dist = (int)(q - (t))
// rather than search for all matches, only try 4 candidate locations,
// chosen based on 4 different hash functions of different lengths.
// this strategy is inspired by LZO; hashing is unrolled here using the
// 'hc' macro
h = stb__hc3(q,0, 1, 2); h1 = STB__SCRAMBLE(h);
t = chash[h1]; if (t) STB__TRY(t,0);
h = stb__hc2(q,h, 3, 4); h2 = STB__SCRAMBLE(h);
h = stb__hc2(q,h, 5, 6); t = chash[h2]; if (t) STB__TRY(t,1);
h = stb__hc2(q,h, 7, 8); h3 = STB__SCRAMBLE(h);
h = stb__hc2(q,h, 9,10); t = chash[h3]; if (t) STB__TRY(t,1);
h = stb__hc2(q,h,11,12); h4 = STB__SCRAMBLE(h);
t = chash[h4]; if (t) STB__TRY(t,1);
// because we use a shared hash table, can only update it
// _after_ we've probed all of them
chash[h1] = chash[h2] = chash[h3] = chash[h4] = q;
if (best > 2)
assert(dist > 0);
// see if our best match qualifies
if (best < 3) { // fast path literals
++q;
} else if (best > 2 && best <= 0x80 && dist <= 0x100) {
outliterals(lit_start, (int)(q-lit_start)); lit_start = (q += best);
stb_out(0x80 + best-1);
stb_out(dist-1);
} else if (best > 5 && best <= 0x100 && dist <= 0x4000) {
outliterals(lit_start, (int)(q-lit_start)); lit_start = (q += best);
stb_out2(0x4000 + dist-1);
stb_out(best-1);
} else if (best > 7 && best <= 0x100 && dist <= 0x80000) {
outliterals(lit_start, (int)(q-lit_start)); lit_start = (q += best);
stb_out3(0x180000 + dist-1);
stb_out(best-1);
} else if (best > 8 && best <= 0x10000 && dist <= 0x80000) {
outliterals(lit_start, (int)(q-lit_start)); lit_start = (q += best);
stb_out3(0x100000 + dist-1);
stb_out2(best-1);
} else if (best > 9 && dist <= 0x1000000) {
if (best > 65536) best = 65536;
outliterals(lit_start, (int)(q-lit_start)); lit_start = (q += best);
if (best <= 0x100) {
stb_out(0x06);
stb_out3(dist-1);
stb_out(best-1);
} else {
stb_out(0x04);
stb_out3(dist-1);
stb_out2(best-1);
}
} else { // fallback literals if no match was a balanced tradeoff
++q;
}
}
// if we didn't get all the way, add the rest to literals
if (q-start < length)
q = start+length;
// the literals are everything from lit_start to q
*pending_literals = (int)(q - lit_start);
stb__running_adler = stb_adler32(stb__running_adler, start, (stb_uint)(q - start));
return (int)(q - start);
}
static int stb_compress_inner(stb_uchar *input, stb_uint length)
{
int literals = 0;
stb_uint len,i;
stb_uchar **chash;
chash = (stb_uchar**) malloc(stb__hashsize * sizeof(stb_uchar*));
if (chash == nullptr) return 0; // failure
for (i=0; i < stb__hashsize; ++i)
chash[i] = nullptr;
// stream signature
stb_out(0x57); stb_out(0xbc);
stb_out2(0);
stb_out4(0); // 64-bit length requires 32-bit leading 0
stb_out4(length);
stb_out4(stb__window);
stb__running_adler = 1;
len = stb_compress_chunk(input, input, input+length, length, &literals, chash, stb__hashsize-1);
assert(len == length);
outliterals(input+length - literals, literals);
free(chash);
stb_out2(0x05fa); // end opcode
stb_out4(stb__running_adler);
return 1; // success
}
stb_uint stb_compress(stb_uchar *out, stb_uchar *input, stb_uint length)
{
stb__out = out;
stb__outfile = nullptr;
stb_compress_inner(input, length);
return (stb_uint)(stb__out - out);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

5447
resources/fonts/test.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@
#include <imgui.h>
#include "backends/imgui_impl_opengl3.h"
#include "backends/imgui_impl_glfw.h"
#include <blt/gfx/imgui/IconsFontAwesome5.h>
#include <blt/gfx/imgui/ImGuiUtils.h>
void error_callback(int error, const char* description)
{
@ -98,12 +98,26 @@ namespace blt::gfx
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
(void) io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::Spectrum::StyleColorsSpectrum();
ImGui::Spectrum::LoadFont();
ImGui::SetupImGuiStyle(true, 1.0);
// Setup FA
ImFontConfig config;
config.MergeMode = true;
config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced
static const ImWchar icon_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
io.Fonts->AddFontFromMemoryCompressedBase85TTF(fontAwesomeRegular_compressed_data_base85, 13.0f, &config, icon_ranges);
io.Fonts->AddFontFromMemoryCompressedTTF(fontAwesomeSolid_compressed_data, static_cast<int>(fontAwesomeSolid_compressed_size), 13.0, &config,
icon_ranges);
io.Fonts->AddFontFromMemoryCompressedTTF(fontAwesomeBrands_compressed_data, static_cast<int>(fontAwesomeBrands_compressed_size), 13.0, &config,
icon_ranges);
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
@ -187,7 +201,7 @@ namespace blt::gfx
#else
/* -- General Loop -- */
while (!glfwWindowShouldClose(window_state.window))
loop((void*)&data);
loop((void*) &data);
#endif
}

15067
src/blt/imgui/imgui_utils.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@
#include <blt/gfx/window.h>
#include <imgui.h>
#include "blt/gfx/imgui/IconsFontAwesome5.h"
void init()
{
@ -11,6 +12,9 @@ void init()
void update(std::int32_t width, std::int32_t height)
{
ImGui::ShowDemoWindow();
ImGui::Text("%s among %d items", ICON_FA_FILE, 0);
ImGui::Button(ICON_FA_SEARCH " Search");
ImGui::End();
}
int main()