|
Post by anthonyrbrown on Feb 13, 2024 10:38:46 GMT
I am trying to get Screen text to print in the Centre of the Screen and using a simpler larger Text size method,using the SCREEN _NEWIMAGE(800, 600, 32) as shown below,so I need to add some code to it ?
SCREEN _NEWIMAGE(800, 600, 32) PRINT PRINT PRINT TAB(10000); "THIS TEXT NEEDS TO BE PRINTED IN THE CENTRE OF THE SCREEN" PRINT PRINT TAB(10000); "I AM USING THE PRINT TAB(10000) TO PUT THE TEXT IN THE CENTRE WHICH DOES NOT WORK ?" PRINT PRINT TAB(10000); "HOW CAN IT BE DONE?" PRINT PRINT TAB(10000); "I ALSO WANT TO MAKE THE TEXT MUCH BIGGER! SO THAT IT IS EASIER TO READ?" END
|
|
|
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.
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
|
|
|
Post by anthonyrbrown on Feb 13, 2024 18:32:11 GMT
Great stuff as always bplus,so is loading fonts etc. the only way? I was hoping for some kind of code that could be add to the SCREEN _NEWIMAGE(800, 600, 32)
I was looking at _WIDTH and _HEIGHT _SCREENMOVE _MIDDLE etc.
I know the Tab() is an old way of printing to the Screen but I like simple ways of doing things if possible.
|
|
|
Post by bplus on Feb 13, 2024 19:51:27 GMT
Well you can make bigger font out of smaller font without loading a new font. It's very complicated graphics tricks and loading a font is way, way , way more easy to do and understand not to mention cleaner.
BTW the only text screen I know are Screen 0 default mode or Console:'ONLY' = all text no graphics.
Using Screen _Newimage(width, height, colormode) starts up a graphics screen which I don't think you, ARB, are very skilled.
A graphics screen allows a shipload of new tools to use!
|
|
|
Post by anthonyrbrown on Feb 13, 2024 21:31:05 GMT
OK Thank's bplus I will play around with it and see what I can come up with,maybe I will find another way,if I do I will post it, or I will use your solution. A.R.B
|
|
ubi44
New Member
Posts: 32
|
Post by ubi44 on Feb 15, 2024 19:07:29 GMT
Hello
I've never used TAB to center text. In general, it's better to start from the center and move back half the length of the text using _printstring(x,y) ! ... otherwise, I have a question about Screen_NewImage !
Can we use POKE with a Screen _Newimage ? And how do we set the offset based on the chosen resolution ?
|
|
|
Post by bplus on Feb 15, 2024 19:43:47 GMT
I was never a fan of POKE (nor PEEK though may be safer) so I don't know what can or can't be done.
May I ask what you need to do with POKE because I strongly suspect an alternate method is now available for you in QB64.
Peek and Poke mainly kept to preserve compatability with old QB code.
|
|
ubi44
New Member
Posts: 32
|
Post by ubi44 on Feb 15, 2024 19:55:15 GMT
This is to draw a point instead of using PSET to be faster ..but it may be useless !
|
|
|
Post by bplus on Feb 16, 2024 16:24:43 GMT
This is to draw a point instead of using PSET to be faster ..but it may be useless ! I don't know which is faster but I do know Poke 'ing around memory is far more dangerous than simply drawing a point with PSet(x, y), colr~& With the old QB stuff, it WAS the only way to do stuff with mouse but now with the new and vastly improved QB64 you don't have to monkey around with Peel and Poke! You don't have to know a dang thing about the OS structure of memory that you could mess up by Poke 'ing around in the wrong place!
|
|