Change print_to_widget, edit_draw_this_line to use struct line_s line[].

Extract color attibutes from char to lines->style.
Add definition struct line_s:
    struct line_s {
        unsigned int ch;    <- textchar
        unsigned int style; <- color attr
    };
This commit is contained in:
Ilia Maslakov 2009-04-12 08:09:00 +00:00
parent b5c4a9ddf2
commit 7d7560deea

View File

@ -210,11 +210,16 @@ void edit_scroll_screen_over_cursor (WEdit * edit)
#define lowlevel_set_color(x) attrset(MY_COLOR_PAIR(color)) #define lowlevel_set_color(x) attrset(MY_COLOR_PAIR(color))
#endif #endif
struct line_s {
unsigned int ch;
unsigned int style;
};
static void static void
print_to_widget (WEdit *edit, long row, int start_col, int start_col_real, print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
long end_col, unsigned int line[]) long end_col, struct line_s line[])
{ {
unsigned int *p; struct line_s *p;
int x = start_col_real + EDIT_TEXT_HORIZONTAL_OFFSET; int x = start_col_real + EDIT_TEXT_HORIZONTAL_OFFSET;
int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET; int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET;
@ -228,7 +233,7 @@ print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
edit_move (x1 + FONT_OFFSET_X, y + FONT_OFFSET_Y); edit_move (x1 + FONT_OFFSET_X, y + FONT_OFFSET_Y);
p = line; p = line;
while (*p) { while (p->ch) {
int style; int style;
int textchar; int textchar;
int color; int color;
@ -239,9 +244,9 @@ print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
continue; continue;
} }
style = *p & 0xFF00; style = p->style & 0xFF00;
textchar = *p & 0xFF; textchar = p->ch;
color = *p >> 16; color = p->style >> 16;
if (style & MOD_ABNORMAL) { if (style & MOD_ABNORMAL) {
/* Non-printable - use black background */ /* Non-printable - use black background */
@ -270,7 +275,6 @@ print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
lowlevel_set_color (color); lowlevel_set_color (color);
} }
} }
addch (textchar); addch (textchar);
p++; p++;
} }
@ -283,8 +287,9 @@ static void
edit_draw_this_line (WEdit *edit, long b, long row, long start_col, edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
long end_col) long end_col)
{ {
static unsigned int line[MAX_LINE_LEN]; struct line_s line[MAX_LINE_LEN];
unsigned int *p = line; struct line_s *p = line;
long m1 = 0, m2 = 0, q, c1, c2; long m1 = 0, m2 = 0, q, c1, c2;
int col, start_col_real; int col, start_col_real;
unsigned int c; unsigned int c;
@ -312,87 +317,131 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
} }
while (col <= end_col - edit->start_col) { while (col <= end_col - edit->start_col) {
*p = 0; p->ch = 0;
p->style = 0;
if (q == edit->curs1) if (q == edit->curs1)
*p |= MOD_CURSOR; p->style |= MOD_CURSOR;
if (q >= m1 && q < m2) { if (q >= m1 && q < m2) {
if (column_highlighting) { if (column_highlighting) {
int x; int x;
x = edit_move_forward3 (edit, b, 0, q); x = edit_move_forward3 (edit, b, 0, q);
if (x >= c1 && x < c2) if (x >= c1 && x < c2)
*p |= MOD_MARKED; p->style |= MOD_MARKED;
} else } else
*p |= MOD_MARKED; p->style |= MOD_MARKED;
} }
if (q == edit->bracket) if (q == edit->bracket)
*p |= MOD_BOLD; p->style |= MOD_BOLD;
if (q >= edit->found_start if (q >= edit->found_start
&& q < edit->found_start + edit->found_len) && q < edit->found_start + edit->found_len)
*p |= MOD_BOLD; p->style |= MOD_BOLD;
c = edit_get_byte (edit, q); c = edit_get_byte (edit, q);
/* we don't use bg for mc - fg contains both */ /* we don't use bg for mc - fg contains both */
edit_get_syntax_color (edit, q, &color); edit_get_syntax_color (edit, q, &color);
*p |= color << 16; p->style |= color << 16;
switch (c) { switch (c) {
case '\n': case '\n':
col = end_col - edit->start_col + 1; /* quit */ col = end_col - edit->start_col + 1; /* quit */
*(p++) |= ' '; p->ch = ' ';
p++;
break; break;
case '\t': case '\t':
i = TAB_SIZE - ((int) col % TAB_SIZE); i = TAB_SIZE - ((int) col % TAB_SIZE);
col += i; col += i;
if (use_colors && visible_tabs) { if (use_colors && visible_tabs) {
c = (*p & ~MOD_CURSOR) | MOD_WHITESPACE; c = 0;
if (i > 2) { if (i > 2) {
*(p++) |= '<' | MOD_WHITESPACE; p->ch |= '<';
while (--i > 1) p->style = MOD_WHITESPACE;
*(p++) = c | '-'; p++;
*(p++) = c | '>'; while (--i > 1) {
p->ch = c | '-';
p->style = MOD_WHITESPACE;
p++;
}
p->ch = c | '>';
p->style = MOD_WHITESPACE;
p++;
} else if (i > 1) { } else if (i > 1) {
*(p++) |= '<' | MOD_WHITESPACE; p->ch |= '<';
*(p++) = c | '>'; p->style = MOD_WHITESPACE;
} else p++;
*(p++) |= '>' | MOD_WHITESPACE; p->ch = c | '>';
p->style = MOD_WHITESPACE;
p++;
} else {
p->ch |= '>';
p->style = MOD_WHITESPACE;
p++;
}
} else if (use_colors && visible_tws && q >= tws) { } else if (use_colors && visible_tws && q >= tws) {
*p |= '.' | MOD_WHITESPACE; p->ch |= '.';
c = *(p++) & ~MOD_CURSOR; p->style = MOD_WHITESPACE;
while (--i) c = p->style & ~MOD_CURSOR;
*(p++) = c; p++;
while (--i) {
p->ch = ' ';
p->style = c;
p++;
}
} else { } else {
*p |= ' '; p->ch |= ' ';
c = *(p++) & ~MOD_CURSOR; c = p->style & ~MOD_CURSOR;
while (--i) p++;
*(p++) = c; while (--i) {
p->ch = ' ';
p->style = c;
p++;
}
} }
break; break;
case ' ': case ' ':
if (use_colors && visible_tws && q >= tws) { if (use_colors && visible_tws && q >= tws) {
*(p++) |= '.' | MOD_WHITESPACE; p->ch |= '.';
p->style = MOD_WHITESPACE;
p++;
col++; col++;
break; break;
} }
/* fallthrough */ /* fallthrough */
default: default:
c = convert_to_display_c (c); if (!edit->utf8) {
c = convert_to_display_c (c);
} else {
//FIXME: if need
}
/* Caret notation for control characters */ /* Caret notation for control characters */
if (c < 32) { if (c < 32) {
*(p++) = '^' | MOD_ABNORMAL; p->ch = '^';
*(p++) = (c + 0x40) | MOD_ABNORMAL; p->style = MOD_ABNORMAL;
p++;
p->ch = c + 0x40;
p->style = MOD_ABNORMAL;
p++;
col += 2; col += 2;
break; break;
} }
if (c == 127) { if (c == 127) {
*(p++) = '^' | MOD_ABNORMAL; p->ch = '^';
*(p++) = '?' | MOD_ABNORMAL; p->style = MOD_ABNORMAL;
p++;
p->ch = '?';
p->style = MOD_ABNORMAL;
p++;
col += 2; col += 2;
break; break;
} }
if (!edit->utf8) {
if (is_printable (c)) { if (is_printable (c)) {
*(p++) |= c; p->ch = c;
p++;
} else {
p->ch = '.';
p->style = MOD_ABNORMAL;
p++;
}
} else { } else {
*(p++) = '.' | MOD_ABNORMAL; //FIXME: col += utfchar_width - 1
} }
col++; col++;
break; break;
@ -403,7 +452,7 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
} else { } else {
start_col_real = start_col = 0; start_col_real = start_col = 0;
} }
*p = 0; p->ch = 0;
print_to_widget (edit, row, start_col, start_col_real, end_col, line); print_to_widget (edit, row, start_col, start_col_real, end_col, line);
} }