refactor canvas

This commit is contained in:
aanper
2020-10-15 18:05:28 +03:00
parent 19ef348c80
commit e684869970
12 changed files with 169 additions and 119 deletions

View File

@@ -13,16 +13,16 @@
ARRAY_DEF(WidgetArray, Widget*, M_PTR_OPLIST);
struct GUI {
GUIEvent* event;
Canvas* canvas;
struct Gui {
GuiEvent* event;
CanvasApi* canvas_api;
WidgetArray_t widgets_status_bar;
WidgetArray_t widgets;
WidgetArray_t widgets_fs;
WidgetArray_t widgets_dialog;
};
void gui_add_widget(GUI* gui, Widget* widget, WidgetLayer layer) {
void gui_add_widget(Gui* gui, Widget* widget, WidgetLayer layer) {
WidgetArray_t* widget_array = NULL;
switch(layer) {
@@ -54,10 +54,10 @@ void gui_add_widget(GUI* gui, Widget* widget, WidgetLayer layer) {
gui_update(gui);
}
void gui_update(GUI* gui) {
void gui_update(Gui* gui) {
assert(gui);
GUIMessage message;
message.type = GUIMessageTypeRedraw;
GuiMessage message;
message.type = GuiMessageTypeRedraw;
gui_event_messsage_send(gui->event, &message);
}
@@ -72,7 +72,7 @@ Widget* gui_widget_find_enabled(WidgetArray_t array) {
return NULL;
}
bool gui_redraw_fs(GUI* gui) {
bool gui_redraw_fs(Gui* gui) {
canvas_frame_set(gui->canvas, 0, 0, 128, 64);
Widget* widget = gui_widget_find_enabled(gui->widgets_fs);
if(widget) {
@@ -83,25 +83,25 @@ bool gui_redraw_fs(GUI* gui) {
}
}
void gui_redraw_status_bar(GUI* gui) {
void gui_redraw_status_bar(Gui* gui) {
canvas_frame_set(gui->canvas, 0, 0, 128, 64);
Widget* widget = gui_widget_find_enabled(gui->widgets_status_bar);
if(widget) widget_draw(widget, gui->canvas);
}
void gui_redraw_normal(GUI* gui) {
void gui_redraw_normal(Gui* gui) {
canvas_frame_set(gui->canvas, 0, 9, 128, 55);
Widget* widget = gui_widget_find_enabled(gui->widgets);
if(widget) widget_draw(widget, gui->canvas);
}
void gui_redraw_dialogs(GUI* gui) {
void gui_redraw_dialogs(Gui* gui) {
canvas_frame_set(gui->canvas, 10, 20, 118, 44);
Widget* widget = gui_widget_find_enabled(gui->widgets_dialog);
if(widget) widget_draw(widget, gui->canvas);
}
void gui_redraw(GUI* gui) {
void gui_redraw(Gui* gui) {
assert(gui);
if(!gui_redraw_fs(gui)) {
@@ -110,10 +110,11 @@ void gui_redraw(GUI* gui) {
}
gui_redraw_dialogs(gui);
canvas_commit(gui->canvas);
// canvas_commit(gui->canvas);
// redraw u8g2
}
void gui_input(GUI* gui, InputEvent* input_event) {
void gui_input(Gui* gui, InputEvent* input_event) {
assert(gui);
Widget* widget = gui_widget_find_enabled(gui->widgets_dialog);
@@ -125,8 +126,8 @@ void gui_input(GUI* gui, InputEvent* input_event) {
}
}
GUI* gui_alloc() {
GUI* gui = furi_alloc(sizeof(GUI));
Gui* gui_alloc() {
Gui* gui = furi_alloc(sizeof(Gui));
// Initialize widget arrays
WidgetArray_init(gui->widgets_status_bar);
WidgetArray_init(gui->widgets);
@@ -135,15 +136,17 @@ GUI* gui_alloc() {
// Event dispatcher
gui->event = gui_event_alloc();
// Drawing canvas
gui->canvas = canvas_alloc();
// Drawing canvas api
gui->canvas_api =
canvas_api_init();
return gui;
}
void gui_task(void* p) {
GUI* gui = gui_alloc();
Gui* gui = gui_alloc();
GuiApi gui_api = {
.add_widget = gui_add_widget,
@@ -160,10 +163,10 @@ void gui_task(void* p) {
// Forever dispatch
while(1) {
GUIMessage message = gui_event_message_next(gui->event);
if(message.type == GUIMessageTypeRedraw) {
GuiMessage message = gui_event_message_next(gui->event);
if(message.type == GuiMessageTypeRedraw) {
gui_redraw(gui);
} else if(message.type == GUIMessageTypeInput) {
} else if(message.type == GuiMessageTypeInput) {
gui_input(gui, &message.input);
}
}