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

Side by Side Diff: gm/circulararcs.cpp

Issue 2265643002: Rename circular_arcs_circular_arcs_fill to circular_arcs_fill (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Also fix issue with second paint's alpha Created 4 years, 4 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 | « no previous file | no next file » | 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 * Copyright 2016 Google Inc. 2 * Copyright 2016 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 7
8 #include <functional> 8 #include <functional>
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "gm.h" 10 #include "gm.h"
11 11
12 static constexpr SkScalar kStarts[] = {0.f, 10.f, 30.f, 45.f, 90.f, 165.f, 180.f , 270.f}; 12 static constexpr SkScalar kStarts[] = {0.f, 10.f, 30.f, 45.f, 90.f, 165.f, 180.f , 270.f};
13 static constexpr SkScalar kSweeps[] = {45.f, 90.f, 165.f, 180.f, 220.f, 270.f, 3 00.f, 315.f}; 13 static constexpr SkScalar kSweeps[] = {45.f, 90.f, 165.f, 180.f, 220.f, 270.f, 3 00.f, 315.f};
14 static constexpr SkScalar kDiameter = 40.f; 14 static constexpr SkScalar kDiameter = 40.f;
15 static constexpr SkRect kRect = {0.f, 0.f, kDiameter, kDiameter}; 15 static constexpr SkRect kRect = {0.f, 0.f, kDiameter, kDiameter};
16 static constexpr int kW = 1000; 16 static constexpr int kW = 1000;
17 static constexpr int kH = 1000; 17 static constexpr int kH = 1000;
18 static constexpr SkScalar kPad = 20.f; 18 static constexpr SkScalar kPad = 20.f;
19 19
20 void draw_arcs(SkCanvas* canvas, std::function<void(SkPaint*)> configureStyle) { 20 void draw_arcs(SkCanvas* canvas, std::function<void(SkPaint*)> configureStyle) {
21 // Draws grid of arcs with different start/sweep angles in red and their com plement arcs in 21 // Draws grid of arcs with different start/sweep angles in red and their com plement arcs in
22 // blue. 22 // blue.
23 auto drawGrid = [canvas, &configureStyle] (SkScalar x, SkScalar y, bool useC enter, bool aa) { 23 auto drawGrid = [canvas, &configureStyle] (SkScalar x, SkScalar y, bool useC enter, bool aa) {
24 SkPaint p0; 24 SkPaint p0;
25 p0.setColor(SK_ColorRED); 25 p0.setColor(SK_ColorRED);
26 p0.setAntiAlias(aa); 26 p0.setAntiAlias(aa);
27 // Set a reasonable stroke width that configureStyle can override. 27 // Set a reasonable stroke width that configureStyle can override.
28 p0.setStrokeWidth(15.f); 28 p0.setStrokeWidth(15.f);
29 SkPaint p1 = p0;
30 p1.setColor(SK_ColorBLUE);
29 // Use alpha so we see magenta on overlap between arc and its complement . 31 // Use alpha so we see magenta on overlap between arc and its complement .
30 p0.setAlpha(100); 32 p0.setAlpha(100);
31 SkPaint p1 = p0; 33 p1.setAlpha(100);
32 p1.setColor(SK_ColorBLUE);
33 configureStyle(&p0); 34 configureStyle(&p0);
34 configureStyle(&p1); 35 configureStyle(&p1);
35 36
36 canvas->save(); 37 canvas->save();
37 canvas->translate(kPad + x, kPad + y); 38 canvas->translate(kPad + x, kPad + y);
38 for (auto start : kStarts) { 39 for (auto start : kStarts) {
39 canvas->save(); 40 canvas->save();
40 for (auto sweep : kSweeps) { 41 for (auto sweep : kSweeps) {
41 canvas->drawArc(kRect, start, sweep, useCenter, p0); 42 canvas->drawArc(kRect, start, sweep, useCenter, p0);
42 canvas->drawArc(kRect, start, -(360.f - sweep), useCenter, p1); 43 canvas->drawArc(kRect, start, -(360.f - sweep), useCenter, p1);
(...skipping 14 matching lines...) Expand all
57 // Draw separators between the grids. 58 // Draw separators between the grids.
58 SkPaint linePaint; 59 SkPaint linePaint;
59 linePaint.setAntiAlias(true); 60 linePaint.setAntiAlias(true);
60 linePaint.setColor(SK_ColorBLACK); 61 linePaint.setColor(SK_ColorBLACK);
61 canvas->drawLine(kGridW, 0.f , kGridW, SkIntToScalar(kH), lineP aint); 62 canvas->drawLine(kGridW, 0.f , kGridW, SkIntToScalar(kH), lineP aint);
62 canvas->drawLine(0.f , kGridH, SkIntToScalar(kW), kGridH, lineP aint); 63 canvas->drawLine(0.f , kGridH, SkIntToScalar(kW), kGridH, lineP aint);
63 } 64 }
64 65
65 #define DEF_ARC_GM(name) DEF_SIMPLE_GM(circular_arcs_##name, canvas, kW, kH) 66 #define DEF_ARC_GM(name) DEF_SIMPLE_GM(circular_arcs_##name, canvas, kW, kH)
66 67
67 DEF_ARC_GM(circular_arcs_fill) { 68 DEF_ARC_GM(fill) {
68 auto setFill = [] (SkPaint*p) { p->setStyle(SkPaint::kFill_Style); }; 69 auto setFill = [] (SkPaint*p) { p->setStyle(SkPaint::kFill_Style); };
69 draw_arcs(canvas, setFill); 70 draw_arcs(canvas, setFill);
70 } 71 }
71 72
72 DEF_ARC_GM(hairline) { 73 DEF_ARC_GM(hairline) {
73 auto setHairline = [] (SkPaint* p) { 74 auto setHairline = [] (SkPaint* p) {
74 p->setStyle(SkPaint::kStroke_Style); 75 p->setStyle(SkPaint::kStroke_Style);
75 p->setStrokeWidth(0.f); 76 p->setStrokeWidth(0.f);
76 }; 77 };
77 draw_arcs(canvas, setHairline); 78 draw_arcs(canvas, setHairline);
(...skipping 15 matching lines...) Expand all
93 draw_arcs(canvas, setStroke); 94 draw_arcs(canvas, setStroke);
94 } 95 }
95 96
96 DEF_ARC_GM(stroke_round) { 97 DEF_ARC_GM(stroke_round) {
97 auto setStroke = [] (SkPaint* p) { 98 auto setStroke = [] (SkPaint* p) {
98 p->setStyle(SkPaint::kStroke_Style); 99 p->setStyle(SkPaint::kStroke_Style);
99 p->setStrokeCap(SkPaint::kRound_Cap); 100 p->setStrokeCap(SkPaint::kRound_Cap);
100 }; 101 };
101 draw_arcs(canvas, setStroke); 102 draw_arcs(canvas, setStroke);
102 } 103 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698