Post by bplus on Feb 13, 2024 15:49:18 GMT
Tab(10000) Yikes!!!! Try Tab(10) Tab(n)will locate cursor to (n) character place on line. An 800 pixel width in graphics screen setup by _Newimage line has max of 800/8 = 100 chars across.
To center text on a line for 100 chars lines tab(int((100 - len(text$)/2))
Now I make a tool called CenterPrint(text$) so I don't have to redo that little forumla every time I want to print something centered on screen:
Now I can copy and paste that little sub into any .bas source for centering text on a 100 character line = 800 pixel width.
Now if you want bigger text you need to use a Font file and recalc the pixel width of the text in that font ie use _PrintWidth and use _PrintString instead of Print and then a new formula is:
_printstring((_width - _PrintWidth(text$))/2, desiredheight_in_pixels), text$
No wait... this is much better when using Font:
Screen _NewImage(800, 600, 32)
Print
Print
Print Tab(10); "THIS TEXT NEEDS TO BE PRINTED IN THE CENTRE OF THE SCREEN"
Print
Print Tab(10); "I AM USING THE PRINT TAB(10000) TO PUT THE TEXT IN THE CENTRE WHICH DOES NOT WORK ?"
Print
Print Tab(10); "HOW CAN IT BE DONE?"
Print
Print Tab(10); "I ALSO WANT TO MAKE THE TEXT MUCH BIGGER! SO THAT IT IS EASIER TO READ?"
End
To center text on a line for 100 chars lines tab(int((100 - len(text$)/2))
Screen _NewImage(800, 600, 32)
Locate 17, 1
text$ = "THIS TEXT NEEDS TO BE PRINTED IN THE CENTRE OF THE SCREEN"
Print Tab(Int((100 - Len(text$)) / 2)); text$
text$ = "I AM USING THE PRINT TAB(10000) TO PUT THE TEXT IN THE CENTRE WHICH DOES NOT WORK ?"
Print Tab(Int((100 - Len(text$)) / 2)); text$
text$ = "HOW CAN IT BE DONE?"
Print Tab(Int((100 - Len(text$)) / 2)); text$
text$ = "I ALSO WANT TO MAKE THE TEXT MUCH BIGGER! SO THAT IT IS EASIER TO READ?"
Print Tab(Int((100 - Len(text$)) / 2)); text$
Now I make a tool called CenterPrint(text$) so I don't have to redo that little forumla every time I want to print something centered on screen:
Screen _NewImage(800, 600, 32)
Locate 17, 1
text$ = "THIS TEXT NEEDS TO BE PRINTED IN THE CENTRE OF THE SCREEN"
CenterPrint text$
text$ = "I AM USING THE PRINT TAB(10000) TO PUT THE TEXT IN THE CENTRE WHICH DOES NOT WORK ?"
CenterPrint text$
text$ = "HOW CAN IT BE DONE?"
CenterPrint text$
text$ = "I ALSO WANT TO MAKE THE TEXT MUCH BIGGER! SO THAT IT IS EASIER TO READ?"
CenterPrint text$
Sub CenterPrint (text$)
Print Tab(Int((100 - Len(text$)) / 2)); text$
End Sub
Now I can copy and paste that little sub into any .bas source for centering text on a 100 character line = 800 pixel width.
Now if you want bigger text you need to use a Font file and recalc the pixel width of the text in that font ie use _PrintWidth and use _PrintString instead of Print and then a new formula is:
_printstring((_width - _PrintWidth(text$))/2, desiredheight_in_pixels), text$
Screen _NewImage(800, 600, 32)
A& = _LoadFont("Arial.ttf", 48, "Monospace")
_Font A&
CenterPrint "Hello World", 17
Sleep
Sub CenterPrint (text$, CharRow)
_PrintString ((_Width - _PrintWidth(text$)) / 2, CharRow * 16), text$
End Sub
No wait... this is much better when using Font:
Screen _NewImage(800, 600, 32)
A& = _LoadFont("Arial.ttf", 48, "Monospace")
_Font A&
CenterPrint "Hello World", 600 / 2 - (48 / 2) ' at .5 screen - .5 height of font
Sleep
Sub CenterPrint (text$, PixelTopLineHeight)
_PrintString ((_Width - _PrintWidth(text$)) / 2, PixelTopLineHeight), text$
End Sub