Skip to content

Commit cf74053

Browse files
author
tixlegeek
committed
cleanup and event management rework
1 parent 62eea82 commit cf74053

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

401lightMessengerApp/401LightMsg_bmp_editor.c

+26-17
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void bmp_editor_text_input_callback(void* ctx) {
8787
LIGHTMSGCONF_SAVE_FOLDER,
8888
BmpEditor->bitmapName,
8989
".bmp");
90-
view_dispatcher_send_custom_event(app->view_dispatcher, SetTextInputSaveEvent);
90+
view_dispatcher_send_custom_event(app->view_dispatcher, AppBmpEditorEventSaveText);
9191
}
9292

9393
static void bmp_editor_select_name(void* ctx) {
@@ -161,6 +161,17 @@ static bool bmp_editor_mainmenu_input_callback(InputEvent* input_event, void* ct
161161
return false;
162162
}
163163

164+
static bool bmp_editor_error_input_callback(InputEvent* input_event, void* ctx) {
165+
AppContext* app = (AppContext*)ctx;
166+
bool consumed = false;
167+
168+
if((input_event->type == InputTypePress) || (input_event->type == InputTypeRepeat)) {
169+
view_dispatcher_send_custom_event(app->view_dispatcher, AppBmpEditorEventQuit);
170+
consumed = true;
171+
}
172+
return consumed;
173+
}
174+
164175
static bool bmp_editor_select_size_input_callback(InputEvent* input_event, void* ctx) {
165176
AppContext* app = (AppContext*)ctx;
166177
AppBmpEditor* BmpEditor = app->sceneBmpEditor;
@@ -226,7 +237,6 @@ static bool bmp_editor_draw_input_callback(InputEvent* input_event, void* ctx) {
226237
break;
227238
case InputKeyOk:
228239
bmp_editor_toggle(BmpEditor);
229-
view_dispatcher_send_custom_event(app->view_dispatcher, AppBmpEditorEventToggle);
230240
consumed = false;
231241
break;
232242
case InputKeyBack:
@@ -265,17 +275,17 @@ static bool app_scene_bmp_editor_input_callback(InputEvent* input_event, void* c
265275
bool consumed = false;
266276
switch(BmpEditorData->state) {
267277
case BmpEditorStateMainMenu:
268-
FURI_LOG_I(__FUNCTION__, "BmpEditorStateMainMenu");
269278
consumed = bmp_editor_mainmenu_input_callback(input_event, ctx);
270279
break;
271280
case BmpEditorStateSelectSize:
272-
FURI_LOG_I(__FUNCTION__, "BmpEditorStateSelectSize");
273281
consumed = bmp_editor_select_size_input_callback(input_event, ctx);
274282
break;
275283
case BmpEditorStateDrawing:
276-
FURI_LOG_I(__FUNCTION__, "BmpEditorStateDrawing");
277284
consumed = bmp_editor_draw_input_callback(input_event, ctx);
278285
break;
286+
case BmpEditorStateSizeError:
287+
consumed = bmp_editor_error_input_callback(input_event, ctx);
288+
break;
279289
default:
280290
break;
281291
}
@@ -313,16 +323,17 @@ static void bmp_editor_drawError(Canvas* canvas, void* ctx) {
313323
switch(BmpEditorData->error) {
314324
case L401_ERR_WIDTH:
315325
canvas_clear(canvas);
316-
canvas_set_font(canvas, FontPrimary);
317-
canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignCenter, "BMP File too large to");
318-
canvas_draw_str_aligned(canvas, 64, 20, AlignCenter, AlignCenter, "be edited on flipper!");
326+
canvas_set_font(canvas, FontSecondary);
327+
canvas_draw_str_aligned(canvas, 64, 20, AlignCenter, AlignCenter, "BMP File too large to");
328+
canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignCenter, "be edited on flipper!");
319329
break;
320330
default:
321331
canvas_clear(canvas);
322332
canvas_set_font(canvas, FontPrimary);
323333
canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignCenter, "Unknown error");
324334
break;
325335
}
336+
elements_button_center(canvas, "Return");
326337
}
327338

328339
static void bmp_editor_drawBoard(Canvas* canvas, void* ctx) {
@@ -395,15 +406,12 @@ static void app_scene_bmp_editor_render_callback(Canvas* canvas, void* _model) {
395406

396407
switch(BmpEditorData->state) {
397408
case BmpEditorStateSelectSize:
398-
FURI_LOG_I(__FUNCTION__, "BmpEditorStateSelectSiz");
399409
bmp_editor_drawSizePicker(canvas, _model);
400410
break;
401411
case BmpEditorStateDrawing:
402-
FURI_LOG_I(__FUNCTION__, "BmpEditorStateDrawing");
403412
bmp_editor_drawBoard(canvas, _model);
404413
break;
405414
case BmpEditorStateSizeError:
406-
FURI_LOG_I(__FUNCTION__, "BmpEditorStateSizeError");
407415
bmp_editor_drawError(canvas, _model);
408416
break;
409417
default:
@@ -418,18 +426,15 @@ static void bmp_editor_mainmenu_callback(void* ctx, uint32_t index) {
418426

419427
switch(index) {
420428
case BmpEditorMainmenuIndex_New:
421-
FURI_LOG_I(__FUNCTION__, "BmpEditorMainmenuIndex_New");
422429
BmpEditorData->state = BmpEditorStateSelectSize;
423430
view_dispatcher_switch_to_view(app->view_dispatcher, AppViewBmpEditor);
424431
break;
425432
case BmpEditorMainmenuIndex_Open:
426-
FURI_LOG_I(__FUNCTION__, "BmpEditorMainmenuIndex_Open");
427433
BmpEditorData->state = BmpEditorStateSelectFile;
428434
bmp_editor_select_file(ctx);
429435

430436
break;
431437
default:
432-
FURI_LOG_I(__FUNCTION__, "Index = %ld", index);
433438
break;
434439
}
435440
}
@@ -480,7 +485,6 @@ AppBmpEditor* app_bmp_editor_alloc(void* ctx) {
480485
view_set_context(appBmpEditor->view, app);
481486
view_set_draw_callback(appBmpEditor->view, app_scene_bmp_editor_render_callback);
482487
view_set_input_callback(appBmpEditor->view, app_scene_bmp_editor_input_callback);
483-
484488
return appBmpEditor;
485489
}
486490

@@ -521,7 +525,6 @@ View* app_bitmap_editor_get_view(AppBmpEditor* appBmpEditor) {
521525
void app_scene_bmp_editor_on_enter(void* context) {
522526
AppContext* app = context;
523527
AppBmpEditor* BmpEditor = app->sceneBmpEditor;
524-
FURI_LOG_I(__FUNCTION__, " enter");
525528
BmpEditor->model_data->state = BmpEditorStateMainMenu;
526529
with_view_model(
527530
BmpEditor->view, bmpEditorModel * model, { model->data = BmpEditor->model_data; }, false);
@@ -581,11 +584,17 @@ bool app_scene_bmp_editor_on_event(void* ctx, SceneManagerEvent event) {
581584
// UNUSED(ctx);
582585
bool consumed = false;
583586
if(event.type == SceneManagerEventTypeCustom) {
584-
if(event.event == SetTextInputSaveEvent) {
587+
switch(event.event) {
588+
case AppBmpEditorEventSaveText:
585589
bmp_editor_init_bitmap(ctx);
586590
BmpEditorData->state = BmpEditorStateDrawing;
587591
view_dispatcher_switch_to_view(app->view_dispatcher, AppViewBmpEditor);
588592
consumed = true;
593+
break;
594+
case AppBmpEditorEventQuit:
595+
view_dispatcher_switch_to_view(app->view_dispatcher, BmpEditorViewMainMenu);
596+
consumed = true;
597+
break;
589598
}
590599
}
591600
// scene_manager_next_scene(app->scene_manager, AppSceneMainMenu);

401lightMessengerApp/401LightMsg_bmp_editor.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <gui/gui.h>
2020
#include <gui/modules/submenu.h>
2121
#include <gui/modules/text_input.h>
22+
#include <gui/elements.h>
2223
#include <gui/scene_manager.h>
2324
#include <gui/view_dispatcher.h>
2425
#include <lib/toolbox/name_generator.h>
@@ -87,11 +88,7 @@ typedef struct AppBmpEditor {
8788

8889
typedef enum {
8990
AppBmpEditorEventQuit,
90-
AppBmpEditorEventUp,
91-
AppBmpEditorEventDown,
92-
AppBmpEditorEventLeft,
93-
AppBmpEditorEventRight,
94-
AppBmpEditorEventToggle,
91+
AppBmpEditorEventSaveText,
9592
} AppBmpEditorCustomEvents;
9693

9794
AppBmpEditor* app_bmp_editor_alloc();

0 commit comments

Comments
 (0)