It is currently Wed Apr 26, 2017 8:14 pm



Welcome
Welcome to rfobasic

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.!


Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Integer keypad
Unread postPosted: Sun Sep 20, 2015 12:46 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 421
onscreen graphical keypad for entering integers

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

testinpint()


Top
 Profile  
 
 Post subject: Re: Integer keypad
Unread postPosted: Tue Oct 20, 2015 4:21 am 
Offline
User avatar

Joined: Thu Jan 08, 2015 11:28 am
Posts: 1088
Location: .NET
works pretty good, though there's a hiccup when it refreshes!


Attachments:
Screenshot_2015-10-20-14-19-59.png
Screenshot_2015-10-20-14-19-59.png [ 7.37 KiB | Viewed 1381 times ]

_________________
https://github.com/evolbug
http://toobasic.jimdo.com
Top
 Profile  
 
 Post subject: Re: Integer keypad
Unread postPosted: Thu Oct 22, 2015 6:22 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 421
Not sure if I fixed it since I posted:

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

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


Top
 Profile  
 
 Post subject: Re: Integer keypad
Unread postPosted: Thu Oct 22, 2015 6:28 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 421
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!


Top
 Profile  
 
 Post subject: Re: Integer keypad
Unread postPosted: Tue Nov 17, 2015 1:41 pm 
Offline

Joined: Fri Oct 30, 2015 1:59 am
Posts: 86
cterp wrote:
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 ...


Top
 Profile  
 
 Post subject: Re: Integer keypad
Unread postPosted: Tue Nov 17, 2015 1:54 pm 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5485
Location: Paris, France
Rendomizer, please ask your questions only one time. You wrote the exact same question 3 times in 3 different places, it may be considered spam.

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: Integer keypad
Unread postPosted: Wed Nov 18, 2015 6:06 am 
Offline

Joined: Fri Oct 30, 2015 1:59 am
Posts: 86
ok excuse me !


Top
 Profile  
 
 Post subject: Re: Integer keypad
Unread postPosted: Thu Nov 19, 2015 7:17 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 421
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.


Top
 Profile  
 
 Post subject: Re: Integer keypad
Unread postPosted: Sat Nov 21, 2015 8:46 am 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2795
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.

- Marc


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: No registered users and 0 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

Search for:
Jump to:  
suspicion-preferred