Files
iroBot/main/swipe_gesture.c
Neil Arora a87cf44759 Remove GIF decoder and add swipe gesture support
Deleted GIF decoder files (app_gifdec.c/h) and blink emotion asset. Added swipe_gesture.c/h for new gesture handling. Updated CMakeLists and emotion_manager to reflect these changes. Added Geist font asset.
2026-01-14 20:05:02 +05:30

56 lines
1.9 KiB
C

#include "swipe_gesture.h"
#include "lvgl.h"
#include <stdlib.h>
// Pastel color definitions
#define COLOR_PASTEL_GREEN lv_color_hex(0xA8E6CF)
#define COLOR_PASTEL_RED lv_color_hex(0xFFB3BA)
#define COLOR_BLACK lv_color_hex(0x000000)
static lv_point_t start_point;
static void swipe_gesture_cb(lv_event_t *e) {
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *scr = lv_event_get_target(e);
lv_indev_t *indev = lv_indev_get_act();
if (!indev)
return;
if (code == LV_EVENT_PRESSED) {
lv_indev_get_point(indev, &start_point);
} else if (code == LV_EVENT_PRESSING) {
lv_point_t curr_point;
lv_indev_get_point(indev, &curr_point);
lv_coord_t diff_x = curr_point.x - start_point.x;
lv_coord_t scr_width = lv_obj_get_width(scr);
if (scr_width <= 0)
scr_width = 368; // LCD_H_RES fallback
float proportion = (float)abs(diff_x) / (float)scr_width;
if (proportion > 1.0f)
proportion = 1.0f;
// Target color based on swipe direction (Right = Green, Left = Red)
lv_color_t target = (diff_x > 0) ? COLOR_PASTEL_GREEN : COLOR_PASTEL_RED;
// Blend target color with black based on swipe proportion
lv_opa_t opa = (lv_opa_t)(proportion * 255);
lv_color_t blended = lv_color_mix(target, COLOR_BLACK, opa);
lv_obj_set_style_bg_color(scr, blended, LV_PART_MAIN);
lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, LV_PART_MAIN);
} else if (code == LV_EVENT_RELEASED || code == LV_EVENT_PRESS_LOST) {
// Return to black on release
lv_obj_set_style_bg_color(scr, COLOR_BLACK, LV_PART_MAIN);
}
}
void swipe_gesture_init(lv_obj_t *scr) {
// Register event callbacks on the screen to track touch manually
lv_obj_add_event_cb(scr, swipe_gesture_cb, LV_EVENT_PRESSED, NULL);
lv_obj_add_event_cb(scr, swipe_gesture_cb, LV_EVENT_PRESSING, NULL);
lv_obj_add_event_cb(scr, swipe_gesture_cb, LV_EVENT_RELEASED, NULL);
lv_obj_add_event_cb(scr, swipe_gesture_cb, LV_EVENT_PRESS_LOST, NULL);
}