mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-08 22:27:43 +00:00
Dedicated PathButtons class and horizontal ScrollView
This commit is contained in:
@@ -7,7 +7,7 @@ namespace Specter
|
||||
#define MAX_SCROLL_SPEED 100
|
||||
|
||||
ScrollView::ScrollView(ViewResources& res, View& parentView, Style style)
|
||||
: View(res, parentView), m_style(style)
|
||||
: View(res, parentView), m_style(style), m_sideButtonBind(*this, rootView().viewManager())
|
||||
{
|
||||
m_vertsBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SolidShaderVert), 4);
|
||||
|
||||
@@ -33,39 +33,66 @@ ScrollView::ScrollView(ViewResources& res, View& parentView, Style style)
|
||||
nullptr, 1, bufs, 0, nullptr);
|
||||
}
|
||||
commitResources(res);
|
||||
|
||||
if (style == Style::SideButtons)
|
||||
{
|
||||
m_sideButtons[0].m_view.reset(new Button(res, *this, &m_sideButtonBind, "<"));
|
||||
m_sideButtons[1].m_view.reset(new Button(res, *this, &m_sideButtonBind, ">"));
|
||||
}
|
||||
}
|
||||
|
||||
bool ScrollView::_scroll(const boo::SScrollDelta& scroll)
|
||||
{
|
||||
if (m_contentView)
|
||||
if (m_contentView.m_view)
|
||||
{
|
||||
float ratio = subRect().size[1] / float(m_contentView->nominalHeight());
|
||||
if (ratio >= 1.f)
|
||||
{
|
||||
m_scroll[0] = 0;
|
||||
m_scroll[1] = 0;
|
||||
m_targetScroll[0] = 0;
|
||||
m_targetScroll[1] = 0;
|
||||
return true;
|
||||
}
|
||||
float ratioX = subRect().size[0] / float(m_contentView.m_view->nominalWidth());
|
||||
float ratioY = subRect().size[1] / float(m_contentView.m_view->nominalHeight());
|
||||
|
||||
float pf = rootView().viewRes().pixelFactor();
|
||||
double mult = 20.0 * pf;
|
||||
if (scroll.isFine)
|
||||
mult = 1.0 * pf;
|
||||
//m_targetScroll[0] -= scroll.delta[0] * mult;
|
||||
m_targetScroll[1] -= scroll.delta[1] * mult;
|
||||
|
||||
m_targetScroll[1] = std::max(m_targetScroll[1], 0);
|
||||
int scrollHeight = m_contentView->nominalHeight() - subRect().size[1];
|
||||
m_targetScroll[1] = std::min(m_targetScroll[1], scrollHeight);
|
||||
bool ret = false;
|
||||
|
||||
if (ratioX >= 1.f)
|
||||
{
|
||||
m_scroll[0] = 0;
|
||||
m_targetScroll[0] = 0;
|
||||
m_drawSideButtons = false;
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_drawSideButtons = true;
|
||||
m_targetScroll[0] += scroll.delta[0] * mult;
|
||||
m_targetScroll[0] = std::min(m_targetScroll[0], 0);
|
||||
int scrollWidth = m_contentView.m_view->nominalWidth() - scrollAreaWidth();
|
||||
m_targetScroll[0] = std::max(m_targetScroll[0], -scrollWidth);
|
||||
}
|
||||
|
||||
if (ratioY >= 1.f)
|
||||
{
|
||||
m_scroll[1] = 0;
|
||||
m_targetScroll[1] = 0;
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_targetScroll[1] -= scroll.delta[1] * mult;
|
||||
m_targetScroll[1] = std::max(m_targetScroll[1], 0);
|
||||
int scrollHeight = m_contentView.m_view->nominalHeight() - subRect().size[1];
|
||||
m_targetScroll[1] = std::min(m_targetScroll[1], scrollHeight);
|
||||
}
|
||||
|
||||
if (scroll.isFine)
|
||||
{
|
||||
m_scroll[0] = m_targetScroll[0];
|
||||
m_scroll[1] = m_targetScroll[1];
|
||||
return true;
|
||||
ret = true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -73,6 +100,7 @@ bool ScrollView::_scroll(const boo::SScrollDelta& scroll)
|
||||
m_scroll[1] = 0;
|
||||
m_targetScroll[0] = 0;
|
||||
m_targetScroll[1] = 0;
|
||||
m_drawSideButtons = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -80,32 +108,53 @@ bool ScrollView::_scroll(const boo::SScrollDelta& scroll)
|
||||
|
||||
void ScrollView::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
||||
{
|
||||
if (m_contentView)
|
||||
m_contentView->mouseDown(coord, button, mod);
|
||||
if (m_style == Style::SideButtons && m_drawSideButtons)
|
||||
{
|
||||
if (m_sideButtons[0].mouseDown(coord, button, mod) ||
|
||||
m_sideButtons[1].mouseDown(coord, button, mod))
|
||||
return;
|
||||
}
|
||||
m_contentView.mouseDown(coord, button, mod);
|
||||
}
|
||||
|
||||
void ScrollView::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
||||
{
|
||||
if (m_contentView)
|
||||
m_contentView->mouseUp(coord, button, mod);
|
||||
if (m_style == Style::SideButtons)
|
||||
{
|
||||
m_sideButtons[0].mouseUp(coord, button, mod);
|
||||
m_sideButtons[1].mouseUp(coord, button, mod);
|
||||
}
|
||||
m_contentView.mouseUp(coord, button, mod);
|
||||
}
|
||||
|
||||
void ScrollView::mouseMove(const boo::SWindowCoord& coord)
|
||||
{
|
||||
if (m_contentView)
|
||||
m_contentView->mouseMove(coord);
|
||||
if (m_style == Style::SideButtons && m_drawSideButtons)
|
||||
{
|
||||
m_sideButtons[0].mouseMove(coord);
|
||||
m_sideButtons[1].mouseMove(coord);
|
||||
}
|
||||
m_contentView.mouseMove(coord);
|
||||
}
|
||||
|
||||
void ScrollView::mouseEnter(const boo::SWindowCoord& coord)
|
||||
{
|
||||
if (m_contentView)
|
||||
m_contentView->mouseEnter(coord);
|
||||
if (m_style == Style::SideButtons && m_drawSideButtons)
|
||||
{
|
||||
m_sideButtons[0].mouseEnter(coord);
|
||||
m_sideButtons[1].mouseEnter(coord);
|
||||
}
|
||||
m_contentView.mouseEnter(coord);
|
||||
}
|
||||
|
||||
void ScrollView::mouseLeave(const boo::SWindowCoord& coord)
|
||||
{
|
||||
if (m_contentView)
|
||||
m_contentView->mouseLeave(coord);
|
||||
if (m_style == Style::SideButtons)
|
||||
{
|
||||
m_sideButtons[0].mouseLeave(coord);
|
||||
m_sideButtons[1].mouseLeave(coord);
|
||||
}
|
||||
m_contentView.mouseLeave(coord);
|
||||
}
|
||||
|
||||
void ScrollView::scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta& scroll)
|
||||
@@ -136,6 +185,17 @@ void ScrollView::think()
|
||||
m_consecutiveScroll[m_consecutiveIdx][0] = 0.0;
|
||||
m_consecutiveScroll[m_consecutiveIdx][1] = 0.0;
|
||||
|
||||
if (m_sideButtonState != SideButtonState::None)
|
||||
{
|
||||
if (m_sideButtonState == SideButtonState::ScrollLeft)
|
||||
m_targetScroll[0] -= 3;
|
||||
else if (m_sideButtonState == SideButtonState::ScrollRight)
|
||||
m_targetScroll[0] += 3;
|
||||
m_targetScroll[0] = std::min(m_targetScroll[0], 0);
|
||||
int scrollWidth = m_contentView.m_view->nominalWidth() - scrollAreaWidth();
|
||||
m_targetScroll[0] = std::max(m_targetScroll[0], -scrollWidth);
|
||||
}
|
||||
|
||||
bool update = false;
|
||||
float pf = rootView().viewRes().pixelFactor();
|
||||
|
||||
@@ -171,14 +231,26 @@ void ScrollView::resized(const boo::SWindowRect& root, const boo::SWindowRect& s
|
||||
{
|
||||
View::resized(root, sub);
|
||||
_scroll({});
|
||||
if (m_contentView)
|
||||
if (m_contentView.m_view)
|
||||
{
|
||||
boo::SWindowRect cRect = sub;
|
||||
cRect.location[0] += m_scroll[0];
|
||||
cRect.location[1] += sub.size[1] - m_contentView->nominalHeight() + m_scroll[1];
|
||||
cRect.size[0] = m_contentView->nominalWidth();
|
||||
cRect.size[1] = m_contentView->nominalHeight();
|
||||
m_contentView->resized(root, cRect, sub);
|
||||
cRect.location[1] += sub.size[1] - m_contentView.m_view->nominalHeight() + m_scroll[1];
|
||||
cRect.size[0] = m_contentView.m_view->nominalWidth();
|
||||
cRect.size[1] = m_contentView.m_view->nominalHeight();
|
||||
m_contentView.m_scissorRect = sub;
|
||||
if (m_style == Style::SideButtons && m_drawSideButtons)
|
||||
{
|
||||
int width0 = m_sideButtons[0].m_view->nominalWidth() + 2;
|
||||
int width1 = m_sideButtons[1].m_view->nominalWidth();
|
||||
cRect.location[0] += width0;
|
||||
cRect.size[0] -= (width0 + width1);
|
||||
|
||||
m_contentView.m_scissorRect.location[0] += width0;
|
||||
m_contentView.m_scissorRect.size[0] -= (width0 + width1);
|
||||
}
|
||||
m_contentView.m_view->resized(root, cRect, m_contentView.m_scissorRect);
|
||||
|
||||
|
||||
if (m_style == Style::ThinIndicator)
|
||||
{
|
||||
@@ -202,14 +274,26 @@ void ScrollView::resized(const boo::SWindowRect& root, const boo::SWindowRect& s
|
||||
m_vertsBuf->load(m_verts, sizeof(m_verts));
|
||||
}
|
||||
}
|
||||
else if (m_style == Style::SideButtons && m_drawSideButtons)
|
||||
{
|
||||
boo::SWindowRect bRect = sub;
|
||||
bRect.size[0] = m_sideButtons[0].m_view->nominalWidth();
|
||||
bRect.size[1] = m_sideButtons[0].m_view->nominalHeight();
|
||||
m_sideButtons[0].m_view->resized(root, bRect);
|
||||
|
||||
bRect.size[0] = m_sideButtons[1].m_view->nominalWidth();
|
||||
bRect.size[1] = m_sideButtons[1].m_view->nominalHeight();
|
||||
bRect.location[0] += sub.size[0] - bRect.size[0];
|
||||
m_sideButtons[1].m_view->resized(root, bRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollView::draw(boo::IGraphicsCommandQueue* gfxQ)
|
||||
{
|
||||
if (m_contentView)
|
||||
if (m_contentView.m_view)
|
||||
{
|
||||
m_contentView->draw(gfxQ);
|
||||
m_contentView.m_view->draw(gfxQ);
|
||||
|
||||
if (m_style == Style::ThinIndicator && m_drawInd)
|
||||
{
|
||||
@@ -217,6 +301,11 @@ void ScrollView::draw(boo::IGraphicsCommandQueue* gfxQ)
|
||||
gfxQ->setDrawPrimitive(boo::Primitive::TriStrips);
|
||||
gfxQ->draw(0, 4);
|
||||
}
|
||||
else if (m_style == Style::SideButtons && m_drawSideButtons)
|
||||
{
|
||||
m_sideButtons[0].m_view->draw(gfxQ);
|
||||
m_sideButtons[1].m_view->draw(gfxQ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user