Previous: , Up: Windows Tutorial   [Contents][Index]


4.9.4 Other border functions

The box and border procedures are useful, but, they only draw borders around the outside of windows. If you want to draw lines on the screen is other locations than the border of windows, you can use the hline and vline procedures.

The following little program shows how to draw a box at any location. To draw a box, it needs to draw four corners, two horizontal lines, and two vertical lines. It uses hline and vline. These two functions are simple. They create a horizontal or vertical line of the specified length at the specified position. The program uses more of the special drawing characters like (acs-urcorner), which is the upper-right corner of a box.

#!/usr/bin/guile
!#

(use-modules (ncurses curses))

(define stdscr (initscr))

;; Draw a box the hard way
(define (box2 win y x height width)
  ;; top
  (move win y x)
  (addch win (acs-ulcorner))
  (move win y (1+ x))
  (hline win (acs-hline) (- width 2))
  (move win y (+ x width -1))
  (addch win (acs-urcorner))

  ;; left side
  (move win (+ y 1) x)
  (vline win (acs-vline) (- height 2))

  ;; right side
  (move win (+ y 1) (+ x width -1))
  (vline win (acs-vline) (- height 2))

  ;; bottom
  (move win (+ y height -1) x)
  (addch win (acs-llcorner))
  (move win (+ y height -1) (1+ x))
  (hline win (acs-hline) (- width 2))
  (move win (+ y height -1) (+ x width -1))
  (addch win (acs-lrcorner)))

(let* ((stdscr (initscr))
       (height 3)
       (width 10)
       (y (round (/ (- (lines) height) 2)))
       (x (round (/ (- (cols) width) 2))))
  (box2 stdscr y x height width)
  (refresh stdscr)
  (sleep 3)
  (endwin))