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

3a9ba38c24ff51f54d5f40526550f9916bc8f0ab — František Boháček 3 years ago b5c4266
refactor: make move cursor handlers to one function
1 files changed, 16 insertions(+), 12 deletions(-)

M image-viewer/src/image_viewer.c
M image-viewer/src/image_viewer.c => image-viewer/src/image_viewer.c +16 -12
@@ 30,40 30,44 @@ void image_viewer_destroy(image_viewer_t *viewer) {
  image_destroy(&viewer->image);
}

void command_handler_move_cursor(void *data, direction_t direction, int amount) {
  image_viewer_t *viewer = (image_viewer_t *)data;

  if (!cursor_move(&viewer->cursor, &viewer->display_region, direction, amount)) {
    image_region_move_within(&viewer->region, direction, (int)(amount * viewer->scale_factor), &viewer->display_region);
    image_viewer_display_image(viewer);
  }

  cursor_show(&viewer->cursor, viewer->display);
  display_render(viewer->display);
}

void command_handler_move_left(void *data, int amount) {
  image_viewer_t *viewer = (image_viewer_t*)data;
  logger_debug(viewer->logger, __FILE__, __FUNCTION__, __LINE__,
               "Moving cursor to left by %d", amount);
  cursor_move(&viewer->cursor, &viewer->region, LEFT, amount);
  cursor_show(&viewer->cursor, viewer->display);
  display_render(viewer->display);
  command_handler_move_cursor(data, LEFT, amount);
}

void command_handler_move_right(void *data, int amount) {
  image_viewer_t *viewer = (image_viewer_t *)data;
  logger_debug(viewer->logger, __FILE__, __FUNCTION__, __LINE__,
               "Moving cursor to right by %d", amount);
  cursor_move(&viewer->cursor, &viewer->region, RIGHT, amount);
  cursor_show(&viewer->cursor, viewer->display);
  display_render(viewer->display);
  command_handler_move_cursor(data, RIGHT, amount);
}

void command_handler_move_up(void *data, int amount) {
  image_viewer_t *viewer = (image_viewer_t *)data;
  logger_debug(viewer->logger, __FILE__, __FUNCTION__, __LINE__,
               "Moving cursor up by %d", amount);
  cursor_move(&viewer->cursor, &viewer->region, UP, amount);
  cursor_show(&viewer->cursor, viewer->display);
  display_render(viewer->display);
  command_handler_move_cursor(data, UP, amount);
}

void command_handler_move_down(void *data, int amount) {
  image_viewer_t *viewer = (image_viewer_t *)data;
  logger_debug(viewer->logger, __FILE__, __FUNCTION__, __LINE__,
               "Moving cursor down by %d", amount);
  cursor_move(&viewer->cursor, &viewer->region, DOWN, amount);
  cursor_show(&viewer->cursor, viewer->display);
  display_render(viewer->display);
  command_handler_move_cursor(data, DOWN, amount);
}

void command_handler_exit(void *data, int amount) {

Do not follow this link