blob: 3a4b046d662611881f813d92dd147b49f12bd464 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
// license:BSD-3-Clause
// copyright-holders:R. Belmont
//============================================================
//
// windowcontroller.mm - our window/fullscreen manager
//
// Mac OSD by R. Belmont
//
//============================================================
#import "windowcontroller.h"
#import "mamefswindow.h"
@interface MAMEWindowController ()
{
MAMEFSWindow *_fullscreenWindow;
NSWindow* _standardWindow;
}
@end
@implementation MAMEWindowController
- (instancetype)initWithWindow:(NSWindow *)window
{
self = [super initWithWindow:window];
if (self)
{
_fullscreenWindow = nil;
_standardWindow = window;
}
return self;
}
- (void) goFullscreen
{
if(_fullscreenWindow)
{
return;
}
_fullscreenWindow = [[MAMEFSWindow alloc] init];
NSRect viewRect = [_fullscreenWindow frame];
[self.window.contentView setFrameSize: viewRect.size];
[_fullscreenWindow setContentView:self.window.contentView];
_standardWindow = [self window];
[_standardWindow orderOut:self];
[self setWindow:_fullscreenWindow];
[_fullscreenWindow makeKeyAndOrderFront:self];
}
- (void) goWindow
{
if(_fullscreenWindow == nil)
{
return;
}
NSRect viewRect = [_standardWindow frame];
[self.window.contentView setFrame:viewRect];
[self setWindow:_standardWindow];
[[self window] setContentView:_fullscreenWindow.contentView];
[[self window] makeKeyAndOrderFront:self];
_fullscreenWindow = nil;
}
- (void) keyDown:(NSEvent *)event
{
// unichar c = [[event charactersIgnoringModifiers] characterAtIndex:0];
[super keyDown:event];
}
- (NSWindow *) getWindow
{
if(_fullscreenWindow == nil)
{
return _standardWindow;
}
return _fullscreenWindow;
}
@end
void MacPollInputs()
{
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny
untilDate:[NSDate distantPast] // do not wait for event
inMode:NSDefaultRunLoopMode
dequeue:YES];
if (event)
{
[NSApp sendEvent:event];
[NSApp updateWindows];
}
}
void *GetOSWindow(void *wincontroller)
{
MAMEWindowController *wc = (MAMEWindowController *)wincontroller;
return [wc getWindow];
}
void *CreateMAMEWindow(const char *title, int x, int y, int w, int h, bool isFullscreen)
{
NSRect bounds = NSMakeRect(x, y, w, h);
NSUInteger style = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask;
NSWindow *window = [NSWindow alloc];
MAMEWindowController *controller = [MAMEWindowController alloc];
[window initWithContentRect:bounds
styleMask:style
backing:NSBackingStoreBuffered
defer:NO];
[controller initWithWindow:window];
NSString *nstitle = [[NSString alloc] initWithUTF8String:title];
[window setTitle:nstitle];
[nstitle release];
if (isFullscreen)
{
[controller goFullscreen];
}
else
{
[window makeKeyAndOrderFront:nil];
}
return (void *)controller;
}
|