Skip to content

Commit 1de70c4

Browse files
committed
ok aaactual fix of the mouse position
1 parent 6430285 commit 1de70c4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/macos.mm

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,16 @@ inline bool keyDown(PlatformKey key, NSEvent* event)
3939
{
4040
inline cocos2d::CCPoint getMousePosition(NSEvent* event)
4141
{
42-
NSWindow* window = [event window];
43-
NSView* contentView = [window contentView];
44-
NSPoint mouseInWindow = [event locationInWindow];
45-
NSPoint mouseInView = [contentView convertPoint:mouseInWindow fromView:nil];
46-
47-
NSRect viewFrame = [contentView frame];
48-
cocos2d::CCSize winSize = cocos2d::CCDirector::get()->getWinSize();
49-
cocos2d::CCPoint scaleFactor = cocos2d::CCPoint(winSize.width / viewFrame.size.width, winSize.height / viewFrame.size.height);
50-
51-
CGFloat cocosY = [contentView isFlipped] ? (viewFrame.size.height - mouseInView.y) : mouseInView.y;
52-
53-
return cocos2d::CCPoint(mouseInView.x * scaleFactor.x, cocosY * scaleFactor.y);
42+
auto window = [event window];
43+
auto windowFrame = [window frame];
44+
auto viewFrame = [[window contentView] frame];
45+
auto scaleFactor = cocos2d::CCPoint{ cocos2d::CCDirector::get()->getWinSize() } / cocos2d::CCPoint{ viewFrame.size.width, viewFrame.size.height };
46+
auto mouse = [event mouseLocation];
47+
48+
return cocos2d::CCPoint{
49+
mouse.x - windowFrame.origin.x,
50+
mouse.y - windowFrame.origin.y
51+
} * scaleFactor;
5452
}
5553
}
5654
}
@@ -211,6 +209,8 @@ void mouseDownExec(EAGLView* self, SEL sel, NSEvent* event)
211209
cocos2d::CCSize winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
212210
cocos2d::CCPoint mousePos = BI::cocos::getMousePosition(event);
213211

212+
geode::log::debug("mouse pos: {}", mousePos);
213+
214214
cocos2d::CCTouch touch{};
215215
touch.setTouchInfo(0, mousePos.x, /* winSize.height - */ mousePos.y);
216216

0 commit comments

Comments
 (0)