MCPcopy Create free account
hub / github.com/ddnet/ddnet / UpdateButtonsEditor

Method UpdateButtonsEditor

src/game/client/components/touch_controls.cpp:1744–2065  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1742}
1743
1744void CTouchControls::UpdateButtonsEditor(const std::vector<IInput::CTouchFingerState> &vTouchFingerStates)
1745{
1746 std::vector<CUnitRect> vVisibleButtonRects;
1747 const vec2 ScreenSize = CalculateScreenSize();
1748 bool LongPress = false;
1749 for(CTouchButton &TouchButton : m_vTouchButtons)
1750 {
1751 TouchButton.UpdateVisibilityEditor();
1752 }
1753
1754 if(vTouchFingerStates.empty())
1755 m_PreventSaving = false;
1756
1757 // Remove if the finger deleted has released.
1758 if(!m_vDeletedFingerState.empty())
1759 {
1760 const auto &Remove = std::remove_if(m_vDeletedFingerState.begin(), m_vDeletedFingerState.end(), [&vTouchFingerStates](const auto &TargetState) {
1761 return std::none_of(vTouchFingerStates.begin(), vTouchFingerStates.end(), [&](const auto &State) {
1762 return State.m_Finger == TargetState.m_Finger;
1763 });
1764 });
1765 m_vDeletedFingerState.erase(Remove, m_vDeletedFingerState.end());
1766 }
1767 // Delete fingers if they are press later. So they cant be the longpress finger.
1768 if(vTouchFingerStates.size() > 1)
1769 {
1770 std::for_each(vTouchFingerStates.begin() + 1, vTouchFingerStates.end(), [&](const auto &State) {
1771 m_vDeletedFingerState.push_back(State);
1772 });
1773 }
1774
1775 // If released, and there is finger on screen, and the "first finger" is not deleted(new finger), then it can be a LongPress candidate.
1776 if(!vTouchFingerStates.empty() && !std::any_of(m_vDeletedFingerState.begin(), m_vDeletedFingerState.end(), [&vTouchFingerStates](const auto &State) {
1777 return vTouchFingerStates[0].m_Finger == State.m_Finger;
1778 }))
1779 {
1780 // If has different finger, reset the accumulated delta.
1781 if(m_LongPressFingerState.has_value() && (*m_LongPressFingerState).m_Finger != vTouchFingerStates[0].m_Finger)
1782 m_AccumulatedDelta = vec2(0.0f, 0.0f);
1783 // Update the LongPress candidate state.
1784 m_LongPressFingerState = vTouchFingerStates[0];
1785 }
1786 // If no suitable finger for long press, then clear it.
1787 else
1788 {
1789 m_LongPressFingerState = std::nullopt;
1790 }
1791
1792 // Find long press button. LongPress == true means the first fingerstate long pressed.
1793 if(m_LongPressFingerState.has_value())
1794 {
1795 m_AccumulatedDelta += (*m_LongPressFingerState).m_Delta;
1796 // If slided, then delete.
1797 if(length(m_AccumulatedDelta) > 0.005f)
1798 {
1799 m_AccumulatedDelta = vec2(0.0f, 0.0f);
1800 m_vDeletedFingerState.push_back(*m_LongPressFingerState);
1801 m_LongPressFingerState = std::nullopt;

Callers

nothing calls this directly

Calls 11

lengthFunction · 0.85
time_get_nanosecondsFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
IsInsideMethod · 0.80
InsideMethod · 0.80
getMethod · 0.80
SetActiveMethod · 0.45
IsActiveMethod · 0.45

Tested by

no test coverage detected