gambas-source-code/app/examples/Image/PhotoTouch/.src/CAnimation.class
Benoît Minisini c6a9cd69c2 [EXAMPLES]
* NEW: Add examples again. I hope correctly this time.


git-svn-id: svn://localhost/gambas/trunk@6726 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2014-12-12 19:58:52 +00:00

97 lines
1.7 KiB
Text

' Gambas class file
Static Private All As New CAnimation[]
Property Read Object As Object
Private $hObject As Object
Private $sProperty As String
Private $fTarget As Float
Private $fTime As Float
Private $hTimer As Timer
Static Public Sub Start(hObject As Control, sProperty As String, fTarget As Float, iTime As Integer)
Dim hAnim As CAnimation
Dim aStop As New CAnimation[]
For Each hAnim In All
If hAnim.Object = hObject Then aStop.Add(hAnim)
Next
For Each hAnim In aStop
hAnim.Stop
Next
hAnim = New CAnimation(hObject, sProperty, fTarget, iTime)
All.Add(hAnim)
End
Static Public Sub Exit()
While All.Count
All[0].Stop
Wend
End
Public Sub _new(hObject As Control, sProperty As String, fTarget As Float, iTime As Integer)
'Debug hObject.Tag;; sProperty;; fTarget
$hObject = hObject
$sProperty = sProperty
$fTarget = fTarget
$fTime = Timer + iTime / 1000
$hTimer = New Timer As "Timer"
$hTimer.Delay = 50
$hTimer.Start
End
Public Sub Timer_Timer()
Dim fValue As Float
Dim iSign As Integer
fValue = Object.GetProperty($hObject, $sProperty)
If Abs(fValue - $fTarget) < 1E-6 Then
Object.SetProperty($hObject, $sProperty, $fTarget)
{Stop}
Else
iSign = Sgn($fTarget - fValue)
fValue += ($fTarget - fValue) / (1000 * ($fTime - Timer) / $hTimer.Delay)
If Sgn($fTarget - fValue) <> iSign Then
Object.SetProperty($hObject, $sProperty, $fTarget)
{Stop}
Else
Object.SetProperty($hObject, $sProperty, fValue)
Endif
Endif
Catch
{Stop}
End
Public Sub Stop()
$hTimer.Stop
$hTimer = Null
$hObject = Null
All.Remove(All.Find(Me))
End
Private Function Object_Read() As Object
Return $hObject
End