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))
#endif
struct line_s {
unsigned int ch;
unsigned int style;
};
static void
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 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);
p = line;
while (*p) {
while (p->ch) {
int style;
int textchar;
int color;
@ -239,9 +244,9 @@ print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
continue;
}
style = *p & 0xFF00;
textchar = *p & 0xFF;
color = *p >> 16;
style = p->style & 0xFF00;
textchar = p->ch;
color = p->style >> 16;
if (style & MOD_ABNORMAL) {
/* 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);
}
}
addch (textchar);
p++;
}
@ -283,8 +287,9 @@ static void
edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
long end_col)
{
static unsigned int line[MAX_LINE_LEN];
unsigned int *p = line;
struct line_s line[MAX_LINE_LEN];
struct line_s *p = line;
long m1 = 0, m2 = 0, q, c1, c2;
int col, start_col_real;
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) {
*p = 0;
p->ch = 0;
p->style = 0;
if (q == edit->curs1)
*p |= MOD_CURSOR;
p->style |= MOD_CURSOR;
if (q >= m1 && q < m2) {
if (column_highlighting) {
int x;
x = edit_move_forward3 (edit, b, 0, q);
if (x >= c1 && x < c2)
*p |= MOD_MARKED;
p->style |= MOD_MARKED;
} else
*p |= MOD_MARKED;
p->style |= MOD_MARKED;
}
if (q == edit->bracket)
*p |= MOD_BOLD;
p->style |= MOD_BOLD;
if (q >= edit->found_start
&& q < edit->found_start + edit->found_len)
*p |= MOD_BOLD;
p->style |= MOD_BOLD;
c = edit_get_byte (edit, q);
/* we don't use bg for mc - fg contains both */
edit_get_syntax_color (edit, q, &color);
*p |= color << 16;
p->style |= color << 16;
switch (c) {
case '\n':
col = end_col - edit->start_col + 1; /* quit */
*(p++) |= ' ';
p->ch = ' ';
p++;
break;
case '\t':
i = TAB_SIZE - ((int) col % TAB_SIZE);
col += i;
if (use_colors && visible_tabs) {
c = (*p & ~MOD_CURSOR) | MOD_WHITESPACE;
c = 0;
if (i > 2) {
*(p++) |= '<' | MOD_WHITESPACE;
while (--i > 1)
*(p++) = c | '-';
*(p++) = c | '>';
p->ch |= '<';
p->style = MOD_WHITESPACE;
p++;
while (--i > 1) {
p->ch = c | '-';
p->style = MOD_WHITESPACE;
p++;
}
p->ch = c | '>';
p->style = MOD_WHITESPACE;
p++;
} else if (i > 1) {
*(p++) |= '<' | MOD_WHITESPACE;
*(p++) = c | '>';
} else
*(p++) |= '>' | MOD_WHITESPACE;
p->ch |= '<';
p->style = MOD_WHITESPACE;
p++;
p->ch = c | '>';
p->style = MOD_WHITESPACE;
p++;
} else {
p->ch |= '>';
p->style = MOD_WHITESPACE;
p++;
}
} else if (use_colors && visible_tws && q >= tws) {
*p |= '.' | MOD_WHITESPACE;
c = *(p++) & ~MOD_CURSOR;
while (--i)
*(p++) = c;
p->ch |= '.';
p->style = MOD_WHITESPACE;
c = p->style & ~MOD_CURSOR;
p++;
while (--i) {
p->ch = ' ';
p->style = c;
p++;
}
} else {
*p |= ' ';
c = *(p++) & ~MOD_CURSOR;
while (--i)
*(p++) = c;
p->ch |= ' ';
c = p->style & ~MOD_CURSOR;
p++;
while (--i) {
p->ch = ' ';
p->style = c;
p++;
}
}
break;
case ' ':
if (use_colors && visible_tws && q >= tws) {
*(p++) |= '.' | MOD_WHITESPACE;
p->ch |= '.';
p->style = MOD_WHITESPACE;
p++;
col++;
break;
}
/* fallthrough */
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 */
if (c < 32) {
*(p++) = '^' | MOD_ABNORMAL;
*(p++) = (c + 0x40) | MOD_ABNORMAL;
p->ch = '^';
p->style = MOD_ABNORMAL;
p++;
p->ch = c + 0x40;
p->style = MOD_ABNORMAL;
p++;
col += 2;
break;
}
if (c == 127) {
*(p++) = '^' | MOD_ABNORMAL;
*(p++) = '?' | MOD_ABNORMAL;
p->ch = '^';
p->style = MOD_ABNORMAL;
p++;
p->ch = '?';
p->style = MOD_ABNORMAL;
p++;
col += 2;
break;
}
if (is_printable (c)) {
*(p++) |= c;
if (!edit->utf8) {
if (is_printable (c)) {
p->ch = c;
p++;
} else {
p->ch = '.';
p->style = MOD_ABNORMAL;
p++;
}
} else {
*(p++) = '.' | MOD_ABNORMAL;
//FIXME: col += utfchar_width - 1
}
col++;
break;
@ -403,7 +452,7 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
} else {
start_col_real = start_col = 0;
}
*p = 0;
p->ch = 0;
print_to_widget (edit, row, start_col, start_col_real, end_col, line);
}