2013-04-18 03:43:35 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-04-12 01:56:05 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <wx/app.h>
|
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/chartype.h>
|
|
|
|
#include <wx/defs.h>
|
|
|
|
#include <wx/dialog.h>
|
|
|
|
#include <wx/event.h>
|
|
|
|
#include <wx/font.h>
|
|
|
|
#include <wx/gbsizer.h>
|
|
|
|
#include <wx/gdicmn.h>
|
2011-02-16 02:19:40 +00:00
|
|
|
#include <wx/notebook.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/setup.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/timer.h>
|
|
|
|
#include <wx/translation.h>
|
|
|
|
#include <wx/windowid.h>
|
2011-02-16 02:19:40 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Core/CoreParameter.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/HotkeyDlg.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "DolphinWX/WXInputBase.h"
|
|
|
|
|
2010-04-12 01:56:05 +00:00
|
|
|
HotkeyConfigDialog::HotkeyConfigDialog(wxWindow *parent, wxWindowID id, const wxString &title,
|
|
|
|
const wxPoint &position, const wxSize& size, long style)
|
|
|
|
: wxDialog(parent, id, title, position, size, style)
|
2014-09-01 17:44:16 +00:00
|
|
|
, m_ButtonMappingTimer(this)
|
2010-04-12 01:56:05 +00:00
|
|
|
{
|
|
|
|
CreateHotkeyGUIControls();
|
|
|
|
|
2014-11-09 00:26:20 +00:00
|
|
|
Bind(wxEVT_BUTTON, &HotkeyConfigDialog::OnButtonClick, this, 0, NUM_HOTKEYS - 1);
|
|
|
|
Bind(wxEVT_TIMER, &HotkeyConfigDialog::OnButtonTimer, this);
|
|
|
|
|
2010-04-12 01:56:05 +00:00
|
|
|
g_Pressed = 0;
|
|
|
|
g_Modkey = 0;
|
2014-03-09 20:14:26 +00:00
|
|
|
ClickedButton = nullptr;
|
2010-04-12 01:56:05 +00:00
|
|
|
GetButtonWaitingID = 0;
|
|
|
|
GetButtonWaitingTimer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
HotkeyConfigDialog::~HotkeyConfigDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save keyboard key mapping
|
|
|
|
void HotkeyConfigDialog::SaveButtonMapping(int Id, int Key, int Modkey)
|
|
|
|
{
|
|
|
|
SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkey[Id] = Key;
|
|
|
|
SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkeyModifier[Id] = Modkey;
|
|
|
|
}
|
|
|
|
|
2014-08-30 16:41:21 +00:00
|
|
|
void HotkeyConfigDialog::EndGetButtons()
|
2010-04-12 01:56:05 +00:00
|
|
|
{
|
2013-01-13 18:07:45 +00:00
|
|
|
wxTheApp->Unbind(wxEVT_KEY_DOWN, &HotkeyConfigDialog::OnKeyDown, this);
|
2014-09-01 17:44:16 +00:00
|
|
|
m_ButtonMappingTimer.Stop();
|
2010-04-12 01:56:05 +00:00
|
|
|
GetButtonWaitingTimer = 0;
|
|
|
|
GetButtonWaitingID = 0;
|
2014-03-09 20:14:26 +00:00
|
|
|
ClickedButton = nullptr;
|
2011-03-16 22:22:21 +00:00
|
|
|
SetEscapeId(wxID_ANY);
|
2010-04-12 01:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HotkeyConfigDialog::OnKeyDown(wxKeyEvent& event)
|
|
|
|
{
|
2014-03-10 11:30:55 +00:00
|
|
|
if (ClickedButton != nullptr)
|
2010-04-12 01:56:05 +00:00
|
|
|
{
|
|
|
|
// Save the key
|
|
|
|
g_Pressed = event.GetKeyCode();
|
|
|
|
g_Modkey = event.GetModifiers();
|
|
|
|
|
|
|
|
// Don't allow modifier keys
|
2010-06-09 20:03:37 +00:00
|
|
|
if (g_Pressed == WXK_CONTROL || g_Pressed == WXK_ALT ||
|
|
|
|
g_Pressed == WXK_SHIFT || g_Pressed == WXK_COMMAND)
|
2010-04-12 01:56:05 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Use the space key to set a blank key
|
|
|
|
if (g_Pressed == WXK_SPACE)
|
|
|
|
{
|
|
|
|
SaveButtonMapping(ClickedButton->GetId(), -1, 0);
|
|
|
|
SetButtonText(ClickedButton->GetId(), wxString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-22 23:28:08 +00:00
|
|
|
// Check if the hotkey combination was already applied to another button
|
|
|
|
// and unapply it if necessary.
|
|
|
|
for (wxButton* btn : m_Button_Hotkeys)
|
|
|
|
{
|
|
|
|
// We compare against this to see if we have a duplicate bind attempt.
|
|
|
|
wxString existingHotkey = btn->GetLabel();
|
|
|
|
|
2014-10-05 09:31:45 +00:00
|
|
|
wxString tentativeModKey = WxUtils::WXKeymodToString(g_Modkey);
|
|
|
|
wxString tentativePressedKey = WxUtils::WXKeyToString(g_Pressed);
|
2014-01-22 23:28:08 +00:00
|
|
|
wxString tentativeHotkey(tentativeModKey + tentativePressedKey);
|
|
|
|
|
|
|
|
// Found a button that already has this binding. Unbind it.
|
|
|
|
if (tentativeHotkey == existingHotkey)
|
|
|
|
{
|
|
|
|
SaveButtonMapping(btn->GetId(), -1, 0);
|
|
|
|
SetButtonText(btn->GetId(), wxString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Proceed to apply the binding to the selected button.
|
2010-04-12 01:56:05 +00:00
|
|
|
SetButtonText(ClickedButton->GetId(),
|
2014-10-05 09:31:45 +00:00
|
|
|
WxUtils::WXKeyToString(g_Pressed),
|
|
|
|
WxUtils::WXKeymodToString(g_Modkey));
|
2010-04-12 01:56:05 +00:00
|
|
|
SaveButtonMapping(ClickedButton->GetId(), g_Pressed, g_Modkey);
|
|
|
|
}
|
|
|
|
EndGetButtons();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the textbox for the buttons
|
|
|
|
void HotkeyConfigDialog::SetButtonText(int id, const wxString &keystr, const wxString &modkeystr)
|
|
|
|
{
|
2011-01-30 14:20:20 +00:00
|
|
|
m_Button_Hotkeys[id]->SetLabel(modkeystr + keystr);
|
2010-04-12 01:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HotkeyConfigDialog::DoGetButtons(int _GetId)
|
|
|
|
{
|
|
|
|
// Values used in this function
|
2010-07-29 13:29:15 +00:00
|
|
|
const int Seconds = 4; // Seconds to wait for
|
|
|
|
const int TimesPerSecond = 40; // How often to run the check
|
2010-04-12 01:56:05 +00:00
|
|
|
|
|
|
|
// If the Id has changed or the timer is not running we should start one
|
2014-09-01 17:44:16 +00:00
|
|
|
if ( GetButtonWaitingID != _GetId || !m_ButtonMappingTimer.IsRunning() )
|
2010-04-12 01:56:05 +00:00
|
|
|
{
|
2014-09-01 17:44:16 +00:00
|
|
|
if (m_ButtonMappingTimer.IsRunning())
|
|
|
|
m_ButtonMappingTimer.Stop();
|
2010-04-12 01:56:05 +00:00
|
|
|
|
2013-04-08 05:16:50 +00:00
|
|
|
// Save the button Id
|
2010-04-12 01:56:05 +00:00
|
|
|
GetButtonWaitingID = _GetId;
|
|
|
|
GetButtonWaitingTimer = 0;
|
|
|
|
|
|
|
|
// Start the timer
|
2014-09-01 17:44:16 +00:00
|
|
|
m_ButtonMappingTimer.Start(1000 / TimesPerSecond);
|
2010-04-12 01:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process results
|
|
|
|
// Count each time
|
|
|
|
GetButtonWaitingTimer++;
|
|
|
|
|
|
|
|
// This is run every second
|
|
|
|
if (GetButtonWaitingTimer % TimesPerSecond == 0)
|
|
|
|
{
|
|
|
|
// Current time
|
|
|
|
int TmpTime = Seconds - (GetButtonWaitingTimer / TimesPerSecond);
|
|
|
|
// Update text
|
2014-05-17 17:17:28 +00:00
|
|
|
SetButtonText(_GetId, wxString::Format("[ %d ]", TmpTime));
|
2010-04-12 01:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Time's up
|
|
|
|
if (GetButtonWaitingTimer / TimesPerSecond >= Seconds)
|
|
|
|
{
|
|
|
|
// Revert back to old label
|
|
|
|
SetButtonText(_GetId, OldLabel);
|
|
|
|
EndGetButtons();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Input button clicked
|
|
|
|
void HotkeyConfigDialog::OnButtonClick(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
|
2014-09-01 17:44:16 +00:00
|
|
|
if (m_ButtonMappingTimer.IsRunning())
|
2013-04-08 05:16:50 +00:00
|
|
|
return;
|
2010-04-12 01:56:05 +00:00
|
|
|
|
2013-01-13 18:07:45 +00:00
|
|
|
wxTheApp->Bind(wxEVT_KEY_DOWN, &HotkeyConfigDialog::OnKeyDown, this);
|
2010-04-12 01:56:05 +00:00
|
|
|
|
|
|
|
// Get the button
|
|
|
|
ClickedButton = (wxButton *)event.GetEventObject();
|
2011-03-16 22:22:21 +00:00
|
|
|
SetEscapeId(wxID_CANCEL);
|
2010-04-12 01:56:05 +00:00
|
|
|
// Save old label so we can revert back
|
|
|
|
OldLabel = ClickedButton->GetLabel();
|
|
|
|
ClickedButton->SetWindowStyle(wxWANTS_CHARS);
|
2011-01-05 17:56:08 +00:00
|
|
|
ClickedButton->SetLabel(_("<Press Key>"));
|
2010-04-12 01:56:05 +00:00
|
|
|
DoGetButtons(ClickedButton->GetId());
|
|
|
|
}
|
|
|
|
|
2011-02-12 07:09:49 +00:00
|
|
|
#define HOTKEY_NUM_COLUMNS 2
|
|
|
|
|
2015-01-27 01:24:47 +00:00
|
|
|
const wxString hkText[] =
|
|
|
|
{
|
|
|
|
_("Open"),
|
|
|
|
_("Change Disc"),
|
|
|
|
_("Refresh List"),
|
|
|
|
|
|
|
|
_("Play/Pause"),
|
|
|
|
_("Stop"),
|
|
|
|
_("Reset"),
|
|
|
|
_("Frame Advance"),
|
|
|
|
|
|
|
|
_("Start Recording"),
|
|
|
|
_("Play Recording"),
|
|
|
|
_("Export Recording"),
|
|
|
|
_("Read-only mode"),
|
|
|
|
|
|
|
|
_("Toggle Fullscreen"),
|
|
|
|
_("Take Screenshot"),
|
|
|
|
_("Exit"),
|
|
|
|
|
|
|
|
_("Connect Wiimote 1"),
|
|
|
|
_("Connect Wiimote 2"),
|
|
|
|
_("Connect Wiimote 3"),
|
|
|
|
_("Connect Wiimote 4"),
|
|
|
|
_("Connect Balance Board"),
|
|
|
|
|
|
|
|
_("Volume Down"),
|
|
|
|
_("Volume Up"),
|
|
|
|
_("Volume Toggle Mute"),
|
|
|
|
|
|
|
|
_("Toggle IR"),
|
|
|
|
_("Toggle Aspect Ratio"),
|
|
|
|
_("Toggle EFB Copies"),
|
|
|
|
_("Toggle Fog"),
|
|
|
|
_("Toggle Frame limit"),
|
|
|
|
_("Decrease Frame limit"),
|
|
|
|
_("Increase Frame limit"),
|
|
|
|
|
|
|
|
_("Freelook Decrease Speed"),
|
|
|
|
_("Freelook Increase Speed"),
|
|
|
|
_("Freelook Reset Speed"),
|
|
|
|
_("Freelook Move Up"),
|
|
|
|
_("Freelook Move Down"),
|
|
|
|
_("Freelook Move Left"),
|
|
|
|
_("Freelook Move Right"),
|
|
|
|
_("Freelook Zoom In"),
|
|
|
|
_("Freelook Zoom Out"),
|
|
|
|
_("Freelook Reset"),
|
|
|
|
|
|
|
|
_("Decrease Depth"),
|
|
|
|
_("Increase Depth"),
|
|
|
|
_("Decrease Convergence"),
|
|
|
|
_("Increase Convergence"),
|
|
|
|
|
|
|
|
_("Load State Slot 1"),
|
|
|
|
_("Load State Slot 2"),
|
|
|
|
_("Load State Slot 3"),
|
|
|
|
_("Load State Slot 4"),
|
|
|
|
_("Load State Slot 5"),
|
|
|
|
_("Load State Slot 6"),
|
|
|
|
_("Load State Slot 7"),
|
|
|
|
_("Load State Slot 8"),
|
|
|
|
_("Load State Slot 9"),
|
|
|
|
_("Load State Slot 10"),
|
|
|
|
|
|
|
|
_("Save State Slot 1"),
|
|
|
|
_("Save State Slot 2"),
|
|
|
|
_("Save State Slot 3"),
|
|
|
|
_("Save State Slot 4"),
|
|
|
|
_("Save State Slot 5"),
|
|
|
|
_("Save State Slot 6"),
|
|
|
|
_("Save State Slot 7"),
|
|
|
|
_("Save State Slot 8"),
|
|
|
|
_("Save State Slot 9"),
|
|
|
|
_("Save State Slot 10"),
|
|
|
|
|
|
|
|
_("Select State Slot 1"),
|
|
|
|
_("Select State Slot 2"),
|
|
|
|
_("Select State Slot 3"),
|
|
|
|
_("Select State Slot 4"),
|
|
|
|
_("Select State Slot 5"),
|
|
|
|
_("Select State Slot 6"),
|
|
|
|
_("Select State Slot 7"),
|
|
|
|
_("Select State Slot 8"),
|
|
|
|
_("Select State Slot 9"),
|
|
|
|
_("Select State Slot 10"),
|
|
|
|
|
|
|
|
_("Save to selected slot"),
|
|
|
|
_("Load from selected slot"),
|
|
|
|
|
|
|
|
_("Load State Last 1"),
|
|
|
|
_("Load State Last 2"),
|
|
|
|
_("Load State Last 3"),
|
|
|
|
_("Load State Last 4"),
|
|
|
|
_("Load State Last 5"),
|
|
|
|
_("Load State Last 6"),
|
|
|
|
_("Load State Last 7"),
|
|
|
|
_("Load State Last 8"),
|
|
|
|
|
|
|
|
_("Save Oldest State"),
|
|
|
|
_("Undo Load State"),
|
|
|
|
_("Undo Save State"),
|
|
|
|
_("Save State"),
|
|
|
|
_("Load State"),
|
|
|
|
};
|
|
|
|
|
2014-08-30 16:41:21 +00:00
|
|
|
void HotkeyConfigDialog::CreateHotkeyGUIControls()
|
2010-04-12 01:56:05 +00:00
|
|
|
{
|
2011-02-16 02:19:40 +00:00
|
|
|
const wxString pageNames[] =
|
|
|
|
{
|
|
|
|
_("General"),
|
|
|
|
_("State Saves")
|
|
|
|
};
|
|
|
|
|
|
|
|
const int page_breaks[3] = {HK_OPEN, HK_LOAD_STATE_SLOT_1, NUM_HOTKEYS};
|
|
|
|
|
2010-04-12 01:56:05 +00:00
|
|
|
// Configuration controls sizes
|
|
|
|
wxSize size(100,20);
|
|
|
|
// A small type font
|
|
|
|
wxFont m_SmallFont(7, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
|
|
|
|
2014-03-06 04:02:34 +00:00
|
|
|
wxNotebook *Notebook = new wxNotebook(this, wxID_ANY);
|
2010-04-12 01:56:05 +00:00
|
|
|
|
2011-02-16 02:19:40 +00:00
|
|
|
for (int j = 0; j < 2; j++)
|
2011-02-12 07:09:49 +00:00
|
|
|
{
|
2014-12-02 03:56:18 +00:00
|
|
|
wxPanel *Page = new wxPanel(Notebook);
|
2011-02-16 02:19:40 +00:00
|
|
|
Notebook->AddPage(Page, pageNames[j]);
|
2010-04-12 01:56:05 +00:00
|
|
|
|
2011-02-16 02:19:40 +00:00
|
|
|
wxGridBagSizer *sHotkeys = new wxGridBagSizer();
|
2010-04-12 01:56:05 +00:00
|
|
|
|
2011-02-16 02:19:40 +00:00
|
|
|
// Header line
|
|
|
|
for (int i = 0; i < HOTKEY_NUM_COLUMNS; i++)
|
|
|
|
{
|
|
|
|
wxBoxSizer *HeaderSizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
wxStaticText *StaticTextHeader = new wxStaticText(Page, wxID_ANY, _("Action"));
|
|
|
|
HeaderSizer->Add(StaticTextHeader, 1, wxALL, 2);
|
|
|
|
StaticTextHeader = new wxStaticText(Page, wxID_ANY, _("Key"), wxDefaultPosition, size);
|
2013-10-29 05:23:17 +00:00
|
|
|
HeaderSizer->Add(StaticTextHeader, 0, wxALL, 2);
|
2011-03-05 16:36:47 +00:00
|
|
|
sHotkeys->Add(HeaderSizer, wxGBPosition(0, i), wxDefaultSpan, wxEXPAND | wxLEFT, (i > 0) ? 30 : 1);
|
2011-02-16 02:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int column_break = (page_breaks[j+1] + page_breaks[j] + 1) / 2;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2011-02-16 02:19:40 +00:00
|
|
|
for (int i = page_breaks[j]; i < page_breaks[j+1]; i++)
|
|
|
|
{
|
|
|
|
// Text for the action
|
|
|
|
wxStaticText *stHotkeys = new wxStaticText(Page, wxID_ANY, hkText[i]);
|
|
|
|
|
|
|
|
// Key selection button
|
2014-03-06 04:02:34 +00:00
|
|
|
m_Button_Hotkeys[i] = new wxButton(Page, i, wxEmptyString, wxDefaultPosition, size);
|
2011-02-16 02:19:40 +00:00
|
|
|
m_Button_Hotkeys[i]->SetFont(m_SmallFont);
|
|
|
|
m_Button_Hotkeys[i]->SetToolTip(_("Left click to detect hotkeys.\nEnter space to clear."));
|
|
|
|
SetButtonText(i,
|
2014-10-05 09:31:45 +00:00
|
|
|
WxUtils::WXKeyToString(SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkey[i]),
|
|
|
|
WxUtils::WXKeymodToString(
|
2011-02-16 02:19:40 +00:00
|
|
|
SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkeyModifier[i]));
|
|
|
|
|
|
|
|
wxBoxSizer *sHotkey = new wxBoxSizer(wxHORIZONTAL);
|
2011-02-18 12:34:24 +00:00
|
|
|
sHotkey->Add(stHotkeys, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 2);
|
2011-02-16 02:19:40 +00:00
|
|
|
sHotkey->Add(m_Button_Hotkeys[i], 0, wxALL, 2);
|
|
|
|
sHotkeys->Add(sHotkey,
|
|
|
|
wxGBPosition((i < column_break) ? i - page_breaks[j] + 1 : i - column_break + 1,
|
|
|
|
(i < column_break) ? 0 : 1),
|
2011-03-05 16:36:47 +00:00
|
|
|
wxDefaultSpan, wxEXPAND | wxLEFT, (i < column_break) ? 1 : 30);
|
2011-02-16 02:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxStaticBoxSizer *sHotkeyBox = new wxStaticBoxSizer(wxVERTICAL, Page, _("Hotkeys"));
|
|
|
|
sHotkeyBox->Add(sHotkeys);
|
|
|
|
|
|
|
|
wxBoxSizer* const sPage = new wxBoxSizer(wxVERTICAL);
|
|
|
|
sPage->Add(sHotkeyBox, 0, wxEXPAND | wxALL, 5);
|
|
|
|
Page->SetSizer(sPage);
|
|
|
|
}
|
2011-02-12 07:09:49 +00:00
|
|
|
|
2010-04-12 01:56:05 +00:00
|
|
|
wxBoxSizer *sMainSizer = new wxBoxSizer(wxVERTICAL);
|
2011-02-16 02:19:40 +00:00
|
|
|
sMainSizer->Add(Notebook, 0, wxEXPAND | wxALL, 5);
|
2011-03-16 22:22:21 +00:00
|
|
|
sMainSizer->Add(CreateButtonSizer(wxOK), 0, wxEXPAND | wxLEFT | wxRIGHT | wxDOWN, 5);
|
2011-03-16 12:59:05 +00:00
|
|
|
SetSizerAndFit(sMainSizer);
|
|
|
|
SetFocus();
|
2010-04-12 01:56:05 +00:00
|
|
|
}
|
|
|
|
|