3.20 Image cache

Many MOAI classes allow you to use icons with the widgets they create, e.g. you can add an icon to a button widget by simply using the Button.Icon attribute. All MOAI classes that can deal with icons require you to pass either a Hollywood brush or a Hollywood icon that shall be used as the icon to the class.

What is important to know now is that RapaGUI caches these images for reasons of performance and economy. Just imagine a listview with thousands of rows and an icon in each of them. It would be an absolute performance killer if RapaGUI had to convert these icons from a Hollywood brush/icon into a RapaGUI image for every single row. That's why the images are cached.

Take a look at this example:

 
<button id="ok" icon="1">OK</button>

The declaration above puts Hollywood brush number 1 next to the text "OK" on the button's label. RapaGUI will now cache the image data of Hollywood brush number 1 internally and whenever there is a reference to Hollywood brush number 1 again, it will simply take the copy from its cache instead of the original one. This means that any changes you make to Hollywood brush number 1 after the declaration above won't have any effect on RapaGUI at all because of its image cache! Please keep that in mind. You either have to use a brush identifier that is not in RapaGUI's image cache yet or you have to remove the brush from RapaGUI's image cache using the moai.FreeImage() function first. For listview and treeview widgets, it's also possible to use moai.UpdateImage() instead.

There is just one exception to the rule: Widgets derived from Image class don't cache any image data, although they deal with Hollywood brushes/icons as well. The reason for this is that image widgets often display pretty large images that could also be animated or changed many times. That's why it doesn't make sense to cache image data for widgets derived from Image class. Images used in other widgets, e.g. buttons, toolbar buttons, listviews, treeviews, pageviews, are usually very small and there is usually just a fixed number of them. On top of that, they might be needed very often - just think of a listview with thousands of rows and an icon in each of those rows - which is why an image cache is really necessary here to guarantee a good performance.


Show TOC