shithub: puzzles

Download patch

ref: d72db91888c1efddd56c67eee665b0a83c9329eb
parent: e4d05c36d996c3053a66ca29cfe84e9652d501e3
author: Simon Tatham <anakin@pobox.com>
date: Wed Sep 20 12:38:31 EDT 2017

Map Ctrl-Shift-Z to Redo.

This is in addition to the existing keystrokes r, ^R and ^Y. I've
become used to Ctrl-Shift-Z in other GUI games, and my fingers keep
getting confused when my own puzzles don't handle it the same way.

--- a/PuzzleApplet.java
+++ b/PuzzleApplet.java
@@ -126,7 +126,12 @@
                     }
                 }
                 public void keyTyped(KeyEvent e) {
-                    runtimeCall("jcallback_key_event", new int[] {0, 0, e.getKeyChar()});
+                    int key = e.getKeyChar();
+                    if (key == 26 && e.isShiftDown() && e.isControlDown()) {
+                        runtimeCall("jcallback_redo_event", new int[0]);
+                        return;
+                    }
+                    runtimeCall("jcallback_key_event", new int[] {0, 0, key});
                 }
             });
             pp.addMouseListener(new MouseAdapter() {
--- a/emcc.c
+++ b/emcc.c
@@ -310,6 +310,8 @@
         keyevent = MOD_NUM_KEYPAD | '7';
     } else if (!strnullcmp(key, "PageUp") || keycode==33) {
         keyevent = MOD_NUM_KEYPAD | '9';
+    } else if (shift && ctrl && (keycode & 0x1F) == 26) {
+        keyevent = UI_REDO;
     } else if (chr && chr[0] && !chr[1]) {
         keyevent = chr[0] & 0xFF;
     } else if (keycode >= 96 && keycode < 106) {
@@ -323,10 +325,10 @@
     }
 
     if (keyevent >= 0) {
-        if (shift && keyevent >= 0x100)
+        if (shift && (keyevent >= 0x100 && !IS_UI_FAKE_KEY(keyevent)))
             keyevent |= MOD_SHFT;
 
-        if (ctrl) {
+        if (ctrl && !IS_UI_FAKE_KEY(keyevent)) {
             if (keyevent >= 0x100)
                 keyevent |= MOD_CTRL;
             else
--- a/gtk.c
+++ b/gtk.c
@@ -1206,6 +1206,8 @@
 	     event->keyval == GDK_KEY_Delete ||
 	     event->keyval == GDK_KEY_KP_Delete)
         keyval = '\177';
+    else if ((event->keyval == 'z' || event->keyval == 'Z') && shift && ctrl)
+        keyval = UI_REDO;
     else if (event->string[0] && !event->string[1])
         keyval = (unsigned char)event->string[0];
     else
--- a/osx.m
+++ b/osx.m
@@ -687,6 +687,10 @@
 	if (c >= '0' && c <= '9' && ([ev modifierFlags] & NSNumericPadKeyMask))
 	    c |= MOD_NUM_KEYPAD;
 
+        if (c == 26 &&
+            !((NSShiftKeyMask | NSControlKeyMask) & ~[ev modifierFlags]))
+            c = UI_REDO;
+
 	[self processKey:c];
     }
 }
--- a/windows.c
+++ b/windows.c
@@ -3405,8 +3405,18 @@
 	}
 	break;
       case WM_CHAR:
-	if (!midend_process_key(fe->me, 0, 0, (unsigned char)wParam))
-	    PostQuitMessage(0);
+        {
+            int key = (unsigned char)wParam;
+            if (key == '\x1A') {
+                BYTE keystate[256];
+                if (GetKeyboardState(keystate) &&
+                    (keystate[VK_SHIFT] & 0x80) &&
+                    (keystate[VK_CONTROL] & 0x80))
+                    key = UI_REDO;
+            }
+            if (!midend_process_key(fe->me, 0, 0, key))
+                PostQuitMessage(0);
+        }
 	return 0;
       case WM_TIMER:
 	if (fe->timer) {