From cec93e2c0319f92c31cbeea2a9e5c5763a71a7dc Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Sat, 4 Jun 2016 19:36:10 +0600 Subject: [PATCH] CLOUD: Make CloudIcon switch ConnMan's timer off CloudIcon is now a Request which is automatically added once first Request is added to ConnMan. When icon decides it should disappear, it gets FINISHED, so ConnMan would switch off the timer if it was the last Request. --- backends/networking/curl/cloudicon.cpp | 106 ++++++++++-------- backends/networking/curl/cloudicon.h | 6 +- .../networking/curl/connectionmanager.cpp | 14 ++- backends/networking/curl/connectionmanager.h | 3 +- cloudicon.png | Bin 0 -> 1374 bytes 5 files changed, 74 insertions(+), 55 deletions(-) create mode 100644 cloudicon.png diff --git a/backends/networking/curl/cloudicon.cpp b/backends/networking/curl/cloudicon.cpp index d79eef6005a..3304c71b980 100644 --- a/backends/networking/curl/cloudicon.cpp +++ b/backends/networking/curl/cloudicon.cpp @@ -34,12 +34,65 @@ const float CloudIcon::ALPHA_STEP = 0.03; const float CloudIcon::ALPHA_MAX = 1; const float CloudIcon::ALPHA_MIN = 0.5; -CloudIcon::CloudIcon(): _frame(0), _wasVisible(false), _iconsInited(false), _currentAlpha(0), _alphaRising(true) { +CloudIcon::CloudIcon(): Request(nullptr, nullptr), _wasVisible(false), _iconsInited(false), _currentAlpha(0), _alphaRising(true) { initIcons(); } CloudIcon::~CloudIcon() {} +void CloudIcon::draw() { + initIcons(); + + Cloud::Storage *storage = CloudMan.getCurrentStorage(); + if (storage && storage->isWorking()) { + if (g_system) { + if (!_wasVisible) { + g_system->clearOSD(); + _wasVisible = true; + } + if (_alphaRising) { + _currentAlpha += ALPHA_STEP; + if (_currentAlpha > ALPHA_MAX) { + _currentAlpha = ALPHA_MAX; + _alphaRising = false; + } + } else { + _currentAlpha -= ALPHA_STEP; + if (_currentAlpha < ALPHA_MIN) { + _currentAlpha = ALPHA_MIN; + _alphaRising = true; + } + } + } else { + _wasVisible = false; + } + } else { + _wasVisible = false; + _currentAlpha -= 3 * ALPHA_STEP; + if (_currentAlpha <= 0) { + _currentAlpha = 0; + finish(); + } + } + + if (g_system) { + Graphics::TransparentSurface *surface = &_icon; + makeAlphaIcon(_currentAlpha); + if (_alphaIcon.getPixels()) surface = &_alphaIcon; + if (surface && surface->getPixels()) { + int x = g_system->getOverlayWidth() - surface->w - 10, y = 10; + g_system->copyRectToOSD(surface->getPixels(), surface->pitch, x, y, surface->w, surface->h); + } + } +} + +void CloudIcon::handle() {} + +void CloudIcon::restart() { + _currentAlpha = 0; + _alphaRising = true; +} + void CloudIcon::initIcons() { if (_iconsInited) return; @@ -47,8 +100,8 @@ void CloudIcon::initIcons() { Common::ArchiveMemberList members; Common::File file; if (!file.open("cloudicon.png")) warning("failed"); - Common::SeekableReadStream *stream = &file; - if (stream) { + Common::SeekableReadStream *stream = &file; + if (stream) { if (!decoder.loadStream(*stream)) error("Error decoding PNG"); @@ -64,8 +117,7 @@ void CloudIcon::initIcons() { _icon.copyFrom(*s); } delete s; - } - else warning("failed reading"); + } else warning("failed reading"); } _iconsInited = true; } @@ -101,48 +153,4 @@ void CloudIcon::makeAlphaIcon(float alpha) { } } -void CloudIcon::draw() { - initIcons(); - _frame++; - - Cloud::Storage *storage = CloudMan.getCurrentStorage(); - if (storage && storage->isWorking()) { - if (g_system) { - if (!_wasVisible) { - g_system->clearOSD(); - _wasVisible = true; - } - if (_alphaRising) { - _currentAlpha += ALPHA_STEP; - if (_currentAlpha > ALPHA_MAX) { - _currentAlpha = ALPHA_MAX; - _alphaRising = false; - } - } else { - _currentAlpha -= ALPHA_STEP; - if (_currentAlpha < ALPHA_MIN) { - _currentAlpha = ALPHA_MIN; - _alphaRising = true; - } - } - } else { - _wasVisible = false; - } - } else { - _wasVisible = false; - _currentAlpha -= 3 * ALPHA_STEP; - if (_currentAlpha <= 0) _currentAlpha = 0; - } - - if (g_system) { - Graphics::TransparentSurface *surface = &_icon; - makeAlphaIcon(_currentAlpha); - if (_alphaIcon.getPixels()) surface = &_alphaIcon; - if (surface && surface->getPixels()) { - int x = g_system->getOverlayWidth() - surface->w - 10, y = 10; - g_system->copyRectToOSD(surface->getPixels(), surface->pitch, x, y, surface->w, surface->h); - } - } -} - } // End of namespace Networking diff --git a/backends/networking/curl/cloudicon.h b/backends/networking/curl/cloudicon.h index 9419cf04bf2..0210899777f 100644 --- a/backends/networking/curl/cloudicon.h +++ b/backends/networking/curl/cloudicon.h @@ -23,14 +23,14 @@ #ifndef BACKENDS_NETWORKING_CURL_CLOUDICON_H #define BACKENDS_NETWORKING_CURL_CLOUDICON_H +#include "backends/networking/curl/request.h" #include "graphics/transparent_surface.h" namespace Networking { -class CloudIcon { +class CloudIcon: public Request { static const float ALPHA_STEP, ALPHA_MAX, ALPHA_MIN; - int _frame; bool _wasVisible, _iconsInited; Graphics::TransparentSurface _icon, _alphaIcon; float _currentAlpha; @@ -44,6 +44,8 @@ public: ~CloudIcon(); void draw(); + virtual void handle(); + virtual void restart(); }; } // End of namespace Networking diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp index af8432d2609..95b38df0c2c 100644 --- a/backends/networking/curl/connectionmanager.cpp +++ b/backends/networking/curl/connectionmanager.cpp @@ -37,7 +37,7 @@ DECLARE_SINGLETON(Networking::ConnectionManager); namespace Networking { -ConnectionManager::ConnectionManager(): _multi(0), _timerStarted(false), _frame(0) { +ConnectionManager::ConnectionManager(): _multi(0), _timerStarted(false), _frame(0), _icon(nullptr) { curl_global_init(CURL_GLOBAL_ALL); _multi = curl_multi_init(); } @@ -84,14 +84,18 @@ void ConnectionManager::startTimer(int interval) { } else { warning("Failed to install Networking::ConnectionManager's timer"); } + if (_timerStarted && !_icon) { + _icon = new CloudIcon(); + addRequest(_icon, new Common::Callback(this, &ConnectionManager::cloudIconDeleted)); + } } void ConnectionManager::stopTimer() { - return; debug("timer stopped"); Common::TimerManager *manager = g_system->getTimerManager(); manager->removeTimerProc(connectionsThread); _timerStarted = false; + if (_icon) _icon->finish(); } void ConnectionManager::handle() { @@ -103,7 +107,7 @@ void ConnectionManager::handle() { _handleMutex.unlock(); //icon redrawing is doesn't require any mutex, but must be done after requests are iterated - _icon.draw(); + if (_icon) _icon->draw(); } void ConnectionManager::interateRequests() { @@ -154,4 +158,8 @@ void ConnectionManager::processTransfers() { } } +void ConnectionManager::cloudIconDeleted(Request *icon) { + if (_icon == icon) _icon = nullptr; +} + } // End of namespace Cloud diff --git a/backends/networking/curl/connectionmanager.h b/backends/networking/curl/connectionmanager.h index 3a2e974bf4c..925312b23b2 100644 --- a/backends/networking/curl/connectionmanager.h +++ b/backends/networking/curl/connectionmanager.h @@ -79,7 +79,7 @@ class ConnectionManager : public Common::Singleton { bool _timerStarted; Common::Array _requests; Common::Mutex _handleMutex; - CloudIcon _icon; + CloudIcon *_icon; uint32 _frame; void startTimer(int interval = TIMER_INTERVAL); @@ -87,6 +87,7 @@ class ConnectionManager : public Common::Singleton { void handle(); void interateRequests(); void processTransfers(); + void cloudIconDeleted(Request *icon); public: ConnectionManager(); diff --git a/cloudicon.png b/cloudicon.png new file mode 100644 index 0000000000000000000000000000000000000000..5f121a855f9939b60762deb57e8b5b5da6e319ba GIT binary patch literal 1374 zcmV-k1)=(hP){<%AM=G;5e!#T5e_WoIRz4n72 zmwV4Szwh__{+-_yNs=&Av0SeWSO=^JUIa|wHQ%u>&)7(nm@@=k32X&k1)c`x0|w9r z>;rcEF9a;t>i`Y_+km-1q?cMV+vYqd__PEp*Rz3-fDT{;XwkrTfM0;Cz##BxGXzAv z9I#w(5AY!npj^EG_z^e^ob(-gxEau_)Of&hy zeJTOqeP9Vt25te{ea9Ye792?3Zlv1NH!vA`1Hf{3vk+Z>|-;vy62mrzTU5gf_G02UHstN8{Lie`Hr0iJ|$rSn3n6c0;^H6 zp9g$C9boT?tE&Lf@%W;Pf85F+k>zA_IZjLg-7PtBV)yaiw|%^B`KboS%T$_Js}Mqp zp1y%sfc>aip8(eRjy+m^^5E&4xogAsj+NqMEkMo?|AwWwJ&qI7oJxS!oG~`9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