axmol/extensions/fairygui/display/FUIInput.cpp

102 lines
2.0 KiB
C++
Raw Normal View History

2020-08-04 12:31:33 +08:00
#include "FUIInput.h"
#include "UIPackage.h"
#include "GTextInput.h"
#include "UIConfig.h"
NS_FGUI_BEGIN
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
{
CC_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
touchDownAction(this, axis::ui::Widget::TouchEventType::ENDED);
2020-08-04 12:31:33 +08:00
#endif
}
void FUIInput::continueInit()
{
applyTextFormat();
//disable default behavior
this->setTouchEnabled(false);
this->addTouchEventListener(CC_CALLBACK_2(FUIInput::_touchDownAction, this));
2020-08-04 12:31:33 +08:00
}
void FUIInput::_touchDownAction(axis::Ref *sender, axis::ui::Widget::TouchEventType controlEvent)
2020-08-04 12:31:33 +08:00
{
//do nothing
}
NS_FGUI_END