OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkView.h" | 9 #include "SkView.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 225 } |
226 | 226 |
227 virtual bool handleKey(SkKey) { | 227 virtual bool handleKey(SkKey) { |
228 this->inval(nullptr); | 228 this->inval(nullptr); |
229 return true; | 229 return true; |
230 } | 230 } |
231 | 231 |
232 private: | 232 private: |
233 typedef SkView INHERITED; | 233 typedef SkView INHERITED; |
234 }; | 234 }; |
| 235 DEF_SAMPLE( return new LayersView; ) |
235 | 236 |
236 ////////////////////////////////////////////////////////////////////////////// | 237 ////////////////////////////////////////////////////////////////////////////// |
237 | 238 |
238 static SkView* MyFactory() { return new LayersView; } | 239 #include "SkBlurImageFilter.h" |
239 static SkViewRegister reg(MyFactory); | 240 #include "SkMatrixConvolutionImageFilter.h" |
| 241 #include "SkMorphologyImageFilter.h" |
| 242 |
| 243 #include "Resources.h" |
| 244 #include "SkAnimTimer.h" |
| 245 |
| 246 class BackdropView : public SampleView { |
| 247 SkPoint fCenter; |
| 248 SkScalar fAngle; |
| 249 SkAutoTUnref<SkImage> fImage; |
| 250 SkAutoTUnref<SkImageFilter> fFilter; |
| 251 public: |
| 252 BackdropView() { |
| 253 fCenter.set(200, 150); |
| 254 fAngle = 0; |
| 255 fImage.reset(GetResourceAsImage("mandrill_512.png")); |
| 256 fFilter.reset(SkDilateImageFilter::Create(8, 8)); |
| 257 } |
| 258 |
| 259 protected: |
| 260 // overrides from SkEventSink |
| 261 bool onQuery(SkEvent* evt) override { |
| 262 if (SampleCode::TitleQ(*evt)) { |
| 263 SampleCode::TitleR(evt, "Backdrop"); |
| 264 return true; |
| 265 } |
| 266 return this->INHERITED::onQuery(evt); |
| 267 } |
| 268 |
| 269 void onDrawContent(SkCanvas* canvas) override { |
| 270 canvas->drawImage(fImage, 0, 0, nullptr); |
| 271 |
| 272 const SkScalar w = 250; |
| 273 const SkScalar h = 150; |
| 274 SkPath path; |
| 275 path.addOval(SkRect::MakeXYWH(-w/2, -h/2, w, h)); |
| 276 SkMatrix m; |
| 277 m.setRotate(fAngle); |
| 278 m.postTranslate(fCenter.x(), fCenter.y()); |
| 279 path.transform(m); |
| 280 |
| 281 canvas->clipPath(path, SkRegion::kIntersect_Op, true); |
| 282 const SkRect bounds = path.getBounds(); |
| 283 |
| 284 SkPaint paint; |
| 285 paint.setAlpha(0xCC); |
| 286 canvas->saveLayer({ &bounds, &paint, fFilter, 0 }); |
| 287 |
| 288 canvas->restore(); |
| 289 } |
| 290 |
| 291 bool onAnimate(const SkAnimTimer& timer) override { |
| 292 fAngle = SkDoubleToScalar(fmod(timer.secs() * 360 / 5, 360)); |
| 293 return true; |
| 294 } |
| 295 |
| 296 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { |
| 297 this->inval(nullptr); |
| 298 return new Click(this); |
| 299 } |
| 300 |
| 301 bool onClick(Click* click) override { |
| 302 this->inval(nullptr); |
| 303 fCenter = click->fCurr; |
| 304 return this->INHERITED::onClick(click); |
| 305 } |
| 306 |
| 307 private: |
| 308 typedef SampleView INHERITED; |
| 309 }; |
| 310 DEF_SAMPLE( return new BackdropView; ) |
| 311 |
OLD | NEW |