This program shows 16 different possible boxes (Four styles and 4 exaples per style).
Use it, abuse it, critique it, whatever ya like. I hope ya find it useful.
Code: Select all
' Title: ASCII Box Routine for Text Mode (Screen 0) and Console Programs
' Program Code by Norby Droid
' Tested in FreeBasic 1.09
' Created in MS-DOS usimg Pedit 4.0 - The Program Editor
' 16 examples of different boxes available
' Subroutine: BoxPrint
' Replaces Print to Show the Text
' ix - x Position
' iy - y Position
' iText - Text to Print
' iColour - Text Colour
Sub BoxPrint(ix as Integer, iy as Integer, iText as String, _
iColour as Integer)
Color iColour : Locate iy, ix, 0
If Len(iText)>80 then Print Left(iText, 80); else Print iText;
End Sub
' Subroutine: CenterText
' Centers Text on the screen
' iy - y Position
' iText - Text Message
' iColour - Colour for the Text
Sub Center(iy as Integer, iText as String, iColour as Integer)
Dim as Integer ix=40-Len(iText)\2
If ix+Len(iText)>80 then _
ix=80-Len(iText): If ix<1 then ix=1
If iy>25 then Exit Sub
Color iColour : Locate iy, ix, 0 : Print iText;
End Sub
' Subroutine: SimpleBox
' Draws a Simple Box on the Screen
' BoxChars - ASCII Chars used to Draw the Boxes
' ix - x Position
' iy - y Position
' iWidth - Width for the Box
' iHeight - Height for the Box
' iColour - Text Colour
Sub SimpleBox( BoxChars() as String,ix as Integer, iy as Integer, _
iWidth as Integer, iHeight as Integer, iColour as Integer)
BoxPrint ix, iy, _
Left(BoxChars(0), 1)+String(iWidth, Mid(BoxChars(0), 2, 1))+ _
Right(BoxChars(0), 1), iColour
For y as Integer=1 to iHeight
BoxPrint ix, iy+y, _
Left(BoxChars(1), 1)+String(iWidth, 32)+ _
Right(BoxChars(1), 1), iColour
Next
BoxPrint ix, iy+iHeight+1, _
Left(BoxChars(3), 1)+String(iWidth, Mid(BoxChars(3), 2, 1))+ _
Right(BoxChars(3), 1), iColour
End Sub
' Subroutine: HorLine
' BoxChars - ASCII Chars used to Draw the Boxes
' ix - x Position
' iy - y Position
' iWidth - Width Position for the Line
' iColour - Text Colour
Sub HorLine(BoxChars() as String, ix as Integer, iy as Integer, _
iWidth as Integer, iColour as Integer)
BoxPrint ix, iy, Left(BoxChars(2), 1)+ _
String$(iWidth, Mid(BoxChars(2), 2, 1))+ _
Right(BoxChars(2), 1), iColour
End Sub
' Subroutine: VertLine
' BoxChars - ASCII Chars used to Draw the Boxes
' ix - x Position
' iy - y Position
' iWidth - Width Position for Line
' iHeight - Height Position for Line
' iColour - Line Colour
Sub VertLine(BoxChars() as String, ix as Integer, iy as Integer, _
iWidth as Integer, iHeight as Integer, iColour as Integer)
BoxPrint ix+iWidth+1, iy, Mid(BoxChars(0), 3, 1), iColour
For y as Integer=1 to iHeight
BoxPrint ix+iWidth+1, iy+y, Mid(BoxChars(1), 3, 1), iColour
Next
BoxPrint ix+iWidth+1, iHeight+2, Mid(BoxChars(3), 3, 1), iColour
End Sub
' Subroutine: TestBox
' Tests that the Box is Drawn Properly
' ix - x Position
' iy - y Position
' iWidth - Box Inside Width
' iHeight - Box Inside Height
Sub TestBox(ix as Integer, iy as Integer, _
iWidth as Integer, iHeight as Integer)
Color 7
For x as Integer=1 to iWidth
If x Mod 10=0 or x=iWidth then _
Locate iy, ix+x-1 : Print Left(Str(x), 1); : _
Locate iy+1, ix+x-1, 0 : Print Right(Str(x), 1);
Next
For y as Integer=1 to iHeight
If (y=1 or y=iHeight) or y Mod 10=0 then _
Locate iy+y-1, ix, 0 : Print Str(y);
Next
End Sub
' Subroutine - DrawBox
' Input: ix - x Position
' iy - y Position
' iWidth1 - Width of the Box(es)
' iWidth2 - Width of the Box(es)
' iHeight1 - Height of the Box(es)
' iHeight2 - Height of the Box(es)
' iColour - Colour of the Box(es)
' This perameter is optional. Default Colour: 7 (White)
' iStyle - Used to determine which Style of Box to display
' This perameter is optional. Default Style: 0 (Simple Box)
Sub DrawBox(ix as Integer, iy as Integer, _
iWidth1 as Integer, iWidth2 as Integer, _
iHeight1 as Integer, iHeight2 as Integer, _
iColour as Integer, iStyle as Integer)
Dim as String BoxLine=""
Dim BoxChars(4) as String
Select Case iStyle
' Single Lines Horizontal & Vertical
Case 0, 1, 2, 3
BoxChars(0)=Chr(218)+Chr(196)+Chr(194)+Chr(191)
BoxChars(1)=Chr(179)+Chr(196)+Chr(179)+Chr(179)
BoxChars(2)=Chr(195)+Chr(196)+Chr(197)+Chr(180)
BoxChars(3)=Chr(192)+Chr(196)+Chr(193)+Chr(217)
' Single Line Horizontal & Dual Lines Vertical
Case 4, 5, 6, 7
BoxChars(0)=Chr(214)+Chr(196)+Chr(210)+Chr(183)
BoxChars(1)=Chr(186)+Chr(196)+Chr(186)+Chr(186)
BoxChars(2)=Chr(199)+Chr(196)+Chr(215)+Chr(182)
BoxChars(3)=Chr(211)+Chr(196)+Chr(208)+Chr(189)
' Dual Lines Horizontal & Single Line Vertical
Case 8, 9, 10, 11
BoxChars(0)=Chr(213)+Chr(205)+Chr(209)+Chr(184)
BoxChars(1)=Chr(179)+Chr(205)+Chr(179)+Chr(179)
BoxChars(2)=Chr(198)+Chr(205)+Chr(216)+Chr(181)
BoxChars(3)=Chr(212)+Chr(205)+Chr(207)+Chr(190)
' Dual Lines Horizontal & Vertical
Case 12, 13, 14, 15
BoxChars(0)=Chr(201)+Chr(205)+Chr(203)+Chr(187)
BoxChars(1)=Chr(186)+Chr(205)+Chr(186)+Chr(186)
BoxChars(2)=Chr(204)+Chr(205)+Chr(206)+Chr(185)
BoxChars(3)=Chr(200)+Chr(205)+Chr(202)+Chr(188)
End Select
' Simple Box
If iStyle Mod 4=0 then
SimpleBox BoxChars(), ix, iy, _
iWidth1+iWidth2, iHeight1+iHeight2, iColour
TestBox ix+1, iy+1, iWidth1+iWidth2, iHeight1+iHeight2
EndIf
' Split Box - Horizontal
If iStyle Mod 4=1 then
SimpleBox BoxChars(), ix, iy, _
iWidth1+iWidth2, iHeight1+iHeight2+1, iColour
HorLine BoxChars(), ix, iy+iHeight1+1, iWIdth1+iWidth2, iColour
TestBox ix+1, iy+1, iWidth1, iHeight1
TestBox ix+1, iy+iHeight1+2, iWidth1, iHeight2
EndIf
' Split Box - Vertical
If iStyle Mod 4=2 then
SimpleBox BoxChars(), ix, iy, iWidth1+iWidth2+1, _
iHeight1+iHeight2, iColour
VertLine BoxChars(), ix, iy, iWidth1, iHeight1+iHeight2, iColour
TestBox ix+1, iy+1, iWidth1, iHeight1
TestBox ix+iWidth1+2, iy+1, iWidth2, iHeight1
EndIf
' Split Box - Horizontal & Vertical
If iStyle Mod 4=3 then
SimpleBox BoxChars(), ix, iy, _
iWidth1+iWidth2+1, iHeight1+iHeight2+1, iColour
HorLine BoxChars(), ix, iy+iHeight1+1, iWIdth1+iWidth2+1, iColour
VertLine BoxChars(), ix, iy, iWidth1, iHeight1+iHeight2+1, iColour
BoxPrint ix+iWidth1+1, iy+iHeight1+1, Mid(BoxChars(2), 3, 1), iColour
TestBox iy+1, ix+1, iWidth1, iHeight1
TestBox iy+iWidth1+2, ix+1, iWidth1, iHeight1
TestBox iy+1, ix+iHeight1+2, iWidth1, iHeight1
TestBox iy+iWidth1+2, ix+iHeight1+2, iWidth1, iHeight1
EndIf
Center 20, "DrawBox Position: "+Str(ix)+", "+Str(iy), 7
If iWidth2=0 then _
Center 21, "DrawBox Width : "+Str(iWidth1), 7 _
Else _
Center 21, "DrawBox Width : "+Str(iWidth1)+" & "+Str(iWidth2), 7
If iHeight2=0 then _
Center 22, "DrawBox Height : "+Str(iHeight1), 7 _
Else _
Center 22, "DrawBox Height : "+Str(iHeight1)+" & "+Str(iHeight2), 7
Center 23, "DrawBox Colour : "+Str(iColour), 7
Center 24, "DrawBox Style : "+Str(iStyle\4+1), 7
Locate 24, 67, 0 : Print "Example: "; Str(4*(iStyle Mod 4)+iStyle\4+1);
End Sub
' Subroutine: Main
' Main Loop
Sub Main
' Simple Box Examples
DrawBox 1, 1, 78, 0, 23, 0, 9, 0
Sleep 1000 : CLS
DrawBox 1, 1, 78, 0, 23, 0, 9, 4
Sleep 1000 : CLS
DrawBox 1, 1, 78, 0, 23, 0, 9, 8
Sleep 1000 : CLS
DrawBox 1, 1, 78, 0, 23, 0, 9, 12
Sleep 1000 : CLS
' Split Horizontal Examples
DrawBox 1, 1, 78, 0, 11, 11, 11, 1
Sleep 1000 : CLS
DrawBox 1, 1, 78, 0, 11, 11, 11, 5
Sleep 1000 : CLS
DrawBox 1, 1, 78, 0, 11, 11, 11, 9
Sleep 1000 : CLS
DrawBox 1, 1, 78, 0, 11, 11, 11, 13
Sleep 1000 : CLS
' Split Vertical Examples
DrawBox 1, 1, 38, 38, 23, 0, 13, 2
Sleep 1000 : CLS
DrawBox 1, 1, 38, 38, 23, 0, 13, 6
Sleep 1000 : CLS
DrawBox 1, 1, 38, 38, 23, 0, 13, 10
Sleep 1000 : CLS
DrawBox 1, 1, 38, 38, 23, 0, 13, 14
Sleep 1000 : CLS
' Split Horizontal & Vertical Examples
DrawBox 1, 1, 38, 38, 11, 11, 15, 3
Sleep 1000 : CLS
DrawBox 1, 1, 38, 38, 11, 11, 15, 7
Sleep 1000 : CLS
DrawBox 1, 1, 38, 38, 11, 11, 15, 11
Sleep 1000 : CLS
DrawBox 1, 1, 38, 38, 11, 11, 15, 15
Sleep 1000 : CLS
End Sub
' Start
Main
' These lines may be Removed
' Added to restore the cursor upon exit
Locate 25, 1, 1