You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!

Not sure the scaling works on all screens... right now only works in portrait mode.

Code:

! inputint.bas graphical keypad for entering positive integers

! numeric keypad entry -- works similar to INKEY$ ! returns '@' if no keypress ! returns 'cancel' if user cancels FN.DEF grkey$(pad[])

GR.SCREEN w, h sq=w/20

found=0 FOR i=1 TO 13 GR.GET.POSITION pad[i],sx,sy GR.BOUNDED.TOUCH touched, sx-sq*2, sy-sq*2, sx+sq*2, sy+sq IF touched found=1 F_N.BREAK ENDIF NEXT I IF !found THEN FN.RTN "@" IF i <10 THEN FN.RTN INT$(i) IF i =10 THEN FN.RTN "0" IF i =11 THEN FN.RTN "del" IF i =12 THEN FN.RTN "ent" IF i=13 POPUP "canceled",0,0,0 FN.RTN "cancel" ENDIF FN.END

! display numeric keypad and put gr object labels in pad[] array FN.DEF makenums(pad[])

GR.SCREEN w, h sq=h/32 GR.TEXT.SIZE h/16 GR.TEXT.ALIGN 2

FOR i=1 TO 12 GR.COLOR 255,0,255,0,1 row=FLOOR((i-1)/3) col=(i-1)-ROW*3 IF i <10 THEN k$=INT$(i) IF i=10 THEN k$="0" IF i=11 THEN k$ ="del" IF i=12 THEN k$ ="ok" GR.TEXT.DRAW pad[i],col*w/4+w/4,row*h/8+h/2,k$ GR.GET.POSITION pad[i],sx,sy GR.COLOR 255,0,255,0,0

GR.RECT b, sx-sq*2, sy-sq*2, sx+sq*2, sy+sq

NEXT I GR.TEXT.SIZE h/20 GR.TEXT.ALIGN 2 GR.COLOR 255,0,255,0,1 GR.TEXT.DRAW pad[13],w/8,h-10,"cancel" GR.RENDER FN.END

! input positive integer with onscreen keypad using prompts p$ and a$ ! with default value of d ! returns -1 if user cancels input ! NOTE: graphics must be opened and closed by calling function

FN.DEF inputintg(p$,a$,d) IF d<0 THEN d=0 GR.CLS GR.ORIENTATION 1 PAUSE 1000

GR.TEXT.ALIGN 2 GR.SET.STROKE 1 DIM pad[13] GR.SCREEN w, h makenums(&pad[]) GR.TEXT.SIZE h/16 GR.TEXT.ALIGN 2 GR.SET.STROKE 1 GR.TEXT.DRAW txt2,w/2,h/10,p$ GR.TEXT.DRAW txt2,w/2,h/6+30,a$ GR.RENDER n=d KB.HIDE GR.COLOR 255,255,255,0,1 GR.TEXT.ALIGN 2 GR.TEXT.SIZE h/12 GR.TEXT.DRAW txt1 ,w/2,h/3,INT$(n) GR.RENDER DO k$=grKEY$(pad[]) UNTIL (k$<>"@") IF k$="ent" FN.RTN n ENDIF n=0 DO IF IS_IN(k$, "0123456789")THEN n=n*10+VAL(k$) IF k$="cancel" THEN D_U.BREAK IF k$="del" THEN n=FLOOR(n/10) GR.MODIFY txt1, "text", INT$(n) GR.RENDER DO GR.TOUCH touched,x,y UNTIL !touched DO k$=grKEY$(pad[]) UNTIL k$<>"@" UNTIL k$="ent" IF k$="cancel" THEN n=-1 FN.RTN n FN.END

! open and close graphics and get integer from user FN.DEF inputint(p$,a$,d) GR.OPEN 255,0,0,0 x=inputintg(p$,a$,d) GR.CLOSE FN.RTN x FN.END

FN.DEF testinpint() GR.OPEN 255,0,0,0 DO x=inputintg("cals for","banana",110) POPUP INT$(x),0,0,0 PAUSE 3000 UNTIL x<0 GR.CLOSE FN.END

At any rate this one also has positive/negative numbers

Code:

! inputint.bas graphical keypad for entering positive integers

! numeric keypad entry -- works similar to INKEY$ ! returns '@' if no keypress ! returns 'cancel' if user cancels FN.DEF grkey$(pad[])

GR.SCREEN w, h sq=w/20

found=0 FOR i=1 TO 14 GR.GET.POSITION pad[i],sx,sy GR.BOUNDED.TOUCH touched, sx-sq*2, sy-sq*2, sx+sq*2, sy+sq IF touched let found=1 F_N.BREAK ENDIF NEXT I IF !found THEN FN.RTN "@" IF i <10 THEN FN.RTN INT$(i) IF i =10 THEN FN.RTN "0" IF i =11 THEN FN.RTN "del" IF i =12 THEN FN.RTN "ent" IF i=13 POPUP "canceled" FN.RTN "cancel" ENDIF if i=14 then fn.rtn "-" FN.END

! display numeric keypad and put gr object labels in pad[] array FN.DEF makenums(pad[])

GR.SCREEN w, h sq=h/32 GR.TEXT.SIZE h/16 GR.TEXT.ALIGN 2

FOR i=1 TO 12 GR.COLOR 255,0,255,0,1 row=FLOOR((i-1)/3) col=(i-1)-ROW*3 IF i <10 THEN k$=INT$(i) IF i=10 THEN k$="0" IF i=11 THEN k$ ="del" IF i=12 THEN k$ ="ok" GR.TEXT.DRAW pad[i],col*w/4+w/4,row*h/8+h/2,k$ GR.GET.POSITION pad[i],sx,sy GR.COLOR 255,0,255,0,0

GR.RECT b, sx-sq*2, sy-sq*2, sx+sq*2, sy+sq

NEXT I GR.TEXT.SIZE h/20 GR.TEXT.ALIGN 2 GR.COLOR 255,0,255,0,1 GR.TEXT.DRAW pad[13],w/8,h-10,"cancel" gr.text.draw pad[14],7*w/8,h-10,"+/-" GR.RENDER FN.END

! input integer with onscreen keypad using prompts p$ and a$ ! with default value of d ! returns -99999 if user cancels input ! NOTE: graphics must be opened and closed by calling function

FN.DEF inputintg(p$,a$,d)

GR.CLS pause 1000 GR.ORIENTATION 1

GR.TEXT.ALIGN 2 GR.SET.STROKE 1 DIM pad[14] GR.SCREEN w, h makenums(&pad[]) GR.TEXT.SIZE h/16 GR.TEXT.ALIGN 2 GR.SET.STROKE 1 GR.TEXT.DRAW txt2,w/2,h/10,p$ GR.TEXT.DRAW txt2,w/2,h/6+30,a$ GR.RENDER n=d KB.HIDE GR.COLOR 255,255,255,0,1 GR.TEXT.ALIGN 2 GR.TEXT.SIZE h/12 GR.TEXT.DRAW txt1 ,w/2,h/3,INT$(n) GR.RENDER tmout=clock() khit=0 DO let k$=grKEY$(pad[]) pause 25 if k$="@" elapsed=clock()-tmout else khit=1 endif UNTIL (k$<>"@") | (elapsed>10000 & !khit) if (elapsed>10000 & !khit) fn.rtn d endif IF k$="ent" FN.RTN n ENDIF n=0 DO IF abs(n)<=999 & IS_IN(k$, "0123456789") THEN let n=n*10+VAL(k$) IF k$="cancel" THEN D_U.BREAK if k$="-" then n=-n IF k$="del" THEN n=FLOOR(n/10) GR.MODIFY txt1, "text", INT$(n) GR.RENDER DO GR.TOUCH touched,x,y UNTIL !touched DO let k$=grKEY$(pad[]) UNTIL k$<>"@" UNTIL k$="ent" IF k$="cancel" THEN n=-99999 FN.RTN n FN.END

! open and close graphics and get integer from user FN.DEF inputint(p$,a$,d) GR.OPEN 255,0,0,0 x=inputintg(p$,a$,d) GR.CLOSE FN.RTN x FN.END

The main reason I wrote the routine was that I wanted something that easily displayed a default value which could be changed in one keystroke and didn't use the ugly D-Pad to enter numbers in. Plus the green color looks nice!

I should probably just use a flag to signal a cancel... I am just too lazy I guess!

The main reason I wrote the routine was that I wanted something that easily displayed a default value which could be changed in one keystroke and didn't use the ugly D-Pad to enter numbers in. Plus the green color looks nice!

I should probably just use a flag to signal a cancel... I am just too lazy I guess!

is it possible to touch the screen more than 2x ? i want to make a piano ...

I am not really sure how multitouch works with the bounded GR.TOUCH... you might be able to mod the functions to check every single key and assign an array rather than return a single character.

Joined: Wed Oct 03, 2012 9:53 am Posts: 2796 Location: Colorado, U.S.

When you touch the screen, that touch is assigned an ID. Until you lift that touch, any movement triggers a motion event that has that same ID. If you have more than two touches active, BASIC! watches the first two and ignores the rest. I don't know why that is, I have never investigated it.

Also, I don't know how the IDs are assigned if you lift touches in a different order than the original touch order. Say you are touching three places at once. You lift the second touch (one BASIC! is watching) and then touch a fourth place, still holding touches one and three. Does the fourth touch get the same ID as the second touch, or does it get a new ID different from all the previous three?

This is relevant to cterp's comment, because GR.Touch and GR.Bounded.Touch can only look at touch events that BASIC! tracks -- the first two.

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum