Skip to content

Commit

Permalink
Changes Cocoa references to Quartz and moved funcs into class
Browse files Browse the repository at this point in the history
Changes references to Cocoa framework in class interface class
names to Quartz such that they match existing Dolphin interfaces.

Additionally, moves the `get_bounds` and `getWindowCenter` helper
functions into the `QuartzInputMouse` class as private methods
as they do not need to be exposed.
  • Loading branch information
brandonsorensen committed May 23, 2022
1 parent 3bafa82 commit 0168201
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
10 changes: 5 additions & 5 deletions Source/Core/InputCommon/QuartzInputMouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ namespace prime
{

bool InitCocoaInputMouse(uint32_t* windowid);
CGRect getBounds(uint32_t* m_windowid);
CGPoint getWindowCenter(uint32_t* m_windowid);

class CocoaInputMouse: public GenericMouse
class QuartzInputMouse: public GenericMouse
{
public:
explicit CocoaInputMouse(uint32_t* windowid);
explicit QuartzInputMouse(uint32_t* windowid);
void UpdateInput() override;
void LockCursorToGameWindow() override;

private:
CGPoint current_loc, center;
CGEventRef event;
CGEventRef event{};
uint32_t* m_windowid;
CGRect getBounds();
CGPoint getWindowCenter();
};

}
27 changes: 13 additions & 14 deletions Source/Core/InputCommon/QuartzInputMouse.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

bool InitCocoaInputMouse(uint32_t* windowid)
{
g_mouse_input = new CocoaInputMouse(windowid);
g_mouse_input = new QuartzInputMouse(windowid);
return true;
}

CocoaInputMouse::CocoaInputMouse(uint32_t* windowid)
QuartzInputMouse::QuartzInputMouse(uint32_t* windowid)
{
m_windowid = windowid;
center = getWindowCenter(m_windowid);
center = current_loc = getWindowCenter();
}

void CocoaInputMouse::UpdateInput()
void QuartzInputMouse::UpdateInput()
{
event = CGEventCreate(nil);
current_loc = CGEventGetLocation(event);
CFRelease(event);
center = getWindowCenter(m_windowid);
center = getWindowCenter();
if (Host_RendererHasFocus() && cursor_locked)
{
this->dx += current_loc.x - center.x;
Expand All @@ -40,11 +40,11 @@ bool InitCocoaInputMouse(uint32_t* windowid)
LockCursorToGameWindow();
}

void CocoaInputMouse::LockCursorToGameWindow()
void QuartzInputMouse::LockCursorToGameWindow()
{
if (Host_RendererHasFocus() && cursor_locked)
{
// Hack to avoid short bit of input supression after warp
// Hack to avoid short bit of input suppression after warp
// Credit/explanation: https://stackoverflow.com/a/17559012/7341382
CGWarpMouseCursorPosition(center);
CGAssociateMouseAndMouseCursorPosition(true);
Expand All @@ -59,7 +59,7 @@ bool InitCocoaInputMouse(uint32_t* windowid)
}
}

CGRect getBounds(uint32_t* m_windowid)
CGRect QuartzInputMouse::getBounds()
{
CGRect bounds = CGRectZero;
CGWindowID windowid[1] = {*m_windowid};
Expand All @@ -83,13 +83,12 @@ CGRect getBounds(uint32_t* m_windowid)
return bounds;
}

CGPoint getWindowCenter(uint32_t* m_windowid)
CGPoint QuartzInputMouse::getWindowCenter()
{
auto bounds = getBounds(m_windowid);
double x = bounds.origin.x + (bounds.size.width / 2);
double y = bounds.origin.y + (bounds.size.height / 2);
CGPoint center = {x, y};
return center;
const auto bounds = getBounds();
const double x = bounds.origin.x + (bounds.size.width / 2);
const double y = bounds.origin.y + (bounds.size.height / 2);
return CGPointMake(x, y);
}

}

0 comments on commit 0168201

Please sign in to comment.