Skip to content

Commit

Permalink
Draw background to edge of canvas and don't segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
newsch committed May 4, 2019
1 parent f550c71 commit 5253be5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void cursor_move_up(Cursor *cursor, View *view) {
}

void cursor_move_down(Cursor *cursor, View *view) {
if (cursor->y == view->canvas->num_rows - view->y - 2) {
if (cursor->y == view->canvas->num_rows - view->y - 1) {
return;
}
if (cursor->y == view_max_y) {
Expand All @@ -42,7 +42,7 @@ void cursor_move_left(Cursor *cursor, View *view) {
}

void cursor_move_right(Cursor *cursor, View *view) {
if (cursor->x == view->canvas->num_cols - view->x - 2) {
if (cursor->x == view->canvas->num_cols - view->x - 1) {
return;
}
if (cursor->x == view_max_x) {
Expand Down
12 changes: 6 additions & 6 deletions src/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ void redraw_canvas_win() {
int max_x = view_max_x;
int max_y = view_max_y;

if (max_x >= view->canvas->num_cols - view->x)
(max_x = view->canvas->num_cols - view->x - 1);
if (max_y >= view->canvas->num_rows - view->y)
(max_y = view->canvas->num_rows - view->y - 1);
if (max_x > view->canvas->num_cols - view->x)
(max_x = view->canvas->num_cols - view->x);
if (max_y > view->canvas->num_rows - view->y)
(max_y = view->canvas->num_rows - view->y);

// draw canvas onto window
for (int x = 0; x <= max_x; x++) {
for (int y = 0; y <= max_y; y++) {
for (int x = 0; x <= max_x - 1; x++) {
for (int y = 0; y <= max_y - 1; y++) {
mvwaddch(canvas_win, y + 1, x + 1,
canvas_gcharyx(view->canvas, y + view->y, x + view->x));
}
Expand Down

0 comments on commit 5253be5

Please sign in to comment.