Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Yellow notebook paper background (scales to fit font setting)
#1
A friend asked me to help him out how making a notebook paper screen that would work for various screen sizes and font size.  He was trying to use an image&, but couldn't get the LOCATE/PRINT to fit in the paper lines.  I suggested this way to him, using _FONTWIDTH/_FONTHEIGHT to scale drawing text LINEs instead. Thought I'd share it here because it may be something others may want.  I commented this code more than usual to help my friend learn.  This SUB draws a yellow legal pad paper, but you can make other papers styles fairly easy.

- Dav

Code: (Select All)
'yellowpaper.bas
'by Dav, OCT/2023
SCREEN _NEWIMAGE(800, 600, 32)
'Here's where you can load another font you want to use....
'fnt& = _LOADFONT("lucon.ttf", 24, "monospace")
'_FONT fnt&
'Call the SUB, with your title$ message
YellowPaper "John's QB64-PE Code Notebook"
'You need to call below so PRINTing text doesn't destroy background.
_PRINTMODE _KEEPBACKGROUND
'=== show some sample information....
COLOR _RGB(64, 64, 64)
FOR y = 5 TO 16
    LOCATE y, 2: PRINT DATE$;
    LOCATE , 16: PRINT "Random Data ="; RND; RN;
NEXT: PRINT
'Use location 2 to print in left column, 16 for printing in the text lines.
PRINT
LOCATE , 16: PRINT "This is another line."
PRINT
LOCATE , 2: PRINT "Tuesday:"
LOCATE , 16: PRINT "Dear diary, today I wrote this...."
SLEEP
SUB YellowPaper (title$)
    'This SUB draws yellow notebook paper, scaled to fit current font settings.
    'It also prints and centers title$ in the top title area.
    fw = _FONTWIDTH: fh = _FONTHEIGHT 'get current font width/height settings
    '(the fw & fh we will use to calculate LINE drawing so they line up right with PRINT)
    CLS , _RGB(255, 245, 154) 'clear screen to yellow color
    'draw the two vertical brown lines, to make column/text area
    LINE (fw * 12, 0)-(fw * 12, _HEIGHT), _RGB(205, 185, 98)
    LINE (fw * 12.5, 0)-(fw * 12.5, _HEIGHT), _RGB(205, 185, 98)
    'draw the text lines to bottom of screen
    FOR y = fh - 1 TO _HEIGHT STEP fh
        LINE (0, y)-(_WIDTH, y), _RGB(152, 160, 74)
    NEXT
    'draw top brown tile area (remove this if not wanted)
    LINE (0, 0)-(_WIDTH, fh * 3), _RGB(102, 19, 15), BF '<< enough for 3 lines
    COLOR _RGB(255, 255, 0)
    'Next we print title$, centering the text in the top area
    'For this we need to calcuale how many letters fit on one line, INT(_WIDTH/fw) / 2.
    'I divided that by 2 to find the center spot on the line.
    'So, subtract half of the title$ length from that spot to make it centered nice.
    LOCATE 2, INT((_WIDTH / fw) / 2) - INT(LEN(title$) / 2)
    'Now we PRINT the text, but we need to print a certain way so the background isn't
    'messed up.  We will use _PRINTMODE _KEEPBACKGROUND to do that.
    'First, let's save the current printmode so we can restore that when SUB is done.
    pmode = _PRINTMODE
    _PRINTMODE _KEEPBACKGROUND
    PRINT title$; 'finally, PRINT the title$
    'All done, so let's restore previous printmode setting
    IF pmode = 1 THEN _PRINTMODE _KEEPBACKGROUND
    IF pmode = 2 THEN _PRINTMODE _ONLYBACKGROUND
    IF pmode = 3 THEN _PRINTMODE _FILLBACKGROUND
END SUB

Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
Yellow notebook paper background (scales to fit font setting) - by Dav - 10-11-2023, 12:55 PM



Users browsing this thread: 1 Guest(s)