Touchscreen Interface

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

Touchscreen Interface

Post by mrminecrafttnt »

I worte an very simle but good working touchscreen interface.
Have fun!

Code: Select all

type button
    x1 as integer
    x2 as integer
    y1 as integer
    y2 as integer
    col as integer
    declare sub d(t as string)
    declare function c(x as integer,y as integer) as integer
end type

sub button.d(t as string)
    dim as integer px,py
    line(x1,y1)-(x2,y2),col,bf
    px=((x1+x2)/8)/2
    py=((y1+y2)/8)/2
    locate py,px
    color 15,col
    print t
end sub

function button.c(x as integer,y as integer) as integer
    if (x>=x1) and (x<=x2) and (y>=y1) and (y<=y2) then
        return 1
    else
        return 0
    end if
end function

screenres 640,480
dim as integer mx,my,m1,m2
dim as integer s = 48
dim as button b(10)
dim as integer i=1
for by as integer = 0 to 2
    for bx as integer = 0 to 2
        with b(i)
        .x1 = bx*s
        .y1 = by*s
        .x2 = .x1+s
        .y2 = .y1+s
        .col = 1
        .d str(I)
        end with
        i+=1
next
next


dim as string x
do
    getmouse mx,my,m1,m2
    if m2 = 1 then
        for i as integer = 1 to 9
            if b(i).c(mx,my) = 1 then
                x+=str(i)
                locate 20,1
                print x
                do
                    getmouse mx,my,m1,m2
                    sleep 1
                loop until m2=0
                exit for
            end if
        next
    end if
    loop until inkey = chr(27)
Post Reply