OLD | NEW |
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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 void Viewer::updateTitle() { | 183 void Viewer::updateTitle() { |
184 SkString title("Viewer: "); | 184 SkString title("Viewer: "); |
185 title.append(fSlides[fCurrentSlide]->getName()); | 185 title.append(fSlides[fCurrentSlide]->getName()); |
186 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) { | 186 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) { |
187 title.append(" sRGB"); | 187 title.append(" sRGB"); |
188 } | 188 } |
189 fWindow->setTitle(title.c_str()); | 189 fWindow->setTitle(title.c_str()); |
190 } | 190 } |
191 | 191 |
192 void Viewer::setupCurrentSlide(int previousSlide) { | 192 void Viewer::setupCurrentSlide(int previousSlide) { |
| 193 fGesture.reset(); |
| 194 fDefaultMatrix.reset(); |
| 195 fDefaultMatrixInv.reset(); |
| 196 |
| 197 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { |
| 198 const SkRect contentRect = fWindow->getContentRect(); |
| 199 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); |
| 200 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.
height()); |
| 201 if (contentRect.width() > 0 && contentRect.height() > 0) { |
| 202 fDefaultMatrix.setRectToRect(slideBounds, contentRect, SkMatrix::kSt
art_ScaleToFit); |
| 203 bool inverted = fDefaultMatrix.invert(&fDefaultMatrixInv); |
| 204 SkASSERT(inverted); |
| 205 } |
| 206 } |
| 207 |
| 208 if (fWindow->supportsContentRect()) { |
| 209 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); |
| 210 SkRect windowRect = fWindow->getContentRect(); |
| 211 fDefaultMatrixInv.mapRect(&windowRect); |
| 212 fGesture.setTransLimit(SkRect::MakeWH(slideSize.width(), slideSize.heigh
t()), windowRect); |
| 213 } |
| 214 |
193 this->updateTitle(); | 215 this->updateTitle(); |
194 fSlides[fCurrentSlide]->load(); | 216 fSlides[fCurrentSlide]->load(); |
195 if (previousSlide >= 0) { | 217 if (previousSlide >= 0) { |
196 fSlides[previousSlide]->unload(); | 218 fSlides[previousSlide]->unload(); |
197 } | 219 } |
198 fWindow->inval(); | 220 fWindow->inval(); |
199 } | 221 } |
200 | 222 |
201 #define MAX_ZOOM_LEVEL 8 | 223 #define MAX_ZOOM_LEVEL 8 |
202 #define MIN_ZOOM_LEVEL -8 | 224 #define MIN_ZOOM_LEVEL -8 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 262 |
241 int count = canvas->save(); | 263 int count = canvas->save(); |
242 | 264 |
243 if (fWindow->supportsContentRect()) { | 265 if (fWindow->supportsContentRect()) { |
244 SkRect contentRect = fWindow->getContentRect(); | 266 SkRect contentRect = fWindow->getContentRect(); |
245 canvas->clipRect(contentRect); | 267 canvas->clipRect(contentRect); |
246 canvas->translate(contentRect.fLeft, contentRect.fTop); | 268 canvas->translate(contentRect.fLeft, contentRect.fTop); |
247 } | 269 } |
248 | 270 |
249 canvas->clear(SK_ColorWHITE); | 271 canvas->clear(SK_ColorWHITE); |
250 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { | 272 canvas->concat(fDefaultMatrix); |
251 const SkRect contentRect = fWindow->getContentRect(); | |
252 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); | |
253 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.
height()); | |
254 SkMatrix matrix; | |
255 matrix.setRectToRect(slideBounds, contentRect, SkMatrix::kCenter_ScaleTo
Fit); | |
256 canvas->concat(matrix); | |
257 } | |
258 canvas->concat(computeMatrix()); | 273 canvas->concat(computeMatrix()); |
259 | 274 |
260 fSlides[fCurrentSlide]->draw(canvas); | 275 fSlides[fCurrentSlide]->draw(canvas); |
261 canvas->restoreToCount(count); | 276 canvas->restoreToCount(count); |
262 | 277 |
263 if (fDisplayStats) { | 278 if (fDisplayStats) { |
264 drawStats(canvas); | 279 drawStats(canvas); |
265 } | 280 } |
266 fCommands.drawHelp(canvas); | 281 fCommands.drawHelp(canvas); |
267 } | 282 } |
268 | 283 |
269 bool Viewer::onTouch(int owner, Window::InputState state, float x, float y) { | 284 bool Viewer::onTouch(int owner, Window::InputState state, float x, float y) { |
270 void* castedOwner = reinterpret_cast<void*>(owner); | 285 void* castedOwner = reinterpret_cast<void*>(owner); |
| 286 SkPoint touchPoint = fDefaultMatrixInv.mapXY(x, y); |
271 switch (state) { | 287 switch (state) { |
272 case Window::kUp_InputState: { | 288 case Window::kUp_InputState: { |
273 fGesture.touchEnd(castedOwner); | 289 fGesture.touchEnd(castedOwner); |
274 break; | 290 break; |
275 } | 291 } |
276 case Window::kDown_InputState: { | 292 case Window::kDown_InputState: { |
277 fGesture.touchBegin(castedOwner, x, y); | 293 fGesture.touchBegin(castedOwner, touchPoint.fX, touchPoint.fY); |
278 break; | 294 break; |
279 } | 295 } |
280 case Window::kMove_InputState: { | 296 case Window::kMove_InputState: { |
281 fGesture.touchMoved(castedOwner, x, y); | 297 fGesture.touchMoved(castedOwner, touchPoint.fX, touchPoint.fY); |
282 break; | 298 break; |
283 } | 299 } |
284 } | 300 } |
285 fWindow->inval(); | 301 fWindow->inval(); |
286 return true; | 302 return true; |
287 } | 303 } |
288 | 304 |
289 void Viewer::drawStats(SkCanvas* canvas) { | 305 void Viewer::drawStats(SkCanvas* canvas) { |
290 static const float kPixelPerMS = 2.0f; | 306 static const float kPixelPerMS = 2.0f; |
291 static const int kDisplayWidth = 130; | 307 static const int kDisplayWidth = 130; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 // Record measurements | 354 // Record measurements |
339 fMeasurements[fCurrentMeasurement++] = ms; | 355 fMeasurements[fCurrentMeasurement++] = ms; |
340 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod | 356 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod |
341 SkASSERT(fCurrentMeasurement < kMeasurementCount); | 357 SkASSERT(fCurrentMeasurement < kMeasurementCount); |
342 | 358 |
343 fAnimTimer.updateTime(); | 359 fAnimTimer.updateTime(); |
344 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { | 360 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { |
345 fWindow->inval(); | 361 fWindow->inval(); |
346 } | 362 } |
347 } | 363 } |
OLD | NEW |