diff options
-rw-r--r-- | include/views/SkTouchGesture.h | 1 | ||||
-rw-r--r-- | src/views/SkTouchGesture.cpp | 8 | ||||
-rw-r--r-- | tools/viewer/Viewer.cpp | 9 | ||||
-rw-r--r-- | tools/viewer/Viewer.h | 7 | ||||
-rw-r--r-- | tools/viewer/sk_app/win/Window_win.cpp | 30 |
5 files changed, 50 insertions, 5 deletions
diff --git a/include/views/SkTouchGesture.h b/include/views/SkTouchGesture.h index 6776de7267..faadfc1b3d 100644 --- a/include/views/SkTouchGesture.h +++ b/include/views/SkTouchGesture.h @@ -39,6 +39,7 @@ public: bool isActive() { return fFlinger.isActive(); } void stop() { fFlinger.stop(); } + bool isBeingTouched() { return kEmpty_State != fState; } const SkMatrix& localM(); const SkMatrix& globalM() const { return fGlobalM; } diff --git a/src/views/SkTouchGesture.cpp b/src/views/SkTouchGesture.cpp index cd7388b6e1..dbcec511b7 100644 --- a/src/views/SkTouchGesture.cpp +++ b/src/views/SkTouchGesture.cpp @@ -209,10 +209,8 @@ void SkTouchGesture::touchMoved(void* owner, float x, float y) { int index = this->findRec(owner); if (index < 0) { - // not found, so I guess we should add it... - SkDebugf("---- add missing begin\n"); - this->appendNewRec(owner, x, y); - index = fTouches.count() - 1; + SkDebugf("---- ignoring move without begin\n"); + return; } Rec& rec = fTouches[index]; @@ -220,7 +218,7 @@ void SkTouchGesture::touchMoved(void* owner, float x, float y) { // not sure how valuable this is if (fTouches.count() == 2) { if (close_enough_for_jitter(rec.fLastX, rec.fLastY, x, y)) { -// SkDebugf("--- drop touchMove, withing jitter tolerance %g %g\n", rec.fLastX - x, rec.fLastY - y); +// SkDebugf("--- drop touchMove, within jitter tolerance %g %g\n", rec.fLastX - x, rec.fLastY - y); return; } } diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index 3503e6481f..e8e37346d8 100644 --- a/tools/viewer/Viewer.cpp +++ b/tools/viewer/Viewer.cpp @@ -251,6 +251,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData) , fColorMode(ColorMode::kLegacy) , fColorSpacePrimaries(gSrgbPrimaries) , fZoomLevel(0.0f) + , fGestureDevice(GestureDevice::kNone) { static SkTaskGroup::Enabler kTaskGroupEnabler; SkGraphics::Init(); @@ -819,6 +820,9 @@ void Viewer::onPaint(SkCanvas* canvas) { } bool Viewer::onTouch(intptr_t owner, Window::InputState state, float x, float y) { + if (GestureDevice::kMouse == fGestureDevice) { + return false; + } void* castedOwner = reinterpret_cast<void*>(owner); switch (state) { case Window::kUp_InputState: { @@ -834,11 +838,15 @@ bool Viewer::onTouch(intptr_t owner, Window::InputState state, float x, float y) break; } } + fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kTouch : GestureDevice::kNone; fWindow->inval(); return true; } bool Viewer::onMouse(float x, float y, Window::InputState state, uint32_t modifiers) { + if (GestureDevice::kTouch == fGestureDevice) { + return false; + } switch (state) { case Window::kUp_InputState: { fGesture.touchEnd(nullptr); @@ -853,6 +861,7 @@ bool Viewer::onMouse(float x, float y, Window::InputState state, uint32_t modifi break; } } + fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kMouse : GestureDevice::kNone; fWindow->inval(); return true; } diff --git a/tools/viewer/Viewer.h b/tools/viewer/Viewer.h index fac280ff59..1b68007ede 100644 --- a/tools/viewer/Viewer.h +++ b/tools/viewer/Viewer.h @@ -91,7 +91,14 @@ private: sk_app::CommandSet fCommands; + enum class GestureDevice { + kNone, + kTouch, + kMouse, + }; + SkTouchGesture fGesture; + GestureDevice fGestureDevice; // identity unless the window initially scales the content to fit the screen. SkMatrix fDefaultMatrix; diff --git a/tools/viewer/sk_app/win/Window_win.cpp b/tools/viewer/sk_app/win/Window_win.cpp index 1bec410ad2..6760089f79 100644 --- a/tools/viewer/sk_app/win/Window_win.cpp +++ b/tools/viewer/sk_app/win/Window_win.cpp @@ -114,6 +114,7 @@ bool Window_win::init(HINSTANCE hInstance) { } SetWindowLongPtr(fHWnd, GWLP_USERDATA, (LONG_PTR)this); + RegisterTouchWindow(fHWnd, 0); return true; } @@ -196,6 +197,7 @@ static uint32_t get_modifiers(UINT message, WPARAM wParam, LPARAM lParam) { if (wParam & MK_SHIFT) { modifiers |= Window::kShift_ModifierKey; } + break; } return modifiers; @@ -296,6 +298,34 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) get_modifiers(message, wParam, lParam)); break; + case WM_TOUCH: { + uint16_t numInputs = LOWORD(wParam); + std::unique_ptr<TOUCHINPUT[]> inputs(new TOUCHINPUT[numInputs]); + if (GetTouchInputInfo((HTOUCHINPUT)lParam, numInputs, inputs.get(), + sizeof(TOUCHINPUT))) { + RECT rect; + GetClientRect(hWnd, &rect); + for (uint16_t i = 0; i < numInputs; ++i) { + TOUCHINPUT ti = inputs[i]; + Window::InputState state; + if (ti.dwFlags & TOUCHEVENTF_DOWN) { + state = Window::kDown_InputState; + } else if (ti.dwFlags & TOUCHEVENTF_MOVE) { + state = Window::kMove_InputState; + } else if (ti.dwFlags & TOUCHEVENTF_UP) { + state = Window::kUp_InputState; + } else { + continue; + } + // TOUCHINPUT coordinates are in 100ths of pixels + // Adjust for that, and make them window relative + LONG tx = (ti.x / 100) - rect.left; + LONG ty = (ti.y / 100) - rect.top; + eventHandled = window->onTouch(ti.dwID, state, tx, ty) || eventHandled; + } + } + } break; + default: return DefWindowProc(hWnd, message, wParam, lParam); } |