From 5595d2c17b24c917e0e61206936549e8a3de1c9c Mon Sep 17 00:00:00 2001 From: rheiny Date: Sun, 11 Feb 2007 15:35:03 +0000 Subject: [PATCH] Improved the Directories configuration dialog. --- src/drivers/win/common.h | 1 + src/drivers/win/debugger.cpp | 38 +-------------------- src/drivers/win/directories.cpp | 57 ++++++++++++++++++++++---------- src/drivers/win/gui.cpp | 57 ++++++++++++++++++++++++++++++++ src/drivers/win/gui.h | 4 ++- src/drivers/win/main.h | 1 + src/drivers/win/res.rc | Bin 138850 -> 138262 bytes src/drivers/win/resource.h | 1 + vc8/fceux.vcproj | 4 +++ 9 files changed, 108 insertions(+), 55 deletions(-) diff --git a/src/drivers/win/common.h b/src/drivers/win/common.h index 4649a6ef..c35c3d90 100644 --- a/src/drivers/win/common.h +++ b/src/drivers/win/common.h @@ -44,3 +44,4 @@ extern int eoptions; #define EO_FORCEISCALE 16384 #define EO_NOFOURSCORE 32768 +bool directoryExists(const char* dirname); \ No newline at end of file diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 9e088456..7109cef0 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -31,7 +31,7 @@ #include "tracer.h" #include "memview.h" #include "cheat.h" -#include +#include "gui.h" // ################################## Start of SP CODE ########################### @@ -57,42 +57,6 @@ HWND hDebug; static HFONT hFont,hNewFont; static SCROLLINFO si; - - -/** -* Centers a window relative to its parent window. -* -* @param hwndDlg Handle of the window to center. -**/ -void CenterWindow(HWND hwndDlg) -{ - //TODO: This function should probably moved into the generic Win32 window file - //move the window relative to its parent - HWND hwndParent = GetParent(hwndDlg); - RECT rect; - RECT rectP; - - GetWindowRect(hwndDlg, &rect); - GetWindowRect(hwndParent, &rectP); - - unsigned int width = rect.right - rect.left; - unsigned height = rect.bottom - rect.top; - - unsigned x = ((rectP.right-rectP.left) - width) / 2 + rectP.left; - unsigned y = ((rectP.bottom-rectP.top) - height) / 2 + rectP.top; - - unsigned screenwidth = GetSystemMetrics(SM_CXSCREEN); - unsigned screenheight = GetSystemMetrics(SM_CYSCREEN); - - //make sure that the dialog box never moves outside of the screen - if(x < 0) x = 0; - if(y < 0) y = 0; - if(x + width > screenwidth) x = screenwidth - width; - if(y + height > screenheight) y = screenheight - height; - - MoveWindow(hwndDlg, x, y, width, height, FALSE); -} - #define START_OFFSET_HANDLE 200 #define END_OFFSET_HANDLE 201 #define READ_BREAKPOINT_HANDLE 102 diff --git a/src/drivers/win/directories.cpp b/src/drivers/win/directories.cpp index ecc36849..a84d2d97 100644 --- a/src/drivers/win/directories.cpp +++ b/src/drivers/win/directories.cpp @@ -1,6 +1,7 @@ #include "common.h" #include "main.h" #include "window.h" +#include "gui.h" /** * Processes information from the Directories selection dialog after @@ -10,8 +11,6 @@ **/ void CloseDirectoriesDialog(HWND hwndDlg) { - int x; - // Update the information from the screenshot naming checkbox if(IsDlgButtonChecked(hwndDlg, CHECK_SCREENSHOT_NAMES) == BST_CHECKED) { @@ -26,38 +25,60 @@ void CloseDirectoriesDialog(HWND hwndDlg) // Read the information from the edit fields and update the // necessary variables. - for(x = 0; x < NUMBER_OF_DIRECTORIES; x++) + for(unsigned int curr_dir = 0; curr_dir < NUMBER_OF_DIRECTORIES; curr_dir++) { LONG len; - len = SendDlgItemMessage(hwndDlg, EDIT_CHEATS + x, WM_GETTEXTLENGTH, 0, 0); + len = SendDlgItemMessage(hwndDlg, EDIT_CHEATS + curr_dir, WM_GETTEXTLENGTH, 0, 0); if(len <= 0) { - if(directory_names[x]) + if(directory_names[curr_dir]) { - free(directory_names[x]); + free(directory_names[curr_dir]); } - directory_names[x] = 0; + directory_names[curr_dir] = 0; continue; } len++; // Add 1 for null character. - if( !(directory_names[x] = (char*)malloc(len))) //mbg merge 7/17/06 added cast + if( !(directory_names[curr_dir] = (char*)malloc(len))) //mbg merge 7/17/06 added cast { continue; } - if(!GetDlgItemText(hwndDlg, EDIT_CHEATS + x, directory_names[x], len)) + if(!GetDlgItemText(hwndDlg, EDIT_CHEATS + curr_dir, directory_names[curr_dir], len)) { - free(directory_names[x]); - directory_names[x]=0; + free(directory_names[curr_dir]); + directory_names[curr_dir] = 0; continue; } + if (!directoryExists(directory_names[curr_dir])) + { + const char* mask = "Error: Directory %s does not exist. Create this directory?"; + + char* buffer = (char*)malloc(strlen(mask) + strlen(directory_names[curr_dir]) + 1); + + sprintf(buffer, mask, directory_names[curr_dir]); + + if ( MessageBox(hwndDlg, buffer, "FCE Ultra", MB_ICONERROR | MB_YESNO) == IDYES ) + { + if (!CreateDirectory(directory_names[curr_dir], 0)) + { + MessageBox(hwndDlg, "Error: Couldn't create directory. Please choose a different directory.", "FCE Ultra", MB_ICONERROR | MB_OK); + free(buffer); + return; + } + } + + free(buffer); + } + } + initDirectories(); CreateDirs(); // Create needed directories. SetDirs(); // Set the directories in the core. @@ -69,18 +90,14 @@ void CloseDirectoriesDialog(HWND hwndDlg) **/ static BOOL CALLBACK DirConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - int x; - switch(uMsg) { case WM_INITDIALOG: - SetDlgItemText(hwndDlg,65508,"The settings in the \"Individual Directory Overrides\" group will override the settings in the \"Base Directory Override\" group. To delete an override, delete the text from the text edit control. Note that the directory the configuration file is in cannot be overridden"); - // Initialize the directories textboxes - for(x = 0; x < NUMBER_OF_DIRECTORIES; x++) + for(unsigned int curr_dir = 0; curr_dir < NUMBER_OF_DIRECTORIES; curr_dir++) { - SetDlgItemText(hwndDlg, EDIT_CHEATS + x, directory_names[x]); + SetDlgItemText(hwndDlg, EDIT_CHEATS + curr_dir, directory_names[curr_dir]); } // Check the screenshot naming checkbox if necessary @@ -88,6 +105,9 @@ static BOOL CALLBACK DirConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM { CheckDlgButton(hwndDlg, CHECK_SCREENSHOT_NAMES, BST_CHECKED); } + + CenterWindowOnScreen(hwndDlg); + break; case WM_CLOSE: @@ -124,6 +144,9 @@ static BOOL CALLBACK DirConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM case CLOSE_BUTTON: CloseDirectoriesDialog(hwndDlg); break; + case BTN_CANCEL: + EndDialog(hwndDlg, 0); + break; } } diff --git a/src/drivers/win/gui.cpp b/src/drivers/win/gui.cpp index b2294fc0..6ffea5ed 100644 --- a/src/drivers/win/gui.cpp +++ b/src/drivers/win/gui.cpp @@ -3,6 +3,63 @@ #include #include // For directories configuration dialog. +/** +* Centers a window relative to its parent window. +* +* @param hwndDlg Handle of the window to center. +**/ +void CenterWindow(HWND hwndDlg) +{ + //TODO: This function should probably moved into the generic Win32 window file + //move the window relative to its parent + HWND hwndParent = GetParent(hwndDlg); + RECT rect; + RECT rectP; + + GetWindowRect(hwndDlg, &rect); + GetWindowRect(hwndParent, &rectP); + + unsigned int width = rect.right - rect.left; + unsigned height = rect.bottom - rect.top; + + unsigned x = ((rectP.right-rectP.left) - width) / 2 + rectP.left; + unsigned y = ((rectP.bottom-rectP.top) - height) / 2 + rectP.top; + + unsigned int screenwidth = GetSystemMetrics(SM_CXSCREEN); + unsigned int screenheight = GetSystemMetrics(SM_CYSCREEN); + + //make sure that the dialog box never moves outside of the screen + if(x < 0) x = 0; + if(y < 0) y = 0; + if(x + width > screenwidth) x = screenwidth - width; + if(y + height > screenheight) y = screenheight - height; + + MoveWindow(hwndDlg, x, y, width, height, FALSE); +} + +/** +* Centers a window on the screen. +* +* @param hwnd The window handle. +**/ +void CenterWindowOnScreen(HWND hwnd) +{ + RECT rect; + + GetWindowRect(hwnd, &rect); + + unsigned int screenwidth = GetSystemMetrics(SM_CXSCREEN); + unsigned int screenheight = GetSystemMetrics(SM_CYSCREEN); + + unsigned int width = rect.right - rect.left; + unsigned height = rect.bottom - rect.top; + + unsigned x = (screenwidth - width) / 2; + unsigned y = (screenheight - height) / 2; + + MoveWindow(hwnd, x, y, width, height, FALSE); +} + /** * Changes the state of the mouse cursor. * diff --git a/src/drivers/win/gui.h b/src/drivers/win/gui.h index b6bf629e..25d71c6d 100644 --- a/src/drivers/win/gui.h +++ b/src/drivers/win/gui.h @@ -1,2 +1,4 @@ void ShowCursorAbs(int set_visible); -int BrowseForFolder(HWND hParent, const char *htext, char *buf); \ No newline at end of file +int BrowseForFolder(HWND hParent, const char *htext, char *buf); +void CenterWindow(HWND hwndDlg); +void CenterWindowOnScreen(HWND hwnd); diff --git a/src/drivers/win/main.h b/src/drivers/win/main.h index 33730c20..8272f92f 100644 --- a/src/drivers/win/main.h +++ b/src/drivers/win/main.h @@ -96,5 +96,6 @@ void DoPriority(); void RemoveDirs(); void CreateDirs(); void SetDirs(); +void initDirectories(); #endif \ No newline at end of file diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 29b919352a149120290e122e698f74e5f5ecf64a..0b95d93a19a4371a8e681239f44d47073529dffd 100644 GIT binary patch delta 792 zcmZ8f&ubGw6n+z9+caR3rf8Z*jiD3-mF{LY*@akbixp}jRdQ%AN~}diX_qEQJqh{` zL?3j(Q$2a{M}>eMiiik;UMxrjPgd_rFVdsm%x*%JWp-xX`@Z+S_ul+i?^$`>v*w)J zYfzC)zHslWY;KA$r^+okc}m3jTlrALrDJ4}MJ{iBIC*!Gvb03=RL5%IT*JCbH?(aI zmPMTIfRQDSZUIx%$SlnTwDBuIW_FhF@W9jj?6T6?tw>Is9lk6E#6nRas=Qs0^_8 zc!<5H;eb@2{J*49%+KMI3dj_Yk|uzDCP(WqsFUe*Crc5X13|9#i{V5Y@9G+M;Y%@< zwXFGk+3(IR<**x6YLhj*DXVxIaj_Q4xnhRs%5Pb|_?XW-Kl@DIrFg#DRW)7T{?i(K-fS!wN7*A|t`Di}H5^ zgZx!ZtDG5ONU8*Mc@6_?5ozSc>ew`ag?&^ delta 929 zcma)4ze^)g5T19$5aZAI>l8&}z$RL_yV+!eQ6n74si--Lwu)LPqTo;L6dS?jaKP8e z!C6@;f?DVycz=LaDu{)(g_VWX&FpiNB|$hA-oE!{-hA_Y^X;Aco-ceyR)2v3253?g ziU+J2IK`*CQhXd}EHt5w1E8I3Zg+pFkAg{GJ6LqB(T-P*Rvk<^bRepCcS6|EQ`Kxh zoIbwiDCe}>C&PYYfR4xSO}kw|EFP?_H0+>8$-13P0NC8E;mK~}zjX;hl=8lWe&M34Uu!tJRD6;<|j3gPI0jC^0sa(Ja!fy6EA=N0TVB_TmS$7 diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index c71e506b..2255f0f7 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -7,6 +7,7 @@ #define BUTTON_CLOSE 1 #define BTN_CLOSE 1 #define GUI_BOT_VALUES 2 +#define BTN_CANCEL 2 #define MENU_OPEN_FILE 100 #define EDIT_CHEATS 100 #define MENU_CLOSE_FILE 101 diff --git a/vc8/fceux.vcproj b/vc8/fceux.vcproj index 705851ab..0aaaec25 100644 --- a/vc8/fceux.vcproj +++ b/vc8/fceux.vcproj @@ -784,6 +784,10 @@ RelativePath="..\src\drivers\win\cheat.h" > + +