jvanverth | c7027ab | 2016-06-16 09:52:35 -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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "tools/viewer/SampleSlide.h" |
jvanverth | c7027ab | 2016-06-16 09:52:35 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkStream.h" |
| 12 | #include "src/core/SkOSFile.h" |
jvanverth | c7027ab | 2016-06-16 09:52:35 -0700 | [diff] [blame] | 13 | |
Jim Van Verth | c9e7f9c | 2017-11-02 09:46:49 -0400 | [diff] [blame] | 14 | using namespace sk_app; |
| 15 | |
Hal Canary | fcf6359 | 2019-07-12 11:32:43 -0400 | [diff] [blame] | 16 | SampleSlide::SampleSlide(const SampleFactory factory) : fSampleFactory(factory) { |
| 17 | std::unique_ptr<Sample> sample(factory()); |
Hal Canary | 8a02731 | 2019-07-03 10:55:44 -0400 | [diff] [blame] | 18 | fName = sample->name(); |
jvanverth | c7027ab | 2016-06-16 09:52:35 -0700 | [diff] [blame] | 19 | } |
| 20 | |
Hal Canary | fcf6359 | 2019-07-12 11:32:43 -0400 | [diff] [blame] | 21 | SampleSlide::~SampleSlide() {} |
jvanverth | c7027ab | 2016-06-16 09:52:35 -0700 | [diff] [blame] | 22 | |
Ben Wagner | 2115112 | 2018-09-04 18:35:20 -0400 | [diff] [blame] | 23 | SkISize SampleSlide::getDimensions() const { |
| 24 | return SkISize::Make(SkScalarCeilToInt(fSample->width()), SkScalarCeilToInt(fSample->height())); |
| 25 | } |
| 26 | |
Hal Canary | 4124807 | 2019-07-11 16:32:53 -0400 | [diff] [blame] | 27 | bool SampleSlide::animate(double nanos) { return fSample->animate(nanos); } |
| 28 | |
jvanverth | c7027ab | 2016-06-16 09:52:35 -0700 | [diff] [blame] | 29 | void SampleSlide::draw(SkCanvas* canvas) { |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 30 | SkASSERT(fSample); |
| 31 | fSample->draw(canvas); |
jvanverth | c7027ab | 2016-06-16 09:52:35 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void SampleSlide::load(SkScalar winWidth, SkScalar winHeight) { |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 35 | fSample.reset(fSampleFactory()); |
| 36 | fSample->setSize(winWidth, winHeight); |
jvanverth | c7027ab | 2016-06-16 09:52:35 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void SampleSlide::unload() { |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 40 | fSample.reset(); |
jvanverth | c7027ab | 2016-06-16 09:52:35 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 43 | bool SampleSlide::onChar(SkUnichar c) { |
Hal Canary | 6cc65e1 | 2019-07-03 15:53:04 -0400 | [diff] [blame] | 44 | return fSample && fSample->onChar(c); |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 45 | } |
| 46 | |
Hal Canary | b1f411a | 2019-08-29 10:39:22 -0400 | [diff] [blame] | 47 | bool SampleSlide::onMouse(SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifierKeys) { |
Hal Canary | ff2e8fe | 2019-07-16 09:58:43 -0400 | [diff] [blame] | 48 | return fSample && fSample->mouse({x, y}, state, modifierKeys); |
Jim Van Verth | c9e7f9c | 2017-11-02 09:46:49 -0400 | [diff] [blame] | 49 | } |