_TITLE "Frame message for QB64 B+ 2018-11-10" '2018-11-11 frame mod with STRING$
'2018-11-12 more frame improvement, embed into centerPrint and setup for text alignment
s$
= CHR$(1) + "Hi TempodiBasic," + CHR$(10)s$
= s$
+ CHR$(10) + "How are you tonight?" + CHR$(10)s$
= s$
+ CHR$(10) + CHR$(9) + "I hope this message is too long, to test fitting a very long line into a box. I am working from modified code of my messageBox$ function."s$ = s$ + " Testing adding a line that takes this beyond box height."
h$
= h$
+ CHR$(2) + "Instructions for alignment with centerPrint sub:" + CHR$(10) + CHR$(10) + CHR$(1)h$
= h$
+ CHR$(9) + "Use CHR$(1) for left alignments." + CHR$(10)h$
= h$
+ CHR$(9) + "Use CHR$(2) for center alignments." + CHR$(10)h$
= h$
+ CHR$(9) + "Use CHR$(3) for right alignments." + CHR$(10)h$
= h$
+ CHR$(9) + "Use CHR$(9) to insert 4 spaces with left alignment." + CHR$(10)h$
= h$
+ CHR$(9) + "Use CHR$(10) or CHR$(13) or one + other, to start new line." + CHR$(10)h$
= h$
+ CHR$(9) + "Use Chr$(10) or CHR$(13) twice in row for blank line." + CHR$(10) + CHR$(10) + CHR$(3)h$ = h$ + "bplus "
'WHILE _KEYDOWN(27) = 0
'framed 10, 5, 20, 5
'check full fill
centerPrint 1, 17, 20, 5, "Test full fill right in here!"
centerPrint 1, 17, 20, 5, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
'framed 25, 13, 40, 10
centerPrint 25, 15, 40, 8, s$
'framed 1, 1, 60, 10
centerPrint 1, 1, 60, 13, h$
'WEND
SUB centerPrint
(x
, y
, w
, h
, m$
) 'embed framed into code, so only one call needed
'setup t$() to store strings with ti as index, limit w chars per line max, b$ is for build
DIM t$
(100), a
(100) AS _BYTE: ti
= 0: b$
= "": align
= 2 'are there any new line signals, CR, LF or both? take CRLF or LFCR as one break but dbl LF or CR means blank line
t$(ti) = b$: b$ = "": a(ti) = align: ti = ti + 1
t$(ti) = b$: b$ = "": a(ti) = align: ti = ti + 1
tail$ = "": ff = 0
FOR j
= LEN(b$
) TO 1 STEP -1 'backup until find a space, save the tail end for next line t$
(ti
) = MID$(b$
, 1, j
- 1): b$
= tail$
+ c$: a
(ti
) = align: ti
= ti
+ 1 ff = 1 'found space flag
tail$ = d$ + tail$ 'the tail grows!
t$(ti) = b$: b$ = c$: a(ti) = align: ti = ti + 1
b$ = b$ + c$ 'just keep building the line
t$(ti) = b$: a(ti) = align
IF ti
> h
- 1 THEN stopper
= h
- 1 ELSE stopper
= ti
IF ti
< h
- 1 THEN starter
= (h
- 1 - ti
) \
2 ELSE starter
= 0 col = x + 1
col
= x
+ (w
- LEN(t$
(r
))) / 2 + 1 col
= x
+ w
- LEN(t$
(r
)) + 1