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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
' Particle Pinch
'
' Copyright 2005 Ian Cowburn
'
' $Id$
'
Strict
Import "types.bmx"
Type TMenu
Field list:TList
Field bdrop:TList
Field mbdown:Int
Function Create:TMenu()
Local menu:TMenu=New TMenu
menu.list=New TList
menu.bdrop=New TList
menu.mbdown=False
For Local f:Int=0 To 500
menu.bdrop.AddLast(New TMenuBdrop)
Next
Return menu
End Function
Method Add(x:Int, y:Int, i:TImage, id:Int)
list.AddLast(TMenuOpt.Create(x,y,i,id))
End Method
' Returns the selected item, or -1 for none. Err, so don't use -1 as an ID. Set hide to remove the buttons.
'
Method Render:Int(hide:Int)
SetAlpha(0.5)
For Local p:TMenuBdrop=EachIn bdrop
p.Update()
Next
SetAlpha(1)
If hide
Return -1
EndIf
Local in:Int=-1
Local mx:Int=MouseX()
Local my:Int=MouseY()
Local any:Int=False
For Local opt:TMenuOpt=EachIn list
If opt.InBox(mx,my)
SetColor(255,255,255)
If MouseDown(1)
mbdown=True
DrawImage(opt.i,opt.x,opt.y+2)
any=True
Else
DrawImage(opt.i,opt.x,opt.y)
If mbdown
in=opt.id
EndIf
mbdown=False
EndIf
Else
SetColor(164,164,164)
DrawImage(opt.i,opt.x,opt.y)
EndIf
Next
If Not any
mbdown=False
EndIf
Return in
End Method
End Type
Type TMenuOpt
Field x:Int
Field y:Int
Field i:TImage
Field id:Int
Function Create:TMenuOpt(x:Int, y:Int, i:TImage, id:Int)
Local o:TMenuOpt=New TMenuOpt
If x=-1
x=(GraphicsWidth()-ImageWidth(i))/2
EndIf
o.x=x
o.y=y
o.i=i
o.id=id
Return o
End Function
Method InBox:Int(mx:Int, my:Int)
Return mx>=x And my>=y And mx<=x+ImageWidth(i) And my<=y+ImageHeight(i)
End Method
End Type
Type TMenuBdrop
Field r:Int
Field g:Int
Field b:Int
Field x:Double
Field y:Double
Field yi:Double
Method New()
r=Rand(128,255)
g=Rand(128,255)
b=Rand(128,255)
x=Rnd(0,GraphicsWidth())
y=Rnd(0,GraphicsHeight())
yi=Rnd(0.1,3)
End Method
Method Update()
SetColor(r,g,b)
DrawImage(GameGFX.point,x,y)
y:+yi
If y>GraphicsHeight()
y=0
EndIf
End Method
End Type
|