7inline uint16_t isqrt32(uint32_t x) {
8 uint32_t
r = 0, r2 = 0;
9 for (
int p = 15; p >= 0; --p) {
10 uint32_t tr2 = r2 + (
r << (p + 1)) + ((uint32_t)1u << (p + p));
13 r |= ((uint32_t)1u << p);
22inline uint16_t calcShadowDiffusion(
const RoundRectShadow::Spec& spec,
23 int16_t x, int16_t y) {
37 if (x >= spec.w - spec.radius) {
38 x += spec.radius - spec.w + 1;
42 if (y >= spec.h - spec.radius) {
43 y += spec.radius - spec.h + 1;
48 if (y > 0)
return 16 * y;
51 if (y <= 0)
return 16 * x;
53 return isqrt32(256 * (x * x + y * y));
58inline uint8_t calcShadowAlpha(
const RoundRectShadow::Spec& spec, int16_t x,
60 uint16_t d = calcShadowDiffusion(spec, x, y);
61 if (d > spec.border * 16) {
62 if (d > spec.radius * 16) {
65 return spec.alpha_start -
66 ((uint32_t)((d - spec.border * 16) * spec.alpha_step) / 256 / 16);
69 return spec.alpha_start;
89 Box(spec_.
x, spec_.
y, spec_.
x + spec_.
w - 1, spec_.
y + spec_.
h - 1);
102 if (xMin >= object_extents_.
xMin() + corner_radius_ &&
103 xMax <= object_extents_.
xMax() - corner_radius_) {
104 if (yMin >= object_extents_.
yMin() && yMax <= object_extents_.
yMax()) {
111 for (
int16_t y = yMin; y <= yMax; ++y) {
113 for (
int16_t x = xMin; x <= xMax; ++x) {
118 }
else if (yMin >= object_extents_.
yMin() + corner_radius_ &&
119 yMax <= object_extents_.
yMax() - corner_radius_) {
122 for (
int16_t x = xMin; x <= xMax; ++x) {
126 for (
int16_t y = yMin; y <= yMax; ++y) {
133 for (
int16_t y = yMin; y <= yMax; ++y) {
134 for (
int16_t x = xMin; x <= xMax; ++x) {
Axis-aligned integer rectangle.
int16_t width() const
Width in pixels (inclusive coordinates).
int16_t xMin() const
Minimum x (inclusive).
int16_t xMax() const
Maximum x (inclusive).
int16_t height() const
Height in pixels (inclusive coordinates).
int16_t yMax() const
Maximum y (inclusive).
int16_t yMin() const
Minimum y (inclusive).
ARGB8888 color stored as a 32-bit unsigned integer.
constexpr uint8_t a() const
Alpha channel.
constexpr Color withA(uint8_t a) const
Return a copy with the specified alpha channel.
void readColors(const int16_t *x, const int16_t *y, uint32_t count, Color *result) const override
Read colors for the given points.
Box extents() const override
Return the bounding box encompassing all pixels that need to be drawn.
bool readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax, roo_display::Color *result) const override
Read colors for a rectangle.
RoundRectShadow(roo_display::Box extents, Color color, uint8_t blur_radius, uint8_t dx, uint8_t dy, uint8_t corner_radius)
Construct a rounded-rect shadow.
Defines 140 opaque HTML named colors.