From 149b35bbc02edd8516ddfec5fd5dac21b28c08ae Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sun, 11 Aug 2024 05:01:09 +0200 Subject: Update bit font encoding --- examples/ui.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'examples') diff --git a/examples/ui.c b/examples/ui.c index c4e4719..9270180 100755 --- a/examples/ui.c +++ b/examples/ui.c @@ -186,16 +186,22 @@ Platform platform = {0}; #define CHAR_NUM_BITS (CHAR_NUM_BITS_X * CHAR_NUM_BITS_Y) u64 bitfont[] = { - 0x1041040000000000, 0x14500100, 0x38538429f28a7ca0, 0x621421f085084394, 0x10472450c614, 0x420410410420000, 0x233f312042082082, 0x411f10400001, 0x1f0000010800000, 0x4100040000000000, 0xc51451c004108208, 0x1c00070820830001, 0x71021070001c1084, 0x470001041c514000, 0x1c51c11800031070, 0x51c0002082107000, 0x31071470001c51c, 0x800000400010000, 0x102042100042000, 0x20400003c03c000, 0x20021050800421, 0xf24918e05955944e, 0x801c924724700924, 0x2492470062410491, 0xf00f0411c13c01c9, 0x4d04918004104704, 0x1c024924f2490062, 0x5104107007082082, 0x410092450c524008, 0x4557db4401c10410, 0x91804516554d1011, 0x411c924700624924, 0x2472062492491800, 0x62481811802491c9, 0x4924010410411f00, 0x10a4514510062492, 0x429100a7d5551440, 0x108429144045128, 0x410c03c108420f0, 0x41020820410c1041, 0x112840c20820820c, 0x3c00000000000000, 0xf206000000000081, 0x1c924704000624, 0x24e2000062412460, 0x604f246000389, 0x892460000821c218, 0x2491c10401883, 0x20c0080007083002, 0x4100514314500108, 0x55554f0000810410, 0x60002492491c0015, 0x472491c000624924, 0x14000838924e0000, 0x6206046000041043, 0x490000820821c000, 0x10a45144000e2492, 0xa44000a7d5451000, 0x108429100044a10, 0x821003c11883c00, 0x1041041041102081, 0x66604208408204, + 0xbc0000000000, 0xc00300000, 0x5fd5040093f24fc9, 0xa00a2c2a1a280105, 0xc000415e6f, 0x400000020be0000, 0x1c38a8400000007d, 0x40002043e1020215, 0x408102000000010, 0x9800000000020002, 0xf913e00000033, 0x53200000207c8800, 0x3654880000099, 0x54b800000f840e00, 0xe953c000001a, 0x953e000000674080, 0x1e54b800000f, 0x490000000000240, 0x88a08000000, 0x20a220000a142850, 0x6520800000, 0x912f801eab260be, 0x800034952bf0001f, 0xc850bf0000921427, 0xf00010a54afc0003, 0xd29427800002142b, 0x840007e1023f0000, 0x7d09100000217e, 0x3f000188a08fc000, 0xc30c0cfc00000810, 0x27803f101013f00f, 0xc244bf0000f214, 0x4bf0002f21427800, 0xc254a480006c24, 0x407c00102fc08100, 0xf208080f0000fa0, 0x531007d81c607c0, 0xc208288c031141, 0x83fc00046954b10, 0x180e03000000, 0x41040000000ff04, 0x2040810000404, 0x2a54600000000101, 0x309123e0000e, 0xc912180000a22447, 0x8000062a54700007, 0xe52a4300000029f0, 0xa0000602043e0001, 0x1d48000002074, 0x1f000003610f8000, 0x13e04f800000010, 0x470000780813e00f, 0x184893e0000e224, 0x23e0001f12243000, 0x82a54100000008, 0x40780000009f0200, 0xe208080e0001f20, 0xa22007981860780, 0x82082888022282, 0x16c200004ca95320, 0x7f000004, 0x408200000086d04, 0x8204, }; #define BITFONT_LEN ((i64) (sizeof bitfont / sizeof *bitfont)) -b8 char_bit(c8 c, i64 column_index, i64 row_index) { - if (column_index < 0 || column_index >= CHAR_NUM_BITS_X || row_index < 0 || row_index >= CHAR_NUM_BITS_Y) +i64 char_column_offset(c8 c, i64 column_index) { + if (column_index < 0 || column_index >= CHAR_NUM_BITS_X) + return -1; + return (c - 32) * CHAR_NUM_BITS + column_index * CHAR_NUM_BITS_Y; +} + +b8 char_bit(i64 column_offset, i64 row_index) { + if (column_offset < 0 || column_offset / 64 >= BITFONT_LEN || row_index < 0 || row_index >= CHAR_NUM_BITS_Y) return 0; - i64 bit_index = (c - 32) * CHAR_NUM_BITS + row_index * CHAR_NUM_BITS_X + column_index; + i64 bit_index = column_offset + row_index; i64 qword_index = bit_index / 64; if (qword_index < 0 || qword_index >= BITFONT_LEN) return 0; @@ -207,10 +213,11 @@ u64 char_column_convolved(c8 c, i64 column_index) { if (column_index < 0 || column_index >= CHAR_NUM_BITS_X) return 0; + i64 offset = char_column_offset(c, column_index); u64 column = 0; for (i64 y = 0; y < CHAR_NUM_BITS_Y; ++y) { - if (!char_bit(c, column_index, y)) + if (!char_bit(offset, y)) continue; u64 mask = 1ull << y; @@ -228,8 +235,10 @@ b8 char_column_empty(c8 c, i64 column_index) { if (column_index < 0 || column_index >= CHAR_NUM_BITS_X) return 1; + i64 offset = char_column_offset(c, column_index); + for (i64 y = 0; y < CHAR_NUM_BITS_Y; ++y) - if (char_bit(c, column_index, y)) + if (char_bit(offset, y)) return 0; return 1; @@ -345,18 +354,20 @@ void print_text(u32 color, f64 x0, f64 y0, f64 scale_x, f64 scale_y, i64 num_cha i64 j0 = (i64) floor(y + .5); i64 j1 = (i64) floor(y + h + .5); - for (i64 j = j0; j < j1; ++j) { - if (j < 0) continue; - if (j >= platform.frame_height) break; + for (i64 i = i0; i < i1; ++i) { + if (i < 0) continue; + if (i >= platform.frame_width) break; + + i64 column = ((i - i0) * num_cols) / (i1 - i0); + i64 offset = char_column_offset(text[n], column); - for (i64 i = i0; i < i1; ++i) { - if (i < 0) continue; - if (i >= platform.frame_width) break; + for (i64 j = j0; j < j1; ++j) { + if (j < 0) continue; + if (j >= platform.frame_height) break; - i64 column = ((i - i0) * num_cols) / (i1 - i0); - i64 row = ((j - j0) * CHAR_NUM_BITS_Y) / (j1 - j0); + i64 row = ((j - j0) * CHAR_NUM_BITS_Y) / (j1 - j0); - if (char_bit(text[n], column, row)) + if (char_bit(offset, row)) platform.pixels[j * platform.frame_width + i] = color; } } @@ -605,6 +616,8 @@ void p_init(void) { _upper[','] = '<'; _upper['.'] = '>'; _upper['/'] = '?'; + _upper['-'] = '_'; + _upper['='] = '+'; _key_table[XKeysymToKeycode(_display, XK_Left)] = KEY_LEFT; _key_table[XKeysymToKeycode(_display, XK_Right)] = KEY_RIGHT; @@ -656,6 +669,8 @@ void p_init(void) { _key_table[XKeysymToKeycode(_display, XK_comma)] = ','; _key_table[XKeysymToKeycode(_display, XK_greater)] = '.'; _key_table[XKeysymToKeycode(_display, XK_question)] = '/'; + _key_table[XKeysymToKeycode(_display, XK_minus)] = '-'; + _key_table[XKeysymToKeycode(_display, XK_equal)] = '='; _key_table[XKeysymToKeycode(_display, XK_F1)] = KEY_F_ + 1; _key_table[XKeysymToKeycode(_display, XK_F2)] = KEY_F_ + 2; _key_table[XKeysymToKeycode(_display, XK_F3)] = KEY_F_ + 3; -- cgit v1.2.3