From adfafd618a0095396441f765647f18add4d330ea Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 13 Nov 2005 23:37:18 +0000 Subject: Updates for BlitzMax 1.12 --- gfxmenu.mod/gfxmenu.bmx | 372 ++++++++++++++++++++++++------------------------ 1 file changed, 186 insertions(+), 186 deletions(-) (limited to 'gfxmenu.mod/gfxmenu.bmx') diff --git a/gfxmenu.mod/gfxmenu.bmx b/gfxmenu.mod/gfxmenu.bmx index aaafd16..0f2c6fa 100644 --- a/gfxmenu.mod/gfxmenu.bmx +++ b/gfxmenu.mod/gfxmenu.bmx @@ -1,186 +1,186 @@ -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 - Field fade: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. @fade is the amount colours will alter as the - about: mouse hovers over buttons. Set this to 255 to make colour changes instant. - 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, fade:Int=5, 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 - menu.fade=fade - - 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,r,g,b)) - 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) - opt.r=Towards(over_r,opt.r) - opt.g=Towards(over_g,opt.g) - opt.b=Towards(over_b,opt.b) - SetColor(opt.r,opt.g,opt.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 - opt.r=Towards(r,opt.r) - opt.g=Towards(g,opt.g) - opt.b=Towards(b,opt.b) - SetColor(opt.r,opt.g,opt.b) - DrawImage(opt.i,opt.x,opt.y) - EndIf - Next - - If Not any - mbdown=False - EndIf - - Return in - End Method - - Method Towards:Int(dest:Int, val:Int) - If valdest - Return Max(dest,val-fade) - EndIf - - Return val - End Method -End Type - -Private - -Type TGfxMenuOpt - Field x:Int - Field y:Int - Field i:TImage - Field id:Int - Field r:Int - Field g:Int - Field b:Int - - Function Create:TGfxMenuOpt(x:Int, y:Int, i:TImage, id:Int, r:Int, g:Int, b: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 - o.r=r - o.g=g - o.b=b - - 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 +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 + Field fade: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. @fade is the amount colours will alter as the + about: mouse hovers over buttons. Set this to 255 to make colour changes instant. + 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, fade:Int=5, 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 + menu.fade=fade + + 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,r,g,b)) + 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) + opt.r=Towards(over_r,opt.r) + opt.g=Towards(over_g,opt.g) + opt.b=Towards(over_b,opt.b) + SetColor(opt.r,opt.g,opt.b) + + If KeyDown(MOUSE_LEFT) + 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 + opt.r=Towards(r,opt.r) + opt.g=Towards(g,opt.g) + opt.b=Towards(b,opt.b) + SetColor(opt.r,opt.g,opt.b) + DrawImage(opt.i,opt.x,opt.y) + EndIf + Next + + If Not any + mbdown=False + EndIf + + Return in + End Method + + Method Towards:Int(dest:Int, val:Int) + If valdest + Return Max(dest,val-fade) + EndIf + + Return val + End Method +End Type + +Private + +Type TGfxMenuOpt + Field x:Int + Field y:Int + Field i:TImage + Field id:Int + Field r:Int + Field g:Int + Field b:Int + + Function Create:TGfxMenuOpt(x:Int, y:Int, i:TImage, id:Int, r:Int, g:Int, b: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 + o.r=r + o.g=g + o.b=b + + 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 -- cgit v1.2.3