Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handle letters dynamically
#5
Hmm, I still can't get it to print when only one text printing job is coded. I included the new .bi file in the code below. Run it and you should see a blank screen. Unremark the second _printstring statement, and it will print the message.

Code: (Select All)
myfont$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf" 'Find Windows Folder Path.

DIM SHARED m_fnt(99, 199), m_trw(999), m_fntset(3), m_lasttext$
sc = _NEWIMAGE(350, 350 / 2, 32): SCREEN sc:
_SCREENMOVE _MIDDLE
_DISPLAYORDER _HARDWARE

'make background
temp = _NEWIMAGE(_WIDTH, _HEIGHT, 32): _DEST temp
FOR x = 0 TO _WIDTH: FOR y = 0 TO _HEIGHT: t = 0: PSET (x, y), _RGB32(255, 255, 255): NEXT y, x
bground = _COPYIMAGE(temp, 33): _FREEIMAGE temp

m_fontsettings "<", ">", 33
m_fontadd 1, myfont$, _RGBA32(0, 0, 0, 190), _RGBA32(255, 255, 255, 0), 0, 400, .97, 1.26

_DEST sc
DO: _LIMIT 30

    _PUTIMAGE , bground

    m_printstring 40, 60, "<fh11><fi1>QB64 Hardware Text", 1, 0

    REM m_printstring_center 300, "<fi1><fh16>", 0, 0 ' Unremark this line to get it to work.

    _DISPLAY
LOOP UNTIL _KEYDOWN(27)


SUB m_fontsettings (a$, b$, x): m_fntset(0) = ASC(a$): m_fntset(1) = ASC(b$): m_fntset(2) = x: END SUB

SUB m_fontadd (i, f$, c AS _INTEGER64, c2 AS _INTEGER64, shmove, fs, xmulti, spfnt)
    m_fnt(i, 0) = fs
    m_fnt(i, 1) = _LOADFONT(f$, fs)
    m_fnt(i, 2) = _RED32(c)
    m_fnt(i, 3) = _GREEN32(c)
    m_fnt(i, 4) = _BLUE32(c)
    m_fnt(i, 5) = _ALPHA32(c)
    m_fnt(i, 6) = xmulti
    m_fnt(i, 7) = 0
    m_fnt(i, 10) = _RED32(c2)
    m_fnt(i, 11) = _GREEN32(c2)
    m_fnt(i, 12) = _BLUE32(c2)
    m_fnt(i, 13) = _ALPHA32(c2)
    m_fnt(i, 14) = shmove
    m_fnt(i, 15) = spfnt
END SUB

SUB m_fontaddpic (i, f$, pic_handle, pic_alpha, pic_multi, c2 AS _INTEGER64, shmove, fs, xmulti, spfnt)
    m_fnt(i, 0) = fs
    m_fnt(i, 1) = _LOADFONT(f$, fs)
    m_fnt(i, 2) = pic_handle
    m_fnt(i, 3) = -1
    m_fnt(i, 4) = pic_alpha
    m_fnt(i, 5) = pic_multi
    m_fnt(i, 6) = xmulti
    m_fnt(i, 7) = 0
    m_fnt(i, 10) = _RED32(c2)
    m_fnt(i, 11) = _GREEN32(c2)
    m_fnt(i, 12) = _BLUE32(c2)
    m_fnt(i, 13) = _ALPHA32(c2)
    m_fnt(i, 14) = shmove
    m_fnt(i, 15) = spfnt
END SUB



FUNCTION m_printwidth (t$): concatenation (t$): printwidth = m_trw(1): END FUNCTION
FUNCTION m_printheight (t$): concatenation (t$): printheight = m_trw(2): END FUNCTION
SUB m_printstring_center (py, t$, r1, r2): concatenation (t$): ps (_WIDTH - m_trw(1)) / 2 + 1, py, r1, r2: END SUB
SUB m_printstring_right (py, t$, marg, r1, r2): concatenation (t$): ps _WIDTH - marg - m_trw(1), py, r1, r2: END SUB
SUB rotate_2d (x, y, ang): x1 = x * COS(ang) - y * SIN(ang): y1 = x * SIN(ang) + y * COS(ang): x = x1: y = y1: END SUB





SUB m_printstring (px, py, t$, r1, r2): m_trw(0) = 0: concatenation (t$): ps px, py, r1, r2: END SUB

SUB ps (sx, sy, r1, r2)
    REDIM r(1), t(4, 1)
    t(4, 0) = sx: t(4, 1) = sy
    r(0) = m_trw(1) / 2 * r1
    r(1) = -m_trw(2) / 2

    FOR t = 0 TO m_trw(0) - 1
        si = 20 + t * 6
        t(0, 0) = m_trw(si + 1): t(0, 1) = m_trw(si + 2): t(1, 0) = m_trw(si + 3): t(1, 1) = m_trw(si + 2)
        t(2, 0) = m_trw(si + 1): t(2, 1) = m_trw(si + 4): t(3, 0) = m_trw(si + 3): t(3, 1) = m_trw(si + 4)

        IF SGN(r2) THEN
            FOR t1 = 0 TO 3: t(t1, 0) = t(t1, 0) - r(0): t(t1, 1) = t(t1, 1) - r(1): rotate_2d t(t1, 0), t(t1, 1), r2
            t(t1, 0) = t(t1, 0) + r(0): t(t1, 1) = t(t1, 1) + r(1): NEXT t1
        END IF

        FOR t1 = 0 TO 7: t2 = INT(t1 * .5): t3 = t1 AND 1: t(t2, t3) = t(t2, t3) + t(4, t3): NEXT t1
        w = _WIDTH(m_trw(si)) - 1: h = _HEIGHT(m_trw(si)) - 1
        _MAPTRIANGLE (0, 0)-(w, 0)-(0, h), m_trw(si) TO(t(0, 0), t(0, 1))-(t(1, 0), t(1, 1))-(t(2, 0), t(2, 1))
        _MAPTRIANGLE (w, h)-(w, 0)-(0, h), m_trw(si) TO(t(3, 0), t(3, 1))-(t(1, 0), t(1, 1))-(t(2, 0), t(2, 1))

    NEXT t
END SUB

SUB concatenation (t$)


    IF t$ = m_lasttext$ THEN EXIT SUB
    m_lasttext$ = t$
    m_trw(0) = 0


    ind = 0: tr_c = 0: f_size = 10
    DO UNTIL ac >= LEN(t$): ac = ac + 1: ac$ = MID$(t$, ac, 1)
        IF ac$ = CHR$(m_fntset(0)) THEN

            vh = INSTR(ac + 1, t$, CHR$(m_fntset(1))): IF vh = 0 THEN PRINT "syntax error in text command": END
            v = VAL(MID$(t$, ac + 3, vh - ac - 3))
            SELECT CASE LCASE$(MID$(t$, ac + 1, 2))
                CASE "fi": ind = v
                CASE "fh": f_size = v
            END SELECT
            ac = vh
        ELSE
            find = -1
            IF SGN(m_fnt(ind, 7)) THEN
                FOR t = 20 TO 20 + m_fnt(ind, 7) * 5
                    IF ASC(ac$) = m_fnt(ind, t) THEN find = t: EXIT FOR
                NEXT t
            END IF

            IF find = -1 THEN
                find = 20 + m_fnt(ind, 7) * 5
                savedest = _DEST
                _FONT m_fnt(ind, 1)
                sh = m_fnt(ind, 14)
                pwac = _PRINTWIDTH(ac$)
                temp2 = _NEWIMAGE(pwac + sh, m_fnt(ind, 0) + sh, 32)

                m_fnt(ind, find + 2) = 1 / (m_fnt(ind, 0) + sh) * (pwac + sh) * m_fnt(ind, 6) 'accel
                m_fnt(ind, find + 3) = 1 / m_fnt(ind, 0) * (m_fnt(ind, 0) + sh) * 1.2 'accel
                m_fnt(ind, find + 4) = 1 / m_fnt(ind, 0) * pwac * m_fnt(ind, 6) * m_fnt(ind, 15) 'accel

                _DEST temp2: CLS , 0
                _FONT m_fnt(ind, 1)
                COLOR _RGBA32(m_fnt(ind, 10), m_fnt(ind, 11), m_fnt(ind, 12), m_fnt(ind, 13)), 0
                _PRINTSTRING (sh, sh), ac$

                IF m_fnt(ind, 3) = -1 THEN
                    temp11 = _NEWIMAGE(pwac + sh, m_fnt(ind, 0) + sh, 32)
                    _DEST temp11

                    sy = m_fnt(ind, 5) * _WIDTH(m_fnt(ind, 2))
                    sx = sy / _HEIGHT * _WIDTH

                    _MAPTRIANGLE (0, 0)-(sx, 0)-(0, sy), m_fnt(ind, 2) TO(0, 0)-(_WIDTH, 0)-(0, _HEIGHT)
                    _MAPTRIANGLE (sx, sy)-(sx, 0)-(0, sy), m_fnt(ind, 2) TO(_WIDTH, _HEIGHT)-(_WIDTH, 0)-(0, _HEIGHT)

                    _SETALPHA m_fnt(ind, 4)
                    temp10 = _NEWIMAGE(pwac + sh, m_fnt(ind, 0) + sh, 32)

                    _DEST temp10
                    CLS , _RGB32(0, 0, 0)
                    _FONT m_fnt(ind, 1)
                    COLOR _RGB32(255, 255, 255)
                    _PRINTSTRING (0, 0), ac$
                    _SETALPHA 0, _RGB32(255, 255, 255) TO _RGB32(1, 1, 1)
                    _DEST temp11
                    _PUTIMAGE , temp10
                    _CLEARCOLOR _RGB32(0, 0, 0)
                    _DEST temp2

                    _PUTIMAGE , temp11
                    _FREEIMAGE temp10
                    _FREEIMAGE temp11
                ELSE
                    COLOR _RGB32(m_fnt(ind, 2), m_fnt(ind, 3), m_fnt(ind, 4)), 0
                    _PRINTSTRING (0, 0), ac$
                    _SETALPHA m_fnt(ind, 5), _RGB32(m_fnt(ind, 2), m_fnt(ind, 3), m_fnt(ind, 4))
                END IF

                m_fnt(ind, find + 1) = _COPYIMAGE(temp2, m_fntset(2))
                _FREEIMAGE temp2
                m_fnt(ind, find) = ASC(ac$)
                _DEST savedest
                m_fnt(ind, 7) = m_fnt(ind, 7) + 1

            END IF

            si = m_trw(0) * 6 + 20
            m_trw(si) = m_fnt(ind, find + 1) 'text
            m_trw(si + 1) = actual_x
            m_trw(si + 2) = -f_size
            m_trw(si + 3) = m_trw(si + 1) + f_size * m_fnt(ind, find + 2)
            m_trw(si + 4) = m_trw(si + 2) + f_size * m_fnt(ind, find + 3)
            m_trw(si + 5) = ac$ = " "
            actual_x = m_trw(si + 1) + f_size * m_fnt(ind, find + 4)
            m_trw(0) = m_trw(0) + 1

        END IF
        IF f_size > f_sizemax THEN f_sizemax = f_size
    LOOP
    m_trw(1) = actual_x
    m_trw(2) = f_sizemax

END SUB

I adjusted the 1500 to 400. I was playing with the values quite a bit to get a feel for the range, which is quite extensive.

Pete
Reply


Messages In This Thread
Handle letters dynamically - by MasterGy - 03-05-2024, 07:59 PM
RE: Handle letters dynamically - by Pete - 03-05-2024, 08:21 PM
RE: Handle letters dynamically - by Pete - 03-08-2024, 10:41 PM
RE: Handle letters dynamically - by MasterGy - 03-09-2024, 06:35 PM
RE: Handle letters dynamically - by Pete - 03-10-2024, 02:17 AM
RE: Handle letters dynamically - by MasterGy - 03-10-2024, 06:12 PM
RE: Handle letters dynamically - by Pete - 03-10-2024, 07:18 PM



Users browsing this thread: 1 Guest(s)