Welcome to mirror list, hosted at ThFree Co, Russian Federation.

icon.c « gui « applications - github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8f02cf6dc8c051b7f985a18b4bae0b68942eadb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "icon_i.h"

#include <cmsis_os2.h>
#include <flipper.h>
#include <flipper_v2.h>

Icon* icon_alloc(const IconData* data) {
    Icon* icon = furi_alloc(sizeof(Icon));
    icon->data = data;
    return icon;
}

void icon_free(Icon* icon) {
    furi_assert(icon);
    free(icon);
}

const uint8_t* icon_get_data(Icon* icon) {
    furi_assert(icon);
    if(icon->tick) {
        uint32_t now = osKernelGetTickCount();
        if(now < icon->tick) {
            icon->tick = now;
            icon_next_frame(icon);
        } else if(now - icon->tick > osKernelGetTickFreq() / icon->data->frame_rate) {
            icon->tick = now;
            icon_next_frame(icon);
        }
    }
    return icon->data->frames[icon->frame];
}

void icon_next_frame(Icon* icon) {
    furi_assert(icon);
    icon->frame = (icon->frame + 1) % icon->data->frame_count;
}

uint8_t icon_get_width(Icon* icon) {
    furi_assert(icon);
    return icon->data->width;
}

uint8_t icon_get_height(Icon* icon) {
    furi_assert(icon);
    return icon->data->height;
}

bool icon_is_animated(Icon* icon) {
    furi_assert(icon);
    return icon->data->frame_count > 1;
}

void icon_start_animation(Icon* icon) {
    furi_assert(icon);
    icon->tick = osKernelGetTickCount();
}

void icon_stop_animation(Icon* icon) {
    furi_assert(icon);
    icon->tick = 0;
    icon->frame = 0;
}