1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-24 00:56:14 +00:00

[color] Removed code related to draw_text_node

This idea failed. Code was slow.
This commit is contained in:
Witold Filipczyk 2022-10-16 15:18:34 +02:00
parent d0537ce3c0
commit c086cbe26e
22 changed files with 303 additions and 990 deletions

View File

@ -184,19 +184,19 @@ static widget_handler_status_T
display_button(struct dialog_data *dlg_data, struct widget_data *widget_data)
{
struct terminal *term = dlg_data->win->term;
unsigned int color_node, shortcut_color_node;
struct color_pair *color, *shortcut_color;
struct el_box *pos = &widget_data->box;
int len, x;
int sel = is_selected_widget(dlg_data, widget_data);
if (sel) {
shortcut_color_node = get_bfu_color_node(term, "dialog.button-shortcut-selected");
color_node = get_bfu_color_node(term, "dialog.button-selected");
shortcut_color = get_bfu_color(term, "dialog.button-shortcut-selected");
color = get_bfu_color(term, "dialog.button-selected");
} else {
shortcut_color_node = get_bfu_color_node(term, "dialog.button-shortcut");
color_node = get_bfu_color_node(term, "dialog.button");
shortcut_color = get_bfu_color(term, "dialog.button-shortcut");
color = get_bfu_color(term, "dialog.button");
}
if (!color_node || !shortcut_color_node) return EVENT_PROCESSED;
if (!color || !shortcut_color) return EVENT_PROCESSED;
#ifdef CONFIG_UTF8
if (term->utf8_cp) {
@ -215,7 +215,7 @@ display_button(struct dialog_data *dlg_data, struct widget_data *widget_data)
}
draw_dlg_text_node(dlg_data, pos->x, pos->y, BUTTON_LEFT, BUTTON_LEFT_LEN, 0, color_node);
draw_dlg_text(dlg_data, pos->x, pos->y, BUTTON_LEFT, BUTTON_LEFT_LEN, 0, color);
if (len > 0) {
char *text = widget_data->widget->text;
int hk_pos = widget_data->widget->info.button.hotkey_pos;
@ -240,18 +240,18 @@ display_button(struct dialog_data *dlg_data, struct widget_data *widget_data)
NULL);
if (hk_pos)
draw_dlg_text_node(dlg_data, x, pos->y,
text, hk_pos, 0, color_node);
draw_dlg_text(dlg_data, x, pos->y,
text, hk_pos, 0, color);
draw_dlg_text_node(dlg_data, x + cells_to_hk, pos->y,
draw_dlg_text(dlg_data, x + cells_to_hk, pos->y,
&text[hk_pos + 1], hk_bytes,
attr, shortcut_color_node);
attr, shortcut_color);
if (right > 1)
draw_dlg_text_node(dlg_data, x+cells_to_hk+hk_cells,
draw_dlg_text(dlg_data, x+cells_to_hk+hk_cells,
pos->y,
&text[hk_pos + hk_bytes + 1],
right - 1, 0, color_node);
right - 1, 0, color);
} else {
int hk_width = utf8_char2cells(text, NULL);
@ -261,13 +261,13 @@ display_button(struct dialog_data *dlg_data, struct widget_data *widget_data)
len - hk_width,
NULL);
draw_dlg_text_node(dlg_data, x, pos->y,
draw_dlg_text(dlg_data, x, pos->y,
text, hk_len,
attr, shortcut_color_node);
attr, shortcut_color);
draw_dlg_text_node(dlg_data, x + hk_width, pos->y,
draw_dlg_text(dlg_data, x + hk_width, pos->y,
&text[hk_len], len_to_display,
0, color_node);
0, color);
}
} else
#endif /* CONFIG_UTF8 */
@ -275,18 +275,18 @@ display_button(struct dialog_data *dlg_data, struct widget_data *widget_data)
int right = widget_data->widget->info.button.truetextlen - hk_pos - 1;
if (hk_pos) {
draw_dlg_text_node(dlg_data, x, pos->y, text, hk_pos, 0, color_node);
draw_dlg_text(dlg_data, x, pos->y, text, hk_pos, 0, color);
}
draw_dlg_text_node(dlg_data, x + hk_pos, pos->y,
&text[hk_pos + 1], 1, attr, shortcut_color_node);
draw_dlg_text(dlg_data, x + hk_pos, pos->y,
&text[hk_pos + 1], 1, attr, shortcut_color);
if (right > 1) {
draw_dlg_text_node(dlg_data, x + hk_pos + 1, pos->y,
&text[hk_pos + 2], right - 1, 0, color_node);
draw_dlg_text(dlg_data, x + hk_pos + 1, pos->y,
&text[hk_pos + 2], right - 1, 0, color);
}
} else {
draw_dlg_text_node(dlg_data, x, pos->y, text, 1, attr, shortcut_color_node);
draw_dlg_text_node(dlg_data, x + 1, pos->y, &text[1], len - 1, 0, color_node);
draw_dlg_text(dlg_data, x, pos->y, text, 1, attr, shortcut_color);
draw_dlg_text(dlg_data, x + 1, pos->y, &text[1], len - 1, 0, color);
}
}
#ifdef CONFIG_UTF8
@ -294,12 +294,12 @@ display_button(struct dialog_data *dlg_data, struct widget_data *widget_data)
int text_cells = utf8_ptr2cells(widget_data->widget->text, NULL);
int hk = (widget_data->widget->info.button.hotkey_pos >= 0);
draw_dlg_text_node(dlg_data, x + text_cells - hk, pos->y,
BUTTON_RIGHT, BUTTON_RIGHT_LEN, 0, color_node);
draw_dlg_text(dlg_data, x + text_cells - hk, pos->y,
BUTTON_RIGHT, BUTTON_RIGHT_LEN, 0, color);
} else
#endif /* CONFIG_UTF8 */
draw_dlg_text_node(dlg_data, x + len, pos->y, BUTTON_RIGHT,
BUTTON_RIGHT_LEN, 0, color_node);
draw_dlg_text(dlg_data, x + len, pos->y, BUTTON_RIGHT,
BUTTON_RIGHT_LEN, 0, color);
if (sel) {
set_dlg_cursor(term, dlg_data, x, pos->y, 1);
set_dlg_window_ptr(dlg_data, dlg_data->win, pos->x, pos->y);

View File

@ -50,11 +50,10 @@ dlg_format_checkbox(struct dialog_data *dlg_data,
if (text && *text) {
if (rw) *rw -= CHECKBOX_LS;
dlg_format_text_do_node(dlg_data, text, x + CHECKBOX_LS, y,
dlg_format_text_do(dlg_data, text, x + CHECKBOX_LS, y,
w - CHECKBOX_LS, rw,
get_bfu_color_node(term, "dialog.checkbox-label"),
get_bfu_color(term, "dialog.checkbox-label"),
align, format_only);
if (rw) *rw += CHECKBOX_LS;
}
}
@ -63,24 +62,24 @@ static widget_handler_status_T
display_checkbox(struct dialog_data *dlg_data, struct widget_data *widget_data)
{
struct terminal *term = dlg_data->win->term;
unsigned int color_node;
struct color_pair *color;
const char *text;
struct el_box *pos = &widget_data->box;
int selected = is_selected_widget(dlg_data, widget_data);
if (selected) {
color_node = get_bfu_color_node(term, "dialog.checkbox-selected");
color = get_bfu_color(term, "dialog.checkbox-selected");
} else {
color_node = get_bfu_color_node(term, "dialog.checkbox");
color = get_bfu_color(term, "dialog.checkbox");
}
if (!color_node) return EVENT_PROCESSED;
if (!color) return EVENT_PROCESSED;
if (widget_data->info.checkbox.checked)
text = widget_data->widget->info.checkbox.gid ? "(X)" : "[X]";
else
text = widget_data->widget->info.checkbox.gid ? "( )" : "[ ]";
draw_dlg_text_node(dlg_data, pos->x, pos->y, text, CHECKBOX_LEN, 0, color_node);
draw_dlg_text(dlg_data, pos->x, pos->y, text, CHECKBOX_LEN, 0, color);
if (selected) {
set_dlg_cursor(term, dlg_data, pos->x + 1, pos->y, 1);

View File

@ -72,7 +72,7 @@ void
redraw_dialog(struct dialog_data *dlg_data, int layout)
{
struct terminal *term = dlg_data->win->term;
unsigned int title_color_node;
struct color_pair *title_color;
if (layout) {
dlg_data->dlg->layouter(dlg_data);
@ -91,12 +91,12 @@ redraw_dialog(struct dialog_data *dlg_data, int layout)
dlg_data->box.width - 2 * (DIALOG_LEFT_BORDER + 1),
dlg_data->box.height - 2 * (DIALOG_TOP_BORDER + 1));
draw_border_node(term, &dlg_data->real_box, get_bfu_color_node(term, "dialog.frame"), DIALOG_FRAME);
draw_border(term, &dlg_data->real_box, get_bfu_color(term, "dialog.frame"), DIALOG_FRAME);
assert(dlg_data->dlg->title);
title_color_node = get_bfu_color_node(term, "dialog.title");
if (title_color_node && dlg_data->real_box.width > 2) {
title_color = get_bfu_color(term, "dialog.title");
if (title_color && dlg_data->real_box.width > 2) {
char *title = dlg_data->dlg->title;
int titlelen = strlen(title);
int titlecells = titlelen;
@ -120,10 +120,10 @@ redraw_dialog(struct dialog_data *dlg_data, int layout)
y = dlg_data->real_box.y - 1;
draw_text_node(term, x - 1, y, " ", 1, 0, title_color_node);
draw_text_node(term, x, y, title, titlelen, 0, title_color_node);
draw_text_node(term, x + titlecells, y, " ", 1, 0,
title_color_node);
draw_text(term, x - 1, y, " ", 1, 0, title_color);
draw_text(term, x, y, title, titlelen, 0, title_color);
draw_text(term, x + titlecells, y, " ", 1, 0,
title_color);
}
}
@ -686,13 +686,13 @@ draw_dialog(struct dialog_data *dlg_data, int width, int height)
(term->width - dlg_width) / 2, (term->height - dlg_height) / 2,
dlg_width, dlg_height);
draw_box_node(term, &dlg_data->box, ' ', 0,
get_bfu_color_node(term, "dialog.generic"));
draw_box(term, &dlg_data->box, ' ', 0,
get_bfu_color(term, "dialog.generic"));
if (get_opt_bool("ui.dialogs.shadows", NULL)) {
/* Draw shadow */
draw_shadow_node(term, &dlg_data->box,
get_bfu_color_node(term, "dialog.shadow"), 2, 1);
draw_shadow(term, &dlg_data->box,
get_bfu_color(term, "dialog.shadow"), 2, 1);
#ifdef CONFIG_UTF8
if (term->utf8_cp)
fix_dwchar_around_box(term, &dlg_data->box, 0, 2, 1);

View File

@ -28,7 +28,7 @@ dlg_format_group(struct dialog_data *dlg_data,
int space_between_widgets = 1;
int line_width = 0;
int xpos;
unsigned int color_node = get_bfu_color_node(term, "dialog.text");
struct color_pair *color = get_bfu_color(term, "dialog.text");
assert(n > 0);
if_assert_failed return;
@ -88,18 +88,18 @@ dlg_format_group(struct dialog_data *dlg_data,
text,
label_length,
NULL);
draw_dlg_text_node(dlg_data, xpos + width
draw_dlg_text(dlg_data, xpos + width
+ label_padding,
*y, text, lb, 0,
color_node);
color);
} else
#endif /* CONFIG_UTF8 */
{
draw_dlg_text_node(dlg_data, xpos + width
draw_dlg_text(dlg_data, xpos + width
+ label_padding,
*y, text,
label_length, 0,
color_node);
color);
}
}
@ -114,14 +114,14 @@ dlg_format_group(struct dialog_data *dlg_data,
text,
label_length,
NULL);
draw_dlg_text_node(dlg_data, xpos, *y,
text, lb, 0, color_node);
draw_dlg_text(dlg_data, xpos, *y,
text, lb, 0, color);
} else
#endif /* CONFIG_UTF8 */
{
draw_dlg_text_node(dlg_data, xpos, *y,
draw_dlg_text(dlg_data, xpos, *y,
text, label_length,
0, color_node);
0, color);
}
}

View File

@ -111,7 +111,7 @@ dlg_format_field(struct dialog_data *dlg_data,
static int max_label_width;
static int *prev_y; /* Assert the uniqueness of y */ /* TODO: get rid of this !! --Zas */
char *label = widget_data->widget->text;
unsigned int text_color_node = 0;
struct color_pair *text_color = NULL;
int label_width = 0;
int float_label = widget_data->widget->info.field.flags & (INPFIELD_FLOAT|INPFIELD_FLOAT2);
@ -131,11 +131,9 @@ dlg_format_field(struct dialog_data *dlg_data,
}
if (label && *label) {
if (!format_only) {
text_color_node = get_bfu_color_node(term, "dialog.text");
}
if (!format_only) text_color = get_bfu_color(term, "dialog.text");
dlg_format_text_do_node(dlg_data, label, x, y, w, rw, text_color_node, ALIGN_LEFT, format_only);
dlg_format_text_do(dlg_data, label, x, y, w, rw, text_color, ALIGN_LEFT, format_only);
}
/* XXX: We want the field and label on the same line if the terminal
@ -143,9 +141,9 @@ dlg_format_field(struct dialog_data *dlg_data,
if (label && *label && float_label) {
if (widget_data->widget->info.field.flags & INPFIELD_FLOAT) {
(*y) -= INPUTFIELD_HEIGHT;
dlg_format_text_do_node(dlg_data, INPUTFIELD_FLOAT_SEPARATOR,
dlg_format_text_do(dlg_data, INPUTFIELD_FLOAT_SEPARATOR,
x + label_width, y, w, rw,
text_color_node, ALIGN_LEFT, format_only);
text_color, ALIGN_LEFT, format_only);
w -= INPUTFIELD_FLOAT_SEPARATOR_LEN + INPUTFIELD_FLOATLABEL_PADDING;
x += INPUTFIELD_FLOAT_SEPARATOR_LEN + INPUTFIELD_FLOATLABEL_PADDING;
}
@ -267,7 +265,7 @@ display_field_do(struct dialog_data *dlg_data, struct widget_data *widget_data,
int hide)
{
struct terminal *term = dlg_data->win->term;
unsigned int color_node;
struct color_pair *color;
int sel = is_selected_widget(dlg_data, widget_data);
#ifdef CONFIG_UTF8
int len = 0, left = 0;
@ -291,16 +289,12 @@ display_field_do(struct dialog_data *dlg_data, struct widget_data *widget_data,
int_lower_bound(&widget_data->info.field.vpos, 0);
}
color_node = get_bfu_color_node(term, "dialog.field");
if (color_node) {
draw_box_node(term, &widget_data->box, ' ', 0, color_node);
}
color_node = get_bfu_color_node(term, "dialog.field-text");
if (color_node) {
color = get_bfu_color(term, "dialog.field");
if (color)
draw_box(term, &widget_data->box, ' ', 0, color);
color = get_bfu_color(term, "dialog.field-text");
if (color) {
char *text = widget_data->cdata + widget_data->info.field.vpos;
int len, w;
@ -319,15 +313,15 @@ display_field_do(struct dialog_data *dlg_data, struct widget_data *widget_data,
if (term->utf8_cp)
w = utf8_cells2bytes(text, w, NULL);
#endif /* CONFIG_UTF8 */
draw_dlg_text_node(dlg_data, widget_data->box.x, widget_data->box.y,
text, w, 0, color_node);
draw_dlg_text(dlg_data, widget_data->box.x, widget_data->box.y,
text, w, 0, color);
} else {
struct el_box box;
copy_box(&box, &widget_data->box);
box.width = w;
draw_box_node(term, &box, '*', 0, color_node);
draw_box(term, &box, '*', 0, color);
}
}
@ -601,9 +595,9 @@ kbd_field(struct dialog_data *dlg_data, struct widget_data *widget_data)
int cdata_len = strlen(widget_data->cdata);
int start = widget_data->info.field.cpos;
while (start > 0 && isspace((unsigned char)widget_data->cdata[start - 1]))
while (start > 0 && isspace(widget_data->cdata[start - 1]))
--start;
while (start > 0 && !isspace((unsigned char)widget_data->cdata[start - 1]))
while (start > 0 && !isspace(widget_data->cdata[start - 1]))
--start;
memmove(widget_data->cdata + start,
@ -616,19 +610,19 @@ kbd_field(struct dialog_data *dlg_data, struct widget_data *widget_data)
}
case ACT_EDIT_MOVE_BACKWARD_WORD:
while (widget_data->info.field.cpos > 0 && isspace((unsigned char)widget_data->cdata[widget_data->info.field.cpos - 1]))
while (widget_data->info.field.cpos > 0 && isspace(widget_data->cdata[widget_data->info.field.cpos - 1]))
--widget_data->info.field.cpos;
while (widget_data->info.field.cpos > 0 && !isspace((unsigned char)widget_data->cdata[widget_data->info.field.cpos - 1]))
while (widget_data->info.field.cpos > 0 && !isspace(widget_data->cdata[widget_data->info.field.cpos - 1]))
--widget_data->info.field.cpos;
goto display_field;
case ACT_EDIT_MOVE_FORWARD_WORD:
while (isspace((unsigned char)widget_data->cdata[widget_data->info.field.cpos]))
while (isspace(widget_data->cdata[widget_data->info.field.cpos]))
++widget_data->info.field.cpos;
while (widget_data->cdata[widget_data->info.field.cpos] && !isspace((unsigned char)widget_data->cdata[widget_data->info.field.cpos]))
while (widget_data->cdata[widget_data->info.field.cpos] && !isspace(widget_data->cdata[widget_data->info.field.cpos]))
++widget_data->info.field.cpos;
while (isspace((unsigned char)widget_data->cdata[widget_data->info.field.cpos]))
while (isspace(widget_data->cdata[widget_data->info.field.cpos]))
++widget_data->info.field.cpos;
goto display_field;

View File

@ -178,7 +178,7 @@ init_led_panel(struct led_panel *leds)
}
static int
draw_timer_node(struct terminal *term, int xpos, int ypos, unsigned int node_number)
draw_timer(struct terminal *term, int xpos, int ypos, struct color_pair *color)
{
char s[64];
int i, length;
@ -187,14 +187,13 @@ draw_timer_node(struct terminal *term, int xpos, int ypos, unsigned int node_num
length = strlen(s);
for (i = length - 1; i >= 0; i--)
draw_char_node(term, xpos - (length - i), ypos, s[i], 0, node_number);
draw_char(term, xpos - (length - i), ypos, s[i], 0, color);
return length;
}
static int
draw_show_ip_node(struct session *ses, int xpos, int ypos, unsigned int node_number)
draw_show_ip(struct session *ses, int xpos, int ypos, struct color_pair *color)
{
if (ses->doc_view && ses->doc_view->document && ses->doc_view->document->ip) {
struct terminal *term = ses->tab->term;
@ -203,21 +202,19 @@ draw_show_ip_node(struct session *ses, int xpos, int ypos, unsigned int node_num
int i;
for (i = length - 1; i >= 0; i--)
draw_char_node(term, xpos - (length - i), ypos, s[i], 0, node_number);
draw_char(term, xpos - (length - i), ypos, s[i], 0, color);
return length;
}
return 0;
}
static int
draw_temperature_node(struct session *ses, int xpos, int ypos, unsigned int node_number)
draw_temperature(struct session *ses, int xpos, int ypos, struct color_pair *color)
{
struct terminal *term = ses->tab->term;
FILE *f;
int temp = 0;
int ret;
struct string text;
int i;
int length;
@ -225,16 +222,9 @@ draw_temperature_node(struct session *ses, int xpos, int ypos, unsigned int node
f = fopen(get_leds_temperature_filename(), "r");
if (!f) {
return 0;
}
ret = fscanf(f, "%d", &temp);
if (!f) return 0;
fscanf(f, "%d", &temp);
fclose(f);
if (ret < 1) {
return 0;
}
if (!init_string(&text)) {
return 0;
}
@ -255,7 +245,7 @@ draw_temperature_node(struct session *ses, int xpos, int ypos, unsigned int node
#else
unsigned char data = pos[i];
#endif
draw_char_node(term, xpos - length + i, ypos, data, 0, node_number);
draw_char(term, xpos - length + i, ypos, data, 0, color);
}
done_string(&text);
@ -264,7 +254,7 @@ draw_temperature_node(struct session *ses, int xpos, int ypos, unsigned int node
#ifdef HAVE_STRFTIME
static int
draw_clock_node(struct terminal *term, int xpos, int ypos, unsigned int node_number)
draw_clock(struct terminal *term, int xpos, int ypos, struct color_pair *color)
{
char s[64];
time_t curtime = time(NULL);
@ -274,7 +264,7 @@ draw_clock_node(struct terminal *term, int xpos, int ypos, unsigned int node_num
length = strftime(s, sizeof(s), get_leds_clock_format(), loctime);
s[length] = '\0';
for (i = length - 1; i >= 0; i--)
draw_char_node(term, xpos - (length - i), ypos, s[i], 0, node_number);
draw_char(term, xpos - (length - i), ypos, s[i], 0, color);
return length;
}
@ -299,7 +289,7 @@ void
draw_leds(struct session *ses)
{
struct terminal *term = ses->tab->term;
unsigned int node_number = 0;
struct color_pair *led_color = NULL;
int i;
int xpos = term->width - LEDS_COUNT - 3;
int ypos = term->height - 1;
@ -309,50 +299,50 @@ draw_leds(struct session *ses)
/* This should be done elsewhere, but this is very nice place where we
* could do that easily. */
if (get_opt_int("ui.timer.enable", NULL) == 2) {
node_number = get_bfu_color_node(term, "status.status-text");
if (!node_number) goto end;
led_color = get_bfu_color(term, "status.status-text");
if (!led_color) goto end;
term->leds_length += draw_timer_node(term, xpos, ypos, node_number);
term->leds_length += draw_timer(term, xpos, ypos, led_color);
}
if (!get_leds_panel_enable()) return;
if (!node_number) {
node_number = get_bfu_color_node(term, "status.status-text");
if (!node_number) goto end;
if (!led_color) {
led_color = get_bfu_color(term, "status.status-text");
if (!led_color) goto end;
}
#ifdef HAVE_STRFTIME
if (get_leds_clock_enable()) {
term->leds_length += draw_clock_node(term, xpos - term->leds_length, ypos, node_number);
term->leds_length += draw_clock(term, xpos - term->leds_length, ypos, led_color);
}
#endif
if (get_leds_temperature_enable()) {
unsigned int node_number = get_bfu_color_node(term, "status.status-text");
struct color_pair *color = get_bfu_color(term, "status.status-text");
if (node_number) term->leds_length += draw_temperature_node(ses, xpos - term->leds_length, ypos, node_number);
if (color) term->leds_length += draw_temperature(ses, xpos - term->leds_length, ypos, color);
}
if (get_leds_show_ip_enable()) {
unsigned int node_number = get_bfu_color_node(term, "status.showip-text");
struct color_pair *color = get_bfu_color(term, "status.showip-text");
if (node_number) term->leds_length += draw_show_ip_node(ses, xpos - term->leds_length, ypos, node_number);
if (color) term->leds_length += draw_show_ip(ses, xpos - term->leds_length, ypos, color);
}
/* We must shift the whole thing by one char to left, because we don't
* draft the char in the right-down corner :(. */
draw_char_node(term, xpos, ypos, '[', 0, node_number);
draw_char(term, xpos, ypos, '[', 0, led_color);
for (i = 0; i < LEDS_COUNT; i++) {
struct led *led = &ses->status.leds.leds[i];
draw_char_node(term, xpos + i + 1, ypos, led->value__, 0, node_number);
draw_char(term, xpos + i + 1, ypos, led->value__, 0, led_color);
led->value_changed__ = 0;
}
draw_char_node(term, xpos + LEDS_COUNT + 1, ypos, ']', 0, node_number);
draw_char(term, xpos + LEDS_COUNT + 1, ypos, ']', 0, led_color);
term->leds_length += LEDS_COUNT + 2;

View File

@ -354,20 +354,20 @@ display_listbox_item(struct listbox_item *item, void *data_, int *offset)
{
struct listbox_context *data = (struct listbox_context *)data_;
int len; /* Length of the current text field. */
unsigned int tree_color_node, text_color_node;
struct color_pair *tree_color, *text_color;
int depth = item->depth + 1;
int d;
int x, y;
tree_color_node = get_bfu_color_node(data->term, "menu.normal");
tree_color = get_bfu_color(data->term, "menu.normal");
if (item == data->box->sel) {
text_color_node = get_bfu_color_node(data->term, "menu.selected");
text_color = get_bfu_color(data->term, "menu.selected");
} else if (item->marked) {
text_color_node = get_bfu_color_node(data->term, "menu.marked");
text_color = get_bfu_color(data->term, "menu.marked");
} else {
text_color_node = tree_color_node;
text_color = tree_color;
}
y = data->widget_data->box.y + data->offset;
@ -383,13 +383,13 @@ display_listbox_item(struct listbox_item *item, void *data_, int *offset)
/* XXX */
x = data->widget_data->box.x + d * 5;
draw_text_node(data->term, x, y, " ", 5, 0, tree_color_node);
draw_text(data->term, x, y, " ", 5, 0, tree_color);
if (root ? root->child.prev == child
: data->box->items->prev == child)
continue; /* We were the last branch. */
draw_border_char_node(data->term, x + 1, y, BORDER_SVLINE, tree_color_node);
draw_border_char(data->term, x + 1, y, BORDER_SVLINE, tree_color);
}
if (depth) {
@ -440,7 +440,7 @@ display_listbox_item(struct listbox_item *item, void *data_, int *offset)
x = data->widget_data->box.x + (depth - 1) * 5;
for (i = 0; i < 5; i++) {
draw_border_char_node(data->term, x + i, y, str[i], tree_color_node);
draw_border_char(data->term, x + i, y, str[i], tree_color);
}
}
@ -451,7 +451,7 @@ display_listbox_item(struct listbox_item *item, void *data_, int *offset)
int width = data->widget_data->box.width - depth * 5;
for (i = 0; i < width; i++) {
draw_border_char_node(data->term, x + i, y, BORDER_SHLINE, text_color_node);
draw_border_char(data->term, x + i, y, BORDER_SHLINE, text_color);
}
} else if (data->box->ops && data->box->ops->draw) {
@ -478,7 +478,7 @@ display_listbox_item(struct listbox_item *item, void *data_, int *offset)
#endif /* CONFIG_UTF8 */
len_bytes = len;
draw_text_node(data->term, x, y, text, len_bytes, 0, text_color_node);
draw_text(data->term, x, y, text, len_bytes, 0, text_color);
mem_free(text);
}
@ -505,8 +505,8 @@ display_listbox(struct dialog_data *dlg_data, struct widget_data *widget_data)
listbox_sel_move(widget_data, 0);
draw_box_node(term, &widget_data->box, ' ', 0,
get_bfu_color_node(term, "menu.normal"));
draw_box(term, &widget_data->box, ' ', 0,
get_bfu_color(term, "menu.normal"));
memset(&data, 0, sizeof(data));
data.term = term;

View File

@ -371,8 +371,8 @@ set_menu_selection(struct menu *menu, int pos)
* separators). For double-width glyph width == 2.
* len - length of text in bytes */
static inline void
draw_menu_left_text_node(struct terminal *term, char *text, int len,
int x, int y, int width, unsigned int color_node)
draw_menu_left_text(struct terminal *term, char *text, int len,
int x, int y, int width, struct color_pair *color)
{
int w = width - (L_TEXT_SPACE + R_TEXT_SPACE);
int max_len;
@ -393,17 +393,17 @@ draw_menu_left_text_node(struct terminal *term, char *text, int len,
if (len > max_len) len = max_len;
draw_text_node(term, x + L_TEXT_SPACE, y, text, len, 0, color_node);
draw_text(term, x + L_TEXT_SPACE, y, text, len, 0, color);
}
static inline void
draw_menu_left_text_hk_node(struct terminal *term, char *text,
draw_menu_left_text_hk(struct terminal *term, char *text,
int hotkey_pos, int x, int y, int width,
unsigned int color_node, int selected)
struct color_pair *color, int selected)
{
unsigned int hk_color_node = get_bfu_color_node(term, "menu.hotkey.normal");
unsigned int hk_color_sel_node = get_bfu_color_node(term, "menu.hotkey.selected");
struct color_pair *hk_color = get_bfu_color(term, "menu.hotkey.normal");
struct color_pair *hk_color_sel = get_bfu_color(term, "menu.hotkey.selected");
screen_char_attr_T hk_attr = get_opt_bool("ui.dialogs.underline_hotkeys", NULL)
? SCREEN_ATTR_UNDERLINE : 0;
unsigned char c;
@ -424,10 +424,10 @@ draw_menu_left_text_hk_node(struct terminal *term, char *text,
if (!hotkey_pos || w <= 0) return;
if (selected) {
unsigned int tmp = hk_color_node;
struct color_pair *tmp = hk_color;
hk_color_node = hk_color_sel_node;
hk_color_sel_node = tmp;
hk_color = hk_color_sel;
hk_color_sel = tmp;
}
#ifdef CONFIG_UTF8
@ -442,14 +442,14 @@ draw_menu_left_text_hk_node(struct terminal *term, char *text,
if (hk_state == 1) {
#ifdef CONFIG_DEBUG
draw_char_node(term, xbase + x - 1, y, c, hk_attr,
(double_hk ? hk_color_sel_node : hk_color_node));
draw_char(term, xbase + x - 1, y, c, hk_attr,
(double_hk ? hk_color_sel : hk_color));
#else
draw_char_node(term, xbase + x - 1, y, c, hk_attr, hk_color_node);
draw_char(term, xbase + x - 1, y, c, hk_attr, hk_color);
#endif /* CONFIG_DEBUG */
hk_state = 2;
} else {
draw_char_node(term, xbase + x - !!hk_state, y, c, 0, color_node);
draw_char(term, xbase + x - !!hk_state, y, c, 0, color);
}
}
return;
@ -470,30 +470,30 @@ utf8:
if (unicode_to_cell(data) == 2) {
if (x < w && xbase + x < term->width) {
#ifdef CONFIG_DEBUG
draw_char_node(term, xbase + x - 1, y,
draw_char(term, xbase + x - 1, y,
data, hk_attr,
(double_hk ? hk_color_sel_node
: hk_color_node));
(double_hk ? hk_color_sel
: hk_color));
#else
draw_char_node(term, xbase + x - 1, y,
data, hk_attr, hk_color_node);
draw_char(term, xbase + x - 1, y,
data, hk_attr, hk_color);
#endif /* CONFIG_DEBUG */
x++;
draw_char_node(term, xbase + x - 1, y,
UCS_NO_CHAR, 0, hk_color_node);
draw_char(term, xbase + x - 1, y,
UCS_NO_CHAR, 0, hk_color);
} else {
draw_char_node(term, xbase + x - 1, y,
UCS_ORPHAN_CELL, 0, hk_color_node);
draw_char(term, xbase + x - 1, y,
UCS_ORPHAN_CELL, 0, hk_color);
}
} else {
#ifdef CONFIG_DEBUG
draw_char_node(term, xbase + x - 1, y,
draw_char(term, xbase + x - 1, y,
data, hk_attr,
(double_hk ? hk_color_sel_node
: hk_color_node));
(double_hk ? hk_color_sel
: hk_color));
#else
draw_char_node(term, xbase + x - 1, y,
data, hk_attr, hk_color_node);
draw_char(term, xbase + x - 1, y,
data, hk_attr, hk_color);
#endif /* CONFIG_DEBUG */
}
hk_state = 2;
@ -501,18 +501,18 @@ utf8:
if (unicode_to_cell(data) == 2) {
if (x - !!hk_state + 1 < w &&
xbase + x - !!hk_state + 1 < term->width) {
draw_char_node(term, xbase + x - !!hk_state,
y, data, 0, color_node);
draw_char(term, xbase + x - !!hk_state,
y, data, 0, color);
x++;
draw_char_node(term, xbase + x - !!hk_state,
y, UCS_NO_CHAR, 0, color_node);
draw_char(term, xbase + x - !!hk_state,
y, UCS_NO_CHAR, 0, color);
} else {
draw_char_node(term, xbase + x - !!hk_state,
y, UCS_ORPHAN_CELL, 0, color_node);
draw_char(term, xbase + x - !!hk_state,
y, UCS_ORPHAN_CELL, 0, color);
}
} else {
draw_char_node(term, xbase + x - !!hk_state,
y, data, 0, color_node);
draw_char(term, xbase + x - !!hk_state,
y, data, 0, color);
}
}
@ -521,8 +521,8 @@ utf8:
}
static inline void
draw_menu_right_text_node(struct terminal *term, char *text, int len,
int x, int y, int width, unsigned int color_node)
draw_menu_right_text(struct terminal *term, char *text, int len,
int x, int y, int width, struct color_pair *color)
{
int w = width - (L_RTEXT_SPACE + R_RTEXT_SPACE);
@ -534,17 +534,15 @@ draw_menu_right_text_node(struct terminal *term, char *text, int len,
x += w - len + L_RTEXT_SPACE + L_TEXT_SPACE;
draw_text_node(term, x, y, text, len, 0, color_node);
draw_text(term, x, y, text, len, 0, color);
}
static void
display_menu(struct terminal *term, struct menu *menu)
{
unsigned int normal_color_node = get_bfu_color_node(term, "menu.normal");
unsigned int selected_color_node = get_bfu_color_node(term, "menu.selected");
unsigned int frame_color_node = get_bfu_color_node(term, "menu.frame");
struct color_pair *normal_color = get_bfu_color(term, "menu.normal");
struct color_pair *selected_color = get_bfu_color(term, "menu.selected");
struct color_pair *frame_color = get_bfu_color(term, "menu.frame");
struct el_box box;
int p;
int menu_height;
@ -555,13 +553,13 @@ display_menu(struct terminal *term, struct menu *menu)
int_max(0, menu->box.width - MENU_BORDER_SIZE * 2),
int_max(0, menu->box.height - MENU_BORDER_SIZE * 2));
draw_box_node(term, &box, ' ', 0, normal_color_node);
draw_border_node(term, &box, frame_color_node, 1);
draw_box(term, &box, ' ', 0, normal_color);
draw_border(term, &box, frame_color, 1);
if (get_opt_bool("ui.dialogs.shadows", NULL)) {
/* Draw shadow */
draw_shadow_node(term, &menu->box,
get_bfu_color_node(term, "dialog.shadow"), 2, 1);
draw_shadow(term, &menu->box,
get_bfu_color(term, "dialog.shadow"), 2, 1);
#ifdef CONFIG_UTF8
if (term->utf8_cp)
fix_dwchar_around_box(term, &box, 1, 2, 1);
@ -578,7 +576,7 @@ display_menu(struct terminal *term, struct menu *menu)
for (p = menu->first;
p < menu->size && p < menu->first + menu_height;
p++, box.y++) {
unsigned int color_node = normal_color_node;
struct color_pair *color = normal_color;
struct menu_item *mi = &menu->items[p];
int selected = (p == menu->selected);
@ -590,23 +588,23 @@ display_menu(struct terminal *term, struct menu *menu)
if (selected) {
/* This entry is selected. */
color_node = selected_color_node;
color = selected_color;
set_cursor(term, box.x, box.y, 1);
set_window_ptr(menu->win, menu->box.x + menu->box.width, box.y);
draw_box_node(term, &box, ' ', 0, color_node);
draw_box(term, &box, ' ', 0, color);
}
if (mi_is_horizontal_bar(mi)) {
/* Horizontal separator */
draw_border_char_node(term, menu->box.x, box.y,
BORDER_SRTEE, frame_color_node);
draw_border_char(term, menu->box.x, box.y,
BORDER_SRTEE, frame_color);
draw_box_node(term, &box, BORDER_SHLINE,
SCREEN_ATTR_FRAME, frame_color_node);
draw_box(term, &box, BORDER_SHLINE,
SCREEN_ATTR_FRAME, frame_color);
draw_border_char_node(term, box.x + box.width, box.y,
BORDER_SLTEE, frame_color_node);
draw_border_char(term, box.x + box.width, box.y,
BORDER_SLTEE, frame_color);
continue;
}
@ -622,29 +620,29 @@ display_menu(struct terminal *term, struct menu *menu)
l = 0;
if (l) {
draw_menu_left_text_hk_node(term, text, l,
box.x, box.y, box.width, color_node,
draw_menu_left_text_hk(term, text, l,
box.x, box.y, box.width, color,
selected);
} else {
draw_menu_left_text_node(term, text, -1,
box.x, box.y, box.width, color_node);
draw_menu_left_text(term, text, -1,
box.x, box.y, box.width, color);
}
}
if (mi_is_submenu(mi)) {
draw_menu_right_text_node(term, m_submenu, m_submenu_len,
menu->box.x, box.y, box.width, color_node);
draw_menu_right_text(term, m_submenu, m_submenu_len,
menu->box.x, box.y, box.width, color);
} else if (mi->action_id != ACT_MAIN_NONE) {
struct string keystroke;
#ifdef CONFIG_DEBUG
/* Help to detect action + right text. --Zas */
if (mi_has_right_text(mi)) {
if (color_node == selected_color_node)
color_node = normal_color_node;
if (color == selected_color)
color = normal_color;
else
color_node = selected_color_node;
color = selected_color;
}
#endif /* CONFIG_DEBUG */
@ -652,10 +650,10 @@ display_menu(struct terminal *term, struct menu *menu)
add_keystroke_action_to_string(&keystroke,
mi->action_id,
KEYMAP_MAIN);
draw_menu_right_text_node(term, keystroke.source,
draw_menu_right_text(term, keystroke.source,
keystroke.length,
menu->box.x, box.y,
box.width, color_node);
box.width, color);
done_string(&keystroke);
}
@ -667,9 +665,9 @@ display_menu(struct terminal *term, struct menu *menu)
if (*rtext) {
/* There's a right text, so print it */
draw_menu_right_text_node(term, rtext, -1,
draw_menu_right_text(term, rtext, -1,
menu->box.x,
box.y, box.width, color_node);
box.y, box.width, color);
}
}
}
@ -1087,8 +1085,8 @@ do_mainmenu(struct terminal *term, struct menu_item *items,
static void
display_mainmenu(struct terminal *term, struct menu *menu)
{
unsigned int normal_color_node = get_bfu_color_node(term, "menu.normal");
unsigned int selected_color_node = get_bfu_color_node(term, "menu.selected");
struct color_pair *normal_color = get_bfu_color(term, "menu.normal");
struct color_pair *selected_color = get_bfu_color(term, "menu.selected");
int p = 0;
int i;
struct el_box box;
@ -1117,18 +1115,18 @@ display_mainmenu(struct terminal *term, struct menu *menu)
int_bounds(&menu->first, 0, menu->last);
set_box(&box, 0, 0, term->width, 1);
draw_box_node(term, &box, ' ', 0, normal_color_node);
draw_box(term, &box, ' ', 0, normal_color);
if (menu->first != 0) {
box.width = L_MAINMENU_SPACE;
draw_box_node(term, &box, '<', 0, normal_color_node);
draw_box(term, &box, '<', 0, normal_color);
}
p += L_MAINMENU_SPACE;
for (i = menu->first; i < menu->size; i++) {
struct menu_item *mi = &menu->items[i];
unsigned int color_node = normal_color_node;
struct color_pair *color = normal_color;
char *text = mi->text;
int l = mi->hotkey_pos;
int textlen;
@ -1147,7 +1145,7 @@ display_mainmenu(struct terminal *term, struct menu *menu)
screencnt = textlen;
if (selected) {
color_node = selected_color_node;
color = selected_color;
box.x = p;
#ifdef CONFIG_UTF8
if (term->utf8_cp)
@ -1160,7 +1158,7 @@ display_mainmenu(struct terminal *term, struct menu *menu)
+ textlen
+ R_TEXT_SPACE + R_MAINTEXT_SPACE;
draw_box_node(term, &box, ' ', 0, color_node);
draw_box(term, &box, ' ', 0, color);
set_cursor(term, p, 0, 1);
set_window_ptr(menu->win, p, 1);
}
@ -1168,13 +1166,13 @@ display_mainmenu(struct terminal *term, struct menu *menu)
p += L_MAINTEXT_SPACE;
if (l) {
draw_menu_left_text_hk_node(term, text, l,
draw_menu_left_text_hk(term, text, l,
p, 0, textlen + R_TEXT_SPACE + L_TEXT_SPACE,
color_node, selected);
color, selected);
} else {
draw_menu_left_text_node(term, text, textlen,
draw_menu_left_text(term, text, textlen,
p, 0, textlen + R_TEXT_SPACE + L_TEXT_SPACE,
color_node);
color);
}
p += screencnt;
@ -1207,7 +1205,7 @@ display_mainmenu(struct terminal *term, struct menu *menu)
set_box(&box,
term->width - R_MAINMENU_SPACE, 0,
R_MAINMENU_SPACE, 1);
draw_box_node(term, &box, '>', 0, normal_color_node);
draw_box(term, &box, '>', 0, normal_color);
}
redraw_windows(REDRAW_IN_FRONT_OF_WINDOW, menu->win);

View File

@ -20,7 +20,7 @@
#include "util/color.h"
/* FIXME: For UTF-8 strings we need better function than isspace. */
#define is_unsplitable(pos) (*(pos) && *(pos) != '\n' && !isspace((unsigned char)*(pos)))
#define is_unsplitable(pos) (*(pos) && *(pos) != '\n' && !isspace(*(pos)))
void
add_dlg_text(struct dialog *dlg, char *text,
@ -175,7 +175,7 @@ split_lines(struct widget_data *widget_data, int max_width)
int cells = 0;
/* Skip first leading \n or space. */
if (isspace((unsigned char)*text)) text++;
if (isspace(*text)) text++;
if (!*text) break;
#ifdef CONFIG_UTF8
@ -210,13 +210,12 @@ split_lines(struct widget_data *widget_data, int max_width)
return lines;
}
/* Format text according to dialog box and alignment. */
void
dlg_format_text_do_node(struct dialog_data *dlg_data,
dlg_format_text_do(struct dialog_data *dlg_data,
const char *text,
int x, int *y, int width, int *real_width,
unsigned int color_node, format_align_T align,
struct color_pair *color, format_align_T align,
int format_only)
{
#ifdef CONFIG_UTF8
@ -230,7 +229,7 @@ dlg_format_text_do_node(struct dialog_data *dlg_data,
int cells = 0;
/* Skip first leading \n or space. */
if (!firstline && isspace((unsigned char)*text))
if (!firstline && isspace(*text))
text++;
else
firstline = 0;
@ -261,11 +260,10 @@ dlg_format_text_do_node(struct dialog_data *dlg_data,
assert(cells <= width && shift < width);
draw_dlg_text_node(dlg_data, x + shift, *y, text, line_width, 0, color_node);
draw_dlg_text(dlg_data, x + shift, *y, text, line_width, 0, color);
}
}
void
dlg_format_text(struct dialog_data *dlg_data,
struct widget_data *widget_data,
@ -344,12 +342,11 @@ dlg_format_text(struct dialog_data *dlg_data,
widget_data->info.text.current = 0;
}
dlg_format_text_do_node(dlg_data, text,
dlg_format_text_do(dlg_data, text,
x, y, width, real_width,
get_bfu_color_node(term, "dialog.text"),
get_bfu_color(term, "dialog.text"),
widget_data->widget->info.text.align, format_only);
if (widget_data->widget->info.text.is_label) (*y)--;
/* If we scrolled and something was trimmed restore it */
@ -373,8 +370,8 @@ display_text(struct dialog_data *dlg_data, struct widget_data *widget_data)
if (!text_is_scrollable(widget_data) || box.height <= 0)
return EVENT_PROCESSED;
draw_box_node(win->term, &box, ' ', 0,
get_bfu_color_node(win->term, "dialog.scrollbar"));
draw_box(win->term, &box, ' ', 0,
get_bfu_color(win->term, "dialog.scrollbar"));
current = widget_data->info.text.current;
scale = (box.height + 1) * 100 / lines;
@ -400,8 +397,8 @@ display_text(struct dialog_data *dlg_data, struct widget_data *widget_data)
widget_data->info.text.scroller_y = box.y;
#endif
draw_box_node(win->term, &box, ' ', 0,
get_bfu_color_node(win->term, "dialog.scrollbar-selected"));
draw_box(win->term, &box, ' ', 0,
get_bfu_color(win->term, "dialog.scrollbar-selected"));
/* Hope this is at least a bit reasonable. Set cursor
* and window pointer to start of the first text line. */
@ -430,8 +427,8 @@ format_and_display_text(struct widget_data *widget_data,
widget_data->info.text.current = current;
draw_box_node(term, &widget_data->box, ' ', 0,
get_bfu_color_node(term, "dialog.generic"));
draw_box(term, &widget_data->box, ' ', 0,
get_bfu_color(term, "dialog.generic"));
dlg_format_text(dlg_data, widget_data,
widget_data->box.x, &y, widget_data->box.width, NULL,

View File

@ -135,7 +135,7 @@ download_dialog_layouter(struct dialog_data *dlg_data)
int url_len;
char *url;
struct download *download = &file_download->download;
unsigned int dialog_text_color_node = get_bfu_color_node(term, "dialog.text");
struct color_pair *dialog_text_color = get_bfu_color(term, "dialog.text");
char *msg = get_download_msg(download, term, 1, 1, "\n");
int show_meter = (download_is_progressing(download)
&& download->progress->size >= 0);
@ -166,8 +166,8 @@ download_dialog_layouter(struct dialog_data *dlg_data)
int_lower_bound(&w, DOWN_DLG_MIN);
}
dlg_format_text_do_node(dlg_data, url, 0, &y, w, &rw,
dialog_text_color_node, ALIGN_LEFT, 1);
dlg_format_text_do(dlg_data, url, 0, &y, w, &rw,
dialog_text_color, ALIGN_LEFT, 1);
y++;
if (show_meter) y += 2;
@ -175,8 +175,8 @@ download_dialog_layouter(struct dialog_data *dlg_data)
#ifdef CONFIG_BITTORRENT
if (bittorrent) y += 2;
#endif
dlg_format_text_do_node(dlg_data, msg, 0, &y, w, &rw,
dialog_text_color_node, ALIGN_LEFT, 1);
dlg_format_text_do(dlg_data, msg, 0, &y, w, &rw,
dialog_text_color, ALIGN_LEFT, 1);
y++;
dlg_format_buttons(dlg_data, dlg_data->widgets_data,
@ -199,25 +199,25 @@ download_dialog_layouter(struct dialog_data *dlg_data)
y = dlg_data->box.y + DIALOG_TB + 1;
x = dlg_data->box.x + DIALOG_LB;
dlg_format_text_do_node(dlg_data, url, x, &y, w, NULL,
dialog_text_color_node, ALIGN_LEFT, 0);
dlg_format_text_do(dlg_data, url, x, &y, w, NULL,
dialog_text_color, ALIGN_LEFT, 0);
if (show_meter) {
y++;
draw_progress_bar_node(download->progress, term, x, y, w, NULL, 0);
draw_progress_bar(download->progress, term, x, y, w, NULL, NULL);
y++;
}
#ifdef CONFIG_BITTORRENT
if (bittorrent) {
y++;
draw_bittorrent_piece_progress_node(download, term, x, y, w, NULL, 0);
draw_bittorrent_piece_progress(download, term, x, y, w, NULL, NULL);
y++;
}
#endif
y++;
dlg_format_text_do_node(dlg_data, msg, x, &y, w, NULL,
dialog_text_color_node, ALIGN_LEFT, 0);
dlg_format_text_do(dlg_data, msg, x, &y, w, NULL,
dialog_text_color, ALIGN_LEFT, 0);
y++;
dlg_format_buttons(dlg_data, dlg_data->widgets_data,