From 8a71abf79c4840742ba80e524859c05c67a14228 Mon Sep 17 00:00:00 2001 From: girst Date: Wed, 28 Feb 2018 00:49:36 +0100 Subject: [PATCH] working invert cursor --- mines_2017.c | 36 +++++++++++++++++++++--------------- schemes.h | 6 ++++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/mines_2017.c b/mines_2017.c index 9d4f464..e62b99a 100644 --- a/mines_2017.c +++ b/mines_2017.c @@ -97,6 +97,7 @@ enum modes { NORMAL, REDUCED, SHOWMINES, + HIGHLIGHT, }; enum flagtypes { NOFLAG, @@ -493,7 +494,7 @@ void flag_square (int l, int c) { are allowed) */ f.c[l][c].f = (f.c[l][c].f + 1) % (op.mode + 1); if (f.c[l][c].f==FLAG) f.f++; - else f.f--; + else f.f--; //WARN: breaks on `-q'! partial_show_minefield (l, c, NORMAL); move (1, op.scheme->cell_width); printf ("[%03d]", f.f); @@ -563,26 +564,31 @@ void cursor_move (int l, int c) { f.p[1] = CLAMP(c, 0, f.w-1); move (f.p[0]+LINE_OFFSET, field2screen_c(f.p[1])); //fputs (op.scheme->mouse_highlight, stdout); - print("\033[7m");//invert - partial_show_minefield (f.p[0], f.p[1], NORMAL); + + if (!f.c[f.p[0]][f.p[1]].f) print("\033[7m");//invert unless ! or ? + partial_show_minefield (f.p[0], f.p[1], HIGHLIGHT); print("\033[0m");//un-invert } char* cell2schema (int l, int c, int mode) { + struct minecell cell = f.c[l][c]; + /* move past invert-ctrlsequence when highlighting the cursor: */ + int offset = ((mode==HIGHLIGHT)*op.scheme->flag_offset); + if (mode == SHOWMINES) return ( - f.c[l][c].f == FLAG && f.c[l][c].m ? op.scheme->field_flagged: - f.c[l][c].f == FLAG && !f.c[l][c].m ? op.scheme->mine_wrongf: - f.c[l][c].m == STD_MINE ? op.scheme->mine_normal: - f.c[l][c].m == DEATH_MINE ? op.scheme->mine_death: - f.c[l][c].o == CLOSED ? op.scheme->field_closed: - /*...........................*/ op.scheme->number[f.c[l][c].n]); + cell.f == FLAG && cell.m ? op.scheme->field_flagged+offset: + cell.f == FLAG && !cell.m ? op.scheme->mine_wrongf+offset: + cell.m == STD_MINE ? op.scheme->mine_normal: + cell.m == DEATH_MINE ? op.scheme->mine_death: + cell.o == CLOSED ? op.scheme->field_closed: + /*.......................*/ op.scheme->number[f.c[l][c].n]); else return ( - f.c[l][c].f == FLAG ? op.scheme->field_flagged: - f.c[l][c].f == QUESM ? op.scheme->field_question: - f.c[l][c].o == CLOSED ? op.scheme->field_closed: - f.c[l][c].m == STD_MINE ? op.scheme->mine_normal: - f.c[l][c].m == DEATH_MINE ? op.scheme->mine_death: - /*...........................*/ op.scheme->number[f.c[l][c].n]); + cell.f == FLAG ? op.scheme->field_flagged+offset: + cell.f == QUESM ? op.scheme->field_question+offset: + cell.o == CLOSED ? op.scheme->field_closed: + cell.m == STD_MINE ? op.scheme->mine_normal: + cell.m == DEATH_MINE ? op.scheme->mine_death: + /*.......................*/ op.scheme->number[f.c[l][c].n]); } void partial_show_minefield (int l, int c, int mode) { diff --git a/schemes.h b/schemes.h index 95cabec..554ac54 100644 --- a/schemes.h +++ b/schemes.h @@ -35,6 +35,7 @@ struct minescheme { char* border_bottom_r; int cell_width; + int flag_offset; char* init_seq; char* reset_seq; }; @@ -42,8 +43,8 @@ struct minescheme { struct minescheme symbols_mono = { .number = {" ", "1", "2", "3", "4", "5", "6", "7", "8"}, .field_closed = "░░", - .field_flagged = "⢕⢕",//⡱⢎",//⣏⣹",//▄▀",//▓▓",//██",//▒▒", - .field_question = "?", + .field_flagged = "\033[7m!\033[0m",//⢕⢕",//⡱⢎",//⣏⣹",//▄▀",//▓▓",//██",//▒▒", + .field_question = "\033[7m?\033[0m", .mouse_highlight = "▓▓", .mine_normal = "*", .mine_death = "#", @@ -69,6 +70,7 @@ struct minescheme symbols_mono = { .border_bottom_r = "═╝", .cell_width = 2, + .flag_offset = 4, //length of the escape sequece infront of .field_flagged and .field_question for cursor highlighting }; struct minescheme symbols_col1 = { -- 2.39.3