roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
smooth.h
Go to the documentation of this file.
1#pragma once
2
3#include "roo_display.h"
6
7namespace roo_display {
8
9/// Line ending style for smooth shapes.
14
15/// Represents one of the supported smooth shapes.
16///
17/// A common representation is used because shapes overlap (e.g., many reduce
18/// to a filled circle).
19class SmoothShape;
20
21/// Create a 1-pixel-wide anti-aliased line.
22SmoothShape SmoothLine(FpPoint a, FpPoint b, Color color);
23
24/// Create a line with width and ending style.
25SmoothShape SmoothThickLine(FpPoint a, FpPoint b, float width, Color color,
26 EndingStyle ending_style = ENDING_ROUNDED);
27
28/// Create a wedged line with different start/end widths.
29SmoothShape SmoothWedgedLine(FpPoint a, float width_a, FpPoint b, float width_b,
30 Color color,
31 EndingStyle ending_style = ENDING_ROUNDED);
32
33/// Create an outlined round-rect.
34SmoothShape SmoothRoundRect(float x0, float y0, float x1, float y1,
35 float radius, Color color,
36 Color interior_color = color::Transparent);
37
38/// Create an outlined round-rect with thickness.
39SmoothShape SmoothThickRoundRect(float x0, float y0, float x1, float y1,
40 float radius, float thickness, Color color,
41 Color interior_color = color::Transparent);
42
43/// Create a filled round-rect.
44SmoothShape SmoothFilledRoundRect(float x0, float y0, float x1, float y1,
45 float radius, Color color);
46
47// SmoothShape SmoothFilledRect(float x0, float y0, float x1, float y1,
48// Color color);
49
50/// Create a circle (optionally with interior color).
51SmoothShape SmoothCircle(FpPoint center, float radius, Color color,
52 Color interior_color = color::Transparent);
53
54/// Create a circle with thickness (ring).
55SmoothShape SmoothThickCircle(FpPoint center, float radius, float thickness,
56 Color color,
57 Color interior_color = color::Transparent);
58
59/// Create a filled circle.
60SmoothShape SmoothFilledCircle(FpPoint center, float radius, Color color);
61
62/// Create a rotated filled rectangle.
63SmoothShape SmoothRotatedFilledRect(FpPoint center, float width, float height,
64 float angle, Color color);
65
66/// Create a 1-pixel-wide arc.
67SmoothShape SmoothArc(FpPoint center, float radius, float angle_start,
68 float angle_end, Color color);
69
70/// Create an arc with thickness.
71SmoothShape SmoothThickArc(FpPoint center, float radius, float thickness,
72 float angle_start, float angle_end, Color color,
73 EndingStyle ending_style = ENDING_ROUNDED);
74
75/// Create a pie slice.
76SmoothShape SmoothPie(FpPoint center, float radius, float angle_start,
77 float angle_end, Color color);
78
79/// Create an arc with background and interior colors.
81 FpPoint center, float radius, float thickness, float angle_start,
82 float angle_end, Color active_color, Color inactive_color,
83 Color interior_color, EndingStyle ending_style = ENDING_ROUNDED);
84
85/// Create a filled triangle.
86SmoothShape SmoothFilledTriangle(FpPoint a, FpPoint b, FpPoint c, Color color);
87
88// Implementation details follow.
89
90/// Smooth (anti-aliased) shape rasterizable.
91class SmoothShape : public Rasterizable {
92 public:
93 struct Wedge {
94 float ax;
95 float ay;
96 float bx;
97 float by;
98 float ar;
99 float br;
102 };
103
104 struct RoundRect {
105 float x0;
106 float y0;
107 float x1;
108 float y1;
109 float ro;
110 float ri;
111 float ro_sq_adj; // ro * ro + 0.25f
112 float ri_sq_adj; // ri * ri + 0.25f
118 };
119
120 struct Arc {
121 float xc;
122 float yc;
123 float ro;
124 float ri; // ro - width
125 float rm; // (ro - ri) / 2
126 float ro_sq_adj; // ro * ro + 0.25f
127 float ri_sq_adj; // ri * ri + 0.25f
128 float rm_sq_adj; // rm * rm + 0.25f
134 // Rectangle fully within the inner circle.
136 // X-slope at angle start: (x_ro - x_rc) / |ro - rc|.
138 // Y-slope at angle start: (y_ro - y_rc) / |ro - rc|.
140 // Endpoint of the cut line at the start angle, mid-band, relative to the
141 // circle center.
144 // X-slope at angle end: (x_ro - x_rc) / |ro - rc|.
146 // Y-slope at angle end: (y_ro - y_rc) / |ro - rc|.
148 // Endpoint of the cut line at the end angle, mid-band, relative to the
149 // circle center.
150 float end_x_rc;
151 float end_y_rc;
160
161 // Lower 4 bits: when a bit is set, it means that the arc includes the
162 // entire given quadrant.
164 };
165
166 struct Triangle {
167 float x1;
168 float y1;
169 float dx12;
170 float dy12;
171 float x2;
172 float y2;
173 float dx23;
174 float dy23;
175 float x3;
176 float y3;
177 float dx31;
178 float dy31;
180 };
181
182 struct Pixel {
184 };
185
186 SmoothShape();
187
188 Box extents() const override { return extents_; }
189
190 void readColors(const int16_t* x, const int16_t* y, uint32_t count,
191 Color* result) const override;
192
193 bool readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax,
194 Color* result) const override;
195
196 private:
198 float width_b, Color color,
200
201 friend SmoothShape SmoothThickRoundRect(float x0, float y0, float x1,
202 float y1, float radius,
203 float thickness, Color color,
204 Color interior_color);
205
207 float height, float angle,
208 Color color);
209
211 FpPoint center, float radius, float thickness, float angle_start,
212 float angle_end, Color active_color, Color inactive_color,
213 Color interior_color, EndingStyle ending_style, bool trim_to_active);
214
216 Color color);
217
218 void drawTo(const Surface& s) const override;
219
220 enum Kind {
221 EMPTY = 0,
222 WEDGE = 1,
223 ROUND_RECT = 2,
224 ARC = 3,
225 TRIANGLE = 4,
226 PIXEL = 5
227 };
228
229 SmoothShape(Box extents, Wedge wedge);
230 SmoothShape(Box extents, RoundRect round_rect);
231 SmoothShape(Box extents, Arc arc);
232 SmoothShape(Box extents, Triangle triangle);
233 SmoothShape(int16_t x, int16_t y, Pixel pixel);
234
235 Kind kind_;
236 Box extents_;
237 union {
243 };
244};
245
246} // namespace roo_display
Axis-aligned integer rectangle.
Definition box.h:12
ARGB8888 color stored as a 32-bit unsigned integer.
Definition color.h:16
Drawable that can provide a color for any point within its extents.
Smooth (anti-aliased) shape rasterizable.
Definition smooth.h:91
friend SmoothShape SmoothThickArcImpl(FpPoint center, float radius, float thickness, float angle_start, float angle_end, Color active_color, Color inactive_color, Color interior_color, EndingStyle ending_style, bool trim_to_active)
Definition smooth.cpp:214
void readColors(const int16_t *x, const int16_t *y, uint32_t count, Color *result) const override
Read colors for the given points.
Definition smooth.cpp:1854
friend SmoothShape SmoothFilledTriangle(FpPoint a, FpPoint b, FpPoint c, Color color)
Create a filled triangle.
Definition smooth.cpp:454
friend SmoothShape SmoothRotatedFilledRect(FpPoint center, float width, float height, float angle, Color color)
Create a rotated filled rectangle.
Definition smooth.cpp:91
friend SmoothShape SmoothWedgedLine(FpPoint a, float width_a, FpPoint b, float width_b, Color color, EndingStyle ending_style)
Create a wedged line with different start/end widths.
Definition smooth.cpp:38
Box extents() const override
Return the bounding box encompassing all pixels that need to be drawn.
Definition smooth.h:188
friend SmoothShape SmoothThickRoundRect(float x0, float y0, float x1, float y1, float radius, float thickness, Color color, Color interior_color)
Create an outlined round-rect with thickness.
Definition smooth.cpp:104
bool readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax, Color *result) const override
Read colors for a rectangle.
Definition smooth.cpp:1888
Low-level handle used to draw to an underlying device.
Definition drawable.h:60
Defines 140 opaque HTML named colors.
SmoothShape SmoothFilledCircle(FpPoint center, float radius, Color color)
Create a filled circle.
Definition smooth.cpp:196
SmoothShape SmoothThickArc(FpPoint center, float radius, float thickness, float angle_start, float angle_end, Color color, EndingStyle ending_style)
Create an arc with thickness.
Definition smooth.cpp:428
SmoothShape SmoothFilledTriangle(FpPoint a, FpPoint b, FpPoint c, Color color)
Create a filled triangle.
Definition smooth.cpp:454
SmoothShape SmoothRotatedFilledRect(FpPoint center, float width, float height, float angle, Color color)
Create a rotated filled rectangle.
Definition smooth.cpp:91
SmoothShape SmoothThickCircle(FpPoint center, float radius, float thickness, Color color, Color interior_color)
Create a circle with thickness (ring).
Definition smooth.cpp:184
SmoothShape SmoothRoundRect(float x0, float y0, float x1, float y1, float radius, Color color, Color interior_color)
Create an outlined round-rect.
Definition smooth.cpp:169
SmoothShape SmoothCircle(FpPoint center, float radius, Color color, Color interior_color)
Create a circle (optionally with interior color).
Definition smooth.cpp:191
EndingStyle
Line ending style for smooth shapes.
Definition smooth.h:10
@ ENDING_FLAT
Definition smooth.h:12
@ ENDING_ROUNDED
Definition smooth.h:11
SmoothShape SmoothThickArcWithBackground(FpPoint center, float radius, float thickness, float angle_start, float angle_end, Color active_color, Color inactive_color, Color interior_color, EndingStyle ending_style)
Create an arc with background and interior colors.
Definition smooth.cpp:443
SmoothShape SmoothWedgedLine(FpPoint a, float width_a, FpPoint b, float width_b, Color color, EndingStyle ending_style)
Create a wedged line with different start/end widths.
Definition smooth.cpp:38
SmoothShape SmoothLine(FpPoint a, FpPoint b, Color color)
Create a 1-pixel-wide anti-aliased line.
Definition smooth.cpp:87
SmoothShape SmoothPie(FpPoint center, float radius, float angle_start, float angle_end, Color color)
Create a pie slice.
Definition smooth.cpp:436
SmoothShape SmoothFilledRoundRect(float x0, float y0, float x1, float y1, float radius, Color color)
Create a filled round-rect.
Definition smooth.cpp:174
SmoothShape SmoothThickRoundRect(float x0, float y0, float x1, float y1, float radius, float thickness, Color color, Color interior_color)
Create an outlined round-rect with thickness.
Definition smooth.cpp:104
SmoothShape SmoothArc(FpPoint center, float radius, float angle_start, float angle_end, Color color)
Create a 1-pixel-wide arc.
Definition smooth.cpp:422
SmoothShape SmoothThickLine(FpPoint a, FpPoint b, float width, Color color, EndingStyle ending_style)
Create a line with width and ending style.
Definition smooth.cpp:82
Public API surface for roo_display display, touch, and drawing utilities.
Floating-point point.
Definition point.h:12