From cb2df22ec2a6ecc0421beeef35d77aa9c2a4a816 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 9 Dec 2015 17:14:38 -1000 Subject: [PATCH] Removed view ownership (client should do this) --- specter/include/Specter/Button.hpp | 2 +- specter/include/Specter/Control.hpp | 6 +++--- specter/include/Specter/RootView.hpp | 4 ++-- specter/include/Specter/Space.hpp | 4 ++-- specter/include/Specter/SplitView.hpp | 4 ++-- specter/include/Specter/Toolbar.hpp | 6 +++--- specter/lib/Button.cpp | 6 +++--- specter/lib/Control.cpp | 10 ++++++---- specter/lib/RootView.cpp | 6 ++++-- specter/lib/Space.cpp | 7 +++---- specter/lib/SplitView.cpp | 7 +++---- 11 files changed, 32 insertions(+), 30 deletions(-) diff --git a/specter/include/Specter/Button.hpp b/specter/include/Specter/Button.hpp index 66edca3e1..eef2e3aee 100644 --- a/specter/include/Specter/Button.hpp +++ b/specter/include/Specter/Button.hpp @@ -38,7 +38,7 @@ public: }; Button(ViewResources& res, View& parentView, - std::unique_ptr&& controlBinding, const std::string& text); + IButtonBinding* controlBinding, const std::string& text); void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseEnter(const boo::SWindowCoord&); diff --git a/specter/include/Specter/Control.hpp b/specter/include/Specter/Control.hpp index 0a28af9d9..7e598b437 100644 --- a/specter/include/Specter/Control.hpp +++ b/specter/include/Specter/Control.hpp @@ -44,15 +44,15 @@ struct CVarControlBinding : IControlBinding class Control : public View { protected: - std::unique_ptr m_controlBinding; + IControlBinding* m_controlBinding = nullptr; public: - Control(ViewResources& res, View& parentView, std::unique_ptr&& controlBinding); + Control(ViewResources& res, View& parentView, IControlBinding* controlBinding); void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseEnter(const boo::SWindowCoord&); void mouseLeave(const boo::SWindowCoord&); - void setControlBinding(std::unique_ptr&& controlBinding); + IControlBinding* setControlBinding(IControlBinding* controlBinding); }; } diff --git a/specter/include/Specter/RootView.hpp b/specter/include/Specter/RootView.hpp index 8ecbf1a12..d041b6839 100644 --- a/specter/include/Specter/RootView.hpp +++ b/specter/include/Specter/RootView.hpp @@ -63,12 +63,12 @@ public: ViewResources& viewRes() const {return *m_viewRes;} const ThemeData& themeData() const {return m_viewRes->m_theme;} - void setContentView(std::unique_ptr&& view); + View* setContentView(View* view); void displayTooltip(const std::string& name, const std::string& help); private: - std::unique_ptr m_view; + View* m_view = nullptr; std::unique_ptr m_tooltip; }; diff --git a/specter/include/Specter/Space.hpp b/specter/include/Specter/Space.hpp index 06f406654..3fc6c3615 100644 --- a/specter/include/Specter/Space.hpp +++ b/specter/include/Specter/Space.hpp @@ -13,12 +13,12 @@ class Space : public View std::unique_ptr m_toolbar; bool m_toolbarMouseIn = false; bool m_toolbarMouseDown = false; - std::unique_ptr m_contentView; + View* m_contentView = nullptr; bool m_contentMouseIn = false; bool m_contentMouseDown = false; public: Space(ViewResources& res, View& parentView, Toolbar::Position toolbarPos); - std::unique_ptr setContentView(std::unique_ptr&& view); + View* setContentView(View* view); Toolbar& toolbar() {return *m_toolbar;} void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); diff --git a/specter/include/Specter/SplitView.hpp b/specter/include/Specter/SplitView.hpp index ef75d4019..400285b2b 100644 --- a/specter/include/Specter/SplitView.hpp +++ b/specter/include/Specter/SplitView.hpp @@ -36,7 +36,7 @@ private: struct Child { - std::unique_ptr m_view; + View* m_view = nullptr; bool m_mouseIn = false; bool m_mouseDown = false; }; @@ -74,7 +74,7 @@ private: boo::IShaderDataBinding* m_splitShaderBinding; public: SplitView(ViewResources& res, View& parentView, Axis axis); - std::unique_ptr setContentView(int slot, std::unique_ptr&& view); + View* setContentView(int slot, View* view); void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseMove(const boo::SWindowCoord&); diff --git a/specter/include/Specter/Toolbar.hpp b/specter/include/Specter/Toolbar.hpp index 8cbe2f4b1..36fffa92a 100644 --- a/specter/include/Specter/Toolbar.hpp +++ b/specter/include/Specter/Toolbar.hpp @@ -27,10 +27,10 @@ private: Position m_tbPos; struct Child { - std::unique_ptr m_view; + View* m_view = nullptr; bool m_mouseIn = false; bool m_mouseDown = false; - Child(std::unique_ptr&& v) : m_view(std::move(v)) {} + Child(View* v) : m_view(v) {} }; std::vector m_children; @@ -106,7 +106,7 @@ public: int nominalHeight() const {return m_nomHeight;} void clear() {m_children.clear();} - void push_back(std::unique_ptr&& v) {m_children.push_back(std::move(v));} + void push_back(View* v) {m_children.push_back(v);} }; } diff --git a/specter/lib/Button.cpp b/specter/lib/Button.cpp index 07bd6d91c..3b52c1ab4 100644 --- a/specter/lib/Button.cpp +++ b/specter/lib/Button.cpp @@ -12,8 +12,8 @@ void Button::Resources::init(boo::IGraphicsDataFactory* factory, const ThemeData } Button::Button(ViewResources& res, View& parentView, - std::unique_ptr&& controlBinding, const std::string& text) -: Control(res, parentView, std::move(controlBinding)), m_textStr(text) + IButtonBinding* controlBinding, const std::string& text) +: Control(res, parentView, controlBinding), m_textStr(text) { m_bBlockBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Uniform, sizeof(ViewBlock), 1); m_bVertsBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SolidShaderVert), 28); @@ -153,7 +153,7 @@ void Button::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, b if (m_pressed && m_hovered) { Log.report(LogVisor::Info, "button '%s' activated", m_textStr.c_str()); - if (m_controlBinding && dynamic_cast(m_controlBinding.get())) + if (m_controlBinding && dynamic_cast(m_controlBinding)) static_cast(*m_controlBinding).pressed(coord); } m_pressed = false; diff --git a/specter/lib/Control.cpp b/specter/lib/Control.cpp index 39746c00c..2640e501b 100644 --- a/specter/lib/Control.cpp +++ b/specter/lib/Control.cpp @@ -4,12 +4,14 @@ namespace Specter { Control::Control(ViewResources& res, View& parentView, - std::unique_ptr&& controlBinding) -: View(res, parentView), m_controlBinding(std::move(controlBinding)) {} + IControlBinding* controlBinding) +: View(res, parentView), m_controlBinding(controlBinding) {} -void Control::setControlBinding(std::unique_ptr&& controlBinding) +IControlBinding* Control::setControlBinding(IControlBinding* controlBinding) { - m_controlBinding = std::move(controlBinding); + IControlBinding* ret = m_controlBinding; + m_controlBinding = controlBinding; + return ret; } void Control::mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey) diff --git a/specter/lib/RootView.cpp b/specter/lib/RootView.cpp index 89c9b0e6e..7b56175b1 100644 --- a/specter/lib/RootView.cpp +++ b/specter/lib/RootView.cpp @@ -122,10 +122,12 @@ void RootView::modKeyUp(boo::EModifierKey mod) { } -void RootView::setContentView(std::unique_ptr&& view) +View* RootView::setContentView(View* view) { - m_view = std::move(view); + View* ret = m_view; + m_view = view; updateSize(); + return ret; } void RootView::displayTooltip(const std::string& name, const std::string& help) diff --git a/specter/lib/Space.cpp b/specter/lib/Space.cpp index 63c9afa85..b1dae9b95 100644 --- a/specter/lib/Space.cpp +++ b/specter/lib/Space.cpp @@ -13,11 +13,10 @@ Space::Space(ViewResources& res, View& parentView, Toolbar::Position tbPos) m_toolbar.reset(new Toolbar(res, *this, tbPos)); } -std::unique_ptr Space::setContentView(std::unique_ptr&& view) +View* Space::setContentView(View* view) { - std::unique_ptr ret; - m_contentView.swap(ret); - m_contentView = std::move(view); + View* ret = m_contentView; + m_contentView = view; updateSize(); return ret; } diff --git a/specter/lib/SplitView.cpp b/specter/lib/SplitView.cpp index b6a1d6962..4d40bbefb 100644 --- a/specter/lib/SplitView.cpp +++ b/specter/lib/SplitView.cpp @@ -51,13 +51,12 @@ SplitView::SplitView(ViewResources& system, View& parentView, Axis axis) commitResources(system); } -std::unique_ptr SplitView::setContentView(int slot, std::unique_ptr&& view) +View* SplitView::setContentView(int slot, View* view) { if (slot < 0 || slot > 1) Log.report(LogVisor::FatalError, "out-of-range slot to RootView::SplitView::setContentView"); - std::unique_ptr ret; - m_views[slot].m_view.swap(ret); - m_views[slot].m_view = std::move(view); + View* ret = m_views[slot].m_view; + m_views[slot].m_view = view; m_views[slot].m_mouseDown = false; m_views[slot].m_mouseIn = false; updateSize();