Skip to content

Commit fdb9cc7

Browse files
authored
Add default constructors for Color, Rect, Point, and Size. (#539)
1 parent 89f9a2c commit fdb9cc7

File tree

88 files changed

+299
-236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+299
-236
lines changed

drawers/src/SimpleText.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void SimpleText::onDraw(tgfx::Canvas* canvas, const drawers::AppHost* host) {
3434
auto bounds = textBlob->getBounds();
3535
auto textScale = screenWidth / bounds.width();
3636
tgfx::Point textStart = {(width - bounds.width()) / 2, height / 2 - bounds.bottom * 1.2f};
37-
auto matrix = tgfx::Matrix::I();
37+
tgfx::Matrix matrix = {};
3838
matrix.setScale(textScale, textScale, width / 2, height / 2);
3939
auto oldMatrix = canvas->getMatrix();
4040
canvas->concat(matrix);

include/tgfx/core/Color.h

+36-20
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,6 @@ namespace tgfx {
2929
* order.
3030
*/
3131
struct Color {
32-
/**
33-
* Red component.
34-
*/
35-
float red;
36-
37-
/**
38-
* Green component.
39-
*/
40-
float green;
41-
42-
/**
43-
* Blue component.
44-
*/
45-
float blue;
46-
47-
/**
48-
* Alpha component.
49-
*/
50-
float alpha;
51-
5232
/**
5333
* Returns a fully transparent Color.
5434
*/
@@ -84,6 +64,42 @@ struct Color {
8464
*/
8565
static Color FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
8666

67+
/**
68+
* Constructs an opaque white Color.
69+
*/
70+
constexpr Color() : red(1.0f), green(1.0f), blue(1.0f), alpha(1.0f) {
71+
}
72+
73+
/**
74+
* Constructs a Color with the specified red, green, blue, and alpha values.
75+
* @param r red component
76+
* @param g green component
77+
* @param b blue component
78+
* @param a alpha component
79+
*/
80+
constexpr Color(float r, float g, float b, float a = 1.0f) : red(r), green(g), blue(b), alpha(a) {
81+
}
82+
83+
/**
84+
* Red component.
85+
*/
86+
float red;
87+
88+
/**
89+
* Green component.
90+
*/
91+
float green;
92+
93+
/**
94+
* Blue component.
95+
*/
96+
float blue;
97+
98+
/**
99+
* Alpha component.
100+
*/
101+
float alpha;
102+
87103
/**
88104
* Compares Color with other, and returns true if all components are equal.
89105
*/

include/tgfx/core/Fill.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ class Fill {
4242
}
4343

4444
/**
45-
* The input color, unpremultiplied, as four floating point values.
45+
* The input color, unpremultiplied, as four floating point values. The default value is opaque
46+
* white.
4647
*/
47-
Color color = Color::White();
48+
Color color = {};
4849

4950
/**
5051
* The blend mode used to combine the fill with the destination pixels.

include/tgfx/core/ImageReader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ImageReader {
9393
uint64_t bufferVersion = 0;
9494
uint64_t textureVersion = 0;
9595
bool hasPendingChanges = true;
96-
Rect dirtyBounds = Rect::MakeEmpty();
96+
Rect dirtyBounds = {};
9797

9898
static std::shared_ptr<ImageReader> MakeFrom(std::shared_ptr<ImageStream> imageStream);
9999

include/tgfx/core/Mask.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class Mask {
138138
const Matrix& matrix, bool antiAlias);
139139

140140
private:
141-
Matrix matrix = Matrix::I();
141+
Matrix matrix = {};
142142
bool antiAlias = true;
143143

144144
bool fillText(const GlyphRunList* glyphRunList, const Stroke* stroke = nullptr);

include/tgfx/core/Point.h

+21-9
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@ namespace tgfx {
2828
* Point holds two 32-bit floating point coordinates.
2929
*/
3030
struct Point {
31-
/**
32-
* x-axis value.
33-
*/
34-
float x;
35-
/**
36-
* y-axis value.
37-
*/
38-
float y;
39-
4031
/**
4132
* Creates a Point set to (0, 0).
4233
*/
@@ -59,6 +50,27 @@ struct Point {
5950
return {static_cast<float>(x), static_cast<float>(y)};
6051
}
6152

53+
/**
54+
* Constructs a Point set to (0, 0).
55+
*/
56+
constexpr Point() : x(0), y(0) {
57+
}
58+
59+
/**
60+
* Constructs a Point set to (x, y).
61+
*/
62+
constexpr Point(float x, float y) : x(x), y(y) {
63+
}
64+
65+
/**
66+
* x-axis value.
67+
*/
68+
float x;
69+
/**
70+
* y-axis value.
71+
*/
72+
float y;
73+
6274
/**
6375
* Returns true if x and y are both zero.
6476
*/

include/tgfx/core/RRect.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ namespace tgfx {
2626
* Round Rect.
2727
*/
2828
struct RRect {
29-
Rect rect = Rect::MakeEmpty();
30-
Point radii = Point::Zero();
29+
Rect rect = {};
30+
Point radii = {};
3131

3232
/**
3333
* Returns true if the bounds are a simple rectangle.

include/tgfx/core/Rect.h

+35-18
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,6 @@ namespace tgfx {
3030
* considered empty.
3131
*/
3232
struct Rect {
33-
/**
34-
* smaller x-axis bounds.
35-
*/
36-
float left;
37-
/**
38-
* smaller y-axis bounds.
39-
*/
40-
float top;
41-
/**
42-
* larger x-axis bounds.
43-
*/
44-
float right;
45-
/**
46-
* larger y-axis bounds.
47-
*/
48-
float bottom;
49-
5033
/**
5134
* Returns constructed Rect set to (0, 0, 0, 0).
5235
*/
@@ -111,6 +94,40 @@ struct Rect {
11194
return Rect{0, 0, size.width, size.height};
11295
}
11396

97+
/**
98+
* Constructs an empty Rect.
99+
*/
100+
constexpr Rect() : left(0), top(0), right(0), bottom(0) {
101+
}
102+
103+
/**
104+
* Constructs a Rect with the given left, top, right, and bottom values.
105+
* @param left left edge of the rectangle
106+
* @param top top edge of the rectangle
107+
* @param right right edge of the rectangle
108+
* @param bottom bottom edge of the rectangle
109+
*/
110+
constexpr Rect(float left, float top, float right, float bottom)
111+
: left(left), top(top), right(right), bottom(bottom) {
112+
}
113+
114+
/**
115+
* smaller x-axis bounds.
116+
*/
117+
float left;
118+
/**
119+
* smaller y-axis bounds.
120+
*/
121+
float top;
122+
/**
123+
* larger x-axis bounds.
124+
*/
125+
float right;
126+
/**
127+
* larger y-axis bounds.
128+
*/
129+
float bottom;
130+
114131
/**
115132
* Returns true if left is equal to or greater than right, or if top is equal to or greater
116133
* than bottom. Call sort() to reverse rectangles with negative width() or height().
@@ -209,7 +226,7 @@ struct Rect {
209226
* Sets Rect to (0, 0, 0, 0).
210227
*/
211228
void setEmpty() {
212-
*this = MakeEmpty();
229+
left = top = right = bottom = 0;
213230
}
214231

215232
/**

include/tgfx/core/Size.h

+44-20
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ namespace tgfx {
2525
* ISize holds two 32-bit integer dimensions.
2626
*/
2727
struct ISize {
28-
/**
29-
* Span on the x-axis.
30-
*/
31-
int width;
32-
33-
/**
34-
* Span on the y-axis.
35-
*/
36-
int height;
37-
3828
static ISize Make(int w, int h) {
3929
return {w, h};
4030
}
@@ -47,6 +37,28 @@ struct ISize {
4737
return {0, 0};
4838
}
4939

40+
/**
41+
* Constructs an empty ISize.
42+
*/
43+
constexpr ISize() : width(0), height(0) {
44+
}
45+
46+
/**
47+
* Constructs an ISize with the specified width and height.
48+
*/
49+
constexpr ISize(int w, int h) : width(w), height(h) {
50+
}
51+
52+
/**
53+
* Span on the x-axis.
54+
*/
55+
int width;
56+
57+
/**
58+
* Span on the y-axis.
59+
*/
60+
int height;
61+
5062
void set(int w, int h) {
5163
*this = ISize{w, h};
5264
}
@@ -91,16 +103,6 @@ struct ISize {
91103
* Size holds two 32-bit floating dimensions.
92104
*/
93105
struct Size {
94-
/**
95-
* Span on the x-axis.
96-
*/
97-
float width;
98-
99-
/**
100-
* Span on the y-axis.
101-
*/
102-
float height;
103-
104106
static Size Make(float w, float h) {
105107
return {w, h};
106108
}
@@ -117,6 +119,28 @@ struct Size {
117119
return {0, 0};
118120
}
119121

122+
/**
123+
* Constructs an empty Size.
124+
*/
125+
constexpr Size() : width(0), height(0) {
126+
}
127+
128+
/**
129+
* Constructs a Size with the specified width and height.
130+
*/
131+
constexpr Size(float w, float h) : width(w), height(h) {
132+
}
133+
134+
/**
135+
* Span on the x-axis.
136+
*/
137+
float width;
138+
139+
/**
140+
* Span on the y-axis.
141+
*/
142+
float height;
143+
120144
void set(float w, float h) {
121145
*this = Size{w, h};
122146
}

include/tgfx/layers/Gradient.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ class LinearGradient : public Gradient {
178178
std::shared_ptr<Shader> onGetShader() const override;
179179

180180
private:
181-
Point _startPoint = Point::Zero();
182-
Point _endPoint = Point::Zero();
181+
Point _startPoint = {};
182+
Point _endPoint = {};
183183

184184
LinearGradient(const Point& startPoint, const Point& endPoint, const std::vector<Color>& colors,
185185
const std::vector<float>& positions)
@@ -228,7 +228,7 @@ class RadialGradient : public Gradient {
228228
std::shared_ptr<Shader> onGetShader() const override;
229229

230230
private:
231-
Point _center = Point::Zero();
231+
Point _center = {};
232232
float _radius = 0;
233233

234234
RadialGradient(const Point& center, float radius, const std::vector<Color>& colors,
@@ -290,7 +290,7 @@ class ConicGradient : public Gradient {
290290
std::shared_ptr<Shader> onGetShader() const override;
291291

292292
private:
293-
Point _center = Point::Zero();
293+
Point _center = {};
294294
float _startAngle = 0;
295295
float _endAngle = 0;
296296

@@ -341,7 +341,7 @@ class DiamondGradient : public Gradient {
341341
std::shared_ptr<Shader> onGetShader() const override;
342342

343343
private:
344-
Point _center = Point::Zero();
344+
Point _center = {};
345345
float _halfDiagonal = 0;
346346

347347
DiamondGradient(const Point& center, float halfDiagonal, const std::vector<Color>& colors,

include/tgfx/layers/Layer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ class Layer {
603603
} bitFields = {};
604604
std::string _name;
605605
float _alpha = 1.0f;
606-
Matrix _matrix = Matrix::I();
606+
Matrix _matrix = {};
607607
float _rasterizationScale = 1.0f;
608608
std::vector<std::shared_ptr<LayerFilter>> _filters = {};
609609
std::shared_ptr<Layer> _mask = nullptr;

include/tgfx/layers/ShapeStyle.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ShapeStyle : public LayerProperty {
7878
private:
7979
float _alpha = 1.0f;
8080
BlendMode _blendMode = BlendMode::SrcOver;
81-
Matrix _matrix = Matrix::I();
81+
Matrix _matrix = {};
8282

8383
friend class ShapeLayer;
8484
};

include/tgfx/layers/SolidLayer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class SolidLayer : public Layer {
103103
std::unique_ptr<LayerContent> onUpdateContent() override;
104104

105105
private:
106-
Color _color = Color::White();
106+
Color _color = {};
107107
float _width = 0;
108108
float _height = 0;
109109
float _radiusX = 0;

0 commit comments

Comments
 (0)