1
1
Fork 0
mirror of https://github.com/FellippeHeitor/InForm.git synced 2025-01-15 03:49:56 +00:00
InForm/examples/GIFPlaySample/GIFPlaySample.bas

121 lines
3.6 KiB
QBasic
Raw Normal View History

2023-11-19 04:53:36 +00:00
': This program uses
': InForm - GUI library for QB64 - Beta version 9
': Fellippe Heitor, 2016-2019 - fellippe@qb64.org - @fellippeheitor
': https://github.com/FellippeHeitor/InForm
'-----------------------------------------------------------
DEFLNG A-Z
OPTION _EXPLICIT
2023-11-19 04:53:36 +00:00
': Controls' IDs: ------------------------------------------------------------------
DIM SHARED DoneProgressBar AS LONG
DIM SHARED AboutButton AS LONG
DIM SHARED GIFPlaySample AS LONG
DIM SHARED GIFPictureBox AS LONG
DIM SHARED LoadButton AS LONG
DIM SHARED PlayButton AS LONG
2023-11-19 04:53:36 +00:00
': External modules: ---------------------------------------------------------------
'$INCLUDE:'../../InForm/extensions/GIFPlay.bi'
'$INCLUDE:'../../InForm/InForm.bi'
2023-11-19 04:53:36 +00:00
'$INCLUDE:'GIFPlaySample.frm'
'$INCLUDE:'../../InForm/InForm.ui'
'$INCLUDE:'../../InForm/extensions/GIFPlay.bas'
2023-11-19 04:53:36 +00:00
': Event procedures: ---------------------------------------------------------------
SUB __UI_BeforeInit
END SUB
SUB __UI_OnLoad
Control(PlayButton).Disabled = TRUE
Control(DoneProgressBar).Disabled = TRUE
2023-11-19 04:53:36 +00:00
END SUB
SUB __UI_BeforeUpdateDisplay
IF GIF_IsLoaded(GIFPictureBox) THEN
GIF_Draw GIFPictureBox
Control(DoneProgressBar).Value = (GIF_GetElapsedTime(GIFPictureBox) / GIF_GetTotalDuration(GIFPictureBox)) * 100
END IF
2023-11-19 04:53:36 +00:00
END SUB
SUB __UI_BeforeUnload
END SUB
SUB __UI_Click (id AS LONG)
SELECT CASE id
CASE DoneProgressBar
CASE AboutButton
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
2023-11-19 04:53:36 +00:00
CASE GIFPlaySample
CASE LoadButton
DIM fileName AS STRING: fileName = _OPENFILEDIALOG$(Caption(GIFPlaySample), , "*.gif|*.GIF|*.Gif", "GIF Files")
2023-11-20 06:46:45 +00:00
IF LEN(fileName) > 0 THEN
IF GIF_LoadFromFile(GIFPictureBox, fileName) THEN
' Calculate picturebox width based on the aspect ratio of the GIF
Control(GIFPictureBox).Width = GIF_GetWidth(GIFPictureBox) / GIF_GetHeight(GIFPictureBox) * Control(GIFPictureBox).Height
Control(GIFPlaySample).Width = Control(GIFPictureBox).Width + Control(LoadButton).Width + 24
Control(DoneProgressBar).Width = Control(GIFPictureBox).Width
2023-11-20 06:46:45 +00:00
Control(DoneProgressBar).Disabled = FALSE
2023-11-20 06:46:45 +00:00
IF GIF_GetTotalFrames(GIFPictureBox) > 1 THEN
Control(PlayButton).Disabled = FALSE
Caption(PlayButton) = "Play"
2023-11-20 06:46:45 +00:00
ELSE
Control(PlayButton).Disabled = TRUE
2023-11-20 06:46:45 +00:00
END IF
2023-11-19 04:53:36 +00:00
ELSE
Control(PlayButton).Disabled = TRUE
Control(DoneProgressBar).Disabled = TRUE
2023-11-20 06:46:45 +00:00
MessageBox fileName + " failed to load!", "", MsgBox_Exclamation
2023-11-19 04:53:36 +00:00
END IF
END IF
2023-11-20 06:46:45 +00:00
CASE PlayButton
IF GIF_IsPlaying(GIFPictureBox) THEN
GIF_Pause GIFPictureBox
Caption(PlayButton) = "Play"
2023-11-19 04:53:36 +00:00
ELSE
GIF_Play GIFPictureBox
Caption(PlayButton) = "Pause"
2023-11-19 04:53:36 +00:00
END IF
2023-11-20 06:46:45 +00:00
CASE GIFPictureBox
GIF_EnableOverlay GIFPictureBox, FALSE
2023-11-19 04:53:36 +00:00
END SELECT
END SUB
SUB __UI_MouseEnter (id AS LONG)
END SUB
SUB __UI_MouseLeave (id AS LONG)
END SUB
SUB __UI_FocusIn (id AS LONG)
END SUB
SUB __UI_FocusOut (id AS LONG)
END SUB
SUB __UI_MouseDown (id AS LONG)
END SUB
SUB __UI_MouseUp (id AS LONG)
END SUB
SUB __UI_KeyPress (id AS LONG)
END SUB
SUB __UI_TextChanged (id AS LONG)
END SUB
SUB __UI_ValueChanged (id AS LONG)
END SUB
SUB __UI_FormResized
END SUB