gui draw refactor

This commit is contained in:
aanper 2020-10-15 18:13:18 +03:00
parent e684869970
commit 78e016412e
4 changed files with 27 additions and 33 deletions

View File

@ -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;
}

View File

@ -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) {
};

View File

@ -4,15 +4,15 @@
#include <input/input.h>
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);

View File

@ -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);
}
}