skia2/tools/viewer/SampleSlide.cpp
Hal Canary 41248071ac tools: separate TimeUtils from AnimTimer
gm, slides, and samples no longer need to know about the implementation
details of AnimTimer.

This
    virtual bool onAnimate(const AnimTimer&);
becomes this:
    virtual bool onAnimate(double /*nanoseconds*/);
which is much easier to reason about.

AnimTimer itself is now part of viewer.

Change-Id: Ib70bf7a0798b1991f25204ae84f70463cdbeb358
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/226838
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
2019-07-12 15:05:01 +00:00

83 lines
2.1 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "tools/viewer/SampleSlide.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkStream.h"
#include "src/core/SkOSFile.h"
using namespace sk_app;
SampleSlide::SampleSlide(const SampleFactory factory)
: fSampleFactory(factory)
, fClick(nullptr)
{
sk_sp<Sample> sample(factory());
fName = sample->name();
}
SampleSlide::~SampleSlide() { delete fClick; }
SkISize SampleSlide::getDimensions() const {
return SkISize::Make(SkScalarCeilToInt(fSample->width()), SkScalarCeilToInt(fSample->height()));
}
bool SampleSlide::animate(double nanos) { return fSample->animate(nanos); }
void SampleSlide::draw(SkCanvas* canvas) {
SkASSERT(fSample);
fSample->draw(canvas);
}
void SampleSlide::load(SkScalar winWidth, SkScalar winHeight) {
fSample.reset(fSampleFactory());
fSample->setSize(winWidth, winHeight);
}
void SampleSlide::unload() {
fSample.reset();
}
bool SampleSlide::onChar(SkUnichar c) {
return fSample && fSample->onChar(c);
}
bool SampleSlide::onMouse(SkScalar x, SkScalar y, Window::InputState state,
ModifierKey modifierKeys) {
bool handled = false;
switch (state) {
case Window::kDown_InputState: {
delete fClick;
fClick = fSample->findClickHandler(SkIntToScalar(x), SkIntToScalar(y), modifierKeys);
if (fClick) {
Sample::DoClickDown(fClick, x, y, modifierKeys);
handled = true;
}
break;
}
case Window::kMove_InputState: {
if (fClick) {
Sample::DoClickMoved(fClick, x, y, modifierKeys);
handled = true;
}
break;
}
case Window::kUp_InputState: {
if (fClick) {
Sample::DoClickUp(fClick, x, y, modifierKeys);
delete fClick;
fClick = nullptr;
handled = true;
}
break;
}
}
return handled;
}