1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
'
' Provides simple menus
'
' $Id$
'
Strict
Import noddybox.bitmapfont
Type TMenu
Field list:TList
Field img:TImage
Field font:TBitmapFont
Field ypos:Int
Field xpos:Int
Field yoff:Int
Field w:Int
Field h:Int
Field count:Int
Field mbdown:Int
Function Create:TMenu(f:TBitmapFont, img:TImage, y:Int)
Local menu:TMenu=New TMenu
menu.list=New TList
menu.img=img
menu.font=f
menu.ypos=y
menu.w=ImageWidth(img)
menu.h=ImageHeight(img)
menu.xpos=GraphicsWidth()/2-menu.w/2
menu.yoff=menu.h/2-f.TextHeight("X")/2
menu.mbdown=False
Return menu
End Function
Method Add(s:String)
list.AddLast(s)
End Method
' Returns the selected item, or "" for none
'
Method Render:String()
Local y:Int=ypos
Local in:String=""
Local mx:Int=MouseX()
Local my:Int=MouseY()
Local any:Int=False
For Local s:String=EachIn list
If (mx>xpos And mx<xpos+w And my>y And my<y+h)
If MouseDown(1)
mbdown=True
DrawImage(img,xpos,y+2)
font.Centre(s,y+yoff+2,255,255,0)
any=True
Else
DrawImage(img,xpos,y)
font.Centre(s,y+yoff,255,255,0)
If mbdown
in=s
EndIf
mbdown=False
EndIf
Else
DrawImage(img,xpos,y)
font.Centre(s,y+yoff,128,128,0)
EndIf
y:+h+20
Next
If Not any
mbdown=False
EndIf
Return in
End Method
End Type
|