Merge pull request #1949 from skidau/hotkey-input

Added the ability to map gamepad buttons to hotkeys.
This commit is contained in:
skidau
2015-02-04 14:35:03 +11:00
14 changed files with 1048 additions and 308 deletions
+1
View File
@@ -9,6 +9,7 @@ set(SRCS ActionReplay.cpp
ec_wii.cpp
GeckoCodeConfig.cpp
GeckoCode.cpp
HotkeyManager.cpp
MemTools.cpp
Movie.cpp
NetPlayClient.cpp
+2
View File
@@ -94,6 +94,7 @@
<ClCompile Include="HLE\HLE.cpp" />
<ClCompile Include="HLE\HLE_Misc.cpp" />
<ClCompile Include="HLE\HLE_OS.cpp" />
<ClCompile Include="HotkeyManager.cpp" />
<ClCompile Include="HW\AudioInterface.cpp" />
<ClCompile Include="HW\BBA-TAP\TAP_Win32.cpp" />
<ClCompile Include="HW\CPU.cpp" />
@@ -306,6 +307,7 @@
<ClInclude Include="HLE\HLE_Misc.h" />
<ClInclude Include="HLE\HLE_OS.h" />
<ClInclude Include="Host.h" />
<ClInclude Include="HotkeyManager.h" />
<ClInclude Include="HW\AudioInterface.h" />
<ClInclude Include="HW\BBA-TAP\TAP_Win32.h" />
<ClInclude Include="HW\CPU.h" />
+2
View File
@@ -144,6 +144,7 @@
<ClCompile Include="CoreParameter.cpp" />
<ClCompile Include="CoreTiming.cpp" />
<ClCompile Include="ec_wii.cpp" />
<ClCompile Include="HotkeyManager.cpp" />
<ClCompile Include="MemTools.cpp" />
<ClCompile Include="Movie.cpp" />
<ClCompile Include="NetPlayClient.cpp" />
@@ -735,6 +736,7 @@
<ClInclude Include="CoreTiming.h" />
<ClInclude Include="ec_wii.h" />
<ClInclude Include="Host.h" />
<ClInclude Include="HotkeyManager.h" />
<ClInclude Include="MemTools.h" />
<ClInclude Include="Movie.h" />
<ClInclude Include="NetPlayClient.h" />
File diff suppressed because it is too large Load Diff
+41
View File
@@ -0,0 +1,41 @@
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#pragma once
#include "Core/CoreParameter.h"
#include "InputCommon/InputConfig.h"
struct HotkeyStatus
{
u32 button[6];
s8 err;
};
class HotkeyManager : public ControllerEmu
{
public:
HotkeyManager();
~HotkeyManager();
std::string GetName() const;
void GetInput(HotkeyStatus* const hk);
void LoadDefaults(const ControllerInterface& ciface);
private:
Buttons* m_keys[6];
ControlGroup* m_options;
};
namespace HotkeyManagerEmu
{
void Initialize(void* const hwnd);
void Shutdown();
InputConfig* GetConfig();
void GetStatus(u8 _port, HotkeyStatus* _pKeyboardStatus);
bool IsPressed(int Id, bool held);
static u32 hotkeyDown[6];
}
+32 -2
View File
@@ -32,6 +32,7 @@
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HotkeyManager.h"
#include "Core/Movie.h"
#include "Core/NetPlayProto.h"
#include "Core/HW/EXI.h"
@@ -47,10 +48,13 @@
#include "DolphinWX/Frame.h"
#include "DolphinWX/Globals.h"
#include "DolphinWX/HotkeyDlg.h"
#include "DolphinWX/InputConfigDiag.h"
#include "DolphinWX/Main.h"
#include "DolphinWX/WxUtils.h"
#include "DolphinWX/Debugger/CodeWindow.h"
#include "InputCommon/InputConfig.h"
#include "VideoCommon/VideoBackendBase.h"
#define TEXT_BOX(page, text) new wxStaticText(page, wxID_ANY, text)
@@ -924,8 +928,34 @@ void CConfigMain::DisplaySettingsChanged(wxCommandEvent& event)
break;
case ID_HOTKEY_CONFIG:
{
HotkeyConfigDialog m_HotkeyDialog(this);
m_HotkeyDialog.ShowModal();
bool was_init = false;
InputConfig* const hotkey_plugin = HotkeyManagerEmu::GetConfig();
// check if game is running
if (g_controller_interface.IsInit())
{
was_init = true;
}
else
{
#if defined(HAVE_X11) && HAVE_X11
Window win = X11Utils::XWindowFromHandle(GetHandle());
HotkeyManagerEmu::Initialize(reinterpret_cast<void*>(win));
#else
HotkeyManagerEmu::Initialize(reinterpret_cast<void*>(GetHandle()));
#endif
}
InputConfigDialog m_ConfigFrame(this, *hotkey_plugin, _("Dolphin Hotkeys"), 0);
m_ConfigFrame.ShowModal();
m_ConfigFrame.Destroy();
// if game isn't running
if (!was_init)
{
HotkeyManagerEmu::Shutdown();
}
}
// Update the GUI in case menu accelerators were changed
main_frame->UpdateGUI();
File diff suppressed because it is too large Load Diff
+11
View File
@@ -47,6 +47,8 @@ class wxAuiNotebook;
class wxAuiNotebookEvent;
class wxListEvent;
class wxMenuItem;
class wxTimer;
class wxTimerEvent;
class wxWindow;
class CRenderFrame : public wxFrame
@@ -175,6 +177,7 @@ private:
bool m_bGameLoading;
bool m_bClosing;
bool m_confirmStop;
bool m_bHotkeysInit;
std::vector<std::string> drives;
@@ -195,6 +198,8 @@ private:
EToolbar_Max
};
wxTimer* m_poll_hotkey_timer;
wxBitmap m_Bitmaps[EToolbar_Max];
wxBitmap m_BitmapsMenu[EToolbar_Max];
@@ -295,6 +300,7 @@ private:
void OnConfigAudio(wxCommandEvent& event);
void OnConfigControllers(wxCommandEvent& event);
void OnConfigHotkey(wxCommandEvent& event);
void OnConfigMenuCommands(wxCommandEvent& event);
void OnToggleFullscreen(wxCommandEvent& event);
void OnToggleDualCore(wxCommandEvent& event);
@@ -337,6 +343,11 @@ private:
void OnSaveCurrentSlot(wxCommandEvent& event);
void OnLoadCurrentSlot(wxCommandEvent& event);
void PollHotkeys(wxTimerEvent&);
void ParseHotkeys(wxKeyEvent &event);
bool InitHotkeys();
// Event table
DECLARE_EVENT_TABLE();
};
+40 -1
View File
@@ -46,6 +46,7 @@
#include "Core/Core.h"
#include "Core/CoreParameter.h"
#include "Core/Host.h"
#include "Core/HotkeyManager.h"
#include "Core/Movie.h"
#include "Core/State.h"
#include "Core/HW/CPU.h"
@@ -238,6 +239,7 @@ wxMenuBar* CFrame::CreateMenu()
pOptionsMenu->Append(IDM_CONFIG_AUDIO, _("&Audio Settings"));
pOptionsMenu->Append(IDM_CONFIG_CONTROLLERS, _("&Controller Settings"));
pOptionsMenu->Append(IDM_CONFIG_HOTKEYS, _("&Hotkey Settings"));
pOptionsMenu->Append(IDM_CONFIG_MENU_COMMANDS, _("&Menu Accelerators"));
if (g_pCodeWindow)
{
pOptionsMenu->AppendSeparator();
@@ -1350,11 +1352,48 @@ void CFrame::OnConfigControllers(wxCommandEvent& WXUNUSED (event))
config_dlg.Destroy();
}
void CFrame::OnConfigHotkey(wxCommandEvent& WXUNUSED (event))
void CFrame::OnConfigMenuCommands(wxCommandEvent& WXUNUSED(event))
{
HotkeyConfigDialog *m_HotkeyDialog = new HotkeyConfigDialog(this);
m_HotkeyDialog->ShowModal();
m_HotkeyDialog->Destroy();
// Update the GUI in case menu accelerators were changed
UpdateGUI();
}
void CFrame::OnConfigHotkey(wxCommandEvent& WXUNUSED (event))
{
bool was_init = false;
InputConfig* const hotkey_plugin = HotkeyManagerEmu::GetConfig();
// check if game is running
if (g_controller_interface.IsInit())
{
was_init = true;
}
else
{
#if defined(HAVE_X11) && HAVE_X11
Window win = X11Utils::XWindowFromHandle(GetHandle());
HotkeyManagerEmu::Initialize(reinterpret_cast<void*>(win));
#else
HotkeyManagerEmu::Initialize(reinterpret_cast<void*>(GetHandle()));
#endif
}
InputConfigDialog m_ConfigFrame(this, *hotkey_plugin, _("Dolphin Hotkeys"), 0);
m_ConfigFrame.ShowModal();
m_ConfigFrame.Destroy();
// if game isn't running
if (!was_init)
{
HotkeyManagerEmu::Shutdown();
}
// Update the GUI in case menu accelerators were changed
UpdateGUI();
}
+1
View File
@@ -149,6 +149,7 @@ enum
IDM_CONFIG_AUDIO,
IDM_CONFIG_CONTROLLERS,
IDM_CONFIG_HOTKEYS,
IDM_CONFIG_MENU_COMMANDS,
IDM_CONFIG_LOGGER,
// Views
+106 -106
View File
@@ -185,6 +185,112 @@ void HotkeyConfigDialog::OnButtonClick(wxCommandEvent& event)
#define HOTKEY_NUM_COLUMNS 2
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"),
};
void HotkeyConfigDialog::CreateHotkeyGUIControls()
{
const wxString pageNames[] =
@@ -193,112 +299,6 @@ void HotkeyConfigDialog::CreateHotkeyGUIControls()
_("State Saves")
};
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"),
};
const int page_breaks[3] = {HK_OPEN, HK_LOAD_STATE_SLOT_1, NUM_HOTKEYS};
// Configuration controls sizes
+1 -1
View File
@@ -29,7 +29,7 @@ class HotkeyConfigDialog : public wxDialog
public:
HotkeyConfigDialog(wxWindow* parent,
wxWindowID id = wxID_ANY,
const wxString &title = _("Hotkey Configuration"),
const wxString &title = _("Menu Accelerators"),
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE);
+2 -1
View File
@@ -839,7 +839,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
// Draw buttons in rows of 8
unsigned int button_cols = group->controls.size() > 8 ? 8 : group->controls.size();
unsigned int button_rows = ceil((float)group->controls.size() / 8.0f);
wxBitmap bitmap(int(12 * button_cols + 1), (12 * button_rows) - (button_rows - 1));
wxBitmap bitmap(int(12 * button_cols + 1), (11 * button_rows) + 1);
dc.SelectObject(bitmap);
dc.Clear();
@@ -1074,6 +1074,7 @@ InputConfigDialog::InputConfigDialog(wxWindow* const parent, InputConfig& config
szr->Add(m_pad_notebook, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5);
szr->Add(CreateButtonSizer(wxOK | wxCANCEL | wxNO_DEFAULT), 0, wxEXPAND|wxALL, 5);
SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED);
SetSizerAndFit(szr);
Center();
@@ -119,12 +119,12 @@ void DrawButton(unsigned int* const bitmasks, unsigned int buttons, unsigned int
unsigned char amt = 255 - g->control_group->controls[(row * 8) + n]->control_ref->State() * 128;
dc.SetBrush(wxBrush(wxColour(amt, amt, amt)));
}
dc.DrawRectangle(n * 12, (row == 0) ? 0 : (row * 12 - 1), 14, 12);
dc.DrawRectangle(n * 12, (row == 0) ? 0 : (row * 11), 14, 12);
// text
const std::string name = g->control_group->controls[(row * 8) + n]->name;
// bit of hax so ZL, ZR show up as L, R
dc.DrawText(StrToWxStr(std::string(1, (name[1] && name[1] < 'a') ? name[1] : name[0])), n * 12 + 2, 1 + ((row == 0) ? 0 : (row * 12 - 1)));
dc.DrawText(StrToWxStr(std::string(1, (name[1] && name[1] < 'a') ? name[1] : name[0])), n * 12 + 2, 1 + ((row == 0) ? 0 : (row * 11)));
}
static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)