in Kits/ATGTK/SampleGUI.cpp [4136:4299]
bool TextBox::Update(float elapsedTime, const DirectX::Mouse::State& mstate, const DirectX::Keyboard::State& kbstate)
{
UNREFERENCED_PARAMETER(elapsedTime);
auto mgr = UIManager::Impl::s_uiManager;
if (!mgr)
{
throw std::exception("UIManager");
}
// Handle mouse
if ((m_style & c_StyleScrollBar) && (m_thumbRect.top != m_thumbRect.bottom))
{
if (mstate.x >= m_scrollRect.left && mstate.x < m_scrollRect.right
&& mstate.y >= m_scrollRect.top && mstate.y < m_scrollRect.bottom)
{
if (mgr->m_mouseButtonState.leftButton == Mouse::ButtonStateTracker::PRESSED)
{
if (mstate.y < m_thumbRect.top)
{
if (!m_wordWrapLines.empty() && (m_lastHeight > 0))
{
int maxl = static_cast<int>(float(m_itemRect.bottom - m_itemRect.top - c_MarginSize * 2) / float(m_lastHeight));
m_topLine -= maxl;
if (m_topLine < 0)
m_topLine = 0;
}
}
else if (mstate.y > m_thumbRect.bottom)
{
if (!m_wordWrapLines.empty() && (m_lastHeight > 0))
{
int maxl = static_cast<int>(float(m_itemRect.bottom - m_itemRect.top - c_MarginSize * 2) / float(m_lastHeight));
m_topLine += maxl;
if (m_topLine >= static_cast<int>(m_wordWrapLines.size()))
m_topLine = static_cast<int>(m_wordWrapLines.size() - 1);
}
}
}
return true;
}
}
if (mstate.scrollWheelValue > m_lastWheelValue)
{
if (!m_wordWrapLines.empty())
{
if (m_topLine > 0)
{
--m_topLine;
}
}
m_lastWheelValue = mstate.scrollWheelValue;
return true;
}
if (mstate.scrollWheelValue < m_lastWheelValue)
{
if (!m_wordWrapLines.empty())
{
++m_topLine;
if (m_topLine >= static_cast<int>(m_wordWrapLines.size()))
m_topLine = static_cast<int>(m_wordWrapLines.size() - 1);
}
m_lastWheelValue = mstate.scrollWheelValue;
return true;
}
// Handle keyboard
if (kbstate.IsKeyDown(Keyboard::W) || kbstate.IsKeyDown(Keyboard::Up))
{
if (mgr->m_keyboardState.IsKeyPressed(Keyboard::W) || mgr->m_keyboardState.IsKeyPressed(Keyboard::Up))
{
mgr->m_heldTimer = c_KeypressRepeatDelay;
}
if (!m_wordWrapLines.empty() && mgr->m_heldTimer <= 0.f)
{
if (m_topLine > 0)
{
--m_topLine;
}
mgr->m_heldTimer = c_KeypressRepeatDelay;
}
return true;
}
else if (kbstate.IsKeyDown(Keyboard::S) || kbstate.IsKeyDown(Keyboard::Down))
{
if (mgr->m_keyboardState.IsKeyPressed(Keyboard::S) || mgr->m_keyboardState.IsKeyPressed(Keyboard::Down))
{
mgr->m_heldTimer = c_KeypressRepeatDelay;
}
if (!m_wordWrapLines.empty() && mgr->m_heldTimer <= 0.f)
{
++m_topLine;
if (m_topLine >= static_cast<int>(m_wordWrapLines.size()))
m_topLine = static_cast<int>(m_wordWrapLines.size() - 1);
mgr->m_heldTimer = c_KeypressRepeatDelay;
}
return true;
}
else if (kbstate.IsKeyDown(Keyboard::Home))
{
if (mgr->m_keyboardState.IsKeyPressed(Keyboard::Home))
{
m_topLine = 0;
}
return true;
}
else if (kbstate.IsKeyDown(Keyboard::End))
{
if (mgr->m_keyboardState.IsKeyPressed(Keyboard::End))
{
if (!m_wordWrapLines.empty())
{
m_topLine = static_cast<int>(m_wordWrapLines.size() - 1);
}
}
return true;
}
else if (kbstate.IsKeyDown(Keyboard::PageUp))
{
if (mgr->m_keyboardState.IsKeyPressed(Keyboard::PageUp))
{
mgr->m_heldTimer = c_KeypressRepeatDelay;
}
if (!m_wordWrapLines.empty() && (m_lastHeight > 0) && mgr->m_heldTimer <= 0.f)
{
int maxl = static_cast<int>(float(m_itemRect.bottom - m_itemRect.top - c_MarginSize * 2) / float(m_lastHeight));
m_topLine -= maxl;
if (m_topLine < 0)
m_topLine = 0;
mgr->m_heldTimer = c_KeypressRepeatDelay;
}
return true;
}
else if (kbstate.IsKeyDown(Keyboard::PageDown))
{
if (mgr->m_keyboardState.IsKeyPressed(Keyboard::PageDown))
{
mgr->m_heldTimer = c_KeypressRepeatDelay;
}
if (!m_wordWrapLines.empty() && (m_lastHeight > 0) && mgr->m_heldTimer <= 0.f)
{
int maxl = static_cast<int>(float(m_itemRect.bottom - m_itemRect.top - c_MarginSize * 2) / float(m_lastHeight));
m_topLine += maxl;
if (m_topLine >= static_cast<int>(m_wordWrapLines.size()))
m_topLine = static_cast<int>(m_wordWrapLines.size() - 1);
mgr->m_heldTimer = c_KeypressRepeatDelay;
}
return true;
}
return false;
}