Browse Source

Add test use of extended ncurses

master
cancel 6 years ago
parent
commit
8b9a95f9a2
  1. 4
      Makefile
  2. 11
      field.c
  3. 2
      field.h
  4. 6
      main.c

4
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

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

2
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);

6
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);

Loading…
Cancel
Save