Added option to control PCSX2 volume only with volume keys, instead of global windows volume. Release shift, control, and alt on deactivate. Fix for changing skip mode on alt-F4 (Accidentally removed the old fix for it in 0.9.5)

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@747 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
mattmenke 2009-03-11 17:25:51 +00:00
parent 90263a17d6
commit 004d559678
8 changed files with 101 additions and 22 deletions

View File

@ -576,7 +576,21 @@ int WritePrivateProfileInt(wchar_t *s1, wchar_t *s2, int v, wchar_t *ini) {
return WritePrivateProfileStringW(s1, s2, temp, ini);
}
int SaveSettings(wchar_t *file = 0) {
void SetVolume(int volume) {
if (volume > 100) volume = 100;
if (volume < 0) volume = 0;
config.volume = volume;
unsigned int val = 0xFFFF * volume/100;
val = val | (val<<16);
for (int i=waveOutGetNumDevs()-1; i>=0; i--) {
waveOutSetVolume((HWAVEOUT)i, val);
}
wchar_t ini[MAX_PATH+20];
GetSettingsFileName(ini);
WritePrivateProfileInt(L"General Settings", L"Volume", config.volume, ini);
}
int SaveSettings(wchar_t *file=0) {
wchar_t ini[MAX_PATH+20];
// Need this either way for saving path.
@ -620,6 +634,9 @@ int SaveSettings(wchar_t *file = 0) {
WritePrivateProfileInt(L"General Settings", L"Save State in Title", config.saveStateTitle, file);
WritePrivateProfileInt(L"General Settings", L"Vista Volume", config.vistaVolume, file);
WritePrivateProfileInt(L"General Settings", L"Volume", config.volume, file);
WritePrivateProfileInt(L"Pad1", L"Guitar", config.guitar[0], file);
WritePrivateProfileInt(L"Pad2", L"Guitar", config.guitar[1], file);
WritePrivateProfileInt(L"Pad1", L"Auto Analog", config.AutoAnalog[0], file);
@ -735,6 +752,18 @@ int LoadSettings(int force, wchar_t *file) {
config.saveStateTitle = GetPrivateProfileBool(L"General Settings", L"Save State in Title", 1, file);
config.vistaVolume = GetPrivateProfileBool(L"General Settings", L"Vista Volume", 1, file);
config.volume = GetPrivateProfileInt(L"General Settings", L"Volume", 100, file);
OSVERSIONINFO os;
os.dwOSVersionInfoSize = sizeof(os);
config.osVersion = 0;
if (GetVersionEx(&os)) {
config.osVersion = os.dwMajorVersion;
}
if (config.osVersion < 6) config.vistaVolume = 0;
if (!config.vistaVolume) config.volume = 100;
if (config.vistaVolume) SetVolume(config.volume);
if (!InitializeRawInput()) {
if (config.keyboardApi == RAW) config.keyboardApi = WM;
if (config.mouseApi == RAW) config.mouseApi = WM;
@ -1517,6 +1546,9 @@ INT_PTR CALLBACK GeneralDialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, L
CheckDlgButton(hWnd, IDC_GH2_HACK, BST_CHECKED * config.GH2);
CheckDlgButton(hWnd, IDC_SAVE_STATE_TITLE, BST_CHECKED * config.saveStateTitle);
CheckDlgButton(hWnd, IDC_VISTA_VOLUME, BST_CHECKED * config.vistaVolume);
if (config.osVersion < 6) EnableWindow(GetDlgItem(hWnd, IDC_VISTA_VOLUME), 0);
CheckDlgButton(hWnd, IDC_GUITAR1, BST_CHECKED * config.guitar[0]);
CheckDlgButton(hWnd, IDC_GUITAR2, BST_CHECKED * config.guitar[1]);
CheckDlgButton(hWnd, IDC_ANALOG_START1, BST_CHECKED * config.AutoAnalog[0]);
@ -1608,6 +1640,13 @@ INT_PTR CALLBACK GeneralDialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, L
config.GH2 = (IsDlgButtonChecked(hWnd, IDC_GH2_HACK) == BST_CHECKED);
config.saveStateTitle = (IsDlgButtonChecked(hWnd, IDC_SAVE_STATE_TITLE) == BST_CHECKED);
u8 newVistaVolume = (IsDlgButtonChecked(hWnd, IDC_VISTA_VOLUME) == BST_CHECKED);
if (config.vistaVolume != newVistaVolume) {
config.vistaVolume = newVistaVolume;
SetVolume(100);
}
unsigned int needUpdate = 0;
unsigned int disablePad1New = (IsDlgButtonChecked(hWnd, IDC_DISABLE_PAD1) == BST_CHECKED);
unsigned int disablePad2New = (IsDlgButtonChecked(hWnd, IDC_DISABLE_PAD2) == BST_CHECKED);

View File

@ -38,6 +38,12 @@ public:
u8 saveStateTitle;
u8 vistaVolume;
int volume;
// Unlike the others, not a changeable value.
DWORD osVersion;
wchar_t lastSaveConfigPath[MAX_PATH+1];
wchar_t lastSaveConfigFileName[MAX_PATH+1];
};
@ -48,6 +54,8 @@ void UnloadConfigs();
void AddIgnore(LPARAM k);
void SetVolume(int volume);
int LoadSettings(int force = 0, wchar_t *file = 0);
void CALLBACK PADconfigure();

View File

@ -20,7 +20,7 @@ inline static u32 flipLong(u32 l) {
static void GUIDtoString(wchar_t *data, const GUID *pg) {
wsprintfW(data, L"%08X-%04X-%04X-%04X-%04X%08X",
pg->Data1, (u32)pg->Data2, (u32)pg->Data3,
flipShort(((u16*)pg->Data4)[0]),
flipShort(((u16*)pg->Data4)[0]),
flipShort(((u16*)pg->Data4)[1]),
flipLong(((u32*)pg->Data4)[1]));
}
@ -320,6 +320,7 @@ public:
did->Unacquire();
did->Release();
ReleaseDirectInput();
did = 0;
active = 0;
}
}

View File

@ -428,7 +428,9 @@ void InputDeviceManager::DisableAllDevices() {
void InputDeviceManager::DisableDevice(int index) {
devices[index]->enabled = 0;
if (devices[index]->active) devices[index]->Deactivate();
if (devices[index]->active) {
devices[index]->Deactivate();
}
}
ForceFeedbackEffectType *Device::GetForcefeedbackEffect(wchar_t *id) {

View File

@ -97,6 +97,16 @@ LRESULT CALLBACK IgnoreKeyboardHook(int code, WPARAM wParam, LPARAM lParam) {
return 1;
}
}
if (config.vistaVolume) {
if (key->vkCode == VK_VOLUME_DOWN) {
SetVolume(config.volume-3);
return 1;
}
if (key->vkCode == VK_VOLUME_UP) {
SetVolume(config.volume+3);
return 1;
}
}
}
else if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP) {
KBDLLHOOKSTRUCT* key = (KBDLLHOOKSTRUCT*) lParam;

View File

@ -132,10 +132,14 @@ u8 Cap (int i) {
return (u8) i;
}
// Just like RefreshEnabledDevices(), but takes into account
// mouse and focus state and which devices have bindings for
// enabled pads. Also releases keyboards if window is not focused.
// RefreshEnabledDevices() enables everything that can potentially
// be bound to, as well as the "Ignore keyboard" device.
//
// This enables everything that input should be read from while the
// emulator is running. Takes into account mouse and focus state
// and which devices have bindings for enabled pads. Releases
// keyboards if window is not focused. Releases game devices if
// background monitoring is not checked.
// And releases games if not focused and config.background is not set.
void UpdateEnabledDevices(int updateList = 0) {
// Enable all devices I might want. Can ignore the rest.
@ -156,7 +160,7 @@ void UpdateEnabledDevices(int updateList = 0) {
// Disable ignore keyboard if don't have focus or there are no keys to ignore.
if (dev->api == IGNORE_KEYBOARD) {
if (config.keyboardApi == NO_API || !activeWindow || !dev->pads[0].numBindings) {
if ((!config.vistaVolume && (config.keyboardApi == NO_API || !dev->pads[0].numBindings)) || !activeWindow) {
dm->DisableDevice(i);
}
continue;
@ -629,6 +633,8 @@ struct QueryInfo {
int saveStateIndex = 0;
// Implements a couple of the hacks, also responsible for monitoring device addition/removal and focus
// changes.
ExtraWndProcResult HackWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output) {
switch (uMsg) {
case WM_SETTEXT:
@ -659,6 +665,12 @@ ExtraWndProcResult HackWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
}
break;
case WM_ACTIVATEAPP:
// Release any buttons PCSX2 may think are down when
// losing/gaining focus.
QueueKeyEvent(VK_SHIFT, KEYRELEASE);
QueueKeyEvent(VK_MENU, KEYRELEASE);
QueueKeyEvent(VK_CONTROL, KEYRELEASE);
// Need to do this when not reading input from gs thread.
// Checking for that case not worth the effort.
EnterCriticalSection(&readInputCriticalSection);
@ -1112,6 +1124,7 @@ keyEvent* CALLBACK PADkeyEvent() {
Update(2);
}
static char shiftDown = 0;
static char altDown = 0;
static keyEvent ev;
if (!GetQueuedKeyEvent(&ev)) return 0;
if ((ev.key == VK_ESCAPE || (int)ev.key == -2) && ev.evt == KEYPRESS && config.escapeFullscreenHack) {
@ -1145,18 +1158,21 @@ keyEvent* CALLBACK PADkeyEvent() {
}
}
// So don't change skip mode on alt-F4.
if (ev.key == VK_F4 && altDown) {
return 0;
}
if (ev.key == VK_LSHIFT || ev.key == VK_RSHIFT || ev.key == VK_SHIFT) {
ev.key = VK_SHIFT;
if (ev.evt == KEYPRESS)
shiftDown = 1;
else
shiftDown = 0;
shiftDown = (ev.evt == KEYPRESS);
}
else if (ev.key == VK_LCONTROL || ev.key == VK_RCONTROL) {
ev.key = VK_CONTROL;
}
else if (ev.key == VK_LMENU || ev.key == VK_RMENU) {
else if (ev.key == VK_LMENU || ev.key == VK_RMENU || ev.key == VK_SHIFT) {
ev.key = VK_MENU;
altDown = (ev.evt == KEYPRESS);
}
return &ev;
}

View File

@ -27,18 +27,18 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// TEXTINCLUDE
//
1 TEXTINCLUDE
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
2 TEXTINCLUDE
BEGIN
"#include <winres.h>\r\n"
"\0"
END
3 TEXTINCLUDE
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
@ -265,12 +265,13 @@ BEGIN
CONTROL "Send escape on window close",IDC_CLOSE_HACK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,223,113,10
CONTROL "Exit emulator on window close",IDC_CLOSE_HACK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,235,112,10
CONTROL "Disable screensaver",IDC_DISABLE_SCREENSAVER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,247,80,10
CONTROL "Safe fullscreen exit on escape (For GSDX+DX10)",IDC_ESCAPE_FULLSCREEN_HACK,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,259,171,10
CONTROL "Safe fullscreen exit on escape",IDC_ESCAPE_FULLSCREEN_HACK,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,259,112,10
CONTROL "Use GS thread (Recommended)",IDC_GS_THREAD_INPUT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,271,116,10
CONTROL "Always hide cursor",IDC_FORCE_HIDE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,336,223,71,10
CONTROL "Save state # in title",IDC_SAVE_STATE_TITLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,336,235,79,10
CONTROL "Guitar Hero 2 Hack",IDC_GH2_HACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,336,247,76,10
CONTROL "App Local Volume",IDC_VISTA_VOLUME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,336,247,71,10
CONTROL "Guitar Hero 2 Hack",IDC_GH2_HACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,336,259,76,10
GROUPBOX "Debugging",IDC_STATIC,216,285,79,25
CONTROL "Enable logging",IDC_DEBUG_FILE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,223,296,63,10
PUSHBUTTON "Load",ID_LOAD,313,295,48,15
@ -302,7 +303,7 @@ END
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
GUIDELINES DESIGNINFO
BEGIN
IDD_CONFIG, DIALOG
BEGIN

View File

@ -42,6 +42,8 @@
#define IDC_FORCE_HIDE2 1125
#define IDC_GH2_HACK 1125
#define IDC_FORCEFEEDBACK_HACK1 1126
#define IDC_GH2_HACK2 1126
#define IDC_VISTA_VOLUME 1126
#define IDC_DISABLE_SCREENSAVER4 1127
#define IDC_FORCEFEEDBACK_HACK2 1127
#define IDC_GS_THREAD_INPUT 1128
@ -115,7 +117,7 @@
#define IDC_FF_MOTOR 0x1303
#define ID_FF 0x1304
#define IDC_FF_EFFECT 0x1305
#define IDC_VERSION 0x1306
#define IDC_VERSION 0x1306
#define IDC_FF_AXIS1_ENABLED 0x1310
#define IDC_FF_AXIS1 0x1311
#define IDC_FF_AXIS1_FLIP 0x1312
@ -150,7 +152,7 @@
#define IDC_FF_AXIS8_SCALE 0x1383
// Next default values for new objects
//
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 112