From e68c67554b12b19faab3d35ca38b222deda07e37 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 26 May 2009 18:56:42 +0400 Subject: [PATCH] TTY: created tty_fill_region() function. src/tty/tty.h: src/tty/tty-slang.c: src/tty/tty-ncurses.c: new tty_fill_region() function. src/dialog.c (widget_erase, dlg_erase): tty_fill_region() function is applied to erase area of widget and dialog. --- src/dialog.c | 27 ++++++++------------------- src/tty/tty-ncurses.c | 13 +++++++++++++ src/tty/tty-slang.c | 6 ++++++ src/tty/tty.h | 1 + 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/dialog.c b/src/dialog.c index 6ed443556..7abe520a3 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -34,7 +34,7 @@ #include "../src/tty/tty.h" #include "../src/tty/color.h" #include "../src/tty/mouse.h" -#include "../src/tty/key.h" /* mi_getch() */ +#include "../src/tty/key.h" #include "help.h" /* interactive_display() */ #include "dialog.h" @@ -90,28 +90,17 @@ draw_double_box (Dlg_head *h, int y, int x, int ys, int xs) #endif /* HAVE_SLANG */ } -void widget_erase (Widget *w) +void +widget_erase (Widget *w) { - int x, y; - - for (y = 0; y < w->lines; y++){ - widget_move (w, y, 0); - for (x = 0; x < w->cols; x++) - addch (' '); - } + tty_fill_region (w->y, w->x, w->lines, w->cols, ' '); } -void dlg_erase (Dlg_head *h) +void +dlg_erase (Dlg_head *h) { - int x, y; - if (h == NULL) - return; - for (y = 0; y < h->lines; y++){ - tty_gotoyx (y + h->y, h->x); /* FIXME: should test if ERR */ - for (x = 0; x < h->cols; x++){ - addch (' '); - } - } + if (h != NULL) + tty_fill_region (h->y, h->x, h->lines, h->cols, ' '); } void diff --git a/src/tty/tty-ncurses.c b/src/tty/tty-ncurses.c index 39db34a31..b3940205c 100644 --- a/src/tty/tty-ncurses.c +++ b/src/tty/tty-ncurses.c @@ -136,6 +136,19 @@ tty_draw_box (int y, int x, int rows, int cols) #undef waddc } +void +tty_fill_region (int y, int x, int rows, int cols, unsigned char ch) +{ + int i; + + for (i = 0; i < rows; i++) { + move (y + i, x); + hline (ch, cols); + } + + move (y, x); +} + void tty_print_char (int c) { diff --git a/src/tty/tty-slang.c b/src/tty/tty-slang.c index 8f761309e..02cee439b 100644 --- a/src/tty/tty-slang.c +++ b/src/tty/tty-slang.c @@ -426,6 +426,12 @@ tty_draw_box (int y, int x, int rows, int cols) SLsmg_draw_box (y, x, rows, cols); } +void +tty_fill_region (int y, int x, int rows, int cols, unsigned char ch) +{ + SLsmg_fill_region (y, x, rows, cols, ch); +} + void tty_print_char (int c) { diff --git a/src/tty/tty.h b/src/tty/tty.h index 87031cb7e..460b68d6d 100644 --- a/src/tty/tty.h +++ b/src/tty/tty.h @@ -52,6 +52,7 @@ 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_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); extern char *tty_tgetstr (const char *name);