stackchan-display
Loading...
Searching...
No Matches
Display.h
1#pragma once
2
3#include <M5Unified.h>
4#include "Drawable.h"
5#include "Expression.h"
6#include "ColorPalette.h"
7#include "Decorator.h"
8#include "SpeechBalloon.h"
9#include "faces/Faces.h"
10
11// https://github.com/m5stack/StackChan/blob/main/firmware/main/stackchan/avatar/avatar/avatar.h
12
13namespace stackchan::display
14{
15 class Display
16 {
17 protected:
18 // bool _is_modify_locked = false;
19
20 M5Canvas canvas_;
21 Face *face_;
22 ExpressionWeight expression_weight_;
23 ColorPalette *color_palette_;
24 SpeechBalloon speech_balloon_;
25
26 void drawEmotionalDecorator(ExpressionWeight &expression_weight, ColorPalette &color_palette);
27
28 public:
29 Display() : canvas_(&M5.Lcd), expression_weight_(), speech_balloon_()
30 {
31 face_ = new Face();
32 color_palette_ = new ColorPalette();
33 };
34 Face *getFace()
35 {
36 return face_;
37 }
38 void setFace(Face *face)
39 {
40 face_ = face;
41 }
42
43 ExpressionWeight &getExpressionWeight()
44 {
45 return expression_weight_;
46 }
47
48 SpeechBalloon &getSpeechBalloon()
49 {
50 return speech_balloon_;
51 }
52
53 ColorPalette *getColorPalette()
54 {
55 return color_palette_;
56 }
57
58 M5Canvas &getCanvas()
59 {
60 return canvas_;
61 }
62
63 // void setCanvas(M5Canvas &canvas)
64 // {
65 // canvas_ = canvas;
66 // }
67
68 virtual void draw(ExpressionWeight &expression_weight, ColorPalette &palette)
69 {
70 canvas_.createSprite(320, 240); // canvas_.width() and canvas_.height() can be used if the canvas size is not fixed`
71 face_->draw(canvas_, expression_weight_, *color_palette_);
72 drawEmotionalDecorator(expression_weight_, *color_palette_);
73 speech_balloon_.draw(canvas_, *color_palette_);
74 };
79 virtual void update()
80 {
81 face_->updateState(expression_weight_);
82 this->draw(expression_weight_, *color_palette_);
83 canvas_.pushSprite(0, 0);
84 canvas_.deleteSprite();
85 };
86 };
87
88 void Display::drawEmotionalDecorator(ExpressionWeight &expression_weight, ColorPalette &color_palette)
89 {
90 int x = 320 - 40;
91 int y = 40;
92 uint16_t color = canvas_.getColorDepth() == 1
93 ? 1
94 : color_palette_->get(DrawingLocation::kBalloonBackground);
95 uint16_t background_color = canvas_.getColorDepth() == 1
96 ? 0
97 : color_palette_->get(DrawingLocation::kBalloonForeground);
98
99 // canvas_.fillCircle(x, y, 40, TFT_GREEN);
100 if (expression_weight.get(Expression::kSleepy) > 128)
101 {
102 drawBubble(canvas_, x, y, 20, color);
103 }
104 if (expression_weight.get(Expression::kAngry) > 128)
105 {
106 drawAngerMark(canvas_, x, y, 20, color, background_color);
107 }
108 if (expression_weight.get(Expression::kUpset) > 128)
109 {
110 drawWaterDrop(canvas_, x, y, 20, color);
111 }
112 if (expression_weight.get(Expression::kSad) > 128)
113 {
114 drawPaleMark(canvas_, x, y, 20, color);
115 }
116 if (expression_weight.get(Expression::kSmile) > 128)
117 {
118 drawHeart(canvas_, x, y, 20, color);
119 }
120 }
121}
Definition ColorPalette.h:48
Definition Display.h:16
virtual void update()
Update avatar, trigger all elements, decorators and modifiers to update.
Definition Display.h:79
Definition Expression.h:39
Definition Faces.h:13
Definition SpeechBalloon.h:25