diff --git a/lib/tty/tty-ncurses.c b/lib/tty/tty-ncurses.c index 67dea4ee9..5275f02b0 100644 --- a/lib/tty/tty-ncurses.c +++ b/lib/tty/tty-ncurses.c @@ -330,31 +330,59 @@ tty_getyx (int *py, int *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) { + int x1; + + if (y < 0 || y >= LINES || x >= COLS) + return; + + x1 = x; + + if (x < 0) + { + len += x; + if (len <= 0) + return; + x = 0; + } + if ((chtype) ch == ACS_HLINE) ch = mc_tty_frm[MC_TTY_FRM_HORIZ]; - if ((y >= 0) && (x >= 0)) - move (y, x); + move (y, x); hline (ch, len); + move (y, x1); } /* --------------------------------------------------------------------------------------------- */ -/* if x < 0 or y < 0, draw line starting from current position */ void tty_draw_vline (int y, int x, int ch, int len) { + int y1; + + if (x < 0 || x >= COLS || y >= LINES) + return; + + y1 = y; + + if (y < 0) + { + len += y; + if (len <= 0) + return; + y = 0; + } + if ((chtype) ch == ACS_VLINE) ch = mc_tty_frm[MC_TTY_FRM_VERT]; - if ((y >= 0) && (x >= 0)) - move (y, x); + move (y, x); vline (ch, len); + move (y1, x); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/tty/tty-slang.c b/lib/tty/tty-slang.c index 99af2384b..6b7fd32f7 100644 --- a/lib/tty/tty-slang.c +++ b/lib/tty/tty-slang.c @@ -509,54 +509,68 @@ tty_getyx (int *py, int *px) } /* --------------------------------------------------------------------------------------------- */ -/* if x < 0 or y < 0, draw line staring from current position */ void tty_draw_hline (int y, int x, int ch, int len) { + int x1; + + if (y < 0 || y >= LINES || x >= COLS) + return; + + x1 = x; + + if (x < 0) + { + len += x; + if (len <= 0) + return; + x = 0; + } + if (ch == ACS_HLINE) ch = mc_tty_frm[MC_TTY_FRM_HORIZ]; - - if ((y < 0) || (x < 0)) - { - y = SLsmg_get_row (); - x = SLsmg_get_column (); - } - else - SLsmg_gotorc (y, x); - if (ch == 0) ch = ACS_HLINE; + SLsmg_gotorc (y, x); + if (ch == ACS_HLINE) SLsmg_draw_hline (len); else while (len-- != 0) tty_print_char (ch); - SLsmg_gotorc (y, x); + SLsmg_gotorc (y, x1); } /* --------------------------------------------------------------------------------------------- */ -/* if x < 0 or y < 0, draw line staring from current position */ void tty_draw_vline (int y, int x, int ch, int len) { + int y1; + + if (x < 0 || x >= COLS || y >= LINES) + return; + + y1 = y; + + if (y < 0) + { + len += y; + if (len <= 0) + return; + y = 0; + } + if (ch == ACS_VLINE) ch = mc_tty_frm[MC_TTY_FRM_VERT]; - - if ((y < 0) || (x < 0)) - { - y = SLsmg_get_row (); - x = SLsmg_get_column (); - } - else - SLsmg_gotorc (y, x); - if (ch == 0) ch = ACS_VLINE; + SLsmg_gotorc (y, x); + if (ch == ACS_VLINE) SLsmg_draw_vline (len); else @@ -571,7 +585,7 @@ tty_draw_vline (int y, int x, int ch, int len) } } - SLsmg_gotorc (y, x); + SLsmg_gotorc (y1, x); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/tty/tty.c b/lib/tty/tty.c index 3b9592d88..1999deb00 100644 --- a/lib/tty/tty.c +++ b/lib/tty/tty.c @@ -177,20 +177,25 @@ tty_print_one_vline (gboolean single) void tty_draw_box (int y, int x, int ys, int xs, gboolean single) { + int y2, x2; + ys--; xs--; + y2 = y + ys; + x2 = x + xs; + tty_draw_vline (y, x, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT], ys); - tty_draw_vline (y, x + xs, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT], ys); + tty_draw_vline (y, x2, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT], ys); tty_draw_hline (y, x, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ], xs); - tty_draw_hline (y + ys, x, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ], xs); + tty_draw_hline (y2, x, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ], xs); tty_gotoyx (y, x); tty_print_alt_char (ACS_ULCORNER, single); - tty_gotoyx (y + ys, x); + tty_gotoyx (y2, x); tty_print_alt_char (ACS_LLCORNER, single); - tty_gotoyx (y, x + xs); + tty_gotoyx (y, x2); tty_print_alt_char (ACS_URCORNER, single); - tty_gotoyx (y + ys, x + xs); + tty_gotoyx (y2, x2); tty_print_alt_char (ACS_LRCORNER, single); } diff --git a/lib/widget/menu.c b/lib/widget/menu.c index 8a32b9d56..fc60153a7 100644 --- a/lib/widget/menu.c +++ b/lib/widget/menu.c @@ -121,11 +121,14 @@ menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color) } else { + int yt, xt; + /* menu text */ tty_setcolor (color); widget_move (&menubar->widget, y, x); tty_print_char ((unsigned char) entry->first_letter); - tty_draw_hline (-1, -1, ' ', menu->max_entry_len + 2); /* clear line */ + tty_getyx (&yt, &xt); + tty_draw_hline (yt, xt, ' ', menu->max_entry_len + 2); /* clear line */ tty_print_string (entry->text.start); if (entry->text.hotkey != NULL) diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 8359ca3cd..60e5d1dc4 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -864,7 +864,12 @@ format_file (char *dest, int limit, WPanel * panel, int file_index, int width, i } if (length < width) - tty_draw_hline (-1, -1, ' ', width - length); + { + int y, x; + + tty_getyx (&y, &x); + tty_draw_hline (y, x, ' ', width - length); + } return res; } @@ -1583,7 +1588,12 @@ paint_frame (WPanel * panel) g_string_free (format_txt, TRUE); if (width > 0) - tty_draw_hline (-1, -1, ' ', width); + { + int y, x; + + tty_getyx (&y, &x); + tty_draw_hline (y, x, ' ', width); + } } if (panel->list_type != list_long) diff --git a/src/viewer/display.c b/src/viewer/display.c index d819bbece..acd2800bb 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -141,7 +141,7 @@ mcview_display_status (mcview_t * view) tty_setcolor (STATUSBAR_COLOR); widget_move (view, top, left); - tty_draw_hline (-1, -1, ' ', width); + tty_draw_hline (top, left, ' ', width); file_label = view->filename_vpath != NULL ?