Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change font size / Maintain screen size.
#7
(11-11-2022, 07:53 PM)Pete Wrote: I'd like the array method, better. If we don't have to swap and remove fonts, it's less jittery on screen size changes.

Code: (Select All)
SCREEN 0
fontsize% = 16
style$ = "monospace"
fontpath$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf"
DIM font(8 TO 32) AS LONG
FOR i = 8 TO 32 STEP 2
    font(i) = _LOADFONT(fontpath$, i, style$)
NEXT
_FONT font(fontsize%)
ww = 600: wh = 350
WIDTH ww \ _FONTWIDTH, wh \ _FONTHEIGHT
PALETTE 7, 63: COLOR 0, 7: CLS
_FONT font(fontsize%)
_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
        _FONT font(fontsize%)
        fw% = 0: fh% = 0
        DO
            fw% = _FONTWIDTH: fh% = _FONTHEIGHT
            IF fw% <> 0 AND fh% <> 0 THEN EXIT DO
            _DELAY .1
        LOOP
        WIDTH ww / fw%, wh / fh%
        PALETTE 7, 63: COLOR 0, 7: CLS
        _FONT font(fontsize%)
        DO: LOOP UNTIL _SCREENEXISTS: _SCREENMOVE 0, 0
        PRINT "Font size changed to:"; fontsize%, "width ="; _WIDTH
        _KEYCLEAR
    END IF
    oldf% = fontsize%
LOOP

It's like the old invention saying goes, "Necessity is a mother."

Pete
I'm just recommending it. Don't use too much x = _loadfont . Not even if you free him. even if it wouldn't cause a memory leak, it's still very slow because of _printstring. I've experimented with it a lot and I'm bored. I found it best to "install" each letter and as an image in any size. Another advantage. You cannot use _printstring in hardware mode. Text output will be slow. If you include _display and use the font as a hardware image, it will be safer and much faster
Reply


Messages In This Thread
RE: Change font size / Maintain screen size. - by MasterGy - 11-11-2022, 08:12 PM



Users browsing this thread: 2 Guest(s)