Display and UI implementation (#169)
* Menu app. Lib: add mlib submodule. * Menu: new startup lib dependency definition * Menu: hierarchy in menu. Cube: fix heap1/4 inconsistency, stack protection. * GUI: rendering pipeline initial version. * GUI: layered widget composing, FURI record. Menu: FURI record, api. * GUI: input dispatching. Menu: switch to input from GUI. * GUI, MENU: code style cleanup, fix type conversion warnings. * GUI, Menu: syntax check. * Makefile: check and reinit submodules, format. * Menu: lock on event processing. Makefile: proper submodule initialization. * Menu: fix stack corruption by queue. * GUI: refactor. * Makefile: format rule fix, st-util pid. * GUI, Menu, FURI: format with clang-format. * GUI, MENU: locks in critical sections, fix stack corruption, ready signaling. * Makefile: clang format rule cleanup. * GUI,MENU: migrate to new API. * Applications: PRODUCTION_HW variable, skip drivers build on local target. * refactor production build * add git to dockerfile * GUI: uncomment lock block Co-authored-by: Aleksandr Kutuzov <aku@plooks.com>
This commit is contained in:
79
applications/gui/canvas.c
Normal file
79
applications/gui/canvas.c
Normal file
@@ -0,0 +1,79 @@
|
||||
#include "canvas.h"
|
||||
#include "canvas_i.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <flipper.h>
|
||||
#include <u8g2.h>
|
||||
|
||||
struct Canvas {
|
||||
FuriRecordSubscriber* fb_record;
|
||||
u8g2_t* fb;
|
||||
uint8_t offset_x;
|
||||
uint8_t offset_y;
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
};
|
||||
|
||||
Canvas* canvas_alloc() {
|
||||
Canvas* canvas = furi_alloc(sizeof(Canvas));
|
||||
canvas->fb_record = furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||
assert(canvas->fb_record);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
void canvas_free(Canvas* canvas) {
|
||||
assert(canvas);
|
||||
free(canvas);
|
||||
}
|
||||
|
||||
void canvas_commit(Canvas* canvas) {
|
||||
assert(canvas);
|
||||
if(canvas->fb) {
|
||||
furi_commit(canvas->fb_record);
|
||||
canvas->fb = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void canvas_frame_set(
|
||||
Canvas* canvas,
|
||||
uint8_t offset_x,
|
||||
uint8_t offset_y,
|
||||
uint8_t width,
|
||||
uint8_t height) {
|
||||
assert(canvas);
|
||||
canvas->offset_x = offset_x;
|
||||
canvas->offset_y = offset_y;
|
||||
canvas->width = width;
|
||||
canvas->height = height;
|
||||
}
|
||||
|
||||
u8g2_t* canvas_fb(Canvas* canvas) {
|
||||
if(!canvas->fb) {
|
||||
canvas->fb = furi_take(canvas->fb_record);
|
||||
assert(canvas->fb);
|
||||
}
|
||||
return canvas->fb;
|
||||
}
|
||||
|
||||
void canvas_clear(Canvas* canvas) {
|
||||
u8g2_t* fb = canvas_fb(canvas);
|
||||
u8g2_ClearBuffer(fb);
|
||||
}
|
||||
|
||||
void canvas_color_set(Canvas* canvas, uint8_t color) {
|
||||
u8g2_t* fb = canvas_fb(canvas);
|
||||
u8g2_SetDrawColor(fb, 1);
|
||||
}
|
||||
|
||||
void canvas_font_set(Canvas* canvas, font_t font) {
|
||||
u8g2_t* fb = canvas_fb(canvas);
|
||||
u8g2_SetFontMode(fb, 1);
|
||||
u8g2_SetFont(fb, font);
|
||||
}
|
||||
|
||||
void canvas_str_draw(Canvas* canvas, uint8_t x, uint8_t y, const char* str) {
|
||||
x += canvas->offset_x;
|
||||
y += canvas->offset_y;
|
||||
u8g2_t* fb = canvas_fb(canvas);
|
||||
u8g2_DrawStr(fb, x, y, str);
|
||||
}
|
Reference in New Issue
Block a user