Skip to content

Commit

Permalink
Undo/Redo gizmo translate/rotate/scale multiple objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Benualdo committed Sep 29, 2024
1 parent 7e61cd0 commit 0b773b5
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 50 deletions.
8 changes: 6 additions & 2 deletions src/core/IUndoRedo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ namespace vg::core
virtual void Undo() = 0;
virtual void Redo() = 0;

virtual string GetName() const = 0;
virtual string GetEntryName() const = 0;
virtual string GetObjectName() const = 0;
virtual string GetDescription() const = 0;

virtual void AddSubEntry(IUndoRedoEntry * _subEntry) = 0;
virtual const vector<IUndoRedoEntry *> * GetSubEntries() const = 0;
};

struct UndoRedoTarget
Expand All @@ -46,7 +50,7 @@ namespace vg::core

bool isEmpty() const
{
return nullptr == m_object && nullptr == m_prop;
return nullptr == m_object;// && nullptr == m_prop;
}

void clear()
Expand Down
5 changes: 3 additions & 2 deletions src/core/UndoRedo/Entry/UndoRedoPropertyEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ namespace vg::core
class UndoRedoPropertyEntry final : public UndoRedoEntry
{
public:
UndoRedoPropertyEntry(IObject * _object, const IProperty * _prop, IObject * _originalObject, IGameObject * _prefab, IDynamicProperty * _propOverride);
UndoRedoPropertyEntry(IObject * _object, const IProperty * _prop, IObject * _originalObject = nullptr, IGameObject * _prefab = nullptr, IDynamicProperty * _propOverride = nullptr);

void BeforeChange() final override;
void AfterChange() final override;

void Undo() final override;
void Redo() final override;

string GetName() const final override;
string GetEntryName() const final override;
string GetObjectName() const final override;
string GetDescription() const final override;

private:
Expand Down
15 changes: 12 additions & 3 deletions src/core/UndoRedo/Entry/UndoRedoPropertyEntry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ namespace vg::core
UndoRedoPropertyEntry::UndoRedoPropertyEntry(IObject * _object, const IProperty * _prop, IObject * _originalObject, IGameObject * _prefab, IDynamicProperty * _propOverride)
{
m_object = _object;
VG_ASSERT(m_object);

m_prop = (IProperty *)_prop;
VG_ASSERT(m_prop);

m_originalObject = _originalObject;
m_prefab = _prefab;
Expand All @@ -32,11 +35,17 @@ namespace vg::core
}

//--------------------------------------------------------------------------------------
string UndoRedoPropertyEntry::GetName() const
string UndoRedoPropertyEntry::GetEntryName() const
{
return "Property";
}

//--------------------------------------------------------------------------------------
string UndoRedoPropertyEntry::GetObjectName() const
{
return m_object->GetName();
}

//--------------------------------------------------------------------------------------
string UndoRedoPropertyEntry::GetDescription() const
{
Expand All @@ -47,7 +56,7 @@ namespace vg::core
void UndoRedoPropertyEntry::Undo()
{
// Restore the original value serialized in memory before change
VG_INFO("[Undo/Redo] Undo Property \"%s\" (0x%016X) from Object \"%s\" (0x%016X)", m_prop->GetName(), m_prop, m_originalObject->GetName().c_str(), m_object);
VG_INFO("[Undo/Redo] Undo Property \"%s\" (0x%016X) from Object \"%s\" (0x%016X)", m_prop->GetName(), m_prop, m_originalObject? m_originalObject->GetName().c_str() : m_object->GetName().c_str(), m_object);

m_original.resetRead();
Factory * factory = (Factory *)Kernel::getFactory();
Expand All @@ -69,7 +78,7 @@ namespace vg::core
void UndoRedoPropertyEntry::Redo()
{
// Restore the modified value serialized in memory before change
VG_INFO("[Undo/Redo] Redo Property \"%s\" (0x%016X) from Object \"%s\" (0x%016X)", m_prop->GetName(), m_prop, m_originalObject->GetName().c_str(), m_object);
VG_INFO("[Undo/Redo] Redo Property \"%s\" (0x%016X) from Object \"%s\" (0x%016X)", m_prop->GetName(), m_prop, m_originalObject ? m_originalObject->GetName().c_str() : m_object->GetName().c_str(), m_object);

m_modified.resetRead();
Factory * factory = (Factory *)Kernel::getFactory();
Expand Down
2 changes: 2 additions & 0 deletions src/core/UndoRedo/UndoRedo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include "core/Kernel.h"
#include "core/Object/Factory.h"
#include "core/IGameObject.h"
#include "core/string/string.h"

#include "UndoRedoManager.hpp"
#include "UndoRedoEntry.hpp"
#include "UndoRedoEntryGroup.hpp"
#include "Entry/UndoRedoPropertyEntry.hpp"

namespace vg::core
Expand Down
5 changes: 4 additions & 1 deletion src/core/UndoRedo/UndoRedoEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ namespace vg::core
void Undo() override= 0;
void Redo() override= 0;

string GetName() const override = 0;
string GetEntryName() const override = 0;
string GetDescription() const override = 0;

void AddSubEntry(IUndoRedoEntry * _subEntry) final override { VG_ASSERT(false); }
const vector<IUndoRedoEntry *> * GetSubEntries() const final override { return nullptr; }
};
}
32 changes: 32 additions & 0 deletions src/core/UndoRedo/UndoRedoEntryGroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

namespace vg::core
{
class IObject;
class IProperty;
class IDynamicProperty;

class UndoRedoEntryGroup : public IUndoRedoEntry
{
public:
UndoRedoEntryGroup(const string & _name);
~UndoRedoEntryGroup();

void BeforeChange() override;
void AfterChange() override;

void Undo() override;
void Redo() override;

string GetEntryName() const override;
string GetObjectName() const final override;
string GetDescription() const override;

void AddSubEntry(IUndoRedoEntry * _subEntry) final override;
const vector<IUndoRedoEntry *> * GetSubEntries() const final override;

private:
string m_name;
core::vector<IUndoRedoEntry *> m_subEntries;
};
}
85 changes: 85 additions & 0 deletions src/core/UndoRedo/UndoRedoEntryGroup.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "UndoRedoEntryGroup.h"

namespace vg::core
{
//--------------------------------------------------------------------------------------
UndoRedoEntryGroup::UndoRedoEntryGroup(const string & _name) :
m_name(_name)
{

}

//--------------------------------------------------------------------------------------
UndoRedoEntryGroup::~UndoRedoEntryGroup()
{
for (auto * entry : m_subEntries)
VG_SAFE_DELETE(entry);
m_subEntries.clear();
}

//--------------------------------------------------------------------------------------
void UndoRedoEntryGroup::BeforeChange()
{
for (auto * entry : m_subEntries)
entry->BeforeChange();
}

//--------------------------------------------------------------------------------------
void UndoRedoEntryGroup::AfterChange()
{
for (auto * entry : m_subEntries)
entry->AfterChange();
}

//--------------------------------------------------------------------------------------
void UndoRedoEntryGroup::Undo()
{
VG_INFO("[Undo/Redo] Begin Undo Group \"%s\" (0x%016X)", GetEntryName().c_str(), this);

for (auto * entry : m_subEntries)
entry->Undo();

VG_INFO("[Undo/Redo] End Undo Group \"%s\" (0x%016X)", GetEntryName().c_str(), this);
}

//--------------------------------------------------------------------------------------
void UndoRedoEntryGroup::Redo()
{
VG_INFO("[Undo/Redo] Begin Redo Group \"%s\" (0x%016X)", GetEntryName().c_str(), this);

for (auto * entry : m_subEntries)
entry->Redo();

VG_INFO("[Undo/Redo] End Redo Group \"%s\" (0x%016X)", GetEntryName().c_str(), this);
}

//--------------------------------------------------------------------------------------
string UndoRedoEntryGroup::GetEntryName() const
{
return m_name;
}

//--------------------------------------------------------------------------------------
string UndoRedoEntryGroup::GetObjectName() const
{
return fmt::sprintf("%u Object%s", m_subEntries.size(), m_subEntries.size() > 1 ? "s" : "");
}

//--------------------------------------------------------------------------------------
string UndoRedoEntryGroup::GetDescription() const
{
return "";
}

//--------------------------------------------------------------------------------------
void UndoRedoEntryGroup::AddSubEntry(IUndoRedoEntry * _subEntry)
{
m_subEntries.push_back(_subEntry);
}

//--------------------------------------------------------------------------------------
const vector<IUndoRedoEntry *> * UndoRedoEntryGroup::GetSubEntries() const
{
return &m_subEntries;
}
}
1 change: 1 addition & 0 deletions src/core/UndoRedo/UndoRedoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "core/IUndoRedo.h"
#include "UndoRedoEntry.h"
#include "UndoRedoEntryGroup.h"

namespace vg::core
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@
<ClInclude Include="UndoRedo\UndoRedo.h" />
<ClInclude Include="UndoRedo\UndoRedoEntry.h" />
<ClInclude Include="UndoRedo\UndoRedoEntry.hpp" />
<ClInclude Include="UndoRedo\UndoRedoEntryGroup.h" />
<ClInclude Include="UndoRedo\UndoRedoEntryGroup.hpp" />
<ClInclude Include="UndoRedo\UndoRedoManager.h" />
<ClInclude Include="UndoRedo\UndoRedoManager.hpp" />
<ClInclude Include="UndoRedo\UndoRedo_consts.h" />
Expand Down
6 changes: 6 additions & 0 deletions src/core/core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@
<ClInclude Include="UndoRedo\Entry\UndoRedoPropertyEntry.hpp">
<Filter>UndoRedo\Entry</Filter>
</ClInclude>
<ClInclude Include="UndoRedo\UndoRedoEntryGroup.h">
<Filter>UndoRedo</Filter>
</ClInclude>
<ClInclude Include="UndoRedo\UndoRedoEntryGroup.hpp">
<Filter>UndoRedo</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Math\Math.cpp">
Expand Down
4 changes: 2 additions & 2 deletions src/editor/ImGui/Extensions/ImGuiExtensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,13 @@ namespace ImGui
void PushStyle(FontStyle _style)
{
auto * imGuiAdapter = Editor::get()->getRenderer()->GetImGuiAdapter();
imGuiAdapter->PushStyle(_style);
imGuiAdapter->PushFontStyle(_style);
}

//--------------------------------------------------------------------------------------
void PopStyle()
{
auto * imGuiAdapter = Editor::get()->getRenderer()->GetImGuiAdapter();
imGuiAdapter->PopStyle();
imGuiAdapter->PopFontStyle();
}
}
Loading

0 comments on commit 0b773b5

Please sign in to comment.