From 0818a32f690eb74f05edc3ce8f57990c697ae103 Mon Sep 17 00:00:00 2001 From: Philip Johansson Date: Tue, 29 Dec 2020 22:09:17 +0100 Subject: [PATCH] removed screen flicker on rapid input --- README.md | 7 ++++--- src/Window.cpp | 37 ++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 44f87f8..5a2539d 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,10 @@ libcurses or curses instead. If it still doesn't work use the -lncurses flag ins of -lncursesw when compiling. ## Screenshots -![new game](https://imgur.com/awu4dbQ.png) -![Same game with pencil marks, a couple boxes filled in and a mistake](https://imgur.com/ooYHXm0.png) -![Same game after check board has been called](https://imgur.com/vF97N1b.png) +![new game](https://i.imgur.com/tdfuKdU.png) +![same game played a little](https://imgur.com/ooYHXm0.png) +![same game with check](https://imgur.com/vF97N1b.png) +![completed game]() ## Generate or Solve Sudoku Puzzles You can use the Generator files and Solver files to generate diff --git a/src/Window.cpp b/src/Window.cpp index 0d1cc64..5f67e0f 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -34,34 +34,37 @@ Window::~Window() { } void Window::printBoard() { + int oldRows = windowRows; + int oldCols = windowCols; getmaxyx(stdscr, windowRows, windowCols); + bool resize = (oldRows != windowRows || oldCols != windowCols); boardTop = (windowRows - BoardRows) / 2; boardLeft = (windowCols - BoardCols) / 2; int gridTop = boardTop + 1; int gridLeft = boardLeft + 2; - clear(); - - if (windowRows < BoardRows || windowCols < BoardCols) { - char error[] = "Not enough space to draw board"; - mvprintw(windowRows / 2, (windowCols - strlen(error)) / 2, "%s", error); - refresh(); - return; - } - - if (windowRows - BoardRows > 3) { - attron(A_BOLD | A_UNDERLINE); - char title[] = "Console Sudoku"; - mvprintw(boardTop - 3, (windowCols - strlen(title)) / 2, "%s", title); - attroff(A_BOLD | A_UNDERLINE); + if (resize) { + clear(); + if (windowRows < BoardRows || windowCols < BoardCols) { + char error[] = "Not enough space to draw board"; + mvprintw(windowRows / 2, (windowCols - strlen(error)) / 2, "%s", error); + refresh(); + return; + } + if (windowRows - BoardRows > 3) { + attron(A_BOLD | A_UNDERLINE); + char title[] = "Console Sudoku"; + mvprintw(boardTop - 3, (windowCols - strlen(title)) / 2, "%s", title); + attroff(A_BOLD | A_UNDERLINE); + } + printBoxes(); + printInstructions(); + printCoords(); } - printBoxes(); printPencil(); printNumbs(); - printInstructions(); - printCoords(); printMode(); printCursor(); refresh();