mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-27 05:32:45 +00:00
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.
This commit is contained in:
parent
135f7d09a8
commit
cec93e2c03
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
BIN
cloudicon.png
Normal file
BIN
cloudicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Loading…
x
Reference in New Issue
Block a user