diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 628213770e..5d30ce364c 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -284,7 +284,7 @@ void GameButton::Draw(UIContext &dc) { title_ = ReplaceAll(title_, "\n", " "); } - dc.MeasureText(dc.GetFontStyle(), title_.c_str(), &tw, &th, 0); + dc.MeasureText(dc.GetFontStyle(), 1.0f, 1.0f, title_.c_str(), &tw, &th, 0); int availableWidth = bounds_.w - 150; float sineWidth = std::max(0.0f, (tw - availableWidth)) / 2.0f; @@ -367,7 +367,7 @@ void DirButton::Draw(UIContext &dc) { } float tw, th; - dc.MeasureText(dc.GetFontStyle(), text.c_str(), &tw, &th, 0); + dc.MeasureText(dc.GetFontStyle(), 1.0f, 1.0f, text.c_str(), &tw, &th, 0); bool compact = bounds_.w < 180; diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index eb4646e5a2..cd9152d837 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -16,7 +16,7 @@ void OnScreenMessagesView::Draw(UIContext &dc) { // Get height float w, h; - dc.MeasureText(dc.theme->uiFont, "Wg", &w, &h); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, "Wg", &w, &h); float y = 10.0f; // Then draw them all. @@ -27,7 +27,7 @@ void OnScreenMessagesView::Draw(UIContext &dc) { if (alpha < 0.0) alpha = 0.0f; // Messages that are wider than the screen are left-aligned instead of centered. float tw, th; - dc.MeasureText(dc.theme->uiFont, iter->text.c_str(), &tw, &th); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, iter->text.c_str(), &tw, &th); float x = bounds_.centerX(); int align = ALIGN_TOP | ALIGN_HCENTER; if (tw > bounds_.w) { diff --git a/UI/SavedataScreen.cpp b/UI/SavedataScreen.cpp index d7bdd87c7b..75ee3974b5 100644 --- a/UI/SavedataScreen.cpp +++ b/UI/SavedataScreen.cpp @@ -251,7 +251,7 @@ void SavedataButton::Draw(UIContext &dc) { subtitle_ = CleanSaveString(savedata_title) + StringFromFormat(" (%d kB)", ginfo->gameSize / 1024); } - dc.MeasureText(dc.GetFontStyle(), title_.c_str(), &tw, &th, 0); + dc.MeasureText(dc.GetFontStyle(), 1.0f, 1.0f, title_.c_str(), &tw, &th, 0); int availableWidth = bounds_.w - 150; float sineWidth = std::max(0.0f, (tw - availableWidth)) / 2.0f; diff --git a/ext/native/ui/ui_context.cpp b/ext/native/ui/ui_context.cpp index 979b1afe6a..def2ac7017 100644 --- a/ext/native/ui/ui_context.cpp +++ b/ext/native/ui/ui_context.cpp @@ -127,36 +127,36 @@ void UIContext::SetFontStyle(const UI::FontStyle &fontStyle) { } } -void UIContext::MeasureText(const UI::FontStyle &style, const char *str, float *x, float *y, int align) const { - MeasureTextCount(style, str, (int)strlen(str), x, y, align); +void UIContext::MeasureText(const UI::FontStyle &style, float scaleX, float scaleY, const char *str, float *x, float *y, int align) const { + MeasureTextCount(style, scaleX, scaleY, str, (int)strlen(str), x, y, align); } -void UIContext::MeasureTextCount(const UI::FontStyle &style, const char *str, int count, float *x, float *y, int align) const { +void UIContext::MeasureTextCount(const UI::FontStyle &style, float scaleX, float scaleY, const char *str, int count, float *x, float *y, int align) const { if (!textDrawer_ || (align & FLAG_DYNAMIC_ASCII)) { float sizeFactor = (float)style.sizePts / 24.0f; - Draw()->SetFontScale(fontScaleX_ * sizeFactor, fontScaleY_ * sizeFactor); + Draw()->SetFontScale(scaleX * sizeFactor, scaleY * sizeFactor); Draw()->MeasureTextCount(style.atlasFont, str, count, x, y); } else { textDrawer_->SetFont(style.fontName.c_str(), style.sizePts, style.flags); - textDrawer_->SetFontScale(fontScaleX_, fontScaleY_); + textDrawer_->SetFontScale(scaleX, scaleY); textDrawer_->MeasureString(str, count, x, y); textDrawer_->SetFont(fontStyle_->fontName.c_str(), fontStyle_->sizePts, fontStyle_->flags); } } -void UIContext::MeasureTextRect(const UI::FontStyle &style, const char *str, int count, const Bounds &bounds, float *x, float *y, int align) const { +void UIContext::MeasureTextRect(const UI::FontStyle &style, float scaleX, float scaleY, const char *str, int count, const Bounds &bounds, float *x, float *y, int align) const { if ((align & FLAG_WRAP_TEXT) == 0) { - MeasureTextCount(style, str, count, x, y, align); + MeasureTextCount(style, scaleX, scaleY, str, count, x, y, align); return; } if (!textDrawer_ || (align & FLAG_DYNAMIC_ASCII)) { float sizeFactor = (float)style.sizePts / 24.0f; - Draw()->SetFontScale(fontScaleX_ * sizeFactor, fontScaleY_ * sizeFactor); + Draw()->SetFontScale(scaleX * sizeFactor, scaleY * sizeFactor); Draw()->MeasureTextRect(style.atlasFont, str, count, bounds, x, y, align); } else { textDrawer_->SetFont(style.fontName.c_str(), style.sizePts, style.flags); - textDrawer_->SetFontScale(fontScaleX_, fontScaleY_); + textDrawer_->SetFontScale(scaleX, scaleY); textDrawer_->MeasureStringRect(str, count, bounds, x, y, align); textDrawer_->SetFont(fontStyle_->fontName.c_str(), fontStyle_->sizePts, fontStyle_->flags); } diff --git a/ext/native/ui/ui_context.h b/ext/native/ui/ui_context.h index 22f944148c..ccb0a7ddca 100644 --- a/ext/native/ui/ui_context.h +++ b/ext/native/ui/ui_context.h @@ -59,9 +59,9 @@ public: void SetFontStyle(const UI::FontStyle &style); const UI::FontStyle &GetFontStyle() { return *fontStyle_; } void SetFontScale(float scaleX, float scaleY); - void MeasureTextCount(const UI::FontStyle &style, const char *str, int count, float *x, float *y, int align = 0) const; - void MeasureText(const UI::FontStyle &style, const char *str, float *x, float *y, int align = 0) const; - void MeasureTextRect(const UI::FontStyle &style, const char *str, int count, const Bounds &bounds, float *x, float *y, int align = 0) const; + void MeasureTextCount(const UI::FontStyle &style, float scaleX, float scaleY, const char *str, int count, float *x, float *y, int align = 0) const; + void MeasureText(const UI::FontStyle &style, float scaleX, float scaleY, const char *str, float *x, float *y, int align = 0) const; + void MeasureTextRect(const UI::FontStyle &style, float scaleX, float scaleY, const char *str, int count, const Bounds &bounds, float *x, float *y, int align = 0) const; void DrawText(const char *str, float x, float y, uint32_t color, int align = 0); void DrawTextShadow(const char *str, float x, float y, uint32_t color, int align = 0); void DrawTextRect(const char *str, const Bounds &bounds, uint32_t color, int align = 0); diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index e4acf73df6..a2bf128087 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -369,7 +369,7 @@ void PopupMultiChoice::Draw(UIContext &dc) { dc.SetFontStyle(dc.theme->uiFont); float ignore; - dc.MeasureText(dc.theme->uiFont, valueText_.c_str(), &textPadding_.right, &ignore, ALIGN_RIGHT | ALIGN_VCENTER); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, valueText_.c_str(), &textPadding_.right, &ignore, ALIGN_RIGHT | ALIGN_VCENTER); textPadding_.right += paddingX; Choice::Draw(dc); @@ -435,7 +435,7 @@ void PopupSliderChoice::Draw(UIContext &dc) { } float ignore; - dc.MeasureText(dc.theme->uiFont, temp, &textPadding_.right, &ignore, ALIGN_RIGHT | ALIGN_VCENTER); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, temp, &textPadding_.right, &ignore, ALIGN_RIGHT | ALIGN_VCENTER); textPadding_.right += paddingX; Choice::Draw(dc); @@ -477,7 +477,7 @@ void PopupSliderChoiceFloat::Draw(UIContext &dc) { } float ignore; - dc.MeasureText(dc.theme->uiFont, temp, &textPadding_.right, &ignore, ALIGN_RIGHT | ALIGN_VCENTER); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, temp, &textPadding_.right, &ignore, ALIGN_RIGHT | ALIGN_VCENTER); textPadding_.right += paddingX; Choice::Draw(dc); @@ -667,7 +667,7 @@ void PopupTextInputChoice::Draw(UIContext &dc) { dc.SetFontStyle(dc.theme->uiFont); float ignore; - dc.MeasureText(dc.theme->uiFont, value_->c_str(), &textPadding_.right, &ignore, ALIGN_RIGHT | ALIGN_VCENTER); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, value_->c_str(), &textPadding_.right, &ignore, ALIGN_RIGHT | ALIGN_VCENTER); textPadding_.right += paddingX; Choice::Draw(dc); @@ -726,7 +726,7 @@ void ChoiceWithValueDisplay::Draw(UIContext &dc) { } float ignore; - dc.MeasureText(dc.theme->uiFont, valueText.str().c_str(), &textPadding_.right, &ignore, ALIGN_RIGHT | ALIGN_VCENTER); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, valueText.str().c_str(), &textPadding_.right, &ignore, ALIGN_RIGHT | ALIGN_VCENTER); textPadding_.right += paddingX; Choice::Draw(dc); diff --git a/ext/native/ui/view.cpp b/ext/native/ui/view.cpp index 6f09ad0b22..2191358f83 100644 --- a/ext/native/ui/view.cpp +++ b/ext/native/ui/view.cpp @@ -443,7 +443,7 @@ void Choice::GetContentDimensions(const UIContext &dc, float &w, float &h) const w = img.w; h = img.h; } else { - dc.MeasureText(dc.theme->uiFont, text_.c_str(), &w, &h); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, text_.c_str(), &w, &h); } w += 24; h += 16; @@ -485,7 +485,7 @@ void Choice::Draw(UIContext &dc) { float scale = 1.0f; float actualWidth, actualHeight; - dc.MeasureText(dc.theme->uiFont, text_.c_str(), &actualWidth, &actualHeight, ALIGN_VCENTER); + dc.MeasureText(dc.theme->uiFont, scale, scale, text_.c_str(), &actualWidth, &actualHeight, ALIGN_VCENTER); if (actualWidth > availWidth) { scale = std::max(MIN_TEXT_SCALE, availWidth / actualWidth); } @@ -541,7 +541,7 @@ void PopupHeader::Draw(UIContext &dc) { float tw, th; dc.SetFontStyle(dc.theme->uiFont); - dc.MeasureText(dc.GetFontStyle(), text_.c_str(), &tw, &th, 0); + dc.MeasureText(dc.GetFontStyle(), 1.0f, 1.0f, text_.c_str(), &tw, &th, 0); float sineWidth = std::max(0.0f, (tw - availableWidth)) / 2.0f; @@ -591,7 +591,7 @@ void CheckBox::Draw(UIContext &dc) { float scale = 1.0f; float actualWidth, actualHeight; - dc.MeasureText(dc.theme->uiFont, text_.c_str(), &actualWidth, &actualHeight, ALIGN_VCENTER); + dc.MeasureText(dc.theme->uiFont, scale, scale, text_.c_str(), &actualWidth, &actualHeight, ALIGN_VCENTER); if (actualWidth > availWidth) { scale = std::max(MIN_TEXT_SCALE, availWidth / actualWidth); } @@ -608,7 +608,7 @@ void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const w = img->w; h = img->h; } else { - dc.MeasureText(dc.theme->uiFont, text_.c_str(), &w, &h); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, text_.c_str(), &w, &h); } // Add some internal padding to not look totally ugly w += 16; @@ -625,7 +625,7 @@ void Button::Draw(UIContext &dc) { // dc.Draw()->DrawImage4Grid(style.image, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), style.bgColor); dc.FillRect(style.background, bounds_); float tw, th; - dc.MeasureText(dc.theme->uiFont, text_.c_str(), &tw, &th); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, text_.c_str(), &tw, &th); if (tw > bounds_.w || imageID_ != -1) { dc.PushScissor(bounds_); } @@ -690,7 +690,7 @@ void TextView::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz bounds.h = vert.size == 0 ? 1000.f : vert.size; } ApplyBoundsBySpec(bounds, horiz, vert); - dc.MeasureTextRect(small_ ? dc.theme->uiFontSmall : dc.theme->uiFont, text_.c_str(), (int)text_.length(), bounds, &w, &h, textAlign_); + dc.MeasureTextRect(small_ ? dc.theme->uiFontSmall : dc.theme->uiFont, 1.0f, 1.0f, text_.c_str(), (int)text_.length(), bounds, &w, &h, textAlign_); } void TextView::Draw(UIContext &dc) { @@ -749,7 +749,7 @@ void TextEdit::Draw(UIContext &dc) { if (HasFocus()) { // Hack to find the caret position. Might want to find a better way... - dc.MeasureTextCount(dc.theme->uiFont, text_.c_str(), caret_, &w, &h, ALIGN_VCENTER | ALIGN_LEFT); + dc.MeasureTextCount(dc.theme->uiFont, 1.0f, 1.0f, text_.c_str(), caret_, &w, &h, ALIGN_VCENTER | ALIGN_LEFT); float caretX = w; caretX += textX; @@ -763,7 +763,7 @@ void TextEdit::Draw(UIContext &dc) { } void TextEdit::GetContentDimensions(const UIContext &dc, float &w, float &h) const { - dc.MeasureText(dc.theme->uiFont, text_.size() ? text_.c_str() : "Wj", &w, &h); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, text_.size() ? text_.c_str() : "Wj", &w, &h); w += 2; h += 2; } @@ -932,7 +932,7 @@ void TextEdit::InsertAtCaret(const char *text) { } void ProgressBar::GetContentDimensions(const UIContext &dc, float &w, float &h) const { - dc.MeasureText(dc.theme->uiFont, " 100% ", &w, &h); + dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, " 100% ", &w, &h); } void ProgressBar::Draw(UIContext &dc) {