diff options
author | Alexander Tkachev | 2016-06-04 19:14:54 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 135f7d09a8ea790df37bff676682163732b1f6ad (patch) | |
tree | d1ad76326ae6f4e2f56952566b52e09626e74b1b | |
parent | de84701aead489de944db078e6b61c2584708c53 (diff) | |
download | scummvm-rg350-135f7d09a8ea790df37bff676682163732b1f6ad.tar.gz scummvm-rg350-135f7d09a8ea790df37bff676682163732b1f6ad.tar.bz2 scummvm-rg350-135f7d09a8ea790df37bff676682163732b1f6ad.zip |
CLOUD: Make CloudIcon pulsate, fade in and fade out
That required ConnMan's timer stopping. Would be fixed in the next
commit.
-rw-r--r-- | backends/networking/curl/cloudicon.cpp | 75 | ||||
-rw-r--r-- | backends/networking/curl/cloudicon.h | 7 | ||||
-rw-r--r-- | backends/networking/curl/connectionmanager.cpp | 1 |
3 files changed, 73 insertions, 10 deletions
diff --git a/backends/networking/curl/cloudicon.cpp b/backends/networking/curl/cloudicon.cpp index ec89c12dc9..d79eef6005 100644 --- a/backends/networking/curl/cloudicon.cpp +++ b/backends/networking/curl/cloudicon.cpp @@ -30,7 +30,11 @@ namespace Networking { -CloudIcon::CloudIcon(): _frame(0), _wasVisible(false), _iconsInited(false) { +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) { initIcons(); } @@ -51,17 +55,52 @@ void CloudIcon::initIcons() { Graphics::TransparentSurface *s = new Graphics::TransparentSurface(*decoder.getSurface(), true); if (s) { Graphics::PixelFormat f = g_system->getOSDFormat(); - //f.bytesPerPixel = 4; - debug("%d in osd vs %d in s", f.bytesPerPixel, s->format.bytesPerPixel); - Graphics::TransparentSurface *s2 = s->convertTo(f); - if (s2) _icon.copyFrom(*s2); - else warning("failed converting"); + if (f != s->format) { + Graphics::TransparentSurface *s2 = s->convertTo(f); + if (s2) _icon.copyFrom(*s2); + else warning("failed converting"); + delete s2; + } else { + _icon.copyFrom(*s); + } + delete s; } else warning("failed reading"); } _iconsInited = true; } +void CloudIcon::makeAlphaIcon(float alpha) { + _alphaIcon.copyFrom(_icon); + + byte *pixels = (byte *)_alphaIcon.getPixels(); + for (int y = 0; y < _alphaIcon.h; y++) { + byte *row = pixels + y * _alphaIcon.pitch; + for (int x = 0; x < _alphaIcon.w; x++) { + uint32 srcColor; + if (_alphaIcon.format.bytesPerPixel == 2) + srcColor = READ_UINT16(row); + else if (_alphaIcon.format.bytesPerPixel == 3) + srcColor = READ_UINT24(row); + else + srcColor = READ_UINT32(row); + + // Update color's alpha + byte r, g, b, a; + _alphaIcon.format.colorToARGB(srcColor, a, r, g, b); + a = (byte)(a * alpha); + uint32 color = _alphaIcon.format.ARGBToColor(a, r, g, b); + + if (_alphaIcon.format.bytesPerPixel == 2) + *((uint16 *)row) = color; + else + *((uint32 *)row) = color; + + row += _alphaIcon.format.bytesPerPixel; + } + } +} + void CloudIcon::draw() { initIcons(); _frame++; @@ -73,17 +112,35 @@ void CloudIcon::draw() { 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) { - if (_icon.getPixels()) { - int x = g_system->getOverlayWidth() - _icon.w - 10, y = 10; - g_system->copyRectToOSD(_icon.getPixels(), _icon.pitch, x, y, _icon.w, _icon.h); + 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); } } } diff --git a/backends/networking/curl/cloudicon.h b/backends/networking/curl/cloudicon.h index 7cecf3acde..9419cf04bf 100644 --- a/backends/networking/curl/cloudicon.h +++ b/backends/networking/curl/cloudicon.h @@ -28,11 +28,16 @@ namespace Networking { class CloudIcon { + static const float ALPHA_STEP, ALPHA_MAX, ALPHA_MIN; + int _frame; bool _wasVisible, _iconsInited; - Graphics::TransparentSurface _icon; + Graphics::TransparentSurface _icon, _alphaIcon; + float _currentAlpha; + bool _alphaRising; void initIcons(); + void makeAlphaIcon(float alpha); public: CloudIcon(); diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp index 57ea2ce999..af8432d260 100644 --- a/backends/networking/curl/connectionmanager.cpp +++ b/backends/networking/curl/connectionmanager.cpp @@ -87,6 +87,7 @@ void ConnectionManager::startTimer(int interval) { } void ConnectionManager::stopTimer() { + return; debug("timer stopped"); Common::TimerManager *manager = g_system->getTimerManager(); manager->removeTimerProc(connectionsThread); |