fix shutdown animation

This commit is contained in:
gagarinlg
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 809480bc6a
commit 89ff8c53f4
3 changed files with 116 additions and 52 deletions
+112 -52
View File
@@ -105,64 +105,122 @@ void drawSleepBitmap()
} }
#define SHUTDOWN_CIRCLE_DIAMETER 150 #define SHUTDOWN_CIRCLE_DIAMETER 150
class ShutdownAnimation: public FormGroup
{
public:
ShutdownAnimation(uint32_t duration, uint32_t totalDuration):
FormGroup(MainWindow::instance(), {0, 0, LCD_W, LCD_H}, OPAQUE | FORM_NO_BORDER),
duration(duration),
totalDuration(totalDuration)
{
Layer::push(this);
bringToTop();
setFocus(SET_FOCUS_DEFAULT);
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "ShutdownAnimation";
}
#endif
void paint(BitmapBuffer * dc) override
{
LcdFlags fgColor;
LcdFlags bgColor;
if (ThemePersistance::instance()->isDefaultTheme()) {
fgColor = COLOR2FLAGS(WHITE);
bgColor = COLOR2FLAGS(BLACK);
} else {
fgColor = COLOR_THEME_PRIMARY2;
bgColor = COLOR_THEME_SECONDARY1;
}
static const BitmapBuffer* shutdown = OpenTxTheme::instance()->shutdown;
dc->reset();
dc->clear(bgColor);
if (shutdown) {
dc->drawMask((LCD_W - shutdown->width()) / 2,
(LCD_H - shutdown->height()) / 2, shutdown, fgColor);
int quarter = duration / (totalDuration / 5);
if (quarter >= 1)
dc->drawBitmapPattern(LCD_W / 2, (LCD_H - SHUTDOWN_CIRCLE_DIAMETER) / 2,
LBM_SHUTDOWN_CIRCLE, fgColor, 0,
SHUTDOWN_CIRCLE_DIAMETER / 2);
if (quarter >= 2)
dc->drawBitmapPattern(LCD_W / 2, LCD_H / 2, LBM_SHUTDOWN_CIRCLE, fgColor,
SHUTDOWN_CIRCLE_DIAMETER / 2,
SHUTDOWN_CIRCLE_DIAMETER / 2);
if (quarter >= 3)
dc->drawBitmapPattern((LCD_W - SHUTDOWN_CIRCLE_DIAMETER) / 2, LCD_H / 2,
LBM_SHUTDOWN_CIRCLE, fgColor,
SHUTDOWN_CIRCLE_DIAMETER,
SHUTDOWN_CIRCLE_DIAMETER / 2);
if (quarter >= 4)
dc->drawBitmapPattern(
(LCD_W - SHUTDOWN_CIRCLE_DIAMETER) / 2,
(LCD_H - SHUTDOWN_CIRCLE_DIAMETER) / 2, LBM_SHUTDOWN_CIRCLE, fgColor,
SHUTDOWN_CIRCLE_DIAMETER * 3 / 2, SHUTDOWN_CIRCLE_DIAMETER / 2);
} else {
int quarter = duration / (totalDuration / 5);
for (int i = 1; i <= 4; i++) {
if (quarter >= i) {
dc->drawSolidFilledRect(LCD_W / 2 - 70 + 24 * i, LCD_H / 2 - 10, 20,
20, fgColor);
}
}
}
}
void deleteLater(bool detach = true, bool trash = true) override
{
Layer::pop(this);
Window::deleteLater(detach, trash);
}
void update(uint32_t newDuration, uint32_t newTotalDuration)
{
duration = newDuration;
totalDuration = newTotalDuration;
}
protected:
uint32_t duration;
uint32_t totalDuration;
std::string message;
};
static ShutdownAnimation *shutdownAnimation = nullptr;
void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration,
const char* message) const char* message)
{ {
if (totalDuration == 0) return; if (totalDuration == 0)
return;
LcdFlags fgColor; if(!shutdownAnimation)
LcdFlags bgColor; shutdownAnimation = new ShutdownAnimation(duration, totalDuration);
else
if (ThemePersistance::instance()->isDefaultTheme()) { shutdownAnimation->update(duration, totalDuration);
fgColor = COLOR2FLAGS(WHITE); shutdownAnimation->invalidate();
bgColor = COLOR2FLAGS(BLACK);
} else {
fgColor = COLOR_THEME_PRIMARY2;
bgColor = COLOR_THEME_SECONDARY1;
}
static const BitmapBuffer* shutdown = OpenTxTheme::instance()->shutdown;
lcd->reset();
lcdInitDirectDrawing();
lcd->clear(bgColor);
if (shutdown) {
lcd->drawMask((LCD_W - shutdown->width()) / 2,
(LCD_H - shutdown->height()) / 2, shutdown, fgColor);
int quarter = duration / (totalDuration / 5);
if (quarter >= 1)
lcd->drawBitmapPattern(LCD_W / 2, (LCD_H - SHUTDOWN_CIRCLE_DIAMETER) / 2,
LBM_SHUTDOWN_CIRCLE, fgColor, 0,
SHUTDOWN_CIRCLE_DIAMETER / 2);
if (quarter >= 2)
lcd->drawBitmapPattern(LCD_W / 2, LCD_H / 2, LBM_SHUTDOWN_CIRCLE, fgColor,
SHUTDOWN_CIRCLE_DIAMETER / 2,
SHUTDOWN_CIRCLE_DIAMETER / 2);
if (quarter >= 3)
lcd->drawBitmapPattern((LCD_W - SHUTDOWN_CIRCLE_DIAMETER) / 2, LCD_H / 2,
LBM_SHUTDOWN_CIRCLE, fgColor,
SHUTDOWN_CIRCLE_DIAMETER,
SHUTDOWN_CIRCLE_DIAMETER / 2);
if (quarter >= 4)
lcd->drawBitmapPattern(
(LCD_W - SHUTDOWN_CIRCLE_DIAMETER) / 2,
(LCD_H - SHUTDOWN_CIRCLE_DIAMETER) / 2, LBM_SHUTDOWN_CIRCLE, fgColor,
SHUTDOWN_CIRCLE_DIAMETER * 3 / 2, SHUTDOWN_CIRCLE_DIAMETER / 2);
} else {
int quarter = duration / (totalDuration / 5);
for (int i = 1; i <= 4; i++) {
if (quarter >= i) {
lcd->drawSolidFilledRect(LCD_W / 2 - 70 + 24 * i, LCD_H / 2 - 10, 20,
20, fgColor);
}
}
}
WDG_RESET(); WDG_RESET();
lcdRefresh(); RTOS_WAIT_MS(1);
MainWindow::instance()->run(false);
LvglWrapper::instance()->run();
}
void clearShutdownAnimation()
{
if(!shutdownAnimation)
return;
shutdownAnimation->deleteLater();
shutdownAnimation = nullptr;
} }
@@ -197,7 +255,6 @@ class FatalErrorScreen: public FormGroup
protected: protected:
std::string message; std::string message;
bool running = false;
}; };
static FatalErrorScreen *errorScreen = nullptr; static FatalErrorScreen *errorScreen = nullptr;
@@ -214,6 +271,9 @@ void drawFatalErrorScreen(const char * message)
} }
void clearFatalErrorScreen() void clearFatalErrorScreen()
{ {
if(!errorScreen)
return;
errorScreen->deleteLater(); errorScreen->deleteLater();
errorScreen = nullptr; errorScreen = nullptr;
} }
+1
View File
@@ -93,6 +93,7 @@ inline void drawChn(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t idx, LcdFla
void drawSplash(); void drawSplash();
void drawSleepBitmap(); void drawSleepBitmap();
void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, const char * message); void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, const char * message);
void clearShutdownAnimation();
// Main view standard widgets // Main view standard widgets
void drawMainPots(); void drawMainPots();
+3
View File
@@ -2049,7 +2049,10 @@ uint32_t pwrCheck()
else { else {
#if defined(COLORLCD) #if defined(COLORLCD)
if (pwr_press_time != 0) if (pwr_press_time != 0)
{
clearShutdownAnimation();
MainWindow::instance()->invalidate(); MainWindow::instance()->invalidate();
}
#endif #endif
pwr_check_state = PWR_CHECK_ON; pwr_check_state = PWR_CHECK_ON;
pwr_press_time = 0; pwr_press_time = 0;