Flutter Impeller
uber_sdf_parameters.h
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 
5 #ifndef FLUTTER_IMPELLER_ENTITY_CONTENTS_UBER_SDF_PARAMETERS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_UBER_SDF_PARAMETERS_H_
7 
8 #include <optional>
9 
12 #include "impeller/geometry/rect.h"
17 
18 namespace impeller {
19 
20 /// Parameters for rendering shapes using the UberSDF shader.
22  /// The amount by which the UberSDF shader fades the edge of the drawn shapes,
23  /// in pixels.
24  static constexpr Scalar kAntialiasPixels = 1.0f;
25 
26  /// The type of primitive shape.
27  enum class Type {
28  kCircle,
29  kRect,
30  kOval,
33  };
34 
35  /// Creates UberSDFParameters for a rectangle.
37  const Rect& rect,
38  std::optional<StrokeParameters> stroke);
39 
40  /// Creates UberSDFParameters for a circle.
42  const Point& center,
43  Scalar radius,
44  std::optional<StrokeParameters> stroke);
45 
46  /// Creates UberSDFParameters for an Oval.
48  const Rect& bounds,
49  std::optional<StrokeParameters> stroke);
50 
51  /// Creates UberSDFParameters for a rounded rectangle.
53  Color color,
54  const Rect& rect,
55  const RoundingRadii& radii,
56  std::optional<StrokeParameters> stroke);
57 
58  /// Creates UberSDFParameters for an asymmetric round superellipse.
60  Color color,
61  const Rect& bounds,
62  const RoundSuperellipseParam& round_superellipse_params,
63  std::optional<StrokeParameters> stroke);
64 
65  /// The type of shape to render.
67 
68  /// The color used for filling or stroking the shape.
70 
71  /// The center point of the shape in local coordinates.
73 
74  /// For a rectangle, this is half the width and height.
75  /// For a circle, this is the radius in both dimensions.
76  /// For an oval, this is half the width and height of the bounds.
78 
79  /// The stroke parameters. If std::nullopt, the shape is filled.
80  std::optional<StrokeParameters> stroke;
81 
82  /// The degree (n) of the superellipse curve for the top and right octants.
84 
85  /// The semi-axis length of the superellipse curve for the top and right
86  /// octants.
88 
89  /// The angular span of the circular cap for the top and right octants.
91 
92  /// The geometric offset 'c' used to connect the two octants of each quadrant.
94 
95  /// The circular cap center for the top octant of each
96  /// quadrant.
98 
99  /// The circular cap center for the right octant of each
100  /// quadrant.
102 
103  /// The scaling factors used to transform normalized superellipses to their
104  /// true size.
106 
107  /// Rounding radii for standard rounded rects and corner radii for circular
108  /// caps of superellipses for top and right octants.
110 };
111 
112 } // namespace impeller
113 
114 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_UBER_SDF_PARAMETERS_H_
float Scalar
Definition: scalar.h:19
Parameters for rendering shapes using the UberSDF shader.
Color color
The color used for filling or stroking the shape.
float octant_offset_c
The geometric offset 'c' used to connect the two octants of each quadrant.
Point superellipse_degree
The degree (n) of the superellipse curve for the top and right octants.
static UberSDFParameters MakeCircle(Color color, const Point &center, Scalar radius, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for a circle.
Point angle_span
The angular span of the circular cap for the top and right octants.
static UberSDFParameters MakeOval(Color color, const Rect &bounds, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for an Oval.
Type type
The type of shape to render.
Point center
The center point of the shape in local coordinates.
static UberSDFParameters MakeRoundedRect(Color color, const Rect &rect, const RoundingRadii &radii, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for a rounded rectangle.
Type
The type of primitive shape.
static constexpr Scalar kAntialiasPixels
static UberSDFParameters MakeRoundedSuperellipse(Color color, const Rect &bounds, const RoundSuperellipseParam &round_superellipse_params, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for an asymmetric round superellipse.
std::optional< StrokeParameters > stroke
The stroke parameters. If std::nullopt, the shape is filled.
static UberSDFParameters MakeRect(Color color, const Rect &rect, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for a rectangle.