Chromium Code Reviews| 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 |
|
robertphillips
2016/01/04 20:12:56
Do we need Blur or MatrixConvolution ?
reed1
2016/01/04 20:49:02
The associated GM has all of those. Just wanted on
| |
| 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 | |
|
robertphillips
2016/01/04 20:12:56
delete this ?
reed1
2016/01/04 20:49:02
Done.
| |
| 246 //void sampleview_draw_clock(SkCanvas* canvas); | |
| 247 | |
| 248 class BackdropView : public SampleView { | |
| 249 SkPoint fCenter; | |
| 250 SkScalar fAngle; | |
| 251 SkAutoTUnref<SkImage> fImage; | |
| 252 SkAutoTUnref<SkImageFilter> fFilter; | |
| 253 public: | |
| 254 BackdropView() { | |
| 255 fCenter.set(200, 150); | |
| 256 fAngle = 0; | |
| 257 fImage.reset(GetResourceAsImage("mandrill_512.png")); | |
| 258 fFilter.reset(SkDilateImageFilter::Create(8, 8)); | |
| 259 } | |
| 260 | |
| 261 protected: | |
| 262 // overrides from SkEventSink | |
| 263 bool onQuery(SkEvent* evt) override { | |
| 264 if (SampleCode::TitleQ(*evt)) { | |
| 265 SampleCode::TitleR(evt, "Backdrop"); | |
| 266 return true; | |
| 267 } | |
| 268 return this->INHERITED::onQuery(evt); | |
| 269 } | |
| 270 | |
| 271 void onDrawContent(SkCanvas* canvas) override { | |
| 272 canvas->drawImage(fImage, 0, 0, nullptr); | |
| 273 | |
| 274 const SkScalar w = 250; | |
| 275 const SkScalar h = 150; | |
| 276 SkPath path; | |
| 277 path.addOval(SkRect::MakeXYWH(-w/2, -h/2, w, h)); | |
| 278 SkMatrix m; | |
| 279 m.setRotate(fAngle); | |
| 280 m.postTranslate(fCenter.x(), fCenter.y()); | |
| 281 path.transform(m); | |
| 282 | |
| 283 canvas->clipPath(path, SkRegion::kIntersect_Op, true); | |
| 284 const SkRect bounds = path.getBounds(); | |
| 285 canvas->saveLayer({ &bounds, nullptr, fFilter, 0 }); | |
| 286 | |
| 287 canvas->restore(); | |
| 288 } | |
| 289 | |
| 290 bool onAnimate(const SkAnimTimer& timer) override { | |
| 291 fAngle = SkDoubleToScalar(fmod(timer.secs() * 360 / 5, 360)); | |
| 292 return true; | |
| 293 } | |
| 294 | |
| 295 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride { | |
| 296 this->inval(nullptr); | |
| 297 return new Click(this); | |
| 298 } | |
| 299 | |
| 300 bool onClick(Click* click) override { | |
| 301 this->inval(nullptr); | |
| 302 fCenter = click->fCurr; | |
| 303 return this->INHERITED::onClick(click); | |
| 304 } | |
| 305 | |
| 306 private: | |
| 307 typedef SampleView INHERITED; | |
| 308 }; | |
| 309 DEF_SAMPLE( return new BackdropView; ) | |
| 310 | |
| OLD | NEW |