-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathGTextInput.cpp
129 lines (105 loc) · 2.71 KB
/
GTextInput.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "GTextInput.h"
#include "UIPackage.h"
#include "GRoot.h"
#include "ui/UIEditBox/UIEditBox.h"
#include "utils/ByteBuffer.h"
#include "utils/UBBParser.h"
#include "utils/ToolSet.h"
NS_FGUI_BEGIN
USING_NS_CC;
GTextInput::GTextInput()
{
}
GTextInput::~GTextInput()
{
}
void GTextInput::handleInit()
{
_input = FUIInput::create();
_input->retain();
_input->setDelegate(this);
_displayObject = _input;
this->addEventListener(UIEventType::TouchEnd, [this](EventContext*) {
_input->openKeyboard();
});
}
bool GTextInput::isSingleLine() const
{
return _input->isSingleLine();
}
void GTextInput::setSingleLine(bool value)
{
_input->setSingleLine(value);
}
void GTextInput::applyTextFormat()
{
_input->applyTextFormat();
}
void GTextInput::setPrompt(const std::string & value)
{
if (value.empty())
_input->setPlaceHolder(value.c_str());
else
{
UBBParser* parser = UBBParser::getInstance();
_input->setPlaceHolder(parser->parse(value.c_str(), true).c_str());
if (!parser->lastColor.empty())
_input->setPlaceholderFontColor(ToolSet::hexToColor(parser->lastColor.c_str()));
if (!parser->lastFontSize.empty())
_input->setPlaceholderFontSize(Value(parser->lastFontSize).asInt());
}
}
void GTextInput::setPassword(bool value)
{
_input->setPassword(value);
}
void GTextInput::setKeyboardType(int value)
{
_input->setKeyboardType(value);
}
void GTextInput::setMaxLength(int value)
{
_input->setMaxLength(value);
}
void GTextInput::setRestrict(const std::string & value)
{
}
void GTextInput::handleSizeChanged()
{
_input->setContentSize(_size);
}
void GTextInput::setup_beforeAdd(ByteBuffer* buffer, int beginPos)
{
GTextField::setup_beforeAdd(buffer, beginPos);
buffer->seek(beginPos, 4);
const std::string* str;
if ((str = buffer->readSP()))
setPrompt(*str);
if ((str = buffer->readSP()))
setRestrict(*str);
int iv = buffer->readInt();
if (iv != 0)
setMaxLength(iv);
iv = buffer->readInt();
if (iv != 0)
setKeyboardType(iv);
if (buffer->readBool())
setPassword(true);
}
void GTextInput::setTextFieldText()
{
if (_templateVars != nullptr)
_input->setText(parseTemplate(_text.c_str()));
else
_input->setText(_text);
}
void GTextInput::editBoxReturn(cocos2d::ui::EditBox * editBox)
{
dispatchEvent(UIEventType::Submit);
}
void GTextInput::editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text)
{
_text.clear();
_text.append(_input->getText());
}
NS_FGUI_END