Code: Select all
#SOC=SizeOf(Character)
Procedure.i GetLongestLine(*c.Character, *numlines.Integer=0)
Protected.i l, n, s
While *c\c
If *c\c=#LF
If s>l : l=s : EndIf
s=0 : n+1
ElseIf *c\c<>#CR
s+1
EndIf
*c+#SOC
Wend
If s ; For last line without #LF at end.
If s>l : l=s : EndIf
n+1
EndIf
If *numlines : *numlines\i=n : EndIf
ProcedureReturn l
EndProcedure
Procedure.s Decorated(*t.Character)
Protected.i l, n, maxlen, numlines, *c.Character
Protected.i x, y, w, h
maxlen = GetLongestLine(*t, @numlines)
w = maxlen + 22 ; desired width for text canvas
h = numlines + 7 ; desired height for text canvas
x = 11 ; desired x for text
y = 2 ; desired y for text
; minimum decoration height is 11 lines
If h < 11 : h = 11 : EndIf
; >> create blank canvas <<
Protected Dim c.c(h,w+1)
FillMemory(@c(0,0), w*#SOC, 32, #PB_Character)
c(0,w) = #CR : c(0,w+1) = #LF
n=h-1 : For l=1 To n
CopyMemory(@c(0,0), @c(l,0), (w+2)*#SOC)
Next
; >> write text to canvas <<
l=y : *c=@c(l,x)
While *t\c
If *t\c=#LF
l+1 : *c=@c(l,x)
ElseIf *t\c<>#CR
*c\c=*t\c : *c+#SOC
EndIf
*t+#SOC
Wend
; >> decorate <<
n=h-4
PokeS(@c( 0,0), " .------", -1, #PB_String_NoZero)
PokeS(@c( 1,0), " / .-. ", -1, #PB_String_NoZero)
PokeS(@c( 2,0), "| / \ ", -1, #PB_String_NoZero)
PokeS(@c( 3,0), "| |\_. |", -1, #PB_String_NoZero)
PokeS(@c( 4,0), "|\| | /|", -1, #PB_String_NoZero)
PokeS(@c( 5,0), "| `---' |", -1, #PB_String_NoZero)
For l = 6 To n
PokeS(@c(l,0), "| |", -1, #PB_String_NoZero)
Next
PokeS(@c(n+1,0), "\ |", -1, #PB_String_NoZero)
PokeS(@c(n+2,0), " \ / ", -1, #PB_String_NoZero)
PokeS(@c(n+3,0), " `---' ", -1, #PB_String_NoZero)
PokeS(@c( 0,w-9), "-------. ", -1, #PB_String_NoZero)
PokeS(@c( 1,w-9), " .-. \", -1, #PB_String_NoZero)
PokeS(@c( 2,w-9), " / \ |", -1, #PB_String_NoZero)
PokeS(@c( 3,w-9), "| /| |", -1, #PB_String_NoZero)
PokeS(@c( 4,w-9), "|\ | |/|", -1, #PB_String_NoZero)
PokeS(@c( 5,w-9), "| `---' |", -1, #PB_String_NoZero)
For l = 6 To n
PokeS(@c(l,w-9), "| |", -1, #PB_String_NoZero)
Next
PokeS(@c(n+1,w-9), "| /", -1, #PB_String_NoZero)
PokeS(@c(n+2,w-9), " \ / ", -1, #PB_String_NoZero)
PokeS(@c(n+3,w-9), " `---' ", -1, #PB_String_NoZero)
l=n
For n=9 To w-10 : c(0,n)='-' : c(l,n)='-' : Next
; return decorated text
ProcedureReturn PeekS(@c(0,0))
EndProcedure
text$="One"+#CRLF$
text$+"Two"+#CRLF$
text$+"Three"+#CRLF$
Debug Decorated(@text$)