gui draw refactor
This commit is contained in:
parent
e684869970
commit
78e016412e
@ -73,10 +73,10 @@ Widget* gui_widget_find_enabled(WidgetArray_t array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool gui_redraw_fs(Gui* gui) {
|
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);
|
Widget* widget = gui_widget_find_enabled(gui->widgets_fs);
|
||||||
if(widget) {
|
if(widget) {
|
||||||
widget_draw(widget, gui->canvas);
|
widget_draw(widget, gui->canvas_api);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -84,21 +84,21 @@ 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);
|
canvas_frame_set(gui->canvas_api, 0, 0, 128, 64);
|
||||||
Widget* widget = gui_widget_find_enabled(gui->widgets_status_bar);
|
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) {
|
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);
|
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) {
|
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);
|
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) {
|
void gui_redraw(Gui* gui) {
|
||||||
@ -110,8 +110,7 @@ void gui_redraw(Gui* gui) {
|
|||||||
}
|
}
|
||||||
gui_redraw_dialogs(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) {
|
||||||
@ -139,8 +138,7 @@ Gui* gui_alloc() {
|
|||||||
|
|
||||||
// Drawing canvas api
|
// Drawing canvas api
|
||||||
|
|
||||||
gui->canvas_api =
|
gui->canvas_api = canvas_api_init();
|
||||||
canvas_api_init();
|
|
||||||
|
|
||||||
return gui;
|
return gui;
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@ void gui_event_input_events_callback(const void* value, size_t size, void* ctx)
|
|||||||
assert(ctx);
|
assert(ctx);
|
||||||
GuiEvent* gui_event = ctx;
|
GuiEvent* gui_event = ctx;
|
||||||
|
|
||||||
GUIMessage message;
|
GuiMessage message;
|
||||||
message.type = GUIMessageTypeInput;
|
message.type = GuiMessageTypeInput;
|
||||||
message.input = *(InputEvent*)value;
|
message.input = *(InputEvent*)value;
|
||||||
|
|
||||||
osMessageQueuePut(gui_event->mqueue, &message, 0, 0);
|
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_alloc() {
|
||||||
GuiEvent* gui_event = furi_alloc(sizeof(GuiEvent));
|
GuiEvent* gui_event = furi_alloc(sizeof(GuiEvent));
|
||||||
// Allocate message que
|
// 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);
|
assert(gui_event->mqueue);
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
@ -57,15 +57,15 @@ void gui_event_unlock(GuiEvent* gui_event) {
|
|||||||
assert(osMutexRelease(gui_event->lock_mutex) == osOK);
|
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(gui_event);
|
||||||
assert(message);
|
assert(message);
|
||||||
osMessageQueuePut(gui_event->mqueue, message, 0, 0);
|
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);
|
assert(gui_event);
|
||||||
GUIMessage message;
|
GuiMessage message;
|
||||||
gui_event_unlock(gui_event);
|
gui_event_unlock(gui_event);
|
||||||
while(osMessageQueueGet(gui_event->mqueue, &message, NULL, osWaitForever) != osOK) {
|
while(osMessageQueueGet(gui_event->mqueue, &message, NULL, osWaitForever) != osOK) {
|
||||||
};
|
};
|
||||||
|
@ -4,15 +4,15 @@
|
|||||||
#include <input/input.h>
|
#include <input/input.h>
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GUIMessageTypeRedraw = 0x00,
|
GuiMessageTypeRedraw = 0x00,
|
||||||
GUIMessageTypeInput = 0x01,
|
GuiMessageTypeInput = 0x01,
|
||||||
} GUIMessageType;
|
} GuiMessageType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GUIMessageType type;
|
GuiMessageType type;
|
||||||
InputEvent input;
|
InputEvent input;
|
||||||
void* data;
|
void* data;
|
||||||
} GUIMessage;
|
} GuiMessage;
|
||||||
|
|
||||||
typedef struct GuiEvent GuiEvent;
|
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_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);
|
||||||
|
@ -56,23 +56,19 @@ void widget_update(Widget* widget) {
|
|||||||
if(widget->gui) gui_update(widget->gui);
|
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(widget);
|
||||||
assert(gui);
|
assert(gui);
|
||||||
widget->gui = gui;
|
widget->gui = gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void widget_draw(Widget* widget, ValueMutex* canvas_api_mutex) {
|
void widget_draw(Widget* widget, CanvasApi* canvas_api) {
|
||||||
assert(widget);
|
assert(widget);
|
||||||
assert(canvas_api_mutex);
|
assert(canvas_api);
|
||||||
assert(widget->gui);
|
assert(widget->gui);
|
||||||
|
|
||||||
if(widget->draw_callback) {
|
if(widget->draw_callback) {
|
||||||
CanvasApi* api = acquire_mutex_block(canvas_api_mutex); // TODO: timeout?
|
widget->draw_callback(canvas_api, widget->draw_callback_context);
|
||||||
if(api != NULL) {
|
|
||||||
widget->draw_callback(api, widget->draw_callback_context);
|
|
||||||
}
|
|
||||||
release_mutex(canvas_api_mutex, api);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user