blob: 2e9650a846f470d2fb9238b0dc7d49bc79218e8a [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"
12#include "sk_app/Window.h"
jvanverth9f372462016-04-06 06:08:59 -070013#include "gm.h"
jvanverthc265a922016-04-08 12:51:45 -070014#include "SkAnimTimer.h"
jvanverth2bb3b6d2016-04-08 07:24:09 -070015#include "Slide.h"
jvanverth9f372462016-04-06 06:08:59 -070016
17class SkCanvas;
18
jvanverth34524262016-05-04 13:49:13 -070019class Viewer : public sk_app::Application {
jvanverth9f372462016-04-06 06:08:59 -070020public:
jvanverth34524262016-05-04 13:49:13 -070021 Viewer(int argc, char** argv, void* platformData);
22 ~Viewer() override;
jvanverth9f372462016-04-06 06:08:59 -070023
jvanverth34524262016-05-04 13:49:13 -070024 bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers);
jvanverthc265a922016-04-08 12:51:45 -070025 bool onChar(SkUnichar, uint32_t modifiers);
jvanverth9f372462016-04-06 06:08:59 -070026 void onPaint(SkCanvas* canvas);
jvanverth3d6ed3a2016-04-07 11:09:51 -070027 void onIdle(double ms) override;
jvanverth9f372462016-04-06 06:08:59 -070028
29private:
jvanverth2bb3b6d2016-04-08 07:24:09 -070030 void initSlides();
brianosman05de2162016-05-06 13:28:57 -070031 void updateTitle();
jvanverthc265a922016-04-08 12:51:45 -070032 void setupCurrentSlide(int previousSlide);
jvanverth2bb3b6d2016-04-08 07:24:09 -070033
jvanverth3d6ed3a2016-04-07 11:09:51 -070034 void drawStats(SkCanvas* canvas);
35
jvanverthc265a922016-04-08 12:51:45 -070036 void changeZoomLevel(float delta);
37 void updateMatrix();
38
jvanverth34524262016-05-04 13:49:13 -070039 sk_app::Window* fWindow;
jvanverth9f372462016-04-06 06:08:59 -070040
jvanverth3d6ed3a2016-04-07 11:09:51 -070041 static const int kMeasurementCount = 64; // should be power of 2 for fast mod
42 double fMeasurements[kMeasurementCount];
43 int fCurrentMeasurement;
44
jvanverthc265a922016-04-08 12:51:45 -070045 SkAnimTimer fAnimTimer;
jvanverth2bb3b6d2016-04-08 07:24:09 -070046 SkTArray<sk_sp<Slide>> fSlides;
47 int fCurrentSlide;
jvanverthc265a922016-04-08 12:51:45 -070048
49 bool fDisplayStats;
50
51 // transform data
52 SkMatrix fLocalMatrix;
53 SkScalar fZoomCenterX;
54 SkScalar fZoomCenterY;
55 SkScalar fZoomLevel;
56 SkScalar fZoomScale;
57
jvanverth9f372462016-04-06 06:08:59 -070058};
59
60
61#endif