Tällöin muistin kätevän ominaisuuden. Klikkaappa johonkin hiiren oikealla .
Ajattelin sitten ohjelmoida tähän kaksi funktiota.
Uskon, että esimerkki selvittää funktioiden käytön. Koodin alussa on ohjeet ButtonMenu-funktiolle.
Code: Select all
Dim button_menu(50)
// px, py = x- and y-direction
// img = image that function shows
// selections example: Load,Save,Exit
// mut = menus id
// nclick = what button needed to click
Function ButtonMenu(px,py,img,selections$,mut,nclick=1)
mx=MouseX()
my=MouseY()
txth=TextHeight("A")
imgw=ImageWidth(img)
imgh=ImageHeight(img)
DrawImage img,px,py
If mx>px And mx<px+imgw And my>py And my<py+imgh Then
If nclick Then
If MouseUp(nclick) Then button_menu(mut)=1 : notn=1
Else
button_menu(mut)=1
EndIf
EndIf
If button_menu(mut) And notn=0 Then
For i=1 To CountWords(selections,"|")
If TextWidth(GetWord(selections,i,"|"))>width Then width=TextWidth(GetWord(selections,i,"|"))
height=height+txth+6
Next i
width+10
Color cbDark
Box px,py,width+3,height
Color cbWhite
Box px,py,width+3,height,0
y=py+3
For i=1 To CountWords(selections,"|")
txt$=GetWord(selections,i,"|")
If mx>px And mx<px+width And my>y And my<y+txth Then
Color 100,100,100
Box px,y,width,txth
If MouseUp(1) Then ret=i
Color cbWhite
EndIf
Text px+3,y,txt
y=y+txth+3
Next i
If mx<px Or mx>px+width Or my<py Or my>py+height Then button_menu(mut)=0
EndIf
Return ret
EndFunction
Dim mouse_menu(3,2)
Function MouseMenu(click=2,selections$="")
mx=MouseX()
my=MouseY()
txth=TextHeight("A")
px=mouse_menu(click,1)
py=mouse_menu(click,2)
If mouse_menu(click,0)=0 Then
If MouseUp(click) Then
mouse_menu(click,0)=1
mouse_menu(click,1)=mx
mouse_menu(click,2)=my
notn=1
EndIf
EndIf
If mouse_menu(click,0) And notn=0 Then
For i=1 To CountWords(selections,"|")
If TextWidth(GetWord(selections,i,"|"))>width Then width=TextWidth(GetWord(selections,i,"|"))
height=height+txth+6
Next i
width+10
Color cbDark
Box px,py,width+3,height
Color cbWhite
Box px,py,width+3,height,0
y=py+3
For i=1 To CountWords(selections,"|")
txt$=GetWord(selections,i,"|")
If mx>px And mx<px+width And my>y And my<y+txth Then
Color 100,100,100
Box px,y,width,txth
If MouseUp(1) Then ret=i
Color cbWhite
EndIf
Text px+3,y,txt
y=y+txth+3
Next i
If mx<px Or mx>px+width Or my<py Or my>py+height Then mouse_menu(click,0)=0
EndIf
Return ret
EndFunction
// ESIMERKKI
tatti=LoadImage("media/tatti.bmp")
txt$=""
txt2$="Klikkaa minne tahansa hiiren oikealla"
While 1
b1=ButtonMenu(50,50,tatti,"Hello|World|Hello, World!",1,1) // Viimeinen parametri: 1 -> 0
If b1=1 Then txt="Hello"
If b1=2 Then txt="World"
If b1=3 Then txt="Hello, World!"
b2=MouseMenu(2,"Tekijä|Tiedot|Exit")
If b2=1 Then txt3$="Ohjelmoinut Jani."
If b2=2 Then txt3$="Versio 0.3 :: 15.3.2010"
If b2=3 Then Exit
Text 0,0,"Klikkaa tattia. >> "+txt
Text 0,15,txt2
Text 0,30,txt3
DrawScreen
Wait 5
Wend
EDIT:
Korjasin tuon dimin tonne.