blob: 662cb4042990a8306765e9163e29136e9fc8a07f [file] [log] [blame]
jvanverthc7027ab2016-06-16 09:52:35 -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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "tools/viewer/SampleSlide.h"
jvanverthc7027ab2016-06-16 09:52:35 -07009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
11#include "include/core/SkStream.h"
12#include "src/core/SkOSFile.h"
jvanverthc7027ab2016-06-16 09:52:35 -070013
Jim Van Verthc9e7f9c2017-11-02 09:46:49 -040014using namespace sk_app;
15
Hal Canaryfcf63592019-07-12 11:32:43 -040016SampleSlide::SampleSlide(const SampleFactory factory) : fSampleFactory(factory) {
17 std::unique_ptr<Sample> sample(factory());
Hal Canary8a027312019-07-03 10:55:44 -040018 fName = sample->name();
jvanverthc7027ab2016-06-16 09:52:35 -070019}
20
Hal Canaryfcf63592019-07-12 11:32:43 -040021SampleSlide::~SampleSlide() {}
jvanverthc7027ab2016-06-16 09:52:35 -070022
Ben Wagner21151122018-09-04 18:35:20 -040023SkISize SampleSlide::getDimensions() const {
24 return SkISize::Make(SkScalarCeilToInt(fSample->width()), SkScalarCeilToInt(fSample->height()));
25}
26
Hal Canary41248072019-07-11 16:32:53 -040027bool SampleSlide::animate(double nanos) { return fSample->animate(nanos); }
28
jvanverthc7027ab2016-06-16 09:52:35 -070029void SampleSlide::draw(SkCanvas* canvas) {
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040030 SkASSERT(fSample);
31 fSample->draw(canvas);
jvanverthc7027ab2016-06-16 09:52:35 -070032}
33
34void SampleSlide::load(SkScalar winWidth, SkScalar winHeight) {
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040035 fSample.reset(fSampleFactory());
36 fSample->setSize(winWidth, winHeight);
jvanverthc7027ab2016-06-16 09:52:35 -070037}
38
39void SampleSlide::unload() {
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040040 fSample.reset();
jvanverthc7027ab2016-06-16 09:52:35 -070041}
42
Jim Van Verth6f449692017-02-14 15:16:46 -050043bool SampleSlide::onChar(SkUnichar c) {
Hal Canary6cc65e12019-07-03 15:53:04 -040044 return fSample && fSample->onChar(c);
Jim Van Verth6f449692017-02-14 15:16:46 -050045}
46
Hal Canaryb1f411a2019-08-29 10:39:22 -040047bool SampleSlide::onMouse(SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifierKeys) {
Hal Canaryff2e8fe2019-07-16 09:58:43 -040048 return fSample && fSample->mouse({x, y}, state, modifierKeys);
Jim Van Verthc9e7f9c2017-11-02 09:46:49 -040049}