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;
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
SampleSlide::SampleSlide(const SampleFactory factory)
|
|
|
|
: fSampleFactory(factory)
|
2019-07-03 14:55:44 +00:00
|
|
|
, fClick(nullptr)
|
|
|
|
{
|
2018-08-08 15:36:17 +00:00
|
|
|
sk_sp<Sample> sample(factory());
|
2019-07-03 14:55:44 +00:00
|
|
|
fName = sample->name();
|
2016-06-16 16:52:35 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 13:46:49 +00:00
|
|
|
SampleSlide::~SampleSlide() { delete fClick; }
|
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
|
|
|
}
|
|
|
|
|
2017-11-02 13:46:49 +00:00
|
|
|
bool SampleSlide::onMouse(SkScalar x, SkScalar y, Window::InputState state,
|
2019-07-08 20:07:57 +00:00
|
|
|
ModifierKey modifierKeys) {
|
2017-11-02 13:46:49 +00:00
|
|
|
bool handled = false;
|
|
|
|
switch (state) {
|
|
|
|
case Window::kDown_InputState: {
|
|
|
|
delete fClick;
|
2018-08-08 15:36:17 +00:00
|
|
|
fClick = fSample->findClickHandler(SkIntToScalar(x), SkIntToScalar(y), modifierKeys);
|
2017-11-02 13:46:49 +00:00
|
|
|
if (fClick) {
|
2018-08-08 15:36:17 +00:00
|
|
|
Sample::DoClickDown(fClick, x, y, modifierKeys);
|
2017-11-02 13:46:49 +00:00
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Window::kMove_InputState: {
|
|
|
|
if (fClick) {
|
2018-08-08 15:36:17 +00:00
|
|
|
Sample::DoClickMoved(fClick, x, y, modifierKeys);
|
2017-11-02 13:46:49 +00:00
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Window::kUp_InputState: {
|
|
|
|
if (fClick) {
|
2018-08-08 15:36:17 +00:00
|
|
|
Sample::DoClickUp(fClick, x, y, modifierKeys);
|
2017-11-02 13:46:49 +00:00
|
|
|
delete fClick;
|
|
|
|
fClick = nullptr;
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|