diff --git a/Makefile b/Makefile index f02e491..c0d211c 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -basic_flags := -std=c99 -pipe -Wall -Wpedantic -Wextra -Werror=implicit-function-declaration +basic_flags := -std=c99 -pipe -Wall -Wpedantic -Wextra -Werror=implicit-function-declaration -D_XOPEN_SOURCE_EXTENDED=1 debug_flags := -DDEBUG -O0 -ggdb -feliminate-unused-debug-symbols sanitize_flags := -fsanitize=address -fsanitize=undefined # note: -fsanitize=leak not available on at least Mac 10.12 release_flags := -DNDEBUG -O2 -s -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fpie -Wl,-pie -library_flags := -lncurses +library_flags := -lncursesw source_files := field.c main.c all: debug diff --git a/field.c b/field.c index bd97028..d1677bd 100644 --- a/field.c +++ b/field.c @@ -124,9 +124,11 @@ void field_poke(Field* f, U32 y, U32 x, Term term) { f->buffer[y * f_width + x] = term; } -void field_debug_draw(Field* f, int offset_y, int offset_x) { +void field_debug_draw(WINDOW* win, Field* f, int offset_y, int offset_x) { enum { Line_buffer_count = 4096 }; - chtype line_buffer[Line_buffer_count]; + cchar_t line_buffer[Line_buffer_count]; + wchar_t wcs[2]; + wcs[1] = '\0'; size_t f_height = f->height; size_t f_width = f->width; Term* f_buffer = f->buffer; @@ -135,9 +137,10 @@ void field_debug_draw(Field* f, int offset_y, int offset_x) { for (size_t iy = 0; iy < f_height; ++iy) { Term* row_p = f_buffer + f_width * iy; for (size_t ix = 0; ix < f_width; ++ix) { - line_buffer[ix] = (chtype)row_p[ix]; + wcs[0] = row_p[ix]; + setcchar(line_buffer + ix, wcs, A_NORMAL, 0, NULL); } move(iy + offset_y, offset_x); - addchnstr(line_buffer, (int)f_width); + wadd_wchnstr(win, line_buffer, (int)f_width); } } diff --git a/field.h b/field.h index 7a7a5dd..e8a428f 100644 --- a/field.h +++ b/field.h @@ -17,4 +17,4 @@ void field_fill_subrect(Field* f, U32 y, U32 x, U32 height, U32 width, Term fill_char); Term field_peek(Field* f, U32 y, U32 x); void field_poke(Field* f, U32 y, U32 x, Term term); -void field_debug_draw(Field* f, int offset_y, int offset_x); +void field_debug_draw(WINDOW* win, Field* f, int offset_y, int offset_x); diff --git a/main.c b/main.c index ce7b78b..f5edd61 100644 --- a/main.c +++ b/main.c @@ -71,12 +71,12 @@ int main() { } field_fill_subrect(&field, 1, 1, field.height - 2, field.width - 2, fill_char); - field_debug_draw(&field, 0, 0); + field_debug_draw(stdscr, &field, 0, 0); field_copy_subrect(&field, &field, 0, 0, 4, 4, 8, 8); field_copy_subrect(&field, &field, 0, 0, 0, 0, 0, 0); - field_debug_draw(&field, field.height + 1, 0); + field_debug_draw(stdscr, &field, field.height + 1, 0); field_copy_subrect(&field, &field, 6, 6, 9, 9, 30, 30); - field_debug_draw(&field, 0, field.width + 1); + field_debug_draw(stdscr, &field, 0, field.width + 1); refresh(); } field_deinit(&field);