blob: af3b6ce88d751789e526820bec00271fad518158 [file] [log] [blame]
jvanverth9f372462016-04-06 06:08:59 -07001/*
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
jvanverth34524262016-05-04 13:49:13 -07008#ifndef Viewer_DEFINED
9#define Viewer_DEFINED
jvanverth9f372462016-04-06 06:08:59 -070010
jvanvertha8d0d6c2016-05-05 12:32:03 -070011#include "sk_app/Application.h"
brianosman622c8d52016-05-10 06:50:49 -070012#include "sk_app/CommandSet.h"
jvanvertha8d0d6c2016-05-05 12:32:03 -070013#include "sk_app/Window.h"
jvanverth9f372462016-04-06 06:08:59 -070014#include "gm.h"
jvanverthc265a922016-04-08 12:51:45 -070015#include "SkAnimTimer.h"
djsollen9207cae2016-06-10 07:50:00 -070016#include "SkTouchGesture.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070017#include "Slide.h"
jvanverth9f372462016-04-06 06:08:59 -070018
19class SkCanvas;
20
jvanverth34524262016-05-04 13:49:13 -070021class Viewer : public sk_app::Application {
jvanverth9f372462016-04-06 06:08:59 -070022public:
jvanverth34524262016-05-04 13:49:13 -070023 Viewer(int argc, char** argv, void* platformData);
24 ~Viewer() override;
jvanverth9f372462016-04-06 06:08:59 -070025
jvanverth9f372462016-04-06 06:08:59 -070026 void onPaint(SkCanvas* canvas);
jvanverth3d6ed3a2016-04-07 11:09:51 -070027 void onIdle(double ms) override;
jvanverth814e38d2016-06-06 08:48:47 -070028 bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y);
liyuqiane5a6cd92016-05-27 08:52:52 -070029 void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
jvanverth9f372462016-04-06 06:08:59 -070030
31private:
jvanverth2bb3b6d2016-04-08 07:24:09 -070032 void initSlides();
brianosman05de2162016-05-06 13:28:57 -070033 void updateTitle();
jvanverthc265a922016-04-08 12:51:45 -070034 void setupCurrentSlide(int previousSlide);
jvanverth2bb3b6d2016-04-08 07:24:09 -070035
liyuqiane5a6cd92016-05-27 08:52:52 -070036 void updateUIState();
37
jvanverth3d6ed3a2016-04-07 11:09:51 -070038 void drawStats(SkCanvas* canvas);
39
jvanverthc265a922016-04-08 12:51:45 -070040 void changeZoomLevel(float delta);
liyuqiand3cdbca2016-05-17 12:44:20 -070041 SkMatrix computeMatrix();
jvanverthc265a922016-04-08 12:51:45 -070042
jvanverth34524262016-05-04 13:49:13 -070043 sk_app::Window* fWindow;
jvanverth9f372462016-04-06 06:08:59 -070044
jvanverth3d6ed3a2016-04-07 11:09:51 -070045 static const int kMeasurementCount = 64; // should be power of 2 for fast mod
46 double fMeasurements[kMeasurementCount];
47 int fCurrentMeasurement;
48
jvanverthc265a922016-04-08 12:51:45 -070049 SkAnimTimer fAnimTimer;
jvanverth2bb3b6d2016-04-08 07:24:09 -070050 SkTArray<sk_sp<Slide>> fSlides;
51 int fCurrentSlide;
jvanverthc265a922016-04-08 12:51:45 -070052
53 bool fDisplayStats;
54
jvanverthaf236b52016-05-20 06:01:06 -070055 sk_app::Window::BackendType fBackendType;
56
jvanverthc265a922016-04-08 12:51:45 -070057 // transform data
jvanverthc265a922016-04-08 12:51:45 -070058 SkScalar fZoomCenterX;
59 SkScalar fZoomCenterY;
60 SkScalar fZoomLevel;
61 SkScalar fZoomScale;
62
brianosman622c8d52016-05-10 06:50:49 -070063 sk_app::CommandSet fCommands;
liyuqiand3cdbca2016-05-17 12:44:20 -070064
65 SkTouchGesture fGesture;
liyuqiane46e4f02016-05-20 07:32:19 -070066
67 // identity unless the window initially scales the content to fit the screen.
68 SkMatrix fDefaultMatrix;
69 SkMatrix fDefaultMatrixInv;
liyuqian1f508fd2016-06-07 06:57:40 -070070
71 Json::Value fAllSlideNames; // cache all slide names for fast updateUIState
jvanverth9f372462016-04-06 06:08:59 -070072};
73
74
75#endif