Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/geode-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- uses: geode-sdk/build-geode-mod/combine@main
id: build

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: Build Output
path: ${{ steps.build.outputs.build-output }}
18 changes: 9 additions & 9 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"geode": "4.1.2",
"geode": "4.2.0",
"gd": {
"win": "2.2074",
"mac": "2.2074"
Expand All @@ -10,14 +10,14 @@
"developer": "SpaghettDev",
"description": "Makes inputs behave like they should.",
"tags": ["enhancement"],
"links": {
"community": "https://discord.gg/3bShQb6Jz3",
"source": "https://github.com/SpaghettDev/BetterInputs"
},
"issues": {
"info": "Report any bugs/suggestions here.",
"url": "https://github.com/SpaghettDev/BetterInputs/issues"
},
"links": {
"community": "https://discord.gg/3bShQb6Jz3",
"source": "https://github.com/SpaghettDev/BetterInputs"
},
"issues": {
"info": "Report any bugs/suggestions here.",
"url": "https://github.com/SpaghettDev/BetterInputs/issues"
},
"settings": {
"allow-any-character": {
"type": "bool",
Expand Down
43 changes: 24 additions & 19 deletions src/macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ inline bool keyDown(PlatformKey key, NSEvent* event)
switch (key)
{
case BI::PlatformKey::LEFT_CONTROL:
return [event modifierFlags] & NSCommandKeyMask;
return [event modifierFlags] & NSEventModifierFlagCommand;
case BI::PlatformKey::LEFT_SHIFT:
return [event modifierFlags] & NSShiftKeyMask;
return [event modifierFlags] & NSEventModifierFlagShift;
case BI::PlatformKey::LEFT_ALT:
return [event modifierFlags] & NSAlternateKeyMask;
return [event modifierFlags] & NSEventModifierFlagOption;
}

return false;
Expand All @@ -37,17 +37,24 @@ inline bool keyDown(PlatformKey key, NSEvent* event)

namespace cocos
{
// TODO: fix
// inline cocos2d::CCPoint getMousePosition(NSEvent* event)
// {
// auto windowFrame = [[event window] frame];
// auto viewFrame = [[[event window] contentView] frame];
// auto winSize = cocos2d::CCDirector::get()->getWinSize();
// auto scaleFactor = cocos2d::CCPoint(winSize) / ccp(viewFrame.size.width, viewFrame.size.height);
// auto mouse = [event locationInWindow];

// return ccp(mouse.x - windowFrame.origin.x, winSize.height - (mouse.y - windowFrame.origin.y)) * scaleFactor;
// }
inline cocos2d::CCPoint getMousePosition(NSEvent* event)
{
auto window = [event window];
auto windowFrame = [window frame];
auto viewFrame = [[window contentView] frame];
auto scaleFactor = cocos2d::CCPoint{
cocos2d::CCDirector::get()->getWinSize()
} / cocos2d::CCPoint{
static_cast<float>(viewFrame.size.width),
static_cast<float>(viewFrame.size.height)
};
auto mousePos = [NSEvent mouseLocation];

return cocos2d::CCPoint{
static_cast<float>(mousePos.x - windowFrame.origin.x),
static_cast<float>(mousePos.y - windowFrame.origin.y)
} * scaleFactor;
}
}
}

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

// cocos2d::CCPoint mousePos = BI::cocos::getMousePosition(event);
cocos2d::CCPoint mousePos = BI::cocos::getMousePosition();
cocos2d::CCSize winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
cocos2d::CCPoint mousePos = BI::cocos::getMousePosition(event);

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

g_selectedInput->useUpdateBlinkPos(true);

Expand Down
6 changes: 2 additions & 4 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,18 @@ namespace BI

namespace cocos
{
#ifdef GEODE_IS_WINDOWS
inline cocos2d::CCPoint getMousePosition()
{
#ifdef GEODE_IS_WINDOWS
auto* director = cocos2d::CCDirector::sharedDirector();
auto* gl = director->getOpenGLView();
auto winSize = director->getWinSize();
auto frameSize = gl->getFrameSize();
auto mouse = gl->getMousePosition() / frameSize;

return cocos2d::CCPoint{ mouse.x, 1.f - mouse.y } * winSize;
#elif defined(GEODE_IS_MACOS)
return geode::cocos::getMousePos();
#endif
}
#endif

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