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