mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Simplify TextInput constructor
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "CFocusableHelper.h"
|
#include "CFocusableHelper.h"
|
||||||
#include "../Global.h"
|
#include "../Global.h"
|
||||||
#include "widgets/TextControls.h"
|
#include "widgets/CTextInput.h"
|
||||||
|
|
||||||
void removeFocusFromActiveInput()
|
void removeFocusFromActiveInput()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ GlobalLobbyLoginWindow::GlobalLobbyLoginWindow()
|
|||||||
labelUsernameTitle = std::make_shared<CLabel>( 10, 65, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->translate("vcmi.lobby.login.username"));
|
labelUsernameTitle = std::make_shared<CLabel>( 10, 65, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->translate("vcmi.lobby.login.username"));
|
||||||
labelUsername = std::make_shared<CLabel>( 10, 65, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, loginAs.toString());
|
labelUsername = std::make_shared<CLabel>( 10, 65, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, loginAs.toString());
|
||||||
backgroundUsername = std::make_shared<TransparentFilledRectangle>(Rect(10, 90, 264, 20), ColorRGBA(0,0,0,128), ColorRGBA(64,64,64,64));
|
backgroundUsername = std::make_shared<TransparentFilledRectangle>(Rect(10, 90, 264, 20), ColorRGBA(0,0,0,128), ColorRGBA(64,64,64,64));
|
||||||
inputUsername = std::make_shared<CTextInput>(Rect(15, 93, 260, 16), FONT_SMALL, nullptr, ETextAlignment::CENTERLEFT, true);
|
inputUsername = std::make_shared<CTextInput>(Rect(15, 93, 260, 16), FONT_SMALL, ETextAlignment::CENTERLEFT, true);
|
||||||
buttonLogin = std::make_shared<CButton>(Point(10, 180), AnimationPath::builtin("MuBchck"), CButton::tooltip(), [this](){ onLogin(); });
|
buttonLogin = std::make_shared<CButton>(Point(10, 180), AnimationPath::builtin("MuBchck"), CButton::tooltip(), [this](){ onLogin(); });
|
||||||
buttonClose = std::make_shared<CButton>(Point(210, 180), AnimationPath::builtin("MuBcanc"), CButton::tooltip(), [this](){ onClose(); });
|
buttonClose = std::make_shared<CButton>(Point(210, 180), AnimationPath::builtin("MuBcanc"), CButton::tooltip(), [this](){ onClose(); });
|
||||||
labelStatus = std::make_shared<CTextBox>( "", Rect(15, 115, 255, 60), 1, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
|
labelStatus = std::make_shared<CTextBox>( "", Rect(15, 115, 255, 60), 1, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ CChatBox::CChatBox(const Rect & rect)
|
|||||||
Rect textInputArea(1, rect.h - height, rect.w - 1, height);
|
Rect textInputArea(1, rect.h - height, rect.w - 1, height);
|
||||||
Rect chatHistoryArea(3, 1, rect.w - 3, rect.h - height - 1);
|
Rect chatHistoryArea(3, 1, rect.w - 3, rect.h - height - 1);
|
||||||
inputBackground = std::make_shared<TransparentFilledRectangle>(textInputArea, ColorRGBA(0,0,0,192));
|
inputBackground = std::make_shared<TransparentFilledRectangle>(textInputArea, ColorRGBA(0,0,0,192));
|
||||||
inputBox = std::make_shared<CTextInput>(textInputArea, EFonts::FONT_SMALL, nullptr, ETextAlignment::CENTERLEFT, true);
|
inputBox = std::make_shared<CTextInput>(textInputArea, EFonts::FONT_SMALL, ETextAlignment::CENTERLEFT, true);
|
||||||
inputBox->removeUsedEvents(KEYBOARD);
|
inputBox->removeUsedEvents(KEYBOARD);
|
||||||
chatHistory = std::make_shared<CTextBox>("", chatHistoryArea, 1);
|
chatHistory = std::make_shared<CTextBox>("", chatHistoryArea, 1);
|
||||||
|
|
||||||
|
|||||||
@@ -893,7 +893,7 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
|
|||||||
labelPlayerName = std::make_shared<CLabel>(55, 10, EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, name, 95);
|
labelPlayerName = std::make_shared<CLabel>(55, 10, EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, name, 95);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
labelPlayerNameEdit = std::make_shared<CTextInput>(Rect(6, 3, 95, 15), EFonts::FONT_SMALL, nullptr, ETextAlignment::CENTER, false);
|
labelPlayerNameEdit = std::make_shared<CTextInput>(Rect(6, 3, 95, 15), EFonts::FONT_SMALL, ETextAlignment::CENTER, false);
|
||||||
labelPlayerNameEdit->setText(name);
|
labelPlayerNameEdit->setText(name);
|
||||||
}
|
}
|
||||||
labelWhoCanPlay = std::make_shared<CMultiLineLabel>(Rect(6, 23, 45, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->arraytxt[206 + whoCanPlay]);
|
labelWhoCanPlay = std::make_shared<CMultiLineLabel>(Rect(6, 23, 45, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->arraytxt[206 + whoCanPlay]);
|
||||||
|
|||||||
@@ -373,7 +373,7 @@ CHighScoreInput::CHighScoreInput(std::string playerName, std::function<void(std:
|
|||||||
buttonOk = std::make_shared<CButton>(Point(26, 142), AnimationPath::builtin("MUBCHCK.DEF"), CGI->generaltexth->zelp[560], std::bind(&CHighScoreInput::okay, this), EShortcut::GLOBAL_ACCEPT);
|
buttonOk = std::make_shared<CButton>(Point(26, 142), AnimationPath::builtin("MUBCHCK.DEF"), CGI->generaltexth->zelp[560], std::bind(&CHighScoreInput::okay, this), EShortcut::GLOBAL_ACCEPT);
|
||||||
buttonCancel = std::make_shared<CButton>(Point(142, 142), AnimationPath::builtin("MUBCANC.DEF"), CGI->generaltexth->zelp[561], std::bind(&CHighScoreInput::abort, this), EShortcut::GLOBAL_CANCEL);
|
buttonCancel = std::make_shared<CButton>(Point(142, 142), AnimationPath::builtin("MUBCANC.DEF"), CGI->generaltexth->zelp[561], std::bind(&CHighScoreInput::abort, this), EShortcut::GLOBAL_CANCEL);
|
||||||
statusBar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(7, 186, 218, 18), 7, 186));
|
statusBar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(7, 186, 218, 18), 7, 186));
|
||||||
textInput = std::make_shared<CTextInput>(Rect(18, 104, 200, 25), FONT_SMALL, nullptr, ETextAlignment::CENTER, true);
|
textInput = std::make_shared<CTextInput>(Rect(18, 104, 200, 25), FONT_SMALL, ETextAlignment::CENTER, true);
|
||||||
textInput->setText(playerName);
|
textInput->setText(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,12 +46,11 @@ void CTextInput::createLabel(bool giveFocusToInput)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CTextInput::CTextInput(const Rect & Pos, EFonts font, const TextEditedCallback & onTextEdited, ETextAlignment alignment, bool giveFocusToInput)
|
CTextInput::CTextInput(const Rect & Pos, EFonts font, ETextAlignment alignment, bool giveFocusToInput)
|
||||||
: CTextInput(Pos)
|
: CTextInput(Pos)
|
||||||
{
|
{
|
||||||
originalAlignment = alignment;
|
originalAlignment = alignment;
|
||||||
setRedrawParent(true);
|
setRedrawParent(true);
|
||||||
this->onTextEdited = onTextEdited;
|
|
||||||
createLabel(giveFocusToInput);
|
createLabel(giveFocusToInput);
|
||||||
setFont(font);
|
setFont(font);
|
||||||
setAlignment(alignment);
|
setAlignment(alignment);
|
||||||
@@ -61,7 +60,11 @@ CTextInput::CTextInput(const Rect & Pos, const Point & bgOffset, const ImagePath
|
|||||||
: CTextInput(Pos)
|
: CTextInput(Pos)
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION;
|
OBJ_CONSTRUCTION;
|
||||||
background = std::make_shared<CPicture>(bgName, bgOffset.x, bgOffset.y);
|
if (!bgName.empty())
|
||||||
|
background = std::make_shared<CPicture>(bgName, bgOffset.x, bgOffset.y);
|
||||||
|
else
|
||||||
|
setRedrawParent(true);
|
||||||
|
|
||||||
createLabel(true);
|
createLabel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ class IImage;
|
|||||||
/// UIElement which can get input focus
|
/// UIElement which can get input focus
|
||||||
class CFocusable : public CIntObject
|
class CFocusable : public CIntObject
|
||||||
{
|
{
|
||||||
|
friend void removeFocusFromActiveInput();
|
||||||
|
|
||||||
static std::atomic<int> usageIndex;
|
static std::atomic<int> usageIndex;
|
||||||
static std::list<CFocusable *> focusables; //all existing objs
|
static std::list<CFocusable *> focusables; //all existing objs
|
||||||
static CFocusable * inputWithFocus; //who has focus now
|
static CFocusable * inputWithFocus; //who has focus now
|
||||||
@@ -76,7 +78,7 @@ private:
|
|||||||
|
|
||||||
CTextInput(const Rect & Pos);
|
CTextInput(const Rect & Pos);
|
||||||
public:
|
public:
|
||||||
CTextInput(const Rect & Pos, EFonts font, const TextEditedCallback& onTextEdited, ETextAlignment alignment, bool giveFocusToInput);
|
CTextInput(const Rect & Pos, EFonts font, ETextAlignment alignment, bool giveFocusToInput);
|
||||||
CTextInput(const Rect & Pos, const Point & bgOffset, const ImagePath & bgName);
|
CTextInput(const Rect & Pos, const Point & bgOffset, const ImagePath & bgName);
|
||||||
CTextInput(const Rect & Pos, std::shared_ptr<IImage> srf);
|
CTextInput(const Rect & Pos, std::shared_ptr<IImage> srf);
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,8 @@ CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _m
|
|||||||
searchBoxRectangle = std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor);
|
searchBoxRectangle = std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor);
|
||||||
searchBoxDescription = std::make_shared<CLabel>(r.center().x, r.center().y, FONT_SMALL, ETextAlignment::CENTER, grayedColor, CGI->generaltexth->translate("vcmi.spellBook.search"));
|
searchBoxDescription = std::make_shared<CLabel>(r.center().x, r.center().y, FONT_SMALL, ETextAlignment::CENTER, grayedColor, CGI->generaltexth->translate("vcmi.spellBook.search"));
|
||||||
|
|
||||||
searchBox = std::make_shared<CTextInput>(r, FONT_SMALL, std::bind(&CSpellWindow::searchInput, this), ETextAlignment::CENTER, true);
|
searchBox = std::make_shared<CTextInput>(r, FONT_SMALL, ETextAlignment::CENTER, true);
|
||||||
|
searchBox->setCallback(std::bind(&CSpellWindow::searchInput, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
processSpells();
|
processSpells();
|
||||||
@@ -161,7 +162,7 @@ CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _m
|
|||||||
for(auto item : schoolBorders)
|
for(auto item : schoolBorders)
|
||||||
item->preload();
|
item->preload();
|
||||||
mana = std::make_shared<CLabel>(435 + (isBigSpellbook ? 159 : 0), 426 + offB, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, std::to_string(myHero->mana));
|
mana = std::make_shared<CLabel>(435 + (isBigSpellbook ? 159 : 0), 426 + offB, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, std::to_string(myHero->mana));
|
||||||
|
|
||||||
if(isBigSpellbook)
|
if(isBigSpellbook)
|
||||||
statusBar = CGStatusBar::create(400, 587);
|
statusBar = CGStatusBar::create(400, 587);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -329,8 +329,11 @@ CSplitWindow::CSplitWindow(const CCreature * creature, std::function<void(int, i
|
|||||||
|
|
||||||
int sliderPosition = total - leftMin - rightMin;
|
int sliderPosition = total - leftMin - rightMin;
|
||||||
|
|
||||||
leftInput = std::make_shared<CTextInput>(Rect(20, 218, 100, 36), FONT_BIG, std::bind(&CSplitWindow::setAmountText, this, _1, true), ETextAlignment::CENTER, true);
|
leftInput = std::make_shared<CTextInput>(Rect(20, 218, 100, 36), FONT_BIG, ETextAlignment::CENTER, true);
|
||||||
rightInput = std::make_shared<CTextInput>(Rect(176, 218, 100, 36), FONT_BIG, std::bind(&CSplitWindow::setAmountText, this, _1, false), ETextAlignment::CENTER, true);
|
rightInput = std::make_shared<CTextInput>(Rect(176, 218, 100, 36), FONT_BIG, ETextAlignment::CENTER, true);
|
||||||
|
|
||||||
|
leftInput->setCallback(std::bind(&CSplitWindow::setAmountText, this, _1, true));
|
||||||
|
rightInput->setCallback(std::bind(&CSplitWindow::setAmountText, this, _1, false));
|
||||||
|
|
||||||
//add filters to allow only number input
|
//add filters to allow only number input
|
||||||
leftInput->setFilterNumber(leftMin, leftMax);
|
leftInput->setFilterNumber(leftMin, leftMax);
|
||||||
|
|||||||
Reference in New Issue
Block a user