Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change font size / Maintain screen size.
#1
This is a simple demo for SCREEN 0, but someone could work up a graphics counterpart easily enough...

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
Reply


Messages In This Thread
Change font size / Maintain screen size. - by Pete - 11-11-2022, 01:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Screen fonts in SCREEN 0 BDS107 14 3,630 07-08-2025, 08:05 PM
Last Post: madscijr
  ASCII font display Helium5793 5 1,251 03-04-2025, 03:50 PM
Last Post: Steffan-68
  A clean font printing SUB I use sometimes. Dav 4 1,277 08-27-2023, 10:16 PM
Last Post: Dav
Lightbulb Fancy font names mnrvovrfc 8 1,692 05-29-2023, 07:15 PM
Last Post: bplus
  wanted: program to process Windows Font files paulel 14 3,083 10-26-2022, 07:29 PM
Last Post: SpriggsySpriggs

Forum Jump:


Users browsing this thread: 1 Guest(s)