From ff37eed7139cfe41ca34aca09f45fd4f9d64c4c7 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:44:59 +0200 Subject: [PATCH] fix: add missing include guards --- image-viewer/include/image_loader.h | 5 +++++ image-viewer/include/input.h | 5 +++++ image-viewer/include/logger.h | 6 +++--- image-viewer/src/cursor.c | 21 +++++---------------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/image-viewer/include/image_loader.h b/image-viewer/include/image_loader.h index 7693cf0..cb080dc 100644 --- a/image-viewer/include/image_loader.h +++ b/image-viewer/include/image_loader.h @@ -1,3 +1,6 @@ +#ifndef __IMAGE_LOADER_H__ +#define __IMAGE_LOADER_H__ + #include "image.h" image_error_t image_loader_load(image_t *image); @@ -7,3 +10,5 @@ image_error_t image_loader_load_jpeg(image_t *image); image_error_t image_loader_load_png(image_t *image); image_error_t image_deduce_type(image_t *image); + +#endif // __IMAGE_LOADER_H__ diff --git a/image-viewer/include/input.h b/image-viewer/include/input.h index 58707a4..25baab8 100644 --- a/image-viewer/include/input.h +++ b/image-viewer/include/input.h @@ -1,3 +1,6 @@ +#ifndef __INPUT_H__ +#define __INPUT_H__ + #include #include #include @@ -55,3 +58,5 @@ bool commands_register(commands_t *commands, input_type_t type, bool commands_unregister(commands_t *commands, command_t *command); short commands_check_input(commands_t *commands); + +#endif // __INPUT_H__ diff --git a/image-viewer/include/logger.h b/image-viewer/include/logger.h index 5ddb30d..c78f34b 100644 --- a/image-viewer/include/logger.h +++ b/image-viewer/include/logger.h @@ -1,5 +1,5 @@ -#ifndef _LOGGER_H -#define _LOGGER_H +#ifndef __LOGGER_H__ +#define __LOGGER_H__ #include @@ -41,4 +41,4 @@ void logger_warn(logger_t *logger, const char *file, const char *function, void logger_error(logger_t *logger, const char *file, const char *function, int line, const char *const message, ...); -#endif //_LOGGER_H +#endif //__LOGGER_H__ diff --git a/image-viewer/src/cursor.c b/image-viewer/src/cursor.c index 2823de2..b5a0115 100644 --- a/image-viewer/src/cursor.c +++ b/image-viewer/src/cursor.c @@ -1,4 +1,5 @@ #include "cursor.h" +#include "direction.h" #include "display_utils.h" #include "image.h" @@ -20,23 +21,9 @@ void cursor_center(cursor_t *cursor, image_region_t *region) { cursor->y = region->y + region->height / 2; } -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) { uint16_t x = cursor->x, y = cursor->y; - - switch (direction) { - case LEFT: - x -= amount; - break; - case RIGHT: - x += amount; - break; - case UP: - y -= amount; - break; - case DOWN: - y += amount; - break; - } + direction_move_xy(direction, &x, &y, amount); if (x < region->x) { x = region->x; @@ -50,8 +37,10 @@ void cursor_move(cursor_t *cursor, image_region_t *region, direction_t direction y = region->y + region->height - 1; } + bool moved = cursor->x != x || cursor->y != y; cursor->x = x; cursor->y = y; + return moved; } void cursor_show(cursor_t *cursor, display_t *display) { -- 2.48.1