Browse Source

Cleanup fancy ruler drawing

master
cancel 5 years ago
parent
commit
2f2cde293c
  1. 50
      tui_main.c

50
tui_main.c

@ -513,6 +513,24 @@ void draw_glyphs_grid(WINDOW* win, int draw_y, int draw_x, int draw_h,
return; return;
bool use_rulers = ruler_spacing_y != 0 && ruler_spacing_x != 0; bool use_rulers = ruler_spacing_y != 0 && ruler_spacing_x != 0;
chtype bullet = ACS_BULLET; chtype bullet = ACS_BULLET;
enum { T = 1 << 0, B = 1 << 1, L = 1 << 2, R = 1 << 3 };
chtype rs[T | B | L | R];
if (use_rulers) {
bool use_fancy_rulers = true;
for (Usz i = 0; i < sizeof rs / sizeof(chtype); ++i) {
rs[i] = '+';
}
if (use_fancy_rulers) {
rs[T | L] = ACS_ULCORNER;
rs[T | R] = ACS_URCORNER;
rs[B | L] = ACS_LLCORNER;
rs[B | R] = ACS_LRCORNER;
rs[T] = ACS_TTEE;
rs[B] = ACS_BTEE;
rs[L] = ACS_LTEE;
rs[R] = ACS_RTEE;
}
}
for (Usz iy = 0; iy < rows; ++iy) { for (Usz iy = 0; iy < rows; ++iy) {
Usz line_offset = (offset_y + iy) * field_w + offset_x; Usz line_offset = (offset_y + iy) * field_w + offset_x;
Glyph const* g_row = gbuffer + line_offset; Glyph const* g_row = gbuffer + line_offset;
@ -523,31 +541,15 @@ void draw_glyphs_grid(WINDOW* win, int draw_y, int draw_x, int draw_h,
Mark m = m_row[ix]; Mark m = m_row[ix];
chtype ch; chtype ch;
if (g == '.') { if (g == '.') {
ch = bullet;
if (use_y_ruler && (ix + offset_x) % ruler_spacing_x == 0) { if (use_y_ruler && (ix + offset_x) % ruler_spacing_x == 0) {
bool top = iy + offset_y == 0; int p = 0; // clang-format off
bool bot = iy + offset_y + 1 == field_h; if (iy + offset_y == 0 ) p |= T;
bool left = ix + offset_x == 0; if (iy + offset_y + 1 == field_h) p |= B;
bool right = ix + offset_x + 1 == field_w; if (ix + offset_x == 0 ) p |= L;
if (top && left) { if (ix + offset_x + 1 == field_w) p |= R;
ch = ACS_ULCORNER; ch = rs[p]; // clang-format on
} else if (top && right) { } else {
ch = ACS_URCORNER; ch = bullet;
} else if (bot && left) {
ch = ACS_LLCORNER;
} else if (bot && right) {
ch = ACS_LRCORNER;
} else if (top) {
ch = ACS_TTEE;
} else if (bot) {
ch = ACS_BTEE;
} else if (left) {
ch = ACS_LTEE;
} else if (right) {
ch = ACS_RTEE;
} else {
ch = '+';
}
} }
} else { } else {
ch = (chtype)g; ch = (chtype)g;

Loading…
Cancel
Save