--- previous/src/gui-osx/SDLMain.m 2018/04/24 19:25:10 1.1 +++ previous/src/gui-osx/SDLMain.m 2018/04/24 19:31:41 1.1.1.4 @@ -14,10 +14,11 @@ #include "dialog.h" #include "reset.h" -#include "screenSnapShot.h" -#include "memorySnapShot.h" +#include "screen.h" +#include "PrefsController.h" +#include "Shared.h" #include "video.h" -#include "avi_record.h" +#include "../debug/debugui.h" // for Hatari @@ -42,9 +43,9 @@ typedef struct CPSProcessSerNum UInt32 hi; } CPSProcessSerNum; -extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); -extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); -extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn); +OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); +OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); +OSErr CPSSetFrontProcess( CPSProcessSerNum *psn); #endif /* SDL_USE_CPS */ @@ -76,22 +77,15 @@ static NSString *getApplicationName(void @end #endif -@interface NSApplication (SDLApplication) -@end - -@implementation NSApplication (SDLApplication) +/* The main class of the application, the application's delegate */ +@implementation SDLMain /* Invoked from the Quit menu item */ -- (void)terminate:(id)sender -{ +- (void)applicationWillTerminate:(NSNotification *)aNotification { /* Post a SDL_QUIT event */ SDL_Event event; event.type = SDL_QUIT; SDL_PushEvent(&event); } -@end - -/* The main class of the application, the application's delegate */ -@implementation SDLMain /* Set the working directory to the .app's parent directory */ - (void) setupWorkingDirectory:(BOOL)shouldChdir @@ -297,7 +291,7 @@ static void CustomApplicationMain (int a /* Called when the internal event loop has just started running */ - (void) applicationDidFinishLaunching: (NSNotification *) note { - int status; + int status = 0; /* Set the working directory to the .app's parent directory */ [self setupWorkingDirectory:gFinderLaunch]; @@ -309,7 +303,7 @@ static void CustomApplicationMain (int a /* Hand off to main application code */ gCalledAppMainline = TRUE; - status = SDL_main (gArgc, gArgv); + //status = SDL_main (gArgc, gArgv); /* We're done, thank you for playing */ exit(status); @@ -334,6 +328,7 @@ static void CustomApplicationMain (int a - (IBAction)warmReset:(id)sender { + /* int b; b = NSRunAlertPanel ( @@ -344,10 +339,12 @@ static void CustomApplicationMain (int a //printf("b=%i\n",b); if (b == 1) Reset_Warm(); + */ } - (IBAction)coldReset:(id)sender { + /* int b; b = NSRunAlertPanel ( @@ -358,17 +355,19 @@ static void CustomApplicationMain (int a //printf("b=%i\n",b); if (b == 1) Reset_Cold(); + */ } - (IBAction)insertDiskA:(id)sender { + /* NSString *path = nil; NSOpenPanel *openPanel = [ NSOpenPanel openPanel ]; if ( [ openPanel runModalForDirectory:nil file:@"SavedGame" types:nil ] ) { - path = [ [ openPanel filenames ] objectAtIndex:0 ]; + path = [[ [ openPanel URLs ] objectAtIndex:0 ] path]; } if (path != nil) @@ -382,17 +381,19 @@ static void CustomApplicationMain (int a // Floppy_SetDiskFileName(0, szPath, NULL); // Floppy_InsertDiskIntoDrive(0); } + */ } - (IBAction)insertDiskB:(id)sender { + /* NSString *path = nil; NSOpenPanel *openPanel = [ NSOpenPanel openPanel ]; if ( [ openPanel runModalForDirectory:nil file:@"SavedGame" types:nil ] ) { - path = [ [ openPanel filenames ] objectAtIndex:0 ]; + path = [[ [ openPanel URLs ] objectAtIndex:0 ] path]; } if (path != nil) @@ -406,6 +407,7 @@ static void CustomApplicationMain (int a // Floppy_SetDiskFileName(1, szPath, NULL); // Floppy_InsertDiskIntoDrive(1); } + */ } /*-----------------------------------------------------------------------*/ @@ -434,34 +436,12 @@ static void CustomApplicationMain (int a return YES; } -- (IBAction)captureScreen:(id)sender +- (NSString*)displayFileSelection:(const char*)pathInParams preferredFileName:(NSString*)preferredFileName allowedExtensions:(NSArray*)allowedExtensions { - GuiOsx_Pause(); - ScreenSnapShot_SaveScreen(); - GuiOsx_Resume(); -} - -- (IBAction)captureAnimation:(id)sender -{ - GuiOsx_Pause(); -// Avi_StartRecording ( AviRecordFile , AviRecordDefaultCrop , nScreenRefreshRate , AviRecordDefaultVcodec ); - GuiOsx_Resume(); -} - -- (IBAction)endCaptureAnimation:(id)sender -{ - GuiOsx_Pause(); -// Avi_StopRecording(); - GuiOsx_Resume(); -} - -- (IBAction)captureSound:(id)sender -{ - GuiOsx_Pause(); - +/* // Get the path from the user settings - NSString *preferredPath = [[NSString stringWithCString:(ConfigureParams.Sound.szYMCaptureFileName) encoding:NSASCIIStringEncoding] stringByAbbreviatingWithTildeInPath]; - + NSString *preferredPath = [[NSString stringWithCString:(pathInParams) encoding:NSASCIIStringEncoding] stringByAbbreviatingWithTildeInPath]; + // Determine the directory and filename NSString *directoryToOpen; NSString *fileToPreselect; @@ -475,28 +455,67 @@ static void CustomApplicationMain (int a { // Currently no path: we will open the user's directory with no file selected. directoryToOpen = [@"~" stringByExpandingTildeInPath]; - fileToPreselect = @"hatari.wav"; + fileToPreselect = preferredFileName; } - + // Create and configure a SavePanel for choosing what file to write NSSavePanel *savePanel = [NSSavePanel savePanel]; - [savePanel setAllowedFileTypes:[NSArray arrayWithObjects:@"ym", @"wav", nil]]; + [savePanel setAllowedFileTypes:allowedExtensions]; [savePanel setExtensionHidden:NO]; - [savePanel setMessage:@"Please specify an .ym or a .wav file."]; // TODO: Move to localizable resources + NSString* extensionList = [allowedExtensions componentsJoinedByString:@" or a ."]; + [savePanel setMessage:[NSString stringWithFormat:@"Please specify a .%@ file",extensionList]]; // TODO: Move to localizable resources // Run the SavePanel, then check if the user clicked OK and selected at least one file if (NSFileHandlingPanelOKButton == [savePanel runModalForDirectory:directoryToOpen file:fileToPreselect] ) - { - // Get the path to the selected file - NSString *path = [savePanel filename]; + return [[savePanel URL] path]; + */ + return nil; +} + +- (IBAction)captureScreen:(id)sender +{ + GuiOsx_Pause(); +// ScreenSnapShot_SaveScreen(); + GuiOsx_Resume(); +} + +- (IBAction)captureAnimation:(id)sender +{ +// GuiOsx_Pause(); +// if(!Avi_AreWeRecording()) { +// NSString* path = [self displayFileSelection:ConfigureParams.Video.AviRecordFile preferredFileName:@"hatari.avi" +// allowedExtensions:[NSArray arrayWithObjects:@"avi", nil]]; - // Store the path in the user settings - GuiOsx_ExportPathString(path, ConfigureParams.Sound.szYMCaptureFileName, sizeof(ConfigureParams.Sound.szYMCaptureFileName)); +// if(path) { +// GuiOsx_ExportPathString(path, ConfigureParams.Video.AviRecordFile, sizeof(ConfigureParams.Video.AviRecordFile)); +// Avi_StartRecording ( ConfigureParams.Video.AviRecordFile , ConfigureParams.Screen.bCrop , +// ConfigureParams.Video.AviRecordFps == 0 ? +// ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , nScreenRefreshRate ) : +// (Uint32)ConfigureParams.Video.AviRecordFps << CLOCKS_TIMINGS_SHIFT_VBL , +// 1 << CLOCKS_TIMINGS_SHIFT_VBL , +// ConfigureParams.Video.AviRecordVcodec ); +// } - // Begin capture -// Sound_BeginRecording(ConfigureParams.Sound.szYMCaptureFileName); - } +// } else { +// Avi_StopRecording(); +// } +// GuiOsx_Resume(); +} +- (IBAction)endCaptureAnimation:(id)sender +{ + //? +} + +- (IBAction)captureSound:(id)sender +{ + GuiOsx_Pause(); +// NSString* path = [self displayFileSelection:ConfigureParams.Sound.szYMCaptureFileName preferredFileName:@"hatari.wav" +// allowedExtensions:[NSArray arrayWithObjects:@"ym", @"wav", nil]]; +// if(path) { +// GuiOsx_ExportPathString(path, ConfigureParams.Sound.szYMCaptureFileName, sizeof(ConfigureParams.Sound.szYMCaptureFileName)); +// Sound_BeginRecording(ConfigureParams.Sound.szYMCaptureFileName); +// } GuiOsx_Resume(); } @@ -509,49 +528,23 @@ static void CustomApplicationMain (int a - (IBAction)saveMemorySnap:(id)sender { + /* GuiOsx_Pause(); - // Get the path from the user settings - NSString *preferredPath = [[NSString stringWithCString:(ConfigureParams.Memory.szMemoryCaptureFileName) encoding:NSASCIIStringEncoding] stringByAbbreviatingWithTildeInPath]; - - // Determine the directory and filename - NSString *directoryToOpen; - NSString *fileToPreselect; - if ((preferredPath != nil) && ([preferredPath length] > 0)) - { - // There is existing path: we will open its directory with its file pre-selected. - directoryToOpen = [preferredPath stringByDeletingLastPathComponent]; - fileToPreselect = [preferredPath lastPathComponent]; - } - else - { - // Currently no path: we will open the user's directory with the default filename. - directoryToOpen = [@"~" stringByExpandingTildeInPath]; - fileToPreselect = @"hatari.sav"; - } - - // Create and configure a SavePanel for choosing what file to write - NSSavePanel *savePanel = [NSSavePanel savePanel]; - [savePanel setExtensionHidden:NO]; - - // Run the SavePanel, then check if the user clicked OK and selected at least one file - if (NSFileHandlingPanelOKButton == [savePanel runModalForDirectory:directoryToOpen file:fileToPreselect] ) - { - // Get the path to the selected file - NSString *path = [savePanel filename]; - - // Store the path in the user settings + NSString* path = [self displayFileSelection:ConfigureParams.Memory.szMemoryCaptureFileName preferredFileName:@"hatari.sav" + allowedExtensions:[NSArray arrayWithObjects:@"sav",nil]]; + if(path) { GuiOsx_ExportPathString(path, ConfigureParams.Memory.szMemoryCaptureFileName, sizeof(ConfigureParams.Memory.szMemoryCaptureFileName)); - - // Perform the memory snapshot save MemorySnapShot_Capture(ConfigureParams.Memory.szMemoryCaptureFileName, TRUE); } - + GuiOsx_Resume(); + */ } - (IBAction)restoreMemorySnap:(id)sender { + /* GuiOsx_Pause(); // Create and configure an OpenPanel @@ -577,17 +570,18 @@ static void CustomApplicationMain (int a } // Run the OpenPanel, then check if the user clicked OK and selected at least one file - if ( (NSOKButton == [openPanel runModalForDirectory:directoryToOpen file:fileToPreselect types:nil] ) - && ([[openPanel filenames] count] > 0) ) + if ( (NSModalResponseOK == [openPanel runModalForDirectory:directoryToOpen file:fileToPreselect types:nil] ) + && ([[openPanel URLs] count] > 0) ) { // Get the path to the selected file - NSString *path = [[openPanel filenames] objectAtIndex:0]; + NSString *path = [[[openPanel URLs] objectAtIndex:0] path]; // Perform the memory snapshot load MemorySnapShot_Restore([path cStringUsingEncoding:NSASCIIStringEncoding], TRUE); } GuiOsx_Resume(); + */ } - (IBAction)doFullScreen:(id)sender @@ -597,7 +591,7 @@ static void CustomApplicationMain (int a SDL_KeyboardEvent event; event.type = SDL_KEYDOWN; - event.which = 0; + //event.which = 0; event.state = SDL_PRESSED; event.keysym.sym = SDLK_F11; SDL_PushEvent((SDL_Event*)&event); // Send the F11 key press @@ -666,7 +660,7 @@ static void CustomApplicationMain (int a # undef main #endif - +#if 0 /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { @@ -688,10 +682,10 @@ int main (int argc, char **argv) } #if SDL_USE_NIB_FILE - NSApplicationMain (argc, argv); + NSApplicationMain (argc, (const char**)argv); #else CustomApplicationMain (argc, argv); #endif return 0; } - +#endif