2015-12-11 02:37:54 +00:00
|
|
|
#include "Space.hpp"
|
2015-12-12 00:37:32 +00:00
|
|
|
#include "ViewManager.hpp"
|
2016-01-07 00:40:27 +00:00
|
|
|
#include "ResourceBrowser.hpp"
|
2016-01-18 23:33:23 +00:00
|
|
|
#include "icons/icons.hpp"
|
2015-12-11 02:37:54 +00:00
|
|
|
|
2016-01-05 09:53:16 +00:00
|
|
|
namespace URDE
|
2015-12-11 02:37:54 +00:00
|
|
|
{
|
2016-01-05 09:53:16 +00:00
|
|
|
static LogVisor::LogModule Log("URDE::Space");
|
2015-12-11 02:37:54 +00:00
|
|
|
|
2016-01-17 04:14:13 +00:00
|
|
|
Space::Space(ViewManager& vm, Class cls, Space* parent)
|
|
|
|
: m_spaceMenuNode(*this), m_spaceSelectBind(*this),
|
|
|
|
m_vm(vm), m_class(cls), m_parent(parent) {}
|
|
|
|
|
2016-01-05 00:01:02 +00:00
|
|
|
Specter::View* Space::buildSpaceView(Specter::ViewResources& res)
|
2015-12-12 00:37:32 +00:00
|
|
|
{
|
2016-01-05 00:01:02 +00:00
|
|
|
if (usesToolbar())
|
2016-01-07 00:40:27 +00:00
|
|
|
{
|
2016-01-11 02:17:08 +00:00
|
|
|
m_spaceView.reset(new Specter::Space(res, m_vm.rootView(), *this, Specter::Toolbar::Position::Bottom));
|
2016-01-07 00:40:27 +00:00
|
|
|
Specter::View* sview = buildContentView(res);
|
2016-01-11 02:17:08 +00:00
|
|
|
m_spaceView->setContentView(sview);
|
2016-01-17 04:14:13 +00:00
|
|
|
Specter::Toolbar& tb = *m_spaceView->toolbar();
|
|
|
|
const std::string* classStr = SpaceMenuNode::lookupClassString(m_class);
|
2016-01-18 23:33:23 +00:00
|
|
|
Specter::Icon* classIcon = SpaceMenuNode::lookupClassIcon(m_class);
|
|
|
|
const Zeus::CColor* classColor = SpaceMenuNode::lookupClassColor(m_class);
|
|
|
|
m_spaceSelectButton.reset(new Specter::Button(res, tb, &m_spaceSelectBind, "", classIcon,
|
|
|
|
Specter::Button::Style::Block,
|
|
|
|
classColor?*classColor:Zeus::CColor::skWhite));
|
2016-01-17 04:14:13 +00:00
|
|
|
tb.push_back(m_spaceSelectButton.get());
|
|
|
|
buildToolbarView(res, tb);
|
2016-01-11 02:17:08 +00:00
|
|
|
return m_spaceView.get();
|
2016-01-07 00:40:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-11 02:17:08 +00:00
|
|
|
m_spaceView.reset(new Specter::Space(res, m_vm.rootView(), *this, Specter::Toolbar::Position::None));
|
2016-01-07 00:40:27 +00:00
|
|
|
Specter::View* sview = buildContentView(res);
|
2016-01-11 02:17:08 +00:00
|
|
|
m_spaceView->setContentView(sview);
|
|
|
|
return m_spaceView.get();
|
2016-01-07 00:40:27 +00:00
|
|
|
}
|
2015-12-12 00:37:32 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:13 +00:00
|
|
|
std::vector<Space::SpaceMenuNode::SubNodeData> Space::SpaceMenuNode::s_subNodeDats =
|
|
|
|
{
|
2016-01-18 23:33:23 +00:00
|
|
|
{Class::ResourceBrowser, "resource_browser", "Resource Browser", GetIcon(SpaceIcon::ResourceBrowser), {0.0,1.0,0.0,1.0}}
|
2016-01-17 04:14:13 +00:00
|
|
|
};
|
|
|
|
std::string Space::SpaceMenuNode::s_text = "Space Types";
|
|
|
|
|
|
|
|
void Space::SpaceMenuNode::initializeStrings(ViewManager& vm)
|
|
|
|
{
|
|
|
|
s_text = vm.translateOr("space_types", s_text.c_str());
|
|
|
|
for (SubNodeData& sn : s_subNodeDats)
|
|
|
|
sn.m_text = vm.translateOr(sn.m_key, sn.m_text.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Specter::View> Space::SpaceSelectBind::buildMenu(const Specter::Button* button)
|
|
|
|
{
|
|
|
|
return std::unique_ptr<Specter::View>(new Specter::Menu(m_space.m_vm.rootView().viewRes(),
|
|
|
|
*m_space.m_spaceView, &m_space.m_spaceMenuNode));
|
|
|
|
}
|
|
|
|
|
2016-01-11 02:17:08 +00:00
|
|
|
Specter::View* RootSpace::buildSpaceView(Specter::ViewResources& res)
|
|
|
|
{
|
|
|
|
Specter::View* newRoot = buildContentView(res);
|
|
|
|
m_vm.RootSpaceViewBuilt(newRoot);
|
|
|
|
return newRoot;
|
|
|
|
}
|
|
|
|
|
2016-01-04 05:31:02 +00:00
|
|
|
Specter::View* SplitSpace::buildContentView(Specter::ViewResources& res)
|
2015-12-12 00:37:32 +00:00
|
|
|
{
|
2016-01-12 00:46:27 +00:00
|
|
|
int clearance = res.pixelFactor() * SPECTER_TOOLBAR_GAUGE;
|
|
|
|
m_splitView.reset(new Specter::SplitView(res, m_vm.rootView(), this, m_state.axis,
|
|
|
|
m_state.split, clearance, clearance));
|
2016-01-05 00:01:02 +00:00
|
|
|
if (m_slots[0])
|
|
|
|
m_splitView->setContentView(0, m_slots[0]->buildSpaceView(res));
|
|
|
|
if (m_slots[1])
|
|
|
|
m_splitView->setContentView(1, m_slots[1]->buildSpaceView(res));
|
2015-12-12 00:37:32 +00:00
|
|
|
return m_splitView.get();
|
|
|
|
}
|
2015-12-11 02:37:54 +00:00
|
|
|
|
2016-01-10 06:42:58 +00:00
|
|
|
void SplitSpace::setChildSlot(unsigned slot, std::unique_ptr<Space>&& space)
|
2016-01-04 05:31:02 +00:00
|
|
|
{
|
2016-01-05 00:01:02 +00:00
|
|
|
if (slot > 1)
|
|
|
|
Log.report(LogVisor::FatalError, "invalid slot %u for SplitView", slot);
|
|
|
|
m_slots[slot] = std::move(space);
|
2016-01-10 06:42:58 +00:00
|
|
|
m_slots[slot]->m_parent = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Specter::ISplitSpaceController* Space::spaceSplit(Specter::SplitView::Axis axis, int thisSlot)
|
|
|
|
{
|
|
|
|
if (m_parent)
|
|
|
|
{
|
2016-01-11 02:17:08 +00:00
|
|
|
SplitSpace* ss = new SplitSpace(m_vm, m_parent, axis);
|
2016-01-10 06:42:58 +00:00
|
|
|
ss->setChildSlot(thisSlot, std::move(m_parent->exchangeSpaceSplitJoin(this, std::unique_ptr<Space>(ss))));
|
|
|
|
ss->setChildSlot(thisSlot ^ 1, std::unique_ptr<Space>(copy(ss)));
|
2016-01-11 02:17:08 +00:00
|
|
|
m_vm.BuildSpaceViews();
|
2016-01-10 06:42:58 +00:00
|
|
|
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);
|
|
|
|
|
2016-01-11 02:17:08 +00:00
|
|
|
if (removeSpace == m_spaceTree.get())
|
2016-01-10 06:42:58 +00:00
|
|
|
{
|
2016-01-11 02:17:08 +00:00
|
|
|
m_spaceTree.swap(ret);
|
|
|
|
m_spaceTree->m_parent = this;
|
2016-01-10 06:42:58 +00:00
|
|
|
}
|
|
|
|
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;
|
2016-01-05 00:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class Reader>
|
2016-01-10 06:42:58 +00:00
|
|
|
static Space* BuildNewSpace(ViewManager& vm, Space::Class cls, Space* parent, Reader& r)
|
2016-01-05 00:01:02 +00:00
|
|
|
{
|
|
|
|
using Class = Space::Class;
|
|
|
|
switch (cls)
|
2016-01-04 05:31:02 +00:00
|
|
|
{
|
|
|
|
case Class::SplitSpace:
|
2016-01-10 06:42:58 +00:00
|
|
|
return new SplitSpace(vm, parent, r);
|
2016-01-07 00:40:27 +00:00
|
|
|
case Class::ResourceBrowser:
|
2016-01-10 06:42:58 +00:00
|
|
|
return new ResourceBrowser(vm, parent, r);
|
2016-01-04 05:31:02 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-07 00:40:27 +00:00
|
|
|
void Space::saveState(Athena::io::IStreamWriter& w) const
|
|
|
|
{
|
|
|
|
w.writeUint32Big(atUint32(m_class));
|
|
|
|
spaceState().write(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Space::saveState(Athena::io::YAMLDocWriter& w) const
|
|
|
|
{
|
|
|
|
w.writeUint32("class", atUint32(m_class));
|
|
|
|
spaceState().write(w);
|
|
|
|
}
|
|
|
|
|
2016-01-10 06:42:58 +00:00
|
|
|
Space* Space::NewSpaceFromConfigStream(ViewManager& vm, Space* parent, ConfigReader& r)
|
2016-01-05 00:01:02 +00:00
|
|
|
{
|
2016-01-05 09:53:16 +00:00
|
|
|
#ifdef URDE_BINARY_CONFIGS
|
2016-01-05 00:01:02 +00:00
|
|
|
Class cls = Class(r.readUint32Big());
|
|
|
|
#else
|
|
|
|
Class cls = Class(r.readUint32("class"));
|
2016-01-10 06:42:58 +00:00
|
|
|
#endif
|
2016-01-15 05:44:42 +00:00
|
|
|
return BuildNewSpace(vm, cls, parent, r);
|
2016-01-10 06:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RootSpace* Space::NewRootSpaceFromConfigStream(ViewManager& vm, ConfigReader& r)
|
|
|
|
{
|
|
|
|
#ifdef URDE_BINARY_CONFIGS
|
|
|
|
Class cls = Class(r.readUint32Big());
|
|
|
|
#else
|
|
|
|
Class cls = Class(r.readUint32("class"));
|
2016-01-15 05:44:42 +00:00
|
|
|
#endif
|
2016-01-10 06:42:58 +00:00
|
|
|
if (cls != Class::RootSpace)
|
|
|
|
return nullptr;
|
|
|
|
return new RootSpace(vm, r);
|
2016-01-05 00:01:02 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 02:37:54 +00:00
|
|
|
}
|