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
8 #include "tools/viewer/SampleSlide.h"
9
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkStream.h"
12 #include "src/core/SkOSFile.h"
13
14 using namespace sk_app;
15
SampleSlide(const SampleFactory factory)16 SampleSlide::SampleSlide(const SampleFactory factory) : fSampleFactory(factory) {
17 std::unique_ptr<Sample> sample(factory());
18 fName = sample->name();
19 }
20
~SampleSlide()21 SampleSlide::~SampleSlide() {}
22
getDimensions() const23 SkISize SampleSlide::getDimensions() const {
24 return SkISize::Make(SkScalarCeilToInt(fSample->width()), SkScalarCeilToInt(fSample->height()));
25 }
26
animate(double nanos)27 bool SampleSlide::animate(double nanos) { return fSample->animate(nanos); }
28
draw(SkCanvas * canvas)29 void SampleSlide::draw(SkCanvas* canvas) {
30 SkASSERT(fSample);
31 fSample->draw(canvas);
32 }
33
load(SkScalar winWidth,SkScalar winHeight)34 void SampleSlide::load(SkScalar winWidth, SkScalar winHeight) {
35 fSample.reset(fSampleFactory());
36 fSample->setSize(winWidth, winHeight);
37 }
38
unload()39 void SampleSlide::unload() {
40 fSample.reset();
41 }
42
onChar(SkUnichar c)43 bool SampleSlide::onChar(SkUnichar c) {
44 return fSample && fSample->onChar(c);
45 }
46
onMouse(SkScalar x,SkScalar y,skui::InputState state,skui::ModifierKey modifierKeys)47 bool SampleSlide::onMouse(SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifierKeys) {
48 return fSample && fSample->mouse({x, y}, state, modifierKeys);
49 }
50