finish win32 gui support for double-wide characters
This commit is contained in:
parent
8278a080af
commit
05b87b1406
3 changed files with 25 additions and 7 deletions
|
|
@ -149,7 +149,7 @@ pub const WindowState = struct {
|
|||
}
|
||||
|
||||
// TODO: this should take a utf8 graphme instead
|
||||
pub fn generateGlyph(state: *WindowState, font: Font, codepoint: u21, right_half: bool) u32 {
|
||||
pub fn generateGlyph(state: *WindowState, font: Font, codepoint: u21, kind: enum { single, left, right }) u32 {
|
||||
// for now we'll just use 1 texture and leverage the entire thing
|
||||
const texture_cell_count: XY(u16) = getD3d11TextureMaxCellCount(font.cell_size);
|
||||
const texture_cell_count_total: u32 =
|
||||
|
|
@ -184,6 +184,11 @@ pub const WindowState = struct {
|
|||
break :blk &(state.glyph_index_cache.?);
|
||||
};
|
||||
|
||||
const right_half: bool = switch (kind) {
|
||||
.single, .left => false,
|
||||
.right => true,
|
||||
};
|
||||
|
||||
switch (glyph_index_cache.reserve(
|
||||
global.glyph_cache_arena.allocator(),
|
||||
codepoint,
|
||||
|
|
@ -194,8 +199,11 @@ pub const WindowState = struct {
|
|||
// defer if (!render_success) state.glyph_index_cache.remove(reserved.index);
|
||||
const pos: XY(u16) = cellPosFromIndex(reserved.index, texture_cell_count.x);
|
||||
const coord = coordFromCellPos(font.cell_size, pos);
|
||||
var staging_size = font.cell_size;
|
||||
staging_size.x = if (right_half) staging_size.x * 2 else staging_size.x;
|
||||
const staging_size: XY(u16) = .{
|
||||
// twice the width to handle double-wide glyphs
|
||||
.x = font.cell_size.x * 2,
|
||||
.y = font.cell_size.y,
|
||||
};
|
||||
const staging = global.staging_texture.update(staging_size);
|
||||
var utf8_buf: [7]u8 = undefined;
|
||||
const utf8_len: u3 = std.unicode.utf8Encode(codepoint, &utf8_buf) catch |e| std.debug.panic(
|
||||
|
|
@ -205,6 +213,10 @@ pub const WindowState = struct {
|
|||
staging.text_renderer.render(
|
||||
font,
|
||||
utf8_buf[0..utf8_len],
|
||||
switch (kind) {
|
||||
.single => false,
|
||||
.left, .right => true,
|
||||
},
|
||||
);
|
||||
const box: win32.D3D11_BOX = .{
|
||||
.left = if (right_half) font.cell_size.x else 0,
|
||||
|
|
@ -292,7 +304,7 @@ pub fn paint(
|
|||
}
|
||||
|
||||
const copy_col_count: u16 = @min(col_count, shader_col_count);
|
||||
const blank_space_glyph_index = state.generateGlyph(font, ' ', false);
|
||||
const blank_space_glyph_index = state.generateGlyph(font, ' ', .single);
|
||||
|
||||
const cell_count: u32 = @as(u32, shader_col_count) * @as(u32, shader_row_count);
|
||||
state.shader_cells.updateCount(cell_count);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue