home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / F_CENTON.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  2.0 KB  |  70 lines

  1. *****************************************************************
  2. FUNCTION CENTERON (line_num, string, new_color)
  3. *****************************************************************
  4.  
  5. * Center a string on selected line in selected color
  6.  
  7. * Copyright(c) 1991 - James Occhiogrosso
  8.  
  9. LOCAL end_col := MAXCOL(), horz_pos, old_color, string_len
  10.  
  11. * Get the length of the passed string data
  12. string_len = LEN(string)
  13.  
  14. * If window color is undefined, initialize it
  15. colwindow := IF (TYPE('colwindow') != 'C', SETCOLOR(), colwindow)
  16.  
  17. DO CASE
  18.  
  19.    CASE string_len > end_col .OR. string_len < 1
  20.       * Invalid length, abort.
  21.       RETURN NIL
  22.  
  23.    * The CASES below pad the displayed string with up to 10
  24.    * spaces. The number of spaces increases as the length of 
  25.    * the passed string decreases. This produces an attractive
  26.    * display for all string lengths.
  27.  
  28.    CASE string_len > end_col-10 .AND. string_len <= end_col-2
  29.       string = ' ' + string + ' '
  30.       horz_pos = INT((end_col - LEN(string))/2)
  31.  
  32.    CASE string_len > end_col-20 .AND. string_len <= end_col-10
  33.       string = '  ' + string + '  '
  34.       horz_pos = INT((end_col - LEN(string))/2)
  35.  
  36.    CASE string_len > end_col-30 .AND. string_len <= end_col-20
  37.       string = '   ' + string + '   '
  38.       horz_pos = INT((end_col - LEN(string))/2)
  39.  
  40.    CASE string_len > end_col-40 .AND. string_len <= end_col-30
  41.       string = '    ' + string + '    '
  42.       horz_pos = INT((end_col - LEN(string))/2)
  43.  
  44.    CASE  string_len <= 40
  45.       string = '     ' + string + '     '
  46.       horz_pos = INT((end_col - LEN(string))/2)
  47.  
  48.    OTHERWISE
  49.       * String is almost width of screen, do not pad
  50.       horz_pos = 0
  51. ENDCASE
  52.  
  53. * Clear the line using current color setting
  54. @ line_num, 0
  55.  
  56. * Save old color and set message color
  57. old_color = IF(new_color == NIL, SETCOLOR(colwindow),  ;
  58.                                  SETCOLOR(new_color) )
  59.  
  60. * Display padded string
  61. @ line_num, horz_pos SAY string
  62.  
  63. * Restore entry color
  64. SETCOLOR(old_color)
  65. RETURN NIL
  66.  
  67.  
  68.  
  69.  
  70.