From 7ff4818c925a84230b5f5386fd90198f6419044a Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 2 Oct 2005 02:08:48 +0000 Subject: Added initial Menu code. --- menu.bmx | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 menu.bmx (limited to 'menu.bmx') 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 -- cgit v1.2.3