From 447b66f0adfb26472ec53e425f0240656407df18 Mon Sep 17 00:00:00 2001 From: Frederic Stark Date: Sun, 13 Feb 2022 18:05:15 +0100 Subject: [PATCH] A lot of little quality of life fixes and polish. See Notes.c for more details. --- macsrc/Library.c | 10 ++--- macsrc/MacFlim_Player.c | 13 ++++++- macsrc/Notes.c | 23 +++++++----- macsrc/Preferences.c | 82 ++++++++++++++++++++++++++++------------- macsrc/Preferences.h | 16 +++++++- macsrc/Resources.h | 14 +++---- macsrc/Self_Player.c | 2 +- macsrc/Tips.c | 8 ++-- macsrc/Tips.h | 2 +- macsrc/User_Interface.c | 72 +++++++++++++++++++++--------------- 10 files changed, 155 insertions(+), 87 deletions(-) diff --git a/macsrc/Library.c b/macsrc/Library.c index 39410ea..cab844a 100644 --- a/macsrc/Library.c +++ b/macsrc/Library.c @@ -114,7 +114,7 @@ struct LibraryRecord #define INTER_X 8 #define INTER_Y 8 #define MARGIN_X 15 -#define MARGIN_Y 15 // Suspects it should be removed for better key scroll behavior in first and last line +#define MARGIN_Y 8 // Suspects it should be removed for better key scroll behavior in first and last line // outer border, white border, inner border, pict, inner border, white border, outer border #define POLAROID_WIDTH (2+POLAROID_BORDER+PICT_WIDTH+POLAROID_BORDER+2) @@ -310,7 +310,7 @@ LibraryPtr LibraryOpenDefault( void ) if (resFile==-1) { - Create( LIBRARY_FILE, 0, 'FLIM', 'FLIB' ); + Create( LIBRARY_FILE, 0, 'FLPL', 'FLIB' ); CreateResFile( LIBRARY_FILE ); resFile = OpenResFile( LIBRARY_FILE ); if (resFile==-1) @@ -345,14 +345,14 @@ LibraryPtr LibraryOpenDefault( void ) lib->entries[i].needsUpdate = FALSE; } - lib->visibleHeight = 271; // This is *just* the right size for the initial window + lib->visibleHeight = 295; lib->offsetHeight = 0; LibrarySetColumnCount( lib, LIBRARY_COLUMNS ); lib->window = GetNewWindow( kWindowLibraryID, NULL, (WindowPtr)-1 ); SizeWindow( lib->window, lib->contentWidth, lib->visibleHeight, FALSE ); - UtilPlaceWindow( lib->window, 0.3 ); + UtilPlaceWindow( lib->window, 0.5 ); { Rect r; @@ -984,7 +984,7 @@ FlimPtr LibraryOpenFlim( LibraryPtr lib, int index ) ParamText( lef->fName, errStr, vRefNumStr, dirIDStr ); - Alert( kAlertOpenFlimErrorID, NULL ); + UtilDialog( kDLOGOpenFlimError ); return NULL; } return flim; diff --git a/macsrc/MacFlim_Player.c b/macsrc/MacFlim_Player.c index d50b500..2af5cd3 100644 --- a/macsrc/MacFlim_Player.c +++ b/macsrc/MacFlim_Player.c @@ -51,6 +51,7 @@ static Boolean AutoPlayFlims( void ) AppFile theAppFile; int i; Ptr savePtr; + Boolean played = FALSE; // Will be TRUE if we played one flim CountAppFiles(&doWhat,&fileCnt); @@ -58,6 +59,7 @@ static Boolean AutoPlayFlims( void ) if (fileCnt==0) return FALSE; + HideCursor(); SaveScreen( &savePtr ); for (;;) @@ -71,7 +73,10 @@ static Boolean AutoPlayFlims( void ) // (note: this means that a bad file will abort the looping too) theResult = PlayFlimFile( theAppFile.fName, theAppFile.vRefNum, kNoDirID, kHFS, FALSE ); - if (theResult==kError || theResult==kAbort) + if (theResult==kError || theResult==kFileError || theResult==kScreenError) + continue; + played = TRUE; + if (theResult==kAbort) goto end; if (theResult==kRestart) i = i-1; @@ -82,12 +87,16 @@ static Boolean AutoPlayFlims( void ) if (i==-2) i = fileCnt-2; } - ClrAppFiles( i+1 ); } + + // If we failed at every flim, we abort + if (!played) + break; } end: RestoreScreen( &savePtr ); + ShowCursor(); return TRUE; } diff --git a/macsrc/Notes.c b/macsrc/Notes.c index 9dbaa79..ee2c5e1 100644 --- a/macsrc/Notes.c +++ b/macsrc/Notes.c @@ -3,34 +3,37 @@ #if 0 TODO: - Loop single flim [DONE] - Create autoplay - Magically set type - Handle 'SELF' flim PREF for SELF? VERSION for SELF? - +#### Use Command-C during playback to copy the current frame in the Clipboard. You can print it and put it on your wall! A974 : Button -* Add back the Help * Play commands (restart/prev/next/etc) in ApplyPlay * Manage play commands (at least) abort (Button) from VBL * Mouse selection is a bit off (click on right border of polaroid) * Check all resource IDs in Resources.h * Don't add duplicate +* Do not show flim already in the Library in SFPGetFile * Sort flims * Drag/drop reorder * When selected, play should indicates the number of selected flims -* When a single one, play indicates the name +* When a single one, play indicates the name in the Play Menu * Add a "Restore Default" in preference dialog. * Changing flim types should not remove auto play -* Select all (and other menus) should not work when Library window not front -* "Cannot open flim" : dialog uncentererd + no mouse - +* Empty state for Library + +* [DONE] Remove VBL from preferences +* [DONE] Adds for type/creator when opening flim files +* [DONE] Put "Show all flims" into the SFPGetFile dialog itself (remove option trick), or add it in preferences +* [DONE] Poster should use flim filter +* [DONE] Double-clic on library crashes +* [DONE] Select directory of SFPGetFile is wrong +* [DONE] Better handling of keys when multiple windows +* [DONE] "Cannot open flim" : dialog uncentererd + no mouse * [DONE] Incomprehensible crash if buffers too small * [DONE] Flim 'A' makes MacFlim crash * [DONE] Escape deselects all. diff --git a/macsrc/Preferences.c b/macsrc/Preferences.c index 50c3ee0..d72ba6d 100644 --- a/macsrc/Preferences.c +++ b/macsrc/Preferences.c @@ -15,22 +15,23 @@ // The preference data structure // ------------------------------------------------------------------- -#define kPrefVersion 0x02 // Bumped at every incompatible change of data structure +#define kPrefVersion 0x03 // Bumped at every incompatible change of data structure typedef struct { short version; Boolean playbackVBL; - Size maxBufferSize; + Boolean showAll; + Boolean setTypeCreator; + Boolean showTipsStartup; Boolean loop; - char filler0; - Boolean showTips; + char filler1; + + Size maxBufferSize; short nextTipIndex; short nextTipBtnIndex; - Boolean showTipsStartup; - char filler2; } PreferenceRecord; typedef PreferenceRecord *PreferencePtr; @@ -117,6 +118,34 @@ Boolean PreferenceGetIsPlaybackVBL( void ) // ------------------------------------------------------------------- +Boolean PreferenceGetShowAll( void ) +{ + return sPreferences->showAll; +} + +// ------------------------------------------------------------------- + +void PreferenceSetShowAll( Boolean b ) +{ + sPreferences->showAll = b; +} + +// ------------------------------------------------------------------- + +Boolean PreferenceGetSetTypeCreator( void ) +{ + return sPreferences->setTypeCreator; +} + +// ------------------------------------------------------------------- + +void PreferenceSetSetTypeCreator( Boolean b ) +{ + sPreferences->setTypeCreator = b; +} + +// ------------------------------------------------------------------- + Size PreferenceGetMaxBufferSize( void ) { return sPreferences->maxBufferSize; @@ -160,7 +189,7 @@ void PreferenceInit( void ) if (sRefNum==-1) { // Creates initial preference file - Create( PREF_FILE, 0, 'FLIM', 'PREF' ); + Create( PREF_FILE, 0, 'FLPL', 'PREF' ); CreateResFile( PREF_FILE ); sRefNum = OpenResFile( PREF_FILE ); if (sRefNum!=-1) @@ -272,16 +301,6 @@ void PreferencesSetNextTipBtnIndex( short nextTipBtnIndex ) sPreferences->nextTipBtnIndex = nextTipBtnIndex; } -Boolean PreferencesGetShowTips( void ) -{ - return sPreferences->showTips; -} - -void PreferencesSetShowTips( Boolean showTips ) -{ - sPreferences->showTips = showTips; -} - Boolean PreferencesGetShowTipsStartup( void ) { return sPreferences->showTipsStartup; @@ -299,7 +318,8 @@ void PreferenceDialog( void ) { DialogPtr preferences; short itemHit; - Handle iCheckVBL; + Handle iCheckShowAll; + Handle iCheckSetTypeCreator; Handle iMaxBufferSize; short iType; short iRect; @@ -308,8 +328,11 @@ void PreferenceDialog( void ) // Getthe dialog and fill it preferences = GetNewDialog( kDialogPreferenceID, NULL, (WindowPtr)-1 ); - GetDItem( preferences, kPreferenceCheckVBL, &iType, &iCheckVBL, &iRect ); - SetCtlValue( iCheckVBL, PreferenceGetIsPlaybackVBL() ); + GetDItem( preferences, kPreferenceShowAll, &iType, &iCheckShowAll, &iRect ); + SetCtlValue( iCheckShowAll, PreferenceGetShowAll() ); + GetDItem( preferences, kPreferenceSetTypeCreator, &iType, &iCheckSetTypeCreator, &iRect ); + SetCtlValue( iCheckSetTypeCreator, PreferenceGetSetTypeCreator() ); + GetDItem( preferences, kPreferenceMaxBufferSize, &iType, &iMaxBufferSize, &iRect ); if (PreferenceGetMaxBufferSize()!=0) NumToString( PreferenceGetMaxBufferSize(), iText ); @@ -317,8 +340,7 @@ void PreferenceDialog( void ) iText[0] = 0; SetIText( iMaxBufferSize, iText ); - if (MachineIsMinimal()) - HiliteControl( iCheckVBL, 255 ); + HiliteControl( iCheckSetTypeCreator, PreferenceGetShowAll()?0:255 ); UtilPlaceWindow( preferences, 0.2 ); ShowWindow( preferences ); @@ -326,10 +348,16 @@ void PreferenceDialog( void ) do { ModalDialog( NULL, &itemHit ); - if (itemHit==kPreferenceCheckVBL) + if (itemHit==kPreferenceShowAll) + { + PreferenceSetShowAll( !PreferenceGetShowAll() ); + SetCtlValue( iCheckShowAll, PreferenceGetShowAll() ); + HiliteControl( iCheckSetTypeCreator, PreferenceGetShowAll()?0:255 ); + } + if (itemHit==kPreferenceSetTypeCreator) { - PreferenceSetIsPlaybackVBL( !PreferenceGetIsPlaybackVBL() ); - SetCtlValue( iCheckVBL, PreferenceGetIsPlaybackVBL() ); + PreferenceSetSetTypeCreator( !PreferenceGetSetTypeCreator() ); + SetCtlValue( iCheckSetTypeCreator, PreferenceGetSetTypeCreator() ); } } while (itemHit!=kPreferenceButtonOk); @@ -340,7 +368,9 @@ void PreferenceDialog( void ) StringToNum( iText, &maxBufferSize ); if (maxBufferSize!=PreferenceGetMaxBufferSize()) { - UtilDialog( kALRTPreferencesRestart ); + HideCursor(); // #### Hideous + UtilDialog( kDLOGPreferencesRestart ); + ShowCursor(); PreferenceSetMaxBufferSize( maxBufferSize ); } } diff --git a/macsrc/Preferences.h b/macsrc/Preferences.h index c33dd5f..91f3819 100644 --- a/macsrc/Preferences.h +++ b/macsrc/Preferences.h @@ -35,6 +35,20 @@ void PreferenceSetIsPlaybackVBL( Boolean b ); Boolean PreferenceGetLoop( void ); void PreferenceSetLoop( Boolean b ); +// ------------------------------------------------------------------- +// Show all flims in SFPGetFile +// ------------------------------------------------------------------- + +Boolean PreferenceGetShowAll( void ); +void PreferenceSetShowAll( Boolean b ); + +// ------------------------------------------------------------------- +// Set type/creator on open +// ------------------------------------------------------------------- + +Boolean PreferenceGetSetTypeCreator( void ); +void PreferenceSetSetTypeCreator( Boolean b ); + // ------------------------------------------------------------------- // Size of buffers (0 if no size set). Can be used from mini player // ------------------------------------------------------------------- @@ -48,8 +62,6 @@ short PreferencesGetNextTipIndex( void ); void PreferencesSetNextTipIndex( short nextTipIndex ); short PreferencesGetNextTipBtnIndex( void ); void PreferencesSetNextTipBtnIndex( short nextTipBtnIndex ); -Boolean PreferencesGetShowTips( void ); -void PreferencesSetShowTips( Boolean showTips ); Boolean PreferencesGetShowTipsStartup( void ); void PreferencesSetShowTipsStartup( Boolean showTipsStartup ); diff --git a/macsrc/Resources.h b/macsrc/Resources.h index a081bdf..0881764 100644 --- a/macsrc/Resources.h +++ b/macsrc/Resources.h @@ -49,10 +49,8 @@ enum { kMenuItemAddFlimID = 1, // ALRT // ------------------------------------------------------------------- -#define kAlertOpenFlimErrorID 137 #define kALRTErrorNonFatal 140 #define kALRTErrorNoBWScreen 142 // No BW screen present -#define kALRTPreferencesRestart 143 // Need to restart to apply prefs // ------------------------------------------------------------------- // Dialogs @@ -74,11 +72,15 @@ enum { kMenuItemAddFlimID = 1, #define kDialogPreferenceID 135 #define kPreferenceButtonOk 1 - #define kPreferenceCheckVBL 2 - #define kPreferenceMaxBufferSize 3 + #define kPreferenceShowAll 2 + #define kPreferenceSetTypeCreator 3 + #define kPreferenceMaxBufferSize 4 #define kDLOGFatal 136 +#define kDLOGOpenFlimError 137 + +#define kDLOGPreferencesRestart 143 #define kDLOGProgress 144 // ------------------------------------------------------------------- @@ -109,10 +111,8 @@ enum { kMenuItemAddFlimID = 1, // ------------------------------------------------------------------- #define kSFAddFlimDialogID 2000 - #define kSFAddFlimHelpTextID 11 #define kSFAddFolderDialogID 2001 - #define kSFAddFolderHelpTextID 11 - #define kSFAddFolderChooseDirectoryID 12 + #define kSFAddFolderChooseDirectoryID 11 #endif diff --git a/macsrc/Self_Player.c b/macsrc/Self_Player.c index e81c550..2a9df22 100644 --- a/macsrc/Self_Player.c +++ b/macsrc/Self_Player.c @@ -149,7 +149,7 @@ Boolean SelfInstallPlayer( Str255 fName, short vRefNum, short dirID ) HUnlock( sCopyHdl ); - UtilSetFileTypeCreator( fName, vRefNum, dirID, 'APPL', 'AFLM' ); + UtilSetFileTypeCreator( fName, vRefNum, dirID, 'APPL', 'MMFL' ); done1: CloseResFile( dest ); diff --git a/macsrc/Tips.c b/macsrc/Tips.c index db3a552..bfff332 100644 --- a/macsrc/Tips.c +++ b/macsrc/Tips.c @@ -94,13 +94,13 @@ void ToggleTips() DisposTips(); } -void DoTipsSelect( short anItem, EventRecord *anEvent ) +Boolean DoTipsSelect( short anItem, EventRecord *anEvent ) { switch (anItem) { case kNextTipItemID: DisplayNextTip(); - break; + return TRUE; case kShowTipItemID: { short theType; @@ -110,7 +110,9 @@ void DoTipsSelect( short anItem, EventRecord *anEvent ) PreferencesSetShowTipsStartup( !GetCtlValue( theItem ) ); SetCtlValue( theItem, PreferencesGetShowTipsStartup() ); PreferenceSave(); - break; + return TRUE; } } + + return FALSE; } diff --git a/macsrc/Tips.h b/macsrc/Tips.h index 7723476..cf4dccd 100644 --- a/macsrc/Tips.h +++ b/macsrc/Tips.h @@ -12,7 +12,7 @@ Boolean IsTips( DialogPtr aDialog ); void ToggleTips( void ); // Handle interaction with the dialog -void DoTipsSelect( short anItem, EventRecord *anEvent ); +Boolean DoTipsSelect( short anItem, EventRecord *anEvent ); // Clean-up void DisposTips( void ); diff --git a/macsrc/User_Interface.c b/macsrc/User_Interface.c index 8bca70d..cf3ebc5 100644 --- a/macsrc/User_Interface.c +++ b/macsrc/User_Interface.c @@ -41,7 +41,7 @@ static Boolean IsFlimTypeCorrect( Str255 fName, short vRefNum, long dirID ) CheckErr( err, "UtilGetFileTypeCreator" ); if (err==noErr && - (type=='FLIM' || type=='AFLM')) + (type=='FLIM' || type=='MMFL')) return TRUE; return FALSE; @@ -131,7 +131,7 @@ static void SetFlimTypeCreator( Str255 fName, short vRefNum, long dirID ) // ------------------------------------------------------------------- // Sets flim creator if needed and accepted by user // Does an optional integrity check -// Return FALSE if file should not be played +// Return FALSE if file should not be played (checksum error) // ------------------------------------------------------------------- static Boolean SetFlimTypeCreatorIfNeeded( Str255 fName, short vRefNum, long dirID ) @@ -149,6 +149,12 @@ static Boolean SetFlimTypeCreatorIfNeeded( Str255 fName, short vRefNum, long dir return TRUE; } + if (PreferenceGetSetTypeCreator()) + { + SetFlimTypeCreator( fName, vRefNum, dirID ); + return TRUE; + } + ParamText( fName, "", "", "" ); theSetTypeDialog = GetNewDialog( kDialogSetTypeID, NULL, (WindowPtr)-1 ); ShowWindow( theSetTypeDialog ); @@ -156,10 +162,10 @@ static Boolean SetFlimTypeCreatorIfNeeded( Str255 fName, short vRefNum, long dir DisposDialog( theSetTypeDialog ); if (itemHit==kSetTypeButtonOk) { - if (ChecksumFlimIfNeeded( fName, vRefNum, dirID, TRUE )) - SetFlimTypeCreator( fName, vRefNum, dirID ); - else + if (!ChecksumFlimIfNeeded( fName, vRefNum, dirID, TRUE )) return FALSE; + + SetFlimTypeCreator( fName, vRefNum, dirID ); } return TRUE; @@ -224,7 +230,7 @@ static pascal Boolean CustomFileFilter( FileParam *pbp ) return FALSE; if (pbp->ioFlFndrInfo.fdType=='APPL' - && pbp->ioFlFndrInfo.fdCreator=='AFLM') + && pbp->ioFlFndrInfo.fdCreator=='MMFL') return FALSE; if (gDeepInspection) @@ -269,7 +275,9 @@ static pascal short CustomHook( short item, DialogPtr dlg ) GetDItem( dlg, kSFAddFolderChooseDirectoryID, &iType, &iHandle, &iRect); - SetCTitle( (ControlHandle)iHandle, gDirectoryName ); +// This only works on the emulator, not on real hardware. Maybe a patch in ROM? +// SetCTitle( (ControlHandle)iHandle, gDirectoryName ); + SetCTitle( (ControlHandle)iHandle, "\pAdd Current Directory" ); if (item==kSFAddFolderChooseDirectoryID) return 1; // Treat this as 'ok' @@ -340,15 +348,13 @@ static Boolean UserInterfaceSFGetFlim( Boolean option, Str255 fName, short *vRef SFReply theReply; Ptr savePtr; - if (option) + if (PreferenceGetShowAll()) { gDeepInspection = TRUE; - ParamText( "\pShowing all flims", "", "", "" ); } else { gDeepInspection = FALSE; - ParamText( "\pHint: Open menu with Option key to see all flim files", "", "", "" ); } // Ask user for a file @@ -878,17 +884,28 @@ static void UserInterfaceDoMenuResult( long theMenuResult, Boolean thefOption ) } } -static void UserInterfaceDoKey( EventRecord *anEvent ) +/// Returns top-most window that accepts keys +static WindowPtr UserInterfaceKeyWindow() +{ + WindowPtr result = FrontWindow(); + if (IsTips(result)) + result = (WindowPtr)(((WindowRecord *)result)->nextWindow); + + return result; +} + +static Boolean UserInterfaceDoKey( EventRecord *anEvent ) { char theKey = anEvent->message & charCodeMask; if (anEvent->modifiers & cmdKey) { UserInterfaceEnableDisableMenus(); UserInterfaceDoMenuResult( MenuKey( theKey ), !!(anEvent->modifiers&optionKey) ); + return TRUE; } else { - if (FrontWindow()==LibraryGetWindow(sLibrary)) + if (UserInterfaceKeyWindow()==LibraryGetWindow(sLibrary)) { switch (anEvent->message&charCodeMask) { @@ -936,9 +953,14 @@ static void UserInterfaceDoKey( EventRecord *anEvent ) UserInterfaceTrySelect( sLibrary, selection ); break; } + default: + { + return FALSE; + } } } } + return TRUE; } static void UserInterfaceDoCloseWindow( WindowPtr aWindow ) @@ -966,18 +988,6 @@ static void UserInterfaceDoMenuBar( Point aPoint, Boolean thefOption ) else SetItem( gFileMenu, kMENUItemShowTips, "\pShow Tips..." ); // #### Localization - // Reword the menu items if option is pressed - if (!thefOption) - { - SetItem( gLibraryMenu, kMenuItemAddFlimID, "\pAdd Flim..." ); // #### Localization - SetItem( gLibraryMenu, kMenuItemAddFolderID, "\pAdd Folder Of Flims..." ); // #### Localization - } - else - { - SetItem( gLibraryMenu, kMenuItemAddFlimID, "\pAdd Flim Of Any Type..." ); // #### Localization - SetItem( gLibraryMenu, kMenuItemAddFolderID, "\pAdd Folder Of Flims Of Any Type..." ); // #### Localization - } - if (LibraryIsSelectionEmpty( sLibrary ) && LibraryGetCount( sLibrary)>0) { SetItem( gLibraryMenu, kMENUItemPlay, "\pPlay All Flims" ); // #### Localization @@ -1182,23 +1192,25 @@ static void UserInterfaceDoUpdate( WindowPtr aWindow ) SetPort( savedPort ); } -static void DoDialogEvent( EventRecord *anEvent ) +/// Return TRUE if event was handled +static Boolean DoDialogEvent( EventRecord *anEvent ) { DialogPtr theDialog; short theItem; if (anEvent->what==keyDown && anEvent->modifiers&cmdKey) { - UserInterfaceDoKey( anEvent ); - return ; + return UserInterfaceDoKey( anEvent ); } if (DialogSelect( anEvent, &theDialog, &theItem )) { if (IsTips( theDialog )) - DoTipsSelect( theItem, anEvent ); + return DoTipsSelect( theItem, anEvent ); } + + return FALSE; } void UserInterfaceLoop() @@ -1228,8 +1240,8 @@ void UserInterfaceLoop() if (IsDialogEvent( &theEvent )) { - DoDialogEvent( &theEvent ); - continue; + if (DoDialogEvent( &theEvent )) + continue; // Handled } switch (theEvent.what)