CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
linear_gradient_brush.h
1
2#pragma once
3
4#include <array>
5#include <tuple>
6
7#include "fwd.h"
8#include "drawing/brush.h"
9#include "drawing/color.h"
10#include "drawing/rectangle_f.h"
11#include "drawing/drawing2d/linear_gradient_mode.h"
12#include "drawing/drawing2d/matrix.h"
13#include "drawing/drawing2d/matrix_order.h"
14#include "drawing/drawing2d/wrap_mode.h"
15
16#include <cstdint>
17
18#ifdef ASPOSECPPLIB_BEING_BUILT
19#include <core/SkPoint.h>
20#include <core/SkColor.h>
21#include <core/SkScalar.h>
22#endif
23
25ASPOSECPP_3RD_PARTY_TYPEDEF(SkColor, std::uint32_t);
27ASPOSECPP_3RD_PARTY_CLASS(SkPaint);
29ASPOSECPP_3RD_PARTY_STRUCT(SkPoint);
31ASPOSECPP_3RD_PARTY_TYPEDEF(SkScalar, float);
32
33namespace System { namespace Drawing { namespace Drawing2D {
34
35namespace Detail {
37 typedef std::array<SkPoint, 2> SkPoints;
39 ASPOSECPP_3RD_PARTY_TYPE_HOLDER_HIDDEN_TYPE(SkPoints, SkPoints, 2*2*sizeof(float), float, SkPointsHolder);
40}
41
42class Blend;
43class ColorBlend;
44
49class ASPOSECPP_SHARED_CLASS LinearGradientBrush: public Brush
50{
52 RTTI_INFO(System::Drawing::Drawing2D::LinearGradientBrush, ::System::BaseTypesInfo<System::Drawing::Brush>);
53
54public:
60 ASPOSECPP_SHARED_API LinearGradientBrush(const PointF& point1, const PointF& point2, const Color& color1, const Color& color2);
66 ASPOSECPP_SHARED_API LinearGradientBrush(const Point& point1, const Point& point2, const Color& color1, const Color& color2);
72 ASPOSECPP_SHARED_API LinearGradientBrush(const RectangleF& rect, const Color& color1, const Color& color2, LinearGradientMode linearGradientMode);
78 ASPOSECPP_SHARED_API LinearGradientBrush(const Rectangle& rect, const Color& color1, const Color& color2, LinearGradientMode linearGradientMode);
85 ASPOSECPP_SHARED_API LinearGradientBrush(const RectangleF& rect, const Color& color1, const Color& color2, float angle, bool isAngleScaleable = false);
92 ASPOSECPP_SHARED_API LinearGradientBrush(const Rectangle& rect, const Color& color1, const Color& color2, float angle, bool isAngleScaleable = false);
93
95 ASPOSECPP_SHARED_API void ResetTransform();
99 ASPOSECPP_SHARED_API void MultiplyTransform(const SharedPtr<Matrix>& matrix, MatrixOrder order = MatrixOrder::Prepend);
103 ASPOSECPP_SHARED_API void RotateTransform(float angle, MatrixOrder order = MatrixOrder::Prepend);
108 ASPOSECPP_SHARED_API void ScaleTransform(float sx, float sy, MatrixOrder order = MatrixOrder::Prepend);
113 ASPOSECPP_SHARED_API void TranslateTransform(float dx, float dy, Drawing2D::MatrixOrder order = Drawing2D::MatrixOrder::Prepend);
114
116 ASPOSECPP_SHARED_API WrapMode get_WrapMode() const;
119 ASPOSECPP_SHARED_API void set_WrapMode(WrapMode value);
121 ASPOSECPP_SHARED_API SharedPtr<Blend> get_Blend() const;
124 ASPOSECPP_SHARED_API void set_Blend(const SharedPtr<Blend>& value);
125
127 ASPOSECPP_SHARED_API SharedPtr<ColorBlend> get_InterpolationColors() const;
130 ASPOSECPP_SHARED_API void set_InterpolationColors(const SharedPtr<ColorBlend>& value);
131
134 ASPOSECPP_SHARED_API SharedPtr<Matrix> get_Transform() const;
138 ASPOSECPP_SHARED_API void set_Transform(const SharedPtr<Matrix>& value);
139
142 ASPOSECPP_SHARED_API void SetSigmaBellShape(float focus, float scale = 1.0f);
143
145 ASPOSECPP_SHARED_API RectangleF get_Rectangle();
146
148 ASPOSECPP_SHARED_API bool get_GammaCorrection() const;
151 ASPOSECPP_SHARED_API void set_GammaCorrection(bool value);
152
154 ASPOSECPP_SHARED_API ArrayPtr<Color> get_LinearColors() const;
157 ASPOSECPP_SHARED_API void set_LinearColors(const ArrayPtr<Color>& value);
158
161 ASPOSECPP_SHARED_API void SetBlendTriangularShape(float focus, float scale = 1.0f);
164 ASPOSECPP_SHARED_API SharedPtr<Brush> Clone() override;
165
166protected:
171 ASPOSECPP_SHARED_API void Apply(SkPaint& paint, const SharedPtr<Drawing2D::Matrix>& matrix, bool apply_shift) override;
172
173private:
175 typedef std::tuple<Detail::SkPointsHolder, RectangleF, float, bool> GradientInnerData;
176
181 LinearGradientBrush(const GradientInnerData& data, const Color& color1, const Color& color2);
182
186 static GradientInnerData CalculateInnerData(const PointF& point1, const PointF& point2);
191 static GradientInnerData CalculateInnerData(const RectangleF& rect, float angle, bool isAngleScaleable);
192
193 static float GetAngleFromMode(LinearGradientMode mode);
194
196 void SetupInitialMatrix(bool isAngleScaleable);
197
198 void InterpolateColors();
199
200private:
202 const Detail::SkPointsHolder m_points;
204 const RectangleF m_rectangle;
206 const float m_angle;
207
208 SkColor m_color1;
209 SkColor m_color2;
210
212 std::vector<SkColor> m_colors;
213 std::vector<float> m_factors;
215 std::vector<SkScalar> m_positions;
216 bool m_interpolation_colors = false;
217
219 WrapMode m_wrap_mode = WrapMode::Tile;
221 SharedPtr<Drawing2D::Matrix> m_transform_matrix;
222
223 bool m_gamma_correction = false;
224};
225
226}}}
A base class for classes that represent fillers used to fill the interiors of graphical shapes....
Definition: brush.h:18
Represents a color. This type should be allocated on stack and passed to functions by value or by ref...
Definition: color.h:24
Represents a linear gradient brush. Objects of this class should only be allocated using System::Make...
Definition: linear_gradient_brush.h:50
LinearGradientBrush(const Rectangle &rect, const Color &color1, const Color &color2, float angle, bool isAngleScaleable=false)
Constructs a new instance of LinearGradientBrush.
void set_Blend(const SharedPtr< Blend > &value)
Sets a blend that specifies factors and positions of base colors for this brush.
void set_LinearColors(const ArrayPtr< Color > &value)
Sets starting and ending colors of this gradient.
LinearGradientBrush(const Point &point1, const Point &point2, const Color &color1, const Color &color2)
Constructs a new instance of LinearGradientBrush.
ArrayPtr< Color > get_LinearColors() const
Returns starting and ending colors of this gradient.
SharedPtr< Brush > Clone() override
Creates a copy of the current object.
void SetSigmaBellShape(float focus, float scale=1.0f)
NOT IMPLEMENTED.
SharedPtr< Matrix > get_Transform() const
Returns a copy of a Matrix object that specifies the geometrical transformations for the brush repres...
void MultiplyTransform(const SharedPtr< Matrix > &matrix, MatrixOrder order=MatrixOrder::Prepend)
Multiplies current object's transform matrix by the specified matrix.
void set_InterpolationColors(const SharedPtr< ColorBlend > &value)
Sets a ColorBlend object that defines a multicolor linear gradient.
LinearGradientBrush(const PointF &point1, const PointF &point2, const Color &color1, const Color &color2)
Constructs a new instance of LinearGradientBrush.
void set_WrapMode(WrapMode value)
Sets the wrap mode.
LinearGradientBrush(const RectangleF &rect, const Color &color1, const Color &color2, LinearGradientMode linearGradientMode)
Constructs a new instance of LinearGradientBrush.
void Apply(SkPaint &paint, const SharedPtr< Drawing2D::Matrix > &matrix, bool apply_shift) override
Sets the properties of the current brush on the specified SkPaint object.
bool get_GammaCorrection() const
Returns a value indicating that gamma correction is enabled for this brush.
RectangleF get_Rectangle()
Returns a bounding rectangle.
void set_GammaCorrection(bool value)
Sets gamma correction status for this brush.
LinearGradientBrush(const Rectangle &rect, const Color &color1, const Color &color2, LinearGradientMode linearGradientMode)
Constructs a new instance of LinearGradientBrush.
void SetBlendTriangularShape(float focus, float scale=1.0f)
NOT IMPLEMENTED.
void TranslateTransform(float dx, float dy, Drawing2D::MatrixOrder order=Drawing2D::MatrixOrder::Prepend)
Translates current object's transform matrix.
SharedPtr< Blend > get_Blend() const
Returns a blend that specifies factors and positions of base colors for this brush.
WrapMode get_WrapMode() const
Returns the wrap mode.
void ResetTransform()
Resets current object's transformation matrix.
void RotateTransform(float angle, MatrixOrder order=MatrixOrder::Prepend)
Rotates current object's transform matrix.
LinearGradientBrush(const RectangleF &rect, const Color &color1, const Color &color2, float angle, bool isAngleScaleable=false)
Constructs a new instance of LinearGradientBrush.
void set_Transform(const SharedPtr< Matrix > &value)
Sets a Matrix object that specifies the geometrical transformations for the brush represented by the ...
SharedPtr< ColorBlend > get_InterpolationColors() const
Returns a ColorBlend object that defines a multicolor linear gradient.
void ScaleTransform(float sx, float sy, MatrixOrder order=MatrixOrder::Prepend)
Scales current object's transform matrix.
Represents a pair of single-precision floating point X and Y coordinates of a point on a 2-dimensiona...
Definition: point_f.h:14
Represents a pair of integer X and Y coordinates of a point on a 2-dimensional plane....
Definition: point.h:15
Represents a rectangular area of an image defined as single-precision floating point X and Y coordina...
Definition: rectangle_f.h:15
Represents a rectangular area of an image defined as integer X and Y coordinates of its upper left co...
Definition: rectangle.h:19
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
LinearGradientMode
Represents a linear gradient direction.
Definition: linear_gradient_mode.h:10
MatrixOrder
Specifies the order of matrix transform operations.
Definition: matrix_order.h:7
@ Prepend
The new operation is applied before the old operation.
WrapMode
Specifies how a texture or a gradient is tiled when it is smaller than the area being filled.
Definition: wrap_mode.h:9
@ Tile
Tiles the gradient or texture.
Definition: db_command.h:9