metaforce/specter/lib/SplitView.cpp

230 lines
7.7 KiB
C++
Raw Normal View History

#include <LogVisor/LogVisor.hpp>
#include "Specter/SplitView.hpp"
2015-12-05 00:42:46 +00:00
#include "Specter/RootView.hpp"
#include "Specter/ViewResources.hpp"
namespace Specter
{
static LogVisor::LogModule Log("Specter::SplitView");
2015-12-04 01:35:01 +00:00
void SplitView::Resources::init(boo::IGraphicsDataFactory* factory, const ThemeData& theme)
{
static const Zeus::RGBA32 tex[3] =
{
{0,0,0,64},
{0,0,0,255},
{255,255,255,64}
};
m_shadingTex = factory->newStaticTexture(3, 1, 1, boo::TextureFormat::RGBA8, tex, 12);
}
2015-12-29 02:02:43 +00:00
SplitView::SplitView(ViewResources& res, View& parentView, Axis axis, int clearanceA, int clearanceB)
: View(res, parentView), m_axis(axis), m_clearanceA(clearanceA), m_clearanceB(clearanceB)
{
2015-12-29 02:02:43 +00:00
m_splitBlockBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Uniform, sizeof(ViewBlock), 1);
m_splitVertsBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(TexShaderVert), 4);
2015-12-29 02:02:43 +00:00
if (!res.m_viewRes.m_texVtxFmt)
{
boo::VertexElementDescriptor vdescs[] =
{
{m_splitVertsBuf, nullptr, boo::VertexSemantic::Position4},
{m_splitVertsBuf, nullptr, boo::VertexSemantic::UV4}
};
2015-12-29 02:02:43 +00:00
m_splitVtxFmt = res.m_factory->newVertexFormat(2, vdescs);
boo::IGraphicsBuffer* bufs[] = {m_splitBlockBuf};
2015-12-29 02:02:43 +00:00
boo::ITexture* texs[] = {res.m_splitRes.m_shadingTex};
m_splitShaderBinding = res.m_factory->newShaderDataBinding(res.m_viewRes.m_texShader,
m_splitVtxFmt, m_splitVertsBuf, nullptr,
nullptr, 1, bufs, 1, texs);
}
else
{
boo::IGraphicsBuffer* bufs[] = {m_splitBlockBuf};
2015-12-29 02:02:43 +00:00
boo::ITexture* texs[] = {res.m_splitRes.m_shadingTex};
m_splitShaderBinding = res.m_factory->newShaderDataBinding(res.m_viewRes.m_texShader,
res.m_viewRes.m_texVtxFmt,
m_splitVertsBuf, nullptr,
nullptr, 1, bufs, 1, texs);
}
2015-12-29 02:02:43 +00:00
commitResources(res);
}
View* SplitView::setContentView(int slot, View* view)
{
if (slot < 0 || slot > 1)
Log.report(LogVisor::FatalError, "out-of-range slot to RootView::SplitView::setContentView");
View* ret = m_views[slot].m_view;
m_views[slot].m_view = view;
2015-12-20 21:59:23 +00:00
m_views[slot].m_mouseDown = 0;
2015-12-05 00:42:46 +00:00
m_views[slot].m_mouseIn = false;
updateSize();
return ret;
}
2015-12-22 01:33:27 +00:00
void SplitView::_setSlide(float slide)
{
m_slide = std::min(std::max(slide, 0.0f), 1.0f);
const boo::SWindowRect& rect = subRect();
if (rect.size[0] && rect.size[1] &&
(m_clearanceA >= 0 || m_clearanceB >= 0))
{
if (m_axis == Axis::Horizontal)
{
int slidePx = rect.size[1] * m_slide;
if (m_clearanceA >= 0 && slidePx < m_clearanceA)
m_slide = m_clearanceA / float(rect.size[1]);
if (m_clearanceB >= 0 && (rect.size[1] - slidePx) < m_clearanceB)
m_slide = 1.0 - m_clearanceB / float(rect.size[1]);
}
else if (m_axis == Axis::Vertical)
{
int slidePx = rect.size[0] * m_slide;
if (m_clearanceA >= 0 && slidePx < m_clearanceA)
m_slide = m_clearanceA / float(rect.size[0]);
if (m_clearanceB >= 0 && (rect.size[0] - slidePx) < m_clearanceB)
m_slide = 1.0 - m_clearanceB / float(rect.size[0]);
}
m_slide = std::min(std::max(m_slide, 0.0f), 1.0f);
}
}
void SplitView::setSlide(float slide)
{
_setSlide(slide);
updateSize();
}
void SplitView::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
2015-12-05 00:42:46 +00:00
if (m_axis == Axis::Horizontal)
{
2015-12-05 00:42:46 +00:00
int slidePx = subRect().size[1] * m_slide;
2015-12-22 01:33:27 +00:00
if (abs(int(coord.pixel[1] - subRect().location[1]) - slidePx) < 4)
2015-12-05 00:42:46 +00:00
{
if (button == boo::EMouseButton::Primary)
{
m_dragging = true;
2015-12-22 01:33:27 +00:00
setSlide((coord.pixel[1] - subRect().location[1]) / float(subRect().size[1]));
2015-12-05 00:42:46 +00:00
}
else if (button == boo::EMouseButton::Secondary)
{
// TODO: Split menu
}
return;
}
}
else if (m_axis == Axis::Vertical)
{
int slidePx = subRect().size[0] * m_slide;
2015-12-22 01:33:27 +00:00
if (abs(int(coord.pixel[0] - subRect().location[0]) - slidePx) < 4)
2015-12-05 00:42:46 +00:00
{
if (button == boo::EMouseButton::Primary)
{
m_dragging = true;
2015-12-22 01:33:27 +00:00
setSlide((coord.pixel[0] - subRect().location[0]) / float(subRect().size[0]));
2015-12-05 00:42:46 +00:00
}
else if (button == boo::EMouseButton::Secondary)
{
// TODO: Split menu
}
return;
}
}
2015-12-20 21:59:23 +00:00
m_views[0].mouseDown(coord, button, mod);
m_views[1].mouseDown(coord, button, mod);
}
void SplitView::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
if (button == boo::EMouseButton::Primary)
m_dragging = false;
2015-12-20 21:59:23 +00:00
m_views[0].mouseUp(coord, button, mod);
m_views[1].mouseUp(coord, button, mod);
}
void SplitView::mouseMove(const boo::SWindowCoord& coord)
{
if (m_axis == Axis::Horizontal)
{
if (m_dragging)
2015-12-22 01:33:27 +00:00
setSlide((coord.pixel[1] - subRect().location[1]) / float(subRect().size[1]));
int slidePx = subRect().size[1] * m_slide;
2015-12-22 01:33:27 +00:00
rootView().setHorizontalSplitHover(abs(int(coord.pixel[1] - subRect().location[1]) - slidePx) < 4);
}
else if (m_axis == Axis::Vertical)
{
if (m_dragging)
2015-12-22 01:33:27 +00:00
setSlide((coord.pixel[0] - subRect().location[0]) / float(subRect().size[0]));
int slidePx = subRect().size[0] * m_slide;
2015-12-22 01:33:27 +00:00
rootView().setVerticalSplitHover(abs(int(coord.pixel[0] - subRect().location[0]) - slidePx) < 4);
2015-12-05 00:42:46 +00:00
}
2015-12-20 21:59:23 +00:00
m_views[0].mouseMove(coord);
m_views[1].mouseMove(coord);
2015-12-05 00:42:46 +00:00
}
void SplitView::mouseEnter(const boo::SWindowCoord& coord)
{
2015-12-20 21:59:23 +00:00
m_views[0].mouseEnter(coord);
m_views[1].mouseEnter(coord);
2015-12-05 00:42:46 +00:00
}
void SplitView::mouseLeave(const boo::SWindowCoord& coord)
{
2015-12-20 21:59:23 +00:00
m_views[0].mouseLeave(coord);
m_views[1].mouseLeave(coord);
}
void SplitView::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
{
View::resized(root, sub);
2015-12-22 01:33:27 +00:00
_setSlide(m_slide);
if (m_axis == Axis::Horizontal)
{
boo::SWindowRect ssub = sub;
ssub.size[1] *= m_slide;
2015-12-05 00:42:46 +00:00
if (m_views[0].m_view)
m_views[0].m_view->resized(root, ssub);
ssub.location[1] += ssub.size[1];
ssub.size[1] = sub.size[1] - ssub.size[1];
2015-12-05 00:42:46 +00:00
if (m_views[1].m_view)
m_views[1].m_view->resized(root, ssub);
2015-12-05 05:34:45 +00:00
ssub.location[1] -= 1;
m_splitBlock.setViewRect(root, ssub);
setHorizontalVerts(ssub.size[0]);
}
else if (m_axis == Axis::Vertical)
{
boo::SWindowRect ssub = sub;
ssub.size[0] *= m_slide;
2015-12-05 00:42:46 +00:00
if (m_views[0].m_view)
m_views[0].m_view->resized(root, ssub);
ssub.location[0] += ssub.size[0];
ssub.size[0] = sub.size[0] - ssub.size[0];
2015-12-05 00:42:46 +00:00
if (m_views[1].m_view)
m_views[1].m_view->resized(root, ssub);
2015-12-05 05:34:45 +00:00
ssub.location[0] -= 1;
m_splitBlock.setViewRect(root, ssub);
setVerticalVerts(ssub.size[1]);
}
m_splitBlockBuf->load(&m_splitBlock, sizeof(ViewBlock));
2015-12-05 00:42:46 +00:00
m_splitVertsBuf->load(m_splitVerts, sizeof(TexShaderVert) * 4);
}
void SplitView::draw(boo::IGraphicsCommandQueue* gfxQ)
{
View::draw(gfxQ);
2015-12-05 00:42:46 +00:00
if (m_views[0].m_view)
m_views[0].m_view->draw(gfxQ);
if (m_views[1].m_view)
m_views[1].m_view->draw(gfxQ);
gfxQ->setShaderDataBinding(m_splitShaderBinding);
gfxQ->draw(0, 4);
}
}