m5stack-avatar
Loading...
Searching...
No Matches
BMPFace.h
1// Copyright (c) Shinya Ishikawa. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full
3// license information.
4
5#ifndef FACES_BMPFACE_H_
6#define FACES_BMPFACE_H_
7
8#include <M5Unified.h> // TODO(meganetaaan): include only the Sprite function not a whole library
9
10#include "../BoundingRect.h"
11#include "../DrawContext.h"
12#include "../Drawable.h"
13#include "../Face.h"
14#include "eye_small.h"
15
16namespace m5avatar
17{
18class BMPEye : public Drawable
19{
20 void draw(M5Canvas *spi, BoundingRect rect, DrawContext *ctx)
21 {
22 uint16_t color = ctx->getColorDepth() == 1 ? 1 : ctx->getColorPalette()->get(COLOR_PRIMARY);
23 uint16_t cx = rect.getCenterX();
24 uint16_t cy = rect.getCenterY();
25 float openRatio = ctx->getEyeOpenRatio();
26 Gaze g = ctx->getGaze();
27 uint32_t offsetX = g.getHorizontal() * 3;
28 uint32_t offsetY = g.getVertical() * 3;
29 if (openRatio == 0) {
30 // close
31 int x1 = cx - eye_small_width / 2 + offsetX;
32 int y1 = cy + offsetY;
33 int w = eye_small_width;
34 int h = 4;
35 spi->fillRect(x1, y1, w, h, color);
36 return;
37 }
38 spi->drawXBitmap(
39 cx - eye_small_width / 2,
40 cy - eye_small_height / 2,
41 eye_small, eye_small_width, eye_small_height, color);
42 }
43};
44
45class BMPFace : public Face
46{
47public:
48 BMPFace()
49 : Face(new Mouth(50, 90, 4, 60), new BoundingRect(148, 163),
50 new BMPEye(),
51 new BoundingRect(103, 80), new BMPEye(),
52 new BoundingRect(106, 240), new Eyeblow(15, 2, false),
53 new BoundingRect(67, 96), new Eyeblow(15, 2, true),
54 new BoundingRect(72, 230)) {}
55};
56
57} // namespace m5avatar
58
59#endif // FACES_BMPFACE_H_
Definition: BMPFace.h:19
Definition: BMPFace.h:46
Definition: BoundingRect.h:10
Definition: DrawContext.h:22
Definition: Drawable.h:13
Definition: Eyeblow.h:15
Definition: Face.h:18
Definition: Gaze.h:9
Definition: Mouth.h:14