1 /* 2 * Copyright 2022 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef ClickHandlerSlide_DEFINED 9 #define ClickHandlerSlide_DEFINED 10 11 #include "tools/SkMetaData.h" 12 #include "tools/viewer/Slide.h" 13 14 /** 15 * Provides a higher level abstraction for click handling than the Slide base class. A Click object 16 * is is used to track the state of the mouse over time. 17 */ 18 class ClickHandlerSlide : public Slide { 19 public: 20 // Click handling 21 class Click { 22 public: Click()23 Click() {} Click(std::function<bool (Click *)> f)24 Click(std::function<bool(Click*)> f) : fFunc(f), fHasFunc(true) {} 25 virtual ~Click() = default; 26 27 SkPoint fOrig = {0, 0}; 28 SkPoint fPrev = {0, 0}; 29 SkPoint fCurr = {0, 0}; 30 31 skui::InputState fState = skui::InputState::kDown; 32 skui::ModifierKey fModifierKeys = skui::ModifierKey::kNone; 33 34 SkMetaData fMeta; 35 36 std::function<bool(Click*)> fFunc; 37 38 bool fHasFunc = false; 39 }; 40 41 bool onMouse(SkScalar x, SkScalar y, 42 skui::InputState clickState, 43 skui::ModifierKey modifierKeys) final; 44 45 protected: 46 /** 47 * Return a Click object to handle the click. onClick will be called repeatedly with the latest 48 * mouse state tracked on the Click object until it returns false. 49 */ 50 virtual Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) = 0; 51 52 /** Override to track clicks. Return true as long as you want to track the pen/mouse. */ 53 virtual bool onClick(Click*) = 0; 54 55 private: 56 std::unique_ptr<Click> fClick; 57 }; 58 59 #endif 60