Skip to content

Commit

Permalink
Merge pull request #82 from mongonta0716/fix-balloon
Browse files Browse the repository at this point in the history
Balloon color can be specified, long strings can be displayed
  • Loading branch information
mongonta0716 committed Aug 30, 2022
2 parents 7b5ab2a + 21606ff commit 70c4274
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Balloon.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Balloon final : public Drawable {
return;
}
ColorPalette* cp = drawContext->getColorPalette();
uint16_t primaryColor = cp->get(COLOR_PRIMARY);
uint16_t backgroundColor = cp->get(COLOR_BACKGROUND);
uint16_t primaryColor = cp->get(COLOR_BALLOON_FOREGROUND);
uint16_t backgroundColor = cp->get(COLOR_BALLOON_BACKGROUND);
M5.Lcd.setTextSize(TEXT_SIZE);
M5.Lcd.setTextDatum(MC_DATUM);
spi->setTextSize(TEXT_SIZE);
Expand All @@ -41,15 +41,15 @@ class Balloon final : public Drawable {
M5.Lcd.setFont(font);
int textWidth = M5.Lcd.textWidth(text);
int textHeight = TEXT_HEIGHT * TEXT_SIZE;
spi->fillEllipse(cx, cy, _max(textWidth, MIN_WIDTH) + 2, textHeight * 2 + 2,
spi->fillEllipse(cx - 20, cy,textWidth + 2, textHeight * 2 + 2,
primaryColor);
spi->fillTriangle(cx - 62, cy - 42, cx - 8, cy - 10, cx - 41, cy - 8,
primaryColor);
spi->fillEllipse(cx, cy, _max(textWidth, MIN_WIDTH), textHeight * 2,
spi->fillEllipse(cx - 20, cy, textWidth, textHeight * 2,
backgroundColor);
spi->fillTriangle(cx - 60, cy - 40, cx - 10, cy - 10, cx - 40, cy - 10,
backgroundColor);
spi->drawString(text, cx, cy, font);//&fonts::lgfxJapanGothic_16); // Continue printing from new x position
spi->drawString(text, cx - textWidth / 6 - 15, cy, font); // Continue printing from new x position
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/ColorPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace m5avatar {
ColorPalette::ColorPalette()
: colors{{COLOR_PRIMARY, TFT_WHITE},
{COLOR_SECONDARY, TFT_BLACK},
{COLOR_BACKGROUND, TFT_BLACK}} {}
{COLOR_BACKGROUND, TFT_BLACK},
{COLOR_BALLOON_FOREGROUND, TFT_BLACK},
{COLOR_BALLOON_BACKGROUND, TFT_WHITE}} {}

uint16_t ColorPalette::get(const char* key) const {
auto itr = colors.find(key);
Expand Down
2 changes: 2 additions & 0 deletions src/ColorPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define COLOR_PRIMARY "primary"
#define COLOR_SECONDARY "secondary"
#define COLOR_BACKGROUND "background"
#define COLOR_BALLOON_FOREGROUND "balloon_f"
#define COLOR_BALLOON_BACKGROUND "balloon_b"

namespace m5avatar {
// enum class ColorType
Expand Down

0 comments on commit 70c4274

Please sign in to comment.