From a30bdf0d8d8ab8e212cc181f7510bd7a238f0552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 15 May 2017 15:01:06 +0200 Subject: [PATCH] [escher] Redraw the window when a timer fires Change-Id: Ib62ad7ec9641e6da61f8c3cbf00fbd470d46326c --- apps/apps_container.cpp | 17 +++++------------ apps/apps_container.h | 3 +-- apps/on_boarding/logo_controller.cpp | 3 --- apps/settings/sub_controller.cpp | 2 +- apps/usb_timer.cpp | 2 +- escher/include/escher/container.h | 1 + escher/include/escher/run_loop.h | 1 + escher/include/escher/timer.h | 2 +- escher/src/container.cpp | 6 +++++- escher/src/run_loop.cpp | 4 +++- escher/src/timer.cpp | 4 +++- 11 files changed, 22 insertions(+), 23 deletions(-) diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 7ece3d73b..b554107a5 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -170,7 +170,7 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) { return true; } if (!didProcessEvent && alphaLockWantsRedraw) { - window()->redraw(); + windowRedraw(); return true; } return didProcessEvent; @@ -192,21 +192,18 @@ void AppsContainer::switchTo(App * app) { } void AppsContainer::updateBatteryState() { - if (m_window.updateBatteryLevel() || m_window.updateIsChargingState() || m_window.updatePluggedState()) { - m_window.redraw(); - } + m_window.updateBatteryLevel(); + m_window.updateIsChargingState(); + m_window.updatePluggedState(); } void AppsContainer::refreshPreferences() { m_window.refreshPreferences(); } -void AppsContainer::displayExamModePopUp(bool activate, bool forceWindowRedraw) { +void AppsContainer::displayExamModePopUp(bool activate) { m_examPopUpController.setActivatingExamMode(activate); activeApp()->displayModalViewController(&m_examPopUpController, 0.f, 0.f, Metric::ExamPopUpTopMargin, Metric::PopUpRightMargin, Metric::ExamPopUpBottomMargin, Metric::PopUpLeftMargin); - if (forceWindowRedraw) { - m_window.redraw(true); - } } void AppsContainer::shutdownDueToLowBattery() { @@ -222,10 +219,6 @@ void AppsContainer::reloadTitleBar() { m_window.reloadTitleBar(); } -void AppsContainer::windowRedraw() { - m_window.redraw(); -} - Window * AppsContainer::window() { return &m_window; } diff --git a/apps/apps_container.h b/apps/apps_container.h index c69e28c47..574cbd2e2 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -56,10 +56,9 @@ public: void switchTo(App * app) override; void updateBatteryState(); void refreshPreferences(); - void displayExamModePopUp(bool activate, bool forceRedrawWindow); + void displayExamModePopUp(bool activate); void shutdownDueToLowBattery(); void reloadTitleBar(); - void windowRedraw(); private: Window * window() override; int numberOfTimers() override; diff --git a/apps/on_boarding/logo_controller.cpp b/apps/on_boarding/logo_controller.cpp index 758df2f82..32700462f 100644 --- a/apps/on_boarding/logo_controller.cpp +++ b/apps/on_boarding/logo_controller.cpp @@ -1,6 +1,5 @@ #include "logo_controller.h" #include "logo_icon.h" -#include "../apps_container.h" namespace OnBoarding { @@ -17,8 +16,6 @@ View * LogoController::view() { void LogoController::fire() { app()->dismissModalViewController(); - AppsContainer * appsContainer = (AppsContainer *)app()->container(); - appsContainer->windowRedraw(); } } diff --git a/apps/settings/sub_controller.cpp b/apps/settings/sub_controller.cpp index 48f7d8047..d116ce015 100644 --- a/apps/settings/sub_controller.cpp +++ b/apps/settings/sub_controller.cpp @@ -70,7 +70,7 @@ bool SubController::handleEvent(Ion::Events::Event event) { return false; } AppsContainer * container = (AppsContainer *)(app()->container()); - container->displayExamModePopUp(true, false); + container->displayExamModePopUp(true); return true; } /* Behaviour of "About" menu */ diff --git a/apps/usb_timer.cpp b/apps/usb_timer.cpp index 0de3b1373..456435bdb 100644 --- a/apps/usb_timer.cpp +++ b/apps/usb_timer.cpp @@ -12,7 +12,7 @@ USBTimer::USBTimer(AppsContainer * container) : void USBTimer::fire() { if (Ion::USB::isPlugged()) { if (!m_previousPluggedState && GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Activate) { - m_container->displayExamModePopUp(false, true); + m_container->displayExamModePopUp(false); } #if LED_WHILE_CHARGING KDColor LEDColor = Ion::Battery::isCharging() ? KDColorYellow : KDColorGreen; diff --git a/escher/include/escher/container.h b/escher/include/escher/container.h index 395065e3e..595f0a177 100644 --- a/escher/include/escher/container.h +++ b/escher/include/escher/container.h @@ -24,6 +24,7 @@ public: virtual void switchTo(App * app); protected: virtual Window * window() = 0; + void windowRedraw() override; private: void step(); App * m_activeApp; diff --git a/escher/include/escher/run_loop.h b/escher/include/escher/run_loop.h index 83f9396d6..81bc7b1fd 100644 --- a/escher/include/escher/run_loop.h +++ b/escher/include/escher/run_loop.h @@ -9,6 +9,7 @@ public: RunLoop(); void run(); protected: + virtual void windowRedraw() = 0; virtual bool dispatchEvent(Ion::Events::Event e) = 0; virtual int numberOfTimers(); virtual Timer * timerAtIndex(int i); diff --git a/escher/include/escher/timer.h b/escher/include/escher/timer.h index 808290922..6d2825f77 100644 --- a/escher/include/escher/timer.h +++ b/escher/include/escher/timer.h @@ -16,7 +16,7 @@ class Timer { public: static constexpr int TickDuration = 300; // In Miliseconds Timer(uint32_t period); // Period is in ticks - void tick(); + bool tick(); void reset(); protected: virtual void fire() = 0; diff --git a/escher/src/container.cpp b/escher/src/container.cpp index 64d0ae8a5..53319bf06 100644 --- a/escher/src/container.cpp +++ b/escher/src/container.cpp @@ -26,7 +26,7 @@ App * Container::activeApp() { bool Container::dispatchEvent(Ion::Events::Event event) { if (m_activeApp->processEvent(event)) { - window()->redraw(); + windowRedraw(); return true; } return false; @@ -37,3 +37,7 @@ void Container::run() { window()->redraw(); RunLoop::run(); } + +void Container::windowRedraw() { + window()->redraw(); +} diff --git a/escher/src/run_loop.cpp b/escher/src/run_loop.cpp index 559a77899..5a15f0724 100644 --- a/escher/src/run_loop.cpp +++ b/escher/src/run_loop.cpp @@ -48,7 +48,9 @@ bool RunLoop::step() { m_time -= Timer::TickDuration; for (int i=0; itick(); + if (timer->tick()) { + windowRedraw(); + } } } diff --git a/escher/src/timer.cpp b/escher/src/timer.cpp index 564cdb51a..4aebee229 100644 --- a/escher/src/timer.cpp +++ b/escher/src/timer.cpp @@ -6,12 +6,14 @@ Timer::Timer(uint32_t period) : { } -void Timer::tick() { +bool Timer::tick() { m_numberOfTicksBeforeFire--; if (m_numberOfTicksBeforeFire == 0) { fire(); reset(); + return true; } + return false; } void Timer::reset() {