The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
icon.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file icon.h
5 * @brief icons from the icon packs in /usr/share/icons.
6 *
7 * two sets: "lucide" has line icons as coverage masks, drawn in a colour
8 * given at draw time (window controls, toolbars); "tela" has full colour
9 * icons (apps, places, file types, devices). tools/icons/build.py makes
10 * the packs; the format is described there.
11 *
12 * an icon is loaded at a size and a scale (1, or 2 for a 2x screen). when
13 * the pack has no image of that many pixels, the next larger one is
14 * scaled down (or the largest one up).
15 */
16
17#include <gfx.h>
18#include <stdbool.h>
19#include <stdint.h>
20
21#define ICON_DIR "/usr/share/icons/"
22#define ICON_NAME_MAX 31
23
24typedef struct icon_set icon_set_t;
25
26typedef struct
27{
30 bool is_mask;
31 uint8_t *mask; // is_mask: width * height coverage bytes
32 gfx_buffer_t *image; // else: premultiplied ARGB
33} icon_t;
34
35/**
36 * open a pack file.
37 * @return the set, or NULL (no file, or not an icon pack).
38 */
39icon_set_t *icon_set_open(const char *path);
40
41/**
42 * open a set by its name: ICON_DIR "<name>.pack".
43 */
44icon_set_t *icon_set_named(const char *name);
45
46void icon_set_close(icon_set_t *set);
47
48/**
49 * true if the set is of masks (lucide), false if of colour images (tela).
50 */
51bool icon_set_is_mask(const icon_set_t *set);
52
53/**
54 * true if the set has an icon of exactly this name.
55 */
56bool icon_set_has(const icon_set_t *set, const char *name);
57
58/**
59 * load an icon.
60 *
61 * a name the set does not have falls back as in the freedesktop icon
62 * naming spec: the last part after a dash is removed until a name is
63 * found (text-x-csrc, text-x, text), then "unknown".
64 *
65 * @param size the icon size in points (16, 20, 24, 32, 48, 64, or any).
66 * @param scale 1 to 4 (2 for a 2x screen); the icon is size * scale
67 * pixels, at most 1024.
68 * @return the icon (free it with icon_free), or NULL.
69 */
70icon_t *icon_load(icon_set_t *set, const char *name, int32_t size, int32_t scale);
71
72void icon_free(icon_t *icon);
73
74/**
75 * draw an icon in a colour: a mask's coverage, or a colour image's alpha.
76 */
77void icon_draw_mask(gfx_buffer_t *buf, const icon_t *icon, int32_t x, int32_t y,
78 gfx_color_t color);
79
80/**
81 * draw an icon as it is, with an opacity (255: opaque). a mask is drawn
82 * in black.
83 */
84void icon_draw(gfx_buffer_t *buf, const icon_t *icon, int32_t x, int32_t y, uint8_t opacity);
libgfx: drawing into pixel buffers in memory.
uint32_t gfx_color_t
a premultiplied ARGB colour, 0xAARRGGBB.
Definition gfx.h:30
void icon_set_close(icon_set_t *set)
Definition icon.c:131
bool icon_set_is_mask(const icon_set_t *set)
true if the set is of masks (lucide), false if of colour images (tela).
Definition icon.c:140
icon_t * icon_load(icon_set_t *set, const char *name, int32_t size, int32_t scale)
load an icon.
Definition icon.c:295
bool icon_set_has(const icon_set_t *set, const char *name)
true if the set has an icon of exactly this name.
Definition icon.c:163
void icon_draw(gfx_buffer_t *buf, const icon_t *icon, int32_t x, int32_t y, uint8_t opacity)
draw an icon as it is, with an opacity (255: opaque).
Definition icon.c:348
void icon_draw_mask(gfx_buffer_t *buf, const icon_t *icon, int32_t x, int32_t y, gfx_color_t color)
draw an icon in a colour: a mask's coverage, or a colour image's alpha.
Definition icon.c:329
void icon_free(icon_t *icon)
Definition icon.c:320
icon_set_t * icon_set_open(const char *path)
open a pack file.
Definition icon.c:65
icon_set_t * icon_set_named(const char *name)
open a set by its name: ICON_DIR "<name>.pack".
Definition icon.c:118
struct icon_set icon_set_t
Definition icon.h:24
unsigned char uint8_t
Definition fb.h:18
integer types of fixed width.
int int32_t
Definition stdint.h:14
bool, true and false.
Definition gfx.h:41
Definition icon.h:27
gfx_buffer_t * image
Definition icon.h:32
bool is_mask
Definition icon.h:30
uint8_t * mask
Definition icon.h:31
int32_t width
Definition icon.h:28
int32_t height
Definition icon.h:29