1 /* 2 * Copyright 2018 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 SlideDir_DEFINED 9 #define SlideDir_DEFINED 10 11 #include "include/core/SkPoint.h" 12 #include "include/core/SkRefCnt.h" 13 #include "include/core/SkScalar.h" 14 #include "include/core/SkSize.h" 15 #include "include/core/SkTypes.h" 16 #include "include/private/base/SkTArray.h" 17 #include "modules/sksg/include/SkSGGroup.h" 18 #include "modules/sksg/include/SkSGScene.h" 19 #include "tools/viewer/Slide.h" 20 21 #include <memory> 22 #include <vector> 23 24 class SkCanvas; 25 class SkString; 26 27 namespace skui { 28 enum class InputState; 29 enum class ModifierKey; 30 } // namespace skui 31 32 class SlideDir final : public Slide { 33 public: 34 SlideDir(const SkString& name, skia_private::TArray<sk_sp<Slide>>&&, 35 int columns = kDefaultColumnCount); 36 37 class Animator; 38 39 protected: 40 void load(SkScalar winWidth, SkScalar winHeight) override; 41 void unload() override; 42 43 SkISize getDimensions() const override; 44 45 void draw(SkCanvas*) override; 46 bool animate(double) override; 47 48 bool onChar(SkUnichar) override; 49 bool onMouse(SkScalar x, SkScalar y, skui::InputState, skui::ModifierKey modifiers) override; 50 51 private: 52 struct Rec; 53 class FocusController; 54 55 static constexpr int kDefaultColumnCount = 4; 56 57 const Rec* findCell(float x, float y) const; 58 59 const skia_private::TArray<sk_sp<Slide>> fSlides; 60 std::unique_ptr<FocusController> fFocusController; 61 const int fColumns; 62 63 std::vector<Rec> fRecs; 64 std::unique_ptr<sksg::Scene> fScene; 65 std::vector<sk_sp<Animator>> fSceneAnimators; 66 sk_sp<sksg::Group> fRoot; 67 68 SkSize fWinSize = SkSize::MakeEmpty(); 69 SkSize fCellSize = SkSize::MakeEmpty(); 70 SkMSec fTimeBase = 0; 71 72 const Rec* fTrackingCell = nullptr; 73 SkPoint fTrackingPos = SkPoint::Make(0, 0); 74 }; 75 76 #endif // SlideDir_DEFINED 77