| 1742 | } |
| 1743 | |
| 1744 | void 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; |
nothing calls this directly
no test coverage detected