mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
trim text
This commit is contained in:
parent
d6cf050b6b
commit
24d4816a36
@ -101,7 +101,7 @@
|
||||
"vcmi.systemOptions.resolutionMenu.help" : "Ändere die Spielauflösung.",
|
||||
"vcmi.systemOptions.scalingButton.hover" : "Interface-Skalierung: %p%",
|
||||
"vcmi.systemOptions.scalingButton.help" : "{Interface-Skalierung}\n\nÄndern der Skalierung des Interfaces im Spiel",
|
||||
"vcmi.systemOptions.scalingMenu.hover" : "Skalierung des Interfaces auswählen",
|
||||
"vcmi.systemOptions.scalingMenu.hover" : "Skalierung auswählen",
|
||||
"vcmi.systemOptions.scalingMenu.help" : "Ändern der Skalierung des Interfaces im Spiel.",
|
||||
"vcmi.systemOptions.longTouchButton.hover" : "Berührungsdauer für langer Touch: %d ms", // Translation note: "ms" = "milliseconds"
|
||||
"vcmi.systemOptions.longTouchButton.help" : "{Berührungsdauer für langer Touch}\n\nBei Verwendung des Touchscreens erscheinen Popup-Fenster nach Berührung des Bildschirms für die angegebene Dauer (in Millisekunden)",
|
||||
|
@ -537,11 +537,11 @@ void OptionsTab::SelectionWindow::recreate()
|
||||
|
||||
void OptionsTab::SelectionWindow::drawOutlinedText(int x, int y, ColorRGBA color, std::string text)
|
||||
{
|
||||
components.push_back(std::make_shared<CLabel>(x-1, y, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text));
|
||||
components.push_back(std::make_shared<CLabel>(x+1, y, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text));
|
||||
components.push_back(std::make_shared<CLabel>(x, y-1, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text));
|
||||
components.push_back(std::make_shared<CLabel>(x, y+1, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text));
|
||||
components.push_back(std::make_shared<CLabel>(x, y, FONT_TINY, ETextAlignment::CENTER, color, text));
|
||||
components.push_back(std::make_shared<CLabel>(x-1, y, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text, 56));
|
||||
components.push_back(std::make_shared<CLabel>(x+1, y, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text, 56));
|
||||
components.push_back(std::make_shared<CLabel>(x, y-1, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text, 56));
|
||||
components.push_back(std::make_shared<CLabel>(x, y+1, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text, 56));
|
||||
components.push_back(std::make_shared<CLabel>(x, y, FONT_TINY, ETextAlignment::CENTER, color, text, 56));
|
||||
}
|
||||
|
||||
void OptionsTab::SelectionWindow::genContentGrid(int lines)
|
||||
@ -774,7 +774,7 @@ OptionsTab::SelectedBox::SelectedBox(Point position, PlayerSettings & playerSett
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
|
||||
image = std::make_shared<CAnimImage>(getImageName(), getImageIndex());
|
||||
subtitle = std::make_shared<CLabel>(23, 39, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, getName());
|
||||
subtitle = std::make_shared<CLabel>(24, 39, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, getName(), 71);
|
||||
|
||||
pos = image->pos;
|
||||
|
||||
@ -889,7 +889,7 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
|
||||
|
||||
background = std::make_shared<CPicture>(ImagePath::builtin(bgs[s->color]), 0, 0);
|
||||
if(s->isControlledByAI() || CSH->isGuest())
|
||||
labelPlayerName = std::make_shared<CLabel>(55, 10, EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, name);
|
||||
labelPlayerName = std::make_shared<CLabel>(55, 10, EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, name, 95);
|
||||
else
|
||||
{
|
||||
labelPlayerNameEdit = std::make_shared<CTextInput>(Rect(6, 3, 95, 15), EFonts::FONT_SMALL, nullptr, false);
|
||||
|
@ -823,7 +823,7 @@ SelectionTab::ListItem::ListItem(Point position, std::shared_ptr<CAnimation> ico
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
pictureEmptyLine = std::make_shared<CPicture>(GH.renderHandler().loadImage(ImagePath::builtin("camcust")), Rect(25, 121, 349, 26), -8, -14);
|
||||
labelName = std::make_shared<CLabel>(184, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
|
||||
labelName = std::make_shared<CLabel>(184, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, "", 185);
|
||||
labelName->setAutoRedraw(false);
|
||||
labelAmountOfPlayers = std::make_shared<CLabel>(8, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
|
||||
labelAmountOfPlayers->setAutoRedraw(false);
|
||||
|
@ -47,8 +47,8 @@ void CLabel::showAll(Canvas & to)
|
||||
|
||||
}
|
||||
|
||||
CLabel::CLabel(int x, int y, EFonts Font, ETextAlignment Align, const ColorRGBA & Color, const std::string & Text)
|
||||
: CTextContainer(Align, Font, Color), text(Text)
|
||||
CLabel::CLabel(int x, int y, EFonts Font, ETextAlignment Align, const ColorRGBA & Color, const std::string & Text, int maxWidth)
|
||||
: CTextContainer(Align, Font, Color), text(Text), maxWidth(maxWidth)
|
||||
{
|
||||
setRedrawParent(true);
|
||||
autoRedraw = true;
|
||||
@ -56,6 +56,8 @@ CLabel::CLabel(int x, int y, EFonts Font, ETextAlignment Align, const ColorRGBA
|
||||
pos.y += y;
|
||||
pos.w = pos.h = 0;
|
||||
|
||||
trimText();
|
||||
|
||||
if(alignment == ETextAlignment::TOPLEFT) // causes issues for MIDDLE
|
||||
{
|
||||
pos.w = (int)graphics->fonts[font]->getStringWidth(visibleText().c_str());
|
||||
@ -81,6 +83,9 @@ void CLabel::setAutoRedraw(bool value)
|
||||
void CLabel::setText(const std::string & Txt)
|
||||
{
|
||||
text = Txt;
|
||||
|
||||
trimText();
|
||||
|
||||
if(autoRedraw)
|
||||
{
|
||||
if(background || !parent)
|
||||
@ -90,6 +95,13 @@ void CLabel::setText(const std::string & Txt)
|
||||
}
|
||||
}
|
||||
|
||||
void CLabel::trimText()
|
||||
{
|
||||
if(maxWidth > 0)
|
||||
while ((int)graphics->fonts[font]->getStringWidth(visibleText().c_str()) > maxWidth)
|
||||
TextOperations::trimRightUnicode(text);
|
||||
}
|
||||
|
||||
void CLabel::setColor(const ColorRGBA & Color)
|
||||
{
|
||||
color = Color;
|
||||
@ -444,7 +456,7 @@ void CGStatusBar::clear()
|
||||
}
|
||||
|
||||
CGStatusBar::CGStatusBar(std::shared_ptr<CIntObject> background_, EFonts Font, ETextAlignment Align, const ColorRGBA & Color)
|
||||
: CLabel(background_->pos.x, background_->pos.y, Font, Align, Color, "")
|
||||
: CLabel(background_->pos.x, background_->pos.y, Font, Align, Color, "", background_->pos.w)
|
||||
, enteringText(false)
|
||||
{
|
||||
addUsedEvents(LCLICK);
|
||||
@ -542,6 +554,7 @@ CTextInput::CTextInput(const Rect & Pos, EFonts font, const CFunctionList<void(c
|
||||
setRedrawParent(true);
|
||||
pos.h = Pos.h;
|
||||
pos.w = Pos.w;
|
||||
maxWidth = Pos.w;
|
||||
background.reset();
|
||||
addUsedEvents(LCLICK | SHOW_POPUP | KEYBOARD | TEXTINPUT);
|
||||
|
||||
@ -557,6 +570,7 @@ CTextInput::CTextInput(const Rect & Pos, const Point & bgOffset, const ImagePath
|
||||
pos += Pos.topLeft();
|
||||
pos.h = Pos.h;
|
||||
pos.w = Pos.w;
|
||||
maxWidth = Pos.w;
|
||||
|
||||
OBJ_CONSTRUCTION;
|
||||
background = std::make_shared<CPicture>(bgName, bgOffset.x, bgOffset.y);
|
||||
@ -575,6 +589,7 @@ CTextInput::CTextInput(const Rect & Pos, std::shared_ptr<IImage> srf)
|
||||
background = std::make_shared<CPicture>(srf, Pos);
|
||||
pos.w = background->pos.w;
|
||||
pos.h = background->pos.h;
|
||||
maxWidth = Pos.w;
|
||||
background->pos = pos;
|
||||
addUsedEvents(LCLICK | KEYBOARD | TEXTINPUT);
|
||||
|
||||
@ -683,7 +698,7 @@ void CTextInput::textInputed(const std::string & enteredText)
|
||||
return;
|
||||
std::string oldText = text;
|
||||
|
||||
text += enteredText;
|
||||
setText(getText() + enteredText);
|
||||
|
||||
filters(text, oldText);
|
||||
if(text != oldText)
|
||||
|
@ -43,9 +43,11 @@ class CLabel : public CTextContainer
|
||||
protected:
|
||||
Point getBorderSize() override;
|
||||
virtual std::string visibleText();
|
||||
virtual void trimText();
|
||||
|
||||
std::shared_ptr<CIntObject> background;
|
||||
std::string text;
|
||||
int maxWidth;
|
||||
bool autoRedraw; //whether control will redraw itself on setTxt
|
||||
|
||||
public:
|
||||
@ -57,7 +59,7 @@ public:
|
||||
size_t getWidth();
|
||||
|
||||
CLabel(int x = 0, int y = 0, EFonts Font = FONT_SMALL, ETextAlignment Align = ETextAlignment::TOPLEFT,
|
||||
const ColorRGBA & Color = Colors::WHITE, const std::string & Text = "");
|
||||
const ColorRGBA & Color = Colors::WHITE, const std::string & Text = "", int maxWidth = 0);
|
||||
void showAll(Canvas & to) override; //shows statusbar (with current text)
|
||||
};
|
||||
|
||||
|
@ -1430,7 +1430,7 @@ CHallInterface::CBuildingBox::CBuildingBox(int x, int y, const CGTownInstance *
|
||||
header = std::make_shared<CAnimImage>(AnimationPath::builtin("TPTHBAR"), panelIndex[static_cast<int>(state)], 0, 1, 73);
|
||||
if(iconIndex[static_cast<int>(state)] >=0)
|
||||
mark = std::make_shared<CAnimImage>(AnimationPath::builtin("TPTHCHK"), iconIndex[static_cast<int>(state)], 0, 136, 56);
|
||||
name = std::make_shared<CLabel>(75, 81, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, building->getNameTranslated());
|
||||
name = std::make_shared<CLabel>(78, 81, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, building->getNameTranslated(), 150);
|
||||
|
||||
//todo: add support for all possible states
|
||||
if(state >= EBuildingState::BUILDING_ERROR)
|
||||
@ -1769,7 +1769,7 @@ CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance *
|
||||
if(getMyBuilding() != nullptr)
|
||||
{
|
||||
buildingIcon = std::make_shared<CAnimImage>(town->town->clientInfo.buildingsIcons, getMyBuilding()->bid, 0, 4, 21);
|
||||
buildingName = std::make_shared<CLabel>(78, 101, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, getMyBuilding()->getNameTranslated());
|
||||
buildingName = std::make_shared<CLabel>(78, 101, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, getMyBuilding()->getNameTranslated(), 152);
|
||||
|
||||
if(vstd::contains(town->builtBuildings, getMyBuilding()->bid))
|
||||
{
|
||||
@ -1783,7 +1783,7 @@ CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance *
|
||||
{
|
||||
hoverText = boost::str(boost::format(CGI->generaltexth->tcommands[21]) % getMyCreature()->getNamePluralTranslated());
|
||||
new CCreaturePic(159, 4, getMyCreature(), false);
|
||||
new CLabel(78, 11, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, getMyCreature()->getNamePluralTranslated());
|
||||
new CLabel(78, 11, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, getMyCreature()->getNamePluralTranslated(), 152);
|
||||
|
||||
Rect sizes(287, 4, 96, 18);
|
||||
values.push_back(std::make_shared<LabeledValue>(sizes, CGI->generaltexth->allTexts[190], CGI->generaltexth->fcommands[0], getMyCreature()->getAttack(false)));
|
||||
|
Loading…
Reference in New Issue
Block a user