TTY: modified line drawing.

This commit is contained in:
Andrew Borodin 2009-06-03 23:07:06 +04:00
parent 28580ca023
commit 30fd7fc34a
14 changed files with 142 additions and 148 deletions

View File

@ -271,9 +271,10 @@ print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
int y = row + EDIT_TEXT_VERTICAL_OFFSET;
int cols_to_skip = abs (x);
unsigned char str[6 + 1];
tty_setcolor (EDITOR_NORMAL_COLOR);
edit_move (x1, y);
hline (' ', end_col + 1 - EDIT_TEXT_HORIZONTAL_OFFSET - x1);
tty_draw_hline (edit->widget.y + y, edit->widget.x + x1,
' ', end_col + 1 - EDIT_TEXT_HORIZONTAL_OFFSET - x1);
if (option_line_state) {
int i;

View File

@ -35,7 +35,11 @@
#include <unistd.h>
#include "global.h"
#include "../src/tty/tty.h"
#include "../src/tty/color.h" /* tty_set_normal_attrs */
#include "../src/tty/win.h"
#include "cons.saver.h"
signed char console_flag = 0;

View File

@ -64,13 +64,10 @@ static void dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t message,
static void
slow_box (Dlg_head *h, int y, int x, int ys, int xs)
{
tty_gotoyx (h->y + y, h->x + x);
hline (' ', xs);
vline (' ', ys);
tty_gotoyx (h->y + y, h->x + x + xs - 1);
vline (' ', ys);
tty_gotoyx (h->y + y + ys - 1, h->x + x);
hline (' ', xs);
tty_draw_hline (h->y + y, h->x + x, ' ', xs);
tty_draw_vline (h->y + y, h->x + x, ' ', ys);
tty_draw_vline (h->y + y, h->x + x + xs - 1, ' ', ys);
tty_draw_hline (h->y + y + ys - 1, h->x + x, ' ', xs);
}
/* draw box in window */

View File

@ -78,8 +78,8 @@ info_show_info (struct WInfo *info)
widget_move (&info->widget, 1, 3);
tty_printf (_("Midnight Commander %s"), VERSION);
tty_setcolor (NORMAL_COLOR);
widget_move (&info->widget, 2, 1);
hline (ACS_HLINE|NORMAL_COLOR, info->widget.cols-2);
tty_draw_hline (info->widget.y + 2, info->widget.x + 1,
ACS_HLINE, info->widget.cols - 2);
if (get_current_type () != view_listing)
return;

View File

@ -94,17 +94,19 @@ static void menubar_paint_idx (WMenu *menubar, int idx, int color)
tty_print_alt_char (ACS_LTEE);
}
tty_print_hline (menubar->widget.y + y, menubar->widget.x + x,
menubar->max_entry_len + 2);
tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x,
slow_terminal ? ' ' : ACS_HLINE, menubar->max_entry_len + 2);
if (!slow_terminal)
if (!slow_terminal) {
widget_move (&menubar->widget, y, x + menubar->max_entry_len + 2);
tty_print_alt_char (ACS_RTEE);
}
} else {
/* menu text */
tty_setcolor (color);
widget_move (&menubar->widget, y, x);
tty_print_char ((unsigned char) entry->first_letter);
hline (' ', menubar->max_entry_len + 1); /* clear line */
tty_draw_hline (-1, -1, ' ', menubar->max_entry_len + 1); /* clear line */
tty_print_string (entry->text.start);
if (entry->text.hotkey != NULL) {
@ -152,9 +154,7 @@ static void menubar_draw (WMenu *menubar)
/* First draw the complete menubar */
tty_setcolor (SELECTED_COLOR);
widget_move (&menubar->widget, 0, 0);
hline (' ', menubar->widget.cols);
tty_draw_hline (menubar->widget.y, menubar->widget.x, ' ', menubar->widget.cols);
tty_setcolor (SELECTED_COLOR);
/* Now each one of the entries */

View File

@ -52,7 +52,7 @@
#include "widget.h"
#include "menu.h" /* menubar_visible */
#include "main-widgets.h"
#include "main.h" /* the_menubar */
#include "main.h" /* the_menubar, slow_terminal */
#include "unixcompat.h"
#include "mountlist.h" /* my_statfs */
#include "selcodepage.h" /* select_charset () */
@ -566,13 +566,13 @@ format_file (char *dest, int limit, WPanel *panel, int file_index, int width, in
tty_setcolor (SELECTED_COLOR);
else
tty_setcolor (NORMAL_COLOR);
tty_print_one_vline ();
tty_print_one_vline (slow_terminal);
length++;
}
}
if (length < width)
hline (' ', width - length);
tty_draw_hline (-1, -1, ' ', width - length);
}
static void
@ -616,7 +616,7 @@ repaint_file (WPanel *panel, int file_index, int mv, int attr, int isstatus)
tty_print_char (' ');
else {
tty_setcolor (NORMAL_COLOR);
tty_print_one_vline ();
tty_print_one_vline (slow_terminal);
}
}
}
@ -737,15 +737,10 @@ mini_info_separator (WPanel *panel)
const int y = llines (panel) + 2;
tty_set_normal_attrs (); /* FIXME: unneeded? */
widget_move (&panel->widget, y, 1);
tty_setcolor (NORMAL_COLOR);
#ifdef HAVE_SLANG
hline (ACS_HLINE, panel->widget.cols - 2);
#else
hline ((slow_terminal ? '-' : ACS_HLINE) | NORMAL_COLOR,
panel->widget.cols - 2);
#endif /* !HAVE_SLANG */
tty_draw_hline (panel->widget.y + y, panel->widget.x + 1,
slow_terminal ? '-' : ACS_HLINE,
panel->widget.cols - 2);
/* Status displays total marked size.
* Centered in panel, full format. */
display_total_marked_size (panel, y, -1, FALSE);
@ -798,7 +793,7 @@ show_dir (WPanel *panel)
panel->widget.y, panel->widget.x,
panel->widget.lines, panel->widget.cols);
if (show_mini_info) {
if (show_mini_info && !slow_terminal) {
widget_move (&panel->widget, llines (panel) + 2, 0);
tty_print_alt_char (ACS_LTEE);
widget_move (&panel->widget, llines (panel) + 2,
@ -1218,7 +1213,7 @@ paint_frame (WPanel *panel)
if (side){
tty_setcolor (NORMAL_COLOR);
tty_print_one_vline ();
tty_print_one_vline (slow_terminal);
width = panel->widget.cols - panel->widget.cols/2 - 1;
} else if (panel->split)
width = panel->widget.cols/2 - 3;
@ -1243,14 +1238,14 @@ paint_frame (WPanel *panel)
width -= format->field_len;
} else {
tty_setcolor (NORMAL_COLOR);
tty_print_one_vline ();
tty_print_one_vline (slow_terminal);
width--;
continue;
}
}
if (width > 0)
tty_printf ("%*s", width, "");
tty_draw_hline (-1, -1, ' ', width);
}
}

View File

@ -175,8 +175,7 @@ static void tree_show_mini_info (WTree *tree, int tree_lines, int tree_cols)
} else
line = tree_lines+1;
widget_move (&tree->widget, line, 1);
hline (' ', tree_cols);
tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols);
widget_move (&tree->widget, line, 1);
if (tree->searching){
@ -258,10 +257,8 @@ static void show_tree (WTree *tree)
/* Loop for every line */
for (i = 0; i < tree_lines; i++){
/* Move to the beginning of the line */
widget_move (&tree->widget, y+i, x);
hline (' ', tree_cols);
widget_move (&tree->widget, y+i, x);
tty_draw_hline (tree->widget.y + y + i, tree->widget.x + x,
' ', tree_cols);
if (!current)
continue;
@ -968,13 +965,14 @@ tree_frame (Dlg_head *h, WTree *tree)
{
tty_setcolor (NORMAL_COLOR);
widget_erase ((Widget*) tree);
if (tree->is_panel)
if (tree->is_panel) {
draw_double_box (h, tree->widget.y, tree->widget.x, tree->widget.lines,
tree->widget.cols);
if (show_mini_info && tree->is_panel){
widget_move (tree, tlines (tree) + 1, 1);
hline (ACS_HLINE, tree->widget.cols - 2);
if (show_mini_info)
tty_draw_hline (tree->widget.y + tlines (tree) + 1,
tree->widget.x + 1,
ACS_HLINE, tree->widget.cols - 2);
}
}

View File

@ -176,6 +176,24 @@ tty_getyx (int *py, int *px)
getyx (stdscr, *py, *px);
}
/* if x < 0 or y < 0, draw line starting from current position */
void
tty_draw_hline (int y, int x, int ch, int len)
{
if ((y >= 0) && (x >= 0))
move (y, x);
hline (ch, len);
}
/* if x < 0 or y < 0, draw line starting from current position */
void
tty_draw_vline (int y, int x, int ch, int len)
{
if ((y >= 0) && (x >= 0))
move (y, x);
vline (ch, len);
}
void
tty_draw_box (int y, int x, int rows, int cols)
{

View File

@ -24,7 +24,6 @@
#include "../../src/tty/win.h"
#include "../../src/background.h" /* we_are_background */
#include "../../src/main.h" /* for slow_terminal */
#include "../../src/util.h" /* str_unconst */
#include "../../src/strutil.h" /* str_term_form */
@ -361,49 +360,6 @@ tty_baudrate (void)
return SLang_TT_Baud_Rate;
}
void
hline (int ch, int len)
{
int last_x, last_y;
last_x = SLsmg_get_column ();
last_y = SLsmg_get_row ();
if (ch == 0)
ch = ACS_HLINE;
if (ch == ACS_HLINE)
SLsmg_draw_hline (len);
else
while (len--)
tty_print_char (ch);
SLsmg_gotorc (last_y, last_x);
}
void
vline (int character, int len)
{
(void) character;
if (!slow_terminal)
SLsmg_draw_vline (len);
else {
int last_x, last_y, pos = 0;
last_x = SLsmg_get_column ();
last_y = SLsmg_get_row ();
while (len--) {
SLsmg_gotorc (last_y + pos, last_x);
tty_print_char (' ');
pos++;
}
SLsmg_gotorc (last_x, last_y);
}
}
int
getch (void)
{
@ -450,6 +406,56 @@ tty_getyx (int *py, int *px)
*px = SLsmg_get_column ();
}
/* if x < 0 or y < 0, draw line staring from current position */
void
tty_draw_hline (int y, int x, int ch, int len)
{
if ((y < 0) || (x < 0)) {
y = SLsmg_get_row ();
x = SLsmg_get_column ();
} else
SLsmg_gotorc (y, x);
if (ch == 0)
ch = ACS_HLINE;
if (ch == ACS_HLINE)
SLsmg_draw_hline (len);
else
while (len-- != 0)
tty_print_char (ch);
SLsmg_gotorc (y, x);
}
/* if x < 0 or y < 0, draw line staring from current position */
void
tty_draw_vline (int y, int x, int ch, int len)
{
if ((y < 0) || (x < 0)) {
y = SLsmg_get_row ();
x = SLsmg_get_column ();
} else
SLsmg_gotorc (y, x);
if (ch == 0)
ch = ACS_VLINE;
if (ch == ACS_VLINE)
SLsmg_draw_vline (len);
else {
int pos = 0;
while (len-- != 0) {
SLsmg_gotorc (y + pos, x);
tty_print_char (ch);
pos++;
}
}
SLsmg_gotorc (y, x);
}
void
tty_draw_box (int y, int x, int rows, int cols)
{

View File

@ -28,8 +28,6 @@ enum {
void init_slang (void);
void init_curses (void);
void hline (int ch, int len);
void vline (int ch, int len);
int getch (void);
#define printw SLsmg_printf

View File

@ -37,7 +37,6 @@
#include "../../src/tty/tty.h"
#include "../../src/main.h" /* for slow_terminal */
#include "../../src/strutil.h"
#include "../../src/background.h" /* we_are_background */
@ -121,42 +120,20 @@ tty_is_ugly_line_drawing (void)
return force_ugly_line_drawing;
}
extern void
tty_print_one_hline(void)
void
tty_print_one_hline (gboolean is_slow_term)
{
if (slow_terminal)
tty_print_char(' ');
if (is_slow_term)
tty_print_char (' ');
else
tty_print_alt_char(ACS_HLINE);
tty_print_alt_char (ACS_HLINE);
}
extern void
tty_print_one_vline(void)
void
tty_print_one_vline (gboolean is_slow_term)
{
if (slow_terminal)
tty_print_char(' ');
if (is_slow_term)
tty_print_char (' ');
else
tty_print_alt_char(ACS_VLINE);
}
extern void
tty_print_hline(int top, int left, int length)
{
int i;
tty_gotoyx(top, left);
for (i = 0; i < length; i++)
tty_print_one_hline();
}
extern void
tty_print_vline(int top, int left, int length)
{
int i;
tty_gotoyx(top, left);
for (i = 0; i < length; i++) {
tty_gotoyx(top + i, left);
tty_print_one_vline();
}
tty_print_alt_char (ACS_VLINE);
}

View File

@ -64,10 +64,10 @@ extern void tty_printf(const char *s, ...);
extern void tty_set_ugly_line_drawing (gboolean do_ugly);
extern gboolean tty_is_ugly_line_drawing (void);
extern void tty_print_one_vline(void);
extern void tty_print_one_hline(void);
extern void tty_print_vline(int top, int left, int length);
extern void tty_print_hline(int top, int left, int length);
extern void tty_print_one_vline (gboolean is_slow_term);
extern void tty_print_one_hline (gboolean is_slow_term);
extern void tty_draw_hline (int y, int x, int ch, int len);
extern void tty_draw_vline (int y, int x, int ch, int len);
extern void tty_draw_box (int y, int x, int rows, int cols);
extern void tty_fill_region (int y, int x, int rows, int cols, unsigned char ch);

View File

@ -2134,8 +2134,7 @@ view_display_status (WView *view)
return;
tty_setcolor (SELECTED_COLOR);
widget_move (view, top, left);
hline (' ', width);
tty_draw_hline (view->widget.y + top, view->widget.x + left, ' ', width);
file_label = _("File: %s");
file_label_width = str_term_width1 (file_label) - 2;
@ -2358,7 +2357,7 @@ view_display_hex (WView *view)
/* After every four bytes, print a group separator */
if (bytes % 4 == 3) {
if (view->data_area.width >= 80 && col < width) {
tty_print_one_vline ();
tty_print_one_vline (slow_terminal);
col += 1;
}
if (col < width) {
@ -2437,26 +2436,26 @@ view_display_text (WView * view)
/* real detection of new line */
if (info.next >= line_act->end) {
line_nxt = view_get_next_line (view, line_act);
if (line_nxt == NULL) break;
if (line_nxt == NULL)
break;
if (view->text_wrap_mode || (line_act->number != line_nxt->number)){
row++;
col = line_nxt->left;
}
line_act = line_nxt;
continue;
}
continue;
}
view_read_continue (view, &info);
if (view_read_test_nroff_back (view, &info)) {
w = str_term_width1 (info.chi1);
col -= w;
if (col >= view->dpy_text_column
&& col + w - view->dpy_text_column <= width) {
widget_move (view, top + row, left + (col - view->dpy_text_column));
hline (' ', w);
}
&& col + w - view->dpy_text_column <= width)
tty_draw_hline (view->widget.y + top + row,
view->widget.x + left + (col - view->dpy_text_column),
' ', w);
if (cmp (info.chi1, "_") && (!cmp (info.cnxt, "_") || !cmp (info.chi2, "\b")))
tty_setcolor (VIEW_UNDERLINED_COLOR);
else

View File

@ -1847,7 +1847,7 @@ listbox_drawscroll (WListbox *l)
/* Are we at the top? */
widget_move (&l->widget, 0, l->width);
if (l->list == l->top)
tty_print_one_vline ();
tty_print_one_vline (FALSE);
else
tty_print_char ('^');
@ -1855,7 +1855,7 @@ listbox_drawscroll (WListbox *l)
widget_move (&l->widget, max_line, l->width);
top = listbox_cdiff (l->list, l->top);
if ((top + l->height == l->count) || l->height >= l->count)
tty_print_one_vline ();
tty_print_one_vline (FALSE);
else
tty_print_char ('v');
@ -1868,7 +1868,7 @@ listbox_drawscroll (WListbox *l)
for (i = 1; i < max_line; i++){
widget_move (&l->widget, i, l->width);
if (i != line)
tty_print_one_vline ();
tty_print_one_vline (FALSE);
else
tty_print_char ('*');
}
@ -1912,10 +1912,11 @@ listbox_draw (WListbox *l, int focused)
tty_print_string (str_fit_to_term (text, l->width - 2, J_LEFT_FIT));
}
l->cursor_y = sel_line;
if (!l->scrollbar)
return;
tty_setcolor (normalc);
listbox_drawscroll (l);
if (l->scrollbar) {
tty_setcolor (normalc);
listbox_drawscroll (l);
}
}
/* Returns the number of items between s and e,
@ -2300,7 +2301,7 @@ listbox_new (int y, int x, int height, int width, lcback callback)
l->count = 0;
l->cback = callback;
l->allow_duplicates = 1;
l->scrollbar = slow_terminal ? 0 : 1;
l->scrollbar = !slow_terminal;
widget_want_hotkey (l->widget, 1);
return l;