fix issue on macos x
This commit is contained in:
@ -310,11 +310,14 @@ mfb_update(struct mfb_window *window, void *buffer) {
|
||||
#endif
|
||||
|
||||
update_events(window_data);
|
||||
if(window_data->close == false) {
|
||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
||||
[[window_data_osx->window contentView] setNeedsDisplay:YES];
|
||||
if(window_data->close) {
|
||||
destroy_window_data(window_data);
|
||||
return STATE_EXIT;
|
||||
}
|
||||
|
||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
||||
[[window_data_osx->window contentView] setNeedsDisplay:YES];
|
||||
|
||||
return STATE_OK;
|
||||
}
|
||||
|
||||
@ -333,11 +336,14 @@ mfb_update_events(struct mfb_window *window) {
|
||||
}
|
||||
|
||||
update_events(window_data);
|
||||
if(window_data->close == false) {
|
||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
||||
[[window_data_osx->window contentView] setNeedsDisplay:YES];
|
||||
if(window_data->close) {
|
||||
destroy_window_data(window_data);
|
||||
return STATE_EXIT;
|
||||
}
|
||||
|
||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
||||
[[window_data_osx->window contentView] setNeedsDisplay:YES];
|
||||
|
||||
return STATE_OK;
|
||||
}
|
||||
|
||||
@ -362,6 +368,10 @@ mfb_wait_sync(struct mfb_window *window) {
|
||||
//NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
||||
if(window_data_osx == 0x0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
double current;
|
||||
uint32_t millis = 1;
|
||||
while(1) {
|
||||
@ -397,6 +407,10 @@ mfb_wait_sync(struct mfb_window *window) {
|
||||
|
||||
bool
|
||||
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||
if(window == 0x0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
|
||||
if(offset_x + width > window_data->window_width) {
|
||||
|
@ -72,6 +72,9 @@
|
||||
|
||||
- (void)flagsChanged:(NSEvent *)event
|
||||
{
|
||||
if(window_data == 0x0)
|
||||
return;
|
||||
|
||||
const uint32_t flags = [event modifierFlags];
|
||||
uint32_t mod_keys = 0, mod_keys_aux = 0;
|
||||
|
||||
@ -135,42 +138,48 @@
|
||||
|
||||
- (void)keyDown:(NSEvent *)event
|
||||
{
|
||||
short int key_code = g_keycodes[[event keyCode] & 0x1ff];
|
||||
window_data->key_status[key_code] = true;
|
||||
kCall(keyboard_func, key_code, window_data->mod_keys, true);
|
||||
if(window_data != 0x0) {
|
||||
short int key_code = g_keycodes[[event keyCode] & 0x1ff];
|
||||
window_data->key_status[key_code] = true;
|
||||
kCall(keyboard_func, key_code, window_data->mod_keys, true);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
- (void)keyUp:(NSEvent *)event
|
||||
{
|
||||
short int key_code = g_keycodes[[event keyCode] & 0x1ff];
|
||||
window_data->key_status[key_code] = false;
|
||||
kCall(keyboard_func, key_code, window_data->mod_keys, false);
|
||||
if(window_data != 0x0) {
|
||||
short int key_code = g_keycodes[[event keyCode] & 0x1ff];
|
||||
window_data->key_status[key_code] = false;
|
||||
kCall(keyboard_func, key_code, window_data->mod_keys, false);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
- (void)insertText:(id)string replacementRange:(NSRange)replacementRange
|
||||
{
|
||||
NSString *characters;
|
||||
NSUInteger length;
|
||||
|
||||
kUnused(replacementRange);
|
||||
|
||||
if ([string isKindOfClass:[NSAttributedString class]])
|
||||
characters = [string string];
|
||||
else
|
||||
characters = (NSString*) string;
|
||||
if(window_data != 0x0) {
|
||||
NSString *characters;
|
||||
NSUInteger length;
|
||||
|
||||
length = [characters length];
|
||||
for (NSUInteger i = 0; i < length; i++)
|
||||
{
|
||||
const unichar code = [characters characterAtIndex:i];
|
||||
if ((code & 0xff00) == 0xf700)
|
||||
continue;
|
||||
if ([string isKindOfClass:[NSAttributedString class]])
|
||||
characters = [string string];
|
||||
else
|
||||
characters = (NSString*) string;
|
||||
|
||||
kCall(char_input_func, code);
|
||||
length = [characters length];
|
||||
for (NSUInteger i = 0; i < length; i++)
|
||||
{
|
||||
const unichar code = [characters characterAtIndex:i];
|
||||
if ((code & 0xff00) == 0xf700)
|
||||
continue;
|
||||
|
||||
kCall(char_input_func, code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,9 +189,11 @@
|
||||
{
|
||||
kUnused(notification);
|
||||
|
||||
if(window_data->is_active == true) {
|
||||
window_data->is_active = false;
|
||||
kCall(active_func, false);
|
||||
if(window_data != 0x0) {
|
||||
if(window_data->is_active == true) {
|
||||
window_data->is_active = false;
|
||||
kCall(active_func, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,10 +201,10 @@
|
||||
|
||||
- (void)setContentView:(NSView *)aView
|
||||
{
|
||||
if ([childContentView isEqualTo:aView])
|
||||
{
|
||||
if ([childContentView isEqualTo:aView]) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSRect bounds = [self frame];
|
||||
bounds.origin = NSZeroPoint;
|
||||
|
||||
@ -232,15 +243,19 @@
|
||||
- (void)windowDidBecomeKey:(NSNotification *)notification
|
||||
{
|
||||
kUnused(notification);
|
||||
window_data->is_active = true;
|
||||
kCall(active_func, true);
|
||||
if(window_data != 0x0) {
|
||||
window_data->is_active = true;
|
||||
kCall(active_func, true);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)windowDidResignKey:(NSNotification *)notification
|
||||
{
|
||||
kUnused(notification);
|
||||
window_data->is_active = false;
|
||||
kCall(active_func, false);
|
||||
if(window_data) {
|
||||
window_data->is_active = false;
|
||||
kCall(active_func, false);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)windowWillClose:(NSNotification *)notification {
|
||||
@ -277,19 +292,23 @@
|
||||
|
||||
- (void)willClose
|
||||
{
|
||||
window_data->close = true;
|
||||
if(window_data != 0x0) {
|
||||
window_data->close = true;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
- (void)windowDidResize:(NSNotification *)notification {
|
||||
kUnused(notification);
|
||||
CGSize size = [self contentRectForFrameRect:[self frame]].size;
|
||||
if(window_data != 0x0) {
|
||||
CGSize size = [self contentRectForFrameRect:[self frame]].size;
|
||||
|
||||
window_data->window_width = size.width;
|
||||
window_data->window_height = size.height;
|
||||
window_data->window_width = size.width;
|
||||
window_data->window_height = size.height;
|
||||
|
||||
kCall(resize_func, size.width, size.height);
|
||||
kCall(resize_func, size.width, size.height);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -65,7 +65,7 @@ extern Vertex g_vertices[4];
|
||||
renderEncoder.label = @"minifb_command_encoder";
|
||||
|
||||
// Set render command encoder state
|
||||
OSXWindow *window = (OSXWindow *) view.window;
|
||||
OSXWindow *window = (OSXWindow *) view.window;
|
||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window->window_data->specific;
|
||||
[renderEncoder setRenderPipelineState:window_data_osx->metal.pipeline_state];
|
||||
|
||||
@ -136,7 +136,7 @@ extern Vertex g_vertices[4];
|
||||
{
|
||||
(void)rect;
|
||||
|
||||
if(!window_data)
|
||||
if(window_data == 0x0)
|
||||
return;
|
||||
|
||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
||||
@ -181,7 +181,9 @@ extern Vertex g_vertices[4];
|
||||
- (void)mouseDown:(NSEvent*)event
|
||||
{
|
||||
(void)event;
|
||||
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, true);
|
||||
if(window_data != 0x0) {
|
||||
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, true);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -189,7 +191,9 @@ extern Vertex g_vertices[4];
|
||||
- (void)mouseUp:(NSEvent*)event
|
||||
{
|
||||
(void)event;
|
||||
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, false);
|
||||
if(window_data != 0x0) {
|
||||
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, false);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -197,7 +201,9 @@ extern Vertex g_vertices[4];
|
||||
- (void)rightMouseDown:(NSEvent*)event
|
||||
{
|
||||
(void)event;
|
||||
kCall(mouse_btn_func, MOUSE_BTN_2, window_data->mod_keys, true);
|
||||
if(window_data != 0x0) {
|
||||
kCall(mouse_btn_func, MOUSE_BTN_2, window_data->mod_keys, true);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -205,7 +211,9 @@ extern Vertex g_vertices[4];
|
||||
- (void)rightMouseUp:(NSEvent*)event
|
||||
{
|
||||
(void)event;
|
||||
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, false);
|
||||
if(window_data != 0x0) {
|
||||
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, false);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -213,7 +221,9 @@ extern Vertex g_vertices[4];
|
||||
- (void)otherMouseDown:(NSEvent *)event
|
||||
{
|
||||
(void)event;
|
||||
kCall(mouse_btn_func, [event buttonNumber], window_data->mod_keys, true);
|
||||
if(window_data != 0x0) {
|
||||
kCall(mouse_btn_func, [event buttonNumber], window_data->mod_keys, true);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -221,14 +231,18 @@ extern Vertex g_vertices[4];
|
||||
- (void)otherMouseUp:(NSEvent *)event
|
||||
{
|
||||
(void)event;
|
||||
kCall(mouse_btn_func, [event buttonNumber], window_data->mod_keys, false);
|
||||
if(window_data != 0x0) {
|
||||
kCall(mouse_btn_func, [event buttonNumber], window_data->mod_keys, false);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
- (void)scrollWheel:(NSEvent *)event
|
||||
{
|
||||
kCall(mouse_wheel_func, window_data->mod_keys, [event deltaX], [event deltaY]);
|
||||
if(window_data != 0x0) {
|
||||
kCall(mouse_wheel_func, window_data->mod_keys, [event deltaX], [event deltaY]);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -250,11 +264,13 @@ extern Vertex g_vertices[4];
|
||||
|
||||
- (void)mouseMoved:(NSEvent *)event
|
||||
{
|
||||
NSPoint point = [event locationInWindow];
|
||||
//NSPoint localPoint = [self convertPoint:point fromView:nil];
|
||||
window_data->mouse_pos_x = point.x;
|
||||
window_data->mouse_pos_y = point.y;
|
||||
kCall(mouse_move_func, point.x, point.y);
|
||||
if(window_data != 0x0) {
|
||||
NSPoint point = [event locationInWindow];
|
||||
//NSPoint localPoint = [self convertPoint:point fromView:nil];
|
||||
window_data->mouse_pos_x = point.x;
|
||||
window_data->mouse_pos_y = point.y;
|
||||
kCall(mouse_move_func, point.x, point.y);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user