mirror of
https://github.com/FellippeHeitor/InForm.git
synced 2025-01-14 11:39:33 +00:00
Update GIF_IsLoaded() to return true only when the GIF is fully loaded
This commit is contained in:
parent
9e7b10b283
commit
08121bfb4f
6 changed files with 57 additions and 36 deletions
|
@ -280,9 +280,9 @@ $IF GIFPLAY_BAS = UNDEFINED THEN
|
|||
|
||||
' Walk through the animation chain and find the frame we have to render based on the tick we recorded the last time
|
||||
DO UNTIL currentTick < __GIFPlay(idx).lastTick + __GIFPlayFrame(__GIFPlay(idx).frame).duration
|
||||
' Add the current frame duration to the lastTick so that we can do frame skips if needed
|
||||
' Add the current frame duration to lastTick so that we can do frame skips if needed
|
||||
__GIFPlay(idx).lastTick = __GIFPlay(idx).lastTick + __GIFPlayFrame(__GIFPlay(idx).frame).duration
|
||||
' We cross the duration of the current frame, so move to the next one
|
||||
' We crossed the duration of the current frame, so move to the next one
|
||||
__GIFPlay(idx).frame = __GIFPlayFrame(__GIFPlay(idx).frame).nextFrame ' this should correctly loop back to the first frame
|
||||
' Increment the frame counter and loop back to 0 if needed
|
||||
__GIFPlay(idx).frameNumber = __GIFPlay(idx).frameNumber + 1
|
||||
|
@ -373,8 +373,11 @@ $IF GIFPLAY_BAS = UNDEFINED THEN
|
|||
' Returns TRUE if a GIF with Id is loaded
|
||||
FUNCTION GIF_IsLoaded%% (Id AS LONG)
|
||||
SHARED __GIFPlayHashTable() AS HashTableType
|
||||
SHARED __GIFPlay() AS __GIFPlayType
|
||||
|
||||
GIF_IsLoaded = HashTable_IsKeyPresent(__GIFPlayHashTable(), Id)
|
||||
IF HashTable_IsKeyPresent(__GIFPlayHashTable(), Id) THEN
|
||||
GIF_IsLoaded = __GIFPlay(HashTable_LookupLong(__GIFPlayHashTable(), Id)).isReady
|
||||
END IF
|
||||
END FUNCTION
|
||||
|
||||
|
||||
|
@ -597,6 +600,7 @@ $IF GIFPLAY_BAS = UNDEFINED THEN
|
|||
HashTable_InsertLong __GIFPlayHashTable(), Id, idx ' add it to the hash table
|
||||
|
||||
' Reset some stuff
|
||||
__GIFPlay(idx).isReady = FALSE
|
||||
__GIFPlay(idx).firstFrame = -1
|
||||
__GIFPlay(idx).lastFrame = -1
|
||||
__GIFPlay(idx).frame = -1
|
||||
|
@ -719,8 +723,8 @@ $IF GIFPLAY_BAS = UNDEFINED THEN
|
|||
END IF
|
||||
__GIFPlay(idx).lastFrame = frameIdx ' make the last frame to point to this
|
||||
__GIFPlayFrame(frameIdx).disposalMethod = rawFrame.disposalMethod
|
||||
IF rawFrame.duration = 0 THEN rawFrame.duration = 10 ' 0.1 seconds if no duration is specified (this behavior is from the erstwhile GIFPlay library)
|
||||
__GIFPlayFrame(frameIdx).duration = rawFrame.duration * 10 ' convert to ticks (ms)
|
||||
IF rawFrame.duration = 0 THEN rawFrame.duration = 10~% ' 0.1 seconds if no duration is specified (this behavior is from the erstwhile GIFPlay library)
|
||||
__GIFPlayFrame(frameIdx).duration = 10~&& * rawFrame.duration ' convert to ticks (ms)
|
||||
__GIFPlay(idx).duration = __GIFPlay(idx).duration + __GIFPlayFrame(frameIdx).duration ' add the frame duration to the global duration
|
||||
__GIFPlay(idx).frameCount = __GIFPlay(idx).frameCount + 1
|
||||
|
||||
|
@ -787,6 +791,7 @@ $IF GIFPLAY_BAS = UNDEFINED THEN
|
|||
__GIFPlay(idx).lastTick = __GIF_GetTicks
|
||||
DIM dummy AS LONG: dummy = GIF_GetFrame(Id)
|
||||
__GIFPlay(idx).isPlaying = FALSE
|
||||
__GIFPlay(idx).isReady = TRUE ' set the ready flag
|
||||
|
||||
__GIF_Load = TRUE
|
||||
EXIT FUNCTION
|
||||
|
|
|
@ -12,6 +12,7 @@ $IF GIFPLAY_BI = UNDEFINED THEN
|
|||
' This is the master animation type that holds info about a complete animation
|
||||
TYPE __GIFPlayType
|
||||
isUsed AS _BYTE ' is this slot being used (this is only here to assist slot allocation)
|
||||
isReady AS _BYTE ' this is set if the GIF is fully loaded (helps fix issues with InForm-PE TIMERs)
|
||||
image AS LONG ' the rendered 32bpp frame image
|
||||
bgColor AS _UNSIGNED _BYTE ' background color
|
||||
firstFrame AS LONG ' index of the first frame in the frame data array
|
||||
|
|
|
@ -7,36 +7,36 @@ $IF MESSAGEBOX_BI = UNDEFINED THEN
|
|||
$LET MESSAGEBOX_BI = TRUE
|
||||
|
||||
'Messagebox constants
|
||||
CONST MsgBox_OkOnly = 1
|
||||
CONST MsgBox_OkCancel = 2
|
||||
CONST MsgBox_AbortRetryIgnore = 4
|
||||
CONST MsgBox_YesNoCancel = 8
|
||||
CONST MsgBox_YesNo = 16
|
||||
CONST MsgBox_RetryCancel = 32
|
||||
CONST MsgBox_CancelTryagainContinue = 64
|
||||
CONST MsgBox_OkOnly& = 1&
|
||||
CONST MsgBox_OkCancel& = 2&
|
||||
CONST MsgBox_AbortRetryIgnore& = 4&
|
||||
CONST MsgBox_YesNoCancel& = 8&
|
||||
CONST MsgBox_YesNo& = 16&
|
||||
CONST MsgBox_RetryCancel& = 32&
|
||||
CONST MsgBox_CancelTryAgainContinue& = 64&
|
||||
|
||||
CONST MsgBox_Critical = 128
|
||||
CONST MsgBox_Question = 256
|
||||
CONST MsgBox_Exclamation = 512
|
||||
CONST MsgBox_Information = 1024
|
||||
CONST MsgBox_Critical& = 128&
|
||||
CONST MsgBox_Question& = 256&
|
||||
CONST MsgBox_Exclamation& = 512&
|
||||
CONST MsgBox_Information& = 1024&
|
||||
|
||||
CONST MsgBox_DefaultButton1 = 2048
|
||||
CONST MsgBox_DefaultButton2 = 4096
|
||||
CONST MsgBox_DefaultButton3 = 8192
|
||||
CONST MsgBox_Defaultbutton4 = 16384
|
||||
CONST MsgBox_DefaultButton1& = 2048&
|
||||
CONST MsgBox_DefaultButton2& = 4096&
|
||||
CONST MsgBox_DefaultButton3& = 8192&
|
||||
CONST MsgBox_Defaultbutton4& = 16384&
|
||||
|
||||
CONST MsgBox_AppModal = 32768
|
||||
CONST MsgBox_SystemModal = 65536
|
||||
CONST MsgBox_SetForeground = 131072
|
||||
CONST MsgBox_AppModal& = 32768&
|
||||
CONST MsgBox_SystemModal& = 65536&
|
||||
CONST MsgBox_SetForeground& = 131072&
|
||||
|
||||
CONST MsgBox_Ok = 1
|
||||
CONST MsgBox_Yes = 2
|
||||
CONST MsgBox_No = 3
|
||||
CONST MsgBox_Cancel = 4
|
||||
CONST MsgBox_Abort = 5
|
||||
CONST MsgBox_Retry = 6
|
||||
CONST MsgBox_Ignore = 7
|
||||
CONST MsgBox_Tryagain = 8
|
||||
CONST MsgBox_Continue = 9
|
||||
CONST MsgBox_Ok& = 1&
|
||||
CONST MsgBox_Yes& = 2&
|
||||
CONST MsgBox_No& = 3&
|
||||
CONST MsgBox_Cancel& = 4&
|
||||
CONST MsgBox_Abort& = 5&
|
||||
CONST MsgBox_Retry& = 6&
|
||||
CONST MsgBox_Ignore& = 7&
|
||||
CONST MsgBox_TryAgain& = 8&
|
||||
CONST MsgBox_Continue& = 9&
|
||||
|
||||
$END IF
|
||||
|
|
|
@ -8,6 +8,7 @@ DEFLNG A-Z
|
|||
OPTION _EXPLICIT
|
||||
|
||||
': Controls' IDs: ------------------------------------------------------------------
|
||||
DIM SHARED AboutBT AS LONG
|
||||
DIM SHARED gifplaySample AS LONG
|
||||
DIM SHARED PictureBox1 AS LONG
|
||||
DIM SHARED LoadBT AS LONG
|
||||
|
@ -36,6 +37,9 @@ END SUB
|
|||
|
||||
SUB __UI_Click (id AS LONG)
|
||||
SELECT CASE id
|
||||
CASE AboutBT
|
||||
MessageBox "GIFPlay library + InForm-PE demo." + STRING$(2, 10) + "Get it from https://github.com/a740g/InForm-PE", "About " + Caption(gifplaySample), MsgBox_OkOnly + MsgBox_Information
|
||||
|
||||
CASE gifplaySample
|
||||
|
||||
CASE LoadBT
|
||||
|
@ -43,6 +47,9 @@ SUB __UI_Click (id AS LONG)
|
|||
|
||||
IF LEN(fileName) > 0 THEN
|
||||
IF GIF_LoadFromFile(PictureBox1, fileName) THEN
|
||||
' Calculate picturebox width based on the aspect ratio of the GIF
|
||||
Control(PictureBox1).Width = GIF_GetWidth(PictureBox1) / GIF_GetHeight(PictureBox1) * Control(PictureBox1).Height
|
||||
Control(gifplaySample).Width = Control(PictureBox1).Width + Control(LoadBT).Width + 24
|
||||
|
||||
Control(PlayBT).Disabled = FALSE
|
||||
|
||||
|
|
|
@ -7,13 +7,13 @@ SUB __UI_LoadForm
|
|||
|
||||
DIM __UI_NewID AS LONG, __UI_RegisterResult AS LONG
|
||||
|
||||
__UI_NewID = __UI_NewControl(__UI_Type_Form, "gifplaySample", 300, 281, 0, 0, 0)
|
||||
__UI_NewID = __UI_NewControl(__UI_Type_Form, "gifplaySample", 425, 339, 0, 0, 0)
|
||||
__UI_RegisterResult = 0
|
||||
SetCaption __UI_NewID, "GIFPlay Sample"
|
||||
Control(__UI_NewID).Font = SetFont("arial.ttf", 12)
|
||||
Control(__UI_NewID).HasBorder = False
|
||||
|
||||
__UI_NewID = __UI_NewControl(__UI_Type_PictureBox, "PictureBox1", 230, 230, 36, 12, 0)
|
||||
__UI_NewID = __UI_NewControl(__UI_Type_PictureBox, "PictureBox1", 320, 320, 95, 10, 0)
|
||||
__UI_RegisterResult = 0
|
||||
Control(__UI_NewID).Stretch = True
|
||||
Control(__UI_NewID).HasBorder = True
|
||||
|
@ -21,18 +21,25 @@ SUB __UI_LoadForm
|
|||
Control(__UI_NewID).VAlign = __UI_Middle
|
||||
Control(__UI_NewID).BorderSize = 1
|
||||
|
||||
__UI_NewID = __UI_NewControl(__UI_Type_Button, "LoadBT", 123, 23, 36, 247, 0)
|
||||
__UI_NewID = __UI_NewControl(__UI_Type_Button, "LoadBT", 80, 40, 10, 10, 0)
|
||||
__UI_RegisterResult = 0
|
||||
SetCaption __UI_NewID, "&Load"
|
||||
Control(__UI_NewID).HasBorder = False
|
||||
Control(__UI_NewID).CanHaveFocus = True
|
||||
|
||||
__UI_NewID = __UI_NewControl(__UI_Type_Button, "PlayBT", 80, 23, 186, 247, 0)
|
||||
__UI_NewID = __UI_NewControl(__UI_Type_Button, "PlayBT", 80, 40, 10, 55, 0)
|
||||
__UI_RegisterResult = 0
|
||||
SetCaption __UI_NewID, "&Play"
|
||||
Control(__UI_NewID).HasBorder = False
|
||||
Control(__UI_NewID).CanHaveFocus = True
|
||||
|
||||
__UI_NewID = __UI_NewControl(__UI_Type_Button, "AboutBT", 80, 40, 10, 100, 0)
|
||||
__UI_RegisterResult = 0
|
||||
SetCaption __UI_NewID, "&About"
|
||||
Control(__UI_NewID).Stretch = True
|
||||
Control(__UI_NewID).HasBorder = False
|
||||
Control(__UI_NewID).CanHaveFocus = True
|
||||
|
||||
END SUB
|
||||
|
||||
SUB __UI_AssignIDs
|
||||
|
@ -40,4 +47,5 @@ SUB __UI_AssignIDs
|
|||
PictureBox1 = __UI_GetID("PictureBox1")
|
||||
LoadBT = __UI_GetID("LoadBT")
|
||||
PlayBT = __UI_GetID("PlayBT")
|
||||
AboutBT = __UI_GetID("AboutBT")
|
||||
END SUB
|
||||
|
|
BIN
examples/GIFPlaySample/never-gonna.gif
Normal file
BIN
examples/GIFPlaySample/never-gonna.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 221 KiB |
Loading…
Reference in a new issue