Skip to content

Commit

Permalink
Merge pull request #19227 from hrydgard/more-text-fixes
Browse files Browse the repository at this point in the history
More text fixes on iOS/Mac
  • Loading branch information
hrydgard authored Jun 1, 2024
2 parents f2e15c3 + 81c642e commit d298c6f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Common/Math/curves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ float linearOut(int t, int fadeOutLength) {
}

float ease(float val) {
if (val > 1.0f) return 1.0f;
if (val < 0.0f) return 0.0f;
if (val >= 1.0f) return 1.0f;
if (val <= 0.0f) return 0.0f;
return (float)(((-cosf(val * PI)) + 1.0f) * 0.5);
}

float ease(int t, int fadeLength)
{
if (t < 0) return 0.0f;
if (t <= 0.0f) return 0.0f;
if (t >= fadeLength) return 1.0f;
return ease((float)t / (float)fadeLength);
}
Expand Down
8 changes: 4 additions & 4 deletions Common/Render/Text/draw_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ void TextDrawer::DrawString(DrawBuffer &target, std::string_view str, float x, f
draw_->BindTexture(0, entry->texture);

// Okay, the texture is bound, let's draw.
float w = entry->width * fontScaleX_ * dpiScale_;
float h = entry->height * fontScaleY_ * dpiScale_;
float u = entry->width / (float)entry->bmWidth;
float v = entry->height / (float)entry->bmHeight;
float w = (float)entry->width * (fontScaleX_ * dpiScale_);
float h = (float)entry->height * (fontScaleY_ * dpiScale_);
float u = (float)entry->width / (float)entry->bmWidth;
float v = (float)entry->height / (float)entry->bmHeight;
DrawBuffer::DoAlign(align, &x, &y, &w, &h);

target.DrawTexRect(x, y, x + w, y + h, 0.0f, 0.0f, u, v, color);
Expand Down
4 changes: 2 additions & 2 deletions Common/Render/Text/draw_text_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ void Destroy() {
float w, h;
MeasureString(str, &w, &h);
// Reverse the DPI scale that MeasureString baked in.
w /= dpiScale_;
h /= dpiScale_;
w /= (dpiScale_ * fontScaleX_);
h /= (dpiScale_ * fontScaleY_);

int width = (int)ceilf(w);
int height = (int)ceilf(h);
Expand Down
4 changes: 1 addition & 3 deletions UI/MiscScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,15 +1041,13 @@ void CreditsScreen::DrawForeground(UIContext &dc) {
float t = (float)(time_now_d() - startTime_) * 60.0;

float y = bounds.y2() - fmodf(t, (float)totalHeight);
std::string line;
for (int i = 0; i < numItems; i++) {
float alpha = linearInOut(y+32, 64, bounds.y2() - 192, 64);
uint32_t textColor = colorAlpha(dc.theme->infoStyle.fgColor, alpha);

if (alpha > 0.0f) {
dc.SetFontScale(ease(alpha), ease(alpha));
line = credits[i];
dc.DrawText(line.c_str(), bounds.centerX(), y, textColor, ALIGN_HCENTER);
dc.DrawText(credits[i], bounds.centerX(), y, textColor, ALIGN_HCENTER);
dc.SetFontScale(1.0f, 1.0f);
}
y += itemHeight;
Expand Down

0 comments on commit d298c6f

Please sign in to comment.