From 39d3fe40626a9e107cbad3fca9aae2816ff73ddb Mon Sep 17 00:00:00 2001 From: Prizrak9 Date: Sat, 27 Feb 2021 11:13:23 +0200 Subject: [PATCH] fixed delete all leaving selected object --- CHANGE_LOG.md | 3 +- StereoPlus2/DomainUtils.hpp | 104 +++++++++++++++++++++--------------- StereoPlus2/main.cpp | 5 +- StereoPlus2/settings.json | 2 +- 4 files changed, 68 insertions(+), 46 deletions(-) diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md index 8dd8109..13af3e8 100644 --- a/CHANGE_LOG.md +++ b/CHANGE_LOG.md @@ -39,4 +39,5 @@ # 0.13.1 - introduced unique naming; - fixed sine curve disappearing when rotation is nan; -- when switching between SinePen Step123 and Step132 the cross will move to the existant relevant point (optional); \ No newline at end of file +- when switching between SinePen Step123 and Step132 the cross will move to the existant relevant point (optional); +- fixed delete all (Close) command leaving selected objects alive and rendered; \ No newline at end of file diff --git a/StereoPlus2/DomainUtils.hpp b/StereoPlus2/DomainUtils.hpp index 18d152a..b8fedd3 100644 --- a/StereoPlus2/DomainUtils.hpp +++ b/StereoPlus2/DomainUtils.hpp @@ -8,6 +8,56 @@ enum SelectPosition { Rest = 0x10, }; +class ObjectSelection { +public: + using Selection = std::set; +private: + static Selection& selected() { + static Selection v; + return v; + } + static Event& onChanged() { + static Event v; + return v; + } +public: + static IEvent& OnChanged() { + return onChanged(); + } + + static const Selection& Selected() { + return selected(); + } + static const Selection** SelectedP() { + static const Selection* v = &selected(); + return &v; + } + + static void Set(SceneObject* o) { + selected().clear(); + selected().emplace(o); + onChanged().Invoke(selected()); + } + static void Set(const std::vector& os) { + selected().clear(); + for (auto o : os) + selected().emplace(o); + onChanged().Invoke(selected()); + } + static void Add(SceneObject* o) { + selected().emplace(o); + onChanged().Invoke(selected()); + } + static void RemoveAll() { + selected().clear(); + onChanged().Invoke(selected()); + } + static void Remove(SceneObject* o) { + selected().erase(o); + onChanged().Invoke(selected()); + } +}; + class StateBuffer { public: // Buffer requires 1 additional state for saving current state. @@ -22,6 +72,8 @@ class StateBuffer { // Objects in their original order std::vector> objects; + std::vector selection; + SceneObject* rootCopy; }; @@ -57,6 +109,9 @@ class StateBuffer { current->objects.push_back({ o.Get(), o }); current->copies[o.Get()] = o->Clone(); } + + for (auto& o : ObjectSelection::Selected()) + current->selection.push_back(o.Get()); } // Erase saved copies. @@ -102,6 +157,12 @@ class StateBuffer { objects.push_back(b); } + std::vector newSelection; + for (auto o : saved.selection) + newSelection.push_back(newCopies[o]); + + ObjectSelection::Set(newSelection); + auto newRoot = saved.rootCopy->Clone(); newRoot->CallRecursive((SceneObject*)nullptr, std::function([&](SceneObject* o, SceneObject* p) { @@ -183,49 +244,6 @@ class StateBuffer { } }; -class ObjectSelection { -public: - using Selection = std::set; -private: - static Selection& selected() { - static Selection v; - return v; - } - static Event& onChanged() { - static Event v; - return v; - } -public: - static IEvent& OnChanged() { - return onChanged(); - } - - static const Selection& Selected() { - return selected(); - } - static const Selection** SelectedP() { - static const Selection* v = &selected(); - return &v; - } - - static void Set(SceneObject* o) { - selected().clear(); - selected().emplace(o); - onChanged().Invoke(selected()); - } - static void Add(SceneObject* o) { - selected().emplace(o); - onChanged().Invoke(selected()); - } - static void RemoveAll() { - selected().clear(); - onChanged().Invoke(selected()); - } - static void Remove(SceneObject* o) { - selected().erase(o); - onChanged().Invoke(selected()); - } -}; class DragDropBuffer { diff --git a/StereoPlus2/main.cpp b/StereoPlus2/main.cpp index 9873e99..8b40947 100644 --- a/StereoPlus2/main.cpp +++ b/StereoPlus2/main.cpp @@ -161,7 +161,6 @@ int main() { }); - ToolPool::Cross() = ✗ ToolPool::Scene() = &scene; ToolPool::KeyBinding() = &gui.keyBinding; @@ -183,6 +182,10 @@ int main() { if (!LocaleProvider::Init()) return false; + scene.OnDeleteAll() += [] { + ObjectSelection::RemoveAll(); + }; + // Position detector doesn't initialize itself // so we need to help it. positionDetector.onStartProcess = [&positionDetector] { diff --git a/StereoPlus2/settings.json b/StereoPlus2/settings.json index 99b308a..3510dcd 100644 --- a/StereoPlus2/settings.json +++ b/StereoPlus2/settings.json @@ -1 +1 @@ -{"language":"ua","ppi":92.56,"logFileName":"log.txt","stateBufferLength":100,"translationStep":1,"useDiscreteMovement":1,"rotationStep":1,"scalingStep":0.01,"mouseSensivity":0.01,"colorLeft":[1,0,0,1],"colorRight":[0,1,1,1],"dimmedColorLeft":[1,0,0,0.5],"dimmedColorRight":[0,1,1,0.5],"customRenderWindowAlpha":1,"shouldMoveCrossOnSinePenModeChange":1} \ No newline at end of file +{"language":"ua","ppi":92.56,"logFileName":"log.txt","stateBufferLength":100,"translationStep":1,"useDiscreteMovement":1,"rotationStep":10,"scalingStep":0.01,"mouseSensivity":0.01,"colorLeft":[1,0,0,1],"colorRight":[0,1,1,1],"dimmedColorLeft":[1,0,0,0.5],"dimmedColorRight":[0,1,1,0.5],"customRenderWindowAlpha":1,"shouldMoveCrossOnSinePenModeChange":1} \ No newline at end of file