1 // Copyright 2020 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(ChromeMDRefreshTab, 256, 256, false, 0) {
5 SkPath GetBorderPath(float scale,
10 // const float top = scale - 1;
11 const float right = size.fWidth * scale;
12 const float bottom = size.fHeight * scale;
13 const float scaled_endcap_radius = (endcap_width / 2) * scale;
16 path.moveTo(0, bottom - 1);
18 path.arcTo(scaled_endcap_radius - 1, scaled_endcap_radius - 1, 90, SkPath::kSmall_ArcSize,
19 SkPathDirection::kCCW, scaled_endcap_radius - 1,
20 bottom - 1 - scaled_endcap_radius);
21 // path.rLineTo(0, -1);
22 // path.rCubicTo(0.75 * scale, 0, 1.625 * scale, -0.5 * scale, 2 * scale,
24 path.lineTo(scaled_endcap_radius - 1, scaled_endcap_radius + 1);
25 // path.lineTo((endcap_width - 2) * scale, top + 1.5 * scale);
27 path.arcTo(scaled_endcap_radius + 1, scaled_endcap_radius + 1, 90, SkPath::kSmall_ArcSize,
28 SkPathDirection::kCW, scaled_endcap_radius * 2, -1);
30 // if (extend_to_top) {
31 // Create the vertical extension by extending the side diagonals until
32 // they reach the top of the bounds.
33 // const float dy = 2.5 * scale - 1;
34 // const float dx = Tab::GetInverseDiagonalSlope() * dy;
35 // path.rLineTo(dx, -dy);
36 // path.lineTo(right - (endcap_width - 2) * scale - dx, 0);
37 // path.rLineTo(dx, dy);
39 // path.rCubicTo(0.375 * scale, -scale, 1.25 * scale, -1.5 * scale, 2 * scale,
41 // path.lineTo(right - endcap_width * scale, top);
42 // path.rCubicTo(0.75 * scale, 0, 1.625 * scale, 0.5 * scale, 2 * scale,
45 path.lineTo(right - scaled_endcap_radius * 2, -1);
46 // path.lineTo(right - 2 * scale, bottom - 1 - 1.5 * scale);
49 path.arcTo(scaled_endcap_radius + 1, scaled_endcap_radius + 1, 90, SkPath::kSmall_ArcSize,
50 SkPathDirection::kCW, right - scaled_endcap_radius + 1,
51 scaled_endcap_radius + 1);
52 // path.arcTo(SkRect::MakeLTRB(right - 2 * scale, bottom - 1 - 1.5 * scale,
53 // right - 2 * scale + 4, bottom - 1 - 1.5 * scale + 4), 90, 90, true);
54 // path.rCubicTo(0.375 * scale, scale, 1.25 * scale, 1.5 * scale, 2 * scale,
57 path.lineTo(right - scaled_endcap_radius + 1, bottom - 1 - scaled_endcap_radius);
58 // path.rLineTo(0, 1);
61 path.arcTo(scaled_endcap_radius - 1, scaled_endcap_radius - 1, 90, SkPath::kSmall_ArcSize,
62 SkPathDirection::kCCW, right, bottom - 1);
65 if (unscale_at_end && (scale != 1)) path.transform(SkMatrix::Scale(1.f / scale,
71 SkPath GetInteriorPath(
72 float scale, const SkISize& size, float endcap_width, float horizontal_inset = 0) {
73 const float right = size.fWidth * scale;
74 // The bottom of the tab needs to be pixel-aligned or else when we call
75 // ClipPath with anti-aliasing enabled it can cause artifacts.
76 const float bottom = std::ceil(size.fHeight * scale);
78 // const float scaled_horizontal_inset = horizontal_inset * scale;
80 const float scaled_endcap_radius = (endcap_width / 2) * scale;
82 // Construct the interior path by intersecting paths representing the left
83 // and right halves of the tab. Compared to computing the full path at once,
84 // this makes it easier to avoid overdraw in the top center near minimum
85 // width, and to implement cases where |horizontal_inset| != 0.
88 right_path.moveTo(right, bottom);
89 // right_path.moveTo(right - 1 - scaled_horizontal_inset, bottom);
91 right_path.arcTo(scaled_endcap_radius, scaled_endcap_radius, 90, SkPath::kSmall_ArcSize,
92 SkPathDirection::kCW, right - scaled_endcap_radius,
93 bottom - scaled_endcap_radius);
94 // right_path.rCubicTo(-0.75 * scale, 0, -1.625 * scale, -0.5 * scale,
95 // -2 * scale, -1.5 * scale);
97 right_path.lineTo(right - scaled_endcap_radius, scaled_endcap_radius);
99 // right - 1 - scaled_horizontal_inset - (endcap_width - 2) * scale,
102 right_path.arcTo(scaled_endcap_radius, scaled_endcap_radius, 90, SkPath::kSmall_ArcSize,
103 SkPathDirection::kCCW, right - scaled_endcap_radius * 2, 0);
104 // right_path.rCubicTo(-0.375 * scale, -1 * scale, -1.25 * scale, -1.5 * scale,
105 // -2 * scale, -1.5 * scale);
107 right_path.lineTo(0, 0);
108 right_path.lineTo(0, bottom);
112 // const float scaled_endcap_width = 1 + endcap_width * scale;
113 left_path.moveTo(scaled_endcap_radius * 2, 0);
114 // left_path.moveTo(scaled_endcap_width + scaled_horizontal_inset, scale);
116 left_path.arcTo(scaled_endcap_radius, scaled_endcap_radius, 90, SkPath::kSmall_ArcSize,
117 SkPathDirection::kCCW, scaled_endcap_radius, scaled_endcap_radius);
118 // left_path.rCubicTo(-0.75 * scale, 0, -1.625 * scale, 0.5 * scale, -2 * scale,
121 left_path.lineTo(scaled_endcap_radius, bottom - scaled_endcap_radius);
122 // left_path.lineTo(1 + scaled_horizontal_inset + 2 * scale,
123 // bottom - 1.5 * scale);
125 left_path.arcTo(scaled_endcap_radius, scaled_endcap_radius, 90, SkPath::kSmall_ArcSize,
126 SkPathDirection::kCW, 0, bottom);
127 // left_path.rCubicTo(-0.375 * scale, scale, -1.25 * scale, 1.5 * scale,
128 // -2 * scale, 1.5 * scale);
130 left_path.lineTo(right, bottom);
131 left_path.lineTo(right, 0);
134 SkPath complete_path;
135 Op(left_path, right_path, SkPathOp::kIntersect_SkPathOp, &complete_path);
136 return complete_path;
139 void draw(SkCanvas* canvas) {
141 p.setColor(SK_ColorRED);
142 p.setAntiAlias(true);
143 p.setStyle(SkPaint::kStroke_Style);
145 SkPath path = GetInteriorPath(1.f, SkISize::Make(250, 36), 16);
146 path.transform(SkMatrix::Translate(0, 30));
147 canvas->drawPath(path, p);
149 p.setColor(SK_ColorBLUE);
150 SkPath border_path = GetBorderPath(1.f, false, false, 16, SkISize::Make(250, 36));
151 border_path.transform(SkMatrix::Translate(0, 30));
152 canvas->drawPath(border_path, p);
154 // canvas->drawLine(20, 20, 100, 100, p);