2024-03-10 23:35:44 +03:00
|
|
|
/**
|
|
|
|
* @file example_images.c
|
|
|
|
* @brief Custom images example.
|
|
|
|
*/
|
2022-10-06 16:55:57 +03:00
|
|
|
#include <furi.h>
|
|
|
|
#include <furi_hal.h>
|
|
|
|
|
|
|
|
#include <gui/gui.h>
|
|
|
|
#include <input/input.h>
|
|
|
|
|
2022-10-12 19:12:05 +03:00
|
|
|
/* Magic happens here -- this file is generated by fbt.
|
|
|
|
* Just set fap_icon_assets in application.fam and #include {APPID}_icons.h */
|
2022-10-06 16:55:57 +03:00
|
|
|
#include "example_images_icons.h"
|
|
|
|
|
|
|
|
typedef struct {
|
2024-03-25 14:04:07 +03:00
|
|
|
int32_t x, y;
|
2022-10-06 16:55:57 +03:00
|
|
|
} ImagePosition;
|
|
|
|
|
|
|
|
static ImagePosition image_position = {.x = 0, .y = 0};
|
|
|
|
|
|
|
|
// Screen is 128x64 px
|
|
|
|
static void app_draw_callback(Canvas* canvas, void* ctx) {
|
|
|
|
UNUSED(ctx);
|
|
|
|
|
|
|
|
canvas_clear(canvas);
|
2024-03-25 14:04:07 +03:00
|
|
|
canvas_draw_icon(canvas, image_position.x, image_position.y, &I_dolphin_71x25);
|
2022-10-06 16:55:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void app_input_callback(InputEvent* input_event, void* ctx) {
|
|
|
|
furi_assert(ctx);
|
|
|
|
|
|
|
|
FuriMessageQueue* event_queue = ctx;
|
|
|
|
furi_message_queue_put(event_queue, input_event, FuriWaitForever);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t example_images_main(void* p) {
|
|
|
|
UNUSED(p);
|
|
|
|
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
|
|
|
|
|
|
|
|
// Configure view port
|
|
|
|
ViewPort* view_port = view_port_alloc();
|
2024-04-18 17:22:36 +03:00
|
|
|
view_port_draw_callback_set(view_port, app_draw_callback, NULL);
|
2022-10-06 16:55:57 +03:00
|
|
|
view_port_input_callback_set(view_port, app_input_callback, event_queue);
|
|
|
|
|
|
|
|
// Register view port in GUI
|
|
|
|
Gui* gui = furi_record_open(RECORD_GUI);
|
|
|
|
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
|
|
|
|
|
|
|
InputEvent event;
|
|
|
|
|
|
|
|
bool running = true;
|
|
|
|
while(running) {
|
|
|
|
if(furi_message_queue_get(event_queue, &event, 100) == FuriStatusOk) {
|
|
|
|
if((event.type == InputTypePress) || (event.type == InputTypeRepeat)) {
|
|
|
|
switch(event.key) {
|
|
|
|
case InputKeyLeft:
|
|
|
|
image_position.x -= 2;
|
|
|
|
break;
|
|
|
|
case InputKeyRight:
|
|
|
|
image_position.x += 2;
|
|
|
|
break;
|
|
|
|
case InputKeyUp:
|
|
|
|
image_position.y -= 2;
|
|
|
|
break;
|
|
|
|
case InputKeyDown:
|
|
|
|
image_position.y += 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
running = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
view_port_update(view_port);
|
|
|
|
}
|
|
|
|
|
|
|
|
view_port_enabled_set(view_port, false);
|
|
|
|
gui_remove_view_port(gui, view_port);
|
|
|
|
view_port_free(view_port);
|
|
|
|
furi_message_queue_free(event_queue);
|
|
|
|
|
|
|
|
furi_record_close(RECORD_GUI);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|