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
|
|
|
|
2011-02-16 02:19:40 +00:00
|
|
|
#include <wx/notebook.h>
|
|
|
|
|
2010-04-12 01:56:05 +00:00
|
|
|
#include "HotkeyDlg.h"
|
|
|
|
#include "ConfigManager.h"
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(HotkeyConfigDialog,wxDialog)
|
2011-02-12 06:46:33 +00:00
|
|
|
EVT_COMMAND_RANGE(0, NUM_HOTKEYS - 1,
|
2013-04-08 05:16:50 +00:00
|
|
|
wxEVT_COMMAND_BUTTON_CLICKED, 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;
|
|
|
|
ClickedButton = NULL;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HotkeyConfigDialog::EndGetButtons(void)
|
|
|
|
{
|
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;
|
|
|
|
ClickedButton = NULL;
|
2011-03-16 22:22:21 +00:00
|
|
|
SetEscapeId(wxID_ANY);
|
2010-04-12 01:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HotkeyConfigDialog::OnKeyDown(wxKeyEvent& event)
|
|
|
|
{
|
|
|
|
if(ClickedButton != NULL)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
{
|
|
|
|
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
|
|
|
|
if( GetButtonWaitingID != _GetId || !m_ButtonMappingTimer->IsRunning() )
|
|
|
|
{
|
|
|
|
if(m_ButtonMappingTimer->IsRunning())
|
|
|
|
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
|
|
|
|
SetButtonText(_GetId, wxString::Format(wxT("[ %d ]"), TmpTime));
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2010-04-12 01:56:05 +00:00
|
|
|
void HotkeyConfigDialog::CreateHotkeyGUIControls(void)
|
|
|
|
{
|
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"),
|
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"),
|
|
|
|
|
|
|
|
_("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"),
|
|
|
|
|
|
|
|
_("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);
|
|
|
|
|
2011-02-16 02:19:40 +00:00
|
|
|
wxNotebook *Notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
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
|
|
|
{
|
2011-02-16 02:19:40 +00:00
|
|
|
wxPanel *Page = new wxPanel(Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
|
|
|
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);
|
2011-03-05 16:36:47 +00:00
|
|
|
HeaderSizer->Add(StaticTextHeader, 0, wxALL, 2);
|
|
|
|
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;
|
2011-03-05 16:36:47 +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
|
|
|
|
m_Button_Hotkeys[i] = new wxButton(Page, i, wxEmptyString,
|
|
|
|
wxDefaultPosition, size);
|
|
|
|
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
|
|
|
}
|
|
|
|
|