@@ -32,21 +32,24 @@ static uint8_t bmp_editor_move(AppBmpEditor* BmpEditor, int8_t x, int8_t y) {
32
32
}
33
33
34
34
static uint8_t bmp_editor_resize (AppBmpEditor * BmpEditor , int8_t w , int8_t h ) {
35
+ // Compute the new dimensions given increments/decrements in size. Usually only height
35
36
int dh = BmpEditor -> model_data -> bmp_h + h ;
36
37
int dw = BmpEditor -> model_data -> bmp_w + w ;
37
- if (dh < PARAM_BMP_EDITOR_MIN_RES_H )
38
+ if (dh < PARAM_BMP_EDITOR_MIN_RES_H ) {
38
39
BmpEditor -> model_data -> bmp_h = PARAM_BMP_EDITOR_MIN_RES_H ;
39
- else if (dh > PARAM_BMP_EDITOR_MAX_RES_H )
40
+ } else if (dh > PARAM_BMP_EDITOR_MAX_RES_H ) {
40
41
BmpEditor -> model_data -> bmp_h = PARAM_BMP_EDITOR_MAX_RES_H ;
41
- else
42
+ } else {
42
43
BmpEditor -> model_data -> bmp_h = dh ;
44
+ }
43
45
44
- if (dw < PARAM_BMP_EDITOR_MIN_RES_W )
46
+ if (dw < PARAM_BMP_EDITOR_MIN_RES_W ) {
45
47
BmpEditor -> model_data -> bmp_w = PARAM_BMP_EDITOR_MIN_RES_W ;
46
- else if (dw > PARAM_BMP_EDITOR_MAX_RES_W )
48
+ } else if (dw > PARAM_BMP_EDITOR_MAX_RES_W ) {
47
49
BmpEditor -> model_data -> bmp_w = PARAM_BMP_EDITOR_MAX_RES_W ;
48
- else
50
+ } else {
49
51
BmpEditor -> model_data -> bmp_w = dw ;
52
+ }
50
53
51
54
BmpEditor -> model_data -> cursor .x = (BmpEditor -> model_data -> bmp_w / 2 );
52
55
BmpEditor -> model_data -> cursor .y = (BmpEditor -> model_data -> bmp_h / 2 );
@@ -84,7 +87,7 @@ static void bmp_editor_text_input_callback(void* ctx) {
84
87
LIGHTMSGCONF_SAVE_FOLDER ,
85
88
BmpEditor -> bitmapName ,
86
89
".bmp" );
87
- view_dispatcher_send_custom_event (app -> view_dispatcher , SetTextInputSaveEvent );
90
+ view_dispatcher_send_custom_event (app -> view_dispatcher , AppBmpEditorEventSaveText );
88
91
}
89
92
90
93
static void bmp_editor_select_name (void * ctx ) {
@@ -114,6 +117,7 @@ static void bmp_editor_select_file(void* ctx) {
114
117
AppContext * app = (AppContext * )ctx ; // Main app struct
115
118
AppData * appData = (AppData * )app -> data ;
116
119
AppBmpEditor * BmpEditor = app -> sceneBmpEditor ;
120
+
117
121
bmpEditorData * BmpEditorData = BmpEditor -> model_data ;
118
122
Configuration * light_msg_data = (Configuration * )appData -> config ;
119
123
DialogsFileBrowserOptions browser_options ;
@@ -129,16 +133,24 @@ static void bmp_editor_select_file(void* ctx) {
129
133
if (dialog_file_browser_show (BmpEditor -> dialogs , bitmapPath , bitmapPath , & browser_options )) {
130
134
if (BmpEditorData -> bitmap ) bitmapMatrix_free (BmpEditorData -> bitmap );
131
135
BmpEditorData -> bitmap = bmp_to_bitmapMatrix (furi_string_get_cstr (bitmapPath ));
132
- BmpEditorData -> bmp_w = BmpEditorData -> bitmap -> width ;
133
- BmpEditorData -> bmp_h = BmpEditorData -> bitmap -> height ;
134
- BmpEditorData -> state = BmpEditorStateDrawing ;
135
-
136
- memcpy (
137
- BmpEditor -> bitmapPath ,
138
- furi_string_get_cstr (bitmapPath ),
139
- strlen (furi_string_get_cstr (bitmapPath )));
140
- bmp_compute_model (BmpEditor , BmpEditor -> model_data );
141
- view_dispatcher_switch_to_view (app -> view_dispatcher , AppViewBmpEditor );
136
+ if (BmpEditorData -> bitmap -> width > PARAM_BMP_EDITOR_MAX_RES_W ) {
137
+ //if(BmpEditorData->bitmap) bitmapMatrix_free(BmpEditorData->bitmap);
138
+ //furi_string_free(bitmapPath);
139
+ BmpEditorData -> state = BmpEditorStateSizeError ;
140
+ BmpEditorData -> error = L401_ERR_WIDTH ;
141
+ view_dispatcher_switch_to_view (app -> view_dispatcher , AppViewBmpEditor );
142
+ return ;
143
+ } else {
144
+ BmpEditorData -> bmp_w = BmpEditorData -> bitmap -> width ;
145
+ BmpEditorData -> bmp_h = BmpEditorData -> bitmap -> height ;
146
+ BmpEditorData -> state = BmpEditorStateDrawing ;
147
+ memcpy (
148
+ BmpEditor -> bitmapPath ,
149
+ furi_string_get_cstr (bitmapPath ),
150
+ strlen (furi_string_get_cstr (bitmapPath )));
151
+ bmp_compute_model (BmpEditor , BmpEditor -> model_data );
152
+ view_dispatcher_switch_to_view (app -> view_dispatcher , AppViewBmpEditor );
153
+ }
142
154
}
143
155
furi_string_free (bitmapPath );
144
156
}
@@ -149,6 +161,17 @@ static bool bmp_editor_mainmenu_input_callback(InputEvent* input_event, void* ct
149
161
return false;
150
162
}
151
163
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
+
152
175
static bool bmp_editor_select_size_input_callback (InputEvent * input_event , void * ctx ) {
153
176
AppContext * app = (AppContext * )ctx ;
154
177
AppBmpEditor * BmpEditor = app -> sceneBmpEditor ;
@@ -189,32 +212,52 @@ static bool bmp_editor_select_size_input_callback(InputEvent* input_event, void*
189
212
static bool bmp_editor_draw_input_callback (InputEvent * input_event , void * ctx ) {
190
213
AppContext * app = (AppContext * )ctx ;
191
214
AppBmpEditor * BmpEditor = app -> sceneBmpEditor ;
192
-
215
+ bmpEditorData * BmpEditorData = BmpEditor -> model_data ;
193
216
bool consumed = false;
194
217
BMP_err res = BMP_OK ;
195
- if ((input_event -> type == InputTypePress ) || (input_event -> type == InputTypeRepeat )) {
218
+ if ((input_event -> type == InputTypePress ) || (input_event -> type == InputTypeRepeat ) ||
219
+ (input_event -> type == InputTypeLong )) {
196
220
switch (input_event -> key ) {
197
221
case InputKeyUp :
198
222
bmp_editor_move (BmpEditor , 0 , -1 );
223
+ if (BmpEditorData -> draw_mode == BmpEditorDrawModeContinuous ) {
224
+ bmp_editor_toggle (BmpEditor );
225
+ }
199
226
consumed = true;
200
227
break ;
201
228
case InputKeyDown :
202
229
bmp_editor_move (BmpEditor , 0 , 1 );
230
+ if (BmpEditorData -> draw_mode == BmpEditorDrawModeContinuous ) {
231
+ bmp_editor_toggle (BmpEditor );
232
+ }
203
233
consumed = true;
204
234
break ;
205
235
case InputKeyLeft :
206
236
bmp_editor_move (BmpEditor , -1 , 0 );
207
- bmp_compute_model (BmpEditor , BmpEditor -> model_data );
237
+ //bmp_compute_model(BmpEditor, BmpEditor->model_data);
238
+ if (BmpEditorData -> draw_mode == BmpEditorDrawModeContinuous ) {
239
+ bmp_editor_toggle (BmpEditor );
240
+ }
208
241
consumed = true;
209
242
break ;
210
243
case InputKeyRight :
211
244
bmp_editor_move (BmpEditor , 1 , 0 );
212
- bmp_compute_model (BmpEditor , BmpEditor -> model_data );
245
+ //bmp_compute_model(BmpEditor, BmpEditor->model_data);
246
+ if (BmpEditorData -> draw_mode == BmpEditorDrawModeContinuous ) {
247
+ bmp_editor_toggle (BmpEditor );
248
+ }
213
249
consumed = true;
214
250
break ;
215
251
case InputKeyOk :
216
- bmp_editor_toggle (BmpEditor );
217
- view_dispatcher_send_custom_event (app -> view_dispatcher , AppBmpEditorEventToggle );
252
+ if (input_event -> type == InputTypeLong ) {
253
+ BmpEditorData -> draw_mode = (BmpEditorData -> draw_mode == BmpEditorDrawModeOneshot ) ?
254
+ BmpEditorDrawModeContinuous :
255
+ BmpEditorDrawModeOneshot ;
256
+ } else {
257
+ if (BmpEditorData -> draw_mode == BmpEditorDrawModeOneshot ) {
258
+ bmp_editor_toggle (BmpEditor );
259
+ }
260
+ }
218
261
consumed = false;
219
262
break ;
220
263
case InputKeyBack :
@@ -261,6 +304,9 @@ static bool app_scene_bmp_editor_input_callback(InputEvent* input_event, void* c
261
304
case BmpEditorStateDrawing :
262
305
consumed = bmp_editor_draw_input_callback (input_event , ctx );
263
306
break ;
307
+ case BmpEditorStateSizeError :
308
+ consumed = bmp_editor_error_input_callback (input_event , ctx );
309
+ break ;
264
310
default :
265
311
break ;
266
312
}
@@ -290,6 +336,27 @@ static void bmp_editor_drawSizePicker(Canvas* canvas, void* ctx) {
290
336
canvas_draw_str (canvas , 25 + 45 , 62 , "OK" );
291
337
}
292
338
339
+ static void bmp_editor_drawError (Canvas * canvas , void * ctx ) {
340
+ // UNUSED(ctx);
341
+ bmpEditorModel * BmpEditorModel = (bmpEditorModel * )ctx ;
342
+ bmpEditorData * BmpEditorData = BmpEditorModel -> data ;
343
+
344
+ switch (BmpEditorData -> error ) {
345
+ case L401_ERR_WIDTH :
346
+ canvas_clear (canvas );
347
+ canvas_set_font (canvas , FontSecondary );
348
+ canvas_draw_str_aligned (canvas , 64 , 20 , AlignCenter , AlignCenter , "BMP File too large to" );
349
+ canvas_draw_str_aligned (canvas , 64 , 30 , AlignCenter , AlignCenter , "be edited on flipper!" );
350
+ break ;
351
+ default :
352
+ canvas_clear (canvas );
353
+ canvas_set_font (canvas , FontPrimary );
354
+ canvas_draw_str_aligned (canvas , 64 , 10 , AlignCenter , AlignCenter , "Unknown error" );
355
+ break ;
356
+ }
357
+ elements_button_center (canvas , "Return" );
358
+ }
359
+
293
360
static void bmp_editor_drawBoard (Canvas * canvas , void * ctx ) {
294
361
bmpEditorModel * BmpEditorModel = (bmpEditorModel * )ctx ;
295
362
bmpEditorData * BmpEditorData = BmpEditorModel -> data ;
@@ -315,8 +382,12 @@ static void bmp_editor_drawBoard(Canvas* canvas, void* ctx) {
315
382
canvas_draw_str (canvas , 25 + 10 , 62 , "Save" );
316
383
canvas_draw_icon (canvas , 25 + 35 , 56 , & I_btn_ok_7x7 );
317
384
canvas_draw_str (canvas , 25 + 45 , 62 , "Toggle" );
318
-
385
+ // Indicates continuous mode
319
386
canvas_set_font (canvas , FontPrimary );
387
+ if (BmpEditorData -> draw_mode == BmpEditorDrawModeContinuous ) {
388
+ canvas_draw_str (canvas , 0 , 62 , "C" );
389
+ ;
390
+ }
320
391
// Bitmap
321
392
for (x = 0 ; x < BmpEditorData -> bmp_w ; x ++ ) {
322
393
for (y = 0 ; y < BmpEditorData -> bmp_h ; y ++ ) {
@@ -365,6 +436,9 @@ static void app_scene_bmp_editor_render_callback(Canvas* canvas, void* _model) {
365
436
case BmpEditorStateDrawing :
366
437
bmp_editor_drawBoard (canvas , _model );
367
438
break ;
439
+ case BmpEditorStateSizeError :
440
+ bmp_editor_drawError (canvas , _model );
441
+ break ;
368
442
default :
369
443
break ;
370
444
}
@@ -404,6 +478,7 @@ AppBmpEditor* app_bmp_editor_alloc(void* ctx) {
404
478
appBmpEditor -> model_data -> bmp_pixel_spacing = 0 ;
405
479
appBmpEditor -> model_data -> bmp_w = 32 ;
406
480
appBmpEditor -> model_data -> bmp_h = 16 ;
481
+ appBmpEditor -> model_data -> error = L401_OK ;
407
482
appBmpEditor -> mainmenu = submenu_alloc ();
408
483
409
484
submenu_add_item (
@@ -432,11 +507,9 @@ AppBmpEditor* app_bmp_editor_alloc(void* ctx) {
432
507
433
508
appBmpEditor -> view = view_alloc ();
434
509
view_allocate_model (appBmpEditor -> view , ViewModelTypeLocking , sizeof (bmpEditorModel ));
435
-
436
510
view_set_context (appBmpEditor -> view , app );
437
511
view_set_draw_callback (appBmpEditor -> view , app_scene_bmp_editor_render_callback );
438
512
view_set_input_callback (appBmpEditor -> view , app_scene_bmp_editor_input_callback );
439
-
440
513
return appBmpEditor ;
441
514
}
442
515
@@ -536,11 +609,17 @@ bool app_scene_bmp_editor_on_event(void* ctx, SceneManagerEvent event) {
536
609
// UNUSED(ctx);
537
610
bool consumed = false;
538
611
if (event .type == SceneManagerEventTypeCustom ) {
539
- if (event .event == SetTextInputSaveEvent ) {
612
+ switch (event .event ) {
613
+ case AppBmpEditorEventSaveText :
540
614
bmp_editor_init_bitmap (ctx );
541
615
BmpEditorData -> state = BmpEditorStateDrawing ;
542
616
view_dispatcher_switch_to_view (app -> view_dispatcher , AppViewBmpEditor );
543
617
consumed = true;
618
+ break ;
619
+ case AppBmpEditorEventQuit :
620
+ view_dispatcher_switch_to_view (app -> view_dispatcher , BmpEditorViewMainMenu );
621
+ consumed = true;
622
+ break ;
544
623
}
545
624
}
546
625
// scene_manager_next_scene(app->scene_manager, AppSceneMainMenu);
0 commit comments