From d961ab0a8a38db3ef6400b6885e20f730b496466 Mon Sep 17 00:00:00 2001 From: Ian C Date: Fri, 4 Nov 2005 00:13:23 +0000 Subject: Added code to fade menu items between colours. --- gfxmenu.mod/gfxmenu.bmx | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/gfxmenu.mod/gfxmenu.bmx b/gfxmenu.mod/gfxmenu.bmx index 7fe44ea..aaafd16 100644 --- a/gfxmenu.mod/gfxmenu.bmx +++ b/gfxmenu.mod/gfxmenu.bmx @@ -43,15 +43,17 @@ Type TGfxMenu 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. + 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, backdrop:TGfxMenuBackdrop=Null, num:Int=0) + 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 @@ -64,6 +66,7 @@ Type TGfxMenu 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 @@ -81,7 +84,7 @@ Type TGfxMenu 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)) + list.AddLast(TGfxMenuOpt.Create(x,y,i,id,r,g,b)) End Method Rem @@ -105,7 +108,10 @@ Type TGfxMenu For Local opt:TGfxMenuOpt=EachIn list If opt.InBox(mx,my) - SetColor(over_r,over_g,over_b) + 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 @@ -119,7 +125,10 @@ Type TGfxMenu mbdown=False EndIf Else - SetColor(r,g,b) + 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 @@ -130,6 +139,16 @@ Type TGfxMenu 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 @@ -139,8 +158,11 @@ Type TGfxMenuOpt 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) + 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 @@ -151,6 +173,9 @@ Type TGfxMenuOpt o.y=y o.i=i o.id=id + o.r=r + o.g=g + o.b=b Return o End Function -- cgit v1.2.3