@@ -37,17 +37,16 @@ inline bool keyDown(PlatformKey key, NSEvent* event)
3737
3838 namespace cocos
3939 {
40- // TODO: fix
41- // inline cocos2d::CCPoint getMousePosition(NSEvent* event)
42- // {
43- // auto windowFrame = [[event window] frame];
44- // auto viewFrame = [[[event window] contentView] frame];
45- // auto winSize = cocos2d::CCDirector::get()->getWinSize();
46- // auto scaleFactor = cocos2d::CCPoint(winSize) / ccp(viewFrame.size.width, viewFrame.size.height);
47- // auto mouse = [event locationInWindow];
48-
49- // return ccp(mouse.x - windowFrame.origin.x, winSize.height - (mouse.y - windowFrame.origin.y)) * scaleFactor;
50- // }
40+ inline cocos2d::CCPoint getMousePosition (NSEvent * event)
41+ {
42+ auto windowFrame = [[event window ] frame ];
43+ auto viewFrame = [[[event window ] contentView ] frame ];
44+ auto winSize = cocos2d::CCDirector::get ()->getWinSize ();
45+ auto scaleFactor = cocos2d::CCPoint (winSize) / ccp (viewFrame.size .width , viewFrame.size .height );
46+ auto mouse = [event locationInWindow ];
47+
48+ return ccp (mouse.x - windowFrame.origin .x , winSize.height - (mouse.y - windowFrame.origin .y )) * scaleFactor;
49+ }
5150 }
5251}
5352
@@ -204,13 +203,17 @@ void mouseDownExec(EAGLView* self, SEL sel, NSEvent* event)
204203 if (!g_selectedInput)
205204 return mouseDownExecOIMP (self, sel, event);
206205
207- // cocos2d::CCPoint mousePos = BI::cocos::getMousePosition(event);
208- cocos2d::CCPoint mousePos = BI::cocos::getMousePosition ();
206+ NSPoint m = [event locationInWindow ];
207+
208+ geode::log::debug (" mouse pos is ({}, {})" , m.x , m.y );
209+
210+ cocos2d::CCSize winSize = cocos2d::CCDirector::sharedDirector ()->getWinSize ();
211+ cocos2d::CCPoint mousePos = cocos2d::CCpoint{ m.x , m.y };
209212
210213 // NSWindow's mouse origin is the bottom left
211214 // CCTouch's mouse origin is top left (because of course it is)
212215 cocos2d::CCTouch touch{};
213- touch.setTouchInfo (0 , mousePos.x , mousePos.y );
216+ touch.setTouchInfo (0 , mousePos.x , winSize. height - mousePos.y );
214217
215218 g_selectedInput->useUpdateBlinkPos (true );
216219
0 commit comments