Added reloading
This commit is contained in:
parent
89b4180eb2
commit
c1ec0d3b43
|
@ -10,12 +10,15 @@
|
|||
|
||||
#import "FBMainThread.h"
|
||||
|
||||
// FIXME: errors during load
|
||||
// FIXME: starting without ROM selected
|
||||
// FIXME: dropping file into window
|
||||
// FIXME: reset window size on reload
|
||||
// FIXME: rotation (mimonkey)
|
||||
@interface AppDelegate ()
|
||||
|
||||
@property (weak) IBOutlet NSWindow *window;
|
||||
|
||||
- (NSSize) gameScreenSize;
|
||||
|
||||
@end
|
||||
|
||||
static AppDelegate *sharedInstance = nil;
|
||||
|
@ -62,32 +65,34 @@ static AppDelegate *sharedInstance = nil;
|
|||
- (NSSize) windowWillResize:(NSWindow *) sender
|
||||
toSize:(NSSize) frameSize
|
||||
{
|
||||
NSSize screenSize = [self gameScreenSize];
|
||||
NSRect windowFrame = [[self window] frame];
|
||||
NSView *contentView = [[self window] contentView];
|
||||
NSRect viewRect = [contentView convertRect:[contentView bounds]
|
||||
toView:nil];
|
||||
NSRect contentRect = [[self window] contentRectForFrameRect:windowFrame];
|
||||
NSSize screenSize = [_video gameScreenSize];
|
||||
if (screenSize.width != 0 && screenSize.height != 0) {
|
||||
NSRect windowFrame = [[self window] frame];
|
||||
NSView *contentView = [[self window] contentView];
|
||||
NSRect viewRect = [contentView convertRect:[contentView bounds]
|
||||
toView:nil];
|
||||
NSRect contentRect = [[self window] contentRectForFrameRect:windowFrame];
|
||||
|
||||
CGFloat screenRatio = screenSize.width / screenSize.height;
|
||||
CGFloat screenRatio = screenSize.width / screenSize.height;
|
||||
|
||||
float marginY = viewRect.origin.y + windowFrame.size.height - contentRect.size.height;
|
||||
float marginX = contentRect.size.width - viewRect.size.width;
|
||||
float marginY = viewRect.origin.y + windowFrame.size.height - contentRect.size.height;
|
||||
float marginX = contentRect.size.width - viewRect.size.width;
|
||||
|
||||
// Clamp the minimum height
|
||||
if ((frameSize.height - marginY) < screenSize.height) {
|
||||
frameSize.height = screenSize.height + marginY;
|
||||
// Clamp the minimum height
|
||||
if ((frameSize.height - marginY) < screenSize.height) {
|
||||
frameSize.height = screenSize.height + marginY;
|
||||
}
|
||||
|
||||
// Set the screen width as a percentage of the screen height
|
||||
frameSize.width = (frameSize.height - marginY) * screenRatio + marginX;
|
||||
}
|
||||
|
||||
// Set the screen width as a percentage of the screen height
|
||||
frameSize.width = (frameSize.height - marginY) * screenRatio + marginX;
|
||||
|
||||
return frameSize;
|
||||
}
|
||||
|
||||
- (void) windowDidResize:(NSNotification *) notification
|
||||
{
|
||||
NSSize screenSize = [self gameScreenSize];
|
||||
NSSize screenSize = [_video gameScreenSize];
|
||||
if (screenSize.width != 0 && screenSize.height != 0) {
|
||||
NSRect windowFrame = [[self window] frame];
|
||||
NSRect contentRect = [[self window] contentRectForFrameRect:windowFrame];
|
||||
|
@ -108,6 +113,7 @@ static AppDelegate *sharedInstance = nil;
|
|||
- (BOOL) application:(NSApplication *) sender
|
||||
openFile:(NSString *) filename
|
||||
{
|
||||
NSLog(@"application:openFile:");
|
||||
main.fileToOpen = filename;
|
||||
return YES;
|
||||
}
|
||||
|
@ -135,15 +141,4 @@ static AppDelegate *sharedInstance = nil;
|
|||
}
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
extern int BurnDrvGetVisibleSize(int* pnWidth, int* pnHeight);
|
||||
|
||||
- (NSSize) gameScreenSize
|
||||
{
|
||||
int w, h;
|
||||
BurnDrvGetVisibleSize(&w, &h);
|
||||
return NSMakeSize(w, h);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -12,6 +12,13 @@ extern int MainInit(const char *, const char *);
|
|||
extern int MainFrame();
|
||||
extern int MainEnd();
|
||||
|
||||
@interface FBMainThread()
|
||||
|
||||
- (NSString *) setPath;
|
||||
- (NSString *) setName;
|
||||
|
||||
@end
|
||||
|
||||
@implementation FBMainThread
|
||||
|
||||
- (instancetype) init
|
||||
|
@ -21,21 +28,43 @@ extern int MainEnd();
|
|||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - NSThread
|
||||
|
||||
- (void) main
|
||||
{
|
||||
NSString *path = [[_fileToOpen stringByDeletingLastPathComponent] stringByAppendingString:@"/"];
|
||||
NSString *setname = [[_fileToOpen lastPathComponent] stringByDeletingPathExtension];
|
||||
|
||||
if (!MainInit([path cStringUsingEncoding:NSUTF8StringEncoding], [setname cStringUsingEncoding:NSUTF8StringEncoding]))
|
||||
return;
|
||||
|
||||
NSLog(@"Entering main loop");
|
||||
while (!self.isCancelled) {
|
||||
MainFrame();
|
||||
}
|
||||
NSLog(@"Exited main loop");
|
||||
if (!_fileToOpen) {
|
||||
[NSThread sleepForTimeInterval:.5]; // Pause until there's something to load
|
||||
continue;
|
||||
}
|
||||
|
||||
MainEnd();
|
||||
if (!MainInit([[self setPath] cStringUsingEncoding:NSUTF8StringEncoding],
|
||||
[[self setName] cStringUsingEncoding:NSUTF8StringEncoding]))
|
||||
return;
|
||||
|
||||
NSLog(@"Entering main loop");
|
||||
NSString *loaded = _fileToOpen;
|
||||
while (!self.isCancelled) {
|
||||
if ([loaded isNotEqualTo:_fileToOpen])
|
||||
break;
|
||||
MainFrame();
|
||||
}
|
||||
NSLog(@"Exited main loop");
|
||||
|
||||
MainEnd();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (NSString *) setPath
|
||||
{
|
||||
return [[_fileToOpen stringByDeletingLastPathComponent] stringByAppendingString:@"/"];
|
||||
}
|
||||
|
||||
- (NSString *) setName
|
||||
{
|
||||
return [[_fileToOpen lastPathComponent] stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// FBInput.h
|
||||
// FinalBurnNeo
|
||||
//
|
||||
// Created by Akop Karapetyan on 10/15/19.
|
||||
// Created by Akop Karapetyan on 10/20/19.
|
||||
// Copyright © 2019 Akop Karapetyan. All rights reserved.
|
||||
//
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// FBInput.mm
|
||||
// FinalBurnNeo
|
||||
//
|
||||
// Created by Akop Karapetyan on 10/15/19.
|
||||
// Created by Akop Karapetyan on 10/20/19.
|
||||
// Copyright © 2019 Akop Karapetyan. All rights reserved.
|
||||
//
|
||||
|
||||
|
|
|
@ -23,4 +23,6 @@
|
|||
|
||||
@property (nonatomic, weak) id<FBVideoDelegate> delegate;
|
||||
|
||||
- (NSSize) gameScreenSize;
|
||||
|
||||
@end
|
||||
|
|
|
@ -58,6 +58,16 @@
|
|||
});
|
||||
}
|
||||
|
||||
- (NSSize) gameScreenSize
|
||||
{
|
||||
if (nBurnDrvActive == ~0U)
|
||||
return NSZeroSize;
|
||||
|
||||
int w, h;
|
||||
BurnDrvGetVisibleSize(&w, &h);
|
||||
return NSMakeSize(w, h);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - FinalBurn callbacks
|
||||
|
|
Loading…
Reference in New Issue