From efdb9180e4b2674fa9c7f09b423ea4cda317e191 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 26 Feb 2013 11:16:26 +0800 Subject: [PATCH] fixed #1750: [iOS] CCEditBox's position is incorrect when it's added to a non-fullscreen CCNode. --- extensions/GUI/CCEditBox/CCEditBox.cpp | 5 ++++- extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm | 16 ++++++++++++---- .../ExtensionsTest/EditBoxTest/EditBoxTest.cpp | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/extensions/GUI/CCEditBox/CCEditBox.cpp b/extensions/GUI/CCEditBox/CCEditBox.cpp index e9c2e48434..8e17e203b9 100644 --- a/extensions/GUI/CCEditBox/CCEditBox.cpp +++ b/extensions/GUI/CCEditBox/CCEditBox.cpp @@ -280,7 +280,10 @@ void CCEditBox::keyboardWillShow(CCIMEKeyboardNotificationInfo& info) CCRect rectTracked = getRect(this); // some adjustment for margin between the keyboard and the edit box. rectTracked.origin.y -= 4; - + if (m_pParent != NULL) + { + rectTracked.origin = m_pParent->convertToWorldSpace(rectTracked.origin); + } // if the keyboard area doesn't intersect with the tracking node area, nothing needs to be done. if (!rectTracked.intersectsRect(info.end)) { diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm index 15f334611d..9c1ba6cc6b 100644 --- a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm +++ b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm @@ -404,9 +404,12 @@ static CGPoint convertDesignCoordToScreenCoord(const CCPoint& designCoord, bool void CCEditBoxImplIOS::setPosition(const CCPoint& pos) { - m_obPosition = pos; - CCPoint designCoord = ccp(pos.x - m_tContentSize.width * m_obAnchorPoint.x, pos.y + m_tContentSize.height * (1 - m_obAnchorPoint.y)); - [m_systemControl setPosition:convertDesignCoordToScreenCoord(designCoord, m_bInRetinaMode)]; + if (!m_obPosition.equals(pos)) + { + m_obPosition = pos; + CCPoint designCoord = ccp(pos.x - m_tContentSize.width * m_obAnchorPoint.x, pos.y + m_tContentSize.height * (1 - m_obAnchorPoint.y)); + [m_systemControl setPosition:convertDesignCoordToScreenCoord(designCoord, m_bInRetinaMode)]; + } } void CCEditBoxImplIOS::setContentSize(const CCSize& size) @@ -424,7 +427,12 @@ void CCEditBoxImplIOS::setAnchorPoint(const CCPoint& anchorPoint) void CCEditBoxImplIOS::visit(void) { - + if(getCCEditBox()->getParent()) { + CCPoint p = getCCEditBox()->getParent()->convertToWorldSpace(getCCEditBox()->getPosition()); + setPosition(p); + } else { + setPosition(getCCEditBox()->getPosition()); + } } void CCEditBoxImplIOS::openKeyboard() diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp index 40355e93bd..81b2f518b2 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp @@ -75,6 +75,8 @@ EditBoxTest::EditBoxTest() m_pEditEmail->setInputMode(kEditBoxInputModeEmailAddr); m_pEditEmail->setDelegate(this); addChild(m_pEditEmail); + + this->setPosition(ccp(10, 20)); } EditBoxTest::~EditBoxTest()