mirror of
https://github.com/geode-sdk/geode.git
synced 2025-04-01 07:40:18 -04:00
Make CCTextInputNode
work in nested hierarchies (#317)
This commit is contained in:
parent
626b86c328
commit
746966c423
1 changed files with 27 additions and 0 deletions
27
loader/src/hooks/CCTextInputNode.cpp
Normal file
27
loader/src/hooks/CCTextInputNode.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <Geode/modify/CCTextInputNode.hpp>
|
||||
|
||||
using namespace geode::prelude;
|
||||
|
||||
// rob only uses `CCTextInputNode`s in mostly-flat hierarchies, which still
|
||||
// happen to work with the weird vanilla code. this fix makes it work even in
|
||||
// deep hierarchies, because the vanilla code uses `getParent` and manually
|
||||
// calculates the child location in the world space based on that rather than
|
||||
// using `convertToNodeSpace`.
|
||||
|
||||
struct CCTextInputNodeFix : Modify<CCTextInputNodeFix, CCTextInputNode> {
|
||||
bool ccTouchBegan(CCTouch* touch, CCEvent* event) {
|
||||
CCPoint pos = this->convertTouchToNodeSpace(touch);
|
||||
CCSize size = this->getContentSize();
|
||||
|
||||
pos += m_textField->getAnchorPoint() * size;
|
||||
|
||||
if (pos.x < 0 || pos.x > size.width || pos.y < 0 || pos.y > size.height)
|
||||
return false;
|
||||
if (!m_delegate->allowTextInput(this))
|
||||
return false;
|
||||
|
||||
this->onClickTrackNode(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
Loading…
Add table
Reference in a new issue