Skip to content

Commit

Permalink
update RGFW for cocoa
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley committed Mar 8, 2024
1 parent 8d13a84 commit 196e290
Showing 1 changed file with 71 additions and 72 deletions.
143 changes: 71 additions & 72 deletions deps/RGFW.h
Original file line number Diff line number Diff line change
Expand Up @@ -4612,97 +4612,96 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) {

NSEvent* e = NSApplication_nextEventMatchingMask(NSApp, NSEventMaskAny, NSDate_distantFuture(), NSDefaultRunLoopMode, true);

if (win->event.type == RGFW_quit)
if (win->event.type == RGFW_quit || NSEvent_window(e) != win->src.window)
return NULL;

if (NSEvent_window(e) == win->src.window) {
u8 button = 0;

switch (NSEvent_type(e)) {
case NSEventTypeKeyDown:
win->event.type = RGFW_keyPressed;
win->event.keyCode = (u16)NSEvent_keyCode(e);
win->event.keyName = (char*)NSEvent_characters(e);
switch (NSEvent_type(e)) {
case NSEventTypeKeyDown:
win->event.type = RGFW_keyPressed;
win->event.keyCode = (u16)NSEvent_keyCode(e);
win->event.keyName = (char*)NSEvent_characters(e);

RGFW_keyMap[win->event.keyCode] = 1;
break;
RGFW_keyMap[win->event.keyCode] = 1;
break;

case NSEventTypeKeyUp:
win->event.type = RGFW_keyReleased;
win->event.keyCode = (u16)NSEvent_keyCode(e);
win->event.keyName = (char*)NSEvent_characters(e);
case NSEventTypeKeyUp:
win->event.type = RGFW_keyReleased;
win->event.keyCode = (u16)NSEvent_keyCode(e);
win->event.keyName = (char*)NSEvent_characters(e);

RGFW_keyMap[win->event.keyCode] = 0;
RGFW_keyMap[win->event.keyCode] = 0;
break;

break;
case NSEventTypeLeftMouseDown:
win->event.button = RGFW_mouseLeft;
win->event.type = RGFW_mouseButtonReleased;
break;

case NSEventTypeLeftMouseDown:
button = 1;
win->event.button = 2;
case NSEventTypeOtherMouseDown:
button = 1;
if (!button)
win->event.button = 1;
case NSEventTypeRightMouseDown:
if (!button)
win->event.button = 0;
case NSEventTypeOtherMouseDown:
win->event.button = RGFW_mouseMiddle;
win->event.type = RGFW_mouseButtonReleased;
break;

case NSEventTypeRightMouseDown:
win->event.button = RGFW_mouseRight;
win->event.type = RGFW_mouseButtonReleased;
break;

win->event.type = RGFW_mouseButtonPressed;
break;
case NSEventTypeLeftMouseUp:
win->event.button = RGFW_mouseLeft;
win->event.type = RGFW_mouseButtonReleased;
break;

case NSEventTypeOtherMouseUp:
win->event.button = RGFW_mouseMiddle;
win->event.type = RGFW_mouseButtonReleased;
break;

case NSEventTypeScrollWheel: {
double deltaY = NSEvent_deltaY(e);

case NSEventTypeLeftMouseUp:
button = 1;
if (NSEvent_type(e) == NSEventTypeLeftMouseUp)
win->event.button = RGFW_mouseLeft;
case NSEventTypeOtherMouseUp:
if (!button && NSEvent_type(e) == NSEventTypeOtherMouseUp)
win->event.button = RGFW_mouseMiddle;
button = 1;
case NSEventTypeScrollWheel:
if (!button && NSEvent_type(e) == NSEventTypeScrollWheel){
double deltaY = NSEvent_deltaY(e);
if (deltaY > 0)
win->event.button = RGFW_mouseScrollUp;

if (deltaY > 0)
win->event.button = RGFW_mouseScrollUp;
else if (deltaY < 0)
win->event.button = RGFW_mouseScrollDown;

win->event.type = RGFW_mouseButtonReleased;
break;
}
case NSEventTypeRightMouseUp:
win->event.button = RGFW_mouseRight;
win->event.type = RGFW_mouseButtonReleased;
break;

else if (deltaY < 0)
win->event.button = RGFW_mouseScrollDown;
}
button = 1;
case NSEventTypeRightMouseUp:
if (!button)
win->event.button = RGFW_mouseRight;
case NSEventTypeMouseMoved:
win->event.type = RGFW_mousePosChanged;

win->event.type = RGFW_mouseButtonReleased;
break;
NSPoint p = NSEvent_locationInWindow(e);

case NSEventTypeMouseMoved:
win->event.type = RGFW_mousePosChanged;
win->event.point.x = p.x;
win->event.point.y = p.y;
break;

NSPoint p = NSEvent_locationInWindow(e);

win->event.point.x = p.x;
win->event.point.y = p.y;
break;
default:
win->event.type = 0;
break;
}

if (win->src.cursorChanged && win->event.inFocus) {
if (win->src.cursor == NULL)
CGDisplayHideCursor(kCGDirectMainDisplay);
else {
CGDisplayShowCursor(kCGDirectMainDisplay);

default: break;
if (win->src.cursor == NULL)
NSCursor_set(NSCursor_arrowCursor());
else
NSCursor_set(win->src.cursor);
}

if (win->src.cursorChanged && win->event.inFocus) {
if (win->src.cursor == NULL)
CGDisplayHideCursor(kCGDirectMainDisplay);
else {
CGDisplayShowCursor(kCGDirectMainDisplay);

if (win->src.cursor == NULL)
NSCursor_set(NSCursor_arrowCursor());
else
NSCursor_set(win->src.cursor);
}

win->src.cursorChanged = false;
}
win->src.cursorChanged = false;
}

NSApplication_sendEvent(NSApp, e);
Expand Down

0 comments on commit 196e290

Please sign in to comment.