#include #include #include namespace NXKit { #define THRESHOLD 10 void UITapGestureRecognizer::touchesBegan(std::vector> touches, std::shared_ptr event) { UIGestureRecognizer::touchesBegan(touches, event); if (!trackingTouch) { trackingTouch = touches[0]; startPoint = trackingTouch->locationIn(this->view().lock()); } } void UITapGestureRecognizer::touchesMoved(std::vector> touches, std::shared_ptr event) { UIGestureRecognizer::touchesMoved(touches, event); if (trackingTouch == touches[0]) { NXPoint diff = startPoint - trackingTouch->locationIn(this->view().lock()); if (abs(diff.x) >= THRESHOLD || abs(diff.y) >= THRESHOLD) { setState(UIGestureRecognizerState::failed); trackingTouch = nullptr; } } } void UITapGestureRecognizer::touchesEnded(std::vector> touches, std::shared_ptr event) { UIGestureRecognizer::touchesEnded(touches, event); if (trackingTouch == touches[0]) { setState(UIGestureRecognizerState::ended); trackingTouch = nullptr; } } void UITapGestureRecognizer::pressesBegan(std::vector> presses, std::shared_ptr event) { UIGestureRecognizer::pressesBegan(presses, event); if (presses.empty()) return; if (presses[0]->type() == UIPressType::select) { setState(UIGestureRecognizerState::began); } } void UITapGestureRecognizer::pressesEnded(std::vector> presses, std::shared_ptr event) { UIGestureRecognizer::pressesEnded(presses, event); if (presses.empty()) return; if (presses[0]->type() == UIPressType::select) { setState(UIGestureRecognizerState::ended); } } }