Icon store. A small cache that maps a resource id to its picture and is shared across a face, so each icon loads once and is freed in one place. Also carries the palette tint and the auto-trim margin scan.
More...
#include "ui/icon_cache.h"
#include <string.h>
|
| struct | IconEntry |
| | One cached icon. Its resource id, the loaded picture, and the extra state icon_tint and the auto-trim scan keep between calls. More...
|
|
| #define | ICON_CACHE_MAX 24 |
| | How many distinct icons the cache holds at once.
|
|
| void | icon_tint (GBitmap *bmp, GColor color) |
| | Paints an icon a different colour. It only works on icons saved as little colour-table pictures. Other kinds it just leaves alone. The see-through pixels stay see-through so the edges keep looking clean.
|
| static uint8_t | px_alpha (GBitmapFormat fmt, const uint8_t *data, const GColor *palette, int x) |
| | Alpha of a single pixel, 0 to 3, across the bitmap formats the colour platforms produce.
|
| IconMargins | icon_margins_of (GBitmap *bmp) |
| | Measures the transparent margins of any bitmap, for icons that live outside the shared cache such as a weather picture that reloads as the weather changes. All zero when auto-trim is off or the bitmap is NULL.
|
| static IconEntry * | icon_entry (uint32_t res) |
| | Finds or loads the cache entry for a resource id.
|
| GBitmap * | icon_get (uint32_t res) |
| | Hands back an icon picture from the cache, loading it the first time it is asked for.
|
| IconMargins | icon_margins (uint32_t res) |
| | The measured transparent margins of a cached icon. Loads and measures it the first time, then returns the cached numbers. All zero when auto-trim is off or the icon could not load.
|
| GSize | icon_size (uint32_t res) |
| | The size of an icon in pixels. Gives back GSize(0,0) if it could not load.
|
| void | icon_align_trim (GAlign align, IconMargins m, int *trim_dx, int *trim_dy) |
| | The extra offset that pins the opaque box rather than the full bitmap at a given anchor. A right or bottom edge kills the trailing margin. A left or top edge kills the leading one. A centred axis splits the difference so the visible art centres.
|
|
void | icons_cleanup (void) |
| | Frees every icon picture in the cache.
|
|
|
static IconEntry | s_cache [ICON_CACHE_MAX] |
| | The cached icons.
|
|
static uint8_t | s_cache_count |
| | How many cache entries are in use.
|
| static uint32_t | s_use_clock |
| | Ticks once per lookup and gets stamped onto whichever entry was touched.
|
Icon store. A small cache that maps a resource id to its picture and is shared across a face, so each icon loads once and is freed in one place. Also carries the palette tint and the auto-trim margin scan.
◆ ICON_CACHE_MAX
| #define ICON_CACHE_MAX 24 |
How many distinct icons the cache holds at once.
It has to cover every icon one redraw touches. A busy layout, two eight column forecast strips with a pair of two icon panels under them, touches 20, so 24 leaves a little room. Past that the cache still works but thrashes. A redraw walks its icons in the same order every time, so the coldest entry is always the next one wanted, and every lookup reloads the resource and rescans its margins. A reload that fails on a busy heap leaves that icon blank.
Icons nothing draws any more, such as the moon glyphs of days gone by, are what gets dropped. A face that draws more at once sets its own cap in its appinfo's defines.
◆ icon_entry()
Finds or loads the cache entry for a resource id.
One scan feeds icon_get, icon_margins, and icon_size, so a caller that reads more than one of them on every panel repaint does not re-scan the same icon for each.
- Parameters
-
- Returns
- The cache entry, or NULL when the icon can't be cached.
◆ px_alpha()
| uint8_t px_alpha |
( |
GBitmapFormat | fmt, |
|
|
const uint8_t * | data, |
|
|
const GColor * | palette, |
|
|
int | x ) |
|
static |
Alpha of a single pixel, 0 to 3, across the bitmap formats the colour platforms produce.
A GColor8 keeps alpha in its top 2 bits, and colour-table pixels index a GColor8 palette. Colour-table pixels pack MSB first, so the leftmost pixel sits in the high-order bits.
- Parameters
-
| fmt | The bitmap's pixel format. |
| data | The row's raw pixel bytes. |
| palette | The bitmap's colour palette, for a colour-table format. |
| x | The pixel's column within the row. |
- Returns
- The pixel's alpha, 0 (fully see-through) to 3 (fully opaque).
◆ s_use_clock
Ticks once per lookup and gets stamped onto whichever entry was touched.
The entry holding the lowest stamp is the one nothing has wanted for the longest.