|
| 1 | +#include <dialogs/dialogs.h> |
| 2 | + |
| 3 | +#include <mp_flipper_modflipperzero.h> |
| 4 | +#include <mp_flipper_runtime.h> |
| 5 | + |
| 6 | +#include "mp_flipper_context.h" |
| 7 | + |
| 8 | +void mp_flipper_dialog_message_set_text( |
| 9 | + const char* text, |
| 10 | + uint8_t x, |
| 11 | + uint8_t y, |
| 12 | + uint8_t h, |
| 13 | + uint8_t v) { |
| 14 | + mp_flipper_context_t* ctx = mp_flipper_context; |
| 15 | + |
| 16 | + Align align_x = x == MP_FLIPPER_ALIGN_BEGIN ? AlignLeft : AlignRight; |
| 17 | + Align align_y = y == MP_FLIPPER_ALIGN_BEGIN ? AlignTop : AlignBottom; |
| 18 | + |
| 19 | + align_x = x == MP_FLIPPER_ALIGN_CENTER ? AlignCenter : align_x; |
| 20 | + align_y = y == MP_FLIPPER_ALIGN_CENTER ? AlignCenter : align_y; |
| 21 | + |
| 22 | + dialog_message_set_text(ctx->dialog_message, text, x, y, align_x, align_y); |
| 23 | +} |
| 24 | + |
| 25 | +void mp_flipper_dialog_message_set_header( |
| 26 | + const char* text, |
| 27 | + uint8_t x, |
| 28 | + uint8_t y, |
| 29 | + uint8_t h, |
| 30 | + uint8_t v) { |
| 31 | + mp_flipper_context_t* ctx = mp_flipper_context; |
| 32 | + |
| 33 | + Align align_x = x == MP_FLIPPER_ALIGN_BEGIN ? AlignLeft : AlignRight; |
| 34 | + Align align_y = y == MP_FLIPPER_ALIGN_BEGIN ? AlignTop : AlignBottom; |
| 35 | + |
| 36 | + align_x = x == MP_FLIPPER_ALIGN_CENTER ? AlignCenter : align_x; |
| 37 | + align_y = y == MP_FLIPPER_ALIGN_CENTER ? AlignCenter : align_y; |
| 38 | + |
| 39 | + dialog_message_set_header(ctx->dialog_message, text, x, y, align_x, align_y); |
| 40 | +} |
| 41 | + |
| 42 | +void mp_flipper_dialog_message_set_button(const char* text, uint8_t button) { |
| 43 | + mp_flipper_context_t* ctx = mp_flipper_context; |
| 44 | + |
| 45 | + // left button |
| 46 | + if(button == MP_FLIPPER_INPUT_BUTTON_LEFT) { |
| 47 | + ctx->dialog_message_button_left = text; |
| 48 | + } |
| 49 | + // center button |
| 50 | + else if(button == MP_FLIPPER_INPUT_BUTTON_OK) { |
| 51 | + ctx->dialog_message_button_center = text; |
| 52 | + } |
| 53 | + // right button |
| 54 | + else if(button == MP_FLIPPER_INPUT_BUTTON_RIGHT) { |
| 55 | + ctx->dialog_message_button_right = text; |
| 56 | + } |
| 57 | + |
| 58 | + dialog_message_set_buttons( |
| 59 | + ctx->dialog_message, |
| 60 | + ctx->dialog_message_button_left, |
| 61 | + ctx->dialog_message_button_center, |
| 62 | + ctx->dialog_message_button_right); |
| 63 | +} |
| 64 | + |
| 65 | +uint8_t mp_flipper_dialog_message_show() { |
| 66 | + mp_flipper_context_t* ctx = mp_flipper_context; |
| 67 | + |
| 68 | + gui_direct_draw_release(ctx->gui); |
| 69 | + |
| 70 | + DialogsApp* dialog = furi_record_open(RECORD_DIALOGS); |
| 71 | + |
| 72 | + uint8_t button = dialog_message_show(dialog, ctx->dialog_message); |
| 73 | + |
| 74 | + furi_record_close(RECORD_DIALOGS); |
| 75 | + |
| 76 | + ctx->canvas = gui_direct_draw_acquire(ctx->gui); |
| 77 | + |
| 78 | + switch(button) { |
| 79 | + case DialogMessageButtonLeft: |
| 80 | + return MP_FLIPPER_INPUT_BUTTON_LEFT; |
| 81 | + case DialogMessageButtonCenter: |
| 82 | + return MP_FLIPPER_INPUT_BUTTON_OK; |
| 83 | + case DialogMessageButtonRight: |
| 84 | + return MP_FLIPPER_INPUT_BUTTON_RIGHT; |
| 85 | + case DialogMessageButtonBack: |
| 86 | + default: |
| 87 | + return MP_FLIPPER_INPUT_BUTTON_BACK; |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +void mp_flipper_dialog_message_clear() { |
| 92 | + mp_flipper_context_t* ctx = mp_flipper_context; |
| 93 | + |
| 94 | + dialog_message_free(ctx->dialog_message); |
| 95 | + |
| 96 | + ctx->dialog_message = dialog_message_alloc(); |
| 97 | + |
| 98 | + ctx->dialog_message_button_left = NULL; |
| 99 | + ctx->dialog_message_button_center = NULL; |
| 100 | + ctx->dialog_message_button_right = NULL; |
| 101 | +} |
0 commit comments