More control over text scaling in TextViews

This commit is contained in:
Henrik Rydgard committed 2013-06-20 21:51:42 +02:00
1 parent deb4ba8323
commit 0a26fae856
2 files changed
+8 -5

No files matched your search

+2 -2
View File
@@ -268,13 +268,13 @@ void TextureView::Draw(UIContext &dc) {
}
void TextView::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
dc.Draw()->SetFontScale(textScale_, textScale_);
dc.Draw()->SetFontScale(textScaleX_, textScaleY_);
dc.Draw()->MeasureText(dc.theme->uiFont, text_.c_str(), &w, &h);
dc.Draw()->SetFontScale(1.0f, 1.0f);
}
void TextView::Draw(UIContext &dc) {
dc.Draw()->SetFontScale(textScale_, textScale_);
dc.Draw()->SetFontScale(textScaleX_, textScaleY_);
dc.Draw()->DrawTextRect(dc.theme->uiFont, text_.c_str(), bounds_.x, bounds_.y, bounds_.w, bounds_.h, 0xFFFFFFFF, textAlign_);
dc.Draw()->SetFontScale(1.0f, 1.0f);
}
+6 -3
View File
@@ -489,16 +489,19 @@ public:
class TextView : public InertView {
public:
TextView(int font, const std::string &text, int textAlign, float textScale, LayoutParams *layoutParams = 0)
: InertView(layoutParams), font_(font), text_(text), textScale_(textScale), textAlign_(textAlign) {}
: InertView(layoutParams), font_(font), text_(text), textScaleX_(textScale), textScaleY_(textScale), textAlign_(textAlign) {}
virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const;
virtual void Draw(UIContext &dc);
virtual void SetText(const std::string &text) { text_ = text; }
void SetText(const std::string &text) { text_ = text; }
void SetTextScaleXY(float sx, float sy) { textScaleX_ = sx; textScaleY_ = sy; }
void SetTextScale(float scale) { textScaleX_ = scale; textScaleY_ = scale; }
private:
int font_;
std::string text_;
float textScale_;
float textScaleX_;
float textScaleY_;
int textAlign_;
};