2015-12-02 01:32:15 +00:00
|
|
|
#include <LogVisor/LogVisor.hpp>
|
|
|
|
#include "Specter/SplitView.hpp"
|
2015-12-05 00:42:46 +00:00
|
|
|
#include "Specter/RootView.hpp"
|
2015-12-02 01:32:15 +00:00
|
|
|
#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)
|
2015-12-02 01:32:15 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
SplitView::SplitView(ViewResources& system, View& parentView, Axis axis)
|
|
|
|
: View(system, parentView), m_axis(axis)
|
|
|
|
{
|
2015-12-03 03:26:50 +00:00
|
|
|
m_splitBlockBuf = system.m_factory->newDynamicBuffer(boo::BufferUse::Uniform, sizeof(ViewBlock), 1);
|
2015-12-05 00:42:46 +00:00
|
|
|
m_splitVertsBuf = system.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(TexShaderVert), 4);
|
2015-12-02 01:32:15 +00:00
|
|
|
|
|
|
|
if (!system.m_viewRes.m_texVtxFmt)
|
|
|
|
{
|
|
|
|
boo::VertexElementDescriptor vdescs[] =
|
|
|
|
{
|
|
|
|
{m_splitVertsBuf, nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{m_splitVertsBuf, nullptr, boo::VertexSemantic::UV4}
|
|
|
|
};
|
|
|
|
m_splitVtxFmt = system.m_factory->newVertexFormat(2, vdescs);
|
|
|
|
boo::IGraphicsBuffer* bufs[] = {m_splitBlockBuf};
|
2015-12-03 03:26:50 +00:00
|
|
|
boo::ITexture* texs[] = {system.m_splitRes.m_shadingTex};
|
2015-12-02 01:32:15 +00:00
|
|
|
m_splitShaderBinding = system.m_factory->newShaderDataBinding(system.m_viewRes.m_texShader,
|
2015-12-05 00:42:46 +00:00
|
|
|
m_splitVtxFmt, m_splitVertsBuf, nullptr,
|
|
|
|
nullptr, 1, bufs, 1, texs);
|
2015-12-02 01:32:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boo::IGraphicsBuffer* bufs[] = {m_splitBlockBuf};
|
2015-12-03 03:26:50 +00:00
|
|
|
boo::ITexture* texs[] = {system.m_splitRes.m_shadingTex};
|
2015-12-02 01:32:15 +00:00
|
|
|
m_splitShaderBinding = system.m_factory->newShaderDataBinding(system.m_viewRes.m_texShader,
|
2015-12-05 00:42:46 +00:00
|
|
|
system.m_viewRes.m_texVtxFmt,
|
|
|
|
m_splitVertsBuf, nullptr,
|
|
|
|
nullptr, 1, bufs, 1, texs);
|
2015-12-02 01:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
commitResources(system);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<View> SplitView::setContentView(int slot, std::unique_ptr<View>&& view)
|
|
|
|
{
|
|
|
|
if (slot < 0 || slot > 1)
|
|
|
|
Log.report(LogVisor::FatalError, "out-of-range slot to RootView::SplitView::setContentView");
|
|
|
|
std::unique_ptr<View> ret;
|
2015-12-05 00:42:46 +00:00
|
|
|
m_views[slot].m_view.swap(ret);
|
|
|
|
m_views[slot].m_view = std::move(view);
|
|
|
|
m_views[slot].m_mouseDown = false;
|
|
|
|
m_views[slot].m_mouseIn = false;
|
2015-12-02 01:32:15 +00:00
|
|
|
updateSize();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02 01:32:15 +00:00
|
|
|
{
|
2015-12-05 00:42:46 +00:00
|
|
|
int slidePx = subRect().size[1] * m_slide;
|
2015-12-05 05:57:51 +00:00
|
|
|
if (abs(int(coord.pixel[1] + 2) - slidePx) < 4)
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
|
|
|
if (button == boo::EMouseButton::Primary)
|
|
|
|
{
|
|
|
|
m_dragging = true;
|
2015-12-05 05:57:51 +00:00
|
|
|
setSlide((coord.pixel[1] + 2) / 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-05 05:57:51 +00:00
|
|
|
if (abs(int(coord.pixel[0] + 2) - slidePx) < 4)
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
|
|
|
if (button == boo::EMouseButton::Primary)
|
|
|
|
{
|
|
|
|
m_dragging = true;
|
2015-12-05 05:57:51 +00:00
|
|
|
setSlide((coord.pixel[0] + 2) / float(subRect().size[0]));
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
|
|
|
else if (button == boo::EMouseButton::Secondary)
|
|
|
|
{
|
|
|
|
// TODO: Split menu
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_views[0].m_view && !m_views[0].m_mouseDown &&
|
|
|
|
m_views[0].m_view->subRect().coordInRect(coord))
|
|
|
|
{
|
|
|
|
m_views[0].m_view->mouseDown(coord, button, mod);
|
|
|
|
m_views[0].m_mouseDown = true;
|
|
|
|
}
|
|
|
|
if (m_views[1].m_view && !m_views[1].m_mouseDown &&
|
|
|
|
m_views[1].m_view->subRect().coordInRect(coord))
|
|
|
|
{
|
|
|
|
m_views[1].m_view->mouseDown(coord, button, mod);
|
|
|
|
m_views[1].m_mouseDown = true;
|
2015-12-02 01:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplitView::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
|
|
|
{
|
|
|
|
if (button == boo::EMouseButton::Primary)
|
|
|
|
m_dragging = false;
|
2015-12-05 00:42:46 +00:00
|
|
|
if (m_views[0].m_view && m_views[0].m_mouseDown)
|
|
|
|
{
|
|
|
|
m_views[0].m_view->mouseUp(coord, button, mod);
|
|
|
|
m_views[0].m_mouseDown = false;
|
|
|
|
}
|
|
|
|
if (m_views[1].m_view && m_views[1].m_mouseDown)
|
|
|
|
{
|
|
|
|
m_views[1].m_view->mouseUp(coord, button, mod);
|
|
|
|
m_views[1].m_mouseDown = false;
|
|
|
|
}
|
2015-12-02 01:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SplitView::mouseMove(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
if (m_axis == Axis::Horizontal)
|
|
|
|
{
|
|
|
|
if (m_dragging)
|
2015-12-05 05:57:51 +00:00
|
|
|
setSlide((coord.pixel[1] + 2) / float(subRect().size[1]));
|
2015-12-02 01:32:15 +00:00
|
|
|
int slidePx = subRect().size[1] * m_slide;
|
2015-12-05 05:57:51 +00:00
|
|
|
if (abs(int(coord.pixel[1] + 2) - slidePx) < 4)
|
2015-12-05 00:42:46 +00:00
|
|
|
rootView().window()->setCursor(boo::EMouseCursor::VerticalArrow);
|
2015-12-02 01:32:15 +00:00
|
|
|
else
|
2015-12-05 00:42:46 +00:00
|
|
|
rootView().window()->setCursor(boo::EMouseCursor::Pointer);
|
2015-12-02 01:32:15 +00:00
|
|
|
}
|
|
|
|
else if (m_axis == Axis::Vertical)
|
|
|
|
{
|
|
|
|
if (m_dragging)
|
2015-12-05 05:57:51 +00:00
|
|
|
setSlide((coord.pixel[0] + 2) / float(subRect().size[0]));
|
2015-12-02 01:32:15 +00:00
|
|
|
int slidePx = subRect().size[0] * m_slide;
|
2015-12-05 05:57:51 +00:00
|
|
|
if (abs(int(coord.pixel[0] + 2) - slidePx) < 4)
|
2015-12-05 00:42:46 +00:00
|
|
|
rootView().window()->setCursor(boo::EMouseCursor::HorizontalArrow);
|
2015-12-02 01:32:15 +00:00
|
|
|
else
|
2015-12-05 00:42:46 +00:00
|
|
|
rootView().window()->setCursor(boo::EMouseCursor::Pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_views[0].m_view)
|
|
|
|
{
|
|
|
|
if (m_views[0].m_view->subRect().coordInRect(coord))
|
|
|
|
{
|
|
|
|
if (!m_views[0].m_mouseIn)
|
|
|
|
{
|
|
|
|
m_views[0].m_view->mouseEnter(coord);
|
|
|
|
m_views[0].m_mouseIn = true;
|
|
|
|
}
|
|
|
|
m_views[0].m_view->mouseMove(coord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_views[0].m_mouseIn)
|
|
|
|
{
|
|
|
|
m_views[0].m_view->mouseLeave(coord);
|
|
|
|
m_views[0].m_mouseIn = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_views[1].m_view)
|
|
|
|
{
|
|
|
|
if (m_views[1].m_view->subRect().coordInRect(coord))
|
|
|
|
{
|
|
|
|
if (!m_views[1].m_mouseIn)
|
|
|
|
{
|
|
|
|
m_views[1].m_view->mouseEnter(coord);
|
|
|
|
m_views[1].m_mouseIn = true;
|
|
|
|
}
|
|
|
|
m_views[1].m_view->mouseMove(coord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_views[1].m_mouseIn)
|
|
|
|
{
|
|
|
|
m_views[1].m_view->mouseLeave(coord);
|
|
|
|
m_views[1].m_mouseIn = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplitView::mouseEnter(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplitView::mouseLeave(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
if (m_views[0].m_view && m_views[0].m_mouseIn)
|
|
|
|
{
|
|
|
|
m_views[0].m_view->mouseLeave(coord);
|
|
|
|
m_views[0].m_mouseIn = false;
|
|
|
|
}
|
|
|
|
if (m_views[1].m_view && m_views[1].m_mouseIn)
|
|
|
|
{
|
|
|
|
m_views[1].m_view->mouseLeave(coord);
|
|
|
|
m_views[1].m_mouseIn = false;
|
2015-12-02 01:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 21:11:50 +00:00
|
|
|
void SplitView::resetResources(ViewResources& res)
|
|
|
|
{
|
2015-12-05 00:42:46 +00:00
|
|
|
if (m_views[0].m_view)
|
|
|
|
m_views[0].m_view->resetResources(res);
|
|
|
|
if (m_views[1].m_view)
|
|
|
|
m_views[1].m_view->resetResources(res);
|
2015-12-02 21:11:50 +00:00
|
|
|
}
|
|
|
|
|
2015-12-02 01:32:15 +00:00
|
|
|
void SplitView::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
|
|
|
|
{
|
|
|
|
View::resized(root, sub);
|
|
|
|
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);
|
2015-12-02 01:32:15 +00:00
|
|
|
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;
|
2015-12-02 01:32:15 +00:00
|
|
|
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);
|
2015-12-02 01:32:15 +00:00
|
|
|
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;
|
2015-12-02 01:32:15 +00:00
|
|
|
m_splitBlock.setViewRect(root, ssub);
|
|
|
|
setVerticalVerts(ssub.size[1]);
|
|
|
|
}
|
2015-12-03 03:26:50 +00:00
|
|
|
m_splitBlockBuf->load(&m_splitBlock, sizeof(ViewBlock));
|
2015-12-05 00:42:46 +00:00
|
|
|
m_splitVertsBuf->load(m_splitVerts, sizeof(TexShaderVert) * 4);
|
2015-12-02 01:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2015-12-02 01:32:15 +00:00
|
|
|
gfxQ->setShaderDataBinding(m_splitShaderBinding);
|
|
|
|
gfxQ->draw(0, 4);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|