summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-11-01 23:43:37 +0000
committerIan C <ianc@noddybox.co.uk>2005-11-01 23:43:37 +0000
commitb4b197bc851f82b63fe0d7ad51be915faa38692f (patch)
tree8fa0df8c9049a0d8eda458d17d41dcf7dc64b7b7
parent53cc1b3be81ac220f6353bb5206b667261b3eab6 (diff)
Added TGfxMenu class.
-rw-r--r--gfxmenu.mod/.cvsignore6
-rw-r--r--gfxmenu.mod/gfxmenu.bmx161
2 files changed, 167 insertions, 0 deletions
diff --git a/gfxmenu.mod/.cvsignore b/gfxmenu.mod/.cvsignore
new file mode 100644
index 0000000..9565593
--- /dev/null
+++ b/gfxmenu.mod/.cvsignore
@@ -0,0 +1,6 @@
+gfxmenu.release.win32.i
+gfxmenu.debug.win32.a
+gfxmenu.debug.win32.i
+gfxmenu.release.win32.a
+.bmx
+doc
diff --git a/gfxmenu.mod/gfxmenu.bmx b/gfxmenu.mod/gfxmenu.bmx
new file mode 100644
index 0000000..7fe44ea
--- /dev/null
+++ b/gfxmenu.mod/gfxmenu.bmx
@@ -0,0 +1,161 @@
+Rem
+bbdoc: noddybox.gfxmenu
+EndRem
+Module noddybox.gfxmenu
+
+ModuleInfo "Framework: Simple Graphical Menu"
+ModuleInfo "Copyright: Public Domain"
+ModuleInfo "Author: Ian Cowburn"
+ModuleInfo "Version: $Revision$"
+
+' $Id$
+
+Strict
+Import brl.linkedlist
+Import brl.max2d
+
+Rem
+bbdoc: Allows a menu backdrop to be automatically processed. Derive a class from this to use.
+EndRem
+Type TGfxMenuBackdrop Abstract
+ Rem
+ bbdoc: Create a menu backdrop element.
+ returns: The created elemnt.
+ about: Notice that this is a method, rather than the usual function creator.
+ EndRem
+ Method Create:TGfxMenuBackdrop() Abstract
+ Rem
+ bbdoc: Called by the menu to update the backdrop.
+ EndRem
+ Method Update() Abstract
+End Type
+
+Rem
+bbdoc: Defines a graphical menu.
+EndRem
+Type TGfxMenu
+ Field list:TList
+ Field bdrop:TList
+ Field mbdown:Int
+ Field r:Int
+ Field g:Int
+ Field b:Int
+ Field over_r:Int
+ Field over_g:Int
+ Field over_b:Int
+
+ Rem
+ bbdoc: Create a menu.
+ returns: The created menu.
+ about: @backdrop is the backdrop to create (null for no backdrop). @num is the number of backdrop items to create.
+ about: SetColor() is called with @r, @g and @b when the mouse is not over an item, overwise SetColor() is
+ about: called with @over_r, @over_g and @over_b when the item is active.
+ EndRem
+ Function Create:TGfxMenu(r:Int=164, g:Int=164, b:Int=164, over_r:Int=255, over_g:Int=255, over_b:Int=255, backdrop:TGfxMenuBackdrop=Null, num:Int=0)
+ Local menu:TGfxMenu=New TGfxMenu
+
+ menu.list=New TList
+ menu.bdrop=New TList
+ menu.mbdown=False
+
+ menu.r=r
+ menu.g=g
+ menu.b=b
+ menu.over_r=over_r
+ menu.over_g=over_g
+ menu.over_b=over_b
+
+ If backdrop
+ For Local f:Int=0 Until num
+ menu.bdrop.AddLast(backdrop.Create())
+ Next
+ EndIf
+
+ Return menu
+ End Function
+
+ Rem
+ bbdoc: Adds a menu item.
+ returns: The created menu.
+ about: @x and @y are the position to draw the image at. If @x is -1 then the image is centred. @i is the image.
+ about: @id is the value returned from @Render() for this menu item. Don't use -1 for this!
+ EndRem
+ Method Add(x:Int, y:Int, i:TImage, id:Int)
+ list.AddLast(TGfxMenuOpt.Create(x,y,i,id))
+ End Method
+
+ Rem
+ bbdoc: Renders and updates the menu.
+ returns: The selected item, or -1 if nothing clicked.
+ about: Set @hide to True to hide the menu (the backdrop is still updated). SetColor() may have changed when this routine exits.
+ EndRem
+ Method Render:Int(hide:Int)
+ For Local p:TGfxMenuBackdrop=EachIn bdrop
+ p.Update()
+ Next
+
+ If hide
+ Return -1
+ EndIf
+
+ Local in:Int=-1
+ Local mx:Int=MouseX()
+ Local my:Int=MouseY()
+ Local any:Int=False
+
+ For Local opt:TGfxMenuOpt=EachIn list
+ If opt.InBox(mx,my)
+ SetColor(over_r,over_g,over_b)
+
+ 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(r,g,b)
+ DrawImage(opt.i,opt.x,opt.y)
+ EndIf
+ Next
+
+ If Not any
+ mbdown=False
+ EndIf
+
+ Return in
+ End Method
+End Type
+
+Private
+
+Type TGfxMenuOpt
+ Field x:Int
+ Field y:Int
+ Field i:TImage
+ Field id:Int
+
+ Function Create:TGfxMenuOpt(x:Int, y:Int, i:TImage, id:Int)
+ Local o:TGfxMenuOpt=New TGfxMenuOpt
+
+ 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