--- 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:52:55 1.1.1.10 @@ -18,8 +18,14 @@ #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" +#include "change.h" // for Hatari @@ -95,6 +101,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 { @@ -329,9 +336,15 @@ static void CustomApplicationMain (int a --in_propdialog; } +- (IBAction) openPreferences:(id)sender +{ + [[PrefsController prefs] loadPrefs:sender]; +} + + - (IBAction)debugUI:(id)sender { - DebugUI(); + DebugUI(REASON_USER); } - (IBAction)warmReset:(id)sender @@ -346,7 +359,7 @@ static void CustomApplicationMain (int a //printf("b=%i\n",b); if (b == 1) Reset_Warm(); -} +} - (IBAction)coldReset:(id)sender { @@ -436,34 +449,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 +468,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 +542,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(); } @@ -608,15 +608,95 @@ static void CustomApplicationMain (int a SDL_PushEvent((SDL_Event*)&event); // Send the F11 key release } + - (IBAction)help:(id)sender { - [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://hatari.berlios.de/docs.html"]]; +NSString *l_aide ; + + l_aide = [[NSBundle mainBundle] pathForResource:@"manual" ofType:@"html" inDirectory:@"AideHatari"] ; + + if (![[NSWorkspace sharedWorkspace] openFile:l_aide withApplication:@"HelpViewer"]) + if (![[NSWorkspace sharedWorkspace] openFile:l_aide withApplication:@"Help Viewer"]) + [[NSWorkspace sharedWorkspace] openFile:l_aide] ; } +- (IBAction)compat:(id)sender +{ +NSString *C_aide ; + + C_aide = [[NSBundle mainBundle] pathForResource:@"compatibility" ofType:@"html" inDirectory:@"AideHatari"] ; + + if (![[NSWorkspace sharedWorkspace] openFile:C_aide withApplication:@"HelpViewer"]) + if (![[NSWorkspace sharedWorkspace] openFile:C_aide withApplication:@"Help Viewer"]) + [[NSWorkspace sharedWorkspace] openFile:C_aide] ; +} -- (IBAction)openConfig:(id)sender { +- (IBAction)openConfig:(id)sender +{ + BOOL applyChanges = true; + NSString *ConfigFile = [NSString stringWithCString:(sConfigFileName) encoding:NSASCIIStringEncoding]; + NSOpenPanel *openPanel = [ NSOpenPanel openPanel ]; + + CNF_PARAMS CurrentParams; + + + // Backup of configuration settings to CurrentParams (which we will only + // commit back to the configuration settings if choosing user confirm) + CurrentParams = ConfigureParams; + + GuiOsx_Pause(); + + if ( [ openPanel runModalForDirectory:nil file:ConfigFile types:nil ] ) + { + ConfigFile = [ [ openPanel filenames ] objectAtIndex:0 ]; + } + else + { + ConfigFile = nil; + } + + //[openPanel release]; + + if (ConfigFile != nil) + { + // Make a non-const C string out of it + const char* constSzPath = [ConfigFile cStringUsingEncoding:NSASCIIStringEncoding]; + size_t cbPath = strlen(constSzPath) + 1; + char szPath[cbPath]; + strncpy(szPath, constSzPath, cbPath); + + // Load the config into ConfigureParams + Configuration_Load(szPath); + strcpy(sConfigFileName,szPath); + // Refresh all the controls to match ConfigureParams + + if (Change_DoNeedReset(&CurrentParams, &ConfigureParams)) + { + applyChanges = ( 0 == NSRunAlertPanel ( + NSLocalizedStringFromTable(@"Reset the emulator",@"Localizable",@"comment"), + NSLocalizedStringFromTable(@"Must be reset",@"Localizable",@"comment"), + NSLocalizedStringFromTable(@"Don't reset",@"Localizable",@"comment"), + NSLocalizedStringFromTable(@"Reset",@"Localizable",@"comment"), nil) ); + } + + // Commit the new configuration + if (applyChanges) + { + Change_CopyChangedParamsToConfiguration(&CurrentParams, &ConfigureParams, true); + } + else + { + ConfigureParams = CurrentParams; + } + + + } + + GuiOsx_Resume(); + //[ConfigFile release]; } + - (IBAction)saveConfig:(id)sender { } @@ -690,7 +770,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