home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DSKCACHE / EVALCACH.ZIP / BOXES.PAS next >
Encoding:
Pascal/Delphi Source File  |  1989-10-26  |  4.2 KB  |  139 lines

  1. {
  2. **************************************************************************
  3. BOXES.PAS -- Box objects for screen-oriented programs
  4. Copyright 1989 L. Brett Glass -- All rights reserved.
  5. **************************************************************************
  6. }
  7. unit Boxes;
  8.  
  9. interface
  10.  
  11. uses CRT, CharScrn, StrUtil;
  12.  
  13. type
  14.   BoxTypes = (THINBOX, THICKBOX);
  15.   BoxHDividers = set of RowType;
  16.   BoxVDividers = set of ColType;
  17.   Box = object (TitledCharObject)
  18.     width : WidthType;
  19.     height : HeightType;
  20.     boxType : BoxTypes;
  21.     hDividers : BoxHDividers;
  22.     vDividers : BoxVDividers;
  23.  
  24.     procedure Draw; virtual;
  25.     {Draw a box with upper left corner, width, and height specified. The
  26.      box can be thick or thin, the interior is cleared, and a title
  27.      may be written on the top row.}
  28.     procedure DispTitle; virtual;
  29.     {Display the box's title}
  30.     end;
  31.  
  32. implementation
  33.  
  34. type
  35.   BoxRec =
  36.     record
  37.       ul, ur, ll, lr, horiz, vert, toptee, btmtee, ltee, rtee, cross : Char
  38.       end;
  39.  
  40. const
  41.   boxChars : array[BoxTypes] of BoxRec =
  42.     ((ul : '┌'; ur : '┐'; ll : '└';                   { THINBOX  }
  43.       lr : '┘'; horiz  : '─'; vert : '│';
  44.       toptee : '┬'; btmtee : '┴';
  45.       ltee : '├'; rtee : '┤'; cross : '┼'),
  46.      (ul : '╔'; ur : '╗'; ll : '╚';                   { THICKBOX }
  47.       lr : '╝'; horiz  : '═'; vert : '║';
  48.       toptee : '╦'; btmtee : '╩';
  49.       ltee : '╠'; rtee : '╣'; cross : '╬'));
  50.  
  51.  
  52.  
  53.  
  54. procedure Box.DispTitle;
  55.   const
  56.     leftBracket : Char = '[';
  57.     rightBracket : Char = ']';
  58.   var
  59.     tLen : Byte absolute title;
  60.   begin {Box,DispTitle}
  61.   Ellipsis(title,width-4);
  62.   CharToScreen(Succ(x),y,leftBracket);
  63.   CharToScreen(x + 2 + tLen,y,rightBracket);
  64.   CharsToScreen(x+2,y,tLen,title[1])
  65.   end;  {Box.DispTitle}
  66.  
  67. procedure VertDivider(col : ColType;
  68.                       top : RowType;
  69.                       height : HeightType;
  70.                       boxType : BoxTypes);
  71. {Divide a box vertically along the specified column, given the row of
  72.  the top of the box and its height.}
  73.   begin {VertDivider}
  74.   CharToScreen(col,top,boxChars[boxType].toptee);
  75.   FillBox(col,Succ(top),1,height-2,boxChars[boxType].vert);
  76.   CharToScreen(col,Pred(top+height),boxChars[boxType].btmtee)
  77.   end;  {VertDivider}
  78.  
  79. procedure HorizDivider(left : ColType;
  80.                        row : RowType;
  81.                        width : WidthType;
  82.                        boxType : BoxTypes);
  83. {Divide a box horizontally along the specified row, given the column of
  84.  the left edge of the box and its width.}
  85.   begin {HorizDivider}
  86.   CharToScreen(left,row,boxChars[boxType].ltee);
  87.   FillBox(Succ(left),row,width-2,1,boxChars[boxType].horiz);
  88.   CharToScreen(Pred(left+width),row,boxChars[boxType].rtee)
  89.   end;  {HorizDivider}
  90.  
  91. {Public routines}
  92.  
  93. procedure Box.Draw;
  94. type
  95.   HDivNumber = 0..SCREENHEIGHT;
  96.   HDivRange = 1..SCREENHEIGHT;
  97. var
  98.   i : RowType;
  99.   j : ColType;
  100.   k : HDivNumber;
  101.   p : ScreenParms;
  102.   hDivs : array [HDivRange] of RowType;
  103.   hDivCount : HDivNumber;
  104. begin {Box.Draw}
  105. p.Save;
  106. TextAttr := color;
  107. CharToScreen(x,y,boxChars[boxType].ul); {Upper left corner}
  108. FillBox(Succ(x),y,width-2,1,boxChars[boxType].horiz); {Top}
  109. CharToScreen(Pred(x+width),y,boxChars[boxType].ur); {Upper right corner}
  110. FillBox(x,Succ(y),1,height-2,boxChars[boxType].vert); {Left}
  111. FillBox(Pred(x+width),Succ(y),1,height-2,boxChars[boxType].vert); {Right}
  112. CharToScreen(x,Pred(y+height),boxChars[boxType].ll); {Lower left corner}
  113. FillBox(Succ(x),Pred(y+height),width-2,1,boxChars[boxType].horiz); {Bottom}
  114. CharToScreen(Pred(x+width),Pred(y+height),boxChars[boxType].lr); {Lower right corner}
  115. FillBox(Succ(x),Succ(y),width-2,height-2,' '); {Clear innards}
  116. hDivCount := 0;
  117. FillChar(hDivs,SizeOf(hDivs),FALSE);
  118. for i := FIRSTROW to LASTROW do
  119.   if i in hDividers then
  120.     begin
  121.     HorizDivider(x,i,width,boxType);
  122.     Inc(hDivCount);
  123.     hDivs[hDivCount] := i;
  124.     end;
  125. for j := FIRSTCOL to LASTCOL do
  126.   if j in vDividers then
  127.     begin
  128.     VertDivider(j,y,height,boxType);
  129.     for k := 1 to hDivCount do
  130.       CharsToScreen(j,hDivs[k],1,boxChars[boxType].cross)
  131.     end;
  132. if Length(title) <> 0 then
  133.   Self.DispTitle;
  134. p.Restore;
  135. dirty := FALSE;
  136. end;  {Box.Draw}
  137.  
  138. end.  {Boxes}
  139.