BSB Developer Docs
Loading...
Searching...
No Matches
canvas/canvas.h
1#pragma once
2
3#include <furi.h>
4#include <m-array.h>
5#include <gui/gui.h>
8#include <gui/modules/image.h>
9#include <loader/loader.h>
10#include <time.h>
11
12#define RECORD_CANVAS "CANVAS"
13#define CANVAS_MAX_PRIORITY LOADER_MAX_PRIORITY
14#define CANVAS_MAX_ELEMENTS 100
15
16typedef struct CanvasSrv CanvasSrv;
17
18typedef enum {
19 CanvasResultOk = 0,
20 CanvasResultBadParameters,
21 CanvasResultLowPriority,
22 CanvasResultEmptyScreen,
23 CanvasResultTooManyElements,
24 CanvasResultNonexistentElementId,
25 CanvasResultWrongAppId,
26
27 CanvasResultMax,
28} CanvasResult;
29
30typedef enum {
31 CanvasElementTypeImage,
32 CanvasElementTypeAnimPlayer,
33 CanvasElementTypeText,
34 CanvasElementTypeCountdown,
35 CanvasElementTypeRectangle,
36 CanvasElementTypeRawImage,
37
38 CanvasElementTypeMax,
39} CanvasElementType;
40
41typedef struct {
42 char* id;
43 uint32_t timeout;
44 time_t display_until;
45 int16_t x;
46 int16_t y;
47 GuiDisplayId display;
48 Align align;
49 CanvasElementType type;
50 int32_t z_index;
51
52 union {
53 struct {
54 FuriString* file_path;
55 uint8_t opacity;
56 } image;
57
58 struct {
59 FuriString* file_path;
60 FuriString* section;
61 AnimFilePlayFlag flags;
62 uint8_t opacity;
63 } anim_player;
64
65 struct {
66 char* text_str;
67 char* font_path;
68 Color color;
69 size_t width;
70 size_t scroll_rate_cpm;
71 size_t scroll_start_delay;
72 size_t scroll_repeat_delay;
73 } text;
74
75 struct {
76 time_t timestamp;
77 Color color;
78 CountdownDirection direction;
79 CountdownShowHour hours;
80 } countdown;
81
82 struct {
83 size_t width;
84 size_t height;
85 size_t radius;
86 size_t border_width;
87 enum {
88 RectangleFillNone,
89 RectangleFillSolid,
90 RectangleFillGradientH,
91 RectangleFillGradientV,
92
93 RectangleFillMax,
94 } fill;
95 Color fill_color[2];
96 Color border_color;
97 } rectangle;
98
99 struct {
100 void* data;
101 size_t data_size;
102 uint32_t width;
103 uint32_t height;
104 ImageColorFormat format;
105 uint8_t opacity;
106 } raw_image;
107 };
109
110static inline void canvas_element_clear(CanvasElement* obj) {
111 if(obj->id) {
112 free(obj->id);
113 obj->id = NULL;
114 }
115 if(obj->type == CanvasElementTypeImage) {
116 if(obj->image.file_path) furi_string_free(obj->image.file_path);
117 } else if(obj->type == CanvasElementTypeText) {
118 if(obj->text.text_str) free(obj->text.text_str);
119 if(obj->text.font_path) free(obj->text.font_path);
120 } else if(obj->type == CanvasElementTypeAnimPlayer) {
121 if(obj->anim_player.file_path) furi_string_free(obj->anim_player.file_path);
122 if(obj->anim_player.section) furi_string_free(obj->anim_player.section);
123 } else if(obj->type == CanvasElementTypeRawImage) {
124 if(obj->raw_image.data) free(obj->raw_image.data);
125 }
126}
127
128static inline void canvas_element_clone(CanvasElement* obj, const CanvasElement* src) {
129 memcpy(obj, src, sizeof(CanvasElement));
130 if(src->id) obj->id = strdup(src->id);
131 if(src->type == CanvasElementTypeImage) {
132 if(src->image.file_path) {
133 obj->image.file_path = furi_string_alloc_set(src->image.file_path);
134 }
135 } else if(src->type == CanvasElementTypeText) {
136 if(src->text.text_str) obj->text.text_str = strdup(src->text.text_str);
137 if(src->text.font_path) obj->text.font_path = strdup(src->text.font_path);
138 } else if(src->type == CanvasElementTypeAnimPlayer) {
139 if(src->anim_player.file_path) {
140 obj->anim_player.file_path = furi_string_alloc_set(src->anim_player.file_path);
141 }
142 if(src->anim_player.section) {
143 obj->anim_player.section = furi_string_alloc_set(src->anim_player.section);
144 }
145 } else if(src->type == CanvasElementTypeRawImage) {
146 if(src->raw_image.data) {
147 obj->raw_image.data = malloc(src->raw_image.data_size);
148 memcpy(obj->raw_image.data, src->raw_image.data, src->raw_image.data_size);
149 }
150 }
151}
152
153ARRAY_DEF(
154 CanvasElementsArray,
156 M_OPEXTEND(
157 M_POD_OPLIST,
158 CLEAR(API_2(canvas_element_clear)),
159 INIT_SET(API_6(canvas_element_clone))))
160
161typedef void (*CanvasDrawCallback)(CanvasResult result, void* ctx);
162
163CanvasResult canvas_show_elements(
164 CanvasSrv* canvas,
165 const char* app_id,
166 size_t priority,
167 CanvasElementsArray_t elements);
168
169void canvas_show_elements_async(
170 CanvasSrv* canvas,
171 const char* app_id,
172 size_t priority,
173 CanvasElementsArray_t elements,
174 CanvasDrawCallback callback,
175 void* callback_ctx);
176
190CanvasResult
191 canvas_delete_elements(CanvasSrv* canvas, const char* app_id, const char* const* element_ids);
192
193CanvasResult canvas_get_app_id(CanvasSrv* canvas, FuriString* string);
194
195void canvas_set_clear_on_back(CanvasSrv* canvas, bool is_clear_on_back);
A widget that plays an AnimFile.
A widget that displays time until or from the specified timestamp.
GUI system APIs.
GuiDisplayId
Enumeration of available display identifiers.
Definition gui.h:18
A widget that displays a static image.
ImageColorFormat
Pixel format of raw image data passed to image_set_source_raw().
Definition image.h:17
Loader service API.
Definition canvas/canvas.h:41
Definition canvas/canvas.c:48
RGB color structure.
Definition color.h:42
TIME (Simple Network Time Protocol) service API.
Align
Enumeration of supported widget alignment modes.
Definition widget.h:27