Index: tools/viewer/Viewer.cpp |
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp |
index 7dd265e6e2183cd75c4e726410be8a845aa12d41..d492cdeefeb854246b90d5e721cfa43c28662cb9 100644 |
--- a/tools/viewer/Viewer.cpp |
+++ b/tools/viewer/Viewer.cpp |
@@ -28,6 +28,13 @@ static void on_paint_handler(SkCanvas* canvas, void* userData) { |
return vv->onPaint(canvas); |
} |
+static bool on_touch_handler(int owner, Window::InputState state, float x, float y, void* userData) |
+{ |
+ Viewer* viewer = reinterpret_cast<Viewer*>(userData); |
+ |
+ return viewer->onTouch(owner, state, x, y); |
+} |
+ |
DEFINE_bool2(fullscreen, f, true, "Run fullscreen."); |
DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON identifying this builder."); |
DEFINE_string2(match, m, nullptr, |
@@ -65,6 +72,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData) |
// register callbacks |
fCommands.attach(fWindow); |
fWindow->registerPaintFunc(on_paint_handler, this); |
+ fWindow->registerTouchFunc(on_touch_handler, this); |
// add key-bindings |
fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() { |
@@ -112,7 +120,6 @@ Viewer::Viewer(int argc, char** argv, void* platformData) |
// set up first frame |
fCurrentSlide = 0; |
setupCurrentSlide(-1); |
- updateMatrix(); |
fWindow->show(); |
} |
@@ -205,10 +212,9 @@ void Viewer::changeZoomLevel(float delta) { |
} else { |
fZoomScale = SK_Scalar1; |
} |
- this->updateMatrix(); |
} |
-void Viewer::updateMatrix(){ |
+SkMatrix Viewer::computeMatrix() { |
SkMatrix m; |
m.reset(); |
@@ -224,12 +230,10 @@ void Viewer::updateMatrix(){ |
m.postTranslate(cx, cy); |
} |
- // TODO: add gesture support |
- // Apply any gesture matrix |
- //m.preConcat(fGesture.localM()); |
- //m.preConcat(fGesture.globalM()); |
+ m.preConcat(fGesture.localM()); |
+ m.preConcat(fGesture.globalM()); |
- fLocalMatrix = m; |
+ return m; |
} |
void Viewer::onPaint(SkCanvas* canvas) { |
@@ -251,7 +255,7 @@ void Viewer::onPaint(SkCanvas* canvas) { |
matrix.setRectToRect(slideBounds, contentRect, SkMatrix::kCenter_ScaleToFit); |
canvas->concat(matrix); |
} |
- canvas->concat(fLocalMatrix); |
+ canvas->concat(computeMatrix()); |
fSlides[fCurrentSlide]->draw(canvas); |
canvas->restoreToCount(count); |
@@ -262,6 +266,26 @@ void Viewer::onPaint(SkCanvas* canvas) { |
fCommands.drawHelp(canvas); |
} |
+bool Viewer::onTouch(int owner, Window::InputState state, float x, float y) { |
+ void* castedOwner = reinterpret_cast<void*>(owner); |
+ switch (state) { |
+ case Window::kUp_InputState: { |
+ fGesture.touchEnd(castedOwner); |
+ break; |
+ } |
+ case Window::kDown_InputState: { |
+ fGesture.touchBegin(castedOwner, x, y); |
+ break; |
+ } |
+ case Window::kMove_InputState: { |
+ fGesture.touchMoved(castedOwner, x, y); |
+ break; |
+ } |
+ } |
+ fWindow->inval(); |
+ return true; |
+} |
+ |
void Viewer::drawStats(SkCanvas* canvas) { |
static const float kPixelPerMS = 2.0f; |
static const int kDisplayWidth = 130; |