chiark / gitweb /
Refactor modifier handling in Pearl's cursor code.
[sgt-puzzles.git] / pearl.c
diff --git a/pearl.c b/pearl.c
index 8b1afe9ace3f9bf0f5c291c07c9469857d339ce7..83413a2b9ecdb9a647836a76265faa9914235cdf 100644 (file)
--- a/pearl.c
+++ b/pearl.c
@@ -1722,12 +1722,38 @@ done:
 
 static int game_can_format_as_text_now(const game_params *params)
 {
-    return FALSE;
+    return TRUE;
 }
 
 static char *game_text_format(const game_state *state)
 {
-    return NULL;
+    int w = state->shared->w, h = state->shared->h, cw = 4, ch = 2;
+    int gw = cw*(w-1) + 2, gh = ch*(h-1) + 1, len = gw * gh, r, c, j;
+    char *board = snewn(len + 1, char);
+
+    assert(board);
+    memset(board, ' ', len);
+
+    for (r = 0; r < h; ++r) {
+       for (c = 0; c < w; ++c) {
+           int i = r*w + c, cell = r*ch*gw + c*cw;
+           board[cell] = state->shared->clues[i]["+BW"];
+           if (c < w - 1 && (state->lines[i] & R || state->lines[i+1] & L))
+               memset(board + cell + 1, '-', cw - 1);
+           if (r < h - 1 && (state->lines[i] & D || state->lines[i+w] & U))
+               for (j = 1; j < ch; ++j) board[cell + j*gw] = '|';
+           if (c < w - 1 && (state->marks[i] & R || state->marks[i+1] & L))
+               board[cell + cw/2] = 'x';
+           if (r < h - 1 && (state->marks[i] & D || state->marks[i+w] & U))
+               board[cell + (ch/2 * gw)] = 'x';
+       }
+
+       for (j = 0; j < (r == h - 1 ? 1 : ch); ++j)
+           board[r*ch*gw + (gw - 1) + j*gw] = '\n';
+    }
+
+    board[len] = '\0';
+    return board;
 }
 
 struct game_ui {
@@ -1972,6 +1998,9 @@ static char *interpret_move(const game_state *state, game_ui *ui,
     int release = FALSE;
     char tmpbuf[80];
 
+    int shift = button & MOD_SHFT, control = button & MOD_CTRL;
+    button &= ~MOD_MASK;
+
     if (IS_MOUSE_DOWN(button)) {
        ui->cursor_active = FALSE;
 
@@ -1994,10 +2023,10 @@ static char *interpret_move(const game_state *state, game_ui *ui,
 
     if (IS_MOUSE_RELEASE(button)) release = TRUE;
 
-    if (IS_CURSOR_MOVE(button & ~MOD_MASK)) {
+    if (IS_CURSOR_MOVE(button)) {
        if (!ui->cursor_active) {
            ui->cursor_active = TRUE;
-       } else if (button & (MOD_SHFT | MOD_CTRL)) {
+       } else if (control | shift) {
            if (ui->ndragcoords > 0) return NULL;
            ui->ndragcoords = -1;
            return mark_in_direction(state, ui->curx, ui->cury,
@@ -2011,7 +2040,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
        return "";
     }
 
-    if (IS_CURSOR_SELECT(button & ~MOD_MASK)) {
+    if (IS_CURSOR_SELECT(button)) {
        if (!ui->cursor_active) {
            ui->cursor_active = TRUE;
            return "";
@@ -2537,7 +2566,7 @@ const struct game thegame = {
     dup_game,
     free_game,
     TRUE, solve_game,
-    FALSE, game_can_format_as_text_now, game_text_format,
+    TRUE, game_can_format_as_text_now, game_text_format,
     new_ui,
     free_ui,
     encode_ui,