diff --git a/README.md b/README.md index 7d3b238..0842301 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ This isn't an exhaustive list, but these are some features I would like to add t - [x] Display clicked positions - [x] Redraw components when resized -- [ ] Support undo (with ``) and redo (with `` or ``) +- [x] Support undo (with ``) and redo (with `` or ``) - [ ] Export to code - Possibly different options like creating a flat array/vector or an index buffer - [ ] Linear interpolation diff --git a/dotscape b/dotscape index 9e5f2fa..4a21257 100755 Binary files a/dotscape and b/dotscape differ diff --git a/ffi/glfw-input.c b/ffi/glfw-input.c index c16f0ea..5538bf6 100644 --- a/ffi/glfw-input.c +++ b/ffi/glfw-input.c @@ -5,6 +5,7 @@ int PRESS = GLFW_PRESS; int RELEASE = GLFW_RELEASE; int LEFT_MOUSE_BUTTON = GLFW_MOUSE_BUTTON_1; int KEY_Z = GLFW_KEY_Z; +int KEY_Y = GLFW_KEY_Y; // Calls function exported from SML void mouseMoveCallback(GLFWwindow *window, double xpos, double ypos) { diff --git a/ffi/glfw-input.sml b/ffi/glfw-input.sml index 340243e..f829574 100644 --- a/ffi/glfw-input.sml +++ b/ffi/glfw-input.sml @@ -33,4 +33,6 @@ struct val (KEY_Z, _) = _symbol "KEY_Z" public : ( unit -> int ) * ( int -> unit ); + val (KEY_Y, _) = + _symbol "KEY_Y" public : ( unit -> int ) * ( int -> unit ); end diff --git a/imperative-shell/input-callbacks.sml b/imperative-shell/input-callbacks.sml index 04ef7b7..5122021 100644 --- a/imperative-shell/input-callbacks.sml +++ b/imperative-shell/input-callbacks.sml @@ -21,9 +21,24 @@ struct fun keyActionCallback mailbox (key, scancode, action, mods) = if key = Input.KEY_Z () andalso action <> Input.RELEASE () + then + if mods = 0x0002 then + (* ctrl-z *) + Mailbox.send (mailbox, UNDO_ACTION) + else if mods = 0x0003 then + (* ctrl-shift-z *) + Mailbox.send (mailbox, REDO_ACTION) + else + (* no action recognised *) + () + else if + key = Input.KEY_Y () andalso action <> Input.RELEASE () andalso mods = 0x0002 - then Mailbox.send (mailbox, UNDO_ACTION) - else () + then + (* ctrl-y *) + Mailbox.send (mailbox, REDO_ACTION) + else + () fun registerCallbacks (window, inputMailbox) = let