GLBasic User Manual

Main sections

GETFONTSIZE

GETFONTSIZE sx##, sy##



Retrieves the size of a single character in the current font into sx## and sy##. Each character in the font is the same size.

Sample:
 
DRAWRECT 300, 100, 200, 300, RGB(20,20,120)
BOXPRINT ("This is a long string of text, which has to be wrapped", 300, 100, 200)
SHOWSCREEN
MOUSEWAIT


// ------------------------------------------------------------- //
// -=# BOXPRINT #=-
// ------------------------------------------------------------- //
FUNCTION BOXPRINT: str$, x, y, wx
// These variables are locally defined:
// Diese Variablen sind als LOCAL definiert:
// str$, x, y, wx, void

LOCAL tx, ty // Width of one character
LOCAL cx, cy, word$, c$, cpos

GETFONTSIZE tx, ty

cy=y
str$=str$+" "
cx=x
WHILE cpos < LEN(str$)
c$=MID$(str$, cpos, 1)

word$=word$+c$

IF c$=" "
IF cx-x+(LEN(word$)-1)*tx > wx
cx=x; cy=cy+ty
ENDIF
PRINT word$, cx, cy
cx=cx+ LEN(word$)*tx
word$=""
ENDIF
cpos=cpos+1
WEND
ENDFUNCTION void // BOXPRINT

See also...