PuzzleSDK
TextFieldTTFActionTest类 参考

#include <TextInputTest.h>

+ 类 TextFieldTTFActionTest 继承关系图:
+ TextFieldTTFActionTest 的协作图:

Public 成员函数

 CREATE_FUNC (TextFieldTTFActionTest)
 
void callbackRemoveNodeWhenDidAction (Node *node)
 
virtual std::string subtitle () const override
 
virtual void onClickTrackNode (bool bClicked, const cocos2d::Vec2 &touchPos) override
 
virtual void onEnter () override
 
virtual void onExit () override
 
virtual bool onTextFieldAttachWithIME (cocos2d::TextFieldTTF *sender) override
 
virtual bool onTextFieldDetachWithIME (cocos2d::TextFieldTTF *sender) override
 
virtual bool onTextFieldInsertText (cocos2d::TextFieldTTF *sender, const char *text, size_t nLen) override
 
virtual bool onTextFieldDeleteBackward (cocos2d::TextFieldTTF *sender, const char *delText, size_t nLen) override
 
virtual bool onDraw (cocos2d::TextFieldTTF *sender)
 
- Public 成员函数 继承自 KeyboardNotificationLayer
 KeyboardNotificationLayer ()
 
virtual std::string title () const override
 
virtual void keyboardWillShow (cocos2d::IMEKeyboardNotificationInfo &info) override
 
bool onTouchBegan (cocos2d::Touch *touch, cocos2d::Event *event)
 
void onTouchEnded (cocos2d::Touch *touch, cocos2d::Event *event)
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 

Private 属性

cocos2d::TextFieldTTF * _textField
 
cocos2d::Action * _textFieldAction
 
bool _action
 
size_t _charLimit
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 
- Protected 属性 继承自 KeyboardNotificationLayer
cocos2d::Node * _trackNode
 
cocos2d::Vec2 _beginPos
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

详细描述

在文件 TextInputTest.h75 行定义.

成员函数说明

◆ callbackRemoveNodeWhenDidAction()

void TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction ( Node *  node)

在文件 TextInputTest.cpp365 行定义.

366{
367 this->removeChild(node, true);
368}

被这些函数引用 onTextFieldDeleteBackward() , 以及 onTextFieldInsertText().

+ 这是这个函数的调用关系图:

◆ CREATE_FUNC()

TextFieldTTFActionTest::CREATE_FUNC ( TextFieldTTFActionTest  )

◆ onClickTrackNode()

void TextFieldTTFActionTest::onClickTrackNode ( bool  bClicked,
const cocos2d::Vec2 &  touchPos 
)
overridevirtual

实现了 KeyboardNotificationLayer.

在文件 TextInputTest.cpp200 行定义.

201{
202 auto pTextField = (TextFieldTTF*)_trackNode;
203 if (bClicked)
204 {
205 // TextFieldTTFTest be clicked
206 CCLOG("TextFieldTTFActionTest:TextFieldTTF attachWithIME");
207 pTextField->attachWithIME();
208 }
209 else
210 {
211 // TextFieldTTFTest not be clicked
212 CCLOG("TextFieldTTFActionTest:TextFieldTTF detachWithIME");
213 pTextField->detachWithIME();
214 }
215}
cocos2d::Node * _trackNode
Definition: TextInputTest.h:51

引用了 KeyboardNotificationLayer::_trackNode.

◆ onDraw()

bool TextFieldTTFActionTest::onDraw ( cocos2d::TextFieldTTF *  sender)
virtual

在文件 TextInputTest.cpp360 行定义.

361{
362 return false;
363}

◆ onEnter()

void TextFieldTTFActionTest::onEnter ( )
overridevirtual

重载 TestCase .

在文件 TextInputTest.cpp217 行定义.

218{
220
221 _charLimit = 12;
222
223 _textFieldAction = RepeatForever::create(
224 Sequence::create(
225 FadeOut::create(0.25),
226 FadeIn::create(0.25),
227 nullptr
228 ));
229 _textFieldAction->retain();
230 _action = false;
231
232 // add TextFieldTTF
233 auto s = Director::getInstance()->getWinSize();
234
235 _textField = TextFieldTTF::textFieldWithPlaceHolder("<click here for input>",
236 FONT_NAME,
237 FONT_SIZE);
238 addChild(_textField);
239
240 _textField->setDelegate(this);
241
242#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
243 // on android, TextFieldTTF cannot auto adjust its position when soft-keyboard pop up
244 // so we had to set a higher position
245 _textField->setPosition(Vec2(s.width / 2, s.height/2 + 50));
246#else
247 _textField->setPosition(Vec2(s.width / 2, s.height / 2));
248#endif
249
251}
#define FONT_NAME
#define FONT_SIZE
virtual void onEnter() override
Definition: BaseTest.cpp:430
cocos2d::TextFieldTTF * _textField
Definition: TextInputTest.h:77
cocos2d::Action * _textFieldAction
Definition: TextInputTest.h:78

引用了 _action, _charLimit, _textField, _textFieldAction, KeyboardNotificationLayer::_trackNode, FONT_NAME, FONT_SIZE , 以及 TestCase::onEnter().

+ 函数调用图:

◆ onExit()

void TextFieldTTFActionTest::onExit ( )
overridevirtual

在文件 TextInputTest.cpp253 行定义.

254{
255 KeyboardNotificationLayer::onExit();
256 _textFieldAction->release();
257}

引用了 _textFieldAction.

◆ onTextFieldAttachWithIME()

bool TextFieldTTFActionTest::onTextFieldAttachWithIME ( cocos2d::TextFieldTTF *  sender)
overridevirtual

在文件 TextInputTest.cpp260 行定义.

261{
262 if (! _action)
263 {
264 _textField->runAction(_textFieldAction);
265 _action = true;
266 }
267 return false;
268}

引用了 _action, _textField , 以及 _textFieldAction.

◆ onTextFieldDeleteBackward()

bool TextFieldTTFActionTest::onTextFieldDeleteBackward ( cocos2d::TextFieldTTF *  sender,
const char *  delText,
size_t  nLen 
)
overridevirtual

在文件 TextInputTest.cpp326 行定义.

327{
328 // create a delete text sprite and do some action
329 auto label = Label::createWithSystemFont(delText, FONT_NAME, FONT_SIZE);
330 this->addChild(label);
331
332 // move the sprite to fly out
333 auto beginPos = sender->getPosition();
334 auto textfieldSize = sender->getContentSize();
335 auto labelSize = label->getContentSize();
336 beginPos.x += (textfieldSize.width - labelSize.width) / 2.0f;
337
338 auto winSize = Director::getInstance()->getWinSize();
339 Vec2 endPos(- winSize.width / 4.0f, winSize.height * (0.5 + (float)rand() / (2.0f * RAND_MAX)));
340
341 float duration = 1;
342 float rotateDuration = 0.2f;
343 int repeatTime = 5;
344 label->setPosition(beginPos);
345
346 auto seq = Sequence::create(
347 Spawn::create(
348 MoveTo::create(duration, endPos),
349 Repeat::create(
350 RotateBy::create(rotateDuration, (rand()%2) ? 360 : -360),
351 repeatTime),
352 FadeOut::create(duration),
353 nullptr),
354 CallFuncN::create(CC_CALLBACK_1(TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction, this)),
355 nullptr);
356 label->runAction(seq);
357 return false;
358}
void callbackRemoveNodeWhenDidAction(Node *node)

引用了 callbackRemoveNodeWhenDidAction(), FONT_NAME , 以及 FONT_SIZE.

+ 函数调用图:

◆ onTextFieldDetachWithIME()

bool TextFieldTTFActionTest::onTextFieldDetachWithIME ( cocos2d::TextFieldTTF *  sender)
overridevirtual

在文件 TextInputTest.cpp270 行定义.

271{
272 if (_action)
273 {
274 _textField->stopAction(_textFieldAction);
275 _textField->setOpacity(255);
276 _action = false;
277 }
278 return false;
279}

引用了 _action, _textField , 以及 _textFieldAction.

◆ onTextFieldInsertText()

bool TextFieldTTFActionTest::onTextFieldInsertText ( cocos2d::TextFieldTTF *  sender,
const char *  text,
size_t  nLen 
)
overridevirtual

在文件 TextInputTest.cpp281 行定义.

282{
283 // if insert enter, treat as default to detach with ime
284 if ('\n' == *text)
285 {
286 return false;
287 }
288
289 // if the textfield's char count more than _charLimit, doesn't insert text anymore.
290 if (sender->getCharCount() >= _charLimit)
291 {
292 return true;
293 }
294
295 // create a insert text sprite and do some action
296 auto label = Label::createWithSystemFont(text, FONT_NAME, FONT_SIZE);
297 this->addChild(label);
298 Color3B color(226, 121, 7);
299 label->setColor(color);
300
301 // move the sprite from top to position
302 auto endPos = sender->getPosition();
303 if (sender->getCharCount())
304 {
305 endPos.x += sender->getContentSize().width / 2;
306 }
307 auto inputTextSize = label->getContentSize();
308 Vec2 beginPos(endPos.x, Director::getInstance()->getWinSize().height - inputTextSize.height * 2);
309
310 float duration = 0.5;
311 label->setPosition(beginPos);
312 label->setScale(8);
313
314 auto seq = Sequence::create(
315 Spawn::create(
316 MoveTo::create(duration, endPos),
317 ScaleTo::create(duration, 1),
318 FadeOut::create(duration),
319 nullptr),
320 CallFuncN::create(CC_CALLBACK_1(TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction, this)),
321 nullptr);
322 label->runAction(seq);
323 return false;
324}

引用了 _charLimit, callbackRemoveNodeWhenDidAction(), FONT_NAME , 以及 FONT_SIZE.

+ 函数调用图:

◆ subtitle()

std::string TextFieldTTFActionTest::subtitle ( ) const
overridevirtual

重载 TestCase .

在文件 TextInputTest.cpp195 行定义.

196{
197 return "CCTextFieldTTF with action and char limit test";
198}

类成员变量说明

◆ _action

bool TextFieldTTFActionTest::_action
private

在文件 TextInputTest.h79 行定义.

被这些函数引用 onEnter(), onTextFieldAttachWithIME() , 以及 onTextFieldDetachWithIME().

◆ _charLimit

size_t TextFieldTTFActionTest::_charLimit
private

在文件 TextInputTest.h80 行定义.

被这些函数引用 onEnter() , 以及 onTextFieldInsertText().

◆ _textField

cocos2d::TextFieldTTF* TextFieldTTFActionTest::_textField
private

在文件 TextInputTest.h77 行定义.

被这些函数引用 onEnter(), onTextFieldAttachWithIME() , 以及 onTextFieldDetachWithIME().

◆ _textFieldAction

cocos2d::Action* TextFieldTTFActionTest::_textFieldAction
private

在文件 TextInputTest.h78 行定义.

被这些函数引用 onEnter(), onExit(), onTextFieldAttachWithIME() , 以及 onTextFieldDetachWithIME().


该类的文档由以下文件生成: