07-16-2023, 10:31 AM
Here you have a code that demonstrates the whole thing
With the arrow keys left and right can you change the height of the TTF Font
With the arrow keys left and right can you change the height of the TTF Font
Code: (Select All)
OPTION _EXPLICIT
' Screen mode 13 with 640x480
SCREEN _NEWIMAGE(640, 480, 13)
DIM keyin AS STRING
DIM curHeight AS INTEGER ' current height of TTF Font
DIM oldHeight AS INTEGER ' old height of TTF Font
DIM FNThandle AS LONG ' Image handle
' This is for the TEXTfield positions
DIM MAXwidth AS INTEGER
DIM MAXheight AS INTEGER
curHeight = 32
FNThandle = _LOADFONT("C:\WINDOWS\fonts\courbd.ttf", curHeight, "monospace")
_FONT FNThandle
DO
IF oldHeight <> curHeight THEN
_FONT 16
_FREEFONT FNThandle
FNThandle = _LOADFONT("C:\WINDOWS\fonts\courbd.ttf", curHeight, "monospace")
_FONT FNThandle
oldHeight = curHeight
END IF
' Rounding down the TEXTfield to a Integer
MAXwidth = FIX(_WIDTH / _FONTWIDTH)
MAXheight = FIX(_HEIGHT / _FONTHEIGHT)
CLS , 7
COLOR 7, 1
LOCATE 1, 1: PRINT SPACE$(MAXwidth);
LOCATE MAXheight, 1: PRINT SPACE$(MAXwidth);
LOCATE 1, 2: PRINT "This is a TTF Font Example";
LOCATE MAXheight, 2: PRINT "ESC - EXIT";
COLOR 0, 7
LOCATE 3, 2: PRINT "Screen Res : " + LTRIM$(STR$(_WIDTH)) + "x" + LTRIM$(STR$(_HEIGHT));
LOCATE 4, 2: PRINT "Font Res : " + LTRIM$(STR$(_FONTWIDTH)) + "x" + LTRIM$(STR$(_FONTHEIGHT));
LOCATE 5, 2: PRINT "TextRes RD : " + LTRIM$(STR$(CLNG((_WIDTH / _FONTWIDTH) * 100) / 100)) + "x" + LTRIM$(STR$(CLNG((_HEIGHT / _FONTHEIGHT) * 100) / 100));
LOCATE 6, 2: PRINT "TextRes INT: " + LTRIM$(STR$(MAXwidth)) + "x" + LTRIM$(STR$(MAXheight));
LOCATE 7, 2: PRINT "FNT handle : " + LTRIM$(STR$(_FONT));
LOCATE 9, 2: PRINT "<- Size -1";
LOCATE 9, MAXwidth - 10: PRINT "Size +1 ->";
DO
COLOR 7, 1
LOCATE MAXheight, MAXwidth - LEN(TIME$) + 1: PRINT TIME$;
keyin = INKEY$
LOOP WHILE keyin = ""
IF keyin = CHR$(0) + CHR$(77) THEN IF curHeight < 32 THEN curHeight = curHeight + 1
IF keyin = CHR$(0) + CHR$(75) THEN IF curHeight > 1 THEN curHeight = curHeight - 1
LOOP WHILE keyin <> CHR$(27)
SYSTEM