I can't tell these days if I'm getting too old, or getting to complicated. Simple wrap routines are a decent challenge, but I'm adding in variable size fonts and a matrix string to keep those attributes in memory. Well, a code snippet is worth a thousand words, so here you go...
Code: (Select All)
_ControlChr Off
$Color:32
Screen _NewImage(1300, 600, 32)
f16& = _LoadFont(Environ$("SYSTEMROOT") + "\Fonts\lucon.ttf", 16)
f20& = _LoadFont(Environ$("SYSTEMROOT") + "\Fonts\lucon.ttf", 20)
_ScreenMove 20, 0
_Font f16&
mc = 10
noa = 5
sa = 5
ln = 1
ReDim m$(7)
ReDim a$(7)
a$(1) = "abcd "
a$(1) = a$(1) + String$(mc - Len(a$(1)), Chr$(0))
a$(2) = "wert cat"
a$(2) = a$(2) + String$(mc - Len(a$(2)), Chr$(0))
a$(3) = "123 56 7"
a$(3) = a$(3) + String$(mc - Len(a$(3)), Chr$(0))
a$(4) = "X box A "
a$(4) = a$(4) + String$(mc - Len(a$(3)), Chr$(0))
a$(5) = "Pete 1. "
a$(5) = a$(5) + String$(mc - Len(a$(3)), Chr$(0))
a$(6) = "zzzzzzzz"
a$(6) = a$(6) + String$(mc - Len(a$(3)), Chr$(0))
a$(7) = "complete"
a$(7) = a$(7) + String$(mc - Len(a$(3)), Chr$(0))
For i = 1 To UBound(a$)
m$(i) = String$(mc * (noa + 1) + sa, Chr$(0))
Mid$(m$(i), 1, Len(m$(1))) = a$(i) 'Front end.
k = InStr(a$(i) + Chr$(0), Chr$(0)) - 1
Mid$(m$(i), mc + 1, sa) = String$(5, "|")
For j = 1 To k
Mid$(m$(i), mc + sa + 1 + ((j - 1) * noa), 1) = Mid$(a$(i), j, 1)
Mid$(m$(i), mc + sa + 2 + (j - 1) * noa, 1) = Chr$(16) ' 16 pixels high.
Mid$(m$(i), mc + sa + 3 + (j - 1) * noa, 1) = Chr$(8) ' 8 pixels wide.
Next
Print i, m$(i); "|", Len(m$(i))
Next
_Display: Sleep: Cls
If scr + ln = 1 Then h2 = 1 Else h2 = 0
h = 0: i = 1
Do
c = c + 1
Print "At line:"; c; "looking above and below... "
For g = h + h2 To i
If ln + g > UBound(m$) Then Exit Do
j = mc - InStr(Mid$(m$(ln - 1 + g), 1, mc) + Chr$(0), Chr$(0))
x% = 0: For p = 1 To mc - 1 - j
x% = x% + Asc(Mid$(m$(ln - 1 + g), mc + sa + 3 + (p - 1) * noa, 1))
Next
j2 = (mc - 1) * 8 - x%
k = _InStrRev(Mid$(m$(ln + g), 1, j + 1), " ") - 1
If k < 0 Then k = InStr(Mid$(m$(ln + g), 1, mc) + Chr$(0), Chr$(0)) - 1
x% = 0: For p = 1 To k
x% = x% + Asc(Mid$(m$(ln + g), mc + sa + 3 + (p - 1) * noa, 1))
Next
k2 = x%
Print "Analyzing lines"; ln - 1 + g; "and"; ln + g; " |"; Mid$(m$(ln - 1 + g), 1, mc); "|", "|"; Mid$(m$(ln + g), 1, mc); "|"
Print "Number of open spaces (j) on line: "; ln - 1 + g; "="; j
Print "Number of chrs (k) to wrap upwards:"; ln + g; "="; k
Print "Number of open pixels (j2) on line: "; ln - 1 + g; "="; j2
Print "Number of pixels (k2) in 1st word line:"; ln + g; "="; k2
If k2 And k2 <= j2 Then
Print: Print "------> Word Wrap lines"; ln - 1 + g; "and"; ln + g
Mid$(m$(ln + g - 1), mc - j, k + 1) = Mid$(m$(ln + g), 1, k + 1) ' Front end
Mid$(m$(ln + g - 1), mc + sa + 1 + (mc - 1 - j) * noa, (j + 1) * noa) = Mid$(m$(ln + g), mc + sa + 1, (k + 1) * noa) ' Back end.
x% = InStr(Mid$(m$(ln + g), k + 2, mc - (k + 2)) + Chr$(0), Chr$(0)) - 1
Mid$(m$(ln + g), 1, mc) = Mid$(m$(ln + g), k + 2, x%) + String$(mc - x%, Chr$(0)) ' Front end.
Mid$(m$(ln + g), mc + sa + 1, mc * noa) = Mid$(m$(ln + g), mc + sa + 1 + (k + 1) * noa, (x%) * noa) + String$((mc - x% + 1) * noa, Chr$(0)) ' Front end.
Exit For
Else
If Left$(m$(ln + g), 1) = Chr$(0) Then
j = UBound(m$)
Print: Print "------> Decreasing Array Size from"; j; "to"; j - 1: Print
For i = c To j - 1
m$(i) = m$(i + 1)
Next
ReDim _Preserve m$(j - 1)
Else
Print "------> Can't Wrap this line...": Print
End If
End If
Next
h2 = 0: h = h + 1: i = h + 1
GoSub mydisplay
Print "--------------------------------------------------------------------------------------------------------------------------"
_Display: Sleep: Cls
Loop
Print: Print "Finished..."
GoSub mydisplay
Sleep 2
End
mydisplay:
For q = 1 To UBound(m$)
Print m$(q)
Next
col = 0: row = 400: maxheight = 0
For q = 1 To UBound(m$)
For qq = 1 To mc
f& = Asc(Mid$(m$(q), mc + sa + 2 + (qq - 1) * noa, 1))
If f& = 0 Then Exit For
If f& <> oldf& Then
If f& > maxheight Then maxheight = f&
_Font f&: oldf& = f&
End If
_PrintString (col, row - maxheight \ 2), Mid$(m$(q), qq, 1)
col = col + Asc(Mid$(m$(q), mc + sa + 3 + (qq - 1) * noa, 1)) + 2
Next
row = row + 16: col = 0
Next
Return
It simply word wraps the 7 9-characters or less lines into a 6-line block. You have to keep pressing keys to get it to advance. All the added crap is for debugging purposes. The bottom of the screen would be the actual display. It is set up for pixels, so when I change the sizes, my next bit of testing, it should wrap according to size, and not character count.
Edit:
Okay, changing the font of 1-character from 16 to 20 works, so this looks promising...
Code: (Select All)
_ControlChr Off
$Color:32
Screen _NewImage(1300, 600, 32)
Dim f&(2)
f&(1) = _LoadFont(Environ$("SYSTEMROOT") + "\Fonts\lucon.ttf", 16)
f&(2) = _LoadFont(Environ$("SYSTEMROOT") + "\Fonts\lucon.ttf", 20)
_ScreenMove 20, 0
_Font f&(1)
mc = 10
noa = 5
sa = 5
ln = 1
ReDim m$(7)
ReDim a$(7)
a$(1) = "abc "
a$(1) = a$(1) + String$(mc - Len(a$(1)), Chr$(0))
a$(2) = "wert cat"
a$(2) = a$(2) + String$(mc - Len(a$(2)), Chr$(0))
a$(3) = "123 56 7"
a$(3) = a$(3) + String$(mc - Len(a$(3)), Chr$(0))
a$(4) = "X box A "
a$(4) = a$(4) + String$(mc - Len(a$(3)), Chr$(0))
a$(5) = "Pete 1. "
a$(5) = a$(5) + String$(mc - Len(a$(3)), Chr$(0))
a$(6) = "zzzzzzzz"
a$(6) = a$(6) + String$(mc - Len(a$(3)), Chr$(0))
a$(7) = "complete"
a$(7) = a$(7) + String$(mc - Len(a$(3)), Chr$(0))
For i = 1 To UBound(a$)
m$(i) = String$(mc * (noa + 1) + sa, Chr$(0))
Mid$(m$(i), 1, Len(m$(1))) = a$(i) 'Front end.
k = InStr(a$(i) + Chr$(0), Chr$(0)) - 1
Mid$(m$(i), mc + 1, sa) = String$(5, "|")
For j = 1 To k
Mid$(m$(i), mc + sa + 1 + ((j - 1) * noa), 1) = Mid$(a$(i), j, 1)
Mid$(m$(i), mc + sa + 2 + (j - 1) * noa, 1) = Chr$(1) ' Font size.
Mid$(m$(i), mc + sa + 3 + (j - 1) * noa, 1) = Chr$(8) ' 8 pixels wide.
Mid$(m$(i), mc + sa + 4 + (j - 1) * noa, 1) = Chr$(16) ' 16 pixels high.
Next
Print i, m$(i); "|", Len(m$(i))
Mid$(m$(2), mc + sa + 2 + (2 - 1) * noa, 1) = Chr$(2)
Mid$(m$(2), mc + sa + 3 + (2 - 1) * noa, 1) = Chr$(10)
Mid$(m$(2), mc + sa + 4 + (2 - 1) * noa, 1) = Chr$(20)
Next
_Display: Sleep: Cls
If scr + ln = 1 Then h2 = 1 Else h2 = 0
h = 0: i = 1
Do
c = c + 1
Print "At line:"; c; "looking above and below... "
For g = h + h2 To i
If ln + g > UBound(m$) Then Exit Do
j = mc - InStr(Mid$(m$(ln - 1 + g), 1, mc) + Chr$(0), Chr$(0))
x% = 0: For p = 1 To mc - 1 - j
x% = x% + Asc(Mid$(m$(ln - 1 + g), mc + sa + 3 + (p - 1) * noa, 1))
Next
j2 = (mc - 1) * 8 - x%
k = _InStrRev(Mid$(m$(ln + g), 1, j + 1), " ") - 1
If k < 0 Then k = InStr(Mid$(m$(ln + g), 1, mc) + Chr$(0), Chr$(0)) - 1
x% = 0: For p = 1 To k
x% = x% + Asc(Mid$(m$(ln + g), mc + sa + 3 + (p - 1) * noa, 1))
Next
k2 = x%
Print "Analyzing lines"; ln - 1 + g; "and"; ln + g; " |"; Mid$(m$(ln - 1 + g), 1, mc); "|", "|"; Mid$(m$(ln + g), 1, mc); "|"
Print "Number of open spaces (j) on line: "; ln - 1 + g; "="; j
Print "Number of chrs (k) to wrap upwards:"; ln + g; "="; k
Print "Number of open pixels (j2) on line: "; ln - 1 + g; "="; j2
Print "Number of pixels (k2) in 1st word line:"; ln + g; "="; k2
If k2 And k2 <= j2 Then
Print: Print "------> Word Wrap lines"; ln - 1 + g; "and"; ln + g
Mid$(m$(ln + g - 1), mc - j, k + 1) = Mid$(m$(ln + g), 1, k + 1) ' Front end
Mid$(m$(ln + g - 1), mc + sa + 1 + (mc - 1 - j) * noa, (j + 1) * noa) = Mid$(m$(ln + g), mc + sa + 1, (k + 1) * noa) ' Back end.
x% = InStr(Mid$(m$(ln + g), k + 2, mc - (k + 2)) + Chr$(0), Chr$(0)) - 1
Mid$(m$(ln + g), 1, mc) = Mid$(m$(ln + g), k + 2, x%) + String$(mc - x%, Chr$(0)) ' Front end.
Mid$(m$(ln + g), mc + sa + 1, mc * noa) = Mid$(m$(ln + g), mc + sa + 1 + (k + 1) * noa, (x%) * noa) + String$((mc - x% + 1) * noa, Chr$(0)) ' Front end.
Exit For
Else
If Left$(m$(ln + g), 1) = Chr$(0) Then
j = UBound(m$)
Print: Print "------> Decreasing Array Size from"; j; "to"; j - 1: Print
For i = c To j - 1
m$(i) = m$(i + 1)
Next
ReDim _Preserve m$(j - 1)
Else
Print "------> Can't Wrap this line...": Print
End If
End If
Next
h2 = 0: h = h + 1: i = h + 1
GoSub mydisplay
Print "--------------------------------------------------------------------------------------------------------------------------"
_Display: Sleep: Cls
Loop
Print: Print "Finished..."
GoSub mydisplay
Sleep 2
End
mydisplay:
For q = 1 To UBound(m$)
Print m$(q)
Next
col = 0: row = 400: maxheight = 0
For q = 1 To UBound(m$)
For qq = 1 To mc
f& = Asc(Mid$(m$(q), mc + sa + 2 + (qq - 1) * noa, 1))
fw& = Asc(Mid$(m$(q), mc + sa + 3 + (qq - 1) * noa, 1)) + 2
fh& = Asc(Mid$(m$(q), mc + sa + 4 + (qq - 1) * noa, 1))
If f& = 0 Then Exit For
If fh& > maxheight Then maxheight = fh&
If f& <> oldf& Then
_Font f&(f&): oldf& = f&
End If
_PrintString (col, row - fh& \ 2), Mid$(m$(q), qq, 1)
col = col + fw&
Next
row = row + maxheight + 2: col = 0
Next
Return
Pete