diff --git a/misc/Window.m b/misc/Window.m index 96d93a7a1..d4e5a76bd 100644 --- a/misc/Window.m +++ b/misc/Window.m @@ -11,54 +11,70 @@ static NSWindow* winHandle; extern void Window_CommonInit(void); void Window_Init(void) { - appHandle = [NSApplication sharedApplication]; - [appHandle activateIgnoringOtherApps: YES]; - Window_CommonInit(); + appHandle = [NSApplication sharedApplication]; + [appHandle activateIgnoringOtherApps: YES]; + Window_CommonInit(); } #define Display_CentreX(width) (Display_Bounds.X + (Display_Bounds.Width - width) / 2) #define Display_CentreY(height) (Display_Bounds.Y + (Display_Bounds.Height - height) / 2) void Window_Create(int width, int height) { - NSRect rect; - // TODO: don't set, RefreshBounds - Window_Width = width; - Window_Height = height; - Window_Exists = true; + NSRect rect; + // TODO: don't set, RefreshBounds + Window_Width = width; + Window_Height = height; + Window_Exists = true; - rect.origin.x = Display_CentreX(width); - rect.origin.y = Display_CentreY(height); - rect.size.width = width; - rect.size.height = height; - // TODO: opentk seems to flip y? + rect.origin.x = Display_CentreX(width); + rect.origin.y = Display_CentreY(height); + rect.size.width = width; + rect.size.height = height; + // TODO: opentk seems to flip y? - winHandle = [NSWindow alloc]; - [winHandle initWithContentRect: rect styleMask: NSTitledWindowMask|NSClosableWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask backing:0 defer:NO]; + winHandle = [NSWindow alloc]; + [winHandle initWithContentRect: rect styleMask: NSTitledWindowMask|NSClosableWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask backing:0 defer:NO]; - [winHandle makeKeyAndOrderFront: appHandle]; + [winHandle makeKeyAndOrderFront: appHandle]; } void Window_SetTitle(const String* title) { - UInt8 str[600]; - CFStringRef titleCF; - int len; + UInt8 str[600]; + CFStringRef titleCF; + int len; - /* TODO: This leaks memory, old title isn't released */ - len = Platform_ConvertString(str, title); - titleCF = CFStringCreateWithBytes(kCFAllocatorDefault, str, len, kCFStringEncodingUTF8, false); - [winHandle setTitle: (NSString*)titleCF]; + /* TODO: This leaks memory, old title isn't released */ + len = Platform_ConvertString(str, title); + titleCF = CFStringCreateWithBytes(kCFAllocatorDefault, str, len, kCFStringEncodingUTF8, false); + [winHandle setTitle: (NSString*)titleCF]; +} + +static int Window_MapMouse(int button) { + if (button == 0) return Key_ } void Window_ProcessEvents(void) { - NSEvent* ev; - int type; + NSEvent* ev; + int type, button; - for (;;) { - ev = [appHandle nextEventMatchingMask: 0xFFFFFFFFU untilDate:Nil inMode:NSDefaultRunLoopMode dequeue:YES]; - if (!ev) break; + for (;;) { + ev = [appHandle nextEventMatchingMask: 0xFFFFFFFFU untilDate:Nil inMode:NSDefaultRunLoopMode dequeue:YES]; + if (!ev) break; + type = [ev type]; - type = [ev type]; - Platform_Log1("EVENT: %i", &type); - [appHandle sendEvent:ev]; - } + switch (type) { + case NSLeftMouseDown: + case NSRightMouseDown: + case NSOtherMouseDown: + button = [ev buttonNumber]; + + case NSLeftMouseUp: + case NSRightMouseUp: + case NSOtherMouseUp: + button = [ev buttonNumber]; + } + + Platform_Log1("EVENT: %i", &type); + [appHandle sendEvent:ev]; + } } diff --git a/misc/info.plist b/misc/info.plist new file mode 100644 index 000000000..561cb5aba --- /dev/null +++ b/misc/info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleExecutable + ClassiCube + CFBundleIconFile + ClassiCube + CFBundleIdentifier + com.classicube.game + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ClassiCube + CFBundlePackageType + APPL + CFBundleDisplayName + ClassiCube + + \ No newline at end of file diff --git a/src/Window.c b/src/Window.c index 3add03edd..1545ae1b7 100644 --- a/src/Window.c +++ b/src/Window.c @@ -3730,15 +3730,35 @@ void Window_ExitFullscreen(void) { } void Window_SetSize(int width, int height) { } void Window_Close(void) { } +#define NSMouseMoved 5 +#define NSLeftMouseDragged 6 +#define NSRightMouseDragged 7 +#define NSKeyDown 10 +#define NSKeyUp 11 +#define NSScrollWheel 22 +#define NSOtherMouseDragged 27 + void Window_ProcessEvents(void) { id ev; - int type; + int button, type; for (;;) { ev = objc_msgSend(appHandle, selNextEvent, 0xFFFFFFFFU, NULL, NSDefaultRunLoopMode, true); if (!ev) break; - type = (int)objc_msgSend(ev, selType); + + switch (type) { + case 1: /* NSLeftMouseDown */ + case 3: /* NSRightMouseDown */ + case 25: /* NSOtherMouseDown */ + button = (int)objc_msgSend(ev, sel_registerName("buttonNumber")); + + case 2: /* NSLeftMouseUp */ + case 4: /* NSRightMouseUp */ + case 26: /* NSOtherMouseUp */ + button = (int)objc_msgSend(ev, sel_registerName("buttonNumber")); + + } Platform_Log1("EVENT: %i", &type); objc_msgSend(appHandle, selSendEvent, ev); }