Code: Select all
Procedure GadgetEvents()
Select EventGadget()
Case 1 ; set image on image button
Debug "set image on image button"
SetGadgetAttribute(2, #PB_Button_Image, ImageID(0))
Case 2 ; image button test
Debug "image button"
EndSelect
EndProcedure
If OpenWindow(0, 20, 20, 820, 620, "", #PB_Window_SystemMenu | #PB_Window_Background)
Top = 10
GadgetHeight = 24
ButtonGadget(1, 223, Top, 180, GadgetHeight, "<<--- SetGadgetAttribute")
ButtonImageGadget(2, 10, Top, 200, 200, ImageID(0))
TextGadget(3, 10, 220, 400, 25, "Problem: Image on ButtonImageGadget wont load and display at startup, only after clicking button: SetGadgetAttribute")
BindEvent(#PB_Event_Gadget, @GadgetEvents())
CompilerIf #PB_Compiler_OS <> #PB_OS_Web
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
CompilerEndIf
EndIf
OpenWindowedScreen(WindowID(0), 500, 10, 100, 100)
Procedure RenderFrame()
Static x = 100, y = 200
ClearScreen(RGB(0, 0, 0))
If ExamineMouse()
If MouseButton(#PB_MouseButton_Left)
Debug "Left button"
EndIf
EndIf
FlipBuffers() ; continue the rendering
EndProcedure
Procedure Loading(Type, Filename$, ObjectId)
Static NbLoadedElements
NbLoadedElements+1
If NbLoadedElements = 1 ; The loading of all images and sounds is finished, we can start the rendering
FlipBuffers() ; start the rendering
EndIf
EndProcedure
Procedure LoadingError(Type, Filename$, ObjectId)
Debug Filename$ + ": loading error"
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
BindEvent(#PB_Event_RenderFrame, @RenderFrame())
LoadSprite(0, "Data/Spider.png")
LoadImage(0, "Data/knop1.png") ; just a png with a color for test purposes