_PRINTSTRING

From QB64 Wiki
Jump to navigation Jump to search

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.
  • _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.
  • In SCREEN 0 (text only), _PRINTSTRING works as one-line replacement for LOCATE x, y: PRINT text$, without changing the current cursor position.


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: 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

Adapted from code by Unseen Machine


See also



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page