2020-08-04 12:31:33 +08:00
|
|
|
#include "FUIInput.h"
|
|
|
|
#include "UIPackage.h"
|
|
|
|
#include "GTextInput.h"
|
|
|
|
#include "UIConfig.h"
|
|
|
|
NS_FGUI_BEGIN
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
FUIInput * FUIInput::create()
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
FUIInput* pRet = new FUIInput();
|
2020-08-04 12:31:33 +08:00
|
|
|
|
2021-12-08 00:11:53 +08:00
|
|
|
if (pRet->initWithSizeAndBackgroundSprite(Size(100, 100),
|
2020-08-04 12:31:33 +08:00
|
|
|
(ui::Scale9Sprite*)ui::Scale9Sprite::createWithTexture(UIPackage::getEmptyTexture())))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
pRet->continueInit();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(pRet);
|
2020-08-04 12:31:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
FUIInput::FUIInput() :
|
|
|
|
_textFormat(new TextFormat()),
|
|
|
|
_password(false),
|
|
|
|
_keyboardType(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FUIInput::~FUIInput()
|
|
|
|
{
|
|
|
|
delete _textFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string FUIInput::getText() const
|
|
|
|
{
|
|
|
|
return ui::EditBox::getText();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FUIInput::setText(const std::string & value)
|
|
|
|
{
|
|
|
|
ui::EditBox::setText(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FUIInput::applyTextFormat()
|
|
|
|
{
|
|
|
|
setFontName(UIConfig::getRealFontName(_textFormat->face).c_str());
|
|
|
|
setFontSize(_textFormat->fontSize);
|
|
|
|
setPlaceholderFontSize(_textFormat->fontSize);
|
|
|
|
setFontColor(_textFormat->color);
|
|
|
|
//setPlaceholderFontColor(_textFormat->color);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FUIInput::isSingleLine() const
|
|
|
|
{
|
|
|
|
return getInputMode() == ui::EditBox::InputMode::SINGLE_LINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FUIInput::setSingleLine(bool value)
|
|
|
|
{
|
|
|
|
setInputMode(ui::EditBox::InputMode::SINGLE_LINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FUIInput::setPassword(bool value)
|
|
|
|
{
|
|
|
|
_password = value;
|
|
|
|
setInputFlag(ui::EditBox::InputFlag::PASSWORD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FUIInput::setKeyboardType(int value)
|
|
|
|
{
|
|
|
|
//if (!_password)
|
|
|
|
//setInputMode((ui::EditBox::InputMode)value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FUIInput::openKeyboard()
|
|
|
|
{
|
|
|
|
#if COCOS2D_VERSION >= 0x00031700
|
|
|
|
EditBox::openKeyboard();
|
|
|
|
#else
|
2022-08-08 18:02:17 +08:00
|
|
|
touchDownAction(this, ax::ui::Widget::TouchEventType::ENDED);
|
2020-08-04 12:31:33 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void FUIInput::continueInit()
|
|
|
|
{
|
|
|
|
applyTextFormat();
|
|
|
|
|
|
|
|
//disable default behavior
|
|
|
|
this->setTouchEnabled(false);
|
2022-07-15 19:17:01 +08:00
|
|
|
this->addTouchEventListener(AX_CALLBACK_2(FUIInput::_touchDownAction, this));
|
2020-08-04 12:31:33 +08:00
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
void FUIInput::_touchDownAction(ax::Ref *sender, ax::ui::Widget::TouchEventType controlEvent)
|
2020-08-04 12:31:33 +08:00
|
|
|
{
|
|
|
|
//do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_FGUI_END
|