Skip to content

Commit 97b8564

Browse files
author
botamochi6277
committed
Add RectMouth
1 parent 9da9801 commit 97b8564

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/Mouths.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "Mouths.hpp"
22

3+
#ifndef _min
4+
#define _min(a, b) std::min(a, b)
5+
#endif
36
namespace m5avatar {
47

58
BaseMouth::BaseMouth() : BaseMouth(80, 80, 15, 30) {}
@@ -23,6 +26,16 @@ void BaseMouth::update(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {
2326
center_x_ = rect.getCenterX();
2427
center_y_ = rect.getCenterY();
2528
open_ratio_ = ctx->getMouthOpenRatio();
29+
breath_ = _min(1.0f, ctx->getBreath());
30+
}
31+
32+
void RectMouth::draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {
33+
this->update(canvas, rect, ctx); // update drawing cache
34+
int16_t h = min_height_ + (max_height_ - min_height_) * open_ratio_;
35+
int16_t w = min_width_ + (max_width_ - min_width_) * (1 - open_ratio_);
36+
int16_t top_left_x = rect.getLeft() - w / 2;
37+
int16_t top_left_y = rect.getTop() - h / 2 + breath_ * 2;
38+
canvas->fillRect(top_left_x, top_left_y, w, h, primary_color_);
2639
}
2740

2841
void OmegaMouth::draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx) {

src/Mouths.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class BaseMouth : public Drawable {
3232
uint16_t secondary_color_;
3333
uint16_t background_color_;
3434
float open_ratio_;
35+
float breath_;
3536
Expression expression_;
3637

3738
public:
@@ -42,6 +43,12 @@ class BaseMouth : public Drawable {
4243
void update(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx);
4344
};
4445

46+
class RectMouth : public BaseMouth {
47+
public:
48+
using BaseMouth::BaseMouth;
49+
void draw(M5Canvas *canvas, BoundingRect rect, DrawContext *ctx);
50+
};
51+
4552
class OmegaMouth : public BaseMouth {
4653
public:
4754
using BaseMouth::BaseMouth;

0 commit comments

Comments
 (0)