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(ChromeMDRefreshTabs, 256, 256, false, 0) {
5 SkPath GetInteriorPath(
6 float scale, const SkISize& size, float endcap_width, float horizontal_inset = 0) {
7 const float right = size.fWidth * scale;
8 // The bottom of the tab needs to be pixel-aligned or else when we call
9 // ClipPath with anti-aliasing enabled it can cause artifacts.
10 const float bottom = std::ceil(size.fHeight * scale);
12 // const float scaled_horizontal_inset = horizontal_inset * scale;
14 const float endcap_radius = endcap_width / 2;
16 // Construct the interior path by intersecting paths representing the left
17 // and right halves of the tab. Compared to computing the full path at once,
18 // this makes it easier to avoid overdraw in the top center near minimum
19 // width, and to implement cases where |horizontal_inset| != 0.
22 right_path.moveTo(right, bottom);
23 // right_path.moveTo(right - 1 - scaled_horizontal_inset, bottom);
25 right_path.arcTo(endcap_radius, endcap_radius, 90, SkPath::kSmall_ArcSize,
26 SkPathDirection::kCW, right - endcap_radius, bottom - endcap_radius);
27 // right_path.rCubicTo(-0.75 * scale, 0, -1.625 * scale, -0.5 * scale,
28 // -2 * scale, -1.5 * scale);
30 right_path.lineTo(right - endcap_radius, endcap_radius);
32 // right - 1 - scaled_horizontal_inset - (endcap_width - 2) * scale,
35 right_path.arcTo(endcap_radius, endcap_radius, 90, SkPath::kSmall_ArcSize,
36 SkPathDirection::kCCW, right - endcap_width, 0);
37 // right_path.rCubicTo(-0.375 * scale, -1 * scale, -1.25 * scale, -1.5 * scale,
38 // -2 * scale, -1.5 * scale);
40 right_path.lineTo(0, 0);
41 right_path.lineTo(0, bottom);
45 // const float scaled_endcap_width = 1 + endcap_width * scale;
46 left_path.moveTo(endcap_width, 0);
47 // left_path.moveTo(scaled_endcap_width + scaled_horizontal_inset, scale);
49 left_path.arcTo(endcap_radius, endcap_radius, 90, SkPath::kSmall_ArcSize,
50 SkPathDirection::kCCW, endcap_radius, endcap_radius);
51 // left_path.rCubicTo(-0.75 * scale, 0, -1.625 * scale, 0.5 * scale, -2 * scale,
54 left_path.lineTo(endcap_radius, bottom - endcap_radius);
55 // left_path.lineTo(1 + scaled_horizontal_inset + 2 * scale,
56 // bottom - 1.5 * scale);
58 left_path.arcTo(endcap_radius, endcap_radius, 90, SkPath::kSmall_ArcSize,
59 SkPathDirection::kCW, 0, bottom);
60 // left_path.rCubicTo(-0.375 * scale, scale, -1.25 * scale, 1.5 * scale,
61 // -2 * scale, 1.5 * scale);
63 left_path.lineTo(right, bottom);
64 left_path.lineTo(right, 0);
68 Op(left_path, right_path, SkPathOp::kIntersect_SkPathOp, &complete_path);
72 void draw(SkCanvas* canvas) {
74 p.setColor(SK_ColorRED);
76 p.setStyle(SkPaint::kStroke_Style);
78 SkPath path = GetInteriorPath(1.f, SkISize::Make(250, 36), 16);
79 canvas->drawPath(path, p);
81 // canvas->drawLine(20, 20, 100, 100, p);