From 5fba286cef29542703b78f9cb63dbd7ebaf6f725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Tue, 15 Jun 2021 23:41:44 +0200 Subject: [PATCH] refactor: move direction functions to separate module --- image-viewer/include/cursor.h | 12 +++--------- image-viewer/include/direction.h | 15 +++++++++++++++ image-viewer/src/direction.c | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 image-viewer/include/direction.h create mode 100644 image-viewer/src/direction.c diff --git a/image-viewer/include/cursor.h b/image-viewer/include/cursor.h index 2304d8b..d68492f 100644 --- a/image-viewer/include/cursor.h +++ b/image-viewer/include/cursor.h @@ -3,6 +3,7 @@ #include "display_utils.h" #include "image.h" +#include "direction.h" #include #include @@ -18,18 +19,11 @@ typedef struct { display_pixel_t previous_display_data[CURSOR_SIZE * 2 - 1]; } cursor_t; -typedef enum { - UP, - LEFT, - DOWN, - RIGHT, -} direction_t; - -const display_pixel_t CURSOR_COLOR = {.fields = {.r = (uint8_t)DISPLAY_MAX_RED, .g = 0, .b = 0}}; +extern const display_pixel_t CURSOR_COLOR; cursor_t cursor_create(); void cursor_center(cursor_t *cursor, image_region_t *region); -void cursor_move(cursor_t *cursor, image_region_t *region, direction_t direction, uint8_t amount); +bool cursor_move(cursor_t *cursor, image_region_t *region, direction_t direction, int16_t amount); void cursor_show(cursor_t *cursor, display_t *display); void cursor_hide(cursor_t *cursor, display_t *display); diff --git a/image-viewer/include/direction.h b/image-viewer/include/direction.h new file mode 100644 index 0000000..ad7b454 --- /dev/null +++ b/image-viewer/include/direction.h @@ -0,0 +1,15 @@ +#ifndef __DIRECTION_H__ +#define __DIRECTION_H__ + +#include + +typedef enum { + UP, + LEFT, + DOWN, + RIGHT, +} direction_t; + +void direction_move_xy(direction_t direction, uint16_t *x, uint16_t *y, int16_t amount); + +#endif // __DIRECTION_H__ diff --git a/image-viewer/src/direction.c b/image-viewer/src/direction.c new file mode 100644 index 0000000..8ca6223 --- /dev/null +++ b/image-viewer/src/direction.c @@ -0,0 +1,18 @@ +#include "direction.h" + +void direction_move_xy(direction_t direction, uint16_t *x, uint16_t *y, int16_t amount) { + switch (direction) { + case LEFT: + *x -= amount; + break; + case RIGHT: + *x += amount; + break; + case UP: + *y -= amount; + break; + case DOWN: + *y += amount; + break; + } +} -- 2.48.1