Flutter Engine
 
Loading...
Searching...
No Matches
rsuperellipse.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
10
11namespace flutter {
12
13namespace {
14
15flutter::DlRect BuildBounds(float left, float top, float right, float bottom) {
16 // The Flutter rect may be inverted (upside down, backward, or both)
17 // Historically, Skia would normalize such rects but we will do that
18 // manually below when we construct the Impeller Rect
19 flutter::DlRect raw_rect =
20 flutter::DlRect::MakeLTRB(left, top, right, bottom);
21 return raw_rect.GetPositive();
22}
23
24impeller::RoundingRadii BuildRadii(float tl_radius_x,
25 float tl_radius_y,
26 float tr_radius_x,
27 float tr_radius_y,
28 float br_radius_x,
29 float br_radius_y,
30 float bl_radius_x,
31 float bl_radius_y) {
32 // Flutter has radii in TL,TR,BR,BL (clockwise) order,
33 // but Impeller uses TL,TR,BL,BR (zig-zag) order
35 .top_left = flutter::DlSize(tl_radius_x, tl_radius_y),
36 .top_right = flutter::DlSize(tr_radius_x, tr_radius_y),
37 .bottom_left = flutter::DlSize(bl_radius_x, bl_radius_y),
38 .bottom_right = flutter::DlSize(br_radius_x, br_radius_y),
39 };
40}
41} // namespace
42
44
45void RSuperellipse::Create(Dart_Handle wrapper,
46 double left,
47 double top,
48 double right,
49 double bottom,
50 double tl_radius_x,
51 double tl_radius_y,
52 double tr_radius_x,
53 double tr_radius_y,
54 double br_radius_x,
55 double br_radius_y,
56 double bl_radius_x,
57 double bl_radius_y) {
59 auto res = fml::MakeRefCounted<RSuperellipse>(
60 BuildBounds(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right),
61 SafeNarrow(bottom)),
62 BuildRadii(SafeNarrow(tl_radius_x), SafeNarrow(tl_radius_y),
63 SafeNarrow(tr_radius_x), SafeNarrow(tr_radius_y),
64 SafeNarrow(br_radius_x), SafeNarrow(br_radius_y),
65 SafeNarrow(bl_radius_x), SafeNarrow(bl_radius_y)));
66 res->AssociateWithDartWrapper(wrapper);
67}
68
69RSuperellipse::RSuperellipse(flutter::DlRect bounds,
71 : bounds_(bounds), radii_(radii) {}
72
74
78
82
83bool RSuperellipse::contains(double x, double y) {
85 if (!bounds_.Contains(point)) {
86 return false;
87 }
88 return param().Contains(point);
89}
90
91} // namespace flutter
flutter::DlRoundSuperellipse rsuperellipse() const
static void Create(Dart_Handle wrapper, double left, double top, double right, double bottom, double tl_radius_x, double tl_radius_y, double tr_radius_x, double tr_radius_y, double br_radius_x, double br_radius_y, double bl_radius_x, double bl_radius_y)
impeller::RoundSuperellipseParam param() const
bool contains(double x, double y)
static void ThrowIfUIOperationsProhibited()
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
int32_t x
double y
impeller::Size DlSize
static float SafeNarrow(double value)
static RoundSuperellipse MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
static RoundSuperellipseParam MakeBoundsRadii(const Rect &bounds, const RoundingRadii &radii)
bool Contains(const Point &point) const
constexpr bool Contains(const TPoint< Type > &p) const
Returns true iff the provided point |p| is inside the half-open interior of this rectangle.
Definition rect.h:231
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition rect.h:398
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129