The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
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
24
typedef
struct
icon_set
icon_set_t
;
25
26
typedef
struct
27
{
28
int32_t
width
;
29
int32_t
height
;
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
*/
39
icon_set_t
*
icon_set_open
(
const
char
*path);
40
41
/**
42
* open a set by its name: ICON_DIR "<name>.pack".
43
*/
44
icon_set_t
*
icon_set_named
(
const
char
*name);
45
46
void
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
*/
51
bool
icon_set_is_mask
(
const
icon_set_t
*set);
52
53
/**
54
* true if the set has an icon of exactly this name.
55
*/
56
bool
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
*/
70
icon_t
*
icon_load
(
icon_set_t
*set,
const
char
*name,
int32_t
size,
int32_t
scale);
71
72
void
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
*/
77
void
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
*/
84
void
icon_draw
(
gfx_buffer_t
*buf,
const
icon_t
*icon,
int32_t
x,
int32_t
y,
uint8_t
opacity);
gfx.h
libgfx: drawing into pixel buffers in memory.
gfx_color_t
uint32_t gfx_color_t
a premultiplied ARGB colour, 0xAARRGGBB.
Definition
gfx.h:30
icon_set_close
void icon_set_close(icon_set_t *set)
Definition
icon.c:131
icon_set_is_mask
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_load
icon_t * icon_load(icon_set_t *set, const char *name, int32_t size, int32_t scale)
load an icon.
Definition
icon.c:295
icon_set_has
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
icon_draw
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
icon_draw_mask
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
icon_free
void icon_free(icon_t *icon)
Definition
icon.c:320
icon_set_open
icon_set_t * icon_set_open(const char *path)
open a pack file.
Definition
icon.c:65
icon_set_named
icon_set_t * icon_set_named(const char *name)
open a set by its name: ICON_DIR "<name>.pack".
Definition
icon.c:118
icon_set_t
struct icon_set icon_set_t
Definition
icon.h:24
uint8_t
unsigned char uint8_t
Definition
fb.h:18
stdint.h
integer types of fixed width.
int32_t
int int32_t
Definition
stdint.h:14
stdbool.h
bool, true and false.
gfx_buffer_t
Definition
gfx.h:41
icon_t
Definition
icon.h:27
icon_t::image
gfx_buffer_t * image
Definition
icon.h:32
icon_t::is_mask
bool is_mask
Definition
icon.h:30
icon_t::mask
uint8_t * mask
Definition
icon.h:31
icon_t::width
int32_t width
Definition
icon.h:28
icon_t::height
int32_t height
Definition
icon.h:29
src
lib
icon
include
icon.h
Generated by
1.18.0