Chromium Code Reviews| Index: gm/OverStroke.cpp |
| diff --git a/gm/OverStroke.cpp b/gm/OverStroke.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..79dde4fe99c24cc6177e0555435770dbdfd64916 |
| --- /dev/null |
| +++ b/gm/OverStroke.cpp |
| @@ -0,0 +1,217 @@ |
| +/* |
| + * Copyright 2016 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "gm.h" |
| +#include "SkPaint.h" |
| +#include "SkPath.h" |
| + |
| +//////// path and paint builders |
| + |
| +SkPaint make_overstroke_paint() { |
| + SkPaint p; |
| + p.setAntiAlias(true); |
| + p.setStyle(SkPaint::kStroke_Style); |
| + p.setStrokeWidth(500); |
| + |
| + return p; |
| +} |
| + |
| +SkPath quad_path() { |
| + SkPoint p1 = SkPoint::Make(0, 0); |
|
reed1
2016/08/02 15:21:31
nit: I think it hurts readability a little to name
Harry Stern
2016/08/02 15:44:02
I actually think the exact opposite. seeing a bunc
|
| + SkPoint p2 = SkPoint::Make(100, 0); |
| + SkPoint p3 = SkPoint::Make(50, -40); |
| + |
| + SkPath path; |
| + path.moveTo(p1); |
| + path.lineTo(p2); |
| + path.quadTo(p3, p1); |
| + |
| + return path; |
| +} |
| + |
| +SkPath cubic_path() { |
| + SkPoint p1 = SkPoint::Make(0, 0); |
|
reed1
2016/08/02 15:21:31
ditto
Harry Stern
2016/08/02 15:44:02
Done.
|
| + SkPoint p2 = SkPoint::Make(25, 75); |
| + SkPoint p3 = SkPoint::Make(75, -50); |
| + SkPoint p4 = SkPoint::Make(100, 0); |
| + |
| + SkPath path; |
| + path.moveTo(p1); |
| + path.cubicTo(p2, p3, p4); |
| + |
| + return path; |
| +} |
| + |
| +SkPath oval_path() { |
| + SkRect oval = SkRect::MakeWH(100, 50); |
|
reed1
2016/08/02 15:21:31
nit: use SkRect::MakeXYWH(0, -25, 100, 50);
Harry Stern
2016/08/02 15:44:02
Done.
|
| + oval.offset(0, -25); |
| + |
| + SkPath path; |
| + path.arcTo(oval, 0, 359, true); |
|
Harry Stern
2016/08/02 15:44:02
There's no way to make a complete oval just with a
|
| + |
| + return path; |
| +} |
| + |
| +///////// quads |
| + |
| +void draw_small_quad(SkCanvas *canvas) { |
| + // scaled so it's visible |
| + canvas->scale(8, 8); |
| + |
| + SkPaint p; |
| + p.setAntiAlias(true); |
| + p.setStyle(SkPaint::kStroke_Style); |
| + p.setStrokeWidth(3); |
| + |
| + SkPath path = quad_path(); |
| + |
| + canvas->drawPath(path, p); |
| +} |
| + |
| +void draw_large_quad(SkCanvas *canvas) { |
| + SkPaint p = make_overstroke_paint(); |
| + SkPath path = quad_path(); |
| + |
| + canvas->drawPath(path, p); |
| +} |
| + |
| +void draw_quad_fillpath(SkCanvas *canvas) { |
| + SkPath path = quad_path(); |
| + SkPaint p = make_overstroke_paint(); |
| + |
| + SkPaint fillp; |
| + fillp.setAntiAlias(true); |
| + fillp.setStyle(SkPaint::kStroke_Style); |
| + fillp.setColor(SK_ColorMAGENTA); |
| + |
| + SkPath fillpath; |
| + p.getFillPath(path, &fillpath); |
| + |
| + canvas->drawPath(fillpath, fillp); |
| +} |
| + |
| +void draw_stroked_quad(SkCanvas *canvas) { |
| + canvas->translate(200, 0); |
| + draw_large_quad(canvas); |
| + draw_quad_fillpath(canvas); |
| +} |
| + |
| +////////// cubics |
| + |
| +void draw_small_cubic(SkCanvas *canvas) { |
| + // scaled so it's visible |
| + canvas->scale(8, 8); |
| + |
| + SkPaint p; |
| + p.setAntiAlias(true); |
| + p.setStyle(SkPaint::kStroke_Style); |
| + p.setStrokeWidth(3); |
| + |
| + SkPath path = cubic_path(); |
| + |
| + canvas->drawPath(path, p); |
| +} |
| + |
| +void draw_large_cubic(SkCanvas *canvas) { |
| + SkPaint p = make_overstroke_paint(); |
| + SkPath path = cubic_path(); |
| + |
| + canvas->drawPath(path, p); |
| +} |
| + |
| +void draw_cubic_fillpath(SkCanvas *canvas) { |
| + SkPath path = cubic_path(); |
| + SkPaint p = make_overstroke_paint(); |
| + |
| + SkPaint fillp; |
| + fillp.setAntiAlias(true); |
| + fillp.setStyle(SkPaint::kStroke_Style); |
| + fillp.setColor(SK_ColorMAGENTA); |
| + |
| + SkPath fillpath; |
| + p.getFillPath(path, &fillpath); |
| + |
| + canvas->drawPath(fillpath, fillp); |
| +} |
| + |
| +void draw_stroked_cubic(SkCanvas *canvas) { |
| + canvas->translate(400, 0); |
| + draw_large_cubic(canvas); |
| + draw_cubic_fillpath(canvas); |
| +} |
| + |
| +////////// ovals |
| + |
| +void draw_small_oval(SkCanvas *canvas) { |
| + // scaled so it's visible |
| + canvas->scale(8, 8); |
| + |
| + SkPaint p; |
| + p.setAntiAlias(true); |
| + p.setStyle(SkPaint::kStroke_Style); |
| + p.setStrokeWidth(3); |
| + |
| + SkPath path = oval_path(); |
| + |
| + canvas->drawPath(path, p); |
| +} |
| + |
| +void draw_large_oval(SkCanvas *canvas) { |
| + SkPaint p = make_overstroke_paint(); |
| + SkPath path = oval_path(); |
| + |
| + canvas->drawPath(path, p); |
| +} |
| + |
| +void draw_oval_fillpath(SkCanvas *canvas) { |
| + SkPath path = oval_path(); |
| + SkPaint p = make_overstroke_paint(); |
| + |
| + SkPaint fillp; |
| + fillp.setAntiAlias(true); |
| + fillp.setStyle(SkPaint::kStroke_Style); |
| + fillp.setColor(SK_ColorMAGENTA); |
| + |
| + SkPath fillpath; |
| + p.getFillPath(path, &fillpath); |
| + |
| + canvas->drawPath(fillpath, fillp); |
| +} |
| + |
| +void draw_stroked_oval(SkCanvas *canvas) { |
| + canvas->translate(400, 0); |
| + draw_large_oval(canvas); |
| + draw_oval_fillpath(canvas); |
| +} |
| + |
| +////////// gm |
| + |
| +void (*examples[])(SkCanvas *canvas) = { |
| + draw_small_quad, draw_stroked_quad, draw_small_cubic, |
| + draw_stroked_cubic, draw_small_oval, draw_stroked_oval, |
| +}; |
| + |
| +DEF_SIMPLE_GM(OverStroke, canvas, 500, 500) { |
|
reed1
2016/08/02 15:21:31
// overstroke means ... and that's why I want to e
Harry Stern
2016/08/02 15:44:02
Done, at top of file.
|
| + const size_t length = sizeof(examples) / sizeof(examples[0]); |
| + const size_t width = 2; |
| + |
| + printf("length %ld\n", length); |
| + |
| + for (size_t i = 0; i < length; i++) { |
| + int x = i % width; |
| + int y = i / width; |
| + |
| + canvas->save(); |
| + canvas->translate(200 * x, 150 * y); |
| + canvas->scale(0.25f, 0.25f); |
| + canvas->translate(100, 400); |
| + |
| + examples[i](canvas); |
| + |
| + canvas->restore(); |
| + } |
| +} |