Skip to content

Commit 9eafa7c

Browse files
authored
Fix MacOS mouse position getter (#18)
* yeah * misspelt CCPoint and use not deprecated masks * explicitly cast double to float * update workflow * fix mouse positioning * ok aaactual fix of the mouse position * mouseLocation is not a method oops * okay * waiter waiter! more explicit casting please * ok now i should substract window size from y coord * log * windows workflow
1 parent b4d3d84 commit 9eafa7c

File tree

4 files changed

+36
-33
lines changed

4 files changed

+36
-33
lines changed

.github/workflows/geode-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- uses: geode-sdk/build-geode-mod/combine@main
4343
id: build
4444

45-
- uses: actions/upload-artifact@v3
45+
- uses: actions/upload-artifact@v4
4646
with:
4747
name: Build Output
4848
path: ${{ steps.build.outputs.build-output }}

mod.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "4.1.2",
2+
"geode": "4.2.0",
33
"gd": {
44
"win": "2.2074",
55
"mac": "2.2074"
@@ -10,14 +10,14 @@
1010
"developer": "SpaghettDev",
1111
"description": "Makes inputs behave like they should.",
1212
"tags": ["enhancement"],
13-
"links": {
14-
"community": "https://discord.gg/3bShQb6Jz3",
15-
"source": "https://github.com/SpaghettDev/BetterInputs"
16-
},
17-
"issues": {
18-
"info": "Report any bugs/suggestions here.",
19-
"url": "https://github.com/SpaghettDev/BetterInputs/issues"
20-
},
13+
"links": {
14+
"community": "https://discord.gg/3bShQb6Jz3",
15+
"source": "https://github.com/SpaghettDev/BetterInputs"
16+
},
17+
"issues": {
18+
"info": "Report any bugs/suggestions here.",
19+
"url": "https://github.com/SpaghettDev/BetterInputs/issues"
20+
},
2121
"settings": {
2222
"allow-any-character": {
2323
"type": "bool",

src/macos.mm

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ inline bool keyDown(PlatformKey key, NSEvent* event)
2424
switch (key)
2525
{
2626
case BI::PlatformKey::LEFT_CONTROL:
27-
return [event modifierFlags] & NSCommandKeyMask;
27+
return [event modifierFlags] & NSEventModifierFlagCommand;
2828
case BI::PlatformKey::LEFT_SHIFT:
29-
return [event modifierFlags] & NSShiftKeyMask;
29+
return [event modifierFlags] & NSEventModifierFlagShift;
3030
case BI::PlatformKey::LEFT_ALT:
31-
return [event modifierFlags] & NSAlternateKeyMask;
31+
return [event modifierFlags] & NSEventModifierFlagOption;
3232
}
3333

3434
return false;
@@ -37,17 +37,24 @@ 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 window = [event window];
43+
auto windowFrame = [window frame];
44+
auto viewFrame = [[window contentView] frame];
45+
auto scaleFactor = cocos2d::CCPoint{
46+
cocos2d::CCDirector::get()->getWinSize()
47+
} / cocos2d::CCPoint{
48+
static_cast<float>(viewFrame.size.width),
49+
static_cast<float>(viewFrame.size.height)
50+
};
51+
auto mousePos = [NSEvent mouseLocation];
52+
53+
return cocos2d::CCPoint{
54+
static_cast<float>(mousePos.x - windowFrame.origin.x),
55+
static_cast<float>(mousePos.y - windowFrame.origin.y)
56+
} * scaleFactor;
57+
}
5158
}
5259
}
5360

@@ -204,13 +211,11 @@ void mouseDownExec(EAGLView* self, SEL sel, NSEvent* event)
204211
if (!g_selectedInput)
205212
return mouseDownExecOIMP(self, sel, event);
206213

207-
// cocos2d::CCPoint mousePos = BI::cocos::getMousePosition(event);
208-
cocos2d::CCPoint mousePos = BI::cocos::getMousePosition();
214+
cocos2d::CCSize winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
215+
cocos2d::CCPoint mousePos = BI::cocos::getMousePosition(event);
209216

210-
// NSWindow's mouse origin is the bottom left
211-
// CCTouch's mouse origin is top left (because of course it is)
212217
cocos2d::CCTouch touch{};
213-
touch.setTouchInfo(0, mousePos.x, mousePos.y);
218+
touch.setTouchInfo(0, mousePos.x, winSize.height - mousePos.y);
214219

215220
g_selectedInput->useUpdateBlinkPos(true);
216221

src/utils.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,18 @@ namespace BI
9999

100100
namespace cocos
101101
{
102+
#ifdef GEODE_IS_WINDOWS
102103
inline cocos2d::CCPoint getMousePosition()
103104
{
104-
#ifdef GEODE_IS_WINDOWS
105105
auto* director = cocos2d::CCDirector::sharedDirector();
106106
auto* gl = director->getOpenGLView();
107107
auto winSize = director->getWinSize();
108108
auto frameSize = gl->getFrameSize();
109109
auto mouse = gl->getMousePosition() / frameSize;
110110

111111
return cocos2d::CCPoint{ mouse.x, 1.f - mouse.y } * winSize;
112-
#elif defined(GEODE_IS_MACOS)
113-
return geode::cocos::getMousePos();
114-
#endif
115112
}
113+
#endif
116114

117115
inline bool isPositionInNode(cocos2d::CCNode* node, const cocos2d::CCPoint& pos)
118116
{

0 commit comments

Comments
 (0)