From b3d15b6a39ef9c9b97da4790d81d3a20049cf50d Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sat, 1 Oct 2022 20:34:23 +0800 Subject: [PATCH] Added WIP UndoRedoStack --- SHADE_Managed/src/Editor/Editor.cxx | 2 +- SHADE_Managed/src/Editor/UndoRedoStack .cxx | 49 +++++++++++++++++++++ SHADE_Managed/src/Editor/UndoRedoStack.hxx | 48 ++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 SHADE_Managed/src/Editor/UndoRedoStack .cxx create mode 100644 SHADE_Managed/src/Editor/UndoRedoStack.hxx diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index 629c9e65..73d52d14 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -3,7 +3,7 @@ \author Tng Kah Wei, kahwei.tng, 390009620 \par email: kahwei.tng\@digipen.edu \date Sep 27, 2022 -\brief Contains the definition of the functions for the ScriptStore managed +\brief Contains the definition of the functions for the Editor managed static class. Note: This file is written in C++17/CLI. diff --git a/SHADE_Managed/src/Editor/UndoRedoStack .cxx b/SHADE_Managed/src/Editor/UndoRedoStack .cxx new file mode 100644 index 00000000..e3fdc2f0 --- /dev/null +++ b/SHADE_Managed/src/Editor/UndoRedoStack .cxx @@ -0,0 +1,49 @@ +/************************************************************************************//*! +\file UndoRedoStack.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Sep 29, 2022 +\brief Contains the definition of the functions for the UndoRedoStack managed + class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "UndoRedoStack.hxx" +// External Dependencies +#include "Editor/SHEditorUI.h" +// Project Headers + +namespace SHADE +{ + void UndoRedoStack::Add(Command command) + { + // Erase any other actions ahead of the current action + if (latestActionIndex < commandStack->Count - 1) + { + commandStack->RemoveRange(latestActionIndex + 1, commandStack->Count - latestActionIndex); + } + + // Add the command + commandStack->Add(command); + + // Increment latest command + ++latestActionIndex; + } + + void UndoRedoStack::Undo() + { + + } + + void UndoRedoStack::Redo() + { + + } +} diff --git a/SHADE_Managed/src/Editor/UndoRedoStack.hxx b/SHADE_Managed/src/Editor/UndoRedoStack.hxx new file mode 100644 index 00000000..2db3cacb --- /dev/null +++ b/SHADE_Managed/src/Editor/UndoRedoStack.hxx @@ -0,0 +1,48 @@ +/************************************************************************************//*! +\file UndoRedoStack.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Sep 29, 2022 +\brief Contains the definition of the managed UndoRedoStack class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +namespace SHADE +{ + /// + /// Class that is able to store a stack of actions that can be done and redone. + /// + private ref class UndoRedoStack sealed + { + public: + /*-----------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------*/ + value struct Command + { + public: + System::Action^ UndoAction; + System::Action^ RedoAction; + }; + + /*-----------------------------------------------------------------------------*/ + /* Usage Functions */ + /*-----------------------------------------------------------------------------*/ + void Add(Command command); + void Undo(); + void Redo(); + + private: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + int latestActionIndex = -1; + System::Collections::Generic::List^ commandStack = gcnew System::Collections::Generic::List(); + }; +}