Linux: Implemented mouse clicks for zapper/etc.

This commit is contained in:
Souryo 2016-12-14 18:26:52 -05:00
parent fc24993836
commit cd1c53efa1
5 changed files with 56 additions and 16 deletions

View File

@ -13,6 +13,10 @@ namespace Mesen.GUI.Controls
{
public partial class ctrlRenderer : BaseControl
{
private const int LeftMouseButtonKeyCode = 0x200;
private const int RightMouseButtonKeyCode = 0x201;
private const int MiddleMouseButtonKeyCode = 0x202;
private bool _cursorHidden = false;
public ctrlRenderer()
@ -41,6 +45,27 @@ namespace Mesen.GUI.Controls
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
SetMouseButtonState(e.Button, true);
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
SetMouseButtonState(e.Button, false);
}
private void SetMouseButtonState(MouseButtons button, bool down)
{
switch(button) {
case MouseButtons.Left: InteropEmu.SetKeyState(LeftMouseButtonKeyCode, down); break;
case MouseButtons.Right: InteropEmu.SetKeyState(RightMouseButtonKeyCode, down); break;
case MouseButtons.Middle: InteropEmu.SetKeyState(MiddleMouseButtonKeyCode, down); break;
}
}
private void ctrlRenderer_MouseMove(object sender, MouseEventArgs e)
{
if(!InteropEmu.IsRunning() || InteropEmu.IsPaused() || !InteropEmu.HasArkanoidPaddle()) {

View File

@ -226,7 +226,7 @@ static vector<KeyDefinition> _keyDefinitions = {
LinuxKeyManager::LinuxKeyManager()
{
_keyState.insert(_keyState.end(), 0x200, 0);
ResetKeyState();
for(KeyDefinition &keyDef : _keyDefinitions) {
_keyNames[keyDef.keyCode] = keyDef.description;
@ -254,8 +254,12 @@ bool LinuxKeyManager::IsKeyPressed(uint32_t key)
bool LinuxKeyManager::IsMouseButtonPressed(MouseButton button)
{
//TODO: NOT IMPLEMENTED YET
//Only needed for zapper/etc
switch(button) {
case MouseButton::LeftButton: return _mouseState[0];
case MouseButton::RightButton: return _mouseState[1];
case MouseButton::MiddleButton: return _mouseState[2];
}
return false;
}
@ -295,10 +299,15 @@ void LinuxKeyManager::UpdateDevices()
void LinuxKeyManager::SetKeyState(uint16_t scanCode, bool state)
{
_keyState[scanCode & 0xFF] = state ? 1 : 0;
if(scanCode > 0x1FF) {
_mouseState[scanCode & 0x03] = state;
} else {
_keyState[scanCode & 0xFF] = state;
}
}
void LinuxKeyManager::ResetKeyState()
{
memset(_keyState.data(), 0, 0x200 * sizeof(uint32_t));
}
memset(_mouseState, 0, sizeof(_mouseState));
memset(_keyState, 0, sizeof(_keyState));
}

View File

@ -12,7 +12,8 @@ struct KeyDefinition {
class LinuxKeyManager : public IKeyManager
{
private:
vector<uint32_t> _keyState;
bool _keyState[0x200];
bool _mouseState[0x03];
std::unordered_map<uint32_t, string> _keyNames;
std::unordered_map<string, uint32_t> _keyCodes;

View File

@ -205,7 +205,7 @@ WindowsKeyManager::WindowsKeyManager(HWND hWnd)
{
_hWnd = hWnd;
_keyState.insert(_keyState.end(), 0x200, 0);
ResetKeyState();
//Init XInput buttons
vector<string> buttonNames = { "Up", "Down", "Left", "Right", "Start", "Back", "L3", "R3", "L1", "R1", "?", "?", "A", "B", "X", "Y", "L2", "R2", "RT Up", "RT Down", "RT Up", "RT Left", "RT Right" };
@ -298,14 +298,13 @@ bool WindowsKeyManager::IsKeyPressed(uint32_t key)
bool WindowsKeyManager::IsMouseButtonPressed(MouseButton button)
{
uint32_t key = 0;
switch(button) {
case MouseButton::LeftButton: key = VK_LBUTTON; break;
case MouseButton::RightButton: key = VK_RBUTTON; break;
case MouseButton::MiddleButton: key = VK_MBUTTON; break;
case MouseButton::LeftButton: return _mouseState[0];
case MouseButton::RightButton: return _mouseState[1];
case MouseButton::MiddleButton: return _mouseState[2];
}
return (GetAsyncKeyState(key) & 0x8000) == 0x8000;
return false;
}
uint32_t WindowsKeyManager::GetPressedKey()
@ -366,10 +365,15 @@ void WindowsKeyManager::UpdateDevices()
void WindowsKeyManager::SetKeyState(uint16_t scanCode, bool state)
{
_keyState[scanCode & 0x1FF] = state ? 1 : 0;
if(scanCode > 0x1FF) {
_mouseState[scanCode & 0x03] = state;
} else {
_keyState[scanCode & 0x1FF] = state;
}
}
void WindowsKeyManager::ResetKeyState()
{
memset(_keyState.data(), 0, 0x200);
memset(_mouseState, 0, sizeof(_mouseState));
memset(_keyState, 0, sizeof(_keyState));
}

View File

@ -18,7 +18,8 @@ class WindowsKeyManager : public IKeyManager
{
private:
HWND _hWnd;
vector<uint32_t> _keyState;
bool _keyState[0x200];
bool _mouseState[0x03];
unique_ptr<DirectInputManager> _directInput;
unique_ptr<XInputManager> _xInput;
std::unordered_map<uint32_t, string> _keyNames;