Loading icons using a timer
Posted: Tue Feb 13, 2024 4:04 pm
The timer has low priority so it runs when the icons are already loaded
Code: Select all
#Window = 0
#Menu3 = 3
Enumeration
#btnMenu
EndEnumeration
Global IsLoad
Global g_Timer
Global Dim icons(3)
Procedure Loaded(Type, Filename$, ID)
Select Mid(Filename$, Len(Filename$) - 4, 1)
Case "1"
icons(0) = ImageID(ID)
IsLoad + 1
Case "2"
icons(1) = ImageID(ID)
IsLoad + 1
Case "3"
icons(2) = ImageID(ID)
IsLoad + 1
Case "4"
icons(3) = ImageID(ID)
IsLoad + 1
EndSelect
EndProcedure
BindEvent(#PB_Event_Loading, @Loaded())
LoadImage(0, "./data/p/1.png")
LoadImage(1, "./data/p/2.png")
LoadImage(2, "./data/p/3.png")
LoadImage(3, "./data/p/4.png")
Procedure TimerEvents()
g_Timer + 1
If IsLoad = 4 Or g_Timer > 3
If CreatePopupImageMenu(#Menu3)
MenuItem(0, "Home", icons(0))
MenuItem(1, "Settings", icons(1))
MenuItem(2, "Help", icons(2))
MenuItem(3, "About", icons(3))
EndIf
RemoveWindowTimer(#Window, 0)
EndIf
EndProcedure
Procedure btnMenu()
; g_flgMenu = 3
DisplayPopupMenu(#Menu3, WindowID(#Window), 0, 31)
EndProcedure
;- GUI
If OpenWindow(#Window, 0, 0, ww, hh, "", #PB_Window_Background)
ButtonGadget(#btnMenu, 0, 0, 30, 30, Chr($2630)))
BindGadgetEvent(#btnMenu, @btnMenu())
AddWindowTimer(#Window, 0, 100)
BindEvent(#PB_Event_Timer, @TimerEvents())
Else
End
EndIf