Skip to content

Commit

Permalink
fix rotation and palette bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mongonta0716 committed Dec 31, 2022
2 parents 768df29 + 0166875 commit 52df9fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Face::Face(Drawable *mouth, BoundingRect *mouthPos, Drawable *eyeR,
eyeblowRPos{eyeblowRPos},
eyeblowLPos{eyeblowLPos},
boundingRect{new BoundingRect(0, 0, 320, 240)},
sprite{new M5Canvas(&M5.Lcd)} {}
sprite{new M5Canvas(&M5.Lcd)},
tmpSprite{new M5Canvas(&M5.Lcd)} {}

Face::~Face() {
delete mouth;
Expand Down Expand Up @@ -76,6 +77,8 @@ void Face::draw(DrawContext *ctx) {
ctx->getColorPalette()->get(COLOR_BACKGROUND));
if (ctx->getColorDepth() != 1) {
sprite->fillSprite(ctx->getColorPalette()->get(COLOR_BACKGROUND));
} else {
sprite->fillSprite(0);
}
float breath = _min(1.0f, ctx->getBreath());

Expand Down Expand Up @@ -111,9 +114,20 @@ void Face::draw(DrawContext *ctx) {
float rotation = ctx->getRotation();

if (scale != 1.0 || rotation != 0) {
sprite->pushRotateZoom(rotation, scale, scale);
tmpSprite->setColorDepth(ctx->getColorDepth());
tmpSprite->createSprite(M5.Display.width(), M5.Display.height());
tmpSprite->setBitmapColor(ctx->getColorPalette()->get(COLOR_PRIMARY),
ctx->getColorPalette()->get(COLOR_BACKGROUND));
if (ctx->getColorDepth() != 1) {
tmpSprite->fillSprite(ctx->getColorPalette()->get(COLOR_BACKGROUND));
} else {
tmpSprite->fillSprite(0);
}
sprite->pushRotateZoom(tmpSprite, rotation, scale, scale);
tmpSprite->pushSprite(&M5.Display, 0, 0);
tmpSprite->deleteSprite();
} else {
sprite->pushSprite(boundingRect->getLeft(), boundingRect->getTop());
sprite->pushSprite(&M5.Display, boundingRect->getLeft(), boundingRect->getTop());
}
sprite->deleteSprite();
}
Expand Down
1 change: 1 addition & 0 deletions src/Face.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Face {
BoundingRect *eyeblowLPos;
BoundingRect *boundingRect;
M5Canvas *sprite;
M5Canvas *tmpSprite;

public:
// constructor
Expand Down

0 comments on commit 52df9fc

Please sign in to comment.