Added files I forgot in last commit.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5337 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice 2010-04-12 01:56:05 +00:00
parent 33a64d5db0
commit 3861f56d51
4 changed files with 489 additions and 0 deletions

View File

@ -0,0 +1,244 @@
// 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/
#include "HotkeyDlg.h"
#include "ConfigManager.h"
BEGIN_EVENT_TABLE(HotkeyConfigDialog,wxDialog)
EVT_CLOSE(HotkeyConfigDialog::OnClose)
EVT_BUTTON(ID_CLOSE, HotkeyConfigDialog::CloseClick)
EVT_BUTTON(ID_FULLSCREEN, HotkeyConfigDialog::OnButtonClick)
EVT_BUTTON(ID_PLAY_PAUSE, HotkeyConfigDialog::OnButtonClick)
EVT_BUTTON(ID_STOP, HotkeyConfigDialog::OnButtonClick)
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
if (g_Pressed == WXK_CONTROL || g_Pressed == WXK_ALT || g_Pressed == WXK_SHIFT)
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)
{
m_Button_Hotkeys[id]->SetLabel(modkeystr + (modkeystr.Len() ? _T("+") : _T("")) + keystr);
}
void HotkeyConfigDialog::DoGetButtons(int _GetId)
{
// Values used in this function
int Seconds = 4; // Seconds to wait for
int TimesPerSecond = 40; // How often to run the check
// 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);
ClickedButton->SetLabel(wxT("<Press Key>"));
DoGetButtons(ClickedButton->GetId());
}
void HotkeyConfigDialog::CreateHotkeyGUIControls(void)
{
static const wxChar* hkText[] =
{
wxT("Toggle Fullscreen"),
wxT("Play/Pause"),
wxT("Stop"),
};
// Configuration controls sizes
wxSize size(100,20);
// A small type font
wxFont m_SmallFont(7, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
wxStaticBoxSizer *sHotkeys = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Hotkeys"));
// Header line
wxBoxSizer *HeaderSizer = new wxBoxSizer(wxHORIZONTAL);
wxStaticText *StaticTextHeader = new wxStaticText(this, wxID_ANY, wxT("Action"));
HeaderSizer->Add(StaticTextHeader, 1, wxALL, 2);
HeaderSizer->AddStretchSpacer();
StaticTextHeader = new wxStaticText(this, wxID_ANY, wxT("Key"), wxDefaultPosition, size);
HeaderSizer->Add(StaticTextHeader, 0, wxALL, 2);
sHotkeys->Add(HeaderSizer, 0, wxEXPAND | wxALL, 1);
for (int i = 0; i < NUM_HOTKEYS; i++)
{
// Text for the action
wxStaticText *stHotkeys = new wxStaticText(this, wxID_ANY, hkText[i]);
// Key selection button
m_Button_Hotkeys[i] = new wxButton(this, ID_FULLSCREEN + i, wxEmptyString,
wxDefaultPosition, size);
m_Button_Hotkeys[i]->SetFont(m_SmallFont);
SetButtonText(i,
InputCommon::WXKeyToString(SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkey[i]),
InputCommon::WXKeymodToString(SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkeyModifier[i]));
wxBoxSizer *sHotkey = new wxBoxSizer(wxHORIZONTAL);
sHotkey->Add(stHotkeys, 1, wxALIGN_LEFT | wxALL, 2);
sHotkey->AddStretchSpacer();
sHotkey->Add(m_Button_Hotkeys[i], 0, wxALL, 2);
sHotkeys->Add(sHotkey, 0, wxEXPAND | wxALL, 1);
}
m_Close = new wxButton(this, ID_CLOSE, wxT("Close"));
wxBoxSizer* sButtons = new wxBoxSizer(wxHORIZONTAL);
sButtons->AddStretchSpacer();
sButtons->Add(m_Close, 0, (wxLEFT), 5);
wxBoxSizer *sMainSizer = new wxBoxSizer(wxVERTICAL);
sMainSizer->Add(sHotkeys, 0, wxEXPAND | wxALL, 5);
sMainSizer->Add(sButtons, 0, wxEXPAND | (wxLEFT | wxRIGHT | wxDOWN), 5);
SetSizer(sMainSizer);
Layout();
Fit();
}

View File

@ -0,0 +1,90 @@
// 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/
#ifndef __HOTKEYDIALOG_h__
#define __HOTKEYDIALOG_h__
#include <wx/wx.h>
#include <wx/textctrl.h>
#include <wx/button.h>
#include <wx/stattext.h>
#include <wx/combobox.h>
#include <wx/checkbox.h>
#include <wx/gbsizer.h>
#ifndef _WIN32
#include "Config.h"
#endif
#include "WXInputBase.h"
#if defined(HAVE_X11) && HAVE_X11
#include "X11InputBase.h"
#include <X11/Xlib.h>
#include <X11/keysym.h>
#endif
class HotkeyConfigDialog : public wxDialog
{
public:
HotkeyConfigDialog(wxWindow *parent,
wxWindowID id = 1,
const wxString &title = wxT("Hotkey Configuration"),
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE | wxWANTS_CHARS);
virtual ~HotkeyConfigDialog();
wxTimer *m_ButtonMappingTimer;
private:
DECLARE_EVENT_TABLE();
enum
{
ID_FULLSCREEN,
ID_PLAY_PAUSE,
ID_STOP,
NUM_HOTKEYS,
ID_CLOSE = 1000,
IDTM_BUTTON, // Timer
ID_APPLY
};
wxString OldLabel;
wxButton *m_Close, *m_Apply, *ClickedButton,
*m_Button_Hotkeys[NUM_HOTKEYS];
wxRadioButton *m_Radio_FSPause[5];
void OnClose(wxCloseEvent& event);
void CloseClick(wxCommandEvent& event);
void OnButtonTimer(wxTimerEvent& WXUNUSED(event)) { DoGetButtons(GetButtonWaitingID); }
void OnButtonClick(wxCommandEvent& event);
void OnKeyDown(wxKeyEvent& event);
void SaveButtonMapping(int Id, int Key, int Modkey);
void CreateHotkeyGUIControls(void);
void SetButtonText(int id, const wxString &keystr, const wxString &modkeystr = wxString());
wxString GetButtonText(int id);
void DoGetButtons(int id);
void EndGetButtons(void);
int GetButtonWaitingID, GetButtonWaitingTimer, g_Pressed, g_Modkey;
};
#endif

View File

@ -0,0 +1,127 @@
// 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/
#include <wx/stattext.h>
#include "WXInputBase.h"
//#include <string.h>
//#include <stdio.h>
//#include <ctype.h>
namespace InputCommon
{
const wxChar *WXKeyToString(int keycode)
{
switch (keycode)
{
case WXK_CANCEL: return wxT("Cancel"); break;
case WXK_BACK: return wxT("Back"); break;
case WXK_TAB: return wxT("Tab"); break;
case WXK_CLEAR: return wxT("Clear"); break;
case WXK_RETURN: return wxT("Return"); break;
case WXK_SHIFT: return wxT("Shift"); break;
case WXK_CONTROL: return wxT("Control"); break;
case WXK_ALT: return wxT("Alt"); break;
case WXK_CAPITAL: return wxT("CapsLock"); break;
case WXK_MENU : return wxT("Menu"); break;
case WXK_PAUSE: return wxT("Pause"); break;
case WXK_ESCAPE: return wxT("Escape"); break;
case WXK_SPACE: return wxT("Space"); break;
case WXK_PAGEUP: return wxT("PgUp"); break;
case WXK_PAGEDOWN: return wxT("PgDn"); break;
case WXK_END: return wxT("End"); break;
case WXK_HOME : return wxT("Home"); break;
case WXK_LEFT : return wxT("Left"); break;
case WXK_UP: return wxT("Up"); break;
case WXK_RIGHT: return wxT("Right"); break;
case WXK_DOWN : return wxT("Down"); break;
case WXK_SELECT: return wxT("Select"); break;
case WXK_PRINT: return wxT("Print"); break;
case WXK_EXECUTE: return wxT("Execute"); break;
case WXK_INSERT: return wxT("Insert"); break;
case WXK_DELETE: return wxT("Delete"); break;
case WXK_HELP : return wxT("Help"); break;
case WXK_NUMPAD0: return wxT("NP 0"); break;
case WXK_NUMPAD1: return wxT("NP 1"); break;
case WXK_NUMPAD2: return wxT("NP 2"); break;
case WXK_NUMPAD3: return wxT("NP 3"); break;
case WXK_NUMPAD4: return wxT("NP 4"); break;
case WXK_NUMPAD5: return wxT("NP 5"); break;
case WXK_NUMPAD6: return wxT("NP 6"); break;
case WXK_NUMPAD7: return wxT("NP 7"); break;
case WXK_NUMPAD8: return wxT("NP 8"); break;
case WXK_NUMPAD9: return wxT("NP 9"); break;
case WXK_NUMPAD_DECIMAL: return wxT("NP ."); break;
case WXK_NUMPAD_DELETE: return wxT("NP Delete"); break;
case WXK_NUMPAD_INSERT: return wxT("NP Insert"); break;
case WXK_NUMPAD_END: return wxT("NP End"); break;
case WXK_NUMPAD_DOWN: return wxT("NP Down"); break;
case WXK_NUMPAD_PAGEDOWN: return wxT("NP Pagedown"); break;
case WXK_NUMPAD_LEFT: return wxT("NP Left"); break;
case WXK_NUMPAD_RIGHT: return wxT("NP Right"); break;
case WXK_NUMPAD_HOME: return wxT("NP Home"); break;
case WXK_NUMPAD_UP: return wxT("NP Up"); break;
case WXK_NUMPAD_PAGEUP: return wxT("NP Pageup"); break;
case WXK_NUMPAD_MULTIPLY: return wxT("NP *"); break;
case WXK_NUMPAD_ADD: return wxT("NP +"); break;
case WXK_NUMPAD_SUBTRACT: return wxT("NP -"); break;
case WXK_NUMPAD_DIVIDE: return wxT("NP /"); break;
case WXK_NUMPAD_ENTER: return wxT("NP Enter"); break;
case WXK_NUMPAD_SEPARATOR: return wxT("NP Separator"); break;
case WXK_F1: return wxT("F1"); break;
case WXK_F2: return wxT("F2"); break;
case WXK_F3: return wxT("F3"); break;
case WXK_F4: return wxT("F4"); break;
case WXK_F5: return wxT("F5"); break;
case WXK_F6: return wxT("F6"); break;
case WXK_F7: return wxT("F7"); break;
case WXK_F8: return wxT("F8"); break;
case WXK_F9: return wxT("F9"); break;
case WXK_F10: return wxT("F10"); break;
case WXK_F11: return wxT("F11"); break;
case WXK_F12: return wxT("F12"); break;
case WXK_F13: return wxT("F13"); break;
case WXK_F14: return wxT("F14"); break;
case WXK_F15: return wxT("F15"); break;
case WXK_F16: return wxT("F16"); break;
case WXK_F17: return wxT("F17"); break;
case WXK_F18: return wxT("F19"); break;
case WXK_F19: return wxT("F20"); break;
case WXK_F20: return wxT("F21"); break;
case WXK_F21: return wxT("F22"); break;
case WXK_F22: return wxT("F23"); break;
case WXK_F23: return wxT("F24"); break;
case WXK_F24: return wxT("F25"); break;
case WXK_NUMLOCK: return wxT("Numlock"); break;
case WXK_SCROLL: return wxT("Scrolllock"); break;
default: return wxString::FromAscii(keycode);
}
}
const wxChar *WXKeymodToString(int modifier)
{
switch (modifier)
{
case wxMOD_ALT: return wxT("Alt"); break;
case wxMOD_CMD: return wxT("Ctrl"); break;
case wxMOD_ALTGR: return wxT("Ctrl+Alt"); break;
case wxMOD_SHIFT: return wxT("Shift"); break;
default: return wxT(""); break;
}
}
}

View File

@ -0,0 +1,28 @@
// 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/
#ifndef WXINPUTBASE_H
#define WXINPUTBASE_H
#include <wx/wx.h>
namespace InputCommon
{
const wxChar *WXKeyToString(int keycode);
const wxChar *WXKeymodToString(int modifier);
}
#endif