| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | /* Generated with cbindgen:0.26.0 */ |
| 4 | |
| 5 | #include <cstdarg> |
| 6 | #include <cstdint> |
| 7 | #include <cstdlib> |
| 8 | #include <ostream> |
| 9 | #include <new> |
| 10 | #include "slint_enums_internal.h" |
| 11 | |
| 12 | namespace slint { |
| 13 | namespace cbindgen_private { |
| 14 | namespace types { |
| 15 | |
| 16 | /// GradientStop describes a single color stop in a gradient. The colors between multiple |
| 17 | /// stops are interpolated. |
| 18 | struct GradientStop { |
| 19 | /// The color to draw at this stop. |
| 20 | Color color; |
| 21 | /// The position of this stop on the entire shape, as a normalized value between 0 and 1. |
| 22 | float position; |
| 23 | |
| 24 | bool operator==(const GradientStop& other) const { |
| 25 | return color == other.color && |
| 26 | position == other.position; |
| 27 | } |
| 28 | bool operator!=(const GradientStop& other) const { |
| 29 | return color != other.color || |
| 30 | position != other.position; |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | /// The LinearGradientBrush describes a way of filling a shape with different colors, which |
| 35 | /// are interpolated between different stops. The colors are aligned with a line that's rotated |
| 36 | /// by the LinearGradient's angle. |
| 37 | using LinearGradientBrush = SharedVector<GradientStop>; |
| 38 | |
| 39 | /// The RadialGradientBrush describes a way of filling a shape with a circular gradient |
| 40 | using RadialGradientBrush = SharedVector<GradientStop>; |
| 41 | |
| 42 | /// A brush is a data structure that is used to describe how |
| 43 | /// a shape, such as a rectangle, path or even text, shall be filled. |
| 44 | /// A brush can also be applied to the outline of a shape, that means |
| 45 | /// the fill of the outline itself. |
| 46 | struct Brush { |
| 47 | enum class Tag { |
| 48 | /// The color variant of brush is a plain color that is to be used for the fill. |
| 49 | SolidColor, |
| 50 | /// The linear gradient variant of a brush describes the gradient stops for a fill |
| 51 | /// where all color stops are along a line that's rotated by the specified angle. |
| 52 | LinearGradient, |
| 53 | /// The radial gradient variant of a brush describes a circle variant centered |
| 54 | /// in the middle |
| 55 | RadialGradient, |
| 56 | }; |
| 57 | |
| 58 | struct SolidColor_Body { |
| 59 | Color _0; |
| 60 | |
| 61 | bool operator==(const SolidColor_Body& other) const { |
| 62 | return _0 == other._0; |
| 63 | } |
| 64 | bool operator!=(const SolidColor_Body& other) const { |
| 65 | return _0 != other._0; |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | struct LinearGradient_Body { |
| 70 | LinearGradientBrush _0; |
| 71 | |
| 72 | bool operator==(const LinearGradient_Body& other) const { |
| 73 | return _0 == other._0; |
| 74 | } |
| 75 | bool operator!=(const LinearGradient_Body& other) const { |
| 76 | return _0 != other._0; |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | struct RadialGradient_Body { |
| 81 | RadialGradientBrush _0; |
| 82 | |
| 83 | bool operator==(const RadialGradient_Body& other) const { |
| 84 | return _0 == other._0; |
| 85 | } |
| 86 | bool operator!=(const RadialGradient_Body& other) const { |
| 87 | return _0 != other._0; |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | Tag tag; |
| 92 | union { |
| 93 | SolidColor_Body solid_color; |
| 94 | LinearGradient_Body linear_gradient; |
| 95 | RadialGradient_Body radial_gradient; |
| 96 | }; |
| 97 | |
| 98 | static Brush SolidColor(const Color &_0) { |
| 99 | Brush result; |
| 100 | ::new (&result.solid_color._0) (Color)(_0); |
| 101 | result.tag = Tag::SolidColor; |
| 102 | return result; |
| 103 | } |
| 104 | |
| 105 | bool IsSolidColor() const { |
| 106 | return tag == Tag::SolidColor; |
| 107 | } |
| 108 | |
| 109 | static Brush LinearGradient(const LinearGradientBrush &_0) { |
| 110 | Brush result; |
| 111 | ::new (&result.linear_gradient._0) (LinearGradientBrush)(_0); |
| 112 | result.tag = Tag::LinearGradient; |
| 113 | return result; |
| 114 | } |
| 115 | |
| 116 | bool IsLinearGradient() const { |
| 117 | return tag == Tag::LinearGradient; |
| 118 | } |
| 119 | |
| 120 | static Brush RadialGradient(const RadialGradientBrush &_0) { |
| 121 | Brush result; |
| 122 | ::new (&result.radial_gradient._0) (RadialGradientBrush)(_0); |
| 123 | result.tag = Tag::RadialGradient; |
| 124 | return result; |
| 125 | } |
| 126 | |
| 127 | bool IsRadialGradient() const { |
| 128 | return tag == Tag::RadialGradient; |
| 129 | } |
| 130 | |
| 131 | bool operator==(const Brush& other) const { |
| 132 | if (tag != other.tag) { |
| 133 | return false; |
| 134 | } |
| 135 | switch (tag) { |
| 136 | case Tag::SolidColor: return solid_color == other.solid_color; |
| 137 | case Tag::LinearGradient: return linear_gradient == other.linear_gradient; |
| 138 | case Tag::RadialGradient: return radial_gradient == other.radial_gradient; |
| 139 | |
| 140 | } |
| 141 | return true; |
| 142 | } |
| 143 | |
| 144 | bool operator!=(const Brush& other) const { |
| 145 | return !(*this == other); |
| 146 | } |
| 147 | |
| 148 | private: |
| 149 | Brush() { |
| 150 | |
| 151 | } |
| 152 | public: |
| 153 | |
| 154 | |
| 155 | ~Brush() { |
| 156 | switch (tag) { |
| 157 | case Tag::SolidColor: solid_color.~SolidColor_Body(); break; |
| 158 | case Tag::LinearGradient: linear_gradient.~LinearGradient_Body(); break; |
| 159 | case Tag::RadialGradient: radial_gradient.~RadialGradient_Body(); break; |
| 160 | |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | Brush(const Brush& other) |
| 165 | : tag(other.tag) { |
| 166 | switch (tag) { |
| 167 | case Tag::SolidColor: ::new (&solid_color) (SolidColor_Body)(other.solid_color); break; |
| 168 | case Tag::LinearGradient: ::new (&linear_gradient) (LinearGradient_Body)(other.linear_gradient); break; |
| 169 | case Tag::RadialGradient: ::new (&radial_gradient) (RadialGradient_Body)(other.radial_gradient); break; |
| 170 | |
| 171 | } |
| 172 | } |
| 173 | Brush& operator=(const Brush& other) { |
| 174 | if (this != &other) { |
| 175 | this->~Brush(); |
| 176 | new (this) Brush(other); |
| 177 | } |
| 178 | return *this; |
| 179 | } |
| 180 | }; |
| 181 | |
| 182 | } // namespace types |
| 183 | } // namespace cbindgen_private |
| 184 | } // namespace slint |
| 185 |
