summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-11-04 00:13:23 +0000
committerIan C <ianc@noddybox.co.uk>2005-11-04 00:13:23 +0000
commitd961ab0a8a38db3ef6400b6885e20f730b496466 (patch)
treed8eea43eec92f0d60c0be079e5cd8f0a7e73194c
parentb4b197bc851f82b63fe0d7ad51be915faa38692f (diff)
Added code to fade menu items between colours.
-rw-r--r--gfxmenu.mod/gfxmenu.bmx37
1 files 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 val<dest
+ Return Min(dest,val+fade)
+ ElseIf val>dest
+ 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