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