summaryrefslogtreecommitdiff
path: root/menu.bmx
diff options
context:
space:
mode:
Diffstat (limited to 'menu.bmx')
-rw-r--r--menu.bmx76
1 files changed, 76 insertions, 0 deletions
diff --git a/menu.bmx b/menu.bmx
new file mode 100644
index 0000000..b441a0f
--- /dev/null
+++ b/menu.bmx
@@ -0,0 +1,76 @@
+'
+' Provides simple menus
+'
+' $Id$
+'
+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 KeyDown(KEY_MOUSELEFT)
+ 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 \ No newline at end of file