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

ff7e1283be434e42a449b0adeefd82d830730f67 — František Boháček 3 years ago fede96e
refactor: unify cursor functions
2 files changed, 14 insertions(+), 14 deletions(-)

M image-viewer/include/cursor.h
M image-viewer/src/cursor.c
M image-viewer/include/cursor.h => image-viewer/include/cursor.h +2 -2
@@ 22,8 22,8 @@ typedef struct {
extern const display_pixel_t CURSOR_COLOR;

cursor_t cursor_create();
void cursor_center(cursor_t *cursor, image_region_t *region);
bool cursor_move(cursor_t *cursor, image_region_t *region, direction_t direction, int16_t amount);
void cursor_center(cursor_t *cursor, image_region_t region);
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);

M image-viewer/src/cursor.c => image-viewer/src/cursor.c +12 -12
@@ 16,25 16,25 @@ cursor_t cursor_create() {
  return cursor;
}

void cursor_center(cursor_t *cursor, image_region_t *region) {
  cursor->x = region->x + region->width / 2;
  cursor->y = region->y + region->height / 2;
void cursor_center(cursor_t *cursor, image_region_t region) {
  cursor->x = region.x + region.width / 2;
  cursor->y = region.y + region.height / 2;
}

bool cursor_move(cursor_t *cursor, image_region_t *region, direction_t direction, int16_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;
  direction_move_xy(direction, &x, &y, amount);

  if (x < region->x) {
    x = region->x;
  } else if (x > region->x + region->width - 1) {
    x = region->x + region->width - 1;
  if (x < region.x) {
    x = region.x;
  } else if (x > region.x + region.width - 1) {
    x = region.x + region.width - 1;
  }

  if (y < region->y) {
    y = region->y;
  } else if (y > region->y + region->height - 1) {
    y = region->y + region->height - 1;
  if (y < region.y) {
    y = region.y;
  } else if (y > region.y + region.height - 1) {
    y = region.y + region.height - 1;
  }

  bool moved = cursor->x != x || cursor->y != y;

Do not follow this link