From 0dad45e8949ef930df0d21441b45ada339453212 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 11 Dec 2015 14:37:32 -1000 Subject: [PATCH] Recreated test layout in new space architecture --- Editor/CMakeLists.txt | 4 +- Editor/ResourceOutliner/ResourceOutliner.hpp | 12 ++-- Editor/Space.cpp | 12 ++++ Editor/Space.hpp | 66 +++++++++++++++++--- Editor/ViewManager.cpp | 43 +++++-------- Editor/ViewManager.hpp | 47 +++++++------- 6 files changed, 115 insertions(+), 69 deletions(-) diff --git a/Editor/CMakeLists.txt b/Editor/CMakeLists.txt index 6920d49b6..fe619cf8e 100644 --- a/Editor/CMakeLists.txt +++ b/Editor/CMakeLists.txt @@ -1,6 +1,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(locale) +atdna(atdna_Space.cpp Space.hpp) + set(SPACE_HEADERS ResourceOutliner/ResourceOutliner.hpp) @@ -9,7 +11,7 @@ set(SPACE_SOURCES add_executable(rude WIN32 main.cpp - Space.hpp Space.cpp + Space.hpp Space.cpp atdna_Space.cpp ${SPACE_HEADERS} ${SPACE_SOURCES} ViewManager.hpp ViewManager.cpp) diff --git a/Editor/ResourceOutliner/ResourceOutliner.hpp b/Editor/ResourceOutliner/ResourceOutliner.hpp index 9607e80a9..f8613d8dc 100644 --- a/Editor/ResourceOutliner/ResourceOutliner.hpp +++ b/Editor/ResourceOutliner/ResourceOutliner.hpp @@ -6,15 +6,13 @@ namespace RUDE { -struct ResourceOutlinerState : SpaceState -{ - DECL_YAML -}; - class ResourceOutliner : public Space { - ResourceOutlinerState m_state; - SpaceState& spaceState() {return m_state;} + struct State : SpaceState + { + DECL_YAML + } m_state; + SpaceState* spaceState() {return &m_state;} }; } diff --git a/Editor/Space.cpp b/Editor/Space.cpp index 551f99a8d..ec3b91a9b 100644 --- a/Editor/Space.cpp +++ b/Editor/Space.cpp @@ -1,7 +1,19 @@ #include "Space.hpp" +#include "ViewManager.hpp" namespace RUDE { +Specter::Space* Space::buildSpace(Specter::ViewResources& res) +{ + m_space.reset(new Specter::Space(res, m_vm.rootView(), Specter::Toolbar::Position::Bottom)); + return m_space.get(); +} + +Specter::View* SplitSpace::buildContent(Specter::ViewResources& res) +{ + m_splitView.reset(new Specter::SplitView(res, m_vm.rootView(), Specter::SplitView::Axis::Horizontal)); + return m_splitView.get(); +} } diff --git a/Editor/Space.hpp b/Editor/Space.hpp index b31a163dd..cacb385a8 100644 --- a/Editor/Space.hpp +++ b/Editor/Space.hpp @@ -2,7 +2,7 @@ #define RUDE_SPACE_HPP #include -#include +#include namespace Specter { @@ -15,44 +15,92 @@ namespace RUDE { class ViewManager; -struct SpaceState : Athena::io::DNAYaml {}; +struct SpaceState : Athena::io::DNAYaml {Delete _d;}; class Space { - std::unique_ptr m_space; public: enum class Class { None, - Split, + SplitSpace, + TestSpace, ResourceOutliner, }; protected: + friend class ViewManager; ViewManager& m_vm; Class m_class = Class::None; + std::unique_ptr m_space; Space(ViewManager& vm, Class cls) : m_vm(vm), m_class(cls) {} - Space(ViewManager& vm, Class cls, Athena::io::IStreamReader& r) : m_vm(vm), m_class(cls) {} + Space(ViewManager& vm, Class cls, Athena::io::IStreamReader& r) : m_vm(vm), m_class(cls) + {if (spaceState()) spaceState()->read(r);} void writeState(Athena::io::IStreamWriter& w) const; /* Allows common Space code to access DNA-encoded state */ - virtual SpaceState& spaceState()=0; + virtual SpaceState* spaceState() {return nullptr;} /* Structural control */ virtual bool usesToolbar() const {return false;} virtual void buildToolbar(Specter::ViewResources& res, Specter::Toolbar& tb) {} virtual Specter::View* buildContent(Specter::ViewResources& res)=0; public: + Specter::Space* buildSpace(Specter::ViewResources& res); }; -class Split : public Space +class SplitSpace : public Space { - std::unique_ptr m_split; + friend class ViewManager; + std::unique_ptr m_splitView; struct State : SpaceState { DECL_YAML Value m_split; } m_state; - SpaceState& spaceState() {return m_state;} + SpaceState* spaceState() {return &m_state;} + +public: + SplitSpace(ViewManager& vm) + : Space(vm, Class::SplitSpace) {} + Specter::View* buildContent(Specter::ViewResources& res); +}; + +class TestSpace : public Space +{ + std::unique_ptr m_button; + std::unique_ptr m_textView; + + std::string m_contentStr; + std::string m_buttonStr; + + Specter::IButtonBinding* m_binding; + +public: + TestSpace(ViewManager& vm, const std::string& content, const std::string& button, + Specter::IButtonBinding* binding) + : Space(vm, Class::TestSpace), m_contentStr(content), m_buttonStr(button), m_binding(binding) + {} + + struct State : SpaceState + { + DECL_YAML + } m_state; + SpaceState* spaceState() {return &m_state;} + + bool usesToolbar() const {return true;} + void buildToolbar(Specter::ViewResources& res, Specter::Toolbar& tb) + { + m_button.reset(new Specter::Button(res, tb, m_binding, m_buttonStr)); + tb.push_back(m_button.get()); + } + + Specter::View* buildContent(Specter::ViewResources& res) + { + m_textView.reset(new Specter::MultiLineTextView(res, *m_space, res.m_heading14)); + m_textView->setBackground(res.themeData().viewportBackground()); + m_textView->typesetGlyphs(m_contentStr, res.themeData().uiText()); + return m_textView.get(); + } }; } diff --git a/Editor/ViewManager.cpp b/Editor/ViewManager.cpp index 2008ac930..7a95512f0 100644 --- a/Editor/ViewManager.cpp +++ b/Editor/ViewManager.cpp @@ -1,44 +1,29 @@ #include "ViewManager.hpp" #include "Specter/Control.hpp" +#include "Specter/Space.hpp" using YAMLNode = Athena::io::YAMLNode; namespace RUDE { +Specter::View* ViewManager::BuildSpaceViews(RUDE::Space* space) +{ + Specter::Space* sspace = space->buildSpace(m_viewResources); + Specter::View* sview = space->buildContent(m_viewResources); + sspace->setContentView(sview); + if (space->usesToolbar()) + space->buildToolbar(m_viewResources, sspace->toolbar()); + return sspace; +} + void ViewManager::SetupRootView() { m_rootView.reset(new Specter::RootView(*this, m_viewResources, m_mainWindow.get())); - m_splitView.reset(new Specter::SplitView(m_viewResources, *m_rootView, Specter::SplitView::Axis::Horizontal)); - m_rootView->setContentView(m_splitView.get()); - - m_space1.reset(new Specter::Space(m_viewResources, *m_splitView, Specter::Toolbar::Position::Top)); - m_butt1.reset(new Specter::Button(m_viewResources, m_space1->toolbar(), - &m_setTo1, "Hello Button")); - m_space1->toolbar().push_back(m_butt1.get()); - - m_space2.reset(new Specter::Space(m_viewResources, *m_splitView, Specter::Toolbar::Position::Bottom)); - m_butt2.reset(new Specter::Button(m_viewResources, m_space2->toolbar(), - &m_setTo2, "こんにちはボタン")); - m_space2->toolbar().push_back(m_butt2.get()); - - m_splitView->setContentView(0, m_space1.get()); - m_splitView->setContentView(1, m_space2.get()); - m_rootView->setBackground(Zeus::CColor::skGrey); - - m_textView1.reset(new Specter::MultiLineTextView(m_viewResources, *m_space1, m_viewResources.m_heading18)); - m_space1->setContentView(m_textView1.get()); - - m_textView2.reset(new Specter::MultiLineTextView(m_viewResources, *m_space2, m_viewResources.m_heading18)); - m_space2->setContentView(m_textView2.get()); - - m_textView1->typesetGlyphs("Hello, World!\n\n", m_viewResources.themeData().uiText()); - m_textView2->typesetGlyphs("こんにちは世界!\n\n", m_viewResources.themeData().uiText()); - - m_textView1->setBackground(m_viewResources.themeData().viewportBackground()); - m_textView2->setBackground(m_viewResources.themeData().viewportBackground()); - + m_rootView->setContentView(m_split.buildContent(m_viewResources)); + m_split.m_splitView->setContentView(0, BuildSpaceViews(&m_space1)); + m_split.m_splitView->setContentView(1, BuildSpaceViews(&m_space2)); m_rootView->updateSize(); } diff --git a/Editor/ViewManager.hpp b/Editor/ViewManager.hpp index 3bdeb4ab6..4a08d3dcd 100644 --- a/Editor/ViewManager.hpp +++ b/Editor/ViewManager.hpp @@ -1,7 +1,6 @@ #ifndef RUDE_VIEW_MANAGER_HPP #define RUDE_VIEW_MANAGER_HPP -#include #include #include "Space.hpp" @@ -15,36 +14,15 @@ class ViewManager : Specter::IViewManager Specter::ViewResources m_viewResources; std::unique_ptr m_mainWindow; std::unique_ptr m_rootView; - std::unique_ptr m_splitView; - - std::unique_ptr m_space1; - std::unique_ptr m_butt1; - std::unique_ptr m_textView1; - std::unique_ptr m_space2; - std::unique_ptr m_butt2; - std::unique_ptr m_textView2; HECL::CVar* m_cvPixelFactor; bool m_updatePf = false; float m_reqPf; + Specter::View* BuildSpaceViews(RUDE::Space* space); void SetupRootView(); public: - ViewManager(HECL::Runtime::FileStoreManager& fileMgr, HECL::CVarManager& cvarMgr) - : m_cvarManager(cvarMgr), m_fontCache(fileMgr), m_setTo1(*this), m_setTo2(*this) {} - - Specter::RootView& rootView() const {return *m_rootView;} - void RequestPixelFactor(float pf) - { - m_reqPf = pf; - m_updatePf = true; - } - - void init(boo::IApplication* app); - bool proc(); - void stop(); - struct SetTo1 : Specter::IButtonBinding { ViewManager& m_vm; @@ -76,6 +54,29 @@ public: } }; SetTo2 m_setTo2; + + SplitSpace m_split; + TestSpace m_space1; + TestSpace m_space2; + + ViewManager(HECL::Runtime::FileStoreManager& fileMgr, HECL::CVarManager& cvarMgr) + : m_cvarManager(cvarMgr), m_fontCache(fileMgr), + m_setTo1(*this), m_setTo2(*this), + m_split(*this), + m_space1(*this, "Hello, World!\n\n", "Hello Button", &m_setTo1), + m_space2(*this, "こんにちは世界!\n\n", "こんにちはボタン", &m_setTo2) + {} + + Specter::RootView& rootView() const {return *m_rootView;} + void RequestPixelFactor(float pf) + { + m_reqPf = pf; + m_updatePf = true; + } + + void init(boo::IApplication* app); + bool proc(); + void stop(); }; }