[FL-2150] Dolphin animation refactoring (#938)

* Dolphin Animation Refactoring, part 1
* Remove animations from desktop
* Remove excess, first start
* Split animation_manager with callbacks
* allocate view inside animation_view
* Work on ViewComposed
* Draw white rectangles under bubble corners
* Fix bubbles sequence
* RPC: remove obsolete include "status.pb.h"
* Add animations manifest decoding
* Flipper file: add strict mode
* FFF: Animation structures parsing
* Assembling structure of animation
* Lot of view fixes:
  Add multi-line bubbles
  Add support for passive bubbles (frame_order values starts from passive now)
  Add hard-coded delay (active_shift) for active state enabling
  Fix active state handling
  Fix leaks
  Fix parsing uncorrect bubble_animation meta file
  Fix bubble rules of showing
* Animation load/unload & view freeze/unfreeze
* Blocking & system animations, fixes:
  View correct activation
  Refactoring + blocking animation
  Freeze first passive/active frames
  Many insert/eject SD tests fixes
  Add system animations
  Add Loader events app started/finished
  Add system no_sd animation
* Assets: dolphin packer. Scripts: minor refactoring.
* Desktop: update logging tags. Scripts: add metadata to dolphin bundling process, extra sorting for fs traversing. Make: phony assets rules.
* Github: rebuild assets on build
* Docker: add missing dependencies for assets compilation
* Docker: fix run command syntax
* ReadMe: update naming rules with link to source
* Assets: recompile icons
* Loader: add loader event
* Desktop, Gui, Furi Core: const shenanigans macros

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Albert Kharisov
2022-01-03 01:39:56 +04:00
committed by GitHub
parent 065241fe5b
commit a39002ce22
349 changed files with 3531 additions and 1912 deletions

View File

@@ -348,6 +348,140 @@ void elements_bubble(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_
canvas_set_color(canvas, ColorBlack);
}
void elements_bubble_str(
Canvas* canvas,
uint8_t x,
uint8_t y,
const char* text,
Align horizontal,
Align vertical) {
furi_assert(canvas);
furi_assert(text);
uint8_t font_y = canvas_current_font_height(canvas);
uint16_t str_width = canvas_string_width(canvas, text);
// count \n's
uint8_t lines = 1;
const char* t = text;
while(*t != '\0') {
if(*t == '\n') {
lines++;
uint16_t temp_width = canvas_string_width(canvas, t + 1);
str_width = temp_width > str_width ? temp_width : str_width;
}
t++;
}
uint8_t frame_x = x;
uint8_t frame_y = y;
uint8_t frame_width = str_width + 8;
uint8_t frame_height = font_y * lines + 4;
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, frame_x + 1, frame_y + 1, frame_width - 2, frame_height - 2);
canvas_set_color(canvas, ColorBlack);
canvas_draw_rframe(canvas, frame_x, frame_y, frame_width, frame_height, 1);
elements_multiline_text(canvas, x + 4, y - 1 + font_y, text);
uint8_t x1 = 0;
uint8_t x2 = 0;
uint8_t x3 = 0;
uint8_t y1 = 0;
uint8_t y2 = 0;
uint8_t y3 = 0;
if((horizontal == AlignLeft) && (vertical == AlignTop)) {
x1 = frame_x;
y1 = frame_y;
x2 = frame_x - 4;
y2 = frame_y;
x3 = frame_x;
y3 = frame_y + 4;
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, x2 + 2, y2 + 1, 2, 2);
canvas_set_color(canvas, ColorBlack);
} else if((horizontal == AlignLeft) && (vertical == AlignCenter)) {
x1 = frame_x;
y1 = frame_y + (frame_height - 1) / 2 - 4;
x2 = frame_x - 4;
y2 = frame_y + (frame_height - 1) / 2;
x3 = frame_x;
y3 = frame_y + (frame_height - 1) / 2 + 4;
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, x2 + 2, y2 - 2, 2, 5);
canvas_draw_dot(canvas, x2 + 1, y2);
canvas_set_color(canvas, ColorBlack);
} else if((horizontal == AlignLeft) && (vertical == AlignBottom)) {
x1 = frame_x;
y1 = frame_y + (frame_height - 1) - 4;
x2 = frame_x - 4;
y2 = frame_y + (frame_height - 1);
x3 = frame_x;
y3 = frame_y + (frame_height - 1);
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, x2 + 2, y2 - 2, 2, 2);
canvas_set_color(canvas, ColorBlack);
} else if((horizontal == AlignRight) && (vertical == AlignTop)) {
x1 = frame_x + (frame_width - 1);
y1 = frame_y;
x2 = frame_x + (frame_width - 1) + 4;
y2 = frame_y;
x3 = frame_x + (frame_width - 1);
y3 = frame_y + 4;
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, x2 - 3, y2 + 1, 2, 2);
canvas_set_color(canvas, ColorBlack);
} else if((horizontal == AlignRight) && (vertical == AlignCenter)) {
x1 = frame_x + (frame_width - 1);
y1 = frame_y + (frame_height - 1) / 2 - 4;
x2 = frame_x + (frame_width - 1) + 4;
y2 = frame_y + (frame_height - 1) / 2;
x3 = frame_x + (frame_width - 1);
y3 = frame_y + (frame_height - 1) / 2 + 4;
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, x2 - 3, y2 - 2, 2, 5);
canvas_draw_dot(canvas, x2 - 1, y2);
canvas_set_color(canvas, ColorBlack);
} else if((horizontal == AlignRight) && (vertical == AlignBottom)) {
x1 = frame_x + (frame_width - 1);
y1 = frame_y + (frame_height - 1) - 4;
x2 = frame_x + (frame_width - 1) + 4;
y2 = frame_y + (frame_height - 1);
x3 = frame_x + (frame_width - 1);
y3 = frame_y + (frame_height - 1);
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, x2 - 3, y2 - 2, 2, 2);
canvas_set_color(canvas, ColorBlack);
} else if((horizontal == AlignCenter) && (vertical == AlignTop)) {
x1 = frame_x + (frame_width - 1) / 2 - 4;
y1 = frame_y;
x2 = frame_x + (frame_width - 1) / 2;
y2 = frame_y - 4;
x3 = frame_x + (frame_width - 1) / 2 + 4;
y3 = frame_y;
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, x2 - 2, y2 + 2, 5, 2);
canvas_draw_dot(canvas, x2, y2 + 1);
canvas_set_color(canvas, ColorBlack);
} else if((horizontal == AlignCenter) && (vertical == AlignBottom)) {
x1 = frame_x + (frame_width - 1) / 2 - 4;
y1 = frame_y + (frame_height - 1);
x2 = frame_x + (frame_width - 1) / 2;
y2 = frame_y + (frame_height - 1) + 4;
x3 = frame_x + (frame_width - 1) / 2 + 4;
y3 = frame_y + (frame_height - 1);
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, x2 - 2, y2 - 3, 5, 2);
canvas_draw_dot(canvas, x2, y2 - 1);
canvas_set_color(canvas, ColorBlack);
}
canvas_set_color(canvas, ColorWhite);
canvas_draw_line(canvas, x3, y3, x1, y1);
canvas_set_color(canvas, ColorBlack);
canvas_draw_line(canvas, x1, y1, x2, y2);
canvas_draw_line(canvas, x2, y2, x3, y3);
}
void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width) {
furi_assert(canvas);
furi_assert(string);

18
applications/gui/elements.h Executable file → Normal file
View File

@@ -160,6 +160,24 @@ void elements_slightly_rounded_box(
*/
void elements_bubble(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
/** Draw bubble frame for text with corner
*
* @param canvas Canvas instance
* @param x left x coordinates
* @param y top y coordinate
* @param width bubble width
* @param height bubble height
* @param horizontal horizontal aligning
* @param vertical aligning
*/
void elements_bubble_str(
Canvas* canvas,
uint8_t x,
uint8_t y,
const char* text,
Align horizontal,
Align vertical);
/** Trim string buffer to fit width in pixels
*
* @param canvas Canvas instance

View File

@@ -0,0 +1,166 @@
#include "gui/view.h"
#include "furi/memmgr.h"
#include "view_composed.h"
#include "view_i.h"
typedef struct {
View* bottom;
View* top;
bool top_enabled;
} ViewComposedModel;
struct ViewComposed {
View* view;
};
static void view_composed_draw(Canvas* canvas, void* model);
static bool view_composed_input(InputEvent* event, void* context);
static void view_composed_update_callback(View* view_top_or_bottom, void* context) {
furi_assert(view_top_or_bottom);
furi_assert(context);
View* view_composed_view = context;
view_composed_view->update_callback(
view_composed_view, view_composed_view->update_callback_context);
}
static void view_composed_enter(void* context) {
furi_assert(context);
ViewComposed* view_composed = context;
ViewComposedModel* model = view_get_model(view_composed->view);
/* if more than 1 composed views hold same view it has to reassign update_callback_context */
if(model->bottom) {
view_set_update_callback_context(model->bottom, view_composed->view);
if(model->bottom->enter_callback) {
model->bottom->enter_callback(model->bottom->context);
}
}
if(model->top) {
view_set_update_callback_context(model->top, view_composed->view);
if(model->top->enter_callback) {
model->top->enter_callback(model->top->context);
}
}
view_commit_model(view_composed->view, false);
}
static void view_composed_exit(void* context) {
furi_assert(context);
ViewComposed* view_composed = context;
ViewComposedModel* model = view_get_model(view_composed->view);
if(model->bottom) {
if(model->bottom->exit_callback) {
model->bottom->exit_callback(model->bottom->context);
}
}
if(model->top) {
if(model->top->exit_callback) {
model->top->exit_callback(model->top->context);
}
}
view_commit_model(view_composed->view, false);
}
ViewComposed* view_composed_alloc(void) {
ViewComposed* view_composed = furi_alloc(sizeof(ViewComposed));
view_composed->view = view_alloc();
view_allocate_model(view_composed->view, ViewModelTypeLocking, sizeof(ViewComposedModel));
view_set_draw_callback(view_composed->view, view_composed_draw);
view_set_input_callback(view_composed->view, view_composed_input);
view_set_context(view_composed->view, view_composed);
view_set_enter_callback(view_composed->view, view_composed_enter);
view_set_exit_callback(view_composed->view, view_composed_exit);
return view_composed;
}
void view_composed_free(ViewComposed* view_composed) {
furi_assert(view_composed);
ViewComposedModel* view_composed_model = view_get_model(view_composed->view);
view_set_update_callback(view_composed_model->bottom, NULL);
view_set_update_callback_context(view_composed_model->bottom, NULL);
view_set_update_callback(view_composed_model->top, NULL);
view_set_update_callback_context(view_composed_model->top, NULL);
view_commit_model(view_composed->view, true);
view_free(view_composed->view);
free(view_composed);
}
static void view_composed_draw(Canvas* canvas, void* model) {
furi_assert(model);
ViewComposedModel* view_composed_model = model;
view_draw(view_composed_model->bottom, canvas);
if(view_composed_model->top_enabled && view_composed_model->top) {
view_draw(view_composed_model->top, canvas);
}
}
static bool view_composed_input(InputEvent* event, void* context) {
furi_assert(event);
furi_assert(context);
ViewComposed* view_composed = context;
ViewComposedModel* view_composed_model = view_get_model(view_composed->view);
bool consumed = false;
if(view_composed_model->top_enabled && view_composed_model->top) {
consumed = view_input(view_composed_model->top, event);
}
if(!consumed) {
consumed = view_input(view_composed_model->bottom, event);
}
view_commit_model(view_composed->view, false);
return consumed;
}
void view_composed_top_enable(ViewComposed* view_composed, bool enable) {
furi_assert(view_composed);
ViewComposedModel* view_composed_model = view_get_model(view_composed->view);
bool update = (view_composed_model->top_enabled != enable);
view_composed_model->top_enabled = enable;
view_commit_model(view_composed->view, update);
}
void view_composed_tie_views(ViewComposed* view_composed, View* view_bottom, View* view_top) {
furi_assert(view_composed);
furi_assert(view_bottom);
ViewComposedModel* view_composed_model = view_get_model(view_composed->view);
if(view_composed_model->bottom) {
view_set_update_callback(view_composed_model->bottom, NULL);
view_set_update_callback_context(view_composed_model->bottom, NULL);
}
if(view_composed_model->top) {
view_set_update_callback(view_composed_model->top, NULL);
view_set_update_callback_context(view_composed_model->top, NULL);
}
view_composed_model->bottom = view_bottom;
view_set_update_callback(view_bottom, view_composed_update_callback);
view_set_update_callback_context(view_bottom, view_composed->view);
view_composed_model->top = view_top;
view_set_update_callback(view_top, view_composed_update_callback);
view_set_update_callback_context(view_top, view_composed->view);
view_commit_model(view_composed->view, true);
}
View* view_composed_get_view(ViewComposed* view_composed) {
furi_assert(view_composed);
return view_composed->view;
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include <stdbool.h>
#include "view.h"
typedef struct ViewComposed ViewComposed;
ViewComposed* view_composed_alloc(void);
void view_composed_free(ViewComposed* view_composed);
void view_composed_top_enable(ViewComposed* view_composed, bool enable);
void view_composed_tie_views(ViewComposed* view_composed, View* view_bottom, View* view_top);
View* view_composed_get_view(ViewComposed* view_composed);

View File

@@ -188,7 +188,7 @@ void view_dispatcher_send_to_front(ViewDispatcher* view_dispatcher) {
void view_dispatcher_send_to_back(ViewDispatcher* view_dispatcher) {
furi_assert(view_dispatcher);
furi_assert(view_dispatcher->gui);
gui_view_port_send_to_front(view_dispatcher->gui, view_dispatcher->view_port);
gui_view_port_send_to_back(view_dispatcher->gui, view_dispatcher->view_port);
}
void view_dispatcher_attach_to_gui(