Browse Source

TTY: modified line drawing.

Andrew Borodin 16 years ago
parent
commit
30fd7fc34a
10 changed files with 107 additions and 90 deletions
  1. 3 2
      edit/editdraw.c
  2. 4 0
      src/cons.handler.c
  3. 4 7
      src/dialog.c
  4. 2 2
      src/info.c
  5. 7 7
      src/menu.c
  6. 11 16
      src/screen.c
  7. 8 10
      src/tree.c
  8. 18 0
      src/tty/tty-ncurses.c
  9. 50 44
      src/tty/tty-slang.c
  10. 0 2
      src/tty/tty-slang.h

+ 3 - 2
edit/editdraw.c

@@ -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;

+ 4 - 0
src/cons.handler.c

@@ -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;

+ 4 - 7
src/dialog.c

@@ -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 */

+ 2 - 2
src/info.c

@@ -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;
 

+ 7 - 7
src/menu.c

@@ -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 */

+ 11 - 16
src/screen.c

@@ -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);
     }
 }
 

+ 8 - 10
src/tree.c

@@ -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);
     }
 }
 

+ 18 - 0
src/tty/tty-ncurses.c

@@ -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)
 {

+ 50 - 44
src/tty/tty-slang.c

@@ -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)
 {

+ 0 - 2
src/tty/tty-slang.h

@@ -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

Some files were not shown because too many files changed in this diff