Skip to content

Commit 6e52efd

Browse files
author
botamochi6277
committed
Add rect eyebrow
1 parent 049b6df commit 6e52efd

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/Eyebrows.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ void BaseEyebrow::update(M5Canvas *canvas, BoundingRect rect,
2323
ctx->getColorDepth() == 1 ? ERACER_COLOR : cp->get(COLOR_BACKGROUND);
2424
center_x_ = rect.getCenterX();
2525
center_y_ = rect.getCenterY();
26+
expression_ = ctx->getExpression();
2627
}
2728

2829
void EllipseEyebrow::draw(M5Canvas *canvas, BoundingRect rect,
2930
DrawContext *ctx) {
3031
this->update(canvas, rect, ctx);
32+
if (width_ == 0 || height_ == 0) {
33+
return; // draw nothing
34+
}
3135

3236
canvas->fillEllipse(center_x_, center_y_, this->width_ / 2,
3337
this->height_ / 2, primary_color_);
@@ -43,4 +47,22 @@ void BowEyebrow::draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {
4347
angle0, angle0 + stroke_angle, primary_color_);
4448
}
4549

50+
void RectEyebrow::draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {
51+
this->update(canvas, rect, ctx);
52+
53+
if (width_ == 0 || height_ == 0) {
54+
return;
55+
}
56+
float angle = 0.0f;
57+
if (expression_ == Expression::Angry) {
58+
angle = is_left_ ? -M_PI / 6.0f : M_PI / 6.0f;
59+
}
60+
if (expression_ == Expression::Sad) {
61+
angle = is_left_ ? M_PI / 6.0f : -M_PI / 6.0f;
62+
}
63+
64+
fillRotatedRect(canvas, center_x_, center_y_, width_, height_, angle,
65+
primary_color_);
66+
}
67+
4668
} // namespace m5avatar

src/Eyebrows.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ class BowEyebrow : public BaseEyebrow {
5151
void draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx);
5252
};
5353

54+
class RectEyebrow : public BaseEyebrow {
55+
public:
56+
using BaseEyebrow::BaseEyebrow;
57+
void draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx);
58+
};
59+
5460
} // namespace m5avatar
5561

5662
#endif

0 commit comments

Comments
 (0)