Fix scaled things

This commit is contained in:
Pk11
2021-01-14 12:35:56 -06:00
parent ca9dc8250b
commit e663a46a57
3 changed files with 43 additions and 41 deletions
+20 -17
View File
@@ -216,6 +216,9 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
}
const int xStart = x;
if(maxWidth != 0)
scaleX = std::min(scaleX, (float)maxWidth / (calcWidth(text) * scaleX));
bool rtl = false;
for(const auto c : text) {
if(c >= 0x0590 && c <= 0x05FF) {
@@ -273,7 +276,7 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
if(*it == '\n') {
x = xStart;
y += tileHeight;
y += tileHeight * scaleY;
continue;
}
@@ -322,44 +325,44 @@ ITCM_CODE void Font::print(std::u16string_view text, int x, int y, bool top, int
// Don't draw off screen chars
if(x >= 0 && x + fontWidths[(index * 3) + 2] < 256 && y >= 0 && y + tileHeight < 192) {
#ifdef TEXT_BUFFERED
u8 *dst = textBuf[top] + x + fontWidths[(index * 3)];
u8 *dst = textBuf[top] + y * 256 + x + fontWidths[(index * 3)];
#else
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4) + x + fontWidths[(index * 3)];
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4) + y * 256 + x + fontWidths[(index * 3)];
#endif
// Use faster integer math if scale is 1
if(scaleX == 1.0f && scaleY == 1.0f) {
for(int i = 0; i < tileHeight; i++) {
for(int j = 0; j < tileWidth; j++) {
u8 px = fontTiles[(index * tileSize) + (i * tileWidth + j) / 4] >>
((3 - ((i * tileWidth + j) % 4)) * 2) &
3;
if(px)
((3 - ((i * tileWidth + j) % 4)) * 2) & 3;
if(px) {
#ifdef TEXT_BUFFERED
dst[(y + i) * 256 + j] = px + (color * 4);
dst[i * 256 + j] = px + (color * 4);
#else
toncset(dst + (y + i) * 256 + j, px + (color * 4), 1);
toncset(dst + i * 256 + j, px + (color * 4), 1);
#endif
}
}
}
} else {
for(float i = 0.0f; i < tileHeight; i += 1 / scaleY) {
for(float j = 0.0f; j < tileWidth; j += 1 / scaleX) {
u8 px = fontTiles[(index * tileSize) + int(i * tileWidth + j) / 4] >>
((3 - (int(i * tileWidth + j) % 4)) * 2) &
3;
if(px)
for(int i = 0; i < tileHeight * scaleY; i++) {
for(int j = 0; j < tileWidth * scaleX; j++) {
u8 loc = int(i / scaleY) * tileWidth + int(j / scaleX);
u8 px = fontTiles[index * tileSize + loc / 4] >> ((3 - (loc % 4)) * 2) & 3;
if(px) {
#ifdef TEXT_BUFFERED
dst[int((y + i) * 256 + j)] = px + (color * 4);
dst[i * 256 + j] = px + (color * 4);
#else
toncset(dst + int((y + i) * 256 + j), px + (color * 4), 1);
toncset(dst + i * 256 + j, px + (color * 4), 1);
#endif
}
}
}
}
}
}
x += fontWidths[(index * 3) + 2];
x += fontWidths[(index * 3) + 2] * scaleX;
}
}
+15 -16
View File
@@ -93,10 +93,10 @@ void Image::draw(int x, int y, bool top, int layer, int channel, bool copyPal) {
// If full width and X is 0, copy it all in one go
if(_width == width && x == 0) {
dmaCopyHalfWords(channel, _bitmap.data(), dst, _width * _height);
tonccpy(dst, _bitmap.data(), _width * _height);
} else {
for(int i = 0; i < _height; i++) {
dmaCopyHalfWords(channel, _bitmap.data() + (i * _width), dst + (y + i) * 256 + x, _width);
tonccpy(dst + (y + i) * 256 + x, _bitmap.data() + i * _width, _width);
}
}
}
@@ -106,7 +106,7 @@ void Image::drawSpecial(int x, int y, bool top, int layer, float scaleX, float s
if(copyPal)
tonccpy((top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs + paletteOffset, _palette.data(), _palette.size() * 2);
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4);
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4) + y * 256 + x;
// If the scale is 1 use faster integer math
if(scaleX == 1.0f && scaleY == 1.0f) {
@@ -114,15 +114,15 @@ void Image::drawSpecial(int x, int y, bool top, int layer, float scaleX, float s
for(float j = 0; j < _width; j++) {
u8 px = _bitmap[i * _width + j];
if(_palette[px - _palOfs] & 0x8000)
toncset(dst + int((y + i) * 256 + x + j), px + paletteOffset, 1);
toncset(dst + i * 256 + x, px + paletteOffset, 1);
}
}
} else {
for(float i = 0.0f; i < _height; i += 1 / scaleY) {
for(float j = 0.0f; j < _width; j += 1 / scaleX) {
u8 px = _bitmap[int((i * _width) + j)];
for(int i = 0; i < _height * scaleY; i++) {
for(int j = 0; j < _width * scaleX; j++) {
u8 px = _bitmap[int(i / scaleY) * _width + int(j / scaleX)];
if(_palette[px - _palOfs] & 0x8000)
toncset(dst + int((y + i) * 256 + x + j), px + paletteOffset, 1);
toncset(dst + i * 256 + j, px + paletteOffset, 1);
}
}
}
@@ -134,8 +134,7 @@ void Image::drawSegment(int x, int y, int imageX, int imageY, int w, int h, bool
tonccpy((top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs, _palette.data(), _palette.size() * 2);
for(int i = 0; i < h; i++) {
dmaCopyHalfWords(channel, _bitmap.data() + ((imageY + i) * _width) + imageX,
(u8 *)bgGetGfxPtr(top ? layer : layer + 4) + ((y + i) * 256) + x, w);
tonccpy((u8 *)bgGetGfxPtr(top ? layer : layer + 4) + (y + i) * 256 + x, _bitmap.data() + (imageY + i) * _width + imageX, w);
}
}
@@ -144,7 +143,7 @@ void Image::drawSegmentSpecial(int x, int y, int imageX, int imageY, int w, int
if(copyPal)
tonccpy((top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs + paletteOffset, _palette.data(), _palette.size() * 2);
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4);
u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4) + y * 256 + x;
// If the scale is 1 use faster integer math
if(scaleX == 1.0f && scaleY == 1.0f) {
@@ -152,15 +151,15 @@ void Image::drawSegmentSpecial(int x, int y, int imageX, int imageY, int w, int
for(int j = 0; j < w; j++) {
u8 px = _bitmap[i * _width + j];
if(_palette[px - _palOfs] & 0x8000)
toncset(dst + ((y + i) * 256 + x + j), px + paletteOffset, 1);
toncset(dst + i * 256 + j, px + paletteOffset, 1);
}
}
} else {
for(float i = 0; i < h; i += 1 / scaleX) {
for(float j = 0; j < _width; j += 1 / scaleY) {
u8 px = _bitmap[i * _width + j];
for(int i = 0; i < h * scaleY; i++) {
for(int j = 0; j < w * scaleX; j++) {
u8 px = _bitmap[(imageY + int(i / scaleY)) * _width + imageX + int(j / scaleX)];
if(_palette[px - _palOfs] & 0x8000)
toncset(dst + int((y + i) * 256 + x + j), px + paletteOffset, 1);
toncset(dst + i * 256 + j, px + paletteOffset, 1);
}
}
}
+8 -8
View File
@@ -159,11 +159,11 @@ void Sprite::drawImage(int x, int y, const Image &image, float scaleX, float sca
}
}
} else {
for(float i = 0.0f; i < image.height(); i += 1 / scaleY) {
for(float j = 0.0f; j < image.width(); j += 1 / scaleX) {
u16 px = image.palette()[image.bitmap()[int(i * image.width() + j)] - image.palOfs()];
for(int i = 0; i < image.height() * scaleY; i++) {
for(int j = 0; j < image.width() * scaleX; j++) {
u16 px = image.palette()[image.bitmap()[int(i / scaleY) * image.width() + int(j / scaleX)] - image.palOfs()];
if(px & 0x8000)
toncset16(_gfx + int((y + i) * _height + j) + x, px, 1);
toncset16(_gfx + (y + i) * _height + j + x, px, 1);
}
}
}
@@ -181,11 +181,11 @@ void Sprite::drawImageSegment(int x, int y, int imageX, int imageY, int w, int h
}
}
} else {
for(float i = 0; i < h; i += 1 / scaleX) {
for(float j = 0; j < image.width(); j += 1 / scaleY) {
u16 px = image.palette()[image.bitmap()[(imageY + i) * image.width() + imageX + j] - image.palOfs()];
for(int i = 0; i < h * scaleY; i++) {
for(int j = 0; j < w * scaleX; j++) {
u16 px = image.palette()[image.bitmap()[(imageY + int(i / scaleY)) * image.width() + imageX + int(j / scaleX)] - image.palOfs()];
if(px & 0x8000)
toncset16(_gfx + int((y + i) * _height + x + j), px, 1);
toncset16(_gfx + (y + i) * _height + x + j, px, 1);
}
}
}