List_box object (2nd version)

Post Reply
Henko
Posts: 797
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

List_box object (2nd version)

Post by Henko »

option base 1
dim cities$(26)
for i=1 to 26
  read cities$(i)
  next i
data "Amsterdam","Bangkok","Caracas","Dublin","Edinburgh"
data "Fremont","Groningen","Helsinki","Inverness","Jakarta"
data "Kano","London","Moskow","Nairobi","Osaka"
data "Proletarskiy","Quatar","Riad","Sydney","Tunis"
data "Ulm","Vancouver","Warschau","Xnotfound","Yosemite"
data "Zaragoza"
graphics
draw color 0,0,0
fill color .8,.8,.8

again:
cls
draw text "select a city from the listbox" at 20,20
draw text "by touching the number button besides it." at 20,50
draw text "Press the Done button to quit." at 20,80
num=sel_box ("Cities table",cities$,26,12,100,150,0)
if (num) then
  draw text "You selected " & cities$(num) at 100,550
  else 
  draw text "You didn't select a city " at 100,550
  end if
button "ag" title "again ?" at 220,600 size 120,30
test:
if button_pressed("ag") then
  button "ag" delete
  goto again
  end if
goto test

end

def sel_box (titel$,name$(),max,nr,xtop,ytop,breed)
dh=25
selected=0
if breed=0 then
  for i=1 to max
    l=len(name$(i))
    if breed<l then breed=l
    next i
  breed=12*breed+104
  end if
xbot=xtop+breed
ybot=ytop+(nr+1)*dh+40
w_open (titel$,xtop,ytop,xbot,ybot)
button "ok" title "done ?" at xbot-130,ybot-35 size 120,30
xs=xtop+50
ys=ytop
top=1
goto sel3
sel1:
graphics lock
fill rect xs,ys+30 to xs+breed-55,ybot-5
for j=top to bot
  k=j-top+1
  b$="s" & j
  button b$ title "" & j at xbot-50,ys+2+25*k size 40,20
  if j=selected then draw color .8,0,0 else draw color 0,0,0
  draw text name$(j) at xs,ys+25*k
next j
graphics unlock
sel2:
for j=top to bot
  b$="s" & j
  if button_pressed(b$) then
    if selected=j then flag=1 else flag=0
    sel_oud=selected
    selected=j
    draw color .8,0,0
    draw text name$(j) at xs,ys+25*(j-top+1)
    draw color 0,0,0
    if sel_oud>0 then 
      k=sel_oud-top+1
      if k>0 and k<=nr then draw text name$(sel_oud) at xs,ys+25*k
    end if
  end if
next j
if button_pressed("down") then
  bot=bot+nr
  if bot>=max then
    bot=max
    button "down" delete
  end if
  top=bot-nr+1
  if top<=1 then
    top=1
    button "up" delete
  else
    button "up" title "^" at xs-40,ys+40 size 30,80
  end if
  goto sel1
end if
if button_pressed("up") then
  top=top-nr
  if top<=1 then
    top=1
    button "up" delete
  end if
sel3:
  bot=top+nr-1
  if bot>=max then
    bot=max
    button "down" delete
  else
    button "down" title "v" at xs-40,ybot-90 size 30,80
  end if
  goto sel1
end if
if button_pressed("ok") then
  button "ok" delete
  button "up" delete
  button "down" delete
  for j=1 to max
    b$="s" & j
    button b$ delete
  next j
  fill rect xtop-2,ytop-2 to xbot+2,ybot+2
  if flag=1 then selected=0
  sel_box=selected
  return
endif
goto sel2
end def

def w_open (title$,xtop,ytop,xbot,ybot)
r=10
draw color 0,0,0
draw size 4
draw circle xtop,ytop to xtop+20,ytop+20
draw circle xbot-20,ytop to xbot,ytop+20
draw circle xtop,ybot-20 to xtop+20,ybot
draw circle xbot-20,ybot-20 to xbot,ybot
draw line xtop+r,ytop to xbot-r,ytop
draw line xtop+r,ybot to xbot-r,ybot
draw line xtop,ytop+r to xtop,ybot-r
draw line xbot,ytop+r to xbot,ybot-r
fill rect xtop+r,ytop+2 to xbot-r,ybot-2
fill rect xtop+2,ytop+r to xbot-2,ybot-r
if title$<>"" then
  l=(xbot-xtop-12*len(title$))/2
  draw line xtop,ytop+24 to xbot,ytop+24
  draw color 0,0,1
  draw text title$ at xtop+l,ytop-2
  draw color 0,0,0
end if
end def

def cls()
fill rect 0,0 to screen_width(),screen_height()
end def

Post Reply