From: Holger Schemel Date: Thu, 20 Jun 2019 18:43:26 +0000 (+0200) Subject: added support for undo/redo using Ctrl-z/Ctrl-Shift-z in level editor X-Git-Tag: 4.1.4.0~24 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=a59ebe8eb3a68db0a2ffcb8ce5127c767737d5ad;p=rocksndiamonds.git added support for undo/redo using Ctrl-z/Ctrl-Shift-z in level editor --- diff --git a/src/editor.c b/src/editor.c index 81757814..c8444b11 100644 --- a/src/editor.c +++ b/src/editor.c @@ -12355,6 +12355,16 @@ void CopyBrushToClipboard_Small(void) CopyBrushExt(0, 0, 0, 0, 0, CB_BRUSH_TO_CLIPBOARD_SMALL); } +void UndoLevelEditorOperation(void) +{ + ClickOnGadget(level_editor_gadget[GADGET_ID_UNDO], -1); +} + +void RedoLevelEditorOperation(void) +{ + ClickOnGadget(level_editor_gadget[GADGET_ID_UNDO], 3); +} + static void FloodFill(int from_x, int from_y, int fill_element) { FloodFillLevel(from_x, from_y, fill_element, Feld, lev_fieldx, lev_fieldy); @@ -13820,7 +13830,9 @@ static void HandleControlButtons(struct GadgetInfo *gi) break; case GADGET_ID_UNDO: - if (button == 1 && GetKeyModState() & (KMOD_Shift|KMOD_Control)) + if (button < 0) // keep button value (even if modifier keys are pressed) + button = -button; + else if (button == 1 && GetKeyModState() & (KMOD_Shift | KMOD_Control)) button = 3; if (button == 1 && undo_buffer_steps == 0) diff --git a/src/editor.h b/src/editor.h index 09c2ccac..19791965 100644 --- a/src/editor.h +++ b/src/editor.h @@ -31,4 +31,7 @@ void CopyClipboardToBrush(void); void CopyBrushToClipboard(void); void CopyBrushToClipboard_Small(void); +void UndoLevelEditorOperation(void); +void RedoLevelEditorOperation(void); + #endif diff --git a/src/events.c b/src/events.c index 085dd9ff..9526f198 100644 --- a/src/events.c +++ b/src/events.c @@ -1910,6 +1910,13 @@ static void HandleKeysSpecial(Key key) { CopyClipboardToBrush(); } + else if (letter == 'z') // undo or redo last operation + { + if (GetKeyModState() & KMOD_Shift) + RedoLevelEditorOperation(); + else + UndoLevelEditorOperation(); + } } }