Adding a lot of images to a ListIconGadget...
Posted: Tue Jul 27, 2010 10:26 pm
The following code snippets are from my large project, where I load a list of country names with their related flag into a list in a ListIconGadget.
On Windows all is working fine, but on MacOS I get a lot GFX errors, when the flags should be displayed in front of the country names in the ListIcon.
The "trick" is: The flag image gets loaded, added to the listicon, and then freed. The same then for every of the >250 countries/flags...
Now my question:
Is this a misbehaviour of PB / MacOS?
Or it's a "ugly" programming trick, which works on Windows but don't work on MacOS? In this case I must load every flag image into a separate ImageID, before adding the ImageIDs via AddGadgetItem() to the ListIcon...
Or do you have any other suggestions?
On Windows all is working fine, but on MacOS I get a lot GFX errors, when the flags should be displayed in front of the country names in the ListIcon.
The "trick" is: The flag image gets loaded, added to the listicon, and then freed. The same then for every of the >250 countries/flags...
Code: Select all
Procedure LoadFlagImage()
Protected image.i
If IsImage(0)
FreeImage(0)
EndIf
If IsImage(1)
FreeImage(1)
EndIf
;DisableDebugger ; because else each missing flag would call a "Image filename not found" error"
If LoadImage(0, path$ + "Flags/small/"+LCase(Countries()\ISO3166A2)+".png")
CreateImage(1,16,16)
StartDrawing(ImageOutput(1)) ; the loaded flags are 16x11 pixel only
Box(0, 0, 16, 16, RGB(255, 255, 255)) ; so we draw a white background...
DrawImage(ImageID(0), 0, 3) ; and paint the image on it
StopDrawing()
image = ImageID(1)
Else
image = 0
Debug "Image loading failed for: " + LCase(Countries()\ISO3166A2) + ".png"
EndIf
;EnableDebugger ; enable the debugger for the further program
ProcedureReturn image
EndProcedure
; snippet from the code, which is calling the LoadFlagImage() routine and add the flag image to the ListIcon:
ForEach Countries()
image = LoadFlagImage() ; Note: Countries() list must be active, so the ISO3166A2 field of is available
AddGadgetItem(#Gadget_CountryList, index, Countries()\Name, image)
index + 1
Next
Is this a misbehaviour of PB / MacOS?
Or it's a "ugly" programming trick, which works on Windows but don't work on MacOS? In this case I must load every flag image into a separate ImageID, before adding the ImageIDs via AddGadgetItem() to the ListIcon...
Or do you have any other suggestions?