Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / docs / examples / ChromeMDRefreshTabs.cpp
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);
11
12     // const float scaled_horizontal_inset = horizontal_inset * scale;
13
14     const float endcap_radius = endcap_width / 2;
15
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.
20     SkPath right_path;
21
22     right_path.moveTo(right, bottom);
23     // right_path.moveTo(right - 1 - scaled_horizontal_inset, bottom);
24
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);
29
30     right_path.lineTo(right - endcap_radius, endcap_radius);
31     // right_path.lineTo(
32     //    right - 1 - scaled_horizontal_inset - (endcap_width - 2) * scale,
33     //    2.5 * scale);
34
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);
39
40     right_path.lineTo(0, 0);
41     right_path.lineTo(0, bottom);
42     right_path.close();
43
44     SkPath left_path;
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);
48
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,
52     //                   1.5 * scale);
53
54     left_path.lineTo(endcap_radius, bottom - endcap_radius);
55     // left_path.lineTo(1 + scaled_horizontal_inset + 2 * scale,
56     //                 bottom - 1.5 * scale);
57
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);
62
63     left_path.lineTo(right, bottom);
64     left_path.lineTo(right, 0);
65     left_path.close();
66
67     SkPath complete_path;
68     Op(left_path, right_path, SkPathOp::kIntersect_SkPathOp, &complete_path);
69     return complete_path;
70 }
71
72 void draw(SkCanvas* canvas) {
73     SkPaint p;
74     p.setColor(SK_ColorRED);
75     p.setAntiAlias(true);
76     p.setStyle(SkPaint::kStroke_Style);
77     p.setStrokeWidth(1);
78     SkPath path = GetInteriorPath(1.f, SkISize::Make(250, 36), 16);
79     canvas->drawPath(path, p);
80
81     //  canvas->drawLine(20, 20, 100, 100, p);
82 }
83 }  // END FIDDLE