PRINTSTRING: Difference between revisions
Jump to navigation
Jump to search
Code by Ted Weissgerber
Download of Example 2 Bitmap images
Adapted from code by Unseen Machine
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "{{DISPLAYTITLE:_PRINTSTRING}} The _PRINTSTRING statement prints text strings using graphic column and row coordinate positions. {{PageSyntax}} : _PRINTSTRING({{Parameter|column}}, {{Parameter|row}}), {{Parameter|textExpression$}}[, {{Parameter|imageHandle&}}] {{Parameters}} * {{Parameter|column}} and {{Parameter|row}} are INTEGER or LONG starting PIXEL (graphic) column and row coordinates to set text or custom fonts. * {{Parameter|textExpr...") |
No edit summary |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
{{PageSyntax}} | {{PageSyntax}} | ||
: [[_PRINTSTRING]]({{Parameter|column}}, {{Parameter|row}}), {{Parameter|textExpression$}}[, {{Parameter|imageHandle&}}] | : [[_PRINTSTRING]]({{Parameter|column}}, {{Parameter|row}}), {{Parameter|textExpression$}}[, {{Parameter|imageHandle&}}] | ||
{{ | {{PageParameters}} | ||
* {{Parameter|column}} and {{Parameter|row}} are [[INTEGER]] or [[LONG]] starting PIXEL (graphic) column and row coordinates to set text or custom fonts. | * {{Parameter|column}} and {{Parameter|row}} are [[INTEGER]] or [[LONG]] starting PIXEL (graphic) column and row coordinates to set text or custom fonts. | ||
* {{Parameter|textExpression$}} is any literal or variable [[STRING|string]] value of text to be displayed. | * {{Parameter|textExpression$}} is any literal or variable [[STRING|string]] value of text to be displayed. | ||
* {{Parameter|imageHandle&}} is the optional image or destination to use. Zero designates current [[ | * {{Parameter|imageHandle&}} is the optional image or destination to use. Zero designates current [[SCREEN]] page. | ||
{{PageDescription}} | {{PageDescription}} | ||
* The starting coordinate sets the top left corner of the text to be printed. Use [[_FONTHEIGHT]] to calculate that text or [[_FONT|font]] position | * The starting coordinate sets the top left corner of the text to be printed. Use [[_FONTHEIGHT]] to calculate that text or [[_FONT|font]] position | ||
* The [[_FONT]] size can affect the [[SCREEN | * The [[_FONT]] size can affect the [[SCREEN|screen]] and row heights. | ||
** Custom fonts are not required. [[_PRINTSTRING]] can print all [[ASCII]] characters. | ** Custom fonts are not required. [[_PRINTSTRING]] can print all [[ASCII]] characters. | ||
* [[_PRINTWIDTH]] can be used to determine how wide a text print will be so that the screen width is not exceeded. | * [[_PRINTWIDTH]] can be used to determine how wide a text print will be so that the screen width is not exceeded. | ||
Line 25: | Line 25: | ||
{{PageAvailability}} | |||
* In versions of QB64 prior to 1.000 _PRINTSTRING can only be used in graphic, 256 color or 32 bit screen modes, not SCREEN 0.'' | * In versions of QB64 prior to 1.000 _PRINTSTRING can only be used in graphic, 256 color or 32 bit screen modes, not SCREEN 0.'' | ||
Line 31: | Line 31: | ||
{{PageExamples}} | {{PageExamples}} | ||
''Example 1:'' Printing those unprintable [[ASCII]] control characters is no longer a problem! | ''Example 1:'' Printing those unprintable [[ASCII]] control characters is no longer a problem! | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(800, 600, 256) | {{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(800, 600, 256) | ||
Line 42: | Line 42: | ||
{{Cl|_PRINTSTRING}} (0, 16), chrstr$ | {{Cl|_PRINTSTRING}} (0, 16), chrstr$ | ||
{{Cl|END}} | {{Cl|END}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}} | {{OutputStart}} | ||
Line 49: | Line 49: | ||
''Example 2:'' Making any '''QB64 program window''' larger using a SUB that easily converts PRINT to [[_PRINTSTRING]]. | ''Example 2:'' Making any '''QB64 program window''' larger using a SUB that easily converts PRINT to [[_PRINTSTRING]]. | ||
{{CodeStart}} | {{CodeStart}} | ||
Scr13& = {{Cl|_NEWIMAGE}}(320, 200, 13) 'this is the old SCREEN 13 image page to set the image | Scr13& = {{Cl|_NEWIMAGE}}(320, 200, 13) 'this is the old SCREEN 13 image page to set the image | ||
Big13& = {{Cl|_NEWIMAGE}}(640, 480, 256) 'use 4 X 3 aspect ratio that | Big13& = {{Cl|_NEWIMAGE}}(640, 480, 256) 'use 4 X 3 aspect ratio that QBasic used when full screen | ||
{{Cl | {{Cl|SCREEN}} Big13& | ||
{{Cl|_DEST}} Scr13& | {{Cl|_DEST}} Scr13& | ||
image1& = {{Cl|_LOADIMAGE}}("Howie.BMP", 256) | image1& = {{Cl|_LOADIMAGE}}("Howie.BMP", 256) | ||
Line 61: | Line 61: | ||
{{Cl|_PUTIMAGE}} (160, 20), image2&, Scr13& | {{Cl|_PUTIMAGE}} (160, 20), image2&, Scr13& | ||
{{Cl|_COPYPALETTE}} image1&, Scr13& | {{Cl|_COPYPALETTE}} image1&, Scr13& | ||
{{Cl|COLOR}} 151: {{Cl|LOCATE}} 2, 4: PRINTS "Screen 13 Height Reduction to 83%" | {{Cl|COLOR}} 151: {{Cl|LOCATE}} 2, 4: PRINTS "Screen 13 Height Reduction to 83%" | ||
{{Cl|LOCATE}} 22, 22: PRINTS {{Cl|CHR$}}(24) + " 4 X 3 Proportion" 'use {{Cl|concatenation}} | {{Cl|LOCATE}} 22, 22: PRINTS {{Cl|CHR$}}(24) + " 4 X 3 Proportion" 'use {{Cl|concatenation}} | ||
{{Cl|LOCATE}} 24, 21: PRINTS {{Cl|CHR$}}(27) + " Stretched at 100%" 'instead of a {{Cl|semicolon}}! | {{Cl|LOCATE}} 24, 21: PRINTS {{Cl|CHR$}}(27) + " Stretched at 100%" 'instead of a {{Cl|semicolon}}! | ||
Line 73: | Line 73: | ||
col% = ({{Cl|POS}}(0) - 1) * {{Cl|_PRINTWIDTH}}("W") 'finds current page text or font column width | col% = ({{Cl|POS}}(0) - 1) * {{Cl|_PRINTWIDTH}}("W") 'finds current page text or font column width | ||
{{Cl|_PRINTSTRING}} (col%, row%), Text$ | {{Cl|_PRINTSTRING}} (col%, row%), Text$ | ||
{{Cl|END SUB}} | {{Cl|END SUB}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{ | {{Small|Code by Ted Weissgerber}} | ||
: ''Explanation:'' The procedure above creates a larger version of a SCREEN 13 window by stretching it with [[_PUTIMAGE]]. It cannot stretch PRINTed text so [[_PRINTSTRING]] must be used instead. [[LOCATE]] sets the PRINT cursor position for [[CSRLIN]] and [[POS]](0) to read. The SUB then converts the coordinates to graphical ones. Then '''change''' [[PRINT]] to PRINTS using the IDE '''Search Menu'''. | : ''Explanation:'' The procedure above creates a larger version of a SCREEN 13 window by stretching it with [[_PUTIMAGE]]. It cannot stretch PRINTed text so [[_PRINTSTRING]] must be used instead. [[LOCATE]] sets the PRINT cursor position for [[CSRLIN]] and [[POS]](0) to read. The SUB then converts the coordinates to graphical ones. Then '''change''' [[PRINT]] to PRINTS using the IDE '''Search Menu'''. | ||
<center>[https://www.dropbox.com/s/tcdik1ajegbeiz4/HOWIE.zip?dl=0 Download of Example 2 Bitmap images]</center> | <center>[https://www.dropbox.com/s/tcdik1ajegbeiz4/HOWIE.zip?dl=0 Download of Example 2 Bitmap images]</center> | ||
Line 81: | Line 81: | ||
''Example 3:'' Rotating a text string around a graphic object. | ''Example 3:'' Rotating a text string around a graphic object. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl | {{Cl|SCREEN}} 12 | ||
{{Cl|DIM}} row {{Cl|AS}} {{Cl|INTEGER}}, cnt {{Cl|AS}} {{Cl|INTEGER}}, cstart {{Cl|AS}} {{Cl|SINGLE}}, cend {{Cl|AS}} {{Cl|SINGLE}} | {{Cl|DIM}} row {{Cl|AS}} {{Cl|INTEGER}}, cnt {{Cl|AS}} {{Cl|INTEGER}}, cstart {{Cl|AS}} {{Cl|SINGLE}}, cend {{Cl|AS}} {{Cl|SINGLE}} | ||
{{Cl|DIM}} xrot {{Cl|AS}} {{Cl|INTEGER}}, yrot {{Cl|AS}} {{Cl|INTEGER}}, scale {{Cl|AS}} {{Cl|INTEGER}} | {{Cl|DIM}} xrot {{Cl|AS}} {{Cl|INTEGER}}, yrot {{Cl|AS}} {{Cl|INTEGER}}, scale {{Cl|AS}} {{Cl|INTEGER}} | ||
' {{Cl|_FULLSCREEN}} 'full screen optional | ' {{Cl|_FULLSCREEN}} 'full screen optional | ||
cstart = 0: cend = 8 * {{Cl|ATN}}(1) | cstart = 0: cend = 8 * {{Cl|ATN}}(1) | ||
xrot = 6: yrot = 60: scale = 4 | xrot = 6: yrot = 60: scale = 4 | ||
row = 1 | row = 1 | ||
{{Cl|CIRCLE}} (320, 240), 15, 9: {{Cl|PAINT}} {{Cl|STEP}}(0, 0), 9 | {{Cl|CIRCLE}} (320, 240), 15, 9: {{Cl|PAINT}} {{Cl|STEP}}(0, 0), 9 | ||
Line 95: | Line 95: | ||
y = 200 + (scale * 40 - (row * yrot)) * {{Cl|SIN}}(i) | y = 200 + (scale * 40 - (row * yrot)) * {{Cl|SIN}}(i) | ||
cnt = cnt + 1 | cnt = cnt + 1 | ||
{{Cl|COLOR}} 7: {{Cl|_PRINTSTRING}} (x, y), "HELLO WORLD!", 0 'display | {{Cl|COLOR}} 7: {{Cl|_PRINTSTRING}} (x, y), "HELLO WORLD!", 0 'display | ||
{{Cl|IF}} cnt = {{Cl|LEN}}(text$) * 8 {{Cl|THEN}} cnt = 0: {{Cl|EXIT DO}} | {{Cl|IF}} cnt = {{Cl|LEN}}(text$) * 8 {{Cl|THEN}} cnt = 0: {{Cl|EXIT DO}} | ||
{{Cl|_DISPLAY}} | {{Cl|_DISPLAY}} | ||
{{Cl|COLOR}} 0: {{Cl|_PRINTSTRING}} (x, y), "HELLO WORLD!", 0 'erase | {{Cl|COLOR}} 0: {{Cl|_PRINTSTRING}} (x, y), "HELLO WORLD!", 0 'erase | ||
{{Cl|_DELAY}} 0.02 | {{Cl|_DELAY}} 0.02 | ||
{{Cl|NEXT}} | {{Cl|NEXT}} | ||
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) 'escape key exit | {{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) 'escape key exit | ||
{{Cl|COLOR}} 15 | {{Cl|COLOR}} 15 | ||
{{Cl|END}} | {{Cl|END}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{ | {{Small|Adapted from code by Unseen Machine}} | ||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [[_NEWIMAGE]], [[_PRINTWIDTH]], [[_PRINTMODE]] | * [[_NEWIMAGE]], [[_PRINTWIDTH]], [[_PRINTMODE]] | ||
* [[_CONTROLCHR]] | * [[_CONTROLCHR]] | ||
* [[_FONT]], [[_LOADFONT]], [[_FONTHEIGHT]], [[_FONTWIDTH]] | * [[_FONT]], [[_LOADFONT]], [[_FONTHEIGHT]], [[_FONTWIDTH]] | ||
* [[_SCREENIMAGE]], [[_SCREENPRINT]] | * [[_SCREENIMAGE]], [[_SCREENPRINT]] |
Latest revision as of 22:42, 11 February 2023
The _PRINTSTRING statement prints text strings using graphic column and row coordinate positions.
Syntax
- _PRINTSTRING(column, row), textExpression$[, imageHandle&]
Parameters
- column and row are INTEGER or LONG starting PIXEL (graphic) column and row coordinates to set text or custom fonts.
- textExpression$ is any literal or variable string value of text to be displayed.
- imageHandle& is the optional image or destination to use. Zero designates current SCREEN page.
Description
- The starting coordinate sets the top left corner of the text to be printed. Use _FONTHEIGHT to calculate that text or font position
- The _FONT size can affect the screen and row heights.
- Custom fonts are not required. _PRINTSTRING can print all ASCII characters.
- _PRINTWIDTH can be used to determine how wide a text print will be so that the screen width is not exceeded.
- If the imageHandle& is omitted, the current image, page or screen destination is used.
- Can use the current font alpha blending with a designated image background. See the _RGBA function example.
- Use the _PRINTMODE statement before printing to set how the background is rendered.
- Use the _PRINTMODE (function) to find the current _PRINTMODE setting.
- In SCREEN 0 (text only), _PRINTSTRING works as one-line replacement for LOCATE x, y: PRINT text$, without changing the current cursor position.
Availability
- In versions of QB64 prior to 1.000 _PRINTSTRING can only be used in graphic, 256 color or 32 bit screen modes, not SCREEN 0.
Examples
Example 1: Printing those unprintable ASCII control characters is no longer a problem!
SCREEN _NEWIMAGE(800, 600, 256) FOR code = 0 TO 31 chrstr$ = chrstr$ + CHR$(code) + SPACE$(1) NEXT _FONT _LOADFONT("C:\Windows\Fonts\Cour.ttf", 20, "MONOSPACE") 'select monospace font _PRINTSTRING (0, 16), chrstr$ END |
☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼ |
Example 2: Making any QB64 program window larger using a SUB that easily converts PRINT to _PRINTSTRING.
Scr13& = _NEWIMAGE(320, 200, 13) 'this is the old SCREEN 13 image page to set the image Big13& = _NEWIMAGE(640, 480, 256) 'use 4 X 3 aspect ratio that QBasic used when full screen SCREEN Big13& _DEST Scr13& image1& = _LOADIMAGE("Howie.BMP", 256) image2& = _LOADIMAGE("Howie2.BMP", 256) _PUTIMAGE (10, 20), image1&, Scr13& _PUTIMAGE (160, 20), image2&, Scr13& _COPYPALETTE image1&, Scr13& COLOR 151: LOCATE 2, 4: PRINTS "Screen 13 Height Reduction to 83%" LOCATE 22, 22: PRINTS CHR$(24) + " 4 X 3 Proportion" 'use concatenation LOCATE 24, 21: PRINTS CHR$(27) + " Stretched at 100%" 'instead of a semicolon! _COPYPALETTE Scr13&, Big13& 'required when imported image colors are used _PUTIMAGE , Scr13&, Big13& 'stretches the screen to double the size K$ = INPUT$(1) END SUB PRINTS (Text$) row% = (CSRLIN - 1) * _FONTHEIGHT 'finds current screen page text or font row height col% = (POS(0) - 1) * _PRINTWIDTH("W") 'finds current page text or font column width _PRINTSTRING (col%, row%), Text$ END SUB |
- Explanation: The procedure above creates a larger version of a SCREEN 13 window by stretching it with _PUTIMAGE. It cannot stretch PRINTed text so _PRINTSTRING must be used instead. LOCATE sets the PRINT cursor position for CSRLIN and POS(0) to read. The SUB then converts the coordinates to graphical ones. Then change PRINT to PRINTS using the IDE Search Menu.
Example 3: Rotating a text string around a graphic object.
SCREEN 12 DIM row AS INTEGER, cnt AS INTEGER, cstart AS SINGLE, cend AS SINGLE DIM xrot AS INTEGER, yrot AS INTEGER, scale AS INTEGER ' _FULLSCREEN 'full screen optional cstart = 0: cend = 8 * ATN(1) xrot = 6: yrot = 60: scale = 4 row = 1 CIRCLE (320, 240), 15, 9: PAINT STEP(0, 0), 9 DO FOR i = cstart TO cend STEP .04 x = 300 + (scale * 40 - (row * xrot)) * COS(i) y = 200 + (scale * 40 - (row * yrot)) * SIN(i) cnt = cnt + 1 COLOR 7: _PRINTSTRING (x, y), "HELLO WORLD!", 0 'display IF cnt = LEN(text$) * 8 THEN cnt = 0: EXIT DO _DISPLAY COLOR 0: _PRINTSTRING (x, y), "HELLO WORLD!", 0 'erase _DELAY 0.02 NEXT LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit COLOR 15 END |
See also
- _NEWIMAGE, _PRINTWIDTH, _PRINTMODE
- _CONTROLCHR
- _FONT, _LOADFONT, _FONTHEIGHT, _FONTWIDTH
- _SCREENIMAGE, _SCREENPRINT
- Text Using Graphics