Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: tools/viewer/Viewer.cpp

Issue 1982643004: Implement touch control (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Dedup Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Viewer.h" 8 #include "Viewer.h"
9 9
10 #include "GMSlide.h" 10 #include "GMSlide.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 this->setupCurrentSlide(previousSlide); 96 this->setupCurrentSlide(previousSlide);
97 }); 97 });
98 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]( ) { 98 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]( ) {
99 this->changeZoomLevel(1.f / 32.f); 99 this->changeZoomLevel(1.f / 32.f);
100 fWindow->inval(); 100 fWindow->inval();
101 }); 101 });
102 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [t his]() { 102 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [t his]() {
103 this->changeZoomLevel(-1.f / 32.f); 103 this->changeZoomLevel(-1.f / 32.f);
104 fWindow->inval(); 104 fWindow->inval();
105 }); 105 });
djsollen 2016/05/17 12:40:25 It seems more natural to me to implement the touch
106 106
107 // set up slides 107 // set up slides
108 this->initSlides(); 108 this->initSlides();
109 109
110 fAnimTimer.run(); 110 fAnimTimer.run();
111 111
112 // set up first frame 112 // set up first frame
113 fCurrentSlide = 0; 113 fCurrentSlide = 0;
114 setupCurrentSlide(-1); 114 setupCurrentSlide(-1);
115 updateMatrix();
116 115
117 fWindow->show(); 116 fWindow->show();
118 } 117 }
119 118
120 void Viewer::initSlides() { 119 void Viewer::initSlides() {
121 const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head()); 120 const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head());
122 while (gms) { 121 while (gms) {
123 SkAutoTDelete<skiagm::GM> gm(gms->factory()(nullptr)); 122 SkAutoTDelete<skiagm::GM> gm(gms->factory()(nullptr));
124 123
125 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) { 124 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 fZoomLevel += delta; 197 fZoomLevel += delta;
199 if (fZoomLevel > 0) { 198 if (fZoomLevel > 0) {
200 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); 199 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL);
201 fZoomScale = fZoomLevel + SK_Scalar1; 200 fZoomScale = fZoomLevel + SK_Scalar1;
202 } else if (fZoomLevel < 0) { 201 } else if (fZoomLevel < 0) {
203 fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL); 202 fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL);
204 fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel); 203 fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel);
205 } else { 204 } else {
206 fZoomScale = SK_Scalar1; 205 fZoomScale = SK_Scalar1;
207 } 206 }
208 this->updateMatrix();
209 } 207 }
210 208
211 void Viewer::updateMatrix(){ 209 SkMatrix Viewer::computeMatrix() {
212 SkMatrix m; 210 SkMatrix m;
213 m.reset(); 211 m.reset();
214 212
215 if (fZoomLevel) { 213 if (fZoomLevel) {
216 SkPoint center; 214 SkPoint center;
217 //m = this->getLocalMatrix();//.invert(&m); 215 //m = this->getLocalMatrix();//.invert(&m);
218 m.mapXY(fZoomCenterX, fZoomCenterY, &center); 216 m.mapXY(fZoomCenterX, fZoomCenterY, &center);
219 SkScalar cx = center.fX; 217 SkScalar cx = center.fX;
220 SkScalar cy = center.fY; 218 SkScalar cy = center.fY;
221 219
222 m.setTranslate(-cx, -cy); 220 m.setTranslate(-cx, -cy);
223 m.postScale(fZoomScale, fZoomScale); 221 m.postScale(fZoomScale, fZoomScale);
224 m.postTranslate(cx, cy); 222 m.postTranslate(cx, cy);
225 } 223 }
226 224
227 // TODO: add gesture support 225 m.preConcat(fWindow->getGestureLocalM());
228 // Apply any gesture matrix 226 m.preConcat(fWindow->getGestureGlobalM());
229 //m.preConcat(fGesture.localM());
230 //m.preConcat(fGesture.globalM());
231 227
232 fLocalMatrix = m; 228 return m;
233 } 229 }
234 230
235 void Viewer::onPaint(SkCanvas* canvas) { 231 void Viewer::onPaint(SkCanvas* canvas) {
236 232
237 int count = canvas->save(); 233 int count = canvas->save();
238 234
239 if (fWindow->supportsContentRect()) { 235 if (fWindow->supportsContentRect()) {
240 SkRect contentRect = fWindow->getContentRect(); 236 SkRect contentRect = fWindow->getContentRect();
241 canvas->clipRect(contentRect); 237 canvas->clipRect(contentRect);
242 canvas->translate(contentRect.fLeft, contentRect.fTop); 238 canvas->translate(contentRect.fLeft, contentRect.fTop);
243 } 239 }
244 240
245 canvas->clear(SK_ColorWHITE); 241 canvas->clear(SK_ColorWHITE);
246 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { 242 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) {
247 const SkRect contentRect = fWindow->getContentRect(); 243 const SkRect contentRect = fWindow->getContentRect();
248 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); 244 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
249 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize. height()); 245 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize. height());
250 SkMatrix matrix; 246 SkMatrix matrix;
251 matrix.setRectToRect(slideBounds, contentRect, SkMatrix::kCenter_ScaleTo Fit); 247 matrix.setRectToRect(slideBounds, contentRect, SkMatrix::kCenter_ScaleTo Fit);
252 canvas->concat(matrix); 248 canvas->concat(matrix);
253 } 249 }
254 canvas->concat(fLocalMatrix); 250 canvas->concat(computeMatrix());
255 251
256 fSlides[fCurrentSlide]->draw(canvas); 252 fSlides[fCurrentSlide]->draw(canvas);
257 canvas->restoreToCount(count); 253 canvas->restoreToCount(count);
258 254
259 if (fDisplayStats) { 255 if (fDisplayStats) {
260 drawStats(canvas); 256 drawStats(canvas);
261 } 257 }
262 fCommands.drawHelp(canvas); 258 fCommands.drawHelp(canvas);
263 } 259 }
264 260
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // Record measurements 310 // Record measurements
315 fMeasurements[fCurrentMeasurement++] = ms; 311 fMeasurements[fCurrentMeasurement++] = ms;
316 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod 312 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod
317 SkASSERT(fCurrentMeasurement < kMeasurementCount); 313 SkASSERT(fCurrentMeasurement < kMeasurementCount);
318 314
319 fAnimTimer.updateTime(); 315 fAnimTimer.updateTime();
320 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { 316 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) {
321 fWindow->inval(); 317 fWindow->inval();
322 } 318 }
323 } 319 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698