Gui: unicode support, new canvas API

merge ofw commit
This commit is contained in:
MX
2024-03-25 14:04:07 +03:00
parent 585b7f963d
commit 9961dadee7
10 changed files with 259 additions and 225 deletions

View File

@@ -14,14 +14,14 @@
#define LOCKED_HINT_TIMEOUT_MS (1000)
#define UNLOCKED_HINT_TIMEOUT_MS (2000)
#define DOOR_OFFSET_START -55
#define DOOR_OFFSET_END 0
#define DOOR_OFFSET_START (-55)
#define DOOR_OFFSET_END (0)
#define DOOR_L_FINAL_POS 0
#define DOOR_R_FINAL_POS 60
#define DOOR_L_FINAL_POS (0)
#define DOOR_R_FINAL_POS (60)
#define UNLOCK_CNT 3
#define UNLOCK_RST_TIMEOUT 600
#define UNLOCK_CNT (3)
#define UNLOCK_RST_TIMEOUT (600)
struct DesktopViewLocked {
View* view;
@@ -63,10 +63,10 @@ static void locked_view_timer_callback(void* context) {
}
static void desktop_view_locked_doors_draw(Canvas* canvas, DesktopViewLockedModel* model) {
int8_t offset = model->door_offset;
uint8_t door_left_x = DOOR_L_FINAL_POS + offset;
uint8_t door_right_x = DOOR_R_FINAL_POS - offset;
uint8_t height = icon_get_height(&I_DoorLeft_70x55);
int32_t offset = model->door_offset;
int32_t door_left_x = DOOR_L_FINAL_POS + offset;
int32_t door_right_x = DOOR_R_FINAL_POS - offset;
size_t height = icon_get_height(&I_DoorLeft_70x55);
canvas_draw_icon(canvas, door_left_x, canvas_height(canvas) - height, &I_DoorLeft_70x55);
canvas_draw_icon(canvas, door_right_x, canvas_height(canvas) - height, &I_DoorRight_70x55);
}

View File

@@ -96,10 +96,10 @@ size_t canvas_get_buffer_size(const Canvas* canvas) {
void canvas_frame_set(
Canvas* canvas,
uint8_t offset_x,
uint8_t offset_y,
uint8_t width,
uint8_t height) {
int32_t offset_x,
int32_t offset_y,
size_t width,
size_t height) {
furi_check(canvas);
canvas->offset_x = offset_x;
canvas->offset_y = offset_y;
@@ -107,19 +107,19 @@ void canvas_frame_set(
canvas->height = height;
}
uint8_t canvas_width(const Canvas* canvas) {
size_t canvas_width(const Canvas* canvas) {
furi_check(canvas);
return canvas->width;
}
uint8_t canvas_height(const Canvas* canvas) {
size_t canvas_height(const Canvas* canvas) {
furi_check(canvas);
return canvas->height;
}
uint8_t canvas_current_font_height(const Canvas* canvas) {
size_t canvas_current_font_height(const Canvas* canvas) {
furi_check(canvas);
uint8_t font_height = u8g2_GetMaxCharHeight(&canvas->fb);
size_t font_height = u8g2_GetMaxCharHeight(&canvas->fb);
if(canvas->fb.font == u8g2_font_haxrcorp4089_tr) {
font_height += 1;
@@ -182,18 +182,18 @@ void canvas_set_custom_u8g2_font(Canvas* canvas, const uint8_t* font) {
u8g2_SetFont(&canvas->fb, font);
}
void canvas_draw_str(Canvas* canvas, uint8_t x, uint8_t y, const char* str) {
void canvas_draw_str(Canvas* canvas, int32_t x, int32_t y, const char* str) {
furi_check(canvas);
if(!str) return;
x += canvas->offset_x;
y += canvas->offset_y;
u8g2_DrawStr(&canvas->fb, x, y, str);
u8g2_DrawUTF8(&canvas->fb, x, y, str);
}
void canvas_draw_str_aligned(
Canvas* canvas,
uint8_t x,
uint8_t y,
int32_t x,
int32_t y,
Align horizontal,
Align vertical,
const char* str) {
@@ -206,10 +206,10 @@ void canvas_draw_str_aligned(
case AlignLeft:
break;
case AlignRight:
x -= u8g2_GetStrWidth(&canvas->fb, str);
x -= u8g2_GetUTF8Width(&canvas->fb, str);
break;
case AlignCenter:
x -= (u8g2_GetStrWidth(&canvas->fb, str) / 2);
x -= (u8g2_GetUTF8Width(&canvas->fb, str) / 2);
break;
default:
furi_crash();
@@ -230,26 +230,26 @@ void canvas_draw_str_aligned(
break;
}
u8g2_DrawStr(&canvas->fb, x, y, str);
u8g2_DrawUTF8(&canvas->fb, x, y, str);
}
uint16_t canvas_string_width(Canvas* canvas, const char* str) {
furi_check(canvas);
if(!str) return 0;
return u8g2_GetStrWidth(&canvas->fb, str);
return u8g2_GetUTF8Width(&canvas->fb, str);
}
uint8_t canvas_glyph_width(Canvas* canvas, uint16_t symbol) {
size_t canvas_glyph_width(Canvas* canvas, uint16_t symbol) {
furi_check(canvas);
return u8g2_GetGlyphWidth(&canvas->fb, symbol);
}
void canvas_draw_bitmap(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t width,
uint8_t height,
int32_t x,
int32_t y,
size_t width,
size_t height,
const uint8_t* compressed_bitmap_data) {
furi_check(canvas);
@@ -262,8 +262,8 @@ void canvas_draw_bitmap(
void canvas_draw_icon_animation(
Canvas* canvas,
uint8_t x,
uint8_t y,
int32_t x,
int32_t y,
IconAnimation* icon_animation) {
furi_check(canvas);
furi_check(icon_animation);
@@ -358,28 +358,28 @@ static void canvas_draw_u8g2_bitmap_int(
void canvas_draw_u8g2_bitmap(
u8g2_t* u8g2,
u8g2_uint_t x,
u8g2_uint_t y,
u8g2_uint_t w,
u8g2_uint_t h,
int32_t x,
int32_t y,
size_t width,
size_t height,
const uint8_t* bitmap,
IconRotation rotation) {
#ifdef U8G2_WITH_INTERSECTION
if(u8g2_IsIntersection(u8g2, x, y, x + w, y + h) == 0) return;
if(u8g2_IsIntersection(u8g2, x, y, x + width, y + height) == 0) return;
#endif /* U8G2_WITH_INTERSECTION */
switch(rotation) {
case IconRotation0:
canvas_draw_u8g2_bitmap_int(u8g2, x, y, w, h, 0, 0, bitmap);
canvas_draw_u8g2_bitmap_int(u8g2, x, y, width, height, 0, 0, bitmap);
break;
case IconRotation90:
canvas_draw_u8g2_bitmap_int(u8g2, x, y, w, h, 0, 1, bitmap);
canvas_draw_u8g2_bitmap_int(u8g2, x, y, width, height, 0, 1, bitmap);
break;
case IconRotation180:
canvas_draw_u8g2_bitmap_int(u8g2, x, y, w, h, 1, 0, bitmap);
canvas_draw_u8g2_bitmap_int(u8g2, x, y, width, height, 1, 0, bitmap);
break;
case IconRotation270:
canvas_draw_u8g2_bitmap_int(u8g2, x, y, w, h, 1, 1, bitmap);
canvas_draw_u8g2_bitmap_int(u8g2, x, y, width, height, 1, 1, bitmap);
break;
default:
break;
@@ -388,8 +388,8 @@ void canvas_draw_u8g2_bitmap(
void canvas_draw_icon_ex(
Canvas* canvas,
uint8_t x,
uint8_t y,
int32_t x,
int32_t y,
const Icon* icon,
IconRotation rotation) {
furi_check(canvas);
@@ -403,7 +403,7 @@ void canvas_draw_icon_ex(
&canvas->fb, x, y, icon_get_width(icon), icon_get_height(icon), icon_data, rotation);
}
void canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, const Icon* icon) {
void canvas_draw_icon(Canvas* canvas, int32_t x, int32_t y, const Icon* icon) {
furi_check(canvas);
furi_check(icon);
@@ -415,14 +415,14 @@ void canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, const Icon* icon) {
&canvas->fb, x, y, icon_get_width(icon), icon_get_height(icon), icon_data, IconRotation0);
}
void canvas_draw_dot(Canvas* canvas, uint8_t x, uint8_t y) {
void canvas_draw_dot(Canvas* canvas, int32_t x, int32_t y) {
furi_check(canvas);
x += canvas->offset_x;
y += canvas->offset_y;
u8g2_DrawPixel(&canvas->fb, x, y);
}
void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
void canvas_draw_box(Canvas* canvas, int32_t x, int32_t y, size_t width, size_t height) {
furi_check(canvas);
x += canvas->offset_x;
y += canvas->offset_y;
@@ -431,18 +431,18 @@ void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_
void canvas_draw_rbox(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t width,
uint8_t height,
uint8_t radius) {
int32_t x,
int32_t y,
size_t width,
size_t height,
size_t radius) {
furi_check(canvas);
x += canvas->offset_x;
y += canvas->offset_y;
u8g2_DrawRBox(&canvas->fb, x, y, width, height, radius);
}
void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
void canvas_draw_frame(Canvas* canvas, int32_t x, int32_t y, size_t width, size_t height) {
furi_check(canvas);
x += canvas->offset_x;
y += canvas->offset_y;
@@ -451,18 +451,18 @@ void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint
void canvas_draw_rframe(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t width,
uint8_t height,
uint8_t radius) {
int32_t x,
int32_t y,
size_t width,
size_t height,
size_t radius) {
furi_check(canvas);
x += canvas->offset_x;
y += canvas->offset_y;
u8g2_DrawRFrame(&canvas->fb, x, y, width, height, radius);
}
void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
void canvas_draw_line(Canvas* canvas, int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
furi_check(canvas);
x1 += canvas->offset_x;
y1 += canvas->offset_y;
@@ -471,14 +471,14 @@ void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_
u8g2_DrawLine(&canvas->fb, x1, y1, x2, y2);
}
void canvas_draw_circle(Canvas* canvas, uint8_t x, uint8_t y, uint8_t radius) {
void canvas_draw_circle(Canvas* canvas, int32_t x, int32_t y, size_t radius) {
furi_check(canvas);
x += canvas->offset_x;
y += canvas->offset_y;
u8g2_DrawCircle(&canvas->fb, x, y, radius, U8G2_DRAW_ALL);
}
void canvas_draw_disc(Canvas* canvas, uint8_t x, uint8_t y, uint8_t radius) {
void canvas_draw_disc(Canvas* canvas, int32_t x, int32_t y, size_t radius) {
furi_check(canvas);
x += canvas->offset_x;
y += canvas->offset_y;
@@ -487,10 +487,10 @@ void canvas_draw_disc(Canvas* canvas, uint8_t x, uint8_t y, uint8_t radius) {
void canvas_draw_triangle(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t base,
uint8_t height,
int32_t x,
int32_t y,
size_t base,
size_t height,
CanvasDirection dir) {
furi_check(canvas);
if(dir == CanvasDirectionBottomToTop) {
@@ -514,18 +514,18 @@ void canvas_draw_triangle(
void canvas_draw_xbm(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t w,
uint8_t h,
int32_t x,
int32_t y,
size_t width,
size_t height,
const uint8_t* bitmap) {
furi_check(canvas);
x += canvas->offset_x;
y += canvas->offset_y;
canvas_draw_u8g2_bitmap(&canvas->fb, x, y, w, h, bitmap, IconRotation0);
canvas_draw_u8g2_bitmap(&canvas->fb, x, y, width, height, bitmap, IconRotation0);
}
void canvas_draw_glyph(Canvas* canvas, uint8_t x, uint8_t y, uint16_t ch) {
void canvas_draw_glyph(Canvas* canvas, int32_t x, int32_t y, uint16_t ch) {
furi_check(canvas);
x += canvas->offset_x;
y += canvas->offset_y;
@@ -616,4 +616,4 @@ void canvas_remove_framebuffer_callback(
furi_check(CanvasCallbackPairArray_count(canvas->canvas_callback_pair, p) == 1);
CanvasCallbackPairArray_remove_val(canvas->canvas_callback_pair, p);
canvas_unlock(canvas);
}
}

View File

@@ -6,6 +6,7 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <gui/icon_animation.h>
#include <gui/icon.h>
@@ -102,7 +103,7 @@ void canvas_commit(Canvas* canvas);
*
* @return width in pixels.
*/
uint8_t canvas_width(const Canvas* canvas);
size_t canvas_width(const Canvas* canvas);
/** Get Canvas height
*
@@ -110,7 +111,7 @@ uint8_t canvas_width(const Canvas* canvas);
*
* @return height in pixels.
*/
uint8_t canvas_height(const Canvas* canvas);
size_t canvas_height(const Canvas* canvas);
/** Get current font height
*
@@ -118,7 +119,7 @@ uint8_t canvas_height(const Canvas* canvas);
*
* @return height in pixels.
*/
uint8_t canvas_current_font_height(const Canvas* canvas);
size_t canvas_current_font_height(const Canvas* canvas);
/** Get current font width
*
@@ -150,8 +151,7 @@ void canvas_clear(Canvas* canvas);
*/
void canvas_set_color(Canvas* canvas, Color color);
/** Set font swap
* Argument String Rotation Description
/** Set font swap Argument String Rotation Description
*
* @param canvas Canvas instance
* @param dir Direction font
@@ -185,7 +185,7 @@ void canvas_set_custom_u8g2_font(Canvas* canvas, const uint8_t* font);
* @param y anchor point y coordinate
* @param str C-string
*/
void canvas_draw_str(Canvas* canvas, uint8_t x, uint8_t y, const char* str);
void canvas_draw_str(Canvas* canvas, int32_t x, int32_t y, const char* str);
/** Draw aligned string defined by x, y.
*
@@ -201,8 +201,8 @@ void canvas_draw_str(Canvas* canvas, uint8_t x, uint8_t y, const char* str);
*/
void canvas_draw_str_aligned(
Canvas* canvas,
uint8_t x,
uint8_t y,
int32_t x,
int32_t y,
Align horizontal,
Align vertical,
const char* str);
@@ -223,37 +223,37 @@ uint16_t canvas_string_width(Canvas* canvas, const char* str);
*
* @return width in pixels
*/
uint8_t canvas_glyph_width(Canvas* canvas, uint16_t symbol);
size_t canvas_glyph_width(Canvas* canvas, uint16_t symbol);
/** Draw bitmap picture at position defined by x,y.
*
* @param canvas Canvas instance
* @param x x coordinate
* @param y y coordinate
* @param width width of bitmap
* @param height height of bitmap
* @param compressed_bitmap_data compressed bitmap data
* @param canvas Canvas instance
* @param x x coordinate
* @param y y coordinate
* @param width width of bitmap
* @param height height of bitmap
* @param compressed_bitmap_data compressed bitmap data
*/
void canvas_draw_bitmap(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t width,
uint8_t height,
int32_t x,
int32_t y,
size_t width,
size_t height,
const uint8_t* compressed_bitmap_data);
/** Draw icon at position defined by x,y with rotation and flip.
*
* @param canvas Canvas instance
* @param x x coordinate
* @param y y coordinate
* @param icon Icon instance
* @param rotation IconRotation
* @param canvas Canvas instance
* @param x x coordinate
* @param y y coordinate
* @param icon Icon instance
* @param rotation IconRotation
*/
void canvas_draw_icon_ex(
Canvas* canvas,
uint8_t x,
uint8_t y,
int32_t x,
int32_t y,
const Icon* icon,
IconRotation rotation);
@@ -266,8 +266,8 @@ void canvas_draw_icon_ex(
*/
void canvas_draw_icon_animation(
Canvas* canvas,
uint8_t x,
uint8_t y,
int32_t x,
int32_t y,
IconAnimation* icon_animation);
/** Draw icon at position defined by x,y.
@@ -277,23 +277,23 @@ void canvas_draw_icon_animation(
* @param y y coordinate
* @param icon Icon instance
*/
void canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, const Icon* icon);
void canvas_draw_icon(Canvas* canvas, int32_t x, int32_t y, const Icon* icon);
/** Draw XBM bitmap
*
* @param canvas Canvas instance
* @param x x coordinate
* @param y y coordinate
* @param w bitmap width
* @param h bitmap height
* @param[in] width bitmap width
* @param[in] height bitmap height
* @param bitmap pointer to XBM bitmap data
*/
void canvas_draw_xbm(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t w,
uint8_t h,
int32_t x,
int32_t y,
size_t width,
size_t height,
const uint8_t* bitmap);
/** Draw dot at x,y
@@ -302,7 +302,7 @@ void canvas_draw_xbm(
* @param x x coordinate
* @param y y coordinate
*/
void canvas_draw_dot(Canvas* canvas, uint8_t x, uint8_t y);
void canvas_draw_dot(Canvas* canvas, int32_t x, int32_t y);
/** Draw box of width, height at x,y
*
@@ -312,7 +312,7 @@ void canvas_draw_dot(Canvas* canvas, uint8_t x, uint8_t y);
* @param width box width
* @param height box height
*/
void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
void canvas_draw_box(Canvas* canvas, int32_t x, int32_t y, size_t width, size_t height);
/** Draw frame of width, height at x,y
*
@@ -322,7 +322,7 @@ void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_
* @param width frame width
* @param height frame height
*/
void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
void canvas_draw_frame(Canvas* canvas, int32_t x, int32_t y, size_t width, size_t height);
/** Draw line from x1,y1 to x2,y2
*
@@ -332,41 +332,42 @@ void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint
* @param x2 x2 coordinate
* @param y2 y2 coordinate
*/
void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
void canvas_draw_line(Canvas* canvas, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
/** Draw circle at x,y with radius r
*
* @param canvas Canvas instance
* @param x x coordinate
* @param y y coordinate
* @param r radius
* @param radius radius
*/
void canvas_draw_circle(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
void canvas_draw_circle(Canvas* canvas, int32_t x, int32_t y, size_t radius);
/** Draw disc at x,y with radius r
*
* @param canvas Canvas instance
* @param x x coordinate
* @param y y coordinate
* @param r radius
* @param radius radius
*/
void canvas_draw_disc(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
void canvas_draw_disc(Canvas* canvas, int32_t x, int32_t y, size_t radius);
/** Draw triangle with given base and height lengths and their intersection coordinate
/** Draw triangle with given base and height lengths and their intersection
* coordinate
*
* @param canvas Canvas instance
* @param x x coordinate of base and height intersection
* @param y y coordinate of base and height intersection
* @param base length of triangle side
* @param height length of triangle height
* @param dir CanvasDirection triangle orientation
* @param canvas Canvas instance
* @param x x coordinate of base and height intersection
* @param y y coordinate of base and height intersection
* @param base length of triangle side
* @param height length of triangle height
* @param dir CanvasDirection triangle orientation
*/
void canvas_draw_triangle(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t base,
uint8_t height,
int32_t x,
int32_t y,
size_t base,
size_t height,
CanvasDirection dir);
/** Draw glyph
@@ -376,7 +377,7 @@ void canvas_draw_triangle(
* @param y y coordinate
* @param ch character
*/
void canvas_draw_glyph(Canvas* canvas, uint8_t x, uint8_t y, uint16_t ch);
void canvas_draw_glyph(Canvas* canvas, int32_t x, int32_t y, uint16_t ch);
/** Set transparency mode
*
@@ -396,11 +397,11 @@ void canvas_set_bitmap_mode(Canvas* canvas, bool alpha);
*/
void canvas_draw_rframe(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t width,
uint8_t height,
uint8_t radius);
int32_t x,
int32_t y,
size_t width,
size_t height,
size_t radius);
/** Draw rounded-corner box of width, height at x,y, with round value radius
*
@@ -413,11 +414,11 @@ void canvas_draw_rframe(
*/
void canvas_draw_rbox(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t width,
uint8_t height,
uint8_t radius);
int32_t x,
int32_t y,
size_t width,
size_t height,
size_t radius);
void canvas_draw_icon_bitmap(
Canvas* canvas,

View File

@@ -38,10 +38,10 @@ ALGO_DEF(CanvasCallbackPairArray, CanvasCallbackPairArray_t);
struct Canvas {
u8g2_t fb;
CanvasOrientation orientation;
uint8_t offset_x;
uint8_t offset_y;
uint8_t width;
uint8_t height;
size_t offset_x;
size_t offset_y;
size_t width;
size_t height;
CompressIcon* compress_icon;
CanvasCallbackPairArray_t canvas_callback_pair;
FuriMutex* mutex;
@@ -85,10 +85,10 @@ size_t canvas_get_buffer_size(const Canvas* canvas);
*/
void canvas_frame_set(
Canvas* canvas,
uint8_t offset_x,
uint8_t offset_y,
uint8_t width,
uint8_t height);
int32_t offset_x,
int32_t offset_y,
size_t width,
size_t height);
/** Set canvas orientation
*
@@ -117,10 +117,10 @@ CanvasOrientation canvas_get_orientation(const Canvas* canvas);
*/
void canvas_draw_u8g2_bitmap(
u8g2_t* u8g2,
uint8_t x,
uint8_t y,
uint8_t width,
uint8_t height,
int32_t x,
int32_t y,
size_t width,
size_t height,
const uint8_t* bitmap,
IconRotation rotation);