From 78e016412e5cda6bc25932c1fbae25d19662737c Mon Sep 17 00:00:00 2001 From: aanper Date: Thu, 15 Oct 2020 18:13:18 +0300 Subject: [PATCH] gui draw refactor --- applications/gui/gui.c | 22 ++++++++++------------ applications/gui/gui_event.c | 12 ++++++------ applications/gui/gui_event.h | 14 +++++++------- applications/gui/widget.c | 12 ++++-------- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/applications/gui/gui.c b/applications/gui/gui.c index 75b9611d..c49ced53 100644 --- a/applications/gui/gui.c +++ b/applications/gui/gui.c @@ -73,10 +73,10 @@ Widget* gui_widget_find_enabled(WidgetArray_t array) { } bool gui_redraw_fs(Gui* gui) { - canvas_frame_set(gui->canvas, 0, 0, 128, 64); + canvas_frame_set(gui->canvas_api, 0, 0, 128, 64); Widget* widget = gui_widget_find_enabled(gui->widgets_fs); if(widget) { - widget_draw(widget, gui->canvas); + widget_draw(widget, gui->canvas_api); return true; } else { return false; @@ -84,21 +84,21 @@ bool gui_redraw_fs(Gui* gui) { } void gui_redraw_status_bar(Gui* gui) { - canvas_frame_set(gui->canvas, 0, 0, 128, 64); + canvas_frame_set(gui->canvas_api, 0, 0, 128, 64); Widget* widget = gui_widget_find_enabled(gui->widgets_status_bar); - if(widget) widget_draw(widget, gui->canvas); + if(widget) widget_draw(widget, gui->canvas_api); } void gui_redraw_normal(Gui* gui) { - canvas_frame_set(gui->canvas, 0, 9, 128, 55); + canvas_frame_set(gui->canvas_api, 0, 9, 128, 55); Widget* widget = gui_widget_find_enabled(gui->widgets); - if(widget) widget_draw(widget, gui->canvas); + if(widget) widget_draw(widget, gui->canvas_api); } void gui_redraw_dialogs(Gui* gui) { - canvas_frame_set(gui->canvas, 10, 20, 118, 44); + canvas_frame_set(gui->canvas_api, 10, 20, 118, 44); Widget* widget = gui_widget_find_enabled(gui->widgets_dialog); - if(widget) widget_draw(widget, gui->canvas); + if(widget) widget_draw(widget, gui->canvas_api); } void gui_redraw(Gui* gui) { @@ -110,8 +110,7 @@ void gui_redraw(Gui* gui) { } gui_redraw_dialogs(gui); - // canvas_commit(gui->canvas); - // redraw u8g2 + canvas_commit(gui->canvas); } void gui_input(Gui* gui, InputEvent* input_event) { @@ -139,8 +138,7 @@ Gui* gui_alloc() { // Drawing canvas api - gui->canvas_api = - canvas_api_init(); + gui->canvas_api = canvas_api_init(); return gui; } diff --git a/applications/gui/gui_event.c b/applications/gui/gui_event.c index 5c04d9a3..8d0914c2 100644 --- a/applications/gui/gui_event.c +++ b/applications/gui/gui_event.c @@ -15,8 +15,8 @@ void gui_event_input_events_callback(const void* value, size_t size, void* ctx) assert(ctx); GuiEvent* gui_event = ctx; - GUIMessage message; - message.type = GUIMessageTypeInput; + GuiMessage message; + message.type = GuiMessageTypeInput; message.input = *(InputEvent*)value; osMessageQueuePut(gui_event->mqueue, &message, 0, 0); @@ -25,7 +25,7 @@ void gui_event_input_events_callback(const void* value, size_t size, void* ctx) GuiEvent* gui_event_alloc() { GuiEvent* gui_event = furi_alloc(sizeof(GuiEvent)); // Allocate message que - gui_event->mqueue = osMessageQueueNew(GUI_EVENT_MQUEUE_SIZE, sizeof(GUIMessage), NULL); + gui_event->mqueue = osMessageQueueNew(GUI_EVENT_MQUEUE_SIZE, sizeof(GuiMessage), NULL); assert(gui_event->mqueue); // Input @@ -57,15 +57,15 @@ void gui_event_unlock(GuiEvent* gui_event) { assert(osMutexRelease(gui_event->lock_mutex) == osOK); } -void gui_event_messsage_send(GuiEvent* gui_event, GUIMessage* message) { +void gui_event_messsage_send(GuiEvent* gui_event, GuiMessage* message) { assert(gui_event); assert(message); osMessageQueuePut(gui_event->mqueue, message, 0, 0); } -GUIMessage gui_event_message_next(GuiEvent* gui_event) { +GuiMessage gui_event_message_next(GuiEvent* gui_event) { assert(gui_event); - GUIMessage message; + GuiMessage message; gui_event_unlock(gui_event); while(osMessageQueueGet(gui_event->mqueue, &message, NULL, osWaitForever) != osOK) { }; diff --git a/applications/gui/gui_event.h b/applications/gui/gui_event.h index 730eb8c6..89ba4ee2 100644 --- a/applications/gui/gui_event.h +++ b/applications/gui/gui_event.h @@ -4,15 +4,15 @@ #include typedef enum { - GUIMessageTypeRedraw = 0x00, - GUIMessageTypeInput = 0x01, -} GUIMessageType; + GuiMessageTypeRedraw = 0x00, + GuiMessageTypeInput = 0x01, +} GuiMessageType; typedef struct { - GUIMessageType type; + GuiMessageType type; InputEvent input; void* data; -} GUIMessage; +} GuiMessage; typedef struct GuiEvent GuiEvent; @@ -24,6 +24,6 @@ void gui_event_lock(GuiEvent* gui_event); void gui_event_unlock(GuiEvent* gui_event); -void gui_event_messsage_send(GuiEvent* gui_event, GUIMessage* message); +void gui_event_messsage_send(GuiEvent* gui_event, GuiMessage* message); -GUIMessage gui_event_message_next(GuiEvent* gui_event); +GuiMessage gui_event_message_next(GuiEvent* gui_event); diff --git a/applications/gui/widget.c b/applications/gui/widget.c index 16981262..106ac7f1 100644 --- a/applications/gui/widget.c +++ b/applications/gui/widget.c @@ -56,23 +56,19 @@ void widget_update(Widget* widget) { if(widget->gui) gui_update(widget->gui); } -void widget_gui_set(Widget* widget, GUI* gui) { +void widget_gui_set(Widget* widget, Gui* gui) { assert(widget); assert(gui); widget->gui = gui; } -void widget_draw(Widget* widget, ValueMutex* canvas_api_mutex) { +void widget_draw(Widget* widget, CanvasApi* canvas_api) { assert(widget); - assert(canvas_api_mutex); + assert(canvas_api); assert(widget->gui); if(widget->draw_callback) { - CanvasApi* api = acquire_mutex_block(canvas_api_mutex); // TODO: timeout? - if(api != NULL) { - widget->draw_callback(api, widget->draw_callback_context); - } - release_mutex(canvas_api_mutex, api); + widget->draw_callback(canvas_api, widget->draw_callback_context); } }