29#define FONT_NAME "fonts/Thonburi.ttf"
32TextInputTests::TextInputTests()
43 rc.origin = node->getPosition();
44 rc.size = node->getContentSize();
45 rc.origin.x -= rc.size.width / 2;
46 rc.origin.y -= rc.size.height / 2;
52 return "text input test";
63 auto listener = EventListenerTouchOneByOne::create();
66 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
71 CCLOG(
"TextInputTest:keyboardWillShowAt(origin:%f,%f, size:%f,%f)",
72 info.end.origin.x, info.end.origin.y, info.end.size.width, info.end.size.height);
80 CCLOG(
"TextInputTest:trackingNodeAt(origin:%f,%f, size:%f,%f)",
81 rectTracked.origin.x, rectTracked.origin.y, rectTracked.size.width, rectTracked.size.height);
84 if (! rectTracked.intersectsRect(info.end))
90 float adjustVert = info.end.getMaxY() - rectTracked.getMinY();
91 CCLOG(
"TextInputTest:needAdjustVerticalPosition(%f)", adjustVert);
94 auto& children = getChildren();
96 ssize_t count = children.size();
98 for (
int i = 0; i < count; ++i)
100 node = children.at(i);
101 pos = node->getPosition();
103 node->setPosition(pos);
111 CCLOG(
"++++++++++++++++++++++++++++++++++++++++++++");
123 auto endPos = touch->getLocation();
126 if (std::abs(endPos.x -
_beginPos.x) > delta
127 || std::abs(endPos.y -
_beginPos.y) > delta)
137 auto clicked = isScreenPointInRect(endPos, Camera::getVisitingCamera(),
_trackNode->getWorldToNodeTransform(), rect,
nullptr);
139 CCLOG(
"----------------------------------");
148 return "TextFieldTTF with default behavior test";
157 CCLOG(
"TextFieldTTFDefaultTest:TextFieldTTF attachWithIME");
158 pTextField->attachWithIME();
163 CCLOG(
"TextFieldTTFDefaultTest:TextFieldTTF detachWithIME");
164 pTextField->detachWithIME();
173 auto s = Director::getInstance()->getWinSize();
175 auto pTextField = TextFieldTTF::textFieldWithPlaceHolder(
"<click here for input>",
178 addChild(pTextField);
180#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
183 pTextField->setPosition(Vec2(s.width / 2, s.height/2 + 50));
185 pTextField->setPosition(Vec2(s.width / 2, s.height / 2));
197 return "CCTextFieldTTF with action and char limit test";
206 CCLOG(
"TextFieldTTFActionTest:TextFieldTTF attachWithIME");
207 pTextField->attachWithIME();
212 CCLOG(
"TextFieldTTFActionTest:TextFieldTTF detachWithIME");
213 pTextField->detachWithIME();
225 FadeOut::create(0.25),
226 FadeIn::create(0.25),
233 auto s = Director::getInstance()->getWinSize();
235 _textField = TextFieldTTF::textFieldWithPlaceHolder(
"<click here for input>",
242#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
245 _textField->setPosition(Vec2(s.width / 2, s.height/2 + 50));
247 _textField->setPosition(Vec2(s.width / 2, s.height / 2));
255 KeyboardNotificationLayer::onExit();
297 this->addChild(label);
298 Color3B color(226, 121, 7);
299 label->setColor(color);
302 auto endPos = sender->getPosition();
303 if (sender->getCharCount())
305 endPos.x += sender->getContentSize().width / 2;
307 auto inputTextSize = label->getContentSize();
308 Vec2 beginPos(endPos.x, Director::getInstance()->getWinSize().height - inputTextSize.height * 2);
310 float duration = 0.5;
311 label->setPosition(beginPos);
314 auto seq = Sequence::create(
316 MoveTo::create(duration, endPos),
317 ScaleTo::create(duration, 1),
318 FadeOut::create(duration),
322 label->runAction(seq);
330 this->addChild(label);
333 auto beginPos = sender->getPosition();
334 auto textfieldSize = sender->getContentSize();
335 auto labelSize = label->getContentSize();
336 beginPos.x += (textfieldSize.width - labelSize.width) / 2.0f;
338 auto winSize = Director::getInstance()->getWinSize();
339 Vec2 endPos(- winSize.width / 4.0f, winSize.height * (0.5 + (
float)rand() / (2.0f * RAND_MAX)));
342 float rotateDuration = 0.2f;
344 label->setPosition(beginPos);
346 auto seq = Sequence::create(
348 MoveTo::create(duration, endPos),
350 RotateBy::create(rotateDuration, (rand()%2) ? 360 : -360),
352 FadeOut::create(duration),
356 label->runAction(seq);
367 this->removeChild(node,
true);
377 return "TextFieldTTF with SecureTextEntry test";
385 auto s = Director::getInstance()->getWinSize();
387 auto pTextField = TextFieldTTF::textFieldWithPlaceHolder(
"<click here for input>",
390 addChild(pTextField);
392#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
395 pTextField->setPosition(Vec2(s.width / 2, s.height/2 + 50));
397 pTextField->setPosition(Vec2(s.width / 2, s.height / 2));
399 pTextField->setSecureTextEntry(
true);
410 return "TextFieldTTF with setCursorFromPoint test";
419 CCLOG(
"TextFieldTTSetCursorFromPoint:TextFieldTTF attachWithIME");
420 pTextField->attachWithIME();
423 pTextField->setCursorFromPoint(touchPos, Camera::getVisitingCamera());
428 CCLOG(
"TextFieldTTSetCursorFromPoint:TextFieldTTF detachWithIME");
429 pTextField->detachWithIME();
438 auto s = Director::getInstance()->getWinSize();
440 auto pTextField = TextFieldTTF::textFieldWithPlaceHolder(
"<click here for input>",
443 addChild(pTextField);
445#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
448 pTextField->setPosition(Vec2(s.width / 2, s.height / 2 + 50));
450 pTextField->setPosition(Vec2(s.width / 2, s.height / 2));
#define ADD_TEST_CASE(__className__)
static Rect getRect(Node *node)
bool onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event)
KeyboardNotificationLayer()
virtual void onClickTrackNode(bool bClicked, const cocos2d::Vec2 &touchPos)=0
void onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *event)
virtual void keyboardWillShow(cocos2d::IMEKeyboardNotificationInfo &info) override
virtual std::string title() const override
cocos2d::Node * _trackNode
virtual void onEnter() override
void callbackRemoveNodeWhenDidAction(Node *node)
virtual void onClickTrackNode(bool bClicked, const cocos2d::Vec2 &touchPos) override
cocos2d::TextFieldTTF * _textField
virtual bool onTextFieldAttachWithIME(cocos2d::TextFieldTTF *sender) override
virtual bool onTextFieldDetachWithIME(cocos2d::TextFieldTTF *sender) override
virtual bool onTextFieldDeleteBackward(cocos2d::TextFieldTTF *sender, const char *delText, size_t nLen) override
virtual bool onTextFieldInsertText(cocos2d::TextFieldTTF *sender, const char *text, size_t nLen) override
virtual std::string subtitle() const override
virtual void onExit() override
virtual bool onDraw(cocos2d::TextFieldTTF *sender)
virtual void onEnter() override
cocos2d::Action * _textFieldAction
virtual std::string subtitle() const override
virtual void onClickTrackNode(bool bClicked, const cocos2d::Vec2 &touchPos) override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void onEnter() override
virtual void onClickTrackNode(bool bClicked, const cocos2d::Vec2 &touchPos) override
virtual std::string subtitle() const override