here is an include file for my GadAnim in beta state
save and rename it GadAnim.pbi
Code: Select all
;----------------------------------------------------------------------------------------------
;
; Nom : GadAnim.pbi
; Auteur : Flype
; Date : 03/05/2004
; Purebasic : 3.90
;
; Explication du programme :
;
; . Jeu de fonctions pour la création de gadgets animés
; . L'animation est produite par une image dite "tube"
; de la même manière que le jeu de fonctions AnimSprite (Librarie PureTools)
;
; Fonctions Publiques :
;
; . GadAnimButton( #Gadget, x, y, w, h, #Image,ImageNB )
; . GadAnimImage ( #Gadget, x, y, w, h, #Image,ImageNB, Flags )
; . GadAnimStart ( hWnd, #Timer, Delay )
; . GadAnimStop ( hWnd, #Timer )
; . GadAnimPause ()
;
; Fonctions Privées :
;
; . GadAnimRefresh()
;
;----------------------------------------------------------------------------------------------
Declare GadAnimButton(GadgetID.l, x.l, y.l, w.l, h.l, ImageID.l, ImageNB.l)
Declare GadAnimImage(GadgetID.l, x.l, y.l, w.l, h.l, ImageID.l, ImageNB.l, Flags.l)
Declare GadAnimStart(hWindow.l, TimerID.l, Delay.l)
Declare GadAnimStop(hWindow.l, TimerID.l)
Declare GadAnimPause()
Declare GadAnimRefresh()
;----------------------------------------------------------------------------------------------
#GadAnim_MaxImages = 20
;----------------------------------------------------------------------------------------------
Structure GadAnimTimer_Struct
hWindow.l
TimerID.l
Delay.l
EndStructure
Structure GadAnimList_Struct
GadgetID.l
Index.l
Number.l
Images.l[ #GadAnim_MaxImages ]
EndStructure
;----------------------------------------------------------------------------------------------
Global GadAnimTimer.GadAnimTimer_Struct
Global NewList GadAnimList.GadAnimList_Struct()
;----------------------------------------------------------------------------------------------
Procedure GadAnimButton(GadgetID.l, x.l, y.l, w.l, h.l, ImageID.l, ImageNB.l)
hImage.l = ImageID(ImageID)
If hImage=#Null
ProcedureReturn #Null
EndIf
imgWidth = ImageWidth(ImageID)
imgHeight = ImageHeight(ImageID)
imgTileWidth = imgWidth/ImageNB
AddElement(GadAnimList())
GadAnimList()\GadgetID = GadgetID
GadAnimList()\Number = ImageNB-1
GadAnimList()\Index = 0
For i=0 To ImageNB-1
GadAnimList()\Images[i] = ImageID(GrabImage(ImageID,#PB_Any,i*imgTileWidth,0,imgTileWidth,imgHeight))
Next
ProcedureReturn ButtonImageGadget(GadgetID, x, y, w, h, hImage)
EndProcedure
Procedure GadAnimImage(GadgetID.l, x.l, y.l, w.l, h.l, ImageID.l, ImageNB.l, Flags.l)
hImage.l = ImageID(ImageID)
If hImage=#Null
ProcedureReturn #Null
EndIf
imgWidth = ImageWidth(ImageID)
imgHeight = ImageHeight(ImageID)
imgTileWidth = imgWidth/ImageNB
AddElement(GadAnimList())
GadAnimList()\GadgetID = GadgetID
GadAnimList()\Number = ImageNB-1
GadAnimList()\Index = 0
For i=0 To ImageNB-1
GadAnimList()\Images[i] = ImageID(GrabImage(ImageID,#PB_Any,i*imgTileWidth,0,imgTileWidth,imgHeight))
Next
ProcedureReturn ImageGadget(GadgetID, x, y, w, h, hImage, Flags)
EndProcedure
Procedure GadAnimRefresh()
ForEach GadAnimList()
GadAnimList()\Index + 1
If GadAnimList()\Index > GadAnimList()\Number
GadAnimList()\Index = 0
EndIf
SetGadgetState( GadAnimList()\GadgetID, GadAnimList()\Images[GadAnimList()\Index])
Next
EndProcedure
Procedure GadAnimStart(hWindow.l, TimerID.l, Delay.l)
If hWindow<>#Null
GadAnimTimer\hWindow = hWindow
GadAnimTimer\TimerID = TimerID
GadAnimTimer\Delay = Delay
SetTimer_(hWindow,TimerID,Delay,@GadAnimRefresh())
EndIf
EndProcedure
Procedure GadAnimStop(hWindow.l, TimerID.l)
If hWindow<>#Null
KillTimer_(hWindow,TimerID.l)
EndIf
EndProcedure
Procedure GadAnimPause()
Static GadAnimSwitch.b
If GadAnimSwitch
GadAnimStart(GadAnimTimer\hWindow,GadAnimTimer\TimerID,GadAnimTimer\Delay)
Else
GadAnimStop(GadAnimTimer\hWindow,GadAnimTimer\TimerID)
EndIf
GadAnimSwitch = #True - GadAnimSwitch
EndProcedure

