Architectual adjustments for space splitting

This commit is contained in:
Jack Andersen 2016-01-09 20:42:58 -10:00
parent 3bd462a4a5
commit 7f07e516e9
8 changed files with 220 additions and 38 deletions

View File

@ -184,15 +184,20 @@ class ResourceBrowser : public Space, public Specter::IPathButtonsBinding
std::unique_ptr<View> m_view; std::unique_ptr<View> m_view;
public: public:
ResourceBrowser(ViewManager& vm) ResourceBrowser(ViewManager& vm, Space* parent)
: Space(vm, Class::ResourceBrowser), : Space(vm, Class::ResourceBrowser, parent),
m_fileListingBind(*this, vm) m_fileListingBind(*this, vm)
{ {
m_state.path = vm.project()->getProjectWorkingPath().getRelativePathUTF8();
reloadState(); reloadState();
} }
ResourceBrowser(ViewManager& vm, ConfigReader& r) ResourceBrowser(ViewManager& vm, Space* parent, const ResourceBrowser& other)
: ResourceBrowser(vm) : ResourceBrowser(vm, parent)
{
m_state = other.m_state;
reloadState();
}
ResourceBrowser(ViewManager& vm, Space* parent, ConfigReader& r)
: ResourceBrowser(vm, parent)
{ {
m_state.read(r); m_state.read(r);
reloadState(); reloadState();
@ -200,11 +205,23 @@ public:
void reloadState() void reloadState()
{ {
HECL::ProjectPath pp(*m_vm.project(), m_state.path);
if (m_state.path.empty() || pp.getPathType() == HECL::ProjectPath::Type::None)
{
m_state.path = m_vm.project()->getProjectWorkingPath().getRelativePathUTF8();
navigateToPath(HECL::ProjectPath(*m_vm.project(), m_state.path)); navigateToPath(HECL::ProjectPath(*m_vm.project(), m_state.path));
} }
else
navigateToPath(pp);
}
bool navigateToPath(const HECL::ProjectPath& path); bool navigateToPath(const HECL::ProjectPath& path);
Space* copy(Space* parent) const
{
return new ResourceBrowser(m_vm, parent, *this);
}
Specter::View* buildContentView(Specter::ViewResources& res) Specter::View* buildContentView(Specter::ViewResources& res)
{ {
m_view.reset(new View(*this, res)); m_view.reset(new View(*this, res));

View File

@ -10,7 +10,7 @@ Specter::View* Space::buildSpaceView(Specter::ViewResources& res)
{ {
if (usesToolbar()) if (usesToolbar())
{ {
m_space.reset(new Specter::Space(res, m_vm.rootView(), Specter::Toolbar::Position::Bottom)); m_space.reset(new Specter::Space(res, m_vm.rootView(), *this, Specter::Toolbar::Position::Bottom));
Specter::View* sview = buildContentView(res); Specter::View* sview = buildContentView(res);
m_space->setContentView(sview); m_space->setContentView(sview);
buildToolbarView(res, *m_space->toolbar()); buildToolbarView(res, *m_space->toolbar());
@ -18,7 +18,7 @@ Specter::View* Space::buildSpaceView(Specter::ViewResources& res)
} }
else else
{ {
m_space.reset(new Specter::Space(res, m_vm.rootView(), Specter::Toolbar::Position::None)); m_space.reset(new Specter::Space(res, m_vm.rootView(), *this, Specter::Toolbar::Position::None));
Specter::View* sview = buildContentView(res); Specter::View* sview = buildContentView(res);
m_space->setContentView(sview); m_space->setContentView(sview);
return m_space.get(); return m_space.get();
@ -35,23 +35,72 @@ Specter::View* SplitSpace::buildContentView(Specter::ViewResources& res)
return m_splitView.get(); return m_splitView.get();
} }
void SplitSpace::setSpaceSlot(unsigned slot, std::unique_ptr<Space>&& space) void SplitSpace::setChildSlot(unsigned slot, std::unique_ptr<Space>&& space)
{ {
if (slot > 1) if (slot > 1)
Log.report(LogVisor::FatalError, "invalid slot %u for SplitView", slot); Log.report(LogVisor::FatalError, "invalid slot %u for SplitView", slot);
m_slots[slot] = std::move(space); m_slots[slot] = std::move(space);
m_slots[slot]->m_parent = this;
}
Specter::ISplitSpaceController* Space::spaceSplit(Specter::SplitView::Axis axis, int thisSlot)
{
if (m_parent)
{
SplitSpace* ss = new SplitSpace(m_vm, m_parent);
ss->setChildSlot(thisSlot, std::move(m_parent->exchangeSpaceSplitJoin(this, std::unique_ptr<Space>(ss))));
ss->setChildSlot(thisSlot ^ 1, std::unique_ptr<Space>(copy(ss)));
m_parent->buildSpaceView(m_vm.rootView().viewRes());
return ss;
}
return nullptr;
}
std::unique_ptr<Space> RootSpace::exchangeSpaceSplitJoin(Space* removeSpace, std::unique_ptr<Space>&& keepSpace)
{
std::unique_ptr<Space> ret = std::move(keepSpace);
if (removeSpace == m_child.get())
{
m_child.swap(ret);
m_child->m_parent = this;
}
else
Log.report(LogVisor::FatalError, "RootSpace::exchangeSpaceSplitJoin() failure");
return ret;
}
std::unique_ptr<Space> SplitSpace::exchangeSpaceSplitJoin(Space* removeSpace, std::unique_ptr<Space>&& keepSpace)
{
std::unique_ptr<Space> ret = std::move(keepSpace);
if (removeSpace == m_slots[0].get())
{
m_slots[0].swap(ret);
m_slots[0]->m_parent = this;
}
else if (removeSpace == m_slots[1].get())
{
m_slots[1].swap(ret);
m_slots[1]->m_parent = this;
}
else
Log.report(LogVisor::FatalError, "SplitSpace::exchangeSpaceSplitJoin() failure");
return ret;
} }
template <class Reader> template <class Reader>
static Space* BuildNewSpace(ViewManager& vm, Space::Class cls, Reader& r) static Space* BuildNewSpace(ViewManager& vm, Space::Class cls, Space* parent, Reader& r)
{ {
using Class = Space::Class; using Class = Space::Class;
switch (cls) switch (cls)
{ {
case Class::SplitSpace: case Class::SplitSpace:
return new SplitSpace(vm, r); return new SplitSpace(vm, parent, r);
case Class::ResourceBrowser: case Class::ResourceBrowser:
return new ResourceBrowser(vm, r); return new ResourceBrowser(vm, parent, r);
default: break; default: break;
} }
return nullptr; return nullptr;
@ -69,14 +118,29 @@ void Space::saveState(Athena::io::YAMLDocWriter& w) const
spaceState().write(w); spaceState().write(w);
} }
Space* Space::NewSpaceFromConfigStream(ViewManager& vm, ConfigReader& r) Space* Space::NewSpaceFromConfigStream(ViewManager& vm, Space* parent, ConfigReader& r)
{ {
#ifdef URDE_BINARY_CONFIGS #ifdef URDE_BINARY_CONFIGS
Class cls = Class(r.readUint32Big()); Class cls = Class(r.readUint32Big());
return BuildNewSpace(vm, cls, parent, r);
#else
Class cls = Class(r.readUint32("class"));
return BuildNewSpace(vm, cls, parent, r);
#endif
}
RootSpace* Space::NewRootSpaceFromConfigStream(ViewManager& vm, ConfigReader& r)
{
#ifdef URDE_BINARY_CONFIGS
Class cls = Class(r.readUint32Big());
if (cls != Class::RootSpace)
return nullptr;
return BuildNewSpace(vm, cls, r); return BuildNewSpace(vm, cls, r);
#else #else
Class cls = Class(r.readUint32("class")); Class cls = Class(r.readUint32("class"));
return BuildNewSpace(vm, cls, r); if (cls != Class::RootSpace)
return nullptr;
return new RootSpace(vm, r);
#endif #endif
} }

View File

@ -15,31 +15,37 @@ class Toolbar;
namespace URDE namespace URDE
{ {
class ViewManager; class ViewManager;
class RootSpace;
class Space class Space : public Specter::ISpaceController
{ {
friend class SplitSpace; friend class SplitSpace;
public: public:
virtual ~Space() = default;
Space(const Space& other) = delete; Space(const Space& other) = delete;
Space& operator=(const Space& other) = delete; Space& operator=(const Space& other) = delete;
enum class Class enum class Class
{ {
None, None,
RootSpace,
SplitSpace, SplitSpace,
TestSpace, TestSpace,
ResourceBrowser, ResourceBrowser,
}; };
struct State : Athena::io::DNAYaml<Athena::BigEndian> {Delete _d;}; struct State : Athena::io::DNAYaml<Athena::BigEndian> {Delete _d;};
static Space* NewSpaceFromConfigStream(ViewManager& vm, ConfigReader& r); static Space* NewSpaceFromConfigStream(ViewManager& vm, Space* parent, ConfigReader& r);
static RootSpace* NewRootSpaceFromConfigStream(ViewManager& vm, ConfigReader& r);
protected: protected:
friend class ViewManager; friend class ViewManager;
friend class RootSpace;
ViewManager& m_vm; ViewManager& m_vm;
Class m_class = Class::None; Class m_class = Class::None;
Space* m_parent;
std::unique_ptr<Specter::Space> m_space; std::unique_ptr<Specter::Space> m_space;
Space(ViewManager& vm, Class cls) : m_vm(vm), m_class(cls) {} Space(ViewManager& vm, Class cls, Space* parent) : m_vm(vm), m_class(cls), m_parent(parent) {}
/* Allows common Space code to access DNA-encoded state */ /* Allows common Space code to access DNA-encoded state */
virtual const Space::State& spaceState() const=0; virtual const Space::State& spaceState() const=0;
@ -56,9 +62,80 @@ public:
virtual void reloadState() {} virtual void reloadState() {}
virtual void think() {} virtual void think() {}
virtual Space* copy(Space* parent) const=0;
bool spaceSplitAllowed() const {return true;}
Specter::ISplitSpaceController* spaceSplit(Specter::SplitView::Axis axis, int thisSlot);
virtual std::unique_ptr<Space> exchangeSpaceSplitJoin(Space* removeSpace, std::unique_ptr<Space>&& keepSpace)
{return std::unique_ptr<Space>();}
}; };
class SplitSpace : public Space class RootSpace : public Space
{
friend class ViewManager;
std::unique_ptr<Space> m_child;
struct State : Space::State
{
DECL_YAML
} m_state;
const Space::State& spaceState() const {return m_state;}
public:
RootSpace(ViewManager& vm) : Space(vm, Class::RootSpace, nullptr) {}
RootSpace(ViewManager& vm, ConfigReader& r)
: RootSpace(vm)
{
m_state.read(r);
#ifdef URDE_BINARY_CONFIGS
m_child.reset(NewSpaceFromConfigStream(vm, this, r));
#else
r.enterSubRecord("child");
m_child.reset(NewSpaceFromConfigStream(vm, this, r));
r.leaveSubRecord();
#endif
}
void saveState(Athena::io::IStreamWriter& w) const
{
w.writeUint32Big(atUint32(m_class));
m_state.write(w);
if (m_child)
m_child->saveState(w);
else
w.writeUint32Big(0);
}
void saveState(Athena::io::YAMLDocWriter& w) const
{
w.writeUint32("class", atUint32(m_class));
m_state.write(w);
w.enterSubRecord("child");
if (m_child)
m_child->saveState(w);
else
w.writeUint32("class", 0);
w.leaveSubRecord();
}
void setChild(std::unique_ptr<Space>&& space)
{
m_child = std::move(space);
m_child->m_parent = this;
}
Space* copy(Space* parent) const {return nullptr;}
bool spaceSplitAllowed() const {return false;}
Specter::View* buildSpaceView(Specter::ViewResources& res) {return buildContentView(res);}
Specter::View* buildContentView(Specter::ViewResources& res) {return m_child->buildSpaceView(res);}
std::unique_ptr<Space> exchangeSpaceSplitJoin(Space* removeSpace, std::unique_ptr<Space>&& keepSpace);
};
class SplitSpace : public Space, public Specter::ISplitSpaceController
{ {
friend class ViewManager; friend class ViewManager;
std::unique_ptr<Space> m_slots[2]; std::unique_ptr<Space> m_slots[2];
@ -71,20 +148,20 @@ class SplitSpace : public Space
const Space::State& spaceState() const {return m_state;} const Space::State& spaceState() const {return m_state;}
public: public:
SplitSpace(ViewManager& vm) : Space(vm, Class::SplitSpace) {} SplitSpace(ViewManager& vm, Space* parent) : Space(vm, Class::SplitSpace, parent) {}
SplitSpace(ViewManager& vm, ConfigReader& r) SplitSpace(ViewManager& vm, Space* parent, ConfigReader& r)
: SplitSpace(vm) : SplitSpace(vm, parent)
{ {
m_state.read(r); m_state.read(r);
#ifdef URDE_BINARY_CONFIGS #ifdef URDE_BINARY_CONFIGS
m_slots[0].reset(NewSpaceFromConfigStream(vm, r)); m_slots[0].reset(NewSpaceFromConfigStream(vm, this, r));
m_slots[1].reset(NewSpaceFromConfigStream(vm, r)); m_slots[1].reset(NewSpaceFromConfigStream(vm, this, r));
#else #else
r.enterSubRecord("slot0"); r.enterSubRecord("slot0");
m_slots[0].reset(NewSpaceFromConfigStream(vm, r)); m_slots[0].reset(NewSpaceFromConfigStream(vm, this, r));
r.leaveSubRecord(); r.leaveSubRecord();
r.enterSubRecord("slot1"); r.enterSubRecord("slot1");
m_slots[1].reset(NewSpaceFromConfigStream(vm, r)); m_slots[1].reset(NewSpaceFromConfigStream(vm, this, r));
r.leaveSubRecord(); r.leaveSubRecord();
#endif #endif
} }
@ -126,10 +203,31 @@ public:
w.leaveSubRecord(); w.leaveSubRecord();
} }
void setSpaceSlot(unsigned slot, std::unique_ptr<Space>&& space); void setChildSlot(unsigned slot, std::unique_ptr<Space>&& space);
Specter::View* buildSpaceView(Specter::ViewResources& res) {return buildContentView(res);} Specter::View* buildSpaceView(Specter::ViewResources& res) {return buildContentView(res);}
Specter::View* buildContentView(Specter::ViewResources& res); Specter::View* buildContentView(Specter::ViewResources& res);
Space* copy(Space* parent) const {return nullptr;}
bool spaceSplitAllowed() const {return false;}
ISpaceController* spaceJoin(int keepSlot)
{
if (m_parent)
{
ISpaceController* ret = m_slots[keepSlot].get();
m_parent->exchangeSpaceSplitJoin(this, std::move(m_slots[keepSlot]));
return ret;
}
return nullptr;
}
std::unique_ptr<Space> exchangeSpaceSplitJoin(Space* removeSpace, std::unique_ptr<Space>&& keepSpace);
Specter::SplitView* splitView()
{
return m_splitView.get();
}
}; };
class TestSpace : public Space class TestSpace : public Space
@ -143,9 +241,9 @@ class TestSpace : public Space
Specter::IButtonBinding* m_binding; Specter::IButtonBinding* m_binding;
public: public:
TestSpace(ViewManager& vm, const std::string& content, const std::string& button, TestSpace(ViewManager& vm, Space* parent, const std::string& content, const std::string& button,
Specter::IButtonBinding* binding) Specter::IButtonBinding* binding)
: Space(vm, Class::TestSpace), m_contentStr(content), m_buttonStr(button), m_binding(binding) : Space(vm, Class::TestSpace, parent), m_contentStr(content), m_buttonStr(button), m_binding(binding)
{} {}
struct State : Space::State struct State : Space::State

View File

@ -43,7 +43,7 @@ class SplashScreen : public Specter::ModalWindow
m_splash.m_fileBrowser.m_view.reset( m_splash.m_fileBrowser.m_view.reset(
new Specter::FileBrowser(m_splash.rootView().viewRes(), new Specter::FileBrowser(m_splash.rootView().viewRes(),
m_splash, m_splash.m_newString, m_splash, m_splash.m_newString,
Specter::FileBrowser::Type::SaveDirectory, Specter::FileBrowser::Type::NewHECLProject,
[&](bool ok, const HECL::SystemString& path) [&](bool ok, const HECL::SystemString& path)
{ {
if (ok) if (ok)

View File

@ -33,10 +33,12 @@ SplashScreen* ViewManager::SetupSplashView()
void ViewManager::SetupEditorView() void ViewManager::SetupEditorView()
{ {
SplitSpace* split = new SplitSpace(*this); m_rootSpace.reset(new RootSpace(*this));
split->setSpaceSlot(0, std::make_unique<ResourceBrowser>(*this));
split->setSpaceSlot(1, std::make_unique<ResourceBrowser>(*this)); SplitSpace* split = new SplitSpace(*this, nullptr);
m_rootSpace.reset(split); m_rootSpace->setChild(std::unique_ptr<Space>(split));
split->setChildSlot(0, std::make_unique<ResourceBrowser>(*this, split));
split->setChildSlot(1, std::make_unique<ResourceBrowser>(*this, split));
std::vector<Specter::View*>& cViews = m_rootView->accessContentViews(); std::vector<Specter::View*>& cViews = m_rootView->accessContentViews();
cViews.clear(); cViews.clear();
@ -47,7 +49,7 @@ void ViewManager::SetupEditorView()
void ViewManager::SetupEditorView(ConfigReader& r) void ViewManager::SetupEditorView(ConfigReader& r)
{ {
m_rootSpace.reset(Space::NewSpaceFromConfigStream(*this, r)); m_rootSpace.reset(Space::NewRootSpaceFromConfigStream(*this, r));
std::vector<Specter::View*>& cViews = m_rootView->accessContentViews(); std::vector<Specter::View*>& cViews = m_rootView->accessContentViews();
cViews.clear(); cViews.clear();
cViews.push_back(BuildSpaceViews(m_rootSpace.get())); cViews.push_back(BuildSpaceViews(m_rootSpace.get()));
@ -96,7 +98,7 @@ void ViewManager::init(boo::IApplication* app)
float pixelFactor = 1.0; float pixelFactor = 1.0;
boo::IGraphicsDataFactory* gf = m_mainWindow->getMainContextDataFactory(); boo::IGraphicsDataFactory* gf = m_mainWindow->getMainContextDataFactory();
m_viewResources.init(gf, &m_fontCache, Specter::ThemeData(), pixelFactor); m_viewResources.init(gf, &m_fontCache, &m_themeData, pixelFactor);
m_viewResources.prepFontCacheAsync(m_mainWindow.get()); m_viewResources.prepFontCacheAsync(m_mainWindow.get());
Specter::RootView* root = SetupRootView(); Specter::RootView* root = SetupRootView();
m_showSplash = true; m_showSplash = true;

View File

@ -17,13 +17,14 @@ class ViewManager : public Specter::IViewManager
HECL::CVarManager& m_cvarManager; HECL::CVarManager& m_cvarManager;
ProjectManager m_projManager; ProjectManager m_projManager;
Specter::FontCache m_fontCache; Specter::FontCache m_fontCache;
Specter::DefaultThemeData m_themeData;
Specter::ViewResources m_viewResources; Specter::ViewResources m_viewResources;
Specter::Translator m_translator; Specter::Translator m_translator;
std::unique_ptr<boo::IWindow> m_mainWindow; std::unique_ptr<boo::IWindow> m_mainWindow;
std::unique_ptr<Specter::RootView> m_rootView; std::unique_ptr<Specter::RootView> m_rootView;
std::unique_ptr<SplashScreen> m_splash; std::unique_ptr<SplashScreen> m_splash;
std::unique_ptr<Space> m_rootSpace; std::unique_ptr<RootSpace> m_rootSpace;
Specter::View* m_rootSpaceView = nullptr; Specter::View* m_rootSpaceView = nullptr;
std::vector<HECL::SystemString> m_recentProjects; std::vector<HECL::SystemString> m_recentProjects;

2
hecl

@ -1 +1 @@
Subproject commit 1b3bdb7c2e72c1c9971c2bb46f06c65a3b78ae1e Subproject commit fcedcb508e0f2c8edb4ad857738e1e664f2d6c95

@ -1 +1 @@
Subproject commit e63ddda724ec6a3760077ec1be6192ca123bbb15 Subproject commit 168b7c8cceb306c53cdaf1b30f3d5c5344f89205