SampleSlide.cpp 1.2 KB

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