Try this.
1) Put the variables
dim as integer mousex,mousey,mousebutton,mouse
at the beginning of the sub so they are global to the goings on.
2) Just before leaving the sub, put
leftmousebuttonpressed=mousebutton
Code: Select all
#include "fbgfx.bi"
Using FB
dim shared as ubyte numofshowicon,leftmousebuttonpressed=0,arraystart,canscrollmenu
dim shared as any ptr whitecircle,leftarrowspr(2),rightarrowspr(2)
type icons
as ushort xplace,yplace
as ubyte exists,pressed
as any ptr itssprite
end type
dim shared numoficons as ubyte=0
redim shared showicons(numoficons) as icons
redim shared scrollarrows(2) as icons
dim shared iconarray(9) as any ptr
screenres 640,480,32
function wcr(n as ubyte) as any ptr
whitecircle=imagecreate(64,64)
circle whitecircle,(32,32),28,Color RGB(0, 0, 0)
draw string whitecircle,(1,1),str(n)
return whitecircle
end function
leftarrowspr(0)=imagecreate(64,64)
circle leftarrowspr(0),(32,32),32,Color RGB(255, 0, 0)
draw string leftarrowspr(0),(1,1),"<-"
leftarrowspr(1)=imagecreate(64,64)
circle leftarrowspr(1),(32,32),32,Color RGB(0, 0, 255)
draw string leftarrowspr(1),(1,1),"<-"
rightarrowspr(0)=imagecreate(64,64)
circle rightarrowspr(0),(32,32),32,Color RGB(255, 0, 0)
draw string rightarrowspr(0),(1,1),"->"
rightarrowspr(1)=imagecreate(64,64)
circle rightarrowspr(1),(32,32),32,Color RGB(0, 0, 255)
draw string rightarrowspr(1),(1,1),"->"
function min(num1 as double, num2 as double) as double
if num1<num2 then
return num1
else
return num2
end if
end function
sub showtheicons()
dim as integer mousex,mousey,mousebutton,mouse
for i as ubyte=0 to 1
if scrollarrows(i).exists=1 then
' dim as integer mousex,mousey,mousebutton,mouse
dim as any ptr scrarrsprite=scrollarrows(i).itssprite
mouse=getmouse(mousex,mousey,,mousebutton)
if mouse=0 then
if (mousebutton and 1) then
if mousex>=scrollarrows(i).xplace and mousex<=scrollarrows(i).xplace+64 and mousey>=scrollarrows(i).yplace and mousey<=scrollarrows(i).yplace+64 then
select case scrollarrows(i).itssprite
case leftarrowspr(0)
scrarrsprite=leftarrowspr(1)
case rightarrowspr(0)
scrarrsprite=rightarrowspr(1)
end select
leftmousebuttonpressed=1
else
select case scrollarrows(i).itssprite
case leftarrowspr(1)
scrarrsprite=leftarrowspr(0)
case rightarrowspr(1)
scrarrsprite=rightarrowspr(0)
end select
'leftmousebuttonpressed=0
end if
elseif leftmousebuttonpressed=1 and mousex>=scrollarrows(i).xplace and mousex<=scrollarrows(i).xplace+64 and mousey>=scrollarrows(i).yplace and mousey<=scrollarrows(i).yplace+64 then
if i=0 then
if arraystart>0 and canscrollmenu=0 then
arraystart-=1
for j as ubyte=0 to numofshowicon-1
if showicons(j).exists=1 then showicons(j).itssprite=iconarray(arraystart+j)
next j
canscrollmenu=10
end if
scrarrsprite=leftarrowspr(0)
else
if arraystart+(numofshowicon-1)<numoficons-1 and canscrollmenu=0 then
arraystart+=1
for j as ubyte=0 to numofshowicon-1
if showicons(j).exists=1 then showicons(j).itssprite=iconarray(arraystart+j)
next j
canscrollmenu=10
end if
scrarrsprite=rightarrowspr(0)
end if
'leftmousebuttonpressed=0
end if
end if
put (scrollarrows(i).xplace, scrollarrows(i).yplace),scrarrsprite,pset
end if
next i
for i as ubyte=0 to min(2,numoficons-1)
if showicons(i).exists=1 then
put (showicons(i).xplace, showicons(i).yplace),showicons(i).itssprite,pset
end if
next i
leftmousebuttonpressed=mousebutton
end sub
iconarray(numoficons)=wcr(numoficons) : numoficons+=1
iconarray(numoficons)=wcr(numoficons) : numoficons+=1
iconarray(numoficons)=wcr(numoficons) : numoficons+=1
iconarray(numoficons)=wcr(numoficons) : numoficons+=1
iconarray(numoficons)=wcr(numoficons) : numoficons+=1
iconarray(numoficons)=wcr(numoficons) : numoficons+=1
iconarray(numoficons)=wcr(numoficons) : numoficons+=1
iconarray(numoficons)=wcr(numoficons) : numoficons+=1
iconarray(numoficons)=wcr(numoficons) : numoficons+=1
dim as ushort xh=4
redim preserve scrollarrows(0)
scrollarrows(0).exists=1
scrollarrows(0).xplace=xh : xh+=64 : scrollarrows(0).yplace=40
scrollarrows(0).itssprite=leftarrowspr(0)
numofshowicon=0 : arraystart=0
for i as ubyte=0 to min(2,numoficons-1)
redim preserve showicons(i)
showicons(i).exists=1 : numofshowicon+=1
showicons(i).xplace=xh : xh+=64 : showicons(i).yplace=40
showicons(i).itssprite=iconarray(i) : showicons(i).pressed=0
next i
redim preserve scrollarrows(1)
scrollarrows(1).exists=1
scrollarrows(1).xplace=xh : scrollarrows(1).yplace=40
scrollarrows(1).itssprite=rightarrowspr(0)
do
screenlock
cls
showtheicons()
if canscrollmenu>0 then canscrollmenu-=1
screenunlock
sleep 50
loop until multikey(sc_q)
imagedestroy whitecircle
for i as ubyte=0 to 1
imagedestroy leftarrowspr(i)
imagedestroy rightarrowspr(i)
next i
This replicates basiccoder2's code behaviour.