@@ -10,6 +10,7 @@ TextInputTests::TextInputTests()
10
10
ADD_TEST_CASE (TextFieldTTFDefaultTest);
11
11
ADD_TEST_CASE (TextFieldTTFActionTest);
12
12
ADD_TEST_CASE (TextFieldTTFSecureTextEntryTest);
13
+ ADD_TEST_CASE (TextFieldTTSetCursorFromPoint);
13
14
}
14
15
15
16
static Rect getRect (Node * node)
@@ -110,7 +111,7 @@ void KeyboardNotificationLayer::onTouchEnded(Touch *touch, Event *event)
110
111
Rect rect;
111
112
rect.size = _trackNode->getContentSize ();
112
113
auto clicked = isScreenPointInRect (endPos, Camera::getVisitingCamera (), _trackNode->getWorldToNodeTransform (), rect, nullptr );
113
- this ->onClickTrackNode (clicked);
114
+ this ->onClickTrackNode (clicked, endPos );
114
115
CCLOG (" ----------------------------------" );
115
116
}
116
117
@@ -123,7 +124,7 @@ std::string TextFieldTTFDefaultTest::subtitle() const
123
124
return " TextFieldTTF with default behavior test" ;
124
125
}
125
126
126
- void TextFieldTTFDefaultTest::onClickTrackNode (bool bClicked)
127
+ void TextFieldTTFDefaultTest::onClickTrackNode (bool bClicked, const Vec2& touchPos )
127
128
{
128
129
auto pTextField = (TextFieldTTF*)_trackNode;
129
130
if (bClicked)
@@ -172,7 +173,7 @@ std::string TextFieldTTFActionTest::subtitle() const
172
173
return " CCTextFieldTTF with action and char limit test" ;
173
174
}
174
175
175
- void TextFieldTTFActionTest::onClickTrackNode (bool bClicked)
176
+ void TextFieldTTFActionTest::onClickTrackNode (bool bClicked, const Vec2& touchPos )
176
177
{
177
178
auto pTextField = (TextFieldTTF*)_trackNode;
178
179
if (bClicked)
@@ -373,5 +374,57 @@ void TextFieldTTFSecureTextEntryTest::onEnter()
373
374
#endif
374
375
pTextField->setSecureTextEntry (true );
375
376
377
+ _trackNode = pTextField;
378
+ }
379
+
380
+ // ////////////////////////////////////////////////////////////////////////
381
+ // implement TextFieldTTSetCursorFromPoint
382
+ // ////////////////////////////////////////////////////////////////////////
383
+
384
+ std::string TextFieldTTSetCursorFromPoint::subtitle () const
385
+ {
386
+ return " TextFieldTTF with setCursorFromPoint test" ;
387
+ }
388
+
389
+ void TextFieldTTSetCursorFromPoint::onClickTrackNode (bool bClicked, const Vec2& touchPos)
390
+ {
391
+ auto pTextField = (TextFieldTTF*)_trackNode;
392
+ if (bClicked)
393
+ {
394
+ // TextFieldTTFTest be clicked
395
+ CCLOG (" TextFieldTTSetCursorFromPoint:TextFieldTTF attachWithIME" );
396
+ pTextField->attachWithIME ();
397
+
398
+ // Set new position cursor
399
+ pTextField->setCursorFromPoint (touchPos, Camera::getVisitingCamera ());
400
+ }
401
+ else
402
+ {
403
+ // TextFieldTTFTest not be clicked
404
+ CCLOG (" TextFieldTTSetCursorFromPoint:TextFieldTTF detachWithIME" );
405
+ pTextField->detachWithIME ();
406
+ }
407
+ }
408
+
409
+ void TextFieldTTSetCursorFromPoint::onEnter ()
410
+ {
411
+ KeyboardNotificationLayer::onEnter ();
412
+
413
+ // add TextFieldTTF
414
+ auto s = Director::getInstance ()->getWinSize ();
415
+
416
+ auto pTextField = TextFieldTTF::textFieldWithPlaceHolder (" <click here for input>" ,
417
+ FONT_NAME,
418
+ FONT_SIZE);
419
+ addChild (pTextField);
420
+
421
+ #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
422
+ // on android, TextFieldTTF cannot auto adjust its position when soft-keyboard pop up
423
+ // so we had to set a higher position to make it visible
424
+ pTextField->setPosition (Vec2 (s.width / 2 , s.height / 2 + 50 ));
425
+ #else
426
+ pTextField->setPosition (Vec2 (s.width / 2 , s.height / 2 ));
427
+ #endif
428
+
376
429
_trackNode = pTextField;
377
430
}
0 commit comments