summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralex <alex@ASUS>2018-09-01 21:02:01 +0200
committeralex <alex@ASUS>2018-09-01 21:02:01 +0200
commited45167e9c73b13006262ac23389af6ce689bea6 (patch)
tree87499e05588fcd34dc5e874e5cb646bcede4eb61
parentb044e6f99dc6fdbc6609f5c4d05ec5d05cc22929 (diff)
Modify player TUI to refresh help window only when needed: solve cursor blinking
-rw-r--r--modules/game/inc/game_iface.h6
-rw-r--r--modules/player/src/player_clui.c6
-rw-r--r--modules/player/src/player_tui.c70
3 files changed, 48 insertions, 34 deletions
diff --git a/modules/game/inc/game_iface.h b/modules/game/inc/game_iface.h
index a920e99..9b61e7d 100644
--- a/modules/game/inc/game_iface.h
+++ b/modules/game/inc/game_iface.h
@@ -94,14 +94,16 @@
};
enum Game_Iface_State {
- GAME_IFACE_STATE_PLAYING = 0,
+ GAME_IFACE_STATE_PLAYING,
GAME_IFACE_STATE_SAFE,
GAME_IFACE_STATE_GAMEOVER,
GAME_IFACE_STATE_PAUSE,
GAME_IFACE_STATE_CHEATED,
GAME_IFACE_STATE_XYZZY,
- GAME_IFACE_STATE_QUIT
+ GAME_IFACE_STATE_QUIT,
+
+ GAME_IFACE_STATE_FOO
};
diff --git a/modules/player/src/player_clui.c b/modules/player/src/player_clui.c
index fb3f6a5..7e47d2f 100644
--- a/modules/player/src/player_clui.c
+++ b/modules/player/src/player_clui.c
@@ -457,11 +457,11 @@ static void show_help (const struct Game_Iface_Out *board)
static void show_help_start (void)
{
- puts( "Move " "|Step " "|Save " "|Quit " "|Confirm");
- printf(" %c%c%c%c %c%c%c%c| %c ""| %c ""| %c ""| Enter\n",
+ puts( "Move " "|Step " "|Quit " "|Confirm");
+ printf(" %c%c%c%c %c%c%c%c| %c ""| %c ""| Enter\n",
'h','j','k','l',
'<','v','^','>',
- '+', 's', 'q');
+ '+', 'q');
}
static void show_help_play (void)
diff --git a/modules/player/src/player_tui.c b/modules/player/src/player_tui.c
index 5e83f82..7033a63 100644
--- a/modules/player/src/player_tui.c
+++ b/modules/player/src/player_tui.c
@@ -48,6 +48,7 @@ bool flag_color;
* * * * * * * * * */
static WINDOW *win_board;
static WINDOW *win_help;
+static int last_help;
/******************************************************************************
@@ -132,14 +133,14 @@ void player_tui_init (int rows, int cols)
const int w1 = 2 * cols + 3;
const int r1 = 0;
const int c1 = 11;
- win_board = newwin(h1, w1, r1, c1);
+ win_board = newwin(h1, w1, r1, c1);
/* Dimensions: help */
const int h2 = 24;
const int w2 = 10;
const int r2 = 0;
const int c2 = 0;
- win_help = newwin(h2, w2, r2, c2);
+ win_help = newwin(h2, w2, r2, c2);
/* Activate keypad, don't echo input, and set timeout = REFRESH_TIME_MS ms */
keypad(win_board, true);
@@ -666,41 +667,49 @@ static int usr_input (void)
* * * * * * * * * */
static void show_help (const struct Game_Iface_Out *board)
{
- /* Clear */
- werase(win_help);
+ if (last_help != board->state) {
+ /* Clear */
+ werase(win_help);
- switch (board->state) {
- case GAME_IFACE_STATE_PLAYING:
- show_help_play();
- break;
+ switch (board->state) {
+ case GAME_IFACE_STATE_PLAYING:
+ show_help_play();
+ break;
- case GAME_IFACE_STATE_PAUSE:
- show_help_pause();
- break;
+ case GAME_IFACE_STATE_PAUSE:
+ show_help_pause();
+ break;
- case GAME_IFACE_STATE_XYZZY:
- show_help_xyzzy();
- break;
+ case GAME_IFACE_STATE_XYZZY:
+ show_help_xyzzy();
+ break;
- case GAME_IFACE_STATE_CHEATED:
- show_help_cheat();
- break;
+ case GAME_IFACE_STATE_CHEATED:
+ show_help_cheat();
+ break;
- case GAME_IFACE_STATE_SAFE:
- show_help_safe();
- break;
+ case GAME_IFACE_STATE_SAFE:
+ show_help_safe();
+ break;
- case GAME_IFACE_STATE_GAMEOVER:
- show_help_gameover();
- break;
- }
+ case GAME_IFACE_STATE_GAMEOVER:
+ show_help_gameover();
+ break;
+ }
- /* Refresh */
- wrefresh(win_help);
+ /* Refresh */
+ wrefresh(win_help);
+
+ /* Update last_help */
+ last_help = board->state;
+ }
}
static void show_help_start (void)
{
+ /* Clear */
+ werase(win_help);
+
int r;
int c;
@@ -734,11 +743,14 @@ static void show_help_start (void)
mvwaddstr(win_help, r++, c, "Step:");
mvwprintw(win_help, r++, c, " Enter / %c", '+');
- mvwaddstr(win_help, r++, c, "Save:");
- mvwprintw(win_help, r++, c, " %c", 's');
-
mvwaddstr(win_help, r++, c, "Quit:");
mvwprintw(win_help, r++, c, " %c", 'q');
+
+ /* Refresh */
+ wrefresh(win_help);
+
+ /* Update last_help */
+ last_help = GAME_IFACE_STATE_FOO;
}
static void show_help_play (void)