1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "backends/networking/curl/cloudicon.h"
#include "backends/cloud/cloudmanager.h"
#include "gui/ThemeEngine.h"
#include "gui/gui-manager.h"
#include "image/png.h"
#include <common/file.h>
#include <backends/graphics/surfacesdl/surfacesdl-graphics.h>
namespace Networking {
const float CloudIcon::ALPHA_STEP = 0.025;
const float CloudIcon::ALPHA_MAX = 1;
const float CloudIcon::ALPHA_MIN = 0.6;
CloudIcon::CloudIcon():
_wasVisible(false), _iconsInited(false), _showingDisabled(false),
_currentAlpha(0), _alphaRising(true), _disabledFrames(0) {
initIcons();
}
CloudIcon::~CloudIcon() {}
bool CloudIcon::draw() {
bool stop = false;
initIcons();
if (CloudMan.isWorking() || _disabledFrames > 0) {
if (g_system) {
if (!_wasVisible) {
g_system->clearOSD();
_wasVisible = true;
}
--_disabledFrames;
if (_alphaRising) {
if (_currentAlpha < ALPHA_MIN)
_currentAlpha += 5 * ALPHA_STEP;
else
_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 -= 5 * ALPHA_STEP;
if (_currentAlpha <= 0) {
_currentAlpha = 0;
stop = true;
}
}
if (g_system) {
Graphics::TransparentSurface *surface = &_icon;
makeAlphaIcon((_showingDisabled? _disabledIcon:_icon), _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);
}
}
if (stop) _showingDisabled = false;
return stop;
}
void CloudIcon::showDisabled() {
_showingDisabled = true;
_disabledFrames = 20 * 3; //3 seconds 20 fps
}
void CloudIcon::initIcons() {
if (_iconsInited) return;
loadIcon(_icon, "cloudicon.png");
loadIcon(_disabledIcon, "cloudicon_disabled.png");
_iconsInited = true;
}
void CloudIcon::loadIcon(Graphics::TransparentSurface &icon, const char *filename) {
Image::PNGDecoder decoder;
Common::ArchiveMemberList members;
Common::File file;
if (!file.open(filename)) warning("CloudIcon::loadIcon: unable to open %s", filename);
Common::SeekableReadStream *stream = &file;
if (stream) {
if (!decoder.loadStream(*stream))
error("CloudIcon::loadIcon: error decoding PNG");
Graphics::TransparentSurface *s = new Graphics::TransparentSurface(*decoder.getSurface(), true);
if (s) {
Graphics::PixelFormat f = g_system->getOSDFormat();
if (f != s->format) {
Graphics::TransparentSurface *s2 = s->convertTo(f);
if (s2) icon.copyFrom(*s2);
else warning("CloudIcon::loadIcon: failed converting TransparentSurface");
delete s2;
} else {
icon.copyFrom(*s);
}
delete s;
} else warning("CloudIcon::loadIcon: failed reading TransparentSurface from PNGDecoder");
}
}
void CloudIcon::makeAlphaIcon(Graphics::TransparentSurface &icon, 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;
}
}
}
} // End of namespace Networking
|