`Buttonset Editor
`2008 Joep Peters
 
set display mode 800,600,16
`set window on
sync on
sync rate 0
create bitmap 1,800,600
 
 
dim MenuButtonX(16,64)
dim MenuButtonY(16,64)
dim MenuButtonText$(16,64)
dim MenuButtonCount(16,1)
 
dim MenuFormText$(16)
dim MenuFormX(16)
dim MenuFormY(16)
dim MenuFormWidth(16)
dim MenuFormHeight(16)
dim MenuFormCount(1)
 
 
 
 
 
 
InterfaceX = 400
InterfaceY = 200
 
 
do
     cls rgb(50,50,50)
 
     InterfaceInput$ = Interface(InterfaceX,InterfaceY)
 
     if InterfaceInput$ = "QUIT" then end
     if InterfaceInput$ = "SAVE"
 
        while returnkey()=0
          cls rgb(50,50,50)
 
         ink rgb(128,128,128),0
         box 250,200,250+220,200+150
         ink rgb(0,0,150),0
         box 250,200,250+220,200+15
         ink rgb(255,255,255),0
         set text to italic
         text 250+4,200,"Type a filename"
         set text to normal
 
         ink 0,0
         DrawOutline(250,200,220,150)
         line 250,200+16,250+220,200+16
 
         ink rgb(255,255,255),0
         box 280,240,400,255
         ink 0,0
         DrawOutline(280,240,120,15)
 
 
          filename$ =  Typing( filename$,0,0)
           text 280,240,filename$
 
 
 
          text 280 + text width(filename$),240,Blinker()
          copy bitmap 1,0
          sync
        endwhile
        SaveButtonSet(filename$)
       endif
     if InterfaceInput$ = "LOAD"
 
        while returnkey()=0
          cls rgb(50,50,50)
 
         ink rgb(128,128,128),0
         box 250,200,250+220,200+150
         ink rgb(0,0,150),0
         box 250,200,250+220,200+15
         ink rgb(255,255,255),0
         set text to italic
         text 250+4,200,"Type a filename"
         set text to normal
         ink 0,0
         DrawOutline(250,200,220,150)
         line 250,200+16,250+220,200+16
 
         ink rgb(255,255,255),0
         box 280,240,400,255
         ink 0,0
         DrawOutline(280,240,120,15)
 
 
          filename$ =  Typing( filename$,0,0)
           text 280,240,filename$
 
 
 
          text 280 + text width(filename$),240,Blinker()
          copy bitmap 1,0
          sync
        endwhile
        LoadButtonSet(filename$)
     endif
     if InterfaceInput$ = "NEW"
         for form = 1 to MenuFormCount(1)
 
             MenuFormText$(form) = ""
             MenuFormCount(1) = 0
 
             for button = 1 to MenuButtonCount(form,1)
                MenuButtonText$(form,button) = ""
                MenuButtonCount(form,1) = 0
             next button
 
         next form
        ` MenuButtonCount(1)=0
     endif
     if InterfaceInput$ = "MOVEINTERFACE" then MoveInterface=1
     if InterfaceInput$ = "SNAP" then Snapping=1
     if InterfaceInput$ = "NOSNAP" then Snapping=0
 
 
     if MoveInterface=1
 
         if mouseclick()=0 then MoveInterface=0
 
         InterfaceX = InterfaceX + mousemovex()
         InterfaceY = InterfaceY + mousemovey()
 
     endif
 
     SelectedForm = TRD_SelectedForm()
     TRD_DrawOtherButtons(SelectedForm)
     SelectedButton = TRD_SelectedButton(SelectedForm)
 
     print selectedbutton
 
     if SelectedForm <> 0
        ink rgb(255,255,255),0
        DrawOutline(MenuFormX(SelectedForm),MenuFormY(SelectedForm),MenuFormWidth(SelectedForm),MenuFormHeight(SelectedForm))
     endif
 
 
     if InterfaceInput$ = "ADD"
         repeat
         until mouseclick()=0
 
         repeat
 
               cls rgb(50,50,50)
               DrawOtherForms(0)
               TRD_DrawOtherButtons(0)
 
               ink rgb(128,128,140),0
               box mousex()-30,mousey()-15,mousex()+30,mousey()
               ink 0,0
               DrawOutline(mousex()-30,mousey()-15,60,15)
 
              copy bitmap 1,0
              sync
 
         until mouseclick()=1
 
         mx = mousex()
         my = mousey()
         SelectedForm = TRD_SelectedForm()
 
         if SelectedForm <> 0
 
            if MenuButtonCount(SelectedForm,1) < 64
             MenuButtonCount(SelectedForm,1) = MenuButtonCount(SelectedForm,1) + 1
 
             MenuButtonText$(SelectedForm,MenuButtonCount(SelectedForm,1)) = "Button"+ str$(MenuButtonCount(SelectedForm,1))
             MenuButtonX(SelectedForm,MenuButtonCount(SelectedForm,1)) = mx - MenuFormX(SelectedForm) - 30
             MenuButtonY(SelectedForm,MenuButtonCount(SelectedForm,1)) = my - MenuFormY(SelectedForm) - 15
            endif
         endif
     endif
 
     if InterfaceInput$ = "ADDFORM"
         repeat
         until mouseclick()=0
 
         repeat
 
               cls rgb(50,50,50)
               DrawOtherForms(0)
               TRD_DrawOtherButtons(0)
 
               ink rgb(128,128,140),0
               box mousex()-50,mousey()-100,mousex()+50,mousey()
               ink rgb(0,0,150),0
               box mousex()-50,mousey()-100,mousex()+50,mousey()-85
               ink 0,0
 
 
              copy bitmap 1,0
              sync
 
         until mouseclick()=1
 
         if MenuFormCount(1) < 16
             MenuFormCount(1) = MenuFormCount(1) + 1
             MenuFormText$(MenuFormCount(1)) = "Form" + str$(MenuFormCount(1))
             MenuFormX(MenuFormCount(1)) = mousex()-50
             MenuFormY(MenuFormCount(1)) = mousey()-100
             MenuFormWidth(MenuFormCount(1)) = 100
             MenuFormHeight(MenuFormCount(1)) = 100
         endif
     endif
 
 
 
     if SelectedButton <> 0
       if SelectedButton > 0
 
           if mouseclick() = 1
               print "Button " + MenuButtonText$(SelectedForm,SelectedButton) + " in form " + MenuFormText$(SelectedForm) + " has been pressed"
           else
               print "Button " + MenuButtonText$(SelectedForm,SelectedButton) + " in form " + MenuFormText$(SelectedForm) + " has been RIGHT CLICKED!!"
              repeat
              until mouseclick()=0
              hide mouse
              repeat
                  cls rgb(50,50,50)
                  DrawOtherForms(0)
                  TRD_DrawOtherButtons(0)
 
                  MenuButtonText$(SelectedForm,SelectedButton) =  Typing(  MenuButtonText$(SelectedForm,SelectedButton),0,0)
                  text MenuFormX(SelectedForm)+ MenuButtonX(SelectedForm,SelectedButton)+ text width(MenuButtonText$(SelectedForm,SelectedButton)),MenuFormY(SelectedForm)+MenuButtonY(SelectedForm,SelectedButton),Blinker()
                 copy bitmap 1,0
                 sync
              until returnkey()=1
              show mouse
 
           endif
 
         if Snapping=0
             MenuButtonX(SelectedForm,SelectedButton)= MenuButtonX(SelectedForm,SelectedButton) + mousemovex()
             MenuButtonY(SelectedForm,SelectedButton)= MenuButtonY(SelectedForm,SelectedButton) + mousemovey()
         endif
 
         if Snapping=1
          `   tempx =  ( (mousex() - MenuFormX(SelectedForm)) - ( (mousex() - MenuFormX(SelectedForm))- MenuButtonX(SelectedForm,SelectedButton))) /5
`             tempy =  ((mousey() - MenuFormY(SelectedForm)) - ( MenuButtonY(SelectedForm,SelectedButton)) /5
 
            ` MenuButtonX(SelectedForm,SelectedButton) = tempx*5
           `  MenuButtonY(SelectedForm,SelectedButton) = tempy*5
 
             `position mouse tempx*10,tempy*10
 
         endif
       endif
       if SelectedButton = -3
           repeat
               cls rgb(50,50,50)
               DrawOtherForms(0)
               TRD_DrawOtherButtons(0)
 
               MenuFormWidth(SelectedForm) = MenuFormWidth(SelectedForm)+mousemovex()
               MenuFormHeight(SelectedForm) = MenuFormHeight(SelectedForm)+mousemovey()
              copy bitmap 1,0
              sync
 
           until mouseclick()=0
 
       endif
       if SelectedButton = -2
           repeat
           until mouseclick()=0
           hide mouse
           repeat
               cls rgb(50,50,50)
               DrawOtherForms(0)
               TRD_DrawOtherButtons(0)
 
              MenuFormText$(SelectedForm) =  Typing(  MenuFormText$(SelectedForm),0,0)
 
               text MenuFormX(SelectedForm)+ text width(MenuFormText$(SelectedForm)),MenuFormY(SelectedForm),Blinker()
 
              copy bitmap 1,0
              sync
           until returnkey()=1
           show mouse
       endif
       if SelectedButton = -1
           print "Title bar from " + MenuFormText$(SelectedForm) + " is clicked!"
 
           repeat
              cls rgb(50,50,50)
 
 
               DrawOtherForms(SelectedForm)
               FormWindow(SelectedForm)
 
               MenuFormX(SelectedForm) = MenuFormX(SelectedForm) + mousemovex()
               MenuFormY(SelectedForm) = MenuFormY(SelectedForm) + mousemovey()
              copy bitmap 1,0
              sync
           until mouseclick()=0
       endif
     endif
 
     if InterfaceInput$ = "DELETEFORM"
         repeat
             sync
         until mouseclick()=0
 
         repeat
            cls rgb(50,50,50)
               DrawOtherForms(0)
               TRD_DrawOtherButtons(0)
               FormToDelete = TRD_SelectedForm()
 
               if FormToDelete > 0
                   ink rgb(255,255,255),0
                   DrawOutline(MenuFormX(FormToDelete),MenuFormY(FormToDelete),MenuFormWidth(FormToDelete),MenuFormHeight(FormToDelete))
 
               endif
            copy bitmap 1,0
            sync
         until mouseclick() > 0
 
         if mouseclick()=1 and FormToDelete > 0
 
            MenuFormText$(FormToDelete) = ""
            for button = 1 to 64
                MenuButtonText$(FormToDelete,button) = ""
            next button
            SortFormArrays()
            SortButtonArrays()
            if MenuFormCount(1) > 0 then MenuFormCount(1) = MenuFormCount(1) - 1
         endif
         repeat
            sync
         until mouseclick()=0
     endif
 
     if InterfaceInput$ = "DELETE"
         repeat
         until mouseclick()=0
 
         repeat
 
               cls rgb(50,50,50)
                 SelectedForm = TRD_SelectedForm()
                 TRD_DrawOtherButtons(SelectedForm)
                 SelectedButton = TRD_SelectedButton(SelectedForm)
               print SelectedButton
               print SelectedForm
 
 
              copy bitmap 1,0
              sync
 
         until mouseclick()=1
 
         repeat
         sync
         until mouseclick()=0
             SelectedForm = TRD_SelectedForm()
             MenuButtonText$(SelectedForm,SelectedButton) = ""
             SortButtonArrays()
             if MenuButtonCount(SelectedForm,1) > 0 then MenuButtonCount(SelectedForm,1) = MenuButtonCount(SelectedForm,1) - 1
         sync
     endif
 
 
     copy bitmap 1,0
     sync
loop
 
Function LoadButtonSet(filename$)
 
    if file exist(filename$)=1
        open to read 1,filename$
 
        read string 1,FormCountTemp$
        MenuFormCount(1) = val(FormCountTemp$)
 
        for form = 1 to MenuFormCount(1)
 
            read string 1,FormTempX$
            read string 1,FormTempY$
            read string 1,FormTempWidth$
            read string 1,FormTempHeight$
            read string 1,FormTempText$
 
            MenuFormText$(form) = FormTempText$
            MenuFormX(form) = val(FormTempX$)
            MenuFormY(form) = val(FormTempY$)
            MenuFormWidth(form) = val(FormTempWidth$)
            MenuFormHeight(form) = val(FormTempHeight$)
 
            read string 1,ButtonCountTemp$
 
            MenuButtonCount(form,1) = val(ButtonCountTemp$)
 
            for button = 1 to MenuButtonCount(form,1)
 
                read string 1,ButtonTempX$
                read string 1,ButtonTempY$
                read string 1,ButtonTempText$
 
                MenuButtonX(form,button) = val(ButtonTempX$)
                MenuButtonY(form,button) = val(ButtonTempY$)
                MenuButtonText$(form,button) = ButtonTempText$
 
 
            next button
        next form
        close file 1
 
    endif
 
 
EndFunction
 
Function SaveButtonSet(filename$)
    if file exist(filename$) = 1 then delete file filename$
        open to write 1,filename$
 
        write string 1,str$(MenuFormCount(1))
 
        for form = 1 to MenuFormCount(1)
 
            write string 1,str$(MenuFormX(form))
            write string 1,str$(MenuFormY(form))
            write string 1,str$(MenuFormWidth(form))
            write string 1,str$(MenuFormHeight(form))
            write string 1,MenuFormText$(form)
 
            write string 1,str$(MenuButtonCount(form,1))
 
            for button = 1 to MenuButtonCount(form,1)
               write string 1,str$(MenuButtonX(form,button))
               write string 1,str$(MenuButtonY(form,button))
               write string 1,MenuButtonText$(form,button)
            next button
 
        next form
        close file 1
EndFunction
 
 
Function TRD_SelectedForm()
   SelectedForm=0
 
   for index = 1 to MenuFormCount(1)
       if FormWindow(index)=1
           SelectedForm=index
       endif
   next index
 
EndFunction SelectedForm
 
Function TRD_DrawOtherButtons(IgnoreForm)
    for index = 1 to MenuFormCount(1)
        if index <> IgnoreForm
            for button = 1 to MenuButtonCount(index,1)
                Button(MenuButtonX(index,button)+MenuFormX(index),MenuButtonY(index,button)+MenuFormY(index),MenuButtonText$(index,button))
            next button
        endif
    next index
 
EndFunction
 
Function TRD_SelectedButton(FormIndex)
 
    Number=0
    for index = 1 to MenuButtonCount(FormIndex,1)
 
        if Button(MenuButtonX(FormIndex,index)+MenuFormX(FormIndex),MenuButtonY(FormIndex,index)+MenuFormY(FormIndex),MenuButtonText$(FormIndex,index)) > 0
            Number=index
        endif
 
    next index
 
       mx = mousex()
       my = mousey()
 
       if mx > MenuFormX(FormIndex)
           if mx < MenuFormX(FormIndex)+MenuFormWidth(FormIndex)
               if my > MenuFormY(FormIndex)
                   if my < MenuFormY(FormIndex) +15
                       if mouseclick()=1
                           Number=-1
                       endif
                       if mouseclick()=2
                          Number=-2
                       endif
 
                   endif
               endif
           endif
       endif
 
       if mx > MenuFormX(FormIndex) + MenuFormWidth(FormIndex) - 10
           if mx < MenuFormX(FormIndex)+MenuFormWidth(FormIndex)
               if my > MenuFormY(FormIndex)+ MenuFormHeight(FormIndex)-10
                   if my < MenuFormY(FormIndex) + MenuFormHeight(FormIndex)
                       if mouseclick()=1
                           Number=-3
                       endif
                   endif
               endif
           endif
       endif
 
EndFunction Number
 
Function DrawOtherForms(IgnoreForm)
 
    for index = 1 to MenuFormCount(1)
       if index <> IgnoreForm
          ink rgb(128,128,128),0
          box MenuFormX(index),MenuFormY(index),MenuFormX(index)+MenuFormWidth(index),MenuFormY(index)+MenuFormHeight(index)
          ink rgb(0,0,150),0
          box MenuFormX(index),MenuFormY(index),MenuFormX(index)+MenuFormWidth(index),MenuFormY(index)+15
          ink rgb(100,100,150),0
          line MenuFormX(index)+1,MenuFormY(index)+1,MenuFormX(index)+MenuFormWidth(index)-1,MenuFormY(index)+1
          ink rgb(255,255,255),0
          set text to italic
          text MenuFormX(index)+4,MenuFormY(index),MenuFormText$(index)
          set text to normal
 
          ink 0,0
          DrawOutline(MenuFormX(index),MenuFormY(index),MenuFormWidth(index),MenuFormHeight(index))
          line MenuFormX(index),MenuFormY(index)+16,MenuFormX(index)+MenuFormWidth(index),MenuFormY(index)+16
       endif
    next index
 
EndFunction
 
Function FormWindow(index)
 
    Selected=0
    ink rgb(128,128,128),0
    box MenuFormX(index),MenuFormY(index),MenuFormX(index)+MenuFormWidth(index),MenuFormY(index)+MenuFormHeight(index)
    ink rgb(0,0,150),0
    box MenuFormX(index),MenuFormY(index),MenuFormX(index)+MenuFormWidth(index),MenuFormY(index)+15
 
    ink rgb(100,100,150),0
    line MenuFormX(index)+1,MenuFormY(index)+1,MenuFormX(index)+MenuFormWidth(index)-1,MenuFormY(index)+1
 
    ink rgb(255,255,255),0
    set text to italic
    text MenuFormX(index)+4,MenuFormY(index),MenuFormText$(index)
    set text to normal
 
    ink 0,0
    DrawOutline(MenuFormX(index),MenuFormY(index),MenuFormWidth(index),MenuFormHeight(index))
    line MenuFormX(index),MenuFormY(index)+16,MenuFormX(index)+MenuFormWidth(index),MenuFormY(index)+16
 
    DrawOutline( MenuFormX(index) + MenuFormWidth(index)-10,MenuFormY(index)+MenuFormHeight(index)-10,10,10)
 
 
    mx = mousex()
    my = mousey()
 
    if mx > MenuFormX(index)
        if mx < MenuFormX(index)+MenuFormWidth(index)
            if my > MenuFormY(index)
                if my < MenuFormY(index) + MenuFormHeight(index)
                    Selected = 1
 
                endif
            endif
        endif
    endif
 
EndFunction Selected
 
 
Function TRD_IndexForm()
 
 
    Number=0
    for index = 1 to MenuButtonCount(1)
 
        if Button(MenuButtonX(index),MenuButtonY(index),MenuButtonText$(index)) = 1 or Button(MenuButtonX(index),MenuButtonY(index),MenuButtonText$(index)) = 2
            Number=index
        endif
 
    next Button
 
EndFunction Number
 
 
Function TRD_Menu()
    Button$ = ""
    for index = 1 to MenuButtonCount(1)
 
        if Button(MenuButtonX(index),MenuButtonY(index),MenuButtonText$(index)) = 1
            Button$ =  MenuButtonText$(index)
        endif
 
        if Button(MenuButtonX(index),MenuButtonY(index),MenuButtonText$(index)) = 2
            Button$ =  "RIGHT " + MenuButtonText$(index)
        endif
 
    next Button
 
EndFunction Button$
 
Function Blinker()
   Blink = Blink + 1
   if Blink > 3
      Blink = 0
      if Blinker$ = "" then Blinker$ = "|" else Blinker$ = ""
   endif
EndFunction Blinker$
 
Function Typing(TypingMod$,TypingL,TypingMode)
   REM Inputs Keys from Keyboard to modify String$
      REM Typing Limit, Zero will make it unlimited suposively.
         REM TypingMode0 = all Letters, Typingmode1= only Numbers
   if TypingL = 0 Then TypingL = 1000
      REM Typing Input.
   TypingI$ = inkey$()
      REM Reset TypingG$ if there's no input.
   if TypingI$ = "" then TypingG$ = ""
      REM Reset keyTyping if BackSpace is not pressed.
   if asc(TypingI$) <> 8 then KeyTyping = 0
      REM BackSpace is Pressed. Erase one off of TypingMod$.
   if asc(TypingI$) = 8
         REM If first time pressing BackSpace
      if KeyTyping = 0
            REM Resets the TypingCounter used to time the key repeat.
         TypingC = 0
            REM Checks if String$ has anything.
         if len(TypingMod$) > 0
               REM Erase the last letter in TypingMod$.
            TypingMod$ = left$(TypingMod$,len(TypingMod$)-1)
         endif
      endif
         REM Flag this variable to not alow TypingMod$ erase.
      KeyTyping = 1
         REM Clear the input so it's not added to TypingG$
      TypingI$=""
         REM Handle the repeat of BackSpace
      inc TypingC,1
      if TypingC > 2 then KeyTyping = 0
   endif
   REM Setting up variable for checks.
   z = asc(TypingI$)
      REM Only numbers can pass
   if TypingMode = 1 & z > 57 or TypingMode = 1 & z < 48 then TypingI$=""
      REM Only letters can pass
   if TypingMode = 0 & z > 127 or TypingMode = 0 & z < 32 then TypingI$=""
      REM Checks if new/old Input are different and TypingMod$ is in Limit.
   if TypingG$ <> TypingI$ & len(TypingMod$) < TypingL then TypingMod$=TypingMod$+TypingI$
      REM Stores the last Input. Used for checking key repeat.
   TypingG$ = TypingI$
EndFunction   TypingMod$
 
Function SortFormArrays()
 
    for form = 1 to MenuFormCount(1)-1
        if MenuFormText$(form) = ""
 
            MenuFormText$(form) = MenuFormText$(form+1)
            MenuFormX(form) = MenuFormX(form+1)
            MenuFormY(form) = MenuFormY(form+1)
            MenuFormWidth(form) = MenuFormWidth(form+1)
            MenuFormHeight(form) = MenuFormHeight(form+1)
            MenuButtonCount(form,1) = MenuButtonCount(form+1,1)
 
            MenuFormText$(form+1) = ""
            MenuFormX(form+1) = 0
            MenuFormY(form+1) = 0
            MenuFormWidth(form+1) = 0
            MenuFormHeight(form+1) = 0
            MenuButtonCount(form+1,1) = 0
 
            for button = 1 to 64
                MenuButtonText$(form,button) = MenuButtonText$(form+1,button)
                MenuButtonX(form,button) = MenuButtonX(form+1,button)
                MenuButtonY(form,button) = MenuButtonY(form+1,button)
 
                MenuButtonText$(form+1,button) = ""
                MenuButtonX(form+1,button) = 0
                MenuButtonY(form+1,button) = 0
 
 
            next button
 
 
        endif
    next form
 
EndFunction
 
 
Function SortButtonArrays()
  for form = 1 to MenuFormCount(1)
    for index = 1 to MenuButtonCount(form,1)-1
        if MenuButtonText$(form,index) = ""
            MenuButtonText$(form,index) = MenuButtonText$(form,index+1)
            MenuButtonX(form,index) = MenuButtonX(form,index+1)
            MenuButtonY(form,index) = MenuButtonY(form,index+1)
 
            MenuButtonText$(form,index+1) = ""
            MenuButtonX(form,index+1) = 0
            MenuButtonY(form,index+1) = 0
        endif
    next index
  next form
 
EndFunction
 
Function Interface(x,y)
    Choice$=""
    ink rgb(128,128,128),0
    box x,y,x+125,y+210
    ink rgb(0,0,150),0
    box x,y,x+125,y+15
    ink rgb(255,255,255),0
    set text to italic
    text x+4,y,"Toolbox"
    set text to normal
 
    ink 0,0
    DrawOutline(x,y,125,210)
    line x,y+16,x+125,y+16
 
    if Button(x+10,y+20,"Add  Button") = 1 then Choice$ = "ADD"
    if Button(x+10,y+40,"Del. Button") = 1 then Choice$ = "DELETE"
    if Button(x+10,y+70,"Add  Form") = 1 then Choice$ = "ADDFORM"
    if Button(x+10,y+90,"Del. Form") = 1 then Choice$ = "DELETEFORM"
 
 
 
   `` if Button(x+10,y+120,"Add  TXTBox") = 1 then Choice$ = "ADDTEXTBOX"
   `` if Button(x+10,y+140,"Del. TXTBox") = 1 then Choice$ = "DELETETEXTBOX"
 
    if Button(x+10,y+170,"New ") = 1 then Choice$ = "NEW"
    if Button(x+50,y+170,"Save") = 1 then Choice$ = "SAVE"
    if Button(x+50,y+190,"Load") = 1 then Choice$ = "LOAD"
    if Button(x+10,y+190,"Quit") = 1 then Choice$ = "QUIT"
 
    MouseX = mousex()
    MouseY = mousey()
 
    if MouseX > x
        if MouseX < x+125
            if MouseY > y
                if MouseY < y + 15
 
                    if mouseclick()=1
                        Choice$= "MOVEINTERFACE"
                    endif
                endif
            endif
        endif
    endif
 
EndFunction Choice$
 
 
Function Button(x,y,Caption$)
 
    Click = 0
    width = ( len(Caption$)*8 ) + 4
    ink rgb(128,128,140),0
    box x,y,x+width,y+15
    ink rgb(180,180,200),0
    line x+1,y+1,x+width-1,y+1
    ink rgb(0,0,0),0
    center text x+ (width/2),y,Caption$
 
 
    MouseX = mousex()
    MouseY = mousey()
 
    ink 0,0
 
    if MouseX > x
        if MouseX < x+width
            if MouseY > y
                if MouseY < y + 15
                    ink rgb(255,255,255),0
                    if mouseclick()=1
                        Click=1
                        ink rgb(255,0,0),0
                    else
                        Click=0
                    endif
                    if mouseclick()=2
                        ink rgb(255,0,0),0
                        Click=2
                    endif
                endif
            endif
        endif
    endif
 
    DrawOutline(x,y,width,15)
 
EndFunction Click
 
 
Function DrawOutline(x,y,width,height)
 
    line x,y,x + width,y
    line x,y,x,y + height
    line x,y + height,x + width,y + height
    line x + width,y,x+ width,y+ height
 
EndFunction