home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progbas / qbnws103.arj / FRAME.BAS < prev    next >
BASIC Source File  |  1990-05-15  |  7KB  |  162 lines

  1. SUB Frame (TopRow%, leftCol%, botRow%, rightCol%, boxType%, boxFg%, boxBg%, filFg%, filBg%, fillChar%, shadow%, header$) STATIC
  2.  
  3. '                     +******************************+    message 2 of 4
  4. '                     *          FRAME.BAS           *
  5. '                     *                              *
  6. '                     *   by: Lawrence Stone, 1990   *
  7. '                     +******************************+
  8. '
  9. '+**************************************************************************+
  10. '*   boxType% 1 = ┌────┐  2 = ╔════╗  3 = ╓────╖  4 = ╒════╕                *
  11. '*                │    │      ║    ║      ║    ║      │    │                *
  12. '*                └────┘      ╚════╝      ╙────╜      ╘════╛                *
  13. '*   header tees =  ┤├          ╡╞          ┤├          ╡╞                  *
  14. '*                                                                          *
  15. '*   If filFg% = 0 *AND* filBg% = 0 then the box does not clear the middle  *
  16. '*   otherwise, the box clears the middle with the colors called for.       *
  17. '*                                                                          *
  18. '*   fillChar% is the ASCII number for the character to fill the box with.  *
  19. '*   Example: fillChar% = 32 is " " or fillChar% = 176 is "░"               *
  20. '*                                                                          *
  21. '*   shadow% if true, computes the character and color attribute along the  *
  22. '*   right and bottom side of the box and prints the appropriate shadow.    *
  23. '*                                                                          *
  24. '*   If header$ <> "" then box centers this message at the top and inside   *
  25. '*   of the appropriate ┤ ├ characters.  Otherwise, if header$ = "" then    *
  26. '*   the box is a non-titled box.                                           *
  27. '*                                                                          *
  28. '*   SPECIAL NOTE:  This subprogram is STATIC.  By making it STATIC, QB     *
  29. '*   doesn't have to re-initialize variables after it is CALLed the first   *
  30. '*   time.  This produces faster execution.  If your program is going to    *
  31. '*   need all the memory it can grab then, remove the STATIC keyword from   *
  32. '*   the top line of this subprogram.                                       *
  33. '+**************************************************************************+
  34.     DEFINT A-Z                       'message 3 of 4
  35.  
  36.     GOSUB InitiateBox
  37.  
  38.     '*** Is the box titled? If so then print it centered on top line of box.
  39.     IF LEN(header$) THEN
  40.         temp$ = leftT$ + " " + header$ + " " + rightT$
  41.  
  42.         '*** How long should horz$ be to left and right of the header$?
  43.         portion = ((boxWide - LEN(temp$)) \ 2)
  44.  
  45.         '*** Print top-left side of box, as well as, the header string.
  46.         PRINT topLeft$; STRING$(portion, horz$); temp$;
  47.  
  48.         '*** Adjust the right side if it isn't the same length as the left.
  49.         IF ((boxWide - LEN(temp$)) MOD 2) THEN
  50.             PRINT STRING$(portion + 1, horz$); topRight$;
  51.  
  52.         '*** No adjustments are needed if left and right side are equal length
  53.         ELSE
  54.             PRINT STRING$(portion, horz$); topRight$;
  55.         END IF
  56.   
  57.     '*** If the box is untitled then draw the top line of box sans header
  58.     ELSE
  59.         PRINT topLeft$; STRING$(boxWide, horz$); topRight$;
  60.     END IF
  61.  
  62.     '*** Draw the sides of the box
  63.     FOR boxRow = TopRow + 1 TO botRow - 1
  64.         COLOR boxFg, boxBg
  65.         LOCATE boxRow, leftCol
  66.         PRINT vert$;                            ' Draw left side of box
  67.         IF clearBox THEN                        ' Do we clear the box?
  68.             COLOR filFg, filBg
  69.             PRINT STRING$(boxWide, fillChar);   ' Clear box with the fillChar
  70.             COLOR boxFg, boxBg
  71.         END IF
  72.         LOCATE boxRow, rightCol
  73.         PRINT vert$;                            ' Draw the right side of box
  74.         IF shadow THEN                          ' Do we draw a shadow?
  75.             FOR B = 1 TO 2
  76.                 csrPos = rightCol + B           ' Calculate the cursor column
  77.                 GOSUB ConfigShadow              ' Calculate and draw shadow
  78.             NEXT
  79.         END IF
  80.     NEXT
  81.    
  82.     COLOR boxFg, boxBg: LOCATE botRow, leftCol
  83.     PRINT botLeft$; STRING$(boxWide, horz$); botRight$;   ' Draw box bottom
  84.   
  85.     IF shadow THEN                              ' Do we draw the shadow?
  86.         boxRow = botRow
  87.         FOR B = 1 TO 2
  88.             csrPos = rightCol + B               ' Finish bottom-right shadow
  89.             GOSUB ConfigShadow
  90.         NEXT
  91.         boxRow = botRow + 1
  92.         FOR csrPos = leftCol + 2 TO leftCol + boxWide + 3
  93.             IF csrPos < 81 THEN LOCATE boxRow, csrPos   ' Prevent's an error
  94.             GOSUB ConfigShadow                  ' Draw shadow below box
  95.         NEXT
  96.     END IF
  97.     IF clearBox THEN COLOR filFg, filBg         ' Reset fill colors
  98.     EXIT SUB
  99. ' message 4 of 4
  100. '           +***************************************************+
  101. '           *                     Subroutines                   *
  102. '           +***************************************************+
  103.  
  104. InitiateBox:
  105.     IF boxType = 1 THEN
  106.         topLeft$ = "┌"
  107.         topRight$ = "┐"
  108.         botLeft$ = "└"
  109.         botRight$ = "┘"
  110.         vert$ = "│"
  111.         horz$ = "─"
  112.         leftT$ = "┤"
  113.         rightT$ = "├"
  114.     ELSEIF boxType = 2 THEN
  115.         topLeft$ = "╔"
  116.         topRight$ = "╗"
  117.         botLeft$ = "╚"
  118.         botRight$ = "╝"
  119.         vert$ = "║"
  120.         horz$ = "═"
  121.         leftT$ = "╡"
  122.         rightT$ = "╞"
  123.     ELSEIF boxType = 3 THEN
  124.         topLeft$ = "╓"
  125.         topRight$ = "╖"
  126.         botLeft$ = "╙"
  127.         botRight$ = "╜"
  128.         vert$ = "║"
  129.         horz$ = "─"
  130.         leftT$ = "┤"
  131.         rightT$ = "├"
  132.     ELSEIF boxType = 4 THEN
  133.         topLeft$ = "╒"
  134.         topRight$ = "╕"
  135.         botLeft$ = "╘"
  136.         botRight$ = "╛"
  137.         vert$ = "│"
  138.         horz$ = "═"
  139.         leftT$ = "╡"
  140.         rightT$ = "╞"
  141.     END IF
  142.  
  143.     boxWide = rightCol - leftCol - 1
  144.     IF (filFg = 0 AND filBg = 0) THEN clearBox = 0 ELSE clearBox = -1
  145.     COLOR boxFg, boxBg
  146.     LOCATE TopRow, leftCol
  147. RETURN
  148.  
  149. ConfigShadow:
  150.     IF ((csrPos < 81) AND (boxRow < 26)) THEN   ' Prevent an illegal function
  151.         attribute = SCREEN(boxRow, csrPos, -1)  ' Obtain the color attribute
  152.         char = SCREEN(boxRow, csrPos)           ' Obtain the charcter
  153.         fg = attribute AND 15                   ' Calculate forground color.
  154.         fg = fg - 8                             ' Remove bright from the color
  155.         IF fg < 1 THEN fg = 8                   ' In case color wasn't bright
  156.         COLOR fg, 0: PRINT CHR$(char);          ' Color and print shadow char
  157.     END IF
  158. RETURN
  159.  
  160. END SUB
  161.  
  162.