summaryrefslogtreecommitdiff
path: root/menu.bmx
diff options
context:
space:
mode:
Diffstat (limited to 'menu.bmx')
-rw-r--r--menu.bmx129
1 files changed, 129 insertions, 0 deletions
diff --git a/menu.bmx b/menu.bmx
new file mode 100644
index 0000000..f156891
--- /dev/null
+++ b/menu.bmx
@@ -0,0 +1,129 @@
+' 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.
+ '
+ Method Render:Int()
+ Local in:Int=-1
+ Local mx:Int=MouseX()
+ Local my:Int=MouseY()
+ Local any:Int=False
+
+ SetAlpha(0.5)
+ For Local p:TMenuBdrop=EachIn bdrop
+ p.Update()
+ Next
+ SetAlpha(1)
+
+ For Local opt:TMenuOpt=EachIn list
+ If opt.InBox(mx,my)
+ SetColor(255,255,200)
+
+ If KeyDown(KEY_MOUSELEFT)
+ 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(200,200,200)
+ 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 \ No newline at end of file