2010-04-11 19:56:05 -06:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2011-02-15 19:19:40 -07:00
|
|
|
#include <wx/notebook.h>
|
|
|
|
|
2010-04-11 19:56:05 -06:00
|
|
|
#include "HotkeyDlg.h"
|
|
|
|
#include "ConfigManager.h"
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(HotkeyConfigDialog,wxDialog)
|
|
|
|
EVT_CLOSE(HotkeyConfigDialog::OnClose)
|
|
|
|
EVT_BUTTON(ID_CLOSE, HotkeyConfigDialog::CloseClick)
|
2011-02-11 23:46:33 -07:00
|
|
|
EVT_COMMAND_RANGE(0, NUM_HOTKEYS - 1,
|
2010-04-25 14:10:16 -06:00
|
|
|
wxEVT_COMMAND_BUTTON_CLICKED, HotkeyConfigDialog::OnButtonClick)
|
2010-04-11 19:56:05 -06:00
|
|
|
EVT_TIMER(IDTM_BUTTON, HotkeyConfigDialog::OnButtonTimer)
|
|
|
|
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
|
|
|
|
m_ButtonMappingTimer = new wxTimer(this, IDTM_BUTTON);
|
|
|
|
g_Pressed = 0;
|
|
|
|
g_Modkey = 0;
|
|
|
|
ClickedButton = NULL;
|
|
|
|
GetButtonWaitingID = 0;
|
|
|
|
GetButtonWaitingTimer = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
HotkeyConfigDialog::~HotkeyConfigDialog()
|
|
|
|
{
|
|
|
|
if (m_ButtonMappingTimer)
|
|
|
|
delete m_ButtonMappingTimer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HotkeyConfigDialog::OnClose(wxCloseEvent& WXUNUSED (event))
|
|
|
|
{
|
|
|
|
if (m_ButtonMappingTimer)
|
|
|
|
m_ButtonMappingTimer->Stop();
|
|
|
|
|
|
|
|
EndModal(wxID_CLOSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HotkeyConfigDialog::CloseClick(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
switch(event.GetId())
|
|
|
|
{
|
|
|
|
case ID_CLOSE:
|
|
|
|
Close();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
wxTheApp->Disconnect(wxID_ANY, wxEVT_KEY_DOWN, // Keyboard
|
|
|
|
wxKeyEventHandler(HotkeyConfigDialog::OnKeyDown),
|
|
|
|
(wxObject*)0, this);
|
|
|
|
m_ButtonMappingTimer->Stop();
|
|
|
|
GetButtonWaitingTimer = 0;
|
|
|
|
GetButtonWaitingID = 0;
|
|
|
|
ClickedButton = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 14:03:37 -06:00
|
|
|
if (g_Pressed == WXK_CONTROL || g_Pressed == WXK_ALT ||
|
|
|
|
g_Pressed == WXK_SHIFT || g_Pressed == WXK_COMMAND)
|
2010-04-11 19:56:05 -06: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(),
|
|
|
|
InputCommon::WXKeyToString(g_Pressed),
|
|
|
|
InputCommon::WXKeymodToString(g_Modkey));
|
|
|
|
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 07:20:20 -07:00
|
|
|
m_Button_Hotkeys[id]->SetLabel(modkeystr + keystr);
|
2010-04-11 19:56:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void HotkeyConfigDialog::DoGetButtons(int _GetId)
|
|
|
|
{
|
|
|
|
// Values used in this function
|
2010-07-29 07:29:15 -06:00
|
|
|
const int Seconds = 4; // Seconds to wait for
|
|
|
|
const int TimesPerSecond = 40; // How often to run the check
|
2010-04-11 19:56:05 -06: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();
|
|
|
|
|
|
|
|
// Save the button Id
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (m_ButtonMappingTimer->IsRunning()) return;
|
|
|
|
|
|
|
|
wxTheApp->Connect(wxID_ANY, wxEVT_KEY_DOWN, // Keyboard
|
|
|
|
wxKeyEventHandler(HotkeyConfigDialog::OnKeyDown),
|
|
|
|
(wxObject*)0, this);
|
|
|
|
|
|
|
|
// Get the button
|
|
|
|
ClickedButton = (wxButton *)event.GetEventObject();
|
|
|
|
// Save old label so we can revert back
|
|
|
|
OldLabel = ClickedButton->GetLabel();
|
|
|
|
ClickedButton->SetWindowStyle(wxWANTS_CHARS);
|
2011-01-05 10:56:08 -07:00
|
|
|
ClickedButton->SetLabel(_("<Press Key>"));
|
2010-04-11 19:56:05 -06:00
|
|
|
DoGetButtons(ClickedButton->GetId());
|
|
|
|
}
|
|
|
|
|
2011-02-12 00:09:49 -07:00
|
|
|
#define HOTKEY_NUM_COLUMNS 2
|
|
|
|
|
2010-04-11 19:56:05 -06:00
|
|
|
void HotkeyConfigDialog::CreateHotkeyGUIControls(void)
|
|
|
|
{
|
2011-02-15 19:19:40 -07:00
|
|
|
const wxString pageNames[] =
|
|
|
|
{
|
|
|
|
_("General"),
|
|
|
|
_("State Saves")
|
|
|
|
};
|
|
|
|
|
|
|
|
const wxString hkText[] =
|
2010-04-11 19:56:05 -06:00
|
|
|
{
|
2011-02-11 23:46:33 -07:00
|
|
|
_("Open"),
|
|
|
|
_("Change Disc"),
|
|
|
|
_("Refresh List"),
|
|
|
|
|
2011-01-04 21:35:46 -07:00
|
|
|
_("Play/Pause"),
|
|
|
|
_("Stop"),
|
2011-02-11 23:46:33 -07:00
|
|
|
_("Reset"),
|
|
|
|
_("Frame Advance"),
|
|
|
|
|
|
|
|
_("Start Recording"),
|
|
|
|
_("Play Recording"),
|
|
|
|
_("Export Recording"),
|
|
|
|
_("Read-only mode"),
|
|
|
|
|
|
|
|
_("Toggle Fullscreen"),
|
2011-01-04 21:35:46 -07:00
|
|
|
_("Take Screenshot"),
|
2011-02-11 23:46:33 -07:00
|
|
|
|
2011-01-04 21:35:46 -07:00
|
|
|
_("Connect Wiimote 1"),
|
|
|
|
_("Connect Wiimote 2"),
|
|
|
|
_("Connect Wiimote 3"),
|
2011-02-11 23:46:33 -07:00
|
|
|
_("Connect Wiimote 4"),
|
|
|
|
|
|
|
|
_("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"),
|
|
|
|
_("Save State Slot 8")
|
2010-04-11 19:56:05 -06:00
|
|
|
};
|
|
|
|
|
2011-02-15 19:19:40 -07:00
|
|
|
const int page_breaks[3] = {HK_OPEN, HK_LOAD_STATE_SLOT_1, NUM_HOTKEYS};
|
|
|
|
|
2010-04-11 19:56:05 -06:00
|
|
|
// Configuration controls sizes
|
|
|
|
wxSize size(100,20);
|
|
|
|
// A small type font
|
|
|
|
wxFont m_SmallFont(7, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
|
|
|
|
2011-02-15 19:19:40 -07:00
|
|
|
wxNotebook *Notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
2010-04-11 19:56:05 -06:00
|
|
|
|
2011-02-15 19:19:40 -07:00
|
|
|
for (int j = 0; j < 2; j++)
|
2011-02-12 00:09:49 -07:00
|
|
|
{
|
2011-02-15 19:19:40 -07:00
|
|
|
wxPanel *Page = new wxPanel(Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
|
|
|
Notebook->AddPage(Page, pageNames[j]);
|
2010-04-11 19:56:05 -06:00
|
|
|
|
2011-02-15 19:19:40 -07:00
|
|
|
wxGridBagSizer *sHotkeys = new wxGridBagSizer();
|
2010-04-11 19:56:05 -06:00
|
|
|
|
2011-02-15 19:19:40 -07: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);
|
|
|
|
HeaderSizer->AddStretchSpacer();
|
|
|
|
StaticTextHeader = new wxStaticText(Page, wxID_ANY, _("Key"), wxDefaultPosition, size);
|
|
|
|
HeaderSizer->Add(StaticTextHeader, 0, wxALL, 2);
|
|
|
|
sHotkeys->Add(HeaderSizer, wxGBPosition(0, i), wxDefaultSpan, wxEXPAND | wxALL, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int column_break = (page_breaks[j+1] + page_breaks[j] + 1) / 2;
|
|
|
|
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 05:34:24 -07:00
|
|
|
sHotkey->Add(stHotkeys, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 2);
|
2011-02-15 19:19:40 -07:00
|
|
|
sHotkey->AddStretchSpacer();
|
|
|
|
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),
|
|
|
|
wxDefaultSpan, wxEXPAND | wxALL, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 00:09:49 -07:00
|
|
|
|
2011-01-04 21:35:46 -07:00
|
|
|
m_Close = new wxButton(this, ID_CLOSE, _("Close"));
|
2010-04-11 19:56:05 -06:00
|
|
|
wxBoxSizer* sButtons = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sButtons->AddStretchSpacer();
|
|
|
|
sButtons->Add(m_Close, 0, (wxLEFT), 5);
|
|
|
|
|
|
|
|
wxBoxSizer *sMainSizer = new wxBoxSizer(wxVERTICAL);
|
2011-02-15 19:19:40 -07:00
|
|
|
sMainSizer->Add(Notebook, 0, wxEXPAND | wxALL, 5);
|
2010-04-11 19:56:05 -06:00
|
|
|
sMainSizer->Add(sButtons, 0, wxEXPAND | (wxLEFT | wxRIGHT | wxDOWN), 5);
|
|
|
|
SetSizer(sMainSizer);
|
|
|
|
Layout();
|
|
|
|
Fit();
|
|
|
|
}
|
|
|
|
|