mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 19:15:14 -04:00
Add info.plist file for osx, start work on cocoa events
This commit is contained in:
parent
faf09dc423
commit
dfc1a4249c
@ -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];
|
||||
}
|
||||
}
|
||||
|
20
misc/info.plist
Normal file
20
misc/info.plist
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>ClassiCube</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>ClassiCube</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.classicube.game</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>ClassiCube</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>ClassiCube</string>
|
||||
</dict>
|
||||
</plist>
|
24
src/Window.c
24
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user