~ruther/CTU-FEE-B0B35APO-Semestral-project

a7da48b6ab870a0b6110b17953839e2b0601a6b3 — František Boháček 3 years ago c2d2df6
fix: image region move within to not set wrong x, y
1 files changed, 4 insertions(+), 2 deletions(-)

M image-viewer/src/image.c
M image-viewer/src/image.c => image-viewer/src/image.c +4 -2
@@ 1,4 1,5 @@
#include "image.h"
#include "direction.h"
#include "display_utils.h"
#include <stdlib.h>



@@ 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;

Do not follow this link