Improved menu system font rendering on GPUs without proper texture filtering support

This commit is contained in:
Leon Styhre 2023-07-29 18:41:43 +02:00
parent abc3eab99c
commit e5758d047e
4 changed files with 18 additions and 19 deletions

View file

@ -60,7 +60,7 @@ float ComponentGrid::getRowHeight(int row)
assert(row >= 0 && row < mGridSize.y);
if (mRowHeights[row] != 0)
return mRowHeights[row] * mSize.y;
return std::round(mRowHeights[row] * mSize.y);
// Calculate automatic height.
float freeHeightPerc {1.0f};
@ -71,7 +71,7 @@ float ComponentGrid::getRowHeight(int row)
++between;
}
return (freeHeightPerc * mSize.y) / static_cast<float>(between);
return std::round((freeHeightPerc * mSize.y) / static_cast<float>(between));
}
void ComponentGrid::setColWidthPerc(int col, float width, bool update)

View file

@ -433,7 +433,7 @@ void ComponentList::updateElementPosition(const ComponentListRow& row)
const auto comp = row.elements.at(i).component;
// Center vertically.
comp->setPosition(x, (mRowHeight - comp->getSize().y) / 2.0f + yOffset);
comp->setPosition(x, (mRowHeight - std::floor(comp->getSize().y)) / 2.0f + yOffset);
x += comp->getSize().x;
}
}

View file

@ -44,13 +44,13 @@ GuiInfoPopup::GuiInfoPopup(std::string message, int duration)
}
// Add a padding to the box.
int paddingX = static_cast<int>(Renderer::getScreenWidth() * 0.03f);
int paddingY = static_cast<int>(Renderer::getScreenHeight() * 0.02f);
mSize.x = mSize.x + paddingX;
mSize.y = mSize.y + paddingY;
int paddingX {static_cast<int>(Renderer::getScreenWidth() * 0.03f)};
int paddingY {static_cast<int>(Renderer::getScreenHeight() * 0.02f)};
mSize.x += paddingX;
mSize.y += paddingY;
float posX = Renderer::getScreenWidth() * 0.5f - mSize.x * 0.5f;
float posY = Renderer::getScreenHeight() * 0.02f;
float posX {Renderer::getScreenWidth() * 0.5f - mSize.x * 0.5f};
float posY {Renderer::getScreenHeight() * 0.02f};
setPosition(posX, posY, 0);
@ -61,9 +61,9 @@ GuiInfoPopup::GuiInfoPopup(std::string message, int duration)
// We only initialize the actual time when we first start to render.
mStartTime = 0;
mGrid = new ComponentGrid(glm::ivec2 {1, 3});
mGrid = new ComponentGrid(glm::ivec2 {1, 1});
mGrid->setSize(mSize);
mGrid->setEntry(s, glm::ivec2 {0, 1}, false, true);
mGrid->setEntry(s, glm::ivec2 {0, 0}, false, true);
addChild(mGrid);
}
@ -76,7 +76,7 @@ GuiInfoPopup::~GuiInfoPopup()
void GuiInfoPopup::render(const glm::mat4& /*parentTrans*/)
{
// We use getIdentity() as we want to render on a specific window position, not on the view.
glm::mat4 trans {getTransform() * Renderer::getIdentity()};
const glm::mat4 trans {getTransform() * Renderer::getIdentity()};
if (mRunning && updateState()) {
// If we're still supposed to be rendering it.
mRenderer->setMatrix(trans);
@ -86,7 +86,7 @@ void GuiInfoPopup::render(const glm::mat4& /*parentTrans*/)
bool GuiInfoPopup::updateState()
{
int curTime = SDL_GetTicks();
const int curTime {static_cast<int>(SDL_GetTicks())};
// We only initialize the actual time when we first start to render.
if (mStartTime == 0)

View file

@ -89,14 +89,14 @@ GuiMsgBox::GuiMsgBox(const HelpStyle& helpstyle,
width = mButtonGrid->getSize().x;
}
// Now that we know width, we can find height.
// Now that we know the width, we can calculate the height.
mMsg->setSize(width, 0.0f); // mMsg->getSize.y() now returns the proper length.
const float msgHeight {std::max(Font::get(FONT_SIZE_LARGE)->getHeight(),
mMsg->getSize().y * VERTICAL_PADDING_MODIFIER)};
setSize(width + std::ceil(HORIZONTAL_PADDING_PX * 2.0f * mRenderer->getScreenWidthModifier()),
msgHeight + mButtonGrid->getSize().y);
setSize(std::round(width + std::ceil(HORIZONTAL_PADDING_PX * 2.0f *
mRenderer->getScreenWidthModifier())),
std::round(msgHeight + mButtonGrid->getSize().y));
// Center for good measure.
setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f,
(mRenderer->getScreenHeight() - mSize.y) / 2.0f);
@ -133,7 +133,7 @@ void GuiMsgBox::changeText(const std::string& newText)
width = mButtonGrid->getSize().x;
}
// Now that we know width, we can find height.
// Now that we know the width, we can calculate the height.
mMsg->setSize(width, 0.0f); // mMsg->getSize.y() now returns the proper height.
newSize = mMsg->getSize();
newSize.y *= VERTICAL_PADDING_MODIFIER;
@ -169,7 +169,6 @@ void GuiMsgBox::onSizeChanged()
mGrid.setSize(mSize);
mGrid.setRowHeightPerc(1, mButtonGrid->getSize().y / mSize.y);
// Update messagebox size.
mMsg->setSize(mSize.x - HORIZONTAL_PADDING_PX * 2.0f * Renderer::getScreenWidthModifier(),
mGrid.getRowHeight(0));
mGrid.onSizeChanged();