CLOUD: Make CloudIcon pulsate, fade in and fade out
That required ConnMan's timer stopping. Would be fixed in the next commit.
This commit is contained in:
parent
de84701aea
commit
135f7d09a8
3 changed files with 73 additions and 10 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue