Posted: 3rd Mar 2003 16:04
quite worthless really, maybe some n00b needs it...

remstart

The button function is called with parameters for the buttons position (x,y) and text.
It will return 1 if the button is leftclicked, and 2 if rightclicked.

remend

rem Button function
function button(x,y,t$)

rem Width and height of button
xx=x+text width(t$)+2
yy=y+text height(t$)+2

rem If mousecursor is over button
if 2dcollide(mousex(),mousey(),x,y,xx,yy)

rem If the button is clicked
if mouseclick()>0

rem Set value of mouseclick (leftclick/rightclick)
click=mouseclick()

rem Draw Clicked-button
ink rgb(50,50,50),0
box x,y,xx,yy
ink rgb(255,255,255),0
text x+1,y+1,t$

rem Wait until the mousebutton is released
repeat : until mouseclick()=0

rem Return mouselick-value
exitfunction click

else

rem Draw MouseOver-button
ink rgb(100,100,100),0
box x,y,xx,yy
ink rgb(190,190,190),0
text x+1,y+1,t$

endif

else

rem Draw button
ink rgb(190,190,190),0
box x,y,xx,yy
ink 0,0
text x+1,y+1,t$

endif

endfunction 0

rem Simple 2D collision function
function 2dcollide(x,y,x2,y2,x3,y3)

rem If the coordinate is within the right X-area
if x>x2 and xy2 and y
Posted: 3rd Mar 2003 16:05
WTF? stupid code

+ Code Snippet
remstart

The button function is called with parameters for the buttons position (x,y) and text.
It will return 1 if the button is leftclicked, and 2 if rightclicked.

remend

rem Button function
function button(x,y,t$)

   rem Width and height of button
   xx=x+text width(t$)+2
   yy=y+text height(t$)+2

   rem If mousecursor is over button
   if 2dcollide(mousex(),mousey(),x,y,xx,yy)

      rem If the button is clicked
      if mouseclick()>0

         rem Set value of mouseclick (leftclick/rightclick)
         click=mouseclick()

         rem Draw Clicked-button
         ink rgb(50,50,50),0
         box x,y,xx,yy
         ink rgb(255,255,255),0
         text x+1,y+1,t$

         rem Wait until the mousebutton is released
         repeat : until mouseclick()=0

         rem Return mouselick-value
         exitfunction click

      else

         rem Draw MouseOver-button
         ink rgb(100,100,100),0
         box x,y,xx,yy
         ink rgb(190,190,190),0
         text x+1,y+1,t$

      endif

   else

      rem Draw button
      ink rgb(190,190,190),0
      box x,y,xx,yy
      ink 0,0
      text x+1,y+1,t$

   endif

endfunction 0

rem Simple 2D collision function
function 2dcollide(x,y,x2,y2,x3,y3)

   rem If the coordinate is within the right X-area
   if x>x2 and x<x3

      rem If the coordinate is within the right Y-area
      if y>y2 and y<y3

         rem Return a one
         exitfunction 1

      endif

   endif

endfunction 0
Posted: 3rd Mar 2003 16:06
and an example use of it:

+ Code Snippet
rem Set manual synchronization on
sync on

rem Main loop
do

   rem Some buttons...
   b1=button(10,10,"Clicked: "+str$(clicked))
   b2=button(10,40,"Exit")

   rem Clicked?
   if b1=1 then inc clicked
   if b2=1 then end

   rem Update screen
   sync

loop
Posted: 4th Apr 2003 19:58
For the "simple button-function",

I must be a newbe cause every time I put it into my program I can't get it to work...It just says "IF EXPECTS AN INTEGER." I've substituted integers in for the x and y variables, but it still won't work. Can you describe (more detailed) how to use this function?