OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "SampleCode.h" | 7 #include "SampleCode.h" |
8 #include "SkView.h" | 8 #include "SkView.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 SkCanvas c(bitmap); | 36 SkCanvas c(bitmap); |
37 c.translate(dx, dy); | 37 c.translate(dx, dy); |
38 | 38 |
39 SkPaint paint; | 39 SkPaint paint; |
40 paint.setStyle(SkPaint::kStroke_Style); | 40 paint.setStyle(SkPaint::kStroke_Style); |
41 paint.setStrokeWidth(1); | 41 paint.setStrokeWidth(1); |
42 | 42 |
43 // use the rect | 43 // use the rect |
44 c.clear(SK_ColorTRANSPARENT); | 44 c.clear(SK_ColorTRANSPARENT); |
45 c.drawRect(r, paint); | 45 c.drawRect(r, paint); |
46 canvas->drawBitmap(bitmap, 0, 0, NULL); | 46 canvas->drawBitmap(bitmap, 0, 0, nullptr); |
47 | 47 |
48 // use the path | 48 // use the path |
49 c.clear(SK_ColorTRANSPARENT); | 49 c.clear(SK_ColorTRANSPARENT); |
50 c.drawPath(path, paint); | 50 c.drawPath(path, paint); |
51 canvas->drawBitmap(bitmap, SkIntToScalar(2*width), 0, NULL); | 51 canvas->drawBitmap(bitmap, SkIntToScalar(2*width), 0, nullptr); |
52 } | 52 } |
53 | 53 |
54 static void drawFadingText(SkCanvas* canvas, | 54 static void drawFadingText(SkCanvas* canvas, |
55 const char* text, size_t len, SkScalar x, SkScalar y, | 55 const char* text, size_t len, SkScalar x, SkScalar y, |
56 const SkPaint& paint) { | 56 const SkPaint& paint) { |
57 // Need a bounds for the text | 57 // Need a bounds for the text |
58 SkRect bounds; | 58 SkRect bounds; |
59 SkPaint::FontMetrics fm; | 59 SkPaint::FontMetrics fm; |
60 | 60 |
61 paint.getFontMetrics(&fm); | 61 paint.getFontMetrics(&fm); |
62 bounds.set(x, y + fm.fTop, x + paint.measureText(text, len), y + fm.fBottom)
; | 62 bounds.set(x, y + fm.fTop, x + paint.measureText(text, len), y + fm.fBottom)
; |
63 | 63 |
64 // may need to outset bounds a little, to account for hinting and/or | 64 // may need to outset bounds a little, to account for hinting and/or |
65 // antialiasing | 65 // antialiasing |
66 bounds.inset(-SkIntToScalar(2), -SkIntToScalar(2)); | 66 bounds.inset(-SkIntToScalar(2), -SkIntToScalar(2)); |
67 | 67 |
68 canvas->saveLayer(&bounds, NULL); | 68 canvas->saveLayer(&bounds, nullptr); |
69 canvas->drawText(text, len, x, y, paint); | 69 canvas->drawText(text, len, x, y, paint); |
70 | 70 |
71 const SkPoint pts[] = { | 71 const SkPoint pts[] = { |
72 { bounds.fLeft, y }, | 72 { bounds.fLeft, y }, |
73 { bounds.fRight, y } | 73 { bounds.fRight, y } |
74 }; | 74 }; |
75 const SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 }; | 75 const SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 }; |
76 | 76 |
77 // pos[1] value is where we start to fade, relative to the width | 77 // pos[1] value is where we start to fade, relative to the width |
78 // of our pts[] array. | 78 // of our pts[] array. |
(...skipping 26 matching lines...) Expand all Loading... |
105 const SkPoint pts[] = { { x, y }, { x + paint.measureText(str, len), y } }; | 105 const SkPoint pts[] = { { x, y }, { x + paint.measureText(str, len), y } }; |
106 const SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 }; | 106 const SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 }; |
107 const SkScalar pos[] = { 0, 0.9f, 1 }; | 107 const SkScalar pos[] = { 0, 0.9f, 1 }; |
108 SkShader* s = SkGradientShader::CreateLinear(pts, colors, pos, | 108 SkShader* s = SkGradientShader::CreateLinear(pts, colors, pos, |
109 SK_ARRAY_COUNT(colors), | 109 SK_ARRAY_COUNT(colors), |
110 SkShader::kClamp_TileMode); | 110 SkShader::kClamp_TileMode); |
111 paint.setShader(s)->unref(); | 111 paint.setShader(s)->unref(); |
112 canvas->drawText(str, len, x, y, paint); | 112 canvas->drawText(str, len, x, y, paint); |
113 | 113 |
114 y += 20; | 114 y += 20; |
115 paint.setShader(NULL); | 115 paint.setShader(nullptr); |
116 drawFadingText(canvas, str, len, x, y, paint); | 116 drawFadingText(canvas, str, len, x, y, paint); |
117 } | 117 } |
118 | 118 |
119 #ifdef SK_DEBUG | 119 #ifdef SK_DEBUG |
120 static void make_rgn(SkRegion* rgn, int left, int top, int right, int bottom, | 120 static void make_rgn(SkRegion* rgn, int left, int top, int right, int bottom, |
121 int count, int32_t runs[]) { | 121 int count, int32_t runs[]) { |
122 SkIRect r; | 122 SkIRect r; |
123 r.set(left, top, right, bottom); | 123 r.set(left, top, right, bottom); |
124 | 124 |
125 rgn->debugSetRuns(runs, count); | 125 rgn->debugSetRuns(runs, count); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 this->build_rgn(&rgn, op); | 262 this->build_rgn(&rgn, op); |
263 | 263 |
264 { | 264 { |
265 SkRegion tmp, tmp2(rgn); | 265 SkRegion tmp, tmp2(rgn); |
266 | 266 |
267 tmp = tmp2; | 267 tmp = tmp2; |
268 tmp.translate(5, -3); | 268 tmp.translate(5, -3); |
269 | 269 |
270 { | 270 { |
271 char buffer[1000]; | 271 char buffer[1000]; |
272 SkDEBUGCODE(size_t size = ) tmp.writeToMemory(NULL); | 272 SkDEBUGCODE(size_t size = ) tmp.writeToMemory(nullptr); |
273 SkASSERT(size <= sizeof(buffer)); | 273 SkASSERT(size <= sizeof(buffer)); |
274 SkDEBUGCODE(size_t size2 = ) tmp.writeToMemory(buffer); | 274 SkDEBUGCODE(size_t size2 = ) tmp.writeToMemory(buffer); |
275 SkASSERT(size == size2); | 275 SkASSERT(size == size2); |
276 | 276 |
277 SkRegion tmp3; | 277 SkRegion tmp3; |
278 SkDEBUGCODE(size2 = ) tmp3.readFromMemory(buffer, 1000); | 278 SkDEBUGCODE(size2 = ) tmp3.readFromMemory(buffer, 1000); |
279 SkASSERT(size == size2); | 279 SkASSERT(size == size2); |
280 | 280 |
281 SkASSERT(tmp3 == tmp); | 281 SkASSERT(tmp3 == tmp); |
282 } | 282 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 this->drawPathOped(canvas, gOps[op].fOp, gOps[op].fColor); | 385 this->drawPathOped(canvas, gOps[op].fOp, gOps[op].fColor); |
386 canvas->restore(); | 386 canvas->restore(); |
387 | 387 |
388 canvas->translate(SkIntToScalar(200), 0); | 388 canvas->translate(SkIntToScalar(200), 0); |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, | 392 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, |
393 unsigned modi) override { | 393 unsigned modi) override { |
394 return fRect.contains(SkScalarRoundToInt(x), | 394 return fRect.contains(SkScalarRoundToInt(x), |
395 SkScalarRoundToInt(y)) ? new Click(this) : NULL; | 395 SkScalarRoundToInt(y)) ? new Click(this) : nullptr
; |
396 } | 396 } |
397 | 397 |
398 bool onClick(Click* click) override { | 398 bool onClick(Click* click) override { |
399 fRect.offset(click->fICurr.fX - click->fIPrev.fX, | 399 fRect.offset(click->fICurr.fX - click->fIPrev.fX, |
400 click->fICurr.fY - click->fIPrev.fY); | 400 click->fICurr.fY - click->fIPrev.fY); |
401 this->inval(NULL); | 401 this->inval(nullptr); |
402 return true; | 402 return true; |
403 } | 403 } |
404 | 404 |
405 private: | 405 private: |
406 SkIRect fBase, fRect; | 406 SkIRect fBase, fRect; |
407 | 407 |
408 typedef SampleView INHERITED; | 408 typedef SampleView INHERITED; |
409 }; | 409 }; |
410 | 410 |
411 ////////////////////////////////////////////////////////////////////////////// | 411 ////////////////////////////////////////////////////////////////////////////// |
412 | 412 |
413 static SkView* MyFactory() { return new RegionView; } | 413 static SkView* MyFactory() { return new RegionView; } |
414 static SkViewRegister reg(MyFactory); | 414 static SkViewRegister reg(MyFactory); |
OLD | NEW |