2016-06-16 16:52:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/viewer/SampleSlide.h"
|
2016-06-16 16:52:35 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "src/core/SkOSFile.h"
|
2016-06-16 16:52:35 +00:00
|
|
|
|
2017-11-02 13:46:49 +00:00
|
|
|
using namespace sk_app;
|
|
|
|
|
2019-07-12 15:32:43 +00:00
|
|
|
SampleSlide::SampleSlide(const SampleFactory factory) : fSampleFactory(factory) {
|
|
|
|
std::unique_ptr<Sample> sample(factory());
|
2019-07-03 14:55:44 +00:00
|
|
|
fName = sample->name();
|
2016-06-16 16:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 15:32:43 +00:00
|
|
|
SampleSlide::~SampleSlide() {}
|
2016-06-16 16:52:35 +00:00
|
|
|
|
2018-09-04 22:35:20 +00:00
|
|
|
SkISize SampleSlide::getDimensions() const {
|
|
|
|
return SkISize::Make(SkScalarCeilToInt(fSample->width()), SkScalarCeilToInt(fSample->height()));
|
|
|
|
}
|
|
|
|
|
2019-07-11 20:32:53 +00:00
|
|
|
bool SampleSlide::animate(double nanos) { return fSample->animate(nanos); }
|
|
|
|
|
2016-06-16 16:52:35 +00:00
|
|
|
void SampleSlide::draw(SkCanvas* canvas) {
|
2018-08-08 15:36:17 +00:00
|
|
|
SkASSERT(fSample);
|
|
|
|
fSample->draw(canvas);
|
2016-06-16 16:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SampleSlide::load(SkScalar winWidth, SkScalar winHeight) {
|
2018-08-08 15:36:17 +00:00
|
|
|
fSample.reset(fSampleFactory());
|
|
|
|
fSample->setSize(winWidth, winHeight);
|
2016-06-16 16:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SampleSlide::unload() {
|
2018-08-08 15:36:17 +00:00
|
|
|
fSample.reset();
|
2016-06-16 16:52:35 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 20:16:46 +00:00
|
|
|
bool SampleSlide::onChar(SkUnichar c) {
|
2019-07-03 19:53:04 +00:00
|
|
|
return fSample && fSample->onChar(c);
|
2017-02-14 20:16:46 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
bool SampleSlide::onMouse(SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifierKeys) {
|
2019-07-16 13:58:43 +00:00
|
|
|
return fSample && fSample->mouse({x, y}, state, modifierKeys);
|
2017-11-02 13:46:49 +00:00
|
|
|
}
|