M image-viewer/include/cursor.h => image-viewer/include/cursor.h +3 -9
@@ 3,6 3,7 @@
#include "display_utils.h"
#include "image.h"
+#include "direction.h"
#include <time.h>
#include <stdint.h>
@@ 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);
A image-viewer/include/direction.h => image-viewer/include/direction.h +15 -0
@@ 0,0 1,15 @@
+#ifndef __DIRECTION_H__
+#define __DIRECTION_H__
+
+#include <stdint.h>
+
+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__
A image-viewer/src/direction.c => image-viewer/src/direction.c +18 -0
@@ 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;
+ }
+}