|
10 | 10 | #import <Geode/cocos/platform/mac/EAGLView.h> |
11 | 11 | #import <objc/runtime.h> |
12 | 12 |
|
| 13 | +#include "BetterTextInputNode.hpp" |
| 14 | + |
13 | 15 | #include "types/TouchMessageType.hpp" |
| 16 | +#include "utils.hpp" |
| 17 | + |
| 18 | +namespace BI::platform |
| 19 | +{ |
| 20 | + inline bool keyDown(PlatformKey key, NSEvent* event) |
| 21 | + { |
| 22 | + switch (key) |
| 23 | + { |
| 24 | + case BI::PlatformKey::LEFT_CONTROL: |
| 25 | + return ([event modifierFlags] & NSCommandKeyMask); |
| 26 | + case BI::PlatformKey::LEFT_SHIFT: |
| 27 | + return ([event modifierFlags] & NSShiftKeyMask); |
| 28 | + } |
| 29 | + |
| 30 | + return false; |
| 31 | + } |
| 32 | +} |
14 | 33 |
|
15 | 34 | #define HOOK_OBJC_METHOD(klass, cleanFuncName, funcName) \ |
16 | 35 | auto cleanFuncName ## Method = class_getInstanceMethod(objc_getClass(#klass), @selector(funcName)); \ |
17 | 36 | cleanFuncName ## OIMP = method_getImplementation(cleanFuncName ## Method); \ |
18 | 37 | method_setImplementation(cleanFuncName ## Method, (EventType<klass>)&funcName); |
19 | 38 |
|
20 | | -#define CALL_OIMP(funcName) reinterpret_cast<decltype(&funcName)>(funcName ## OIMP)(self, sel, event) |
21 | | - |
22 | 39 | template <typename T> |
23 | 40 | using EventType = void(*)(T*, SEL, NSEvent*); |
24 | 41 |
|
25 | 42 |
|
26 | 43 | static EventType<EAGLView> keyDownExecOIMP; |
27 | 44 | void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { |
28 | 45 | if (!g_selectedInput) |
29 | | - CALL_OIMP(keyDownExec); |
| 46 | + keyDownExecOIMP(self, sel, event); |
30 | 47 |
|
31 | 48 | // on click, can be held |
32 | 49 | if ( |
@@ -140,37 +157,37 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { |
140 | 157 | !BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event) && |
141 | 158 | [event keyCode] == kVK_Return |
142 | 159 | ) { |
143 | | - CALL_OIMP(keyDownExec); |
| 160 | + keyDownExec(self, sel, event); |
144 | 161 | } |
145 | 162 | } |
146 | 163 | } |
147 | 164 |
|
148 | 165 | static EventType<EAGLView> keyUpExecOIMP; |
149 | 166 | void keyUpExec(EAGLView* self, SEL sel, NSEvent* event) { |
150 | 167 | if (!g_selectedInput) |
151 | | - CALL_OIMP(keyUpExec); |
| 168 | + keyUpExec(self, sel, event); |
152 | 169 | } |
153 | 170 |
|
154 | 171 |
|
155 | 172 | // TODO: move to hooking mouseDownExec |
156 | 173 | // handles mouse clicks |
157 | | -struct BetterTouchDispatcher : Modify<BetterTouchDispatcher, CCTouchDispatcher> |
| 174 | +struct BetterTouchDispatcher : geode::Modify<BetterTouchDispatcher, cocos2d::CCTouchDispatcher> |
158 | 175 | { |
159 | 176 | // https://github.com/ninXout/Crystal-Client/blob/7df5a8336ccb852bc984e55dd29ca27bb1741443/src/ImGui/ImGui.cpp#L96 |
160 | 177 | void touches(cocos2d::CCSet* touches, cocos2d::CCEvent* event, unsigned int type) |
161 | 178 | { |
162 | 179 | if (!g_selectedInput) |
163 | | - return CCTouchDispatcher::touches(touches, event, type); |
| 180 | + return cocos2d::CCTouchDispatcher::touches(touches, event, type); |
164 | 181 |
|
165 | | - auto* touch = static_cast<CCTouch*>(touches->anyObject()); |
| 182 | + auto* touch = static_cast<cocos2d::CCTouch*>(touches->anyObject()); |
166 | 183 | const auto touchPos = touch->getLocation(); |
167 | 184 |
|
168 | 185 | if (type == TouchMessageType::Began) |
169 | 186 | { |
170 | | - CCSize winSize = CCDirector::sharedDirector()->getWinSize(); |
| 187 | + CCSize winSize = cocos2d::CCDirector::sharedDirector()->getWinSize(); |
171 | 188 |
|
172 | 189 | // the touch event's origin is bottom left |
173 | | - CCTouch touch{}; |
| 190 | + cocos2d::CCTouch touch{}; |
174 | 191 | touch.setTouchInfo(0, touchPos.x, winSize.height - touchPos.y); |
175 | 192 |
|
176 | 193 | g_selectedInput->useUpdateBlinkPos(true); |
|
0 commit comments