GUI: Scale EE in About dialog

This commit is contained in:
Eugene Sandulenko 2021-04-15 23:06:18 +02:00
parent b49e6eb96f
commit 3e84b88400
No known key found for this signature in database
GPG Key ID: 014D387312D34F08

View File

@ -349,6 +349,20 @@ enum { kPlComp, kPlHuman };
enum { kSndPoint, kSndHit, kSndLoss };
enum {
kSpL1, kSpL2, kSpL3,
kSpR1, kSpR2, kSpR3,
kSpB1, kSpB2, kSpB3, kSpB4,
kSp0, kSp1, kSp2, kSp3, kSp4,
kSp5, kSp6, kSp7, kSp8, kSp9,
kSpCode1,
kSpCode1h = kSpCode1 + 6,
kSpNum0 = kSpCode1h + 6,
kSpStar = kSpNum0 + 10,
kSpSpace,
kSpLast
};
class EE {
public:
EE();
@ -392,10 +406,12 @@ private:
Graphics::AmigaFont _font;
Graphics::Surface _sp[10];
Graphics::Surface _sp[kSpLast];
Graphics::PixelFormat _format;
int _windowX, _windowY;
int _windowX, _windowY, _windowW, _windowH;
float _scale;
bool _inited;
uint32 _colorBlue, _colorOrange;
@ -420,7 +436,6 @@ private:
void playSound(int d);
void genSprites();
void drawStatus(Common::String str, int x, uint32 color, int y = 2, int color2 = 0, int w = 184);
};
bool EEHandler::handleKeyDown(Common::KeyState &state) {
@ -438,11 +453,25 @@ bool EEHandler::handleKeyDown(Common::KeyState &state) {
}
EE::EE() {
_windowX = (g_system->getOverlayWidth() > 320) ? (g_system->getOverlayWidth() - 320) / 2 : 0;
_windowY = (g_system->getOverlayHeight() > 200) ? (g_system->getOverlayHeight() - 200) / 2 : 0;
if (g_system->getOverlayWidth() < 320 || g_system->getOverlayHeight() < 200) {
warning("EE: Screen is too small");
_inited = false;
return;
}
// Determine scale factor
float scaleX = g_system->getOverlayWidth() * 0.9 / 320;
float scaleY = g_system->getOverlayHeight() * 0.9 / 200;
_scale = MAX(1.0f, MIN(scaleX, scaleY));
_windowW = 320 * _scale;
_windowH = 200 * _scale;
_windowX = (g_system->getOverlayWidth() > 320) ? (g_system->getOverlayWidth() - _windowW) / 2 : 0;
_windowY = (g_system->getOverlayHeight() > 200) ? (g_system->getOverlayHeight() - _windowH) / 2 : 0;
_format = g_system->getOverlayFormat();
_back.create(MIN<int>(g_system->getOverlayWidth(), 320), MIN<int>(g_system->getOverlayHeight(), 200), _format);
_back.create(_windowW, _windowH, _format);
_colorBlue = _format.RGBToColor(5 * 16, 7 * 16, 8 * 16);
_colorOrange = _format.RGBToColor(15 * 16, 7 * 16, 8 * 16);
@ -451,16 +480,21 @@ EE::EE() {
}
EE::~EE() {
for (int i = 0; i < kSpLast; i++)
_sp[i].free();
}
void EE::cls(bool update) {
_back.fillRect(Common::Rect(0, 0, MIN<int>(g_system->getOverlayWidth(), 320), MIN<int>(g_system->getOverlayHeight(), 200)), 0);
_back.fillRect(Common::Rect(0, 0, _windowW, _windowH), 0);
if (update)
g_system->copyRectToOverlay(_back.getPixels(), _back.pitch, _windowX, _windowY, MIN<int>(g_system->getOverlayWidth(), 320), MIN<int>(g_system->getOverlayHeight(), 200));
g_system->copyRectToOverlay(_back.getPixels(), _back.pitch, _windowX, _windowY, _windowW, _windowH);
}
void EE::run() {
if (!_inited)
return;
_shouldQuit = false;
genSprites();
@ -496,15 +530,6 @@ void EE::run() {
}
}
enum {
kSpL1, kSpL2, kSpL3,
kSpR1, kSpR2, kSpR3,
kSpB1, kSpB2, kSpB3, kSpB4,
kSp0, kSp1, kSp2, kSp3, kSp4,
kSp5, kSp6, kSp7, kSp8, kSp9,
kSpSt
};
const int polecol[] = {0, 1, 2, 3, 3, 4, 6, 7, 9, 14};
const int jump[] = {-4, -4, -3, -3, -3, -3, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, 0, 0,
0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4};
@ -1076,52 +1101,29 @@ void EE::init() {
_rmode = false;
_shouldQuit = false;
_inited = true;
}
void EE::drawStatus(Common::String str, int x, uint32 color, int y, int color2, int w) {
if (color2)
_back.fillRect(Common::Rect(x, y, x + w, y + 10), color2);
_font.drawString(&_back, str, x, y + 1, w, color, Graphics::kTextAlignLeft, 0, false);
}
void EE::draw(int sn, int x, int y) {
void EE::draw(int sn, int x1, int y1) {
int x = x1 * _scale;
int y = y1 * _scale;
_back.transBlitFrom(_sp[sn], Common::Point(x, y), 0);
g_system->copyRectToOverlay(_back.getBasePtr(x, y),
_back.pitch,
MIN<int>(_windowX + x, g_system->getOverlayWidth()),
MIN<int>(_windowY + y, g_system->getOverlayHeight()),
MIN<int>(_sp[sn].w, g_system->getOverlayWidth() - MIN<int>(_windowX + x, g_system->getOverlayWidth())),
MIN<int>(_sp[sn].h, g_system->getOverlayHeight() - MIN<int>(_windowY + y, g_system->getOverlayHeight()) ));
g_system->copyRectToOverlay(_back.getBasePtr(x, y), _back.pitch, _windowX + x, _windowY + y, _sp[sn].w, _sp[sn].h);
}
const char *codes =
"Dvhgkm#Ztrsm|ffrs(#$%&'#$%&O}pes&}{1$M{tiq$%&'#$M{tiq${y5(Fsrv||hv%&'#$"
"Hutxxxjx'~v2%N|udr%&'#Gtsw}wiw&}{1$Hutxxxjx'#$%&'(#$%W|qw$%&'(#$%&'";
void EE::putshapes() {
int sprite;
cls(false);
if (_oCoords) {
g_system->copyRectToOverlay(_back.getBasePtr(_obx, _oby),
_back.pitch,
MIN<int>(_windowX + _obx, g_system->getOverlayWidth()),
MIN<int>(_windowY + _oby, g_system->getOverlayHeight()),
MIN<int>(_sp[kSpB1].w, g_system->getOverlayWidth() - MIN<int>(_windowX + _obx, g_system->getOverlayWidth())),
MIN<int>(_sp[kSpB1].h, g_system->getOverlayHeight() - MIN<int>(_windowY + _oby, g_system->getOverlayHeight()) ));
g_system->copyRectToOverlay(_back.getBasePtr(_olx, _oly),
_back.pitch,
MIN<int>(_windowX + _olx, g_system->getOverlayWidth()),
MIN<int>(_windowY + _oly, g_system->getOverlayHeight()),
MIN<int>(_sp[kSpL1].w, g_system->getOverlayWidth() - MIN<int>(_windowX + _olx, g_system->getOverlayWidth())),
MIN<int>(_sp[kSpL1].h, g_system->getOverlayHeight() - MIN<int>(_windowY + _oly, g_system->getOverlayHeight()) ));
g_system->copyRectToOverlay(_back.getBasePtr(_orx, _ory),
_back.pitch,
MIN<int>(_windowX + _orx, g_system->getOverlayWidth()),
MIN<int>(_windowY + _ory, g_system->getOverlayHeight()),
MIN<int>(_sp[kSpR1].w, g_system->getOverlayWidth() - MIN<int>(_windowX + _orx, g_system->getOverlayWidth())),
MIN<int>(_sp[kSpR1].h, g_system->getOverlayHeight() - MIN<int>(_windowY + _ory, g_system->getOverlayHeight()) ));
int obx = _obx * _scale, oby = _oby * _scale;
int olx = _olx * _scale, oly = _oly * _scale;
int orx = _orx * _scale, ory = _ory * _scale;
g_system->copyRectToOverlay(_back.getBasePtr(obx, oby), _back.pitch, _windowX + obx, _windowY + oby, _sp[kSpB1].w, _sp[kSpB1].h);
g_system->copyRectToOverlay(_back.getBasePtr(olx, oly), _back.pitch, _windowX + olx, _windowY + oly, _sp[kSpL1].w, _sp[kSpL1].h);
g_system->copyRectToOverlay(_back.getBasePtr(orx, ory), _back.pitch, _windowX + orx, _windowY + ory, _sp[kSpR1].w, _sp[kSpR1].h);
}
sprite = kSpB1 + (_tbx / 16) % 4;
@ -1169,65 +1171,40 @@ void EE::putshapes() {
const int *ptr = frames;
for (int i = 0; i < 6; i++, ptr += 4) {
Common::Rect r(ptr[0], ptr[1], ptr[2], ptr[3]);
Common::Rect r(ptr[0] * _scale, ptr[1] * _scale, ptr[2] * _scale, ptr[3] * _scale);
_back.fillRect(r, (i < 5 ? color1 : color2));
g_system->copyRectToOverlay(_back.getBasePtr(ptr[0], ptr[1]),
_back.pitch,
MIN<int>(_windowX + ptr[0], g_system->getOverlayWidth()),
MIN<int>(_windowY + ptr[1], g_system->getOverlayHeight()),
MIN<int>(r.width(), g_system->getOverlayWidth() - MIN<int>(_windowX + ptr[0], g_system->getOverlayWidth())),
MIN<int>(r.height(), g_system->getOverlayHeight() - MIN<int>(_windowY + ptr[1], g_system->getOverlayHeight()) ));
g_system->copyRectToOverlay(_back.getBasePtr(r.left, r.top), _back.pitch, _windowX + r.left, _windowY + r.top, r.width(), r.height());
}
int startx = 32;
for (int i = 0; i < 2; i++) {
int startx = i ? 264 : 32;
Common::String str = Common::String::format("%02d", _score[0]);
drawStatus(str, startx, _colorOrange);
startx += 16;
drawStatus((_server == 0) ? "*" : " ", startx, _colorBlue);
startx = 264;
str = Common::String::format("%02d", _score[1]);
drawStatus(str, startx, _colorOrange);
startx += 16;
drawStatus((_server == 1) ? "*" : " ", startx, _colorBlue);
draw(kSpNum0 + _score[i] / 10, startx, 1);
startx += 8;
draw(kSpNum0 + _score[i] % 10, startx, 1);
startx += 8;
draw(_server == i ? kSpStar : kSpSpace, startx, 1);
}
for (int i = 0; i < 6; i++) {
char buf[100];
int c;
for (c = 0; c < 23; c++)
buf[c] = codes[c + 23 * i] - 3 - c % 6;
buf[c] = 0;
int sx = i == 0 ? 92 : 80;
int sy = i == 0 ? 2 : 20;
int c1 = i == 0 ? _colorOrange : (i - 1 == _opt) ? 0 : _colorBlue;
int c2 = i - 1 == _opt ? _colorBlue : 0;
drawStatus(buf, sx, c1, sy + i * 10, c2);
int code = i == 0 ? kSpCode1 : i - 1 == _opt ? kSpCode1h + i : kSpCode1 + i;
draw(code, sx, sy + i * 10);
if (_mode != kModeMenu)
break;
}
g_system->copyRectToOverlay(_back.getPixels(),
_back.pitch,
MIN<int>(_windowX, g_system->getOverlayWidth()),
MIN<int>(_windowY, g_system->getOverlayHeight()),
MIN<int>(320, g_system->getOverlayWidth() - MIN<int>(_windowX, g_system->getOverlayWidth())),
MIN<int>(12, g_system->getOverlayHeight() - MIN<int>(_windowY, g_system->getOverlayHeight()) ));
g_system->copyRectToOverlay(_back.getPixels(), _back.pitch, _windowX, _windowY, _windowW, 10 * _scale);
if (_mode == kModeMenu) {
g_system->copyRectToOverlay(_back.getBasePtr(80, 30),
_back.pitch,
MIN<int>(_windowX + 80, g_system->getOverlayWidth()),
MIN<int>(_windowY + 30, g_system->getOverlayHeight()),
MIN<int>(250, g_system->getOverlayWidth() - MIN<int>(_windowX + 80, g_system->getOverlayWidth())),
MIN<int>(5 * 10, g_system->getOverlayHeight() - MIN<int>(_windowY + 30, g_system->getOverlayHeight()) ));
int x = 92 * _scale;
int y = 20 * _scale;
int w = _sp[kSpCode1].w;
int h = _sp[kSpCode1].h * 5;
g_system->copyRectToOverlay(_back.getBasePtr(x, y), _back.pitch, _windowX + x, _windowY + y, w, h);
}
}
@ -1337,47 +1314,62 @@ static const int spcolors[10 * 3] = {
0, 0, 0, 12, 12, 12
};
const char *codes =
"Dvhgkm#Ztrsm|ffrs(#$%&'#$%&O}pes&}{1$M{tiq$%&'#$M{tiq${y5(Fsrv||hv%&'#$"
"Hutxxxjx'~v2%N|udr%&'#Gtsw}wiw&}{1$Hutxxxjx'#$%&'(#$%W|qw$%&'(#$%&'";
void EE::genSprites() {
uint32 palette[12];
for (int i = 0; i < 10 * 3; i += 3)
palette[i / 3] = _back.format.RGBToColor(spcolors[i] * 16, spcolors[i + 1] * 16, spcolors[i + 2] * 16);
Graphics::Surface tmp;
int w = 25, h = 21;
tmp.create(w, h, g_system->getOverlayFormat());
for (int s = 0; s < 4; s++) {
_sp[kSpB1 + s].create(25, 21, g_system->getOverlayFormat());
int posy = 0, dy = 1;
if (s & 2) { posy = 20; dy = -1; }
for (int y = 0; y < 21; y++, posy += dy) {
for (int y = 0; y < h; y++, posy += dy) {
uint32 pixels = ball[y];
int posx = 0, dx = 1;
if (s & 1) { posx = 24; dx = -1; }
for (int x = 0; x < 25; x++, posx += dx) {
for (int x = 0; x < w; x++, posx += dx) {
int color = pixels & 1;
pixels >>= 1;
if (_back.format.bytesPerPixel == 2)
*((uint16 *)_sp[kSpB1 + s].getBasePtr(posx, posy)) = (uint16)palette[color + 8];
*((uint16 *)tmp.getBasePtr(posx, posy)) = (uint16)palette[color + 8];
else if (_back.format.bytesPerPixel == 4)
*((uint32 *)_sp[kSpB1 + s].getBasePtr(posx, posy)) = palette[color + 8];
*((uint32 *)tmp.getBasePtr(posx, posy)) = palette[color + 8];
}
}
Graphics::Surface *tmp2 = tmp.scale(w * _scale, h * _scale);
_sp[kSpB1 + s].copyFrom(*tmp2);
tmp2->free();
delete tmp2;
}
tmp.free();
w = 32;
h = 26;
tmp.create(w, h, g_system->getOverlayFormat());
for (int s = 0; s < 6; s++) {
_sp[kSpL1 + s].create(32, 26, g_system->getOverlayFormat());
for (int y = 0; y < 26; y++) {
for (int y = 0; y < h; y++) {
const uint32 *ptr = (y < 19) ? &head[y * 2] : &legs[(y - 19 + (s % 3) * 7) * 2];
uint32 pixels = *ptr++;
int posx = 0, dx = 1;
if (s > 2) { posx = 31; dx = -1; }
for (int x = 0; x < 32; x++, posx += dx) {
for (int x = 0; x < w; x++, posx += dx) {
int color = pixels & 3;
pixels >>= 2;
@ -1386,12 +1378,64 @@ void EE::genSprites() {
pixels = *ptr;
if (_back.format.bytesPerPixel == 2)
*((uint16 *)_sp[kSpL1 + s].getBasePtr(posx, y)) = (uint16)palette[color + 4 * (s / 3)];
*((uint16 *)tmp.getBasePtr(posx, y)) = (uint16)palette[color + 4 * (s / 3)];
else if (_back.format.bytesPerPixel == 4)
*((uint32 *)_sp[kSpL1 + s].getBasePtr(posx, y)) = palette[color + 4 * (s / 3)];
*((uint32 *)tmp.getBasePtr(posx, y)) = palette[color + 4 * (s / 3)];
}
}
Graphics::Surface *tmp2 = tmp.scale(w * _scale, h * _scale);
_sp[kSpL1 + s].copyFrom(*tmp2);
tmp2->free();
delete tmp2;
}
tmp.free();
w = 23 * 8;
h = 10;
tmp.create(w, h, g_system->getOverlayFormat());
for (int hl = 0; hl < 2; hl++) {
for (int i = 0; i < 6; i++) {
tmp.fillRect(Common::Rect(0, 0, w, h), hl == 1 ? _colorBlue : 0);
char buf[100];
int c;
for (c = 0; c < 23; c++)
buf[c] = codes[c + 23 * i] - 3 - c % 6;
buf[c] = 0;
int c1 = i == 0 ? _colorOrange : hl == 1 ? 0 : _colorBlue;
_font.drawString(&tmp, buf, 0, 1, w, c1, Graphics::kTextAlignLeft, 0, false);
Graphics::Surface *tmp2 = tmp.scale(w * _scale, h * _scale, true);
_sp[kSpCode1 + hl * 6 + i].copyFrom(*tmp2);
tmp2->free();
delete tmp2;
}
}
tmp.free();
w = 8;
h = 10;
tmp.create(w, h, g_system->getOverlayFormat());
for (int i = 0; i < 12; i++) {
tmp.fillRect(Common::Rect(0, 0, w, h), 0);
char buf[2];
buf[0] = i == 10 ? '*' : i == 11 ? ' ' : '0' + i;
buf[1] = 0;
int c = i > 9 ? _colorBlue : _colorOrange;
_font.drawString(&tmp, buf, 0, 1, w, c, Graphics::kTextAlignLeft, 0, false);
Graphics::Surface *tmp2 = tmp.scale(w * _scale, h * _scale, true);
_sp[kSpNum0 + i].copyFrom(*tmp2);
tmp2->free();
delete tmp2;
}
tmp.free();
}
} // End of namespace GUI