Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FB GfxInput and GfxPrint
#1
Code:
TYPE fb_FontType
    h AS INTEGER
    data AS UBYTE PTR
END TYPE

'Unrem the font type you wish to use
EXTERN fb_FontData ALIAS "fb_font_8x8" AS fb_FontType
'EXTERN fb_FontData ALIAS "fb_font_8x14" AS fb_FontType
'EXTERN fb_FontData ALIAS "fb_font_8x16" AS fb_FontType

'allowed = which chars to allow:
'1 = 0-9 and -
'2 = a-z and [Space]
'4 = A-Z and [Space]
'8 = , . - _ : ; ! " # % & / \ ( ) = ? + * < > [Space] '
'16 = § ½ | @ £ $ € { [ ] } ´ `^ ¨ ~
'31 = all

'enter = escape char, the key to press to exit the input routine
'            defaults to enter/return
function GfxInput(text as string, defaultval as string, xl as integer, yl as integer, col as integer, allowed as uinteger = 31, enter = 13 ) as string
    dim smallbuff(0, 130) as uinteger
    if allowed and 1 then alist$ = alist$ + "0123456789-"
    if allowed and 2 then alist$ = alist$ + "abcdefghijklmnopqrstuvwxyz "
    if allowed and 4 then alist$ = alist$ + "ABCDEFGHIJKLMNOPQRSTUVWXYZ "
    if allowed and 8 then alist$ = alist$ + ",.-_:;!"+chr$(34)+"#%&/\()=?+*<> '"
    if allowed and 16 then alist$ = alist$ + "§½|@£$€{[]}´`^¨~"
    cx = len(text) * 8
    GfxPrint text, xl, yl, col
    dx = cx
    if defaultval <> "" then
        nt$ = defaultval
        redim smallbuff(len(nt$)-1, 130) as uinteger
        for a = 1 to len(nt$)
            get (cx+xl, yl)-(cx+xl+8, yl+fb_FontData.h), smallbuff(a-1, 0)
            cx=cx+8
        next
    end if
    GfxPrint nt$, dx+xl, yl, col
    do
        k$ = inkey$
        if instr(alist$, k$) then
            nt$ = nt$ + k$
            redim preserve smallbuff(len(nt$)-1, 130) as uinteger
            get (cx+xl, yl)-(cx+xl+8, yl+fb_FontData.h), smallbuff(len(nt$)-1, 0)
            GfxPrint k$, xl+cx, yl, col
            cx=cx+8
        else
            if k$ = chr$(8) and len(nt$) > 0 then
                nt$ = left$(nt$, len(nt$)-1)
                cx=cx-8
                put (cx+xl, yl), smallbuff(len(nt$), 0), pset
            end if
        end if
    loop until k$ = chr$(enter)
    do: loop until inkey$ =""
    GfxInput = nt$
end function

SUB GfxPrint( BYREF text AS STRING, _
    BYVAL x AS INTEGER, BYVAL y AS INTEGER, _
    BYVAL col AS INTEGER, BYVAL buffer AS ANY PTR = 0 )
    DIM row AS INTEGER, i AS INTEGER
    DIM bits AS UBYTE PTR
    FOR i = 1 TO LEN(text)
        bits = fb_FontData.data + (ASC(MID$(text, i, 1)) * fb_FontData.h)
        FOR row = 0 TO fb_FontData.h-1
            IF (buffer) THEN
                LINE buffer, (x + 7, y + row)-(x, y + row), col,,*bits SHL 8
            ELSE
                LINE (x + 7, y + row)-(x, y + row), col,, *bits SHL 8
            END IF
            bits += 1
        NEXT row
        x += 8
    NEXT i
END SUB
Reply
#2
Simple example:
Code:
Screen 18, 32
GfxPrint "Hello, world!", 0, 0, RGB(255, 0, 128)

t$ = GfxInput("Whats your name?", "Anonymous", 100, 100, RGB(0,64,255), 2+4)

t2$ = GfxInput("Please confirm this is correct: ", t$, 100, 120, RGB(0, 64, 255), 2+4)

GfxInput does not erase the background, not very visible here, try it on a background, it will be preserved when you erase a char.
Reply
#3
havent tried it but the gfxinput is a really good idea =)
Reply
#4
Sound's like a pretty good concept. I'll try it.

I see the font routine is made from LINE statements...bleh.
·~¹'°¨°'¹i|¡~æthérFòx~¡|i¹'°¨°'¹~·-
avinash.vora - http://www.avinashv.net
Reply
#5
Quote:I see the font routine is made from LINE statements...bleh.

That's ancient QB lore...
Antoni
Reply
#6
I didnt make the GfxPrint routine, it's in docs\gfxlib.txt, in one of the appendixes.

I've already found a few things in GfxInput that I want to change.. among others, the ability to pass your own AllowedChars list..
Reply
#7
Quote:Sound's like a pretty good concept. I'll try it.

I see the font routine is made from LINE statements...bleh.


it uses the lines to draw out the bits from each character, one row at a time... not like crappy one line chars =P
Reply
#8
Nice routine! Thanks!

With FB 0.13b, I had to change the first line of GfxInput to:

Code:
redim smallbuff(0, 130) as uinteger

It seems that DIM creates a static array which cannot be redimensioned.

Also, place GfxPrint before GfxInput if you don't use DECLARE.

Also, would it be possible to show a cursor during input?
ean Debord
----------------
Math library for FreeBasic:
http://www.unilim.fr/pages_perso/jean.de...fbmath.zip
Reply
#9
dim works fine, unless you've dim shared smallbuff before..

I'll add a cursor to the next version..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)