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"
|
|
|
|
|
|
|
|
class wxWindow;
|
2010-04-12 01:56:05 +00:00
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(HotkeyConfigDialog,wxDialog)
|
2014-05-17 16:49:00 +00:00
|
|
|
EVT_COMMAND_RANGE(0, NUM_HOTKEYS - 1, wxEVT_BUTTON, HotkeyConfigDialog::OnButtonClick)
|
2011-03-15 13:38:52 +00:00
|
|
|
EVT_TIMER(wxID_ANY, HotkeyConfigDialog::OnButtonTimer)
|
2010-04-12 01:56:05 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
HotkeyConfigDialog::HotkeyConfigDialog(wxWindow *parent, wxWindowID id, const wxString &title,
|
|
|
|
const wxPoint &position, const wxSize& size, long style)
|
|
|
|
: wxDialog(parent, id, title, position, size, style)
|
|
|
|
{
|
|
|
|
CreateHotkeyGUIControls();
|
|
|
|
|
|
|
|
#if wxUSE_TIMER
|
2011-03-15 13:38:52 +00:00
|
|
|
m_ButtonMappingTimer = new wxTimer(this, wxID_ANY);
|
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;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
HotkeyConfigDialog::~HotkeyConfigDialog()
|
|
|
|
{
|
2011-03-15 13:38:52 +00:00
|
|
|
delete m_ButtonMappingTimer;
|
2010-04-12 01:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
2010-04-12 01:56:05 +00:00
|
|
|
m_ButtonMappingTimer->Stop();
|
|
|
|
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();
|
|
|
|
|
|
|
|
wxString tentativeModKey = InputCommon::WXKeymodToString(g_Modkey);
|
|
|
|
wxString tentativePressedKey = InputCommon::WXKeyToString(g_Pressed);
|
|
|
|
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(),
|
2013-04-08 05:16:50 +00:00
|
|
|
InputCommon::WXKeyToString(g_Pressed),
|
|
|
|
InputCommon::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-03-10 11:30:55 +00:00
|
|
|
if ( GetButtonWaitingID != _GetId || !m_ButtonMappingTimer->IsRunning() )
|
2010-04-12 01:56:05 +00:00
|
|
|
{
|
2014-03-10 11:30:55 +00:00
|
|
|
if (m_ButtonMappingTimer->IsRunning())
|
2010-04-12 01:56:05 +00:00
|
|
|
m_ButtonMappingTimer->Stop();
|
|
|
|
|
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
|
|
|
|
#if wxUSE_TIMER
|
|
|
|
m_ButtonMappingTimer->Start(1000 / TimesPerSecond);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2013-04-08 05:16:50 +00:00
|
|
|
if (m_ButtonMappingTimer->IsRunning())
|
|
|
|
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
|
|
|
|
|
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 wxString hkText[] =
|
2010-04-12 01:56:05 +00:00
|
|
|
{
|
2011-02-12 06:46:33 +00:00
|
|
|
_("Open"),
|
|
|
|
_("Change Disc"),
|
|
|
|
_("Refresh List"),
|
|
|
|
|
2011-01-05 04:35:46 +00:00
|
|
|
_("Play/Pause"),
|
|
|
|
_("Stop"),
|
2011-02-12 06:46:33 +00:00
|
|
|
_("Reset"),
|
|
|
|
_("Frame Advance"),
|
|
|
|
|
|
|
|
_("Start Recording"),
|
|
|
|
_("Play Recording"),
|
|
|
|
_("Export Recording"),
|
|
|
|
_("Read-only mode"),
|
|
|
|
|
|
|
|
_("Toggle Fullscreen"),
|
2011-01-05 04:35:46 +00:00
|
|
|
_("Take Screenshot"),
|
2012-11-08 07:40:49 +00:00
|
|
|
_("Exit"),
|
2011-02-12 06:46:33 +00:00
|
|
|
|
2011-01-05 04:35:46 +00:00
|
|
|
_("Connect Wiimote 1"),
|
|
|
|
_("Connect Wiimote 2"),
|
|
|
|
_("Connect Wiimote 3"),
|
2011-02-12 06:46:33 +00:00
|
|
|
_("Connect Wiimote 4"),
|
2013-06-26 10:23:29 +00:00
|
|
|
_("Connect Balance Board"),
|
2013-07-30 23:25:12 +00:00
|
|
|
|
2013-07-30 09:49:02 +00:00
|
|
|
_("Toggle IR"),
|
|
|
|
_("Toggle Aspect Ratio"),
|
|
|
|
_("Toggle EFB Copies"),
|
|
|
|
_("Toggle Fog"),
|
2014-02-16 22:13:01 +00:00
|
|
|
_("Toggle Frame limit"),
|
2013-07-30 23:25:12 +00:00
|
|
|
_("Increase Frame limit"),
|
|
|
|
_("Decrease Frame limit"),
|
2011-02-12 06:46:33 +00:00
|
|
|
|
|
|
|
_("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"),
|
2013-08-03 00:42:30 +00:00
|
|
|
_("Load State Slot 9"),
|
|
|
|
_("Load State Slot 10"),
|
2011-02-12 06:46:33 +00:00
|
|
|
|
|
|
|
_("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"),
|
2012-11-08 07:40:49 +00:00
|
|
|
_("Save State Slot 8"),
|
2013-08-03 00:42:30 +00:00
|
|
|
_("Save State Slot 9"),
|
|
|
|
_("Save State Slot 10"),
|
2012-11-08 07:40:49 +00:00
|
|
|
|
|
|
|
_("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"),
|
2013-06-30 23:01:30 +00:00
|
|
|
_("Undo Save State"),
|
|
|
|
_("Save State"),
|
|
|
|
_("Load State"),
|
2010-04-12 01:56:05 +00:00
|
|
|
};
|
|
|
|
|
2011-02-16 02:19:40 +00:00
|
|
|
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-03-06 04:02:34 +00:00
|
|
|
wxPanel *Page = new wxPanel(Notebook, wxID_ANY);
|
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,
|
|
|
|
InputCommon::WXKeyToString(SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkey[i]),
|
|
|
|
InputCommon::WXKeymodToString(
|
|
|
|
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
|
|
|
}
|
|
|
|
|