Fun With FryGUI
BlitzMax Forums/BlitzMax Programming/Fun With FryGUI
| ||
| Thought I would post this before I have to move on to something that pays the bills: Once upon a time when I was a Blitz3D junkie, I got a hold of the brilliant SpriteCandy. When I moved to BlitzMax that was the once thing I missed. When I found FryGUI, I began to use it for almost everything I do that needs a GUI in BlitzMax. Here is a quick, dirty and likely terribly implementation of some SpriteCandy like goodness in FryGUI, mainly "move to" and "fade" functions for buttons and labels. I might extend this to use for a project, if anyone wants to point out where it could be improved, I am all ears. files: www.maasscreativelabs.com/FryGUITest.zip Press keys 1-4 to do stuff.
SuperStrict
Import Fry.FryGUI
SetGraphicsDriver D3D7Max2DDriver()
Global screenWidth:Int = 320
Global screenHeight:Int = 240
SeedRnd MilliSecs()
Global seed:Int=RndSeed()
Type gadbutton
Field name:String
Field gadgetbutton:fry_TButton
Field alpha:Float
Field fadeflag:Int
End Type
' the gad list
Global gadlist:TList = New TList
Type gadlabel
Field name:String
Field gadgetlabel:fry_TLabel
Field alpha:Float
Field labelx:Float
Field labely:Float
Field destx:Float
Field desty:Float
Field damping:Int
Field fadeflag:Int ' 0=none,1=in,2=out
Field moveflag:Int
Field moving:Float
Field ymoving:Float
Field stopmove:Float
End Type
' the gad list
Global labellist:TList = New TList
'set up the graphics and blend mode before loading the GUI
AppTitle = "Test"
Graphics screenWidth, screenHeight, 0, 0
fry_SetResolution(screenWidth, screenHeight)
fry_SystemCursor(False)
SetBlend alphablend
'load in a skin for the GUI
fry_LoadSkin("Skin")
'add the fonts to the GUI. Fonts will be referenced by their names.
fry_AddFont("Default", "trebucbd.ttf", 24)
fry_AddFont("Large", "trebucbd.ttf", 24)
fry_AddFont("labelfont", "arialbd.ttf", 24)
'create the screens
Local startscreen:fry_TScreen = fry_CreateScreen("start")
'create panels
Local startpanel:fry_TPanel = fry_CreatePanel("start panel", 0, 0, 320, 240)
'set the panel colours using hexadecimal colour values (R, G, B can also be used with SetColour())
startpanel.HexColour("000000")
'add the panels to the screens.
startscreen.AddPanel(startpanel)
'Set the initial screen - failure to do this will crash the GUI
fry_SetScreen("start")
'buttons
Local mygadbutton:gadbutton
mygadbutton = New gadbutton
mygadbutton.name = "start_button"
mygadbutton.gadgetbutton = fry_CreateImageButton("start_button", "assets/start_button.png", 0, 0, 312, 71, startpanel)
mygadbutton.alpha = 0.0
mygadbutton.fadeflag = 0
mygadbutton.gadgetbutton.SetAlpha(mygadbutton.alpha,0)
mygadbutton.gadgetbutton.SetLink(startscreen)
gadlist.AddLast(mygadbutton)
'labels
Local mylabel:gadlabel
mylabel = New gadlabel
mylabel.name = "test1"
mylabel.labelx = 10.0
mylabel.labely = 200.0
mylabel.moveflag = 0
mylabel.moving = 4.0
mylabel.ymoving = 0.0
mylabel.gadgetlabel = fry_CreateLabel("test1", "Hello", mylabel.labelx, mylabel.labely, 400, 20, 1, 1, startpanel)
mylabel.alpha = 0.0
mylabel.gadgetlabel.SetAlpha(mylabel.alpha,0)
'leftlabel.HexTextColour("FFFFFF")
mylabel.gadgetlabel.HexTextColour("FFFF00")
mylabel.gadgetlabel.SetFont("labelfont")
mylabel.fadeflag = 0
labellist.AddLast(mylabel)
mylabel = New gadlabel
mylabel.name = "test2"
mylabel.labelx = 50.0
mylabel.labely = 100.0
mylabel.moveflag = 0
mylabel.moving = 4.0
mylabel.ymoving = 0.0
mylabel.gadgetlabel = fry_CreateLabel("test2", "World!", mylabel.labelx, mylabel.labely, 400, 20, 1, 1, startpanel)
mylabel.alpha = 1.0
mylabel.gadgetlabel.SetAlpha(mylabel.alpha,0)
'leftlabel.HexTextColour("FFFFFF")
mylabel.gadgetlabel.HexTextColour("FFFF00")
mylabel.gadgetlabel.SetFont("labelfont")
mylabel.fadeflag = 0
labellist.AddLast(mylabel)
While Not AppTerminate()
PollSystem
Cls
'Refresh the GUI
fry_Refresh()
fadeButton()
fadeinlabel()
movelabel()
If KeyHit(KEY_1)
setbuttonfadeflag("start_button",1)
setlabelfadeflag("test1",1)
EndIf
If KeyHit(KEY_2)
setbuttonfadeflag("start_button",2)
setlabelfadeflag("test1",2)
EndIf
If KeyHit(KEY_3)
Local xm:Float = Rnd(10.0, 300.0)
Local xy:Float = Rnd(10.0, 200.0)
Local spd:Float = Rand(10.0,100.0)
setlabelmoveflag( "test1",xm,xy,spd)
EndIf
If KeyHit(KEY_4)
Local xm:Float = Rnd(10.0, 300.0)
Local xy:Float = Rnd(10.0, 200.0)
Local spd:Float = Rand(10.0,100.0)
setlabelmoveflag( "test2",xm,xy,spd)
EndIf
Flip
GCCollect()
Wend
Function fadeButton()
For Local g:gadbutton = EachIn gadlist
If g.fadeflag = 1
If g.alpha < 1.0
g.alpha = g.alpha + 0.005
g.gadgetbutton.SetAlpha(g.alpha ,0)
EndIf
If g.alpha >= 1.0 Then g.fadeflag = 0
EndIf
If g.fadeflag = 2
If g.alpha > 0.0
g.alpha = g.alpha - 0.005
g.gadgetbutton.SetAlpha(g.alpha ,0)
EndIf
If g.alpha <= 0.0 Then g.fadeflag = 0
EndIf
Next
End Function
Function setbuttonfadeflag(buttonname:String,fadetype:Int)
For Local g:gadbutton = EachIn gadlist
If g.name = buttonname
g.fadeflag = fadetype
EndIf
Next
End Function
Function fadeinlabel()
For Local l:gadlabel = EachIn labellist
If l.fadeflag = 1
If l.alpha < 1.0
l.alpha = l.alpha + 0.002
l.gadgetlabel.SetAlpha(l.alpha ,0)
EndIf
If l.alpha >= 1.0 Then l.fadeflag = 0
EndIf
If l.fadeflag = 2
If l.alpha > 0.0
l.alpha = l.alpha - 0.002
l.gadgetlabel.SetAlpha(l.alpha ,0)
EndIf
If l.alpha <= 0.0 Then l.fadeflag = 0
EndIf
Next
End Function
Function setlabelfadeflag(labelname:String,fadetype:Int)
For Local l:gadlabel = EachIn labellist
If l.name = labelname
l.fadeflag = fadetype
EndIf
Next
End Function
Function setlabelmoveflag(labelname:String,dx:Float,dy:Float,dmp:Float)
For Local l:gadlabel = EachIn labellist
If l.name = labelname
l.moveflag = 1
l.moving = l.labelx
l.ymoving = l.labely
l.destx = dx
l.desty = dy
l.damping = dmp
EndIf
Next
End Function
Function movelabel()
For Local l:gadlabel = EachIn labellist
If l.moveflag = 1
l.moving = curvevalue(l.destx,l.moving,l.damping)
If l.moving = l.stopmove
l.moveflag = 0
EndIf
l.ymoving = curvevalue(l.desty,l.ymoving,l.damping)
l.gadgetlabel.PositionGadget(l.moving,l.ymoving)
l.labelx = l.moving
l.labely = l.ymoving
l.stopmove = l.moving
EndIf
Next
End Function
Function curvevalue:Float(newvalue:Float,oldvalue:Float,increments:Float)
If increments > 1.0 Then oldvalue = oldvalue - (oldvalue - newvalue) / increments
If increments <= 1.0 Then oldvalue = newvalue
Return oldvalue
End Function
|