Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fixed render sizes and SDL_RenderSetLogicalSize for scaling #275

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/TextBox/SaveSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,8 @@ void TB_SaveSelect::SetVisible(bool enable, bool saving)

fCoords.w = 244;
fCoords.h = 152;
if (Renderer::getInstance()->widescreen)
{
fCoords.x = (Renderer::getInstance()->screenWidth / 2) - (fCoords.w / 2);
fCoords.y = 30;
}
else
{
fCoords.x = 38;
fCoords.y = 8;
}
fCoords.x = (Renderer::getInstance()->screenWidth / 2) - (fCoords.w / 2);
fCoords.y = 8;

fNumFiles = MAX_SAVE_SLOTS;
fSaving = saving;
Expand Down
51 changes: 18 additions & 33 deletions src/graphics/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,14 @@ Font::Font()
bool Font::load()
{
cleanup();
std::string font = std::string("font_" + std::to_string(Renderer::getInstance()->scale) + ".fnt");
std::string font = std::string("font_1.fnt");
LOG_DEBUG("Loading font file {}", font.c_str());

// special empty glyph
_glyphs[0] = Font::Glyph{0, 0, 0, 0, 0, 0, 0, 0, 0};

std::string path = ResourceManager::getInstance()->getPath(font);
if (ResourceManager::getInstance()->fileExists(path))
{
_upscale = 1;
}
else
{
_upscale = Renderer::getInstance()->scale;
font = std::string("font_1.fnt");
path = ResourceManager::getInstance()->getPath(font);
}
ResourceManager::getInstance()->fileExists(path);

LOG_DEBUG("Loading font file {}", path.c_str());

Expand Down Expand Up @@ -123,9 +114,6 @@ SDL_Texture *Font::atlas(uint32_t idx)

uint32_t Font::draw(int x, int y, const std::string &text, uint32_t color, bool isShaded)
{
x *= Renderer::getInstance()->scale;
y *= Renderer::getInstance()->scale;

int orgx = x;
int i = 0;
SDL_Rect dstrect;
Expand All @@ -152,8 +140,8 @@ uint32_t Font::draw(int x, int y, const std::string &text, uint32_t color, bool
{
if (_rendering)
{
int offset = (int)round(((double)_height / (double)Renderer::getInstance()->scale - 6.) / 2.);
Renderer::getInstance()->sprites.drawSprite((x / Renderer::getInstance()->scale), (y / Renderer::getInstance()->scale) + offset, SPR_TEXTBULLET);
int offset = (int)round(((double)_height - 6.) / 2.);
Renderer::getInstance()->sprites.drawSprite(x, y + offset, SPR_TEXTBULLET);
}
}
else if (_rendering && ch != ' ')
Expand All @@ -178,7 +166,7 @@ uint32_t Font::draw(int x, int y, const std::string &text, uint32_t color, bool
if (isShaded)
{
shdrect.x = x + (glyph.xoffset * _upscale);
shdrect.y = y + (glyph.yoffset * _upscale + _shadowOffset * Renderer::getInstance()->scale);
shdrect.y = y + (glyph.yoffset * _upscale + _shadowOffset);
shdrect.w = glyph.w * _upscale;
shdrect.h = glyph.h * _upscale;
SDL_SetTextureColorMod(atlas, 0, 0, 0);
Expand All @@ -194,21 +182,21 @@ uint32_t Font::draw(int x, int y, const std::string &text, uint32_t color, bool
{ // 10.5 px for spaces - make smaller than they really are - the default
if (rtl())
{
x -= (Renderer::getInstance()->scale == 1) ? 5 : 10;
x -= 5;
if (i & 1)
x--;
}
else
{
x += (Renderer::getInstance()->scale == 1) ? 5 : 10;
x += 5;
if (i & 1)
x++;
}
}
else if (ch == '=' && game.mode != GM_CREDITS)
{
if (rtl()) x -= 7 * Renderer::getInstance()->scale;
else x += 7 * Renderer::getInstance()->scale;
if (rtl()) x -= 7;
else x += 7;
}
else
{
Expand All @@ -219,14 +207,11 @@ uint32_t Font::draw(int x, int y, const std::string &text, uint32_t color, bool
}

// return the final width of the text drawn
return abs((x - orgx) / Renderer::getInstance()->scale);
return abs(x - orgx);
}

uint32_t Font::drawLTR(int x, int y, const std::string &text, uint32_t color, bool isShaded)
{
x *= Renderer::getInstance()->scale;
y *= Renderer::getInstance()->scale;

int orgx = x;
int i = 0;
SDL_Rect dstrect;
Expand All @@ -252,8 +237,8 @@ uint32_t Font::drawLTR(int x, int y, const std::string &text, uint32_t color, bo
{
if (_rendering)
{
int offset = (int)round(((double)_height / (double)Renderer::getInstance()->scale - 6.) / 2.);
Renderer::getInstance()->sprites.drawSprite((x / Renderer::getInstance()->scale), (y / Renderer::getInstance()->scale) + offset, SPR_TEXTBULLET);
int offset = (int)round(((double)_height - 6.) / 2.);
Renderer::getInstance()->sprites.drawSprite(x, y + offset, SPR_TEXTBULLET);
}
}
else if (_rendering && ch != ' ')
Expand All @@ -278,7 +263,7 @@ uint32_t Font::drawLTR(int x, int y, const std::string &text, uint32_t color, bo
if (isShaded)
{
shdrect.x = x + (glyph.xoffset * _upscale);
shdrect.y = y + glyph.yoffset * _upscale + _shadowOffset * Renderer::getInstance()->scale;
shdrect.y = y + glyph.yoffset * _upscale + _shadowOffset;
shdrect.w = glyph.w * _upscale;
shdrect.h = glyph.h * _upscale;
SDL_SetTextureColorMod(atlas, 0, 0, 0);
Expand All @@ -292,13 +277,13 @@ uint32_t Font::drawLTR(int x, int y, const std::string &text, uint32_t color, bo

if (ch == ' ')
{ // 10.5 px for spaces - make smaller than they really are - the default
x += (Renderer::getInstance()->scale == 1) ? 5 : 10;
x += 5;
if (i & 1)
x++;
}
else if (ch == '=' && game.mode != GM_CREDITS)
{
x += 7 * Renderer::getInstance()->scale;
x += 7;
}
else
{
Expand All @@ -308,7 +293,7 @@ uint32_t Font::drawLTR(int x, int y, const std::string &text, uint32_t color, bo
}

// return the final width of the text drawn
return abs((x - orgx) / Renderer::getInstance()->scale);
return abs(x - orgx);
}

uint32_t Font::getWidth(const std::string &text)
Expand All @@ -324,12 +309,12 @@ uint32_t Font::getWidth(const std::string &text)

uint32_t Font::getHeight() const
{
return _height / ((_upscale == 1) ? Renderer::getInstance()->scale : 1);
return _height;
}

uint32_t Font::getBase() const
{
return _base / ((_upscale == 1) ? Renderer::getInstance()->scale : 1);
return _base;
}

}; // namespace Graphics
Expand Down
Loading