From 1cd34b57ea1b86bc76e901fd170a72859102a37a Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 21 Aug 2010 03:59:17 +0000 Subject: [PATCH] Win32 - Add movie filename at the top of the main window, did this by creating a SetMainWindowText() function that sets it based on various conditions, this allowed some nice code cleanup on the various places that set the window text. Also removed an unused and useless prototype from movie.h --- changelog.txt | 1 + src/drivers/win/window.cpp | 34 +++++++++++++++++++++++++--------- src/drivers/win/window.h | 1 + src/movie.cpp | 12 ++++++++++++ src/movie.h | 3 ++- src/utils/xstring.cpp | 13 +++++++++++++ src/utils/xstring.h | 3 +++ 7 files changed, 57 insertions(+), 10 deletions(-) diff --git a/changelog.txt b/changelog.txt index 9e5fc684..d51890c7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,4 @@ +20-aug-2010 - adelikat - Win32 - Display movie name at the top of the main window 09-july-2010 - mart0258 - TasEdit - cleanup; prevent crash when truncating while turbo 13-june-2010 - adelikat - Win32 - avi capture commandline argument and related parameters 12-june-2010 - adelikat - Save Turbo frame skip amount to config so that it can be customized by user diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 5f5e429f..b6c926de 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -175,6 +175,27 @@ string moviehelp = "{695C964E-B83F-4A6E-9BA2-1A975387DB55}"; //Movie Recording string gettingstartedhelp = "{C76AEBD9-1E27-4045-8A37-69E5A52D0F9A}";//Getting Started //******************************************************************************** +void SetMainWindowText() +{ + if (GameInfo) + { + //Add the filename to the window caption + extern char FileBase[]; + string str = FCEU_NAME_AND_VERSION; + str.append(": "); + str.append(FileBase); + + if (FCEUMOV_IsLoaded()) + { + str.append(" Playing: "); + str.append(StripPath(FCEUI_GetMovieName())); + } + SetWindowText(hAppWnd, str.c_str()); + } + else + SetWindowText(hAppWnd, FCEU_NAME_AND_VERSION); +} + bool HasRecentFiles() { @@ -1022,7 +1043,7 @@ void CloseGame() KillMemView(); updateGameDependentMenus(GameInfo != 0); updateGameDependentMenusDebugger(GameInfo != 0); - SetWindowText(hAppWnd, FCEU_NAME_AND_VERSION); + SetMainWindowText(); } } @@ -1058,13 +1079,7 @@ bool ALoad(char *nameo, char* innerFilename) SetFSVideoMode(); } - //Add the filename to the window caption - extern char FileBase[]; - string str = FCEU_NAME_AND_VERSION; - str.append(": "); - str.append(FileBase); - SetWindowText(hAppWnd, str.c_str()); - + if (AutoRWLoad) { OpenRWRecentFile(0); //adelikat: TODO: This command should be called internally from the RamWatch dialog in order for it to be more portable @@ -1080,7 +1095,8 @@ bool ALoad(char *nameo, char* innerFilename) SetWindowText(hAppWnd, FCEU_NAME_AND_VERSION); //adelikat: If game fails to load while a previous one was open, the previous would have been closed, so reflect that in the window caption return false; } - + + SetMainWindowText(); ParseGIInput(GameInfo); updateGameDependentMenus(GameInfo != 0); diff --git a/src/drivers/win/window.h b/src/drivers/win/window.h index 7b39cccc..22292b04 100644 --- a/src/drivers/win/window.h +++ b/src/drivers/win/window.h @@ -23,6 +23,7 @@ extern HWND pwindow; HWND GetMainHWND(); +void SetMainWindowText(); void HideFWindow(int h); void SetMainWindowStuff(); int GetClientAbsRect(LPRECT lpRect); diff --git a/src/movie.cpp b/src/movie.cpp index edb89382..c2bd741d 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -38,6 +38,7 @@ #include #include "./drivers/win/common.h" #include "./drivers/win/tasedit.h" +#include "./drivers/win/window.h" extern void AddRecentMovieFile(const char *filename); #endif @@ -796,6 +797,10 @@ void FCEUI_StopMovie() curMovieFilename[0] = 0; //No longer a current movie filename freshMovie = false; //No longer a fresh movie loaded if (bindSavestate) AutoSS = false; //If bind movies to savestates is true, then there is no longer a valid auto-save to load + +#ifdef WIN32 + SetMainWindowText(); +#endif } void poweron(bool shouldDisableBatteryLoading) @@ -1005,6 +1010,10 @@ bool FCEUI_LoadMovie(const char *fname, bool _read_only, bool tasedit, int _paus FCEU_DispMessage("Replay started Read+Write.",0); } +#ifdef WIN32 + SetMainWindowText(); +#endif + #ifdef CREATE_AVI if(LoggingEnabled) { @@ -1598,6 +1607,9 @@ void FCEUI_MoviePlayFromBeginning(void) //currMovieData.loadSavestateFrom(&currMovieData.savestate); //TODO: make something like this work instead so it doesn't have to reload } } +#ifdef WIN32 + SetMainWindowText(); +#endif } string FCEUI_GetMovieName(void) diff --git a/src/movie.h b/src/movie.h index 04a09d42..f4ffedc1 100644 --- a/src/movie.h +++ b/src/movie.h @@ -76,6 +76,7 @@ bool FCEUMOV_Mode(int modemask); inline bool FCEUMOV_IsPlaying() { return (FCEUMOV_Mode(MOVIEMODE_PLAY|MOVIEMODE_FINISHED)); } inline bool FCEUMOV_IsRecording() { return FCEUMOV_Mode(MOVIEMODE_RECORD); } inline bool FCEUMOV_IsFinished() { return FCEUMOV_Mode(MOVIEMODE_FINISHED);} +inline bool FCEUMOV_IsLoaded() { return (FCEUMOV_Mode(MOVIEMODE_PLAY|MOVIEMODE_RECORD|MOVIEMODE_FINISHED)); } bool FCEUMOV_ShouldPause(void); int FCEUMOV_GetFrame(void); @@ -268,7 +269,7 @@ bool FCEUI_LoadMovie(const char *fname, bool read_only, bool tasedit, int _stopf void FCEUI_MoviePlayFromBeginning(void); void FCEUI_StopMovie(void); bool FCEUI_MovieGetInfo(FCEUFILE* fp, MOVIE_INFO& info, bool skipFrameCount = false); -char* FCEUI_MovieGetCurrentName(int addSlotNumber); +//char* FCEUI_MovieGetCurrentName(int addSlotNumber); void FCEUI_MovieToggleReadOnly(void); bool FCEUI_GetMovieToggleReadOnly(); void FCEUI_SetMovieToggleReadOnly(bool which); diff --git a/src/utils/xstring.cpp b/src/utils/xstring.cpp index 21e988aa..7af0c846 100644 --- a/src/utils/xstring.cpp +++ b/src/utils/xstring.cpp @@ -774,3 +774,16 @@ std::string getExtension(const char* input) { ext[k]=tolower(ext[k]); return ext; } + +//strips the file extension off a filename +std::string StripExtension(std::string filename) +{ + return filename.substr(0, filename.find_last_of(".")); +} + +//strips the path off a filename +std::string StripPath(std::string filename) +{ + int x = filename.find_last_of("\\") + 1; + return filename.substr(x, filename.length() - x); +} diff --git a/src/utils/xstring.h b/src/utils/xstring.h index aad37674..a841ba74 100644 --- a/src/utils/xstring.h +++ b/src/utils/xstring.h @@ -126,3 +126,6 @@ std::string wcstombs(std::wstring str); //TODO - dont we already have another function that can do this std::string getExtension(const char* input); + +std::string StripExtension(std::string filename); +std::string StripPath(std::string filename); \ No newline at end of file