split and join functionality

This commit is contained in:
Jack Andersen 2016-01-31 15:13:45 -10:00
parent 39012da281
commit a37e6ba8a4
4 changed files with 66 additions and 3 deletions

View File

@ -15,7 +15,7 @@ Specter::View* Space::buildSpaceView(Specter::ViewResources& res)
{ {
if (usesToolbar()) if (usesToolbar())
{ {
m_spaceView.reset(new Specter::Space(res, m_vm.rootView(), *this, Specter::Toolbar::Position::Bottom, toolbarUnits())); m_spaceView.reset(new Specter::Space(res, *m_parent->basisView(), *this, Specter::Toolbar::Position::Bottom, toolbarUnits()));
Specter::View* sview = buildContentView(res); Specter::View* sview = buildContentView(res);
m_spaceView->setContentView(sview); m_spaceView->setContentView(sview);
Specter::Toolbar& tb = *m_spaceView->toolbar(); Specter::Toolbar& tb = *m_spaceView->toolbar();
@ -31,7 +31,7 @@ Specter::View* Space::buildSpaceView(Specter::ViewResources& res)
} }
else else
{ {
m_spaceView.reset(new Specter::Space(res, m_vm.rootView(), *this, Specter::Toolbar::Position::None, 0)); m_spaceView.reset(new Specter::Space(res, *m_parent->basisView(), *this, Specter::Toolbar::Position::None, 0));
Specter::View* sview = buildContentView(res); Specter::View* sview = buildContentView(res);
m_spaceView->setContentView(sview); m_spaceView->setContentView(sview);
return m_spaceView.get(); return m_spaceView.get();
@ -64,6 +64,8 @@ Specter::View* RootSpace::buildSpaceView(Specter::ViewResources& res)
return newRoot; return newRoot;
} }
Specter::View* RootSpace::basisView() {return &m_vm.rootView();}
Specter::View* SplitSpace::buildContentView(Specter::ViewResources& res) Specter::View* SplitSpace::buildContentView(Specter::ViewResources& res)
{ {
int clearance = res.pixelFactor() * SPECTER_TOOLBAR_GAUGE; int clearance = res.pixelFactor() * SPECTER_TOOLBAR_GAUGE;
@ -84,10 +86,61 @@ void SplitSpace::setChildSlot(unsigned slot, std::unique_ptr<Space>&& space)
m_slots[slot]->m_parent = this; m_slots[slot]->m_parent = this;
} }
void SplitSpace::joinViews(Specter::SplitView* thisSplit, int thisSlot, Specter::SplitView* otherSplit, int otherSlot)
{
if (thisSplit == otherSplit)
{
SplitSpace* thisSS = dynamic_cast<SplitSpace*>(m_slots[thisSlot].get());
if (thisSS)
{
int ax = thisSS->m_state.axis == Specter::SplitView::Axis::Horizontal ? 1 : 0;
const boo::SWindowRect& thisRect = m_splitView->subRect();
const boo::SWindowRect& subRect = thisSS->m_splitView->subRect();
int splitPx = subRect.location[ax] + subRect.size[ax] * thisSS->m_state.split -
thisRect.location[ax];
thisSS->m_state.split = splitPx / float(thisRect.size[ax]);
}
m_parent->exchangeSpaceSplitJoin(this, std::move(m_slots[thisSlot]));
m_vm.BuildSpaceViews();
}
else
{
for (int i=0 ; i<2 ; ++i)
{
SplitSpace* otherSS = dynamic_cast<SplitSpace*>(m_slots[i].get());
if (otherSS && otherSS->m_splitView.get() == otherSplit)
{
int ax = m_state.axis == Specter::SplitView::Axis::Horizontal ? 1 : 0;
const boo::SWindowRect& thisRect = m_splitView->subRect();
const boo::SWindowRect& subRect = otherSS->m_splitView->subRect();
int splitPx = subRect.location[ax] + subRect.size[ax] * otherSS->m_state.split -
thisRect.location[ax];
m_state.split = splitPx / float(thisRect.size[ax]);
exchangeSpaceSplitJoin(otherSS, std::move(otherSS->m_slots[otherSlot ^ 1]));
m_vm.BuildSpaceViews();
break;
}
}
}
}
Specter::ISplitSpaceController* Space::spaceSplit(Specter::SplitView::Axis axis, int thisSlot) Specter::ISplitSpaceController* Space::spaceSplit(Specter::SplitView::Axis axis, int thisSlot)
{ {
if (m_parent) if (m_parent)
{ {
/* Reject split operations with insufficient clearance */
int clearance = m_vm.m_viewResources.pixelFactor() * SPECTER_TOOLBAR_GAUGE;
if (axis == Specter::SplitView::Axis::Horizontal)
{
if (m_spaceView->subRect().size[1] <= clearance)
return nullptr;
}
else
{
if (m_spaceView->subRect().size[0] <= clearance)
return nullptr;
}
SplitSpace* ss = new SplitSpace(m_vm, m_parent, axis); SplitSpace* ss = new SplitSpace(m_vm, m_parent, axis);
ss->setChildSlot(thisSlot, std::move(m_parent->exchangeSpaceSplitJoin(this, std::unique_ptr<Space>(ss)))); ss->setChildSlot(thisSlot, std::move(m_parent->exchangeSpaceSplitJoin(this, std::unique_ptr<Space>(ss))));
ss->setChildSlot(thisSlot ^ 1, std::unique_ptr<Space>(copy(ss))); ss->setChildSlot(thisSlot ^ 1, std::unique_ptr<Space>(copy(ss)));

View File

@ -148,11 +148,14 @@ public:
Specter::ISplitSpaceController* spaceSplit(Specter::SplitView::Axis axis, int thisSlot); Specter::ISplitSpaceController* spaceSplit(Specter::SplitView::Axis axis, int thisSlot);
virtual std::unique_ptr<Space> exchangeSpaceSplitJoin(Space* removeSpace, std::unique_ptr<Space>&& keepSpace) virtual std::unique_ptr<Space> exchangeSpaceSplitJoin(Space* removeSpace, std::unique_ptr<Space>&& keepSpace)
{return std::unique_ptr<Space>();} {return std::unique_ptr<Space>();}
virtual Specter::View* basisView() {return m_spaceView.get();}
}; };
class RootSpace : public Space class RootSpace : public Space
{ {
friend class ViewManager; friend class ViewManager;
std::unique_ptr<Specter::RootView> m_rootView;
std::unique_ptr<Space> m_spaceTree; std::unique_ptr<Space> m_spaceTree;
struct State : Space::State struct State : Space::State
{ {
@ -212,6 +215,8 @@ public:
Specter::View* buildContentView(Specter::ViewResources& res) {return m_spaceTree->buildSpaceView(res);} Specter::View* buildContentView(Specter::ViewResources& res) {return m_spaceTree->buildSpaceView(res);}
std::unique_ptr<Space> exchangeSpaceSplitJoin(Space* removeSpace, std::unique_ptr<Space>&& keepSpace); std::unique_ptr<Space> exchangeSpaceSplitJoin(Space* removeSpace, std::unique_ptr<Space>&& keepSpace);
Specter::View* basisView();
}; };
class SplitSpace : public Space, public Specter::ISplitSpaceController class SplitSpace : public Space, public Specter::ISplitSpaceController
@ -324,6 +329,8 @@ public:
Specter::SplitView* splitView() {return m_splitView.get();} Specter::SplitView* splitView() {return m_splitView.get();}
void updateSplit(float split) {m_state.split = split;} void updateSplit(float split) {m_state.split = split;}
void joinViews(Specter::SplitView* thisSplit, int thisSlot, Specter::SplitView* otherSplit, int otherSlot);
void setAxis(Specter::SplitView::Axis axis) void setAxis(Specter::SplitView::Axis axis)
{ {
m_state.axis = axis; m_state.axis = axis;
@ -332,6 +339,8 @@ public:
Specter::SplitView::Axis axis() const {return m_state.axis;} Specter::SplitView::Axis axis() const {return m_state.axis;}
float split() const {return m_state.split;} float split() const {return m_state.split;}
Specter::View* basisView() {return m_splitView.get();}
}; };
class TestSpace : public Space class TestSpace : public Space

View File

@ -14,6 +14,7 @@ class ViewManager : public Specter::IViewManager
friend class ProjectManager; friend class ProjectManager;
friend class Space; friend class Space;
friend class RootSpace; friend class RootSpace;
friend class SplitSpace;
HECL::Runtime::FileStoreManager& m_fileStoreManager; HECL::Runtime::FileStoreManager& m_fileStoreManager;
HECL::CVarManager& m_cvarManager; HECL::CVarManager& m_cvarManager;

@ -1 +1 @@
Subproject commit 60d3894c73d85d95b206b4ecb3681b9512ef7ecf Subproject commit a4272a09a349a1b9ff5ae921960f44470e31b47a