Ok now i took the Code and modified it, now it is...
Buttons!!
- only activated on mouse-release while mouse is over them
- if u click and hold on a button it'll stay down even if u move the mouse
- if u then releae the mouse on an other button none of them returns "pressed"
Example/Code:
Sync On
gosub setupButton
Button1=makeButton("Button1: 0",50,50)
Button2=makeButton("Button2: 0",50,80)
Do : Cls Rgb(240,240,240)
handleButton()
If ButtonPressed(Button1) then Inc N1
But(Button1).label="Button1: "+Str$(N1)
If ButtonPressed(Button2) then Inc N2
But(Button2).label="Button2: "+Str$(N2)
Sync : Loop
setupButton:
type tButton
x,y as integer
label as string
hidden as integer
Done as boolean
endtype
dim But() as tButton
Empty Array But()
global pressed as Integer : pressed=-1
return
function makeButton(label as string , x as integer ,y as integer )
Array Insert At Bottom But()
num=Array Count(But())
But(num).hidden=0
But(num).label=label
But(num).x=x
But(num).y=y
endfunction num
Function ButtonPressed(n)
o=But(n).Done
But(n).Done=0
//If o=1 then pressed=-1
Endfunction o
function handleButton()
num=Array Count(But(0))
for x=0 to num
If But(x).hidden=0
if pressed=x
ink rgb(235,235,235),0
box But(x).x,But(x).y-4,But(x).x+text width(But(x).label),But(x).y+text size()+8
ink rgb(163,170,175),0
line But(x).x,But(x).y-5,But(x).x+text width(But(x).label),But(x).y-5
ink rgb(98,107,110),0
line But(x).x,But(x).y-4,But(x).x,But(x).y+text size()+8
line But(x).x,But(x).y-4,But(x).x+text width(But(x).label),But(x).y-4
ink rgb(231,238,241),0
line But(x).x,But(x).y+text size()+8,But(x).x+text width(But(x).label),But(x).y+text size()+8
line But(x).x+text width(But(x).label),But(x).y-4,But(x).x+text width(But(x).label),But(x).y+text size()+8
ink rgb(0,0,0),0
text But(x).x+1,But(x).y+1,But(x).label
else
ink rgb(245,245,245),0
box But(x).x,But(x).y-4,But(x).x+text width(But(x).label),But(x).y+text size()+8
ink rgb(163,170,175),0
line But(x).x,But(x).y+text size()+8,But(x).x+text width(But(x).label),But(x).y+text size()+8
ink rgb(98,107,110),0
line But(x).x+text width(But(x).label),But(x).y-4,But(x).x+text width(But(x).label),But(x).y+text size()+8
ink rgb(221,228,231),0
line But(x).x,But(x).y-4,But(x).x+text width(But(x).label),But(x).y-4
line But(x).x,But(x).y+text size()+9,But(x).x+text width(But(x).label),But(x).y+text size()+9
line But(x).x,But(x).y-4,But(x).x,But(x).y+text size()+8
ink rgb(0,0,0),0
text But(x).x,But(x).y,But(x).label
endif
endif
If MouseX()>But(x).x and MouseX()<But(x).x+text width(But(x).label) and MouseY()>But(x).y-4 and MouseY()<But(x).y+text size()+8
If MouseClick()&&1 and pressed=-1 Then pressed=x
Endif
next x
If MouseClick()=0 and pressed>-1
If MouseX()>But(pressed).x and MouseX()<But(pressed).x+text width(But(pressed).label) and MouseY()>But(pressed).y-4 and MouseY()<But(pressed).y+text size()+8 Then But(pressed).Done=1
pressed=-1
Endif
endfunction
Oh and thanks sixty squares
Edit:
Added Cursor-moving for Inputs!!
now you can move the cursor either by clicking or by Right/leftkey
[New Code: ]
Sync On
Sync Rate 60
Set Window On
color backdrop rgb(240,240,240)
Make Object cube 1,1
gosub setupInput
// Parameters: The label-string, x, y,Max, End on 'Enter'
I1 = MakeInput("Enter new Label: ", 50, 50, 20, 1)
I2 = MakeInput(" -->Change me<-- :",50, 90, 20, 0)
do
Turn Object Left 1,1
handleInput()
`If Return was pressed on one of them the label will change to the input
If InputDone(I1) Then Inp(I1).label=Inp(I1).In$+":"
If InputDone(I2) Then Inp(I2).label=Inp(I2).In$+":"
sync
loop
`======================InputBoxes by RedFlames========================
setupInput:
#constant waitReturn 0
type tInput
Used as integer
exEnter as Integer
In$ as string
Inpos as Integer
bt as integer
dt as integer
end$ as string
et as integer
x,y as integer
label as string
maxc as integer
hidden as integer
Done as boolean
endtype
dim Inp(0) as tInput
Empty Array Inp(0)
global entr$ as string
global ink$ as string
global Inputting as integer
global LK,RK,OLK,ORK as Boolean
return
function makeInput(label as string , x as integer ,y as integer ,maxchar as integer ,exEnter as Boolean )
Array Insert At Bottom Inp(0)
num=Array Count(Inp(0))
Inp(num).Used=0
Inp(num).exEnter=exEnter
Inp(num).hidden=0
Inp(num).In$=""
Inp(num).bt=0
Inp(num).dt=0
Inp(num).et=5
Inp(num).label=label
Inp(num).x=x
Inp(num).y=y
Inp(num).end$=" "
Inp(num).maxc=maxchar
Inp(num).InPos=1
endfunction num
function InputString(num)
ink$=entry$(1)
Clear Entry Buffer
if len(Inp(num).In$)<Inp(num).maxc and len(ink$)>0 then Inp(num).In$=Insert$(Inp(num).In$,Inp(num).InPos,ink$) : Inc Inp(num).InPos
if keystate(14) and Inp(num).bt<=0 and len(Inp(num).In$)>0 and Inp(num).InPos>1 then Inp(num).In$=remove$(Inp(num).In$,Inp(num).InPos-1,1) : Inp(num).bt=8 : Dec Inp(num).InPos
if Inp(num).bt>=-1 then dec Inp(num).bt
if Inp(num).dt>=-1 then dec Inp(num).dt
If Inp(num).et>=-1 then dec Inp(num).et
if Inp(num).et<=0
if Inp(num).end$=" "
Inp(num).end$=Chr$(0x7C)
Inp(num).et=8
else
Inp(num).end$=" "
Inp(num).et=8
endif
endif
if returnkey()
Inp(num).In$=Trim$(Inp(num).In$,Chr$(10)+Chr$(13))
If exEnter Then Inp(num).Used=0 : Inp(num).end$=" "
Inp(num).Done=1
Endif
endfunction
Function InputDone(n)
o=Inp(n).Done
Inp(n).Done=0
Endfunction o
function handleInput()
Inputting=0
num=Array Count(Inp(0))
for x=0 to num
If Inp(x).hidden=0
if Inp(x).Used=1
InputString(x)
LK=Leftkey()&&(LeftKey()<>OLK)
RK=Rightkey()&&(RightKey()<>OLK)
Inp(x).InPos=clamp(Inp(x).InPos+RK-LK,1,Fast Len(Inp(x).In$)+1)
OLK=Leftkey()
ORK=Rightkey()
endif
ink rgb(250,250,250),0
box Inp(x).x,Inp(x).y-4,Inp(x).x+text width(Inp(x).label)+text width("A")*(Inp(x).maxc+1),Inp(x).y+text size()+8
ink rgb(163,170,175),0
line Inp(x).x,Inp(x).y-5,Inp(x).x+text width(Inp(x).label)+text width("A")*(Inp(x).maxc+1),Inp(x).y-5
ink rgb(98,107,110),0
line Inp(x).x,Inp(x).y-4,Inp(x).x,Inp(x).y+text size()+8
line Inp(x).x,Inp(x).y-4,Inp(x).x+text width(Inp(x).label)+text width("A")*(Inp(x).maxc+1),Inp(x).y-4
ink rgb(231,238,241),0
line Inp(x).x,Inp(x).y+text size()+8,Inp(x).x+text width(Inp(x).label)+text width("A")*(Inp(x).maxc+1),Inp(x).y+text size()+8
line Inp(x).x+text width(Inp(x).label)+text width("A")*(Inp(x).maxc+1),Inp(x).y-4,Inp(x).x+text width(Inp(x).label)+text width("A")*(Inp(x).maxc+1),Inp(x).y+text size()+8
ink rgb(0,0,0),0
If Inp(x).InPos-1>0
If Inp(x).Used
text Inp(x).x,Inp(x).y,Inp(x).label+Mid$(Inp(x).In$,1,Inp(x).InPos-1)+Inp(x).end$+Mid$(Inp(x).In$,Inp(x).InPos,Fast Len(Inp(x).In$))
Else
text Inp(x).x,Inp(x).y,Inp(x).label+Inp(x).In$
Endif
Else
text Inp(x).x,Inp(x).y,Inp(x).label+Inp(x).end$+Inp(x).In$
Endif
if Inp(x).Used then Inputting=1 else Inp(x).end$=" "
endif
next x
if Inputting=0 or waitReturn=0
for x=0 to num
if mouseclick()&&1 >0 and Inp(x).hidden=0
if checkbox(Inp(x).x,Inp(x).y-9,text width(Inp(x).label)+text width("A")*Inp(x).maxc,text size()+18)=1
for y=0 to num
if y=x
If Inp(y).Used=0
Inp(y).Used=1
Inp(y).InPos=Fast Len(Inp(y).In$)+1
Else
Inp(y).InPos=Clamp((MouseX()-Inp(y).x-Fast len(Inp(y).label)*text width("A"))/text width("A")+1,1,Fast Len(Inp(y).In$)+1)
Endif
else
Inp(y).Used=0
Inp(y).InPos=Fast Len(Inp(y).In$)+1
endif
next y
else
Inp(x).Used=0 : Inp(num).end$=" " : Inp(x).InPos=Fast Len(Inp(x).In$)+1
endif
endif
next x
endif
endfunction
function checkbox(x,y,w,h)
if mousey()>y and mousey()<y+h and mousex()>x and mousex()<x+w then exitfunction 1
endfunction 0