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

Side by Side Diff: samplecode/SampleDraw.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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
« no previous file with comments | « samplecode/SampleDitherBitmap.cpp ('k') | samplecode/SampleEffects.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "SkGraphics.h" 11 #include "SkGraphics.h"
12 #include "SkRandom.h" 12 #include "SkRandom.h"
13 13
14 static void test_clearonlayers(SkCanvas* canvas) { 14 static void test_clearonlayers(SkCanvas* canvas) {
15 SkCanvas& c = *canvas; 15 SkCanvas& c = *canvas;
16 16
17 SkPaint paint; 17 SkPaint paint;
18 paint.setColor(SK_ColorBLUE); 18 paint.setColor(SK_ColorBLUE);
19 paint.setStyle(SkPaint::kStrokeAndFill_Style); 19 paint.setStyle(SkPaint::kStrokeAndFill_Style);
20 SkRect rect = SkRect::MakeXYWH(25, 25, 50, 50); 20 SkRect rect = SkRect::MakeXYWH(25, 25, 50, 50);
21 c.drawRect(rect, paint); 21 c.drawRect(rect, paint);
22 22
23 c.clipRect(rect); 23 c.clipRect(rect);
24 24
25 c.saveLayer(NULL, NULL); 25 c.saveLayer(nullptr, nullptr);
26 rect = SkRect::MakeXYWH(50, 10, 40, 80); 26 rect = SkRect::MakeXYWH(50, 10, 40, 80);
27 c.clipRect(rect, SkRegion::kUnion_Op); 27 c.clipRect(rect, SkRegion::kUnion_Op);
28 28
29 rect = SkRect::MakeXYWH(50, 0, 50, 100); 29 rect = SkRect::MakeXYWH(50, 0, 50, 100);
30 // You might draw something here, but it's not necessary. 30 // You might draw something here, but it's not necessary.
31 // paint.setColor(SK_ColorRED); 31 // paint.setColor(SK_ColorRED);
32 // c.drawRect(rect, paint); 32 // c.drawRect(rect, paint);
33 paint.setXfermodeMode(SkXfermode::kClear_Mode); 33 paint.setXfermodeMode(SkXfermode::kClear_Mode);
34 c.drawRect(rect, paint); 34 c.drawRect(rect, paint);
35 c.restore(); 35 c.restore();
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 255 }
256 }; 256 };
257 257
258 class DrawView : public SkView { 258 class DrawView : public SkView {
259 Draw* fDraw; 259 Draw* fDraw;
260 DrawFactory* fFactory; 260 DrawFactory* fFactory;
261 SkRandom fRand; 261 SkRandom fRand;
262 SkTDArray<Draw*> fList; 262 SkTDArray<Draw*> fList;
263 263
264 public: 264 public:
265 DrawView() : fDraw(NULL) { 265 DrawView() : fDraw(nullptr) {
266 fFactory = new RectFactory; 266 fFactory = new RectFactory;
267 } 267 }
268 268
269 virtual ~DrawView() { 269 virtual ~DrawView() {
270 fList.unrefAll(); 270 fList.unrefAll();
271 SkSafeUnref(fDraw); 271 SkSafeUnref(fDraw);
272 delete fFactory; 272 delete fFactory;
273 } 273 }
274 274
275 Draw* setDraw(Draw* d) { 275 Draw* setDraw(Draw* d) {
276 SkRefCnt_SafeAssign(fDraw, d); 276 SkRefCnt_SafeAssign(fDraw, d);
277 return d; 277 return d;
278 } 278 }
279 279
280 SkColor randColor() { 280 SkColor randColor() {
281 return (SkColor)fRand.nextU() | 0xFF000000; 281 return (SkColor)fRand.nextU() | 0xFF000000;
282 } 282 }
283 283
284 Draw* hitTestList(SkScalar x, SkScalar y) const { 284 Draw* hitTestList(SkScalar x, SkScalar y) const {
285 Draw** first = fList.begin(); 285 Draw** first = fList.begin();
286 for (Draw** iter = fList.end(); iter > first;) { 286 for (Draw** iter = fList.end(); iter > first;) {
287 --iter; 287 --iter;
288 if ((*iter)->hitTest(x, y)) { 288 if ((*iter)->hitTest(x, y)) {
289 return *iter; 289 return *iter;
290 } 290 }
291 } 291 }
292 return NULL; 292 return nullptr;
293 } 293 }
294 294
295 protected: 295 protected:
296 // overrides from SkEventSink 296 // overrides from SkEventSink
297 virtual bool onQuery(SkEvent* evt) { 297 virtual bool onQuery(SkEvent* evt) {
298 if (SampleCode::TitleQ(*evt)) { 298 if (SampleCode::TitleQ(*evt)) {
299 SampleCode::TitleR(evt, "Draw"); 299 SampleCode::TitleR(evt, "Draw");
300 return true; 300 return true;
301 } 301 }
302 return this->INHERITED::onQuery(evt); 302 return this->INHERITED::onQuery(evt);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 } 337 }
338 338
339 virtual bool onClick(Click* click) { 339 virtual bool onClick(Click* click) {
340 if (Click::kUp_State == click->fState) { 340 if (Click::kUp_State == click->fState) {
341 if (click->isType("maker")) { 341 if (click->isType("maker")) {
342 if (SkPoint::Distance(click->fOrig, click->fCurr) > SkIntToScala r(3)) { 342 if (SkPoint::Distance(click->fOrig, click->fCurr) > SkIntToScala r(3)) {
343 *fList.append() = fDraw; 343 *fList.append() = fDraw;
344 } else { 344 } else {
345 fDraw->unref(); 345 fDraw->unref();
346 } 346 }
347 fDraw = NULL; 347 fDraw = nullptr;
348 } 348 }
349 return true; 349 return true;
350 } 350 }
351 351
352 if (Click::kDown_State == click->fState) { 352 if (Click::kDown_State == click->fState) {
353 SkPaint p = fFactory->getPaint(); 353 SkPaint p = fFactory->getPaint();
354 p.setColor(this->randColor()); 354 p.setColor(this->randColor());
355 fFactory->setPaint(p); 355 fFactory->setPaint(p);
356 } 356 }
357 357
358 if (click->isType("maker")) { 358 if (click->isType("maker")) {
359 this->setDraw(fFactory->create(click->fOrig, click->fCurr))->unref() ; 359 this->setDraw(fFactory->create(click->fOrig, click->fCurr))->unref() ;
360 } else if (click->isType("dragger")) { 360 } else if (click->isType("dragger")) {
361 for (Draw** iter = fList.begin(); iter < fList.end(); iter++) { 361 for (Draw** iter = fList.begin(); iter < fList.end(); iter++) {
362 if ((*iter)->isSelected()) { 362 if ((*iter)->isSelected()) {
363 (*iter)->offset(click->fCurr.x() - click->fPrev.x(), 363 (*iter)->offset(click->fCurr.x() - click->fPrev.x(),
364 click->fCurr.y() - click->fPrev.y()); 364 click->fCurr.y() - click->fPrev.y());
365 } 365 }
366 } 366 }
367 } 367 }
368 this->inval(NULL); 368 this->inval(nullptr);
369 return true; 369 return true;
370 } 370 }
371 371
372 private: 372 private:
373 typedef SkView INHERITED; 373 typedef SkView INHERITED;
374 }; 374 };
375 375
376 ////////////////////////////////////////////////////////////////////////////// 376 //////////////////////////////////////////////////////////////////////////////
377 377
378 static SkView* MyFactory() { return new DrawView; } 378 static SkView* MyFactory() { return new DrawView; }
379 static SkViewRegister reg(MyFactory); 379 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleDitherBitmap.cpp ('k') | samplecode/SampleEffects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698