From a7da48b6ab870a0b6110b17953839e2b0601a6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Wed, 16 Jun 2021 10:53:02 +0200 Subject: [PATCH] fix: image region move within to not set wrong x, y --- image-viewer/src/image.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/image-viewer/src/image.c b/image-viewer/src/image.c index 902199e112e128a765c38a3b396ec02c81aadf14..d089f6d682b2c8e539f60eb3b8a0c12a6424f155 100644 --- a/image-viewer/src/image.c +++ b/image-viewer/src/image.c @@ -1,4 +1,5 @@ #include "image.h" +#include "direction.h" #include "display_utils.h" #include @@ -38,17 +39,18 @@ bool image_region_move_within(image_region_t *to_move, direction_t direction, int amount, image_region_t *border) { int32_t x = to_move->x; int32_t y = to_move->y; + direction_move_xy(direction, &x, &y, amount); if (x < border->x) { x = border->x; } else if (x + to_move->width >= border->width + border->x) { - x = border->x + border->width - 1; + x = border->x + border->width - 1 - to_move->width; } if (y < border->y) { y = border->y; } else if (y + to_move->height >= border->height + border->y) { - y = border->x + border->height - 1; + y = border->x + border->height - 1 - to_move->height; } bool changed = to_move->x != x || to_move->y != y;