This is a simple demo for SCREEN 0, but someone could work up a graphics counterpart easily enough...
It's a bit of a trick to capture ctrl combos with some keys like + and -. I used inp(96) as it is one of the easiest. The actual trigger happens when the + or - key is released, and nothing registers when either is pressed.
The routine can be expanded to use $RESIZE:ON but the user would need to decide what changes as the screen size changes. Probably the most popular use would be a fixed number of characters across the screen, so when resize increases the widt, the width statement adjusts to the size, and the font size adjusts to as close to the same number of characters across the screen. To do a perfect operation would also require the development of a margin system.
EDIT: Addressed memory leak, thanks Steve!
Pete
Code: (Select All)
SCREEN 0
fontsize% = 16
style$ = "monospace"
fontpath$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf"
font& = _LOADFONT(fontpath$, fontsize%, style$)
_FONT font&
ww = 600: wh = 350
WIDTH ww \ _FONTWIDTH, wh \ _FONTHEIGHT
PALETTE 7, 63: COLOR 0, 7: CLS
_FONT font&
_SCREENMOVE 0, 0
PRINT "Press ctrl + to increase font size or ctrl - to decrease."
DO
_LIMIT 30
c = _KEYHIT
IF c THEN
SELECT CASE c
CASE -189
IF fontsize% > 9 THEN fontsize% = fontsize% - 2
CASE -187
IF fontsize% < 31 THEN fontsize% = fontsize% + 2
END SELECT
END IF
IF oldf% AND fontsize% <> oldf% THEN
_SCREENHIDE: _FONT 8
_FREEFONT font&
font& = _LOADFONT(fontpath$, fontsize%, style$)
_FONT font&
_SCREENSHOW
fw% = _FONTWIDTH: fh% = _FONTHEIGHT
WIDTH ww / fw%, wh / fh%
PALETTE 7, 63: COLOR 0, 7: CLS
_FONT font&
_SCREENMOVE 0, 0
PRINT "Font size changed to:"; fontsize%, "width ="; _WIDTH
_KEYCLEAR
END IF
oldf% = fontsize%
LOOP
It's a bit of a trick to capture ctrl combos with some keys like + and -. I used inp(96) as it is one of the easiest. The actual trigger happens when the + or - key is released, and nothing registers when either is pressed.
The routine can be expanded to use $RESIZE:ON but the user would need to decide what changes as the screen size changes. Probably the most popular use would be a fixed number of characters across the screen, so when resize increases the widt, the width statement adjusts to the size, and the font size adjusts to as close to the same number of characters across the screen. To do a perfect operation would also require the development of a margin system.
EDIT: Addressed memory leak, thanks Steve!
Pete