jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 1 | /* |
2 | * Copyright 2016 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 | |||||
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 8 | #ifndef Viewer_DEFINED |
9 | #define Viewer_DEFINED | ||||
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 10 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 11 | #include "sk_app/Application.h" |
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 12 | #include "sk_app/CommandSet.h" |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 13 | #include "sk_app/Window.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 14 | #include "gm.h" |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 15 | #include "SkAnimTimer.h" |
djsollen | 9207cae | 2016-06-10 07:50:00 -0700 | [diff] [blame^] | 16 | #include "SkTouchGesture.h" |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 17 | #include "Slide.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 18 | |
19 | class SkCanvas; | ||||
20 | |||||
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 21 | class Viewer : public sk_app::Application { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 22 | public: |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 23 | Viewer(int argc, char** argv, void* platformData); |
24 | ~Viewer() override; | ||||
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 25 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 26 | void onPaint(SkCanvas* canvas); |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 27 | void onIdle(double ms) override; |
jvanverth | 814e38d | 2016-06-06 08:48:47 -0700 | [diff] [blame] | 28 | bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y); |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 29 | void onUIStateChanged(const SkString& stateName, const SkString& stateValue); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 30 | |
31 | private: | ||||
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 32 | void initSlides(); |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 33 | void updateTitle(); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 34 | void setupCurrentSlide(int previousSlide); |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 35 | |
liyuqian | e5a6cd9 | 2016-05-27 08:52:52 -0700 | [diff] [blame] | 36 | void updateUIState(); |
37 | |||||
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 38 | void drawStats(SkCanvas* canvas); |
39 | |||||
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 40 | void changeZoomLevel(float delta); |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 41 | SkMatrix computeMatrix(); |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 42 | |
jvanverth | 3452426 | 2016-05-04 13:49:13 -0700 | [diff] [blame] | 43 | sk_app::Window* fWindow; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 44 | |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 45 | static const int kMeasurementCount = 64; // should be power of 2 for fast mod |
46 | double fMeasurements[kMeasurementCount]; | ||||
47 | int fCurrentMeasurement; | ||||
48 | |||||
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 49 | SkAnimTimer fAnimTimer; |
jvanverth | 2bb3b6d | 2016-04-08 07:24:09 -0700 | [diff] [blame] | 50 | SkTArray<sk_sp<Slide>> fSlides; |
51 | int fCurrentSlide; | ||||
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 52 | |
53 | bool fDisplayStats; | ||||
54 | |||||
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 55 | sk_app::Window::BackendType fBackendType; |
56 | |||||
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 57 | // transform data |
jvanverth | c265a92 | 2016-04-08 12:51:45 -0700 | [diff] [blame] | 58 | SkScalar fZoomCenterX; |
59 | SkScalar fZoomCenterY; | ||||
60 | SkScalar fZoomLevel; | ||||
61 | SkScalar fZoomScale; | ||||
62 | |||||
brianosman | 622c8d5 | 2016-05-10 06:50:49 -0700 | [diff] [blame] | 63 | sk_app::CommandSet fCommands; |
liyuqian | d3cdbca | 2016-05-17 12:44:20 -0700 | [diff] [blame] | 64 | |
65 | SkTouchGesture fGesture; | ||||
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 66 | |
67 | // identity unless the window initially scales the content to fit the screen. | ||||
68 | SkMatrix fDefaultMatrix; | ||||
69 | SkMatrix fDefaultMatrixInv; | ||||
liyuqian | 1f508fd | 2016-06-07 06:57:40 -0700 | [diff] [blame] | 70 | |
71 | Json::Value fAllSlideNames; // cache all slide names for fast updateUIState | ||||
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 72 | }; |
73 | |||||
74 | |||||
75 | #endif |