skia2/tools/viewer/SKPSlide.cpp
Jim Van Verth d0cf5da20d Hook up pinch-zoom and swipe gestures.
Sets UIPinchGestureRecognizer and UISwipeGestureRecognizers and
passes the result down to the sk_app::Window. To simplify detection,
swipes take precedence over pans, and pans require a single touch.
This is less flexible for the app, but in most cases I think is
what we want.

Bug: skia:8737
Change-Id: Ib031b6ad465d3a353da29d7e0b48a666d4ff8b9a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/239776
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2019-09-10 13:34:47 +00:00

60 lines
1.4 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/SKPSlide.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkStream.h"
#include "src/core/SkOSFile.h"
SKPSlide::SKPSlide(const SkString& name, const SkString& path) : fPath(path) {
fName = name;
}
SKPSlide::~SKPSlide() {}
void SKPSlide::draw(SkCanvas* canvas) {
if (fPic.get()) {
bool isOffset = SkToBool(fCullRect.left() | fCullRect.top());
if (isOffset) {
canvas->save();
canvas->translate(SkIntToScalar(-fCullRect.left()), SkIntToScalar(-fCullRect.top()));
}
canvas->drawPicture(fPic.get());
if (isOffset) {
canvas->restore();
}
}
}
static sk_sp<SkPicture> read_picture(const char path[]) {
std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
if (!stream) {
SkDebugf("Could not read %s.\n", path);
return nullptr;
}
auto pic = SkPicture::MakeFromStream(stream.get());
if (!pic) {
SkDebugf("Could not read %s as an SkPicture.\n", path);
}
return pic;
}
void SKPSlide::load(SkScalar, SkScalar) {
fPic = read_picture(fPath.c_str());
if (fPic) {
fCullRect = fPic->cullRect().roundOut();
}
}
void SKPSlide::unload() {
fPic.reset(nullptr);
}