aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/networking/curl/cloudicon.cpp106
-rw-r--r--backends/networking/curl/cloudicon.h6
-rw-r--r--backends/networking/curl/connectionmanager.cpp14
-rw-r--r--backends/networking/curl/connectionmanager.h3
-rw-r--r--cloudicon.pngbin0 -> 1374 bytes
5 files changed, 74 insertions, 55 deletions
diff --git a/backends/networking/curl/cloudicon.cpp b/backends/networking/curl/cloudicon.cpp
index d79eef6005..3304c71b98 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 9419cf04bf..0210899777 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 af8432d260..95b38df0c2 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<ConnectionManager, Request *>(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 3a2e974bf4..925312b23b 100644
--- a/backends/networking/curl/connectionmanager.h
+++ b/backends/networking/curl/connectionmanager.h
@@ -79,7 +79,7 @@ class ConnectionManager : public Common::Singleton<ConnectionManager> {
bool _timerStarted;
Common::Array<RequestWithCallback> _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<ConnectionManager> {
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 0000000000..5f121a855f
--- /dev/null
+++ b/cloudicon.png
Binary files differ