diff options
-rw-r--r-- | tools/viewer/SampleSlide.cpp | 49 | ||||
-rw-r--r-- | tools/viewer/SampleSlide.h | 3 | ||||
-rw-r--r-- | tools/viewer/Slide.h | 4 | ||||
-rw-r--r-- | tools/viewer/Viewer.cpp | 32 |
4 files changed, 71 insertions, 17 deletions
diff --git a/tools/viewer/SampleSlide.cpp b/tools/viewer/SampleSlide.cpp index 93a495eb8c..68dab9290f 100644 --- a/tools/viewer/SampleSlide.cpp +++ b/tools/viewer/SampleSlide.cpp @@ -12,13 +12,17 @@ #include "SkOSFile.h" #include "SkStream.h" -SampleSlide::SampleSlide(const SkViewFactory* factory) : fViewFactory(factory) { +using namespace sk_app; + +SampleSlide::SampleSlide(const SkViewFactory* factory) + : fViewFactory(factory) + , fClick(nullptr) { SkView* view = (*factory)(); SampleCode::RequestTitle(view, &fName); view->unref(); } -SampleSlide::~SampleSlide() {} +SampleSlide::~SampleSlide() { delete fClick; } void SampleSlide::draw(SkCanvas* canvas) { SkASSERT(fView); @@ -45,6 +49,47 @@ bool SampleSlide::onChar(SkUnichar c) { return fView->doQuery(&evt); } +bool SampleSlide::onMouse(SkScalar x, SkScalar y, Window::InputState state, + uint32_t modifiers) { + // map to SkView modifiers + unsigned modifierKeys = 0; + modifierKeys |= (state & Window::kShift_ModifierKey) ? kShift_SkModifierKey : 0; + modifierKeys |= (state & Window::kControl_ModifierKey) ? kControl_SkModifierKey : 0; + modifierKeys |= (state & Window::kOption_ModifierKey) ? kOption_SkModifierKey : 0; + modifierKeys |= (state & Window::kCommand_ModifierKey) ? kCommand_SkModifierKey : 0; + + bool handled = false; + switch (state) { + case Window::kDown_InputState: { + delete fClick; + fClick = fView->findClickHandler(SkIntToScalar(x), SkIntToScalar(y), modifierKeys); + if (fClick) { + SkView::DoClickDown(fClick, x, y, modifierKeys); + handled = true; + } + break; + } + case Window::kMove_InputState: { + if (fClick) { + SkView::DoClickMoved(fClick, x, y, modifierKeys); + handled = true; + } + break; + } + case Window::kUp_InputState: { + if (fClick) { + SkView::DoClickUp(fClick, x, y, modifierKeys); + delete fClick; + fClick = nullptr; + handled = true; + } + break; + } + } + + return handled; +} + #if defined(SK_BUILD_FOR_ANDROID) // these are normally defined in SkOSWindow_unix, but we don't // want to include that diff --git a/tools/viewer/SampleSlide.h b/tools/viewer/SampleSlide.h index 24325c91a0..4b91f39f74 100644 --- a/tools/viewer/SampleSlide.h +++ b/tools/viewer/SampleSlide.h @@ -27,10 +27,13 @@ public: } bool onChar(SkUnichar c) override; + bool onMouse(SkScalar x, SkScalar y, sk_app::Window::InputState state, + uint32_t modifiers) override; private: const SkViewFactory* fViewFactory; sk_sp<SkView> fView; + SkView::Click* fClick; }; #endif diff --git a/tools/viewer/Slide.h b/tools/viewer/Slide.h index 9ec7a3dbe1..e23a2eb78d 100644 --- a/tools/viewer/Slide.h +++ b/tools/viewer/Slide.h @@ -11,6 +11,7 @@ #include "SkRefCnt.h" #include "SkSize.h" #include "SkString.h" +#include "sk_app/Window.h" class SkCanvas; class SkAnimTimer; @@ -29,9 +30,12 @@ public: virtual void unload() {} virtual bool onChar(SkUnichar c) { return false; } + virtual bool onMouse(SkScalar x, SkScalar y, sk_app::Window::InputState state, + uint32_t modifiers) { return false; } SkString getName() { return fName; } + protected: SkString fName; }; diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index 85b78baf8f..2355d985b3 100644 --- a/tools/viewer/Viewer.cpp +++ b/tools/viewer/Viewer.cpp @@ -897,24 +897,26 @@ bool Viewer::onTouch(intptr_t owner, Window::InputState state, float x, float y) } 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); - break; - } - case Window::kDown_InputState: { - fGesture.touchBegin(nullptr, x, y); - break; + if (!fSlides[fCurrentSlide]->onMouse(x, y, state, modifiers)) { + if (GestureDevice::kTouch == fGestureDevice) { + return false; } - case Window::kMove_InputState: { - fGesture.touchMoved(nullptr, x, y); - break; + switch (state) { + case Window::kUp_InputState: { + fGesture.touchEnd(nullptr); + break; + } + case Window::kDown_InputState: { + fGesture.touchBegin(nullptr, x, y); + break; + } + case Window::kMove_InputState: { + fGesture.touchMoved(nullptr, x, y); + break; + } } + fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kMouse : GestureDevice::kNone; } - fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kMouse : GestureDevice::kNone; fWindow->inval(); return true; } |