--- hatari/src/gui-osx/SDLMain.m 2019/04/09 08:48:37 1.1.1.6 +++ hatari/src/gui-osx/SDLMain.m 2019/04/09 08:49:23 1.1.1.7 @@ -18,8 +18,13 @@ #include "screenSnapShot.h" #include "memorySnapShot.h" #include "sound.h" +#include "screen.h" +#include "PrefsController.h" +#include "Shared.h" #include "video.h" #include "avi_record.h" +#include "../debug/debugui.h" +#include "clocks_timings.h" // for Hatari @@ -95,6 +100,7 @@ static NSString *getApplicationName(void /* 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 { @@ -436,34 +442,12 @@ static void CustomApplicationMain (int a return YES; } -- (IBAction)captureScreen:(id)sender -{ - 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 +- (NSString*)displayFileSelection:(const char*)pathInParams preferredFileName:(NSString*)preferredFileName allowedExtensions:(NSArray*)allowedExtensions { - 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; @@ -477,28 +461,66 @@ 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(); } @@ -513,42 +535,13 @@ static void CustomApplicationMain (int a { 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(); } @@ -690,7 +683,7 @@ int main (int argc, char **argv) } #if SDL_USE_NIB_FILE - NSApplicationMain (argc, argv); + NSApplicationMain (argc, (const char**)argv); #else CustomApplicationMain (argc, argv); #endif